{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pricing-05",
  "title": "Plan card with a pattern",
  "description": "One plan on a solid panel inside a tray of hairline zigzags that drift while it is on screen, with a billing switch whose price rolls its digits to the yearly figure.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-autoplay.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/wash.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/pricing/pricing-05/index.tsx",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll } from '@/components/core/word-roll';\nimport {\n  type AutoplayStep,\n  useAutoplay,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { type Segment, Segments } from '@/registry/ndeko/ui/segments';\nimport { Wash } from '@/registry/ndeko/ui/wash';\n\nimport { type BillingPeriod, PLAN, SECTION } from './data';\nimport { PatternFrame, type PatternKind } from './pattern-frame';\n\nconst MONTHS_PER_YEAR = 12;\n\nconst PERIODS: Segment<BillingPeriod>[] = [\n  { value: 'monthly', label: 'Monthly' },\n  { value: 'yearly', label: 'Yearly' },\n];\n\nconst PERIOD_ORDER: Record<BillingPeriod, number> = {\n  monthly: 0,\n  yearly: 1,\n};\n\nconst PRICE_FORMAT: Intl.NumberFormatOptions = {\n  style: 'currency',\n  currency: 'USD',\n  maximumFractionDigits: 0,\n};\n\nconst PRICE_FORMATTER = new Intl.NumberFormat('en-US', PRICE_FORMAT);\n\nconst LOOP_AFTER_MS = 2000;\n\nconst NO_STEPS: AutoplayStep[] = [];\n\nfunction monthlyFigureOf(period: BillingPeriod) {\n  if (period === 'yearly') {\n    return PLAN.yearlyPrice / MONTHS_PER_YEAR;\n  }\n  return PLAN.monthlyPrice;\n}\n\nfunction billingNoteOf(period: BillingPeriod) {\n  if (period === 'yearly') {\n    const total = PRICE_FORMATTER.format(PLAN.yearlyPrice);\n    return `Billed ${total} once a year`;\n  }\n  return 'Billed every month';\n}\n\n/** Without a switch the drift of the pattern is all the plan has to show. */\nfunction stepsOf(hasBillingSwitch: boolean, switchSteps: AutoplayStep[]) {\n  if (hasBillingSwitch) {\n    return switchSteps;\n  }\n  return NO_STEPS;\n}\n\n/** An empty script that loops would wake the piece for nothing at every round. */\nfunction loopAfterOf(hasBillingSwitch: boolean) {\n  if (hasBillingSwitch) {\n    return LOOP_AFTER_MS;\n  }\n  return undefined;\n}\n\nfunction announcementOf(period: BillingPeriod) {\n  const figure = monthlyFigureOf(period);\n  const price = PRICE_FORMATTER.format(figure);\n  const note = billingNoteOf(period);\n  return `${price} a month. ${note}.`;\n}\n\nexport type Pricing05Props = {\n  /** The hairline pattern drawn around the plan. */\n  pattern?: PatternKind;\n  /** Without it the plan shows its monthly price only. */\n  hasBillingSwitch?: boolean;\n};\n\nexport default function Pricing05({\n  pattern = 'zigzag',\n  hasBillingSwitch = true,\n}: Pricing05Props) {\n  const [period, setPeriod] = useState<BillingPeriod>('monthly');\n  const [announcement, setAnnouncement] = useState('');\n  const figure = monthlyFigureOf(period);\n  const note = billingNoteOf(period);\n  const periodOrder = PERIOD_ORDER[period];\n\n  /** Only a person's choice is said: the demonstration moves the same switch in silence. */\n  function changePeriod(next: BillingPeriod) {\n    setPeriod(next);\n    setAnnouncement(announcementOf(next));\n  }\n\n  function startOver() {\n    setPeriod('monthly');\n  }\n\n  const switchSteps: AutoplayStep[] = [\n    { after: 2600, run: () => setPeriod('yearly') },\n    { after: 3400, run: () => setPeriod('monthly') },\n  ];\n  const steps = stepsOf(hasBillingSwitch, switchSteps);\n  const loopAfter = loopAfterOf(hasBillingSwitch);\n  const { ref } = useAutoplay<HTMLDivElement>(steps, {\n    loopAfter,\n    onReset: startOver,\n  });\n\n  return (\n    <section className='@container'>\n      <div\n        ref={ref}\n        className='mx-auto flex max-w-5xl flex-col items-center gap-10 px-4 py-16 @2xl:px-6 @2xl:py-24'\n      >\n        <div className='flex max-w-xl flex-col items-center gap-3 text-center'>\n          <h2 className='text-2xl font-semibold text-balance @2xl:text-3xl'>\n            {SECTION.title}\n          </h2>\n          <p className='text-muted-foreground text-base text-pretty'>\n            {SECTION.description}\n          </p>\n        </div>\n        <PatternFrame pattern={pattern} className='w-full max-w-xl'>\n          <article className='surface-brand relative isolate flex flex-col gap-6 rounded-xl p-6 @md:p-7'>\n            <Wash />\n            <div className='flex items-center gap-3'>\n              <CompanyMark seed={PLAN.product} size='lg' />\n              <div className='flex min-w-0 flex-col gap-0.5'>\n                <h3 className='text-sm font-medium'>{PLAN.product}</h3>\n                <p className='text-muted-foreground text-xs text-pretty'>\n                  {PLAN.description}\n                </p>\n              </div>\n            </div>\n            {hasBillingSwitch && (\n              <div className='flex flex-wrap items-center gap-2'>\n                <Segments\n                  value={period}\n                  segments={PERIODS}\n                  onValueChange={changePeriod}\n                  label='Billing period'\n                />\n                <Badge variant='secondary'>{PLAN.yearlyNote}</Badge>\n              </div>\n            )}\n            <div className='flex flex-col gap-1'>\n              <p className='flex items-baseline gap-1.5'>\n                <MotionNumber\n                  value={figure}\n                  format={PRICE_FORMAT}\n                  className='text-5xl font-semibold'\n                />\n                <span className='text-muted-foreground text-[13px]'>\n                  per month\n                </span>\n              </p>\n              <p className='text-muted-foreground text-xs tabular-nums'>\n                <WordRoll text={note} value={periodOrder} />\n              </p>\n            </div>\n            <Button size='lg' nativeButton={false} render={<a href='#' />}>\n              {PLAN.action}\n            </Button>\n            <ul className='flex flex-col gap-2.5 text-[13px]'>\n              {PLAN.features.map((feature) => (\n                <li key={feature} className='flex items-center gap-2.5'>\n                  <span\n                    aria-hidden='true'\n                    className='bg-foreground/25 size-1 shrink-0 rounded-full'\n                  />\n                  {feature}\n                </li>\n              ))}\n            </ul>\n            <p className='text-muted-foreground text-xs text-pretty'>\n              {PLAN.trial}\n            </p>\n          </article>\n        </PatternFrame>\n        <p className='text-muted-foreground text-center text-xs'>\n          {SECTION.footnote}\n        </p>\n      </div>\n      <LiveRegion message={announcement} />\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/pricing-05/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/pricing/pricing-05/pattern-frame.tsx",
      "content": "'use client';\n\nimport { useInView } from 'motion/react';\nimport {\n  type CSSProperties,\n  type ReactNode,\n  type RefObject,\n  useEffect,\n  useId,\n  useRef,\n} from 'react';\n\nimport { useDocumentVisible } from '@/registry/ndeko/hooks/use-agent-run';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nexport type PatternKind = 'zigzag' | 'stripes' | 'grid' | 'dots';\n\ntype PatternTile = {\n  width: number;\n  height: number;\n  /** One whole tile in the direction of the drift, so each loop ends exactly where it began. */\n  driftX: number;\n  driftY: number;\n  shape: ReactNode;\n};\n\n/** The time the pattern takes to drift by one tile, slow enough to read as a texture. */\nconst DRIFT_MS = 3200;\n\nconst UNSAFE_ID_CHARACTERS = /[^a-zA-Z0-9_-]/g;\n\nconst HAIRLINE: CSSProperties = { strokeWidth: 'var(--hairline, 1px)' };\n\nconst TILES: Record<PatternKind, PatternTile> = {\n  zigzag: {\n    width: 16,\n    height: 10,\n    driftX: 16,\n    driftY: 0,\n    shape: (\n      <path\n        d='M0 7.5 4 2.5 8 7.5 12 2.5 16 7.5'\n        fill='none'\n        stroke='currentColor'\n        strokeLinejoin='round'\n        style={HAIRLINE}\n      />\n    ),\n  },\n  stripes: {\n    width: 10,\n    height: 10,\n    driftX: 10,\n    driftY: 0,\n    shape: (\n      <path\n        d='M-2.5 2.5 2.5-2.5M0 10 10 0M7.5 12.5 12.5 7.5'\n        fill='none'\n        stroke='currentColor'\n        style={HAIRLINE}\n      />\n    ),\n  },\n  grid: {\n    width: 16,\n    height: 16,\n    driftX: 16,\n    driftY: 16,\n    shape: (\n      <path\n        d='M16 0H0V16'\n        fill='none'\n        stroke='currentColor'\n        shapeRendering='crispEdges'\n        style={HAIRLINE}\n      />\n    ),\n  },\n  dots: {\n    width: 12,\n    height: 12,\n    driftX: 12,\n    driftY: 12,\n    shape: <circle cx='6' cy='6' r='1' fill='currentColor' />,\n  },\n};\n\nfunction driftFramesOf(tile: PatternTile): Keyframe[] {\n  return [\n    { transform: 'translate(0px, 0px)' },\n    { transform: `translate(${tile.driftX}px, ${tile.driftY}px)` },\n  ];\n}\n\n/** The layer reaches one tile past the top and left edges, so the drift never uncovers a corner. */\nfunction layerStyleOf(tile: PatternTile): CSSProperties {\n  const top = -tile.driftY;\n  const left = -tile.driftX;\n  return { top, left, right: 0, bottom: 0 };\n}\n\n/**\n * One Web Animation on the transform of the layer, made once and only paused or played: it runs\n * on the compositor while the frame is on screen and stays where it stopped when it leaves.\n */\nfunction useDrift(\n  layerRef: RefObject<HTMLDivElement | null>,\n  tile: PatternTile,\n  isDrifting: boolean,\n  shouldReduceMotion: boolean\n) {\n  const animationRef = useRef<Animation | null>(null);\n\n  useEffect(() => {\n    const layer = layerRef.current;\n    if (!layer) {\n      return;\n    }\n    if (shouldReduceMotion) {\n      return;\n    }\n    const frames = driftFramesOf(tile);\n    const animation = layer.animate(frames, {\n      duration: DRIFT_MS,\n      iterations: Infinity,\n      easing: 'linear',\n    });\n    animation.pause();\n    animationRef.current = animation;\n    return () => {\n      animation.cancel();\n      animationRef.current = null;\n    };\n  }, [layerRef, tile, shouldReduceMotion]);\n\n  useEffect(() => {\n    const animation = animationRef.current;\n    if (!animation) {\n      return;\n    }\n    if (isDrifting) {\n      animation.play();\n      return;\n    }\n    animation.pause();\n  }, [isDrifting, tile, shouldReduceMotion]);\n}\n\ntype PatternFrameProps = {\n  pattern: PatternKind;\n  className?: string;\n  children: ReactNode;\n};\n\n/**\n * A tray drawn with a pattern of hairlines around a solid panel. The pattern drifts while the\n * tray is on screen, stops off screen and in a hidden tab, and stays still under reduced motion.\n */\nexport function PatternFrame({\n  pattern,\n  className,\n  children,\n}: PatternFrameProps) {\n  const frameRef = useRef<HTMLDivElement>(null);\n  const layerRef = useRef<HTMLDivElement>(null);\n  const rawId = useId();\n  const isInView = useInView(frameRef, { amount: 0.2 });\n  const isVisible = useDocumentVisible();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const safeId = rawId.replace(UNSAFE_ID_CHARACTERS, '');\n  const patternId = `pattern-${safeId}`;\n  const tile = TILES[pattern];\n  const layerStyle = layerStyleOf(tile);\n  const isDrifting = isInView && isVisible;\n\n  useDrift(layerRef, tile, isDrifting, shouldReduceMotion);\n\n  return (\n    <div\n      ref={frameRef}\n      className={cn(\n        'bg-foreground/[0.02] relative isolate overflow-hidden rounded-2xl p-5 @md:p-10',\n        className\n      )}\n    >\n      <div\n        aria-hidden='true'\n        className='pointer-events-none absolute inset-0 -z-10'\n      >\n        <div ref={layerRef} style={layerStyle} className='absolute'>\n          <svg className='text-border size-full'>\n            <defs>\n              <pattern\n                id={patternId}\n                width={tile.width}\n                height={tile.height}\n                patternUnits='userSpaceOnUse'\n              >\n                {tile.shape}\n              </pattern>\n            </defs>\n            <rect width='100%' height='100%' fill={`url(#${patternId})`} />\n          </svg>\n        </div>\n      </div>\n      {children}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/pricing-05/pattern-frame.tsx"
    },
    {
      "path": "registry/ndeko/blocks/pricing/pricing-05/data.ts",
      "content": "export type BillingPeriod = 'monthly' | 'yearly';\n\nexport const PLAN = {\n  product: 'Inkpond',\n  description: 'Everything Inkpond does, on every device you write on',\n  monthlyPrice: 12,\n  yearlyPrice: 120,\n  yearlyNote: 'Two months free',\n  features: [\n    'Unlimited documents and notebooks',\n    'Sync on Mac, Windows, iPhone and Android',\n    'Every version kept for a year',\n    'Export to PDF, EPUB and Markdown',\n    'Shared notebooks with up to three people',\n  ],\n  action: 'Start writing',\n  trial: '14 days free, cancel from your account at any time',\n};\n\nexport const SECTION = {\n  title: 'One plan with every part of Inkpond',\n  description:\n    'Write on any device, keep every version and export when the draft is done. Pay each month, or once a year for two months free.',\n  footnote:\n    'Illustrative prices in US dollars for an example app, taxes added at checkout',\n};\n",
      "type": "registry:component",
      "target": "components/blocks/pricing-05/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "pricing"
  ],
  "type": "registry:block"
}