{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "blog-02",
  "title": "Blog post",
  "description": "A post in its own scrolling frame with Copy link, a Share menu, a quote, previous and next and related posts, and a table of contents that folds into one bar on phones: as you read, a thin line fills along the top and the marker of the contents travels to the heading you reached.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/breadcrumb.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/collapsible.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/dropdown-menu.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/recipes.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/blog/blog-02/index.tsx",
      "content": "'use client';\n\nimport { useCallback, useEffect, useId, useRef, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { ArrowLeftIcon, ArrowRightIcon } from '@/registry/ndeko/lib/icons';\nimport { FOCUS_RING } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\nimport {\n  Breadcrumb,\n  BreadcrumbItem,\n  BreadcrumbLink,\n  BreadcrumbList,\n  BreadcrumbSeparator,\n} from '@/registry/ndeko/ui/breadcrumb';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { ArticleBody } from './article-body';\nimport { OnThisPage, TableOfContents } from './contents';\nimport { BLOG, NEXT, POST, PREVIOUS, RELATED, SECTIONS } from './data';\nimport { PostActions } from './post-actions';\nimport {\n  INITIAL,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  TOP,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\n/** A heading counts as read once it rises above this line of the frame. */\nconst READ_LINE_PX = 96;\n\n/** Where a heading lands after a jump: under the line, clear of the bar on phones. */\nconst LANDING_PX = 64;\n\nconst COPIED_FOR_MS = 1600;\n\nconst NO_PROGRESS = { transform: 'scaleX(0)' };\n\nconst FIRST_SECTION = SECTIONS[0].id;\n\nconst LAST_SECTION = SECTIONS[SECTIONS.length - 1].id;\n\nconst CARD =\n  'bg-card hairline-ring ring-border dark:bg-foreground/[0.03] rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)]';\n\nfunction isAtEndOf(frame: HTMLElement) {\n  const bottom = frame.scrollTop + frame.clientHeight;\n  const end = frame.scrollHeight - 1;\n  return bottom >= end;\n}\n\n/** The post ends before its last heading can rise to the read line, so the end of the frame marks it. */\nfunction readHeadingOf(frame: HTMLElement) {\n  if (isAtEndOf(frame)) {\n    return LAST_SECTION;\n  }\n  const frameTop = frame.getBoundingClientRect().top;\n  const headings = frame.querySelectorAll<HTMLElement>('[data-heading]');\n  let active = FIRST_SECTION;\n  for (const heading of headings) {\n    const top = heading.getBoundingClientRect().top - frameTop;\n    const isRead = top <= READ_LINE_PX;\n    const id = heading.dataset.heading;\n    if (isRead && id) {\n      active = id;\n    }\n  }\n  return active;\n}\n\nfunction scrollBehaviorOf(shouldReduceMotion: boolean): ScrollBehavior {\n  if (shouldReduceMotion) {\n    return 'auto';\n  }\n  return 'smooth';\n}\n\nfunction shareReadOf(frame: HTMLElement) {\n  const range = frame.scrollHeight - frame.clientHeight;\n  if (range <= 0) {\n    return 0;\n  }\n  return frame.scrollTop / range;\n}\n\nexport default function Blog02() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n    takeOver,\n  } = useSession(SESSION);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const baseId = useId();\n  const frameRef = useRef<HTMLDivElement>(null);\n  const progressRef = useRef<HTMLSpanElement>(null);\n  const pendingFrame = useRef<number | null>(null);\n  const [activeId, setActiveId] = useState(FIRST_SECTION);\n  const message = spokenUnless(isAutoplaying, state.spoken);\n  const canReplay = isFinished && !isAutoplaying;\n\n  const headingIdOf = useCallback(\n    (sectionId: string) => `${baseId}-${sectionId}`,\n    [baseId]\n  );\n\n  const scrollFrameTo = useCallback(\n    (sectionId: string) => {\n      const frame = frameRef.current;\n      const behavior = scrollBehaviorOf(shouldReduceMotion);\n      if (!frame) {\n        return null;\n      }\n      if (sectionId === TOP) {\n        frame.scrollTo({ top: 0, behavior });\n        return null;\n      }\n      const selector = `[data-heading=\"${sectionId}\"]`;\n      const heading = frame.querySelector<HTMLElement>(selector);\n      if (!heading) {\n        return null;\n      }\n      const headingTop = heading.getBoundingClientRect().top;\n      const frameTop = frame.getBoundingClientRect().top;\n      const top = headingTop - frameTop + frame.scrollTop - LANDING_PX;\n      frame.scrollTo({ top, behavior });\n      return heading;\n    },\n    [shouldReduceMotion]\n  );\n\n  useEffect(() => {\n    if (state.readRequest === 0) {\n      return;\n    }\n    scrollFrameTo(state.readTo);\n  }, [state.readRequest, state.readTo, scrollFrameTo]);\n\n  useEffect(() => {\n    if (!state.isLinkCopied) {\n      return;\n    }\n    const timer = setTimeout(() => {\n      act({ type: 'copyReset' });\n    }, COPIED_FOR_MS);\n    return () => clearTimeout(timer);\n  }, [state.isLinkCopied, act]);\n\n  useEffect(() => {\n    return () => {\n      const frameRequest = pendingFrame.current;\n      if (frameRequest !== null) {\n        cancelAnimationFrame(frameRequest);\n      }\n    };\n  }, []);\n\n  function measureReading() {\n    pendingFrame.current = null;\n    const frame = frameRef.current;\n    const bar = progressRef.current;\n    if (!frame || !bar) {\n      return;\n    }\n    const share = shareReadOf(frame);\n    bar.style.transform = `scaleX(${share})`;\n    const readId = readHeadingOf(frame);\n    setActiveId(readId);\n  }\n\n  /** The line and the contents follow the scroll at most once a frame, without a render for the line. */\n  function followReading() {\n    if (pendingFrame.current !== null) {\n      return;\n    }\n    pendingFrame.current = requestAnimationFrame(measureReading);\n  }\n\n  function yieldToWheel() {\n    if (isAutoplaying) {\n      takeOver();\n    }\n  }\n\n  /** A jump also hands the focus to the heading, so the keyboard reads on from there. */\n  function jumpTo(sectionId: string) {\n    const heading = scrollFrameTo(sectionId);\n    heading?.focus({ preventScroll: true });\n  }\n\n  async function copyLink() {\n    try {\n      await navigator.clipboard.writeText(POST.link);\n    } catch {\n      return;\n    }\n    act({ type: 'linkCopied' });\n  }\n\n  function replay() {\n    frameRef.current?.scrollTo({ top: 0 });\n    restart();\n  }\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-background text-foreground @container relative flex h-dvh min-h-[36rem] w-full flex-col overflow-hidden'\n      >\n        <span\n          ref={progressRef}\n          aria-hidden='true'\n          style={NO_PROGRESS}\n          className='bg-primary pointer-events-none absolute inset-x-0 top-0 z-30 h-0.5 origin-left'\n        />\n        <div\n          ref={frameRef}\n          onScroll={followReading}\n          onWheel={yieldToWheel}\n          className='relative min-h-0 flex-1 overflow-y-auto overscroll-contain'\n        >\n          <div className='mx-auto max-w-5xl px-4 pb-16 @2xl:px-8'>\n            <div className='flex min-h-16 items-center gap-3'>\n              <Breadcrumb className='min-w-0 flex-1'>\n                <BreadcrumbList>\n                  <BreadcrumbItem>\n                    <BreadcrumbLink\n                      href={BLOG.blogHref}\n                      className='flex items-center gap-1.5'\n                    >\n                      <CompanyMark seed={BLOG.company} size='sm' />\n                      Field notes\n                    </BreadcrumbLink>\n                  </BreadcrumbItem>\n                  <BreadcrumbSeparator />\n                  <BreadcrumbItem>\n                    <BreadcrumbLink href={BLOG.topicHref}>\n                      {POST.topic}\n                    </BreadcrumbLink>\n                  </BreadcrumbItem>\n                </BreadcrumbList>\n              </Breadcrumb>\n              <ReplayButton\n                isShown={canReplay}\n                onReplay={replay}\n                label='Replay'\n              />\n            </div>\n\n            <div className='grid gap-10 @3xl:grid-cols-[minmax(0,1fr)_13rem] @3xl:gap-14'>\n              <article className='flex min-w-0 flex-col gap-8'>\n                <header className='flex flex-col gap-5 pt-2'>\n                  <h1 className='text-2xl font-semibold text-balance @sm:text-3xl'>\n                    {POST.title}\n                  </h1>\n                  <p className='text-muted-foreground text-lg leading-8 text-pretty'>\n                    {POST.lead}\n                  </p>\n                  <div className='flex flex-wrap items-center gap-x-4 gap-y-3'>\n                    <div className='flex min-w-0 flex-1 items-center gap-3'>\n                      <Avatar seed={POST.author} className='size-9' />\n                      <div className='flex min-w-0 flex-col'>\n                        <p className='truncate text-[13px] font-medium'>\n                          {POST.author}\n                        </p>\n                        <p className='text-muted-foreground truncate text-xs tabular-nums'>\n                          <time dateTime={POST.isoDate}>{POST.date}</time>\n                          {' · '}\n                          {POST.minutes} min read\n                        </p>\n                      </div>\n                    </div>\n                    <PostActions\n                      isLinkCopied={state.isLinkCopied}\n                      isCopyPressed={pressed === 'copy-link'}\n                      onCopy={copyLink}\n                    />\n                  </div>\n                </header>\n\n                <OnThisPage\n                  activeId={activeId}\n                  headingIdOf={headingIdOf}\n                  onJump={jumpTo}\n                />\n\n                <ArticleBody headingIdOf={headingIdOf} />\n\n                <nav\n                  aria-label='More posts'\n                  className='grid gap-3 pt-4 @lg:grid-cols-2'\n                >\n                  <a\n                    href={PREVIOUS.href}\n                    className={cn(\n                      CARD,\n                      'group hover:bg-foreground/[0.02] flex flex-col gap-1 p-4 transition-colors duration-100',\n                      FOCUS_RING\n                    )}\n                  >\n                    <span className='text-muted-foreground flex items-center gap-1 text-xs'>\n                      <ArrowLeftIcon className='size-3.5 transition-transform duration-100 group-hover:-translate-x-0.5' />\n                      Previous\n                    </span>\n                    <span className='text-sm font-medium text-pretty'>\n                      {PREVIOUS.title}\n                    </span>\n                  </a>\n                  <a\n                    href={NEXT.href}\n                    className={cn(\n                      CARD,\n                      'group hover:bg-foreground/[0.02] flex flex-col gap-1 p-4 transition-colors duration-100 @lg:items-end @lg:text-end',\n                      FOCUS_RING\n                    )}\n                  >\n                    <span className='text-muted-foreground flex items-center gap-1 text-xs'>\n                      Next\n                      <ArrowRightIcon className='size-3.5 transition-transform duration-100 group-hover:translate-x-0.5' />\n                    </span>\n                    <span className='text-sm font-medium text-pretty'>\n                      {NEXT.title}\n                    </span>\n                  </a>\n                </nav>\n\n                <section\n                  aria-labelledby={`${baseId}-related`}\n                  className='flex flex-col gap-3'\n                >\n                  <h2\n                    id={`${baseId}-related`}\n                    className='text-[13px] font-medium'\n                  >\n                    Related posts\n                  </h2>\n                  <ul className='flex flex-col'>\n                    {RELATED.map((post) => (\n                      <li key={post.id}>\n                        <a\n                          href={post.href}\n                          className={cn(\n                            'group hover:bg-foreground/[0.03] -mx-2 flex items-center gap-3 rounded-lg px-2 py-2.5 transition-colors duration-100',\n                            FOCUS_RING\n                          )}\n                        >\n                          <span className='flex min-w-0 flex-1 flex-col gap-0.5'>\n                            <span className='truncate text-[13px] font-medium'>\n                              {post.title}\n                            </span>\n                            <span className='text-muted-foreground text-xs tabular-nums'>\n                              {post.topic} · {post.date} · {post.minutes} min\n                              read\n                            </span>\n                          </span>\n                          <ArrowRightIcon className='text-muted-foreground size-4 shrink-0 transition-transform duration-100 group-hover:translate-x-0.5' />\n                        </a>\n                      </li>\n                    ))}\n                  </ul>\n                </section>\n              </article>\n\n              <aside className='hidden @3xl:block'>\n                <div className='sticky top-8 pt-2'>\n                  <TableOfContents\n                    activeId={activeId}\n                    headingIdOf={headingIdOf}\n                    onJump={jumpTo}\n                    pressed={pressed}\n                  />\n                </div>\n              </aside>\n            </div>\n          </div>\n        </div>\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/blog-02/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/blog/blog-02/article-body.tsx",
      "content": "import { FOCUS_RING } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\n\nimport { SECTIONS, type ArticleBlock } from './data';\n\nfunction Block({ block }: { block: ArticleBlock }) {\n  if (block.kind === 'quote') {\n    return (\n      <figure className='bg-foreground/[0.03] flex flex-col gap-3 rounded-xl p-5'>\n        <blockquote className='text-lg leading-8 text-pretty'>\n          {block.text}\n        </blockquote>\n        <figcaption className='flex items-center gap-2.5 text-[13px]'>\n          <Avatar seed={block.person} className='size-6' />\n          <span>\n            <span className='font-medium'>{block.person}</span>\n            <span className='text-muted-foreground'>, {block.role}</span>\n          </span>\n        </figcaption>\n      </figure>\n    );\n  }\n  if (block.kind === 'list') {\n    return (\n      <ul className='flex flex-col gap-2 text-base leading-7'>\n        {block.items.map((item) => (\n          <li key={item} className='flex items-baseline gap-3'>\n            <span\n              aria-hidden='true'\n              className='bg-foreground/30 size-1.5 shrink-0 translate-y-[-0.15em] rounded-full'\n            />\n            {item}\n          </li>\n        ))}\n      </ul>\n    );\n  }\n  if (block.kind === 'code') {\n    return (\n      <figure className='flex flex-col gap-2'>\n        <pre className='bg-foreground/[0.04] relative overflow-x-auto rounded-xl px-4 py-3 font-mono text-[13px] leading-relaxed'>\n          <code>{block.code}</code>\n        </pre>\n        <figcaption className='text-muted-foreground text-xs'>\n          {block.caption}\n        </figcaption>\n      </figure>\n    );\n  }\n  return <p className='text-base leading-7 text-pretty'>{block.text}</p>;\n}\n\ntype ArticleBodyProps = {\n  /** The id a heading carries in the page, unique for each copy of the block. */\n  headingIdOf: (sectionId: string) => string;\n};\n\nexport function ArticleBody({ headingIdOf }: ArticleBodyProps) {\n  return (\n    <div className='flex flex-col gap-10'>\n      {SECTIONS.map((section) => (\n        <section key={section.id} className='flex flex-col gap-5'>\n          <h2\n            id={headingIdOf(section.id)}\n            data-heading={section.id}\n            tabIndex={-1}\n            className={cn(\n              'rounded-sm text-xl font-semibold text-balance',\n              FOCUS_RING\n            )}\n          >\n            {section.title}\n          </h2>\n          {section.blocks.map((block, index) => (\n            <Block key={`${section.id}-${index}`} block={block} />\n          ))}\n        </section>\n      ))}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/blog-02/article-body.tsx"
    },
    {
      "path": "registry/ndeko/blocks/blog/blog-02/contents.tsx",
      "content": "'use client';\n\nimport { motion, type Transition } from 'motion/react';\nimport { useId, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { pressedQuietOf } from '@/registry/ndeko/lib/demonstration';\nimport { ChevronDownIcon } from '@/registry/ndeko/lib/icons';\nimport { INSTANT, SPRING } from '@/registry/ndeko/lib/motion-presets';\nimport { FOCUS_RING } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport {\n  Collapsible,\n  CollapsibleContent,\n  CollapsibleTrigger,\n} from '@/registry/ndeko/ui/collapsible';\n\nimport { SECTIONS } from './data';\n\nfunction travelOf(shouldReduceMotion: boolean): Transition {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return SPRING;\n}\n\nfunction currentOf(isActive: boolean): 'location' | undefined {\n  if (isActive) {\n    return 'location';\n  }\n  return undefined;\n}\n\nfunction sectionTitleOf(sectionId: string) {\n  const section = SECTIONS.find((candidate) => candidate.id === sectionId);\n  return section?.title ?? SECTIONS[0].title;\n}\n\n/** `@starting-style` also plays when the page loads, so the title fades in only once it replaced another. */\nfunction titleEntranceOf(hasChanged: boolean) {\n  if (hasChanged) {\n    return 'transition-opacity duration-150 starting:opacity-0';\n  }\n  return undefined;\n}\n\ntype ContentsProps = {\n  activeId: string;\n  headingIdOf: (sectionId: string) => string;\n  onJump: (sectionId: string) => void;\n};\n\ntype ContentsLinkProps = {\n  sectionId: string;\n  title: string;\n  isActive: boolean;\n  isPressed: boolean;\n  headingIdOf: (sectionId: string) => string;\n  onJump: (sectionId: string) => void;\n  className?: string;\n};\n\nfunction ContentsLink({\n  sectionId,\n  title,\n  isActive,\n  isPressed,\n  headingIdOf,\n  onJump,\n  className,\n}: ContentsLinkProps) {\n  function jump(event: React.MouseEvent<HTMLAnchorElement>) {\n    event.preventDefault();\n    onJump(sectionId);\n  }\n\n  return (\n    <a\n      href={`#${headingIdOf(sectionId)}`}\n      aria-current={currentOf(isActive)}\n      onClick={jump}\n      className={cn(\n        'text-muted-foreground hover:text-foreground block rounded-sm py-1.5 text-[13px] text-pretty transition-[color,scale] duration-150',\n        isActive && 'text-foreground',\n        pressedQuietOf(isPressed),\n        FOCUS_RING,\n        className\n      )}\n    >\n      {title}\n    </a>\n  );\n}\n\nexport function TableOfContents({\n  activeId,\n  headingIdOf,\n  onJump,\n  pressed,\n}: ContentsProps & { pressed: string | null }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const markerId = useId();\n\n  return (\n    <nav aria-label='On this page' className='flex flex-col gap-3'>\n      <p className='text-muted-foreground text-xs font-medium'>On this page</p>\n      <ol className='hairline-l border-border flex flex-col'>\n        {SECTIONS.map((section) => {\n          const isActive = section.id === activeId;\n          return (\n            <li key={section.id} className='relative'>\n              {isActive && (\n                <motion.span\n                  layoutId={markerId}\n                  transition={travelOf(shouldReduceMotion)}\n                  className='bg-primary absolute inset-y-1.5 -start-px w-0.5 rounded-full'\n                />\n              )}\n              <ContentsLink\n                sectionId={section.id}\n                title={section.title}\n                isActive={isActive}\n                isPressed={pressed === `toc-${section.id}`}\n                headingIdOf={headingIdOf}\n                onJump={onJump}\n                className='ps-3'\n              />\n            </li>\n          );\n        })}\n      </ol>\n    </nav>\n  );\n}\n\nexport function OnThisPage({ activeId, headingIdOf, onJump }: ContentsProps) {\n  const [isOpen, setIsOpen] = useState(false);\n  const [firstActiveId] = useState(activeId);\n  const [hasActiveChanged, setHasActiveChanged] = useState(false);\n  const isFirstChange = !hasActiveChanged && activeId !== firstActiveId;\n  const activeTitle = sectionTitleOf(activeId);\n  if (isFirstChange) {\n    setHasActiveChanged(true);\n  }\n\n  function jumpAndClose(sectionId: string) {\n    setIsOpen(false);\n    onJump(sectionId);\n  }\n\n  return (\n    <Collapsible\n      open={isOpen}\n      onOpenChange={setIsOpen}\n      className='bg-background hairline-b border-border sticky top-0 z-10 -mx-4 px-4 @3xl:hidden'\n    >\n      <CollapsibleTrigger\n        className={cn(\n          'flex h-11 w-full items-center gap-2 rounded-md text-start',\n          FOCUS_RING\n        )}\n      >\n        <span className='text-muted-foreground shrink-0 text-xs'>\n          On this page\n        </span>\n        <span\n          key={activeId}\n          className={cn(\n            'min-w-0 truncate text-[13px] font-medium',\n            titleEntranceOf(hasActiveChanged)\n          )}\n        >\n          {activeTitle}\n        </span>\n        <ChevronDownIcon\n          className={cn(\n            'text-muted-foreground ms-auto size-4 shrink-0 transition-transform duration-200',\n            isOpen && 'rotate-180'\n          )}\n        />\n      </CollapsibleTrigger>\n      <CollapsibleContent className='bg-background hairline-b border-border absolute inset-x-0 top-full px-4'>\n        <ol className='flex flex-col pb-3'>\n          {SECTIONS.map((section) => (\n            <li key={section.id}>\n              <ContentsLink\n                sectionId={section.id}\n                title={section.title}\n                isActive={section.id === activeId}\n                isPressed={false}\n                headingIdOf={headingIdOf}\n                onJump={jumpAndClose}\n              />\n            </li>\n          ))}\n        </ol>\n      </CollapsibleContent>\n    </Collapsible>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/blog-02/contents.tsx"
    },
    {
      "path": "registry/ndeko/blocks/blog/blog-02/post-actions.tsx",
      "content": "'use client';\n\nimport { pressedQuietOf } from '@/registry/ndeko/lib/demonstration';\nimport {\n  CheckIcon,\n  LinkedinBrandIcon,\n  LinkIcon,\n  MailIcon,\n  Share2Icon,\n  TwitterXIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuItem,\n  DropdownMenuTrigger,\n} from '@/registry/ndeko/ui/dropdown-menu';\n\nimport { POST } from './data';\n\nfunction encoded(text: string) {\n  return encodeURIComponent(text);\n}\n\nfunction openInNewTab(address: string) {\n  window.open(address, '_blank', 'noopener,noreferrer');\n}\n\nfunction shareByEmail() {\n  const subject = encoded(POST.title);\n  const body = encoded(POST.link);\n  window.location.href = `mailto:?subject=${subject}&body=${body}`;\n}\n\nfunction shareOnLinkedIn() {\n  const link = encoded(POST.link);\n  openInNewTab(`https://www.linkedin.com/sharing/share-offsite/?url=${link}`);\n}\n\nfunction shareOnX() {\n  const link = encoded(POST.link);\n  const text = encoded(POST.title);\n  openInNewTab(`https://x.com/intent/post?url=${link}&text=${text}`);\n}\n\nfunction copyLabelOf(isCopied: boolean) {\n  if (isCopied) {\n    return 'Link copied';\n  }\n  return 'Copy link';\n}\n\ntype PostActionsProps = {\n  isLinkCopied: boolean;\n  isCopyPressed: boolean;\n  onCopy: () => void;\n};\n\nexport function PostActions({\n  isLinkCopied,\n  isCopyPressed,\n  onCopy,\n}: PostActionsProps) {\n  return (\n    <div className='flex items-center gap-2'>\n      <Button\n        type='button'\n        variant='outline'\n        size='sm'\n        onClick={onCopy}\n        className={cn('w-[6.5rem]', pressedQuietOf(isCopyPressed))}\n      >\n        <Swap swapKey={String(isLinkCopied)}>\n          {isLinkCopied && <CheckIcon className='size-3.5' />}\n          {!isLinkCopied && <LinkIcon className='size-3.5' />}\n        </Swap>\n        <Swap swapKey={copyLabelOf(isLinkCopied)}>\n          {copyLabelOf(isLinkCopied)}\n        </Swap>\n      </Button>\n      <DropdownMenu>\n        <DropdownMenuTrigger\n          render={<Button type='button' variant='outline' size='sm' />}\n        >\n          <Share2Icon className='size-3.5' />\n          Share\n        </DropdownMenuTrigger>\n        <DropdownMenuContent align='end' className='min-w-44'>\n          <DropdownMenuItem onClick={shareByEmail}>\n            <MailIcon />\n            Email\n          </DropdownMenuItem>\n          <DropdownMenuItem onClick={shareOnLinkedIn}>\n            <LinkedinBrandIcon />\n            LinkedIn\n          </DropdownMenuItem>\n          <DropdownMenuItem onClick={shareOnX}>\n            <TwitterXIcon />X\n          </DropdownMenuItem>\n        </DropdownMenuContent>\n      </DropdownMenu>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/blog-02/post-actions.tsx"
    },
    {
      "path": "registry/ndeko/blocks/blog/blog-02/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nexport type PostState = {\n  /** The heading the demonstration scrolls the frame to, or the top of the post. */\n  readTo: string;\n  /** Counts the requests, so asking twice for the same place still scrolls. */\n  readRequest: number;\n  isLinkCopied: boolean;\n  spoken: string;\n};\n\nexport type PostAction =\n  | { type: 'readTo'; heading: string }\n  | { type: 'linkCopied' }\n  | { type: 'copyReset' };\n\ntype Step = SessionStep<PostState, PostAction>;\n\nexport const TOP = 'top';\n\nexport const INITIAL: PostState = {\n  readTo: TOP,\n  readRequest: 0,\n  isLinkCopied: false,\n  spoken: '',\n};\n\nexport function reducer(state: PostState, action: PostAction): PostState {\n  switch (action.type) {\n    case 'readTo':\n      return {\n        ...state,\n        readTo: action.heading,\n        readRequest: state.readRequest + 1,\n      };\n    case 'linkCopied':\n      return {\n        ...state,\n        isLinkCopied: true,\n        spoken: 'Link to the post copied',\n      };\n    case 'copyReset':\n      return { ...state, isLinkCopied: false };\n  }\n}\n\nfunction readTo(after: number, heading: string): Step {\n  return { after, by: 'demo', action: { type: 'readTo', heading } };\n}\n\n/**\n * A reader goes down the post one section at a time, jumps to the last one from the table of\n * contents, copies the link and goes back to the top: the round ends where it began.\n */\nexport const SCRIPT: Step[] = [\n  readTo(1500, 'small-changes'),\n  readTo(2300, 'merging'),\n  readTo(2300, 'replayed'),\n  {\n    after: 2000,\n    by: 'demo',\n    press: 'toc-rollout',\n    action: { type: 'readTo', heading: 'rollout' },\n  },\n  {\n    after: 1900,\n    by: 'demo',\n    press: 'copy-link',\n    action: { type: 'linkCopied' },\n  },\n  readTo(2200, TOP),\n];\n\nexport const RESTING: PostState = INITIAL;\n\nexport const LOOP_AFTER_MS = 2200;\n",
      "type": "registry:component",
      "target": "components/blocks/blog-02/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/blog/blog-02/data.ts",
      "content": "export type ArticleBlock =\n  | { kind: 'paragraph'; text: string }\n  | { kind: 'quote'; text: string; person: string; role: string }\n  | { kind: 'list'; items: string[] }\n  | { kind: 'code'; code: string; caption: string };\n\nexport type Section = {\n  id: string;\n  title: string;\n  blocks: ArticleBlock[];\n};\n\nexport type Neighbour = {\n  title: string;\n  href: string;\n};\n\nexport type Related = {\n  id: string;\n  title: string;\n  topic: string;\n  date: string;\n  minutes: number;\n  href: string;\n};\n\nexport const BLOG = {\n  company: 'Saltmarsh',\n  blogHref: '#blog',\n  topicHref: '#blog-engineering',\n};\n\nexport const POST = {\n  title: 'Offline sync that survives a week without signal',\n  lead: 'Surveyors spend days on islands with no network. We rebuilt sync around a log of small changes that merge cleanly when the boat gets back to the harbour.',\n  topic: 'Engineering',\n  author: 'Ines Duarte',\n  role: 'Engineer, sync and storage',\n  date: '4 Nov 2026',\n  isoDate: '2026-11-04',\n  minutes: 9,\n  link: 'https://saltmarsh.example/blog/offline-sync',\n};\n\nexport const SECTIONS: Section[] = [\n  {\n    id: 'week-offline',\n    title: 'A week without signal',\n    blocks: [\n      {\n        kind: 'paragraph',\n        text: 'Most of the people who use Saltmarsh count things in places phones were not built for: salt marsh, sea cliffs, upland bog. A seabird team on a small island can go six days without a bar of signal, then sync everything from the ferry on the way home.',\n      },\n      {\n        kind: 'paragraph',\n        text: 'Our first sync engine sent whole records. When two people edited the same quadrat while offline, the last phone to reach a network won, and the other visit quietly disappeared. Nobody noticed until the season report.',\n      },\n      {\n        kind: 'quote',\n        text: 'We carried a paper notebook as well, because one of the phones always lost the last day.',\n        person: 'Rhys Morgan',\n        role: 'Field lead on the estuary count',\n      },\n    ],\n  },\n  {\n    id: 'small-changes',\n    title: 'A log of small changes',\n    blocks: [\n      {\n        kind: 'paragraph',\n        text: 'We stopped sending records and started sending what happened to them. Every tap that changes data becomes one small entry: set the count of curlews to 14, attach this photo, move this point two metres north.',\n      },\n      {\n        kind: 'code',\n        code: '{\\n  \"device\": \"phone-7f2\",\\n  \"seq\": 4182,\\n  \"record\": \"visit/dee-14\",\\n  \"set\": { \"curlew\": 14 }\\n}',\n        caption: 'One entry of the log, as the phone writes it',\n      },\n      {\n        kind: 'paragraph',\n        text: 'Entries carry the phone that wrote them and a counter that only goes up. They are written to the phone first and never edited afterwards, so a crash in the middle of a count loses at most the entry being written.',\n      },\n    ],\n  },\n  {\n    id: 'merging',\n    title: 'Merging when the boat gets back',\n    blocks: [\n      {\n        kind: 'paragraph',\n        text: 'When a phone finds a network it sends every entry the server has not seen, in order, and the server replays them on top of what it already holds. Two entries that touch different fields both land, which covers almost every case we saw in a season.',\n      },\n      {\n        kind: 'list',\n        items: [\n          'Different fields: both changes are kept',\n          'Same field and same value: there is nothing to decide',\n          'Same field, different values: the field lead picks one, and nothing is thrown away',\n        ],\n      },\n      {\n        kind: 'paragraph',\n        text: 'When two entries change the same field, the record is flagged instead of overwritten. The field lead sees both values side by side, with the names of the two people who entered them, and keeps one.',\n      },\n    ],\n  },\n  {\n    id: 'replayed',\n    title: 'Replaying last season',\n    blocks: [\n      {\n        kind: 'paragraph',\n        text: 'Before shipping, we replayed the logs of last season through the new engine. Every visit the old engine had overwritten came back, with its conflict flagged for a person to settle.',\n      },\n      {\n        kind: 'paragraph',\n        text: 'The log is also smaller than the records were. A day of counting is a few hundred entries of a few dozen bytes each, so even a weak signal on the ferry is enough to send a week.',\n      },\n    ],\n  },\n  {\n    id: 'rollout',\n    title: 'Rolling it out',\n    blocks: [\n      {\n        kind: 'paragraph',\n        text: 'The new engine ran beside the old one for a month, writing the log without using it. Once both agreed on every record for two weeks, we moved teams over one region at a time, starting with the ones that spend the longest offline.',\n      },\n      {\n        kind: 'paragraph',\n        text: 'If you lead a team, there is nothing to do: the next update moves your phones to the log. Conflicts appear in the review tab of each survey, with a dot on the tab while one waits for you.',\n      },\n    ],\n  },\n];\n\nexport const PREVIOUS: Neighbour = {\n  title: 'A species picker for gloved hands',\n  href: '#gloved-picker',\n};\n\nexport const NEXT: Neighbour = {\n  title: 'Planning the winter counts with three teams',\n  href: '#winter-counts',\n};\n\nexport const RELATED: Related[] = [\n  {\n    id: 'search-on-phone',\n    title: 'Why we moved search into the phone',\n    topic: 'Engineering',\n    date: '7 Oct 2026',\n    minutes: 8,\n    href: '#search-on-phone',\n  },\n  {\n    id: 'bat-battery',\n    title: 'What a bat survey taught us about battery life',\n    topic: 'Engineering',\n    date: '16 Sep 2026',\n    minutes: 6,\n    href: '#bat-battery',\n  },\n  {\n    id: 'photo-pins',\n    title: 'Photos that keep their place on the map',\n    topic: 'Product',\n    date: '21 Oct 2026',\n    minutes: 4,\n    href: '#photo-pins',\n  },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/blog-02/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "blog"
  ],
  "type": "registry:block"
}