{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card-04",
  "title": "Post deck",
  "description": "A deck of posts with a drawn visual, a page index and like, reply, share and bookmark, where the front card swings out to the left as the next steps up.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/recipes.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-autoplay.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/card/card-04.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId, useImperativeHandle, useRef, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport type { AutoplayStep } from '@/registry/ndeko/hooks/use-autoplay';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport {\n  PRESS_LEAD_MS,\n  pressedQuietOf,\n  spokenUnless,\n  usePress,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  BookmarkIcon,\n  CheckIcon,\n  ChevronLeftIcon,\n  ChevronRightIcon,\n  HeartIcon,\n  MessageCircleIcon,\n  ShareIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { fadePresence } from '@/registry/ndeko/lib/motion-presets';\nimport { FOCUS_RING } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { depthOf, useDeck } from './_parts/deck';\nimport { holdFocusOutsideCards, isOnControl, sideStepOf } from './_parts/keys';\nimport { PEOPLE } from './_parts/people';\nimport { SampleNote } from './_parts/sample-note';\nimport { useCardDemo } from './_parts/use-card-demo';\n\nexport type PostReply = {\n  id: string;\n  author: string;\n  text: string;\n};\n\nexport type Post = {\n  id: string;\n  author: { name: string; role: string };\n  /** How long ago it was posted, as the card shows it: \"2h\". */\n  age: string;\n  text: string;\n  /** What the inner panel shows: a picture, a chart, any drawing. */\n  visual: React.ReactNode;\n  /** Likes from everyone else: the viewer's own like is added on top. */\n  likeCount: number;\n  replies: PostReply[];\n};\n\n/** The control a demonstration holds down before it acts. */\nexport type PostDeckPress = 'like' | 'next';\n\nexport type PostDeckHandle = {\n  next: () => void;\n  previous: () => void;\n  toggleLike: () => void;\n};\n\nconst LAST_LAYER = 2;\nconst PEEK_PX = 8;\nconst SCALE_STEP = 0.04;\nconst OUT_SHIFT_PERCENT = -60;\nconst OUT_DROP_PX = 12;\nconst OUT_TILT_DEG = -8;\nconst LEAVE_MS = 260;\n\n/** A drag turns the card a little as it moves, and past this distance a release turns the deck. */\nconst TILT_PER_PX = 0.04;\nconst SWIPE_PX = 72;\n\nconst SHARED_FOR_MS = 1600;\n\n/** Under 20rem a post needs a third line of text, so the cards and the deck grow by one line there. */\nconst CARD = [\n  'bg-card hairline-ring ring-border absolute inset-x-0 bottom-0 flex h-[18.75rem] origin-top flex-col gap-3 rounded-xl p-4 @max-xs:h-[20rem]',\n  'shadow-[0_1px_2px_rgb(0_0_0/0.04)] ease-(--ease-out-strong) select-none',\n].join(' ');\n\nconst FRONT =\n  'cursor-grab touch-pan-y data-[dragging=true]:cursor-grabbing data-[dragging=true]:transition-none';\n\nconst TRAVELLING = 'transition-[transform,opacity] duration-300';\n\nconst PLACED = 'transition-none';\n\nconst ACTION = 'text-muted-foreground -mx-1 gap-1.5 px-2 tabular-nums';\n\ntype Placement = { transform: string; opacity: number; zIndex: number };\n\n/** The drag of a finger is added to the place of the card through two custom properties, so no render runs while it moves. */\nfunction transformOf(\n  shiftPercent: number,\n  offsetY: number,\n  scale: number,\n  tilt: number\n) {\n  const shift = `calc(${shiftPercent}% + var(--drag-x, 0px))`;\n  const turn = `calc(${tilt}deg + var(--drag-tilt, 0deg))`;\n  return `translate(${shift}, ${offsetY}px) scale(${scale}) rotate(${turn})`;\n}\n\nfunction opacityOf(isShown: boolean) {\n  if (isShown) {\n    return 1;\n  }\n  return 0;\n}\n\nfunction placementOf(depth: number, isOut: boolean, count: number): Placement {\n  if (isOut) {\n    const swungOut = transformOf(\n      OUT_SHIFT_PERCENT,\n      OUT_DROP_PX,\n      1,\n      OUT_TILT_DEG\n    );\n    const aboveAll = count + 1;\n    return { transform: swungOut, opacity: 0, zIndex: aboveAll };\n  }\n  const layer = Math.min(depth, LAST_LAYER);\n  const lift = layer * -PEEK_PX;\n  const shrink = layer * SCALE_STEP;\n  const scale = 1 - shrink;\n  const isShown = depth <= LAST_LAYER;\n  const stackOrder = count - depth;\n  return {\n    transform: transformOf(0, lift, scale, 0),\n    opacity: opacityOf(isShown),\n    zIndex: stackOrder,\n  };\n}\n\nfunction travelOf(isPlaced: boolean) {\n  if (isPlaced) {\n    return PLACED;\n  }\n  return TRAVELLING;\n}\n\nfunction likesOf(post: Post, isLiked: boolean) {\n  if (isLiked) {\n    return post.likeCount + 1;\n  }\n  return post.likeCount;\n}\n\nfunction likeWordOf(count: number) {\n  if (count === 1) {\n    return 'like';\n  }\n  return 'likes';\n}\n\nfunction replyWordOf(count: number) {\n  if (count === 1) {\n    return 'reply';\n  }\n  return 'replies';\n}\n\nfunction shareLabelOf(isShared: boolean) {\n  if (isShared) {\n    return 'Link copied';\n  }\n  return 'Copy the link';\n}\n\nfunction Replies({ replies }: { replies: PostReply[] }) {\n  if (replies.length === 0) {\n    return <p className='text-muted-foreground text-xs'>No replies yet</p>;\n  }\n\n  return (\n    <ul className='flex w-full flex-col gap-2.5 self-start'>\n      {replies.map((reply) => (\n        <li key={reply.id} className='flex items-start gap-2 text-xs'>\n          <Avatar seed={reply.author} className='size-5' />\n          <p className='min-w-0 leading-5'>\n            <span className='font-medium'>{reply.author}</span>{' '}\n            <span className='text-muted-foreground'>{reply.text}</span>\n          </p>\n        </li>\n      ))}\n    </ul>\n  );\n}\n\ntype Drag = { pointerId: number; startX: number };\n\ntype PostCardProps = {\n  post: Post;\n  position: number;\n  count: number;\n  placement: Placement;\n  isFront: boolean;\n  /** The card takes its pose at once, to travel from there on the next change. */\n  isPlaced: boolean;\n  /** A drag turns the deck: false for a deck of one. */\n  canTurn: boolean;\n  isLiked: boolean;\n  isSaved: boolean;\n  isShared: boolean;\n  showsReplies: boolean;\n  isLikePressed: boolean;\n  canShare: boolean;\n  onToggleLike: () => void;\n  onToggleSaved: () => void;\n  onToggleReplies: () => void;\n  onShare: () => void;\n  onSwipe: (step: 1 | -1) => void;\n};\n\nfunction PostCard({\n  post,\n  position,\n  count,\n  placement,\n  isFront,\n  isPlaced,\n  canTurn,\n  isLiked,\n  isSaved,\n  isShared,\n  showsReplies,\n  isLikePressed,\n  canShare,\n  onToggleLike,\n  onToggleSaved,\n  onToggleReplies,\n  onShare,\n  onSwipe,\n}: PostCardProps) {\n  const drag = useRef<Drag | null>(null);\n  const fade = fadePresence();\n  const likes = likesOf(post, isLiked);\n  const replyCount = post.replies.length;\n  const likeWord = likeWordOf(likes);\n  const replyWord = replyWordOf(replyCount);\n  const likeLabel = `Like, ${likes} ${likeWord}`;\n  const replyLabel = `${replyCount} ${replyWord}`;\n  const shareLabel = shareLabelOf(isShared);\n  const answersDrag = isFront && canTurn;\n\n  function grab(event: React.PointerEvent<HTMLLIElement>) {\n    const isMainButton = event.button === 0;\n    const startsOnCard = !isOnControl(event.target);\n    const canGrab = answersDrag && isMainButton && startsOnCard;\n    if (!canGrab) {\n      return;\n    }\n    const card = event.currentTarget;\n    drag.current = { pointerId: event.pointerId, startX: event.clientX };\n    card.setPointerCapture(event.pointerId);\n    card.dataset.dragging = 'true';\n  }\n\n  function heldBy(event: React.PointerEvent<HTMLLIElement>) {\n    const held = drag.current;\n    if (!held) {\n      return null;\n    }\n    if (held.pointerId !== event.pointerId) {\n      return null;\n    }\n    return held;\n  }\n\n  function follow(event: React.PointerEvent<HTMLLIElement>) {\n    const held = heldBy(event);\n    if (!held) {\n      return;\n    }\n    const offset = event.clientX - held.startX;\n    const tilt = offset * TILT_PER_PX;\n    const card = event.currentTarget;\n    card.style.setProperty('--drag-x', `${offset}px`);\n    card.style.setProperty('--drag-tilt', `${tilt}deg`);\n  }\n\n  function letGo(card: HTMLLIElement) {\n    drag.current = null;\n    delete card.dataset.dragging;\n    card.style.removeProperty('--drag-x');\n    card.style.removeProperty('--drag-tilt');\n  }\n\n  function release(event: React.PointerEvent<HTMLLIElement>) {\n    const held = heldBy(event);\n    if (!held) {\n      return;\n    }\n    const offset = event.clientX - held.startX;\n    letGo(event.currentTarget);\n    if (offset <= -SWIPE_PX) {\n      onSwipe(1);\n      return;\n    }\n    if (offset >= SWIPE_PX) {\n      onSwipe(-1);\n    }\n  }\n\n  /** A drag the browser takes back, to scroll the page for instance, turns nothing. */\n  function cancel(event: React.PointerEvent<HTMLLIElement>) {\n    if (heldBy(event)) {\n      letGo(event.currentTarget);\n    }\n  }\n\n  return (\n    <li\n      style={placement}\n      inert={!isFront}\n      aria-hidden={!isFront}\n      onPointerDown={grab}\n      onPointerMove={follow}\n      onPointerUp={release}\n      onPointerCancel={cancel}\n      className={cn(CARD, travelOf(isPlaced), answersDrag && FRONT)}\n    >\n      <div className='flex items-center gap-2.5'>\n        <Avatar seed={post.author.name} />\n        <div className='min-w-0 flex-1'>\n          <p className='truncate text-[13px] font-medium'>{post.author.name}</p>\n          <p className='text-muted-foreground truncate text-xs'>\n            {post.author.role} · {post.age}\n          </p>\n        </div>\n        <p className='text-muted-foreground text-xs tabular-nums'>\n          {position}/{count}\n        </p>\n      </div>\n      <div className='bg-foreground/[0.04] relative flex h-32 items-center justify-center overflow-hidden rounded-md p-3'>\n        <AnimatePresence mode='popLayout' initial={false}>\n          {showsReplies && (\n            <motion.div\n              key='replies'\n              className='flex size-full items-center justify-center'\n              {...fade}\n            >\n              <Replies replies={post.replies} />\n            </motion.div>\n          )}\n          {!showsReplies && (\n            <motion.div\n              key='visual'\n              className='flex size-full items-center justify-center'\n              {...fade}\n            >\n              {post.visual}\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n      <p className='line-clamp-2 h-10 text-[13px] leading-5 @max-xs:line-clamp-3 @max-xs:h-[3.75rem]'>\n        {post.text}\n      </p>\n      <div className='flex items-center gap-1'>\n        <Button\n          type='button'\n          variant='ghost'\n          size='sm'\n          aria-pressed={isLiked}\n          aria-label={likeLabel}\n          onClick={onToggleLike}\n          className={cn(ACTION, pressedQuietOf(isLikePressed))}\n        >\n          <Swap swapKey={String(isLiked)}>\n            {isLiked && (\n              <HeartIcon fill='currentColor' className='text-primary-ink' />\n            )}\n            {!isLiked && <HeartIcon />}\n          </Swap>\n          <MotionNumber value={likes} />\n        </Button>\n        <Button\n          type='button'\n          variant='ghost'\n          size='sm'\n          aria-expanded={showsReplies}\n          aria-label={replyLabel}\n          onClick={onToggleReplies}\n          className={ACTION}\n        >\n          <MessageCircleIcon />\n          {replyCount}\n        </Button>\n        {canShare && (\n          <Button\n            type='button'\n            variant='ghost'\n            size='icon-sm'\n            aria-label={shareLabel}\n            onClick={onShare}\n            className='text-muted-foreground'\n          >\n            <Swap swapKey={shareLabel}>\n              {isShared && <CheckIcon className='text-success-foreground' />}\n              {!isShared && <ShareIcon />}\n            </Swap>\n          </Button>\n        )}\n        <Button\n          type='button'\n          variant='ghost'\n          size='icon-sm'\n          aria-pressed={isSaved}\n          aria-label='Bookmark'\n          onClick={onToggleSaved}\n          className='text-muted-foreground ms-auto -me-1'\n        >\n          <Swap swapKey={String(isSaved)}>\n            {isSaved && (\n              <BookmarkIcon fill='currentColor' className='text-foreground' />\n            )}\n            {!isSaved && <BookmarkIcon />}\n          </Swap>\n        </Button>\n      </div>\n    </li>\n  );\n}\n\nexport type PostDeckProps = {\n  posts: Post[];\n  likedIds: readonly string[];\n  savedIds: readonly string[];\n  onLikedChange: (postId: string, isLiked: boolean) => void;\n  onSavedChange: (postId: string, isSaved: boolean) => void;\n  /** Copies or sends the link of a post. The mark turns into a check once it resolves. Without it, no share control is drawn. */\n  onShare?: (post: Post) => void | Promise<void>;\n  /** Turns the deck or likes from outside, for a demonstration or a shortcut of the page. */\n  handleRef?: React.Ref<PostDeckHandle>;\n  /** Shows Like or Next held down, for a demonstration that presses it. */\n  pressed?: PostDeckPress | null;\n  /** Keeps the live region quiet while a demonstration turns the deck by itself. */\n  isSilent?: boolean;\n  label?: string;\n  /** Says the posts are made up. Leave it out for real posts. */\n  note?: string;\n  className?: string;\n};\n\nexport function PostDeck({\n  posts,\n  likedIds,\n  savedIds,\n  onLikedChange,\n  onSavedChange,\n  onShare,\n  handleRef,\n  pressed = null,\n  isSilent = false,\n  label = 'Posts',\n  note,\n  className,\n}: PostDeckProps) {\n  const hintId = useId();\n  const count = posts.length;\n  const deck = useDeck(count, LEAVE_MS);\n  const [repliesPostId, setRepliesPostId] = useState<string | null>(null);\n  const [sharedPostId, setSharedPostId] = useState<string | null>(null);\n  const { schedule, clearAll } = useTimeouts();\n  const frontPost = posts[deck.front];\n  const frontPosition = deck.front + 1;\n  const canTurn = count > 1;\n  const canShare = onShare !== undefined;\n  const isLikeDown = pressed === 'like';\n  const isNextDown = pressed === 'next';\n\n  function showNext() {\n    setRepliesPostId(null);\n    deck.next();\n  }\n\n  function showPrevious() {\n    setRepliesPostId(null);\n    deck.previous();\n  }\n\n  function turn(step: 1 | -1) {\n    if (step === 1) {\n      showNext();\n      return;\n    }\n    showPrevious();\n  }\n\n  function turnWithKeys(event: React.KeyboardEvent<HTMLDivElement>) {\n    const step = sideStepOf(event.key);\n    if (step === 0) {\n      return;\n    }\n    event.preventDefault();\n    holdFocusOutsideCards(event.currentTarget);\n    turn(step);\n  }\n\n  function toggleLike(post: Post) {\n    const isLiked = likedIds.includes(post.id);\n    onLikedChange(post.id, !isLiked);\n  }\n\n  function toggleSaved(post: Post) {\n    const isSaved = savedIds.includes(post.id);\n    onSavedChange(post.id, !isSaved);\n  }\n\n  function toggleReplies(post: Post) {\n    if (repliesPostId === post.id) {\n      setRepliesPostId(null);\n      return;\n    }\n    setRepliesPostId(post.id);\n  }\n\n  async function share(post: Post) {\n    if (!onShare) {\n      return;\n    }\n    try {\n      await onShare(post);\n    } catch {\n      return;\n    }\n    clearAll();\n    setSharedPostId(post.id);\n    schedule(() => setSharedPostId(null), SHARED_FOR_MS);\n  }\n\n  function toggleFrontLike() {\n    if (frontPost) {\n      toggleLike(frontPost);\n    }\n  }\n\n  useImperativeHandle(handleRef, () => ({\n    next: showNext,\n    previous: showPrevious,\n    toggleLike: toggleFrontLike,\n  }));\n\n  if (!frontPost) {\n    return (\n      <p className='hairline-border border-foreground/20 text-muted-foreground flex h-[18.75rem] w-full items-center justify-center rounded-xl border-dashed text-[13px]'>\n        No posts yet\n      </p>\n    );\n  }\n\n  const announcement = `Post ${frontPosition} of ${count}, by ${frontPost.author.name}: ${frontPost.text}`;\n\n  return (\n    <div\n      role='group'\n      aria-roledescription='carousel'\n      aria-label={label}\n      aria-describedby={hintId}\n      tabIndex={0}\n      onKeyDown={turnWithKeys}\n      className={cn(\n        '@container flex w-full flex-col gap-3 rounded-xl',\n        FOCUS_RING,\n        className\n      )}\n    >\n      <ul className='relative h-[19.75rem] @max-xs:h-[21rem]'>\n        {posts.map((post, index) => {\n          const depth = depthOf(index, deck.front, count);\n          const isOut = index === deck.out;\n          const isFront = depth === 0;\n          const position = index + 1;\n          const isPlaced = isOut && deck.isReturning;\n          const isLikePressed = isFront && isLikeDown;\n          return (\n            <PostCard\n              key={post.id}\n              post={post}\n              position={position}\n              count={count}\n              placement={placementOf(depth, isOut, count)}\n              isFront={isFront}\n              isPlaced={isPlaced}\n              canTurn={canTurn}\n              isLiked={likedIds.includes(post.id)}\n              isSaved={savedIds.includes(post.id)}\n              isShared={sharedPostId === post.id}\n              showsReplies={repliesPostId === post.id}\n              isLikePressed={isLikePressed}\n              canShare={canShare}\n              onToggleLike={() => toggleLike(post)}\n              onToggleSaved={() => toggleSaved(post)}\n              onToggleReplies={() => toggleReplies(post)}\n              onShare={() => share(post)}\n              onSwipe={turn}\n            />\n          );\n        })}\n      </ul>\n      <div className='flex h-7 items-center justify-between gap-2 ps-1'>\n        <span className='min-w-0 truncate'>\n          {note && <SampleNote>{note}</SampleNote>}\n        </span>\n        {canTurn && (\n          <div className='flex items-center gap-1'>\n            <Button\n              type='button'\n              variant='ghost'\n              size='icon-sm'\n              aria-label='Previous post'\n              onClick={showPrevious}\n              className='text-muted-foreground'\n            >\n              <ChevronLeftIcon />\n            </Button>\n            <Button\n              type='button'\n              variant='ghost'\n              size='icon-sm'\n              aria-label='Next post'\n              onClick={showNext}\n              className={cn(\n                'text-muted-foreground',\n                pressedQuietOf(isNextDown)\n              )}\n            >\n              <ChevronRightIcon />\n            </Button>\n          </div>\n        )}\n      </div>\n      <span id={hintId} className='sr-only'>\n        Left and Right arrows turn the deck\n      </span>\n      <LiveRegion message={spokenUnless(isSilent, announcement)} />\n    </div>\n  );\n}\n\nconst GOAL_BARS = [\n  { id: 'export', height: '54%', isClosed: true },\n  { id: 'search', height: '78%', isClosed: true },\n  { id: 'invites', height: '46%', isClosed: true },\n  { id: 'billing', height: '92%', isClosed: true },\n  { id: 'alerts', height: '64%', isClosed: true },\n  { id: 'roles', height: '84%', isClosed: true },\n  { id: 'audit', height: '38%', isClosed: false },\n];\n\nfunction barToneOf(isClosed: boolean) {\n  if (isClosed) {\n    return 'bg-primary/75';\n  }\n  return 'bg-foreground/15';\n}\n\nfunction GoalsVisual() {\n  return (\n    <div aria-hidden='true' className='flex h-20 items-end gap-2'>\n      {GOAL_BARS.map((bar) => (\n        <span\n          key={bar.id}\n          style={{ height: bar.height }}\n          className={cn('w-4 rounded-sm', barToneOf(bar.isClosed))}\n        />\n      ))}\n    </div>\n  );\n}\n\nfunction EmptyStateVisual() {\n  return (\n    <div\n      aria-hidden='true'\n      className='bg-card hairline-ring ring-border flex w-40 flex-col items-center gap-2 rounded-md p-3'\n    >\n      <span className='bg-foreground/10 size-6 rounded-full' />\n      <span className='bg-foreground/15 h-1.5 w-24 rounded-full' />\n      <span className='bg-foreground/10 h-1.5 w-16 rounded-full' />\n      <span className='bg-primary/75 mt-1 h-4 w-14 rounded-full' />\n    </div>\n  );\n}\n\nfunction BuildVisual() {\n  return (\n    <div\n      aria-hidden='true'\n      className='flex w-full max-w-[14rem] flex-col gap-2.5 text-xs tabular-nums'\n    >\n      <div className='flex items-center gap-2'>\n        <span className='bg-foreground/15 h-3 flex-1 rounded-full' />\n        <span className='text-muted-foreground w-8'>4:00</span>\n      </div>\n      <div className='flex items-center gap-2'>\n        <span className='flex-1'>\n          <span className='bg-primary/75 block h-3 w-[38%] rounded-full' />\n        </span>\n        <span className='w-8 font-medium'>1:30</span>\n      </div>\n    </div>\n  );\n}\n\nconst STREAK_WEEKS = ['Week 43', 'Week 44', 'Week 45'];\n\nfunction StreakVisual() {\n  return (\n    <ul aria-hidden='true' className='flex flex-col gap-1.5 text-xs'>\n      {STREAK_WEEKS.map((week) => (\n        <li\n          key={week}\n          className='bg-card hairline-ring ring-border flex items-center gap-2 rounded-full py-1 ps-1.5 pe-3'\n        >\n          <span className='bg-success/15 text-success-foreground flex size-4 items-center justify-center rounded-full'>\n            <CheckIcon className='size-3' />\n          </span>\n          {week}\n        </li>\n      ))}\n    </ul>\n  );\n}\n\nconst POSTS: Post[] = [\n  {\n    id: 'sprint',\n    author: PEOPLE.amara,\n    age: '2h',\n    text: 'Sprint review done. Six of the seven goals are closed and the audit log moves to next week.',\n    visual: <GoalsVisual />,\n    likeCount: 24,\n    replies: [\n      {\n        id: 'sprint-1',\n        author: PEOPLE.jonas.name,\n        text: 'Good call to move the audit log.',\n      },\n      {\n        id: 'sprint-2',\n        author: PEOPLE.mei.name,\n        text: 'Clear notes, thank you.',\n      },\n    ],\n  },\n  {\n    id: 'empty-states',\n    author: PEOPLE.mei,\n    age: '5h',\n    text: 'The new empty states are in. Every list now says what to do next.',\n    visual: <EmptyStateVisual />,\n    likeCount: 31,\n    replies: [\n      {\n        id: 'empty-1',\n        author: PEOPLE.rafael.name,\n        text: 'Support will feel this one.',\n      },\n    ],\n  },\n  {\n    id: 'build',\n    author: PEOPLE.jonas,\n    age: '1d',\n    text: 'The build went from four minutes to ninety seconds once the icon step was cached.',\n    visual: <BuildVisual />,\n    likeCount: 47,\n    replies: [\n      {\n        id: 'build-1',\n        author: PEOPLE.amara.name,\n        text: 'That is a coffee break back, every day.',\n      },\n      {\n        id: 'build-2',\n        author: PEOPLE.ingrid.name,\n        text: 'Does it hold on a clean checkout?',\n      },\n    ],\n  },\n  {\n    id: 'replies',\n    author: PEOPLE.rafael,\n    age: '2d',\n    text: 'First replies went out in under an hour for the third week in a row.',\n    visual: <StreakVisual />,\n    likeCount: 18,\n    replies: [],\n  },\n];\n\nfunction withId(ids: string[], id: string, isIncluded: boolean) {\n  const others = ids.filter((candidate) => candidate !== id);\n  if (isIncluded) {\n    return [...others, id];\n  }\n  return others;\n}\n\nasync function copyLinkOf(post: Post) {\n  const link = `https://example.com/posts/${post.id}`;\n  await navigator.clipboard.writeText(link);\n}\n\nexport default function Card04() {\n  const [likedIds, setLikedIds] = useState<string[]>([]);\n  const [savedIds, setSavedIds] = useState<string[]>([]);\n  const deck = useRef<PostDeckHandle>(null);\n  const { pressed, press } = usePress<PostDeckPress>();\n\n  function changeLiked(postId: string, isLiked: boolean) {\n    setLikedIds((current) => withId(current, postId, isLiked));\n  }\n\n  function changeSaved(postId: string, isSaved: boolean) {\n    setSavedIds((current) => withId(current, postId, isSaved));\n  }\n\n  const steps: AutoplayStep[] = [\n    { after: 1600, run: () => press('like') },\n    { after: PRESS_LEAD_MS, run: () => deck.current?.toggleLike() },\n    { after: 1400, run: () => press('next') },\n    { after: PRESS_LEAD_MS, run: () => deck.current?.next() },\n  ];\n  const { ref, isAutoplaying } = useCardDemo(steps, {\n    loopAfter: 800,\n  });\n\n  return (\n    <div ref={ref} className='min-h-[22.25rem] w-full max-w-[21rem]'>\n      <PostDeck\n        posts={POSTS}\n        likedIds={likedIds}\n        savedIds={savedIds}\n        onLikedChange={changeLiked}\n        onSavedChange={changeSaved}\n        onShare={copyLinkOf}\n        handleRef={deck}\n        pressed={pressed}\n        isSilent={isAutoplaying}\n        note='Sample posts'\n      />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/card/card-04.tsx"
    },
    {
      "path": "registry/ndeko/components/card/_parts/deck.ts",
      "content": "'use client';\n\nimport { useCallback, useLayoutEffect, useReducer } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\n\ntype DeckDirection = 1 | -1;\n\ntype DeckState = {\n  front: number;\n  /** The card held out of the deck for a moment: the one that left the front, or the one about to come back to it. */\n  out: number | null;\n  /** The out card waits in its pose, then comes back to the front from there. */\n  isReturning: boolean;\n};\n\ntype DeckAction =\n  | { type: 'leave'; count: number }\n  | { type: 'summon'; count: number }\n  | { type: 'jump'; direction: DeckDirection; count: number }\n  | { type: 'land' };\n\nconst RESTING: DeckState = { front: 0, out: null, isReturning: false };\n\n/** An index that runs past either end of a list comes back in at the other end. */\nexport function wrapIndex(index: number, count: number) {\n  if (count <= 0) {\n    return 0;\n  }\n  const remainder = index % count;\n  const positive = remainder + count;\n  return positive % count;\n}\n\n/** How many cards sit in front of this one: 0 for the front card. */\nexport function depthOf(index: number, front: number, count: number) {\n  const behind = index - front;\n  return wrapIndex(behind, count);\n}\n\nfunction landed(deck: DeckState): DeckState {\n  if (deck.out === null) {\n    return deck;\n  }\n  if (deck.isReturning) {\n    return { front: deck.out, out: null, isReturning: false };\n  }\n  return { front: deck.front, out: null, isReturning: false };\n}\n\nfunction reduceDeck(deck: DeckState, action: DeckAction): DeckState {\n  const settled = landed(deck);\n  if (action.type === 'land') {\n    return settled;\n  }\n  if (action.type === 'jump') {\n    const stepped = settled.front + action.direction;\n    const front = wrapIndex(stepped, action.count);\n    return { front, out: null, isReturning: false };\n  }\n  if (action.type === 'leave') {\n    const stepped = settled.front + 1;\n    const front = wrapIndex(stepped, action.count);\n    return { front, out: settled.front, isReturning: false };\n  }\n  const before = settled.front - 1;\n  const out = wrapIndex(before, action.count);\n  return { front: settled.front, out, isReturning: true };\n}\n\n/**\n * A deck that turns one card at a time. Going forward, the front card is held out while the others\n * step up, then it joins the back. Going back, the last card is placed out first and comes to the\n * front from there. Each piece draws the out pose its own way: dropped, swung aside.\n */\nexport function useDeck(count: number, leaveMs: number) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [deck, dispatch] = useReducer(reduceDeck, RESTING);\n  const { schedule, clearAll } = useTimeouts();\n  const canTurn = count > 1;\n\n  useLayoutEffect(() => {\n    if (!deck.isReturning) {\n      return;\n    }\n    // A transition starts from the last pose the browser applied. Reading a layout value applies\n    // the out pose now, so the card travels from there and not from the back of the deck.\n    document.body.getBoundingClientRect();\n    const frame = requestAnimationFrame(() => dispatch({ type: 'land' }));\n    return () => cancelAnimationFrame(frame);\n  }, [deck.isReturning, deck.out]);\n\n  const next = useCallback(() => {\n    if (!canTurn) {\n      return;\n    }\n    clearAll();\n    if (shouldReduceMotion) {\n      dispatch({ type: 'jump', direction: 1, count });\n      return;\n    }\n    dispatch({ type: 'leave', count });\n    schedule(() => dispatch({ type: 'land' }), leaveMs);\n  }, [canTurn, clearAll, count, leaveMs, schedule, shouldReduceMotion]);\n\n  const previous = useCallback(() => {\n    if (!canTurn) {\n      return;\n    }\n    clearAll();\n    if (shouldReduceMotion) {\n      dispatch({ type: 'jump', direction: -1, count });\n      return;\n    }\n    dispatch({ type: 'summon', count });\n  }, [canTurn, clearAll, count, shouldReduceMotion]);\n\n  const front = wrapIndex(deck.front, count);\n\n  return {\n    front,\n    out: deck.out,\n    isReturning: deck.isReturning,\n    next,\n    previous,\n  };\n}\n",
      "type": "registry:component",
      "target": "components/card/_parts/deck.ts"
    },
    {
      "path": "registry/ndeko/components/card/_parts/keys.ts",
      "content": "/** The step an arrow key asks for along a row: -1 for Left, 1 for Right, 0 for any other key. */\nexport function sideStepOf(key: string) {\n  if (key === 'ArrowLeft') {\n    return -1;\n  }\n  if (key === 'ArrowRight') {\n    return 1;\n  }\n  return 0;\n}\n\n/** True when a press landed on a control inside a surface that also answers presses of its own. */\nexport function isOnControl(target: EventTarget) {\n  if (!(target instanceof Element)) {\n    return false;\n  }\n  return target.closest('button, a, input') !== null;\n}\n\n/** True when the keyboard brings focus into an element from outside it, not when focus moves within it. */\nexport function isKeyboardArrival(event: React.FocusEvent<HTMLElement>) {\n  const isKeyboardFocus = event.target.matches(':focus-visible');\n  const cameFromInside = event.currentTarget.contains(event.relatedTarget);\n  return isKeyboardFocus && !cameFromInside;\n}\n\n/**\n * A card that goes behind the others turns inert and would drop the focus it holds. Before a deck\n * turns from the keyboard, the group takes the focus, so the next arrow key still reaches it.\n */\nexport function holdFocusOutsideCards(group: HTMLElement) {\n  const focused = document.activeElement;\n  if (!(focused instanceof Element)) {\n    return;\n  }\n  const card = focused.closest('li');\n  if (!card) {\n    return;\n  }\n  if (group.contains(card)) {\n    group.focus();\n  }\n}\n",
      "type": "registry:component",
      "target": "components/card/_parts/keys.ts"
    },
    {
      "path": "registry/ndeko/components/card/_parts/people.ts",
      "content": "export type Person = {\n  id: string;\n  name: string;\n  role: string;\n  company: string;\n};\n\n/** The invented people of the card demos. The same person keeps the same picture on every card. */\nexport const PEOPLE = {\n  amara: {\n    id: 'amara',\n    name: 'Amara Diallo',\n    role: 'Product lead',\n    company: 'Halden Works',\n  },\n  jonas: {\n    id: 'jonas',\n    name: 'Jonas Weber',\n    role: 'Staff engineer',\n    company: 'Brightwater',\n  },\n  mei: {\n    id: 'mei',\n    name: 'Mei Tanaka',\n    role: 'Design director',\n    company: 'Kiln Studio',\n  },\n  rafael: {\n    id: 'rafael',\n    name: 'Rafael Ortega',\n    role: 'Head of support',\n    company: 'Tallyard',\n  },\n  ingrid: {\n    id: 'ingrid',\n    name: 'Ingrid Solheim',\n    role: 'Finance manager',\n    company: 'Quillhouse',\n  },\n} satisfies Record<string, Person>;\n",
      "type": "registry:component",
      "target": "components/card/_parts/people.ts"
    },
    {
      "path": "registry/ndeko/components/card/_parts/sample-note.tsx",
      "content": "import { cn } from '@/registry/ndeko/lib/utils';\n\ntype SampleNoteProps = {\n  /** What the sample is: \"Illustrative\", \"Sample quote\". */\n  children?: React.ReactNode;\n  className?: string;\n};\n\n/** The word that says the figures or the words of a demo are made up. */\nexport function SampleNote({\n  children = 'Illustrative',\n  className,\n}: SampleNoteProps) {\n  return (\n    <span className={cn('text-muted-foreground text-xs', className)}>\n      {children}\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/card/_parts/sample-note.tsx"
    },
    {
      "path": "registry/ndeko/components/card/_parts/use-card-demo.ts",
      "content": "'use client';\n\nimport {\n  useAutoplay,\n  type AutoplayOptions,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\n\n/**\n * What every card demo shares: the demonstration, and the box that keeps its tallest height so a\n * round never moves the page.\n */\nexport function useCardDemo(\n  steps: readonly AutoplayStep[],\n  options?: AutoplayOptions\n) {\n  const demo = useAutoplay(steps, options);\n  const { ref } = demo;\n\n  useKeptHeight(ref);\n\n  return demo;\n}\n",
      "type": "registry:component",
      "target": "components/card/_parts/use-card-demo.ts"
    }
  ],
  "categories": [
    "components",
    "card"
  ],
  "type": "registry:component"
}