{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pricing-04",
  "title": "Pricing in one sentence",
  "description": "A sentence whose number you type or drag sideways, over a log track notched wherever the cheapest plan changes: the cheapest of three plans lifts out of the row as the volume crosses a notch, while every price rolls with the hand.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chip.json",
    "https://ui.ndekocode.dev/r/demonstration.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/slider.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/utils.json",
    "https://ui.ndekocode.dev/r/wash.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/pricing/pricing-04/index.tsx",
      "content": "'use client';\n\nimport { useId, useState } from 'react';\n\nimport {\n  type AutoplayStep,\n  typingSteps,\n  useAutoplay,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { keyDelayOf, spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { MAX_VOLUME, type Plan, PLANS, SECTION, START_VOLUME } from './data';\nimport { PlanCard } from './plan-card';\nimport {\n  cheapestPlanAt,\n  clampVolume,\n  positionOf,\n  volumeAt,\n  volumeOfText,\n} from './volume-model';\nimport { VolumeSentence } from './volume-sentence';\nimport { VolumeTrack } from './volume-track';\n\n/** Where the demonstration drags the volume: past the notch where Scale becomes the cheapest. */\nconst DEMO_SCRUB_TO = 200_000;\n\n/** What the demonstration then types, back in the stretch where Hobby is the cheapest. */\nconst DEMO_TYPED = '4500';\n\n/** The pause between two stops when the demonstration drags the number. */\nconst SCRUB_STEP_MS = 130;\n\nconst LOOP_AFTER_MS = 3000;\n\n/** A drag of the demonstration from stop to stop, through the same handler a hand uses. */\nfunction scrubSteps(\n  from: number,\n  to: number,\n  write: (volume: number) => void,\n  startAfter: number\n): AutoplayStep[] {\n  const firstPosition = Math.round(positionOf(from));\n  const lastPosition = Math.round(positionOf(to));\n  const distance = lastPosition - firstPosition;\n  const direction = Math.sign(distance);\n  const count = Math.abs(distance);\n  const indexes = Array.from({ length: count }, (_, index) => index);\n  return indexes.map((index) => {\n    const walked = index + 1;\n    const offset = walked * direction;\n    const position = firstPosition + offset;\n    const volume = volumeAt(position);\n    const after = keyDelayOf(index, startAfter, SCRUB_STEP_MS);\n    return { after, run: () => write(volume) };\n  });\n}\n\nfunction announcementOf(cheapest: Plan, isOverLimit: boolean) {\n  if (isOverLimit) {\n    return SECTION.over;\n  }\n  return `${cheapest.name} is the cheapest plan at this volume.`;\n}\n\nexport default function Pricing04() {\n  const [volume, setVolume] = useState(START_VOLUME);\n  const [draft, setDraft] = useState<string | null>(null);\n  const [isOverLimit, setIsOverLimit] = useState(false);\n  const [isDemoScrubbing, setIsDemoScrubbing] = useState(false);\n  const hintId = useId();\n  const cheapest = cheapestPlanAt(volume);\n\n  function type(text: string) {\n    setDraft(text);\n    const typed = volumeOfText(text);\n    if (typed === null) {\n      setIsOverLimit(false);\n      return;\n    }\n    const isOver = typed > MAX_VOLUME;\n    const next = clampVolume(typed);\n    setVolume(next);\n    setIsOverLimit(isOver);\n  }\n\n  function commit() {\n    setDraft(null);\n  }\n\n  function scrubTo(next: number) {\n    setVolume(next);\n    setDraft(null);\n    setIsOverLimit(false);\n  }\n\n  function startOver() {\n    setVolume(START_VOLUME);\n    setDraft(null);\n    setIsOverLimit(false);\n    setIsDemoScrubbing(false);\n  }\n\n  const steps: AutoplayStep[] = [\n    { after: 1300, run: () => setIsDemoScrubbing(true) },\n    ...scrubSteps(START_VOLUME, DEMO_SCRUB_TO, scrubTo, 180),\n    { after: 260, run: () => setIsDemoScrubbing(false) },\n    { after: 1800, run: () => type('') },\n    ...typingSteps(DEMO_TYPED, type, { startAfter: 420, characterMs: 170 }),\n    { after: 600, run: commit },\n  ];\n  const { ref, isAutoplaying } = useAutoplay(steps, {\n    loopAfter: LOOP_AFTER_MS,\n    onReset: startOver,\n  });\n  /** A person who takes over in the middle of the drag lets go of the number. */\n  const showsDemoScrub = isDemoScrubbing && isAutoplaying;\n  const announcement = announcementOf(cheapest, isOverLimit);\n  const message = spokenUnless(isAutoplaying, announcement);\n\n  useKeptHeight(ref);\n\n  return (\n    <section className='@container'>\n      <div\n        ref={ref}\n        className='mx-auto flex min-h-[44rem] max-w-5xl flex-col gap-10 px-4 py-16 @2xl:gap-12 @2xl:px-6 @2xl:py-24'\n      >\n        <div className='flex flex-col gap-6'>\n          <div className='flex max-w-2xl flex-col gap-3'>\n            <h2 className='text-primary-ink text-sm font-medium'>\n              {SECTION.title}\n            </h2>\n            <p className='text-muted-foreground text-base text-pretty'>\n              {SECTION.description}\n            </p>\n          </div>\n          <VolumeSentence\n            volume={volume}\n            draft={draft}\n            isOverLimit={isOverLimit}\n            isDemoScrubbing={showsDemoScrub}\n            hintId={hintId}\n            onType={type}\n            onCommit={commit}\n            onScrub={scrubTo}\n          />\n          <VolumeTrack\n            volume={volume}\n            cheapest={cheapest}\n            onVolumeChange={scrubTo}\n          />\n        </div>\n        <div className='grid gap-4 @3xl:grid-cols-3'>\n          {PLANS.map((plan) => (\n            <PlanCard\n              key={plan.id}\n              plan={plan}\n              volume={volume}\n              isCheapest={plan === cheapest}\n            />\n          ))}\n        </div>\n        <p className='text-muted-foreground text-xs'>{SECTION.footnote}</p>\n      </div>\n      <LiveRegion message={message} />\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/pricing-04/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/pricing/pricing-04/volume-sentence.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useRef, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { rowPresenceOf } from '@/registry/ndeko/lib/motion-presets';\n\nimport { SECTION } from './data';\nimport {\n  formatVolume,\n  positionOf,\n  stopAbove,\n  stopBelow,\n  volumeAt,\n} from './volume-model';\n\n/** How far the pointer travels to reach the next stop when it drags the number. */\nconst PX_PER_STOP = 8;\n\n/** Under this distance a press on the number is a click, and the click opens it for typing. */\nconst DRAG_THRESHOLD_PX = 4;\n\n/** Room for \"10,000,000\" and one key more: a longer entry would push the sentence past the width of a phone. */\nconst MAX_TYPED_CHARACTERS = 11;\n\ntype DragStart = {\n  x: number;\n  position: number;\n};\n\nfunction describedByOf(isOverLimit: boolean, hintId: string) {\n  if (isOverLimit) {\n    return hintId;\n  }\n  return undefined;\n}\n\nfunction scrubbingOf(isScrubbing: boolean) {\n  if (isScrubbing) {\n    return 'true';\n  }\n  return undefined;\n}\n\nfunction isPrimaryPress(event: React.PointerEvent<HTMLInputElement>) {\n  return event.button === 0;\n}\n\n/** A press let go outside the number never reaches its pointerup: the next move finds no button down. */\nfunction isReleased(event: React.PointerEvent<HTMLInputElement>) {\n  return event.buttons === 0;\n}\n\nfunction isFocused(element: HTMLElement) {\n  return document.activeElement === element;\n}\n\n/** A press on the number while it is not being typed in may become a drag: no caret, no focus yet. */\nfunction keepFocusAway(event: React.MouseEvent<HTMLInputElement>) {\n  if (isFocused(event.currentTarget)) {\n    return;\n  }\n  event.preventDefault();\n}\n\ntype VolumeSentenceProps = {\n  volume: number;\n  /** What is typed in the number, while a person or the demonstration types; null shows the volume. */\n  draft: string | null;\n  isOverLimit: boolean;\n  /** The demonstration drags the number: it wears the look of a hand on it. */\n  isDemoScrubbing: boolean;\n  hintId: string;\n  onType: (text: string) => void;\n  onCommit: () => void;\n  onScrub: (volume: number) => void;\n};\n\n/**\n * \"I expect 12,000 requests a month\". The number is a field: drag it sideways to scrub through the\n * stops, click it to type, Up and Down step from stop to stop, Escape puts back what was there.\n * The field takes the width of a hidden copy of its text, so it is given no width of its own.\n */\nexport function VolumeSentence({\n  volume,\n  draft,\n  isOverLimit,\n  isDemoScrubbing,\n  hintId,\n  onType,\n  onCommit,\n  onScrub,\n}: VolumeSentenceProps) {\n  const [isScrubbing, setIsScrubbing] = useState(false);\n  const dragStart = useRef<DragStart | null>(null);\n  const hasDragged = useRef(false);\n  const volumeAtFocus = useRef(volume);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const presence = rowPresenceOf(shouldReduceMotion);\n  const formatted = formatVolume(volume);\n  const shownText = draft ?? formatted;\n  const isHandOnNumber = isScrubbing || isDemoScrubbing;\n\n  function startDrag(event: React.PointerEvent<HTMLInputElement>) {\n    if (!isPrimaryPress(event)) {\n      return;\n    }\n    if (isFocused(event.currentTarget)) {\n      return;\n    }\n    const position = positionOf(volume);\n    dragStart.current = { x: event.clientX, position };\n    hasDragged.current = false;\n  }\n\n  function drag(event: React.PointerEvent<HTMLInputElement>) {\n    const start = dragStart.current;\n    if (!start) {\n      return;\n    }\n    if (isReleased(event)) {\n      cancelDrag();\n      return;\n    }\n    const travelled = event.clientX - start.x;\n    const distance = Math.abs(travelled);\n    const isStillAClick = !hasDragged.current && distance < DRAG_THRESHOLD_PX;\n    if (isStillAClick) {\n      return;\n    }\n    if (!hasDragged.current) {\n      hasDragged.current = true;\n      event.currentTarget.setPointerCapture(event.pointerId);\n      setIsScrubbing(true);\n    }\n    const stops = travelled / PX_PER_STOP;\n    const position = start.position + stops;\n    const next = volumeAt(position);\n    if (next !== volume) {\n      onScrub(next);\n    }\n  }\n\n  function endDrag(event: React.PointerEvent<HTMLInputElement>) {\n    const start = dragStart.current;\n    dragStart.current = null;\n    if (!start) {\n      return;\n    }\n    if (hasDragged.current) {\n      setIsScrubbing(false);\n      return;\n    }\n    const input = event.currentTarget;\n    input.focus();\n    input.select();\n  }\n\n  function cancelDrag() {\n    dragStart.current = null;\n    setIsScrubbing(false);\n  }\n\n  function rememberVolume(event: React.FocusEvent<HTMLInputElement>) {\n    volumeAtFocus.current = volume;\n    event.currentTarget.select();\n  }\n\n  function type(event: React.ChangeEvent<HTMLInputElement>) {\n    onType(event.currentTarget.value);\n  }\n\n  function pressKey(event: React.KeyboardEvent<HTMLInputElement>) {\n    if (event.key === 'ArrowUp') {\n      event.preventDefault();\n      onScrub(stopAbove(volume));\n      return;\n    }\n    if (event.key === 'ArrowDown') {\n      event.preventDefault();\n      onScrub(stopBelow(volume));\n      return;\n    }\n    if (event.key === 'Enter') {\n      event.preventDefault();\n      onCommit();\n      return;\n    }\n    if (event.key === 'Escape') {\n      event.preventDefault();\n      onScrub(volumeAtFocus.current);\n      onCommit();\n    }\n  }\n\n  return (\n    <div className='flex flex-col'>\n      <p className='text-3xl leading-tight font-semibold text-balance @2xl:text-4xl @4xl:text-5xl'>\n        I expect{' '}\n        <span className='relative inline-grid align-baseline'>\n          <span\n            aria-hidden='true'\n            className='invisible col-start-1 row-start-1 px-2 whitespace-pre tabular-nums'\n          >\n            {shownText}\n          </span>\n          <input\n            type='text'\n            size={1}\n            maxLength={MAX_TYPED_CHARACTERS}\n            inputMode='numeric'\n            autoComplete='off'\n            spellCheck={false}\n            aria-label='Requests you expect each month'\n            aria-describedby={describedByOf(isOverLimit, hintId)}\n            data-scrubbing={scrubbingOf(isHandOnNumber)}\n            value={shownText}\n            onChange={type}\n            onFocus={rememberVolume}\n            onBlur={onCommit}\n            onKeyDown={pressKey}\n            onMouseDown={keepFocusAway}\n            onPointerDown={startDrag}\n            onPointerMove={drag}\n            onPointerUp={endDrag}\n            onPointerCancel={cancelDrag}\n            className='bg-primary/10 text-primary-ink hover:bg-primary/15 focus-visible:ring-ring/25 data-scrubbing:bg-primary/20 col-start-1 row-start-1 w-full min-w-0 cursor-ew-resize touch-pan-y rounded-xl px-2 tabular-nums transition-[background-color,box-shadow] duration-150 outline-none focus:cursor-text focus-visible:ring-[3px]'\n          />\n        </span>{' '}\n        requests a month\n      </p>\n      <AnimatePresence initial={false}>\n        {isOverLimit && (\n          <motion.p\n            key='over'\n            id={hintId}\n            {...presence}\n            className='text-warning-foreground overflow-hidden text-[13px] text-pretty'\n          >\n            <span className='block pt-3'>{SECTION.over}</span>\n          </motion.p>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/pricing-04/volume-sentence.tsx"
    },
    {
      "path": "registry/ndeko/blocks/pricing/pricing-04/volume-track.tsx",
      "content": "'use client';\n\nimport type { CSSProperties } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Slider } from '@/registry/ndeko/ui/slider';\n\nimport type { Plan } from './data';\nimport {\n  formatVolume,\n  LAST_POSITION,\n  NOTCHES,\n  positionOf,\n  shareOf,\n  volumeAt,\n  type Zone,\n  ZONES,\n} from './volume-model';\n\nconst ZONE_INK =\n  'text-muted-foreground transition-colors duration-200 data-current:text-foreground data-current:font-medium';\n\nfunction amountOf(value: number | readonly number[]) {\n  if (typeof value === 'number') {\n    return value;\n  }\n  return value[0];\n}\n\n/** A zero-width anchor moved by a share of the row: it never widens the page. */\nfunction anchorStyleOf(share: number): CSSProperties {\n  const percent = share * 100;\n  return { transform: `translateX(${percent}cqw)` };\n}\n\nfunction zoneCenterOf(zone: Zone) {\n  const sum = zone.from + zone.to;\n  const middle = sum / 2;\n  return shareOf(middle);\n}\n\nfunction currentOf(isCurrent: boolean) {\n  if (isCurrent) {\n    return '';\n  }\n  return undefined;\n}\n\n/** Notches drawn across the track where another plan becomes the cheapest; the track paints over their middle. */\nfunction TrackNotches() {\n  return (\n    <div\n      aria-hidden='true'\n      className='@container pointer-events-none absolute inset-x-0 top-1/2 h-3 -translate-y-1/2'\n    >\n      {NOTCHES.map((notch) => {\n        const share = shareOf(notch.position);\n        return (\n          <span\n            key={notch.volume}\n            style={anchorStyleOf(share)}\n            className='absolute inset-y-0 left-0 w-0'\n          >\n            <span className='bg-foreground/35 absolute inset-y-0 left-0 w-px -translate-x-1/2' />\n          </span>\n        );\n      })}\n    </div>\n  );\n}\n\nfunction ZoneNames({ cheapest }: { cheapest: Plan }) {\n  return (\n    <div aria-hidden='true' className='@container relative h-5'>\n      {ZONES.map((zone) => {\n        const center = zoneCenterOf(zone);\n        const isCurrent = zone.plan === cheapest;\n        return (\n          <span\n            key={zone.from}\n            style={anchorStyleOf(center)}\n            className='absolute top-0 left-0 w-0'\n          >\n            <span\n              data-current={currentOf(isCurrent)}\n              className={cn(\n                'absolute top-0 left-0 -translate-x-1/2 text-xs whitespace-nowrap',\n                ZONE_INK\n              )}\n            >\n              {zone.plan.name}\n            </span>\n          </span>\n        );\n      })}\n    </div>\n  );\n}\n\ntype VolumeTrackProps = {\n  volume: number;\n  cheapest: Plan;\n  onVolumeChange: (volume: number) => void;\n};\n\n/** The same volume on a log track, with a notch wherever the cheapest plan changes and the plan named on each stretch. */\nexport function VolumeTrack({\n  volume,\n  cheapest,\n  onVolumeChange,\n}: VolumeTrackProps) {\n  const position = positionOf(volume);\n  const spokenVolume = formatVolume(volume);\n\n  function change(value: number | readonly number[]) {\n    const nextPosition = amountOf(value);\n    const next = volumeAt(nextPosition);\n    onVolumeChange(next);\n  }\n\n  function spokenValueOf() {\n    return `${spokenVolume} requests a month, ${cheapest.name} is the cheapest`;\n  }\n\n  return (\n    <div className='flex flex-col gap-1.5'>\n      <div className='relative'>\n        <TrackNotches />\n        <Slider\n          value={position}\n          min={0}\n          max={LAST_POSITION}\n          step={1}\n          thumbLabels={['Requests a month']}\n          getAriaValueText={spokenValueOf}\n          onValueChange={change}\n        />\n      </div>\n      <ZoneNames cheapest={cheapest} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/pricing-04/volume-track.tsx"
    },
    {
      "path": "registry/ndeko/blocks/pricing/pricing-04/plan-card.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { EASE_OUT_STRONG } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Chip } from '@/registry/ndeko/ui/chip';\nimport { Wash } from '@/registry/ndeko/ui/wash';\n\nimport type { Plan } from './data';\nimport {\n  costOf,\n  formatPrice,\n  formatRate,\n  formatVolume,\n  PRICE_FORMAT,\n} from './volume-model';\n\nconst RESTING_SURFACE =\n  'bg-card hairline-ring ring-border shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:bg-foreground/[0.03]';\n\nconst LIFTED_SURFACE = 'surface-brand -translate-y-1';\n\nconst CHIP_SHOWN = { opacity: 1, scale: 1 };\n\nconst CHIP_HIDDEN = { opacity: 0, scale: 0.95 };\n\nconst CHIP_FADE = { opacity: 0 };\n\nconst CHIP_TRANSITION: Transition = { duration: 0.18, ease: EASE_OUT_STRONG };\n\nfunction surfaceOf(isCheapest: boolean) {\n  if (isCheapest) {\n    return LIFTED_SURFACE;\n  }\n  return RESTING_SURFACE;\n}\n\nfunction actionVariantOf(isCheapest: boolean) {\n  if (isCheapest) {\n    return 'default' as const;\n  }\n  return 'outline' as const;\n}\n\nfunction chipHiddenOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return CHIP_FADE;\n  }\n  return CHIP_HIDDEN;\n}\n\ntype PlanCardProps = {\n  plan: Plan;\n  volume: number;\n  isCheapest: boolean;\n};\n\n/** One plan priced for the volume of the sentence; the cheapest one lifts out of the row. */\nexport function PlanCard({ plan, volume, isCheapest }: PlanCardProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const cost = costOf(plan, volume);\n  const price = Math.round(cost);\n  const basePrice = formatPrice(plan.basePrice);\n  const included = formatVolume(plan.includedRequests);\n  const rate = formatRate(plan.pricePerThousand);\n  const chipHidden = chipHiddenOf(shouldReduceMotion);\n\n  return (\n    <article\n      className={cn(\n        'relative isolate flex flex-col gap-5 rounded-xl p-5 transition-[translate,box-shadow] duration-300 ease-(--ease-out-strong)',\n        surfaceOf(isCheapest)\n      )}\n    >\n      <Wash isShown={isCheapest} />\n      <div className='flex flex-col gap-1'>\n        <div className='flex min-h-5 items-center justify-between gap-2'>\n          <h3 className='text-sm font-medium'>{plan.name}</h3>\n          <AnimatePresence initial={false}>\n            {isCheapest && (\n              <motion.span\n                key='cheapest'\n                initial={chipHidden}\n                animate={CHIP_SHOWN}\n                exit={chipHidden}\n                transition={CHIP_TRANSITION}\n                className='inline-flex'\n              >\n                <Chip>Cheapest for you</Chip>\n              </motion.span>\n            )}\n          </AnimatePresence>\n        </div>\n        <p className='text-muted-foreground text-[13px] text-pretty'>\n          {plan.summary}\n        </p>\n      </div>\n      <p className='flex items-baseline gap-1.5'>\n        <MotionNumber\n          value={price}\n          format={PRICE_FORMAT}\n          className='text-4xl font-semibold'\n        />\n        <span className='text-muted-foreground text-[13px]'>a month</span>\n      </p>\n      <ul className='text-muted-foreground flex flex-col gap-1 text-xs tabular-nums'>\n        <li>{basePrice} base price</li>\n        <li>{included} requests included</li>\n        <li>{rate} per 1,000 after that</li>\n      </ul>\n      <Button\n        size='lg'\n        variant={actionVariantOf(isCheapest)}\n        nativeButton={false}\n        render={<a href='#' />}\n        className='mt-auto'\n      >\n        {plan.action}\n      </Button>\n    </article>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/pricing-04/plan-card.tsx"
    },
    {
      "path": "registry/ndeko/blocks/pricing/pricing-04/volume-model.ts",
      "content": "import { MAX_VOLUME, type Plan, PLANS, STOPS } from './data';\n\n/** A place on the track where another plan becomes the cheapest. */\nexport type Notch = {\n  volume: number;\n  position: number;\n  plan: Plan;\n};\n\n/** The stretch of the track where one plan is the cheapest. */\nexport type Zone = {\n  plan: Plan;\n  from: number;\n  to: number;\n};\n\nexport const LAST_POSITION = STOPS.length - 1;\n\nconst FIRST_STOP = STOPS[0];\n\nexport const 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 RATE_FORMATTER = new Intl.NumberFormat('en-US', {\n  style: 'currency',\n  currency: 'USD',\n  minimumFractionDigits: 2,\n  maximumFractionDigits: 2,\n});\n\nconst VOLUME_FORMATTER = new Intl.NumberFormat('en-US');\n\nconst NOT_DIGITS = /\\D/g;\n\nexport function formatPrice(amount: number) {\n  return PRICE_FORMATTER.format(amount);\n}\n\nexport function formatRate(amount: number) {\n  return RATE_FORMATTER.format(amount);\n}\n\nexport function formatVolume(volume: number) {\n  return VOLUME_FORMATTER.format(volume);\n}\n\n/** The number in a typed text, whatever separators came with it; null while nothing is typed. */\nexport function volumeOfText(text: string) {\n  const digits = text.replace(NOT_DIGITS, '');\n  if (digits === '') {\n    return null;\n  }\n  return Number(digits);\n}\n\nexport function clampVolume(volume: number) {\n  const atLeastZero = Math.max(volume, 0);\n  return Math.min(atLeastZero, MAX_VOLUME);\n}\n\nexport function costOf(plan: Plan, volume: number) {\n  const over = volume - plan.includedRequests;\n  const billable = Math.max(0, over);\n  const thousands = billable / 1_000;\n  const overage = thousands * plan.pricePerThousand;\n  return plan.basePrice + overage;\n}\n\n/** The plan that costs the least for this volume. A tie goes to the smaller plan. */\nexport function cheapestPlanAt(volume: number) {\n  let cheapest = PLANS[0];\n  let lowest = costOf(cheapest, volume);\n  for (const plan of PLANS) {\n    const cost = costOf(plan, volume);\n    if (cost < lowest) {\n      cheapest = plan;\n      lowest = cost;\n    }\n  }\n  return cheapest;\n}\n\n/** Where a volume sits on the track: on a stop, or between two stops on a log scale. */\nexport function positionOf(volume: number) {\n  if (volume <= FIRST_STOP) {\n    return 0;\n  }\n  for (let index = 0; index < LAST_POSITION; index += 1) {\n    const low = STOPS[index];\n    const high = STOPS[index + 1];\n    if (volume <= high) {\n      const covered = Math.log(volume / low);\n      const span = Math.log(high / low);\n      const along = covered / span;\n      return index + along;\n    }\n  }\n  return LAST_POSITION;\n}\n\nexport function volumeAt(position: number) {\n  const index = Math.round(position);\n  const atLeastFirst = Math.max(index, 0);\n  const bounded = Math.min(atLeastFirst, LAST_POSITION);\n  return STOPS[bounded];\n}\n\nexport function shareOf(position: number) {\n  return position / LAST_POSITION;\n}\n\n/** The arrow keys go from stop to stop, starting from any typed volume. */\nexport function stopAbove(volume: number) {\n  const stop = STOPS.find((candidate) => candidate > volume);\n  if (stop === undefined) {\n    return MAX_VOLUME;\n  }\n  return stop;\n}\n\n/** Under the first stop there is nowhere lower to go, so a typed 300 stays 300 instead of rising to it. */\nexport function stopBelow(volume: number) {\n  const lower = STOPS.filter((candidate) => candidate < volume);\n  const stop = lower.at(-1);\n  if (stop === undefined) {\n    return volume;\n  }\n  return stop;\n}\n\n/** The smallest volume past `low` where the cheapest plan is no longer the one at `low`. */\nfunction firstVolumeOfChange(low: number, high: number) {\n  const before = cheapestPlanAt(low);\n  let below = low;\n  let above = high;\n  while (above - below > 1) {\n    const sum = below + above;\n    const middle = Math.floor(sum / 2);\n    const plan = cheapestPlanAt(middle);\n    if (plan === before) {\n      below = middle;\n    } else {\n      above = middle;\n    }\n  }\n  return above;\n}\n\nfunction notchesOf() {\n  const notches: Notch[] = [];\n  for (let index = 0; index < LAST_POSITION; index += 1) {\n    const low = STOPS[index];\n    const high = STOPS[index + 1];\n    const lowPlan = cheapestPlanAt(low);\n    const highPlan = cheapestPlanAt(high);\n    if (lowPlan === highPlan) {\n      continue;\n    }\n    const volume = firstVolumeOfChange(low, high);\n    const position = positionOf(volume);\n    notches.push({ volume, position, plan: highPlan });\n  }\n  return notches;\n}\n\nfunction zonesOf(notches: readonly Notch[]) {\n  const zones: Zone[] = [];\n  let from = 0;\n  let plan = cheapestPlanAt(FIRST_STOP);\n  for (const notch of notches) {\n    zones.push({ plan, from, to: notch.position });\n    from = notch.position;\n    plan = notch.plan;\n  }\n  zones.push({ plan, from, to: LAST_POSITION });\n  return zones;\n}\n\n/** The prices are fixed, so the places where the cheapest plan changes are worked out once. */\nexport const NOTCHES = notchesOf();\n\nexport const ZONES = zonesOf(NOTCHES);\n",
      "type": "registry:component",
      "target": "components/blocks/pricing-04/volume-model.ts"
    },
    {
      "path": "registry/ndeko/blocks/pricing/pricing-04/data.ts",
      "content": "export type PlanId = 'hobby' | 'growth' | 'scale';\n\nexport type Plan = {\n  id: PlanId;\n  name: string;\n  summary: string;\n  basePrice: number;\n  includedRequests: number;\n  /** For each thousand requests past the included ones. */\n  pricePerThousand: number;\n  action: string;\n};\n\nexport const PLANS: Plan[] = [\n  {\n    id: 'hobby',\n    name: 'Hobby',\n    summary: 'For a side project or a first prototype',\n    basePrice: 0,\n    includedRequests: 1_000,\n    pricePerThousand: 4,\n    action: 'Start for free',\n  },\n  {\n    id: 'growth',\n    name: 'Growth',\n    summary: 'For an app with steady traffic',\n    basePrice: 29,\n    includedRequests: 25_000,\n    pricePerThousand: 1.6,\n    action: 'Start with Growth',\n  },\n  {\n    id: 'scale',\n    name: 'Scale',\n    summary: 'For products that look up addresses all day',\n    basePrice: 249,\n    includedRequests: 250_000,\n    pricePerThousand: 0.8,\n    action: 'Start with Scale',\n  },\n];\n\n/** The volumes the track and the drag stop at, about evenly spaced on a log scale. */\nexport const STOPS = [\n  500, 600, 800, 1_000, 1_200, 1_500, 2_000, 2_500, 3_000, 4_000, 5_000, 6_000,\n  8_000, 10_000, 12_000, 15_000, 20_000, 25_000, 30_000, 40_000, 50_000, 60_000,\n  80_000, 100_000, 120_000, 150_000, 200_000, 250_000, 300_000, 400_000,\n  500_000, 600_000, 800_000, 1_000_000,\n];\n\nexport const MAX_VOLUME = 1_000_000;\n\nexport const START_VOLUME = 12_000;\n\nexport const SECTION = {\n  title: 'Pricing that follows your requests',\n  description:\n    'Waypost turns addresses into points on a map. Type or drag the volume you expect and every plan below is priced for it.',\n  over: 'Prices here go up to 1,000,000 requests a month. Above that, we set a price with you.',\n  footnote:\n    'Illustrative prices in US dollars for an example API, taxes added at checkout',\n};\n",
      "type": "registry:component",
      "target": "components/blocks/pricing-04/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "pricing"
  ],
  "type": "registry:block"
}