{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "story-section",
  "title": "Story Section",
  "description": "A numbered section of a long read, with the number, heading and text set three ways and a note for what is still to be written.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/motion.json"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/story-section.tsx",
      "content": "import type * as React from \"react\"\nimport { useId, useRef } from \"react\"\nimport { motion, useInView, useReducedMotion } from \"motion/react\"\nimport { SPRING_DEFAULT } from \"@/registry/miseui/lib/motion\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype StorySectionVariant = \"stacked\" | \"aside\" | \"chapter\"\ntype StorySectionEffect = \"reveal\"\ntype StoryHeading = \"h2\" | \"h3\" | \"h4\"\n\n/** Slower than a press: a block of text arriving should be felt, not noticed. */\nconst REVEAL_TRANSITION = { ...SPRING_DEFAULT, duration: 0.6 }\nconst VIEW_MARGIN = \"0px 0px -10% 0px\"\n\nconst ROOT_CLASS: Record<StorySectionVariant, string> = {\n  stacked: \"border-t pt-8 pb-12\",\n  aside: \"border-t pt-8 pb-12\",\n  chapter: \"pt-12 pb-12\",\n}\n\n/** On a child of the root: an element cannot answer a container query about itself. Only a wide column has room for the heading to ride along. */\nconst LAYOUT_CLASS: Record<StorySectionVariant, string> = {\n  stacked: \"\",\n  aside: \"grid grid-cols-[minmax(0,1fr)] gap-4 @xl:grid-cols-[minmax(0,14rem)_minmax(0,1fr)] @xl:gap-8\",\n  chapter: \"\",\n}\n\nconst HEADER_CLASS: Record<StorySectionVariant, string> = {\n  stacked: \"grid gap-1\",\n  aside: \"grid content-start gap-1 @xl:sticky @xl:top-24 @xl:self-start\",\n  chapter: \"grid gap-2\",\n}\n\nconst NUMBER_CLASS: Record<StorySectionVariant, string> = {\n  stacked: \"font-mono text-xs leading-5 text-muted-foreground tabular-nums\",\n  aside: \"font-mono text-xs leading-5 text-muted-foreground tabular-nums\",\n  chapter: \"text-[clamp(48px,24cqi,96px)] leading-none font-semibold tracking-tight text-muted-foreground/60 tabular-nums\",\n}\n\nconst TITLE_CLASS: Record<StorySectionVariant, string> = {\n  stacked: \"text-title text-[clamp(20px,6cqi,28px)] text-pretty\",\n  aside: \"text-title text-[clamp(20px,5cqi,24px)] text-pretty\",\n  chapter: \"text-title text-[clamp(28px,9cqi,48px)] text-pretty\",\n}\n\nconst BODY_CLASS: Record<StorySectionVariant, string> = {\n  stacked: \"mt-4 min-w-0 text-[15px] leading-7\",\n  aside: \"min-w-0 text-[15px] leading-7\",\n  chapter: \"mt-6 max-w-[65ch] min-w-0 text-[15px] leading-7\",\n}\n\nfunction StoryBody({ reveal, className, children }: { reveal: boolean; className: string; children: React.ReactNode }) {\n  const ref = useRef<HTMLDivElement>(null)\n  const seen = useInView(ref, { once: true, margin: VIEW_MARGIN })\n  if (!reveal) {\n    return (\n      <div data-slot=\"story-section-body\" className={className}>\n        {children}\n      </div>\n    )\n  }\n  return (\n    <motion.div\n      ref={ref}\n      data-slot=\"story-section-body\"\n      className={className}\n      initial={{ opacity: 0, y: 16 }}\n      animate={seen ? { opacity: 1, y: 0 } : { opacity: 0, y: 16 }}\n      transition={REVEAL_TRANSITION}\n    >\n      {children}\n    </motion.div>\n  )\n}\n\ntype StorySectionProps = Omit<React.ComponentProps<\"section\">, \"title\"> & {\n  /** The section's number, zero padded when it is a number. */\n  no?: number | string\n  title: React.ReactNode\n  /** The heading level, so the outline of the page stays right. */\n  as?: StoryHeading\n  /** A note shown in a dashed box while there is no content, such as the question this section should answer. With neither, the section is left out. */\n  pending?: React.ReactNode\n  /** `stacked` number and title above the text, `aside` the heading stays beside the text on wide screens, `chapter` a large numeral opens the section. */\n  variant?: StorySectionVariant\n  /** `reveal` lets the text arrive once it comes into view. */\n  effect?: StorySectionEffect\n}\n\nfunction formatNumber(no: number | string) {\n  return typeof no === \"number\" ? String(no).padStart(2, \"0\") : no\n}\n\nfunction StorySection({ no, title, as: Heading = \"h2\", pending, variant = \"stacked\", effect, className, children, ...props }: StorySectionProps) {\n  const reduceMotion = useReducedMotion() ?? false\n  const titleId = useId()\n  const hasContent = children !== undefined && children !== null && children !== false\n  if (!hasContent && !pending) return null\n  return (\n    <section aria-labelledby={titleId} data-slot=\"story-section\" data-variant={variant} data-effect={effect} className={cn(\"@container w-full min-w-0 scroll-mt-24\", ROOT_CLASS[variant], className)} {...props}>\n      <div data-slot=\"story-section-layout\" className={LAYOUT_CLASS[variant]}>\n        <header data-slot=\"story-section-header\" className={HEADER_CLASS[variant]}>\n          {no === undefined ? null : <p data-slot=\"story-section-number\" className={NUMBER_CLASS[variant]}>{formatNumber(no)}</p>}\n          <Heading id={titleId} className={TITLE_CLASS[variant]}>\n            {title}\n          </Heading>\n        </header>\n        <StoryBody reveal={effect === \"reveal\" && !reduceMotion} className={BODY_CLASS[variant]}>\n          {hasContent ? children : <p data-slot=\"story-section-pending\" className=\"rounded-lg border border-dashed p-4 text-[13px] leading-5 text-muted-foreground\">{pending}</p>}\n        </StoryBody>\n      </div>\n    </section>\n  )\n}\n\nexport { StorySection, type StorySectionProps, type StorySectionVariant, type StorySectionEffect }\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "display"
  ],
  "type": "registry:ui"
}