{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "error-pages-01",
  "title": "Page not found",
  "description": "A calm 404 with a search that suggests pages as you type, the typed words marked, popular pages and Go home: on the folded map above, the trail that stops at the fold draws itself on to a pin as soon as a page matches.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/kbd.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/error-pages/error-pages-01/index.tsx",
      "content": "'use client';\n\nimport { useCallback, useId } from 'react';\n\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { ArrowRightIcon } from '@/registry/ndeko/lib/icons';\nimport { FOCUS_RING } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\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 { POPULAR, SITE, type PopularPage } from './data';\nimport { wordsOf } from './match';\nimport { PageSearch } from './page-search';\nimport {\n  INITIAL,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  suggestionsIn,\n  type SearchState,\n} from './session';\nimport { TrailMap } from './trail-map';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nfunction matchLineOf(state: SearchState, count: number) {\n  const hasWords = wordsOf(state.query).length > 0;\n  const isListed = state.isOpen && hasWords;\n  if (!isListed) {\n    return '';\n  }\n  if (count === 0) {\n    return 'No page matches';\n  }\n  if (count === 1) {\n    return '1 suggestion';\n  }\n  return `${count} suggestions`;\n}\n\nfunction PopularRow({ page }: { page: PopularPage }) {\n  const Glyph = page.icon;\n\n  return (\n    <li>\n      <a\n        href={page.href}\n        className={cn(\n          'group hover:bg-foreground/[0.04] flex items-center gap-3 rounded-xl p-2 transition-colors duration-100',\n          FOCUS_RING\n        )}\n      >\n        <span className='keycap-3d flex size-8 shrink-0 items-center justify-center rounded-lg'>\n          <Glyph className='text-muted-foreground size-4' />\n        </span>\n        <span className='flex min-w-0 flex-col'>\n          <span className='text-[13px] font-medium'>{page.title}</span>\n          <span className='text-muted-foreground truncate text-xs'>\n            {page.lead}\n          </span>\n        </span>\n        <ArrowRightIcon className='text-muted-foreground ms-auto size-4 shrink-0 transition-transform duration-100 group-hover:translate-x-0.5' />\n      </a>\n    </li>\n  );\n}\n\nexport default function ErrorPages01() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const popularId = useId();\n  const suggestions = suggestionsIn(state);\n  const isFound = suggestions.length > 0;\n  const matchLine = matchLineOf(state, suggestions.length);\n  const message = spokenUnless(isAutoplaying, matchLine);\n  const canReplay = isFinished && !isAutoplaying;\n\n  const close = useCallback(() => act({ type: 'closed' }), [act]);\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-background text-foreground @container flex min-h-dvh w-full flex-col'\n      >\n        <header className='flex min-h-16 items-center gap-3 px-4 @2xl:px-8'>\n          <a\n            href={SITE.homeHref}\n            className={cn(\n              'flex items-center gap-2 rounded-md text-sm font-semibold',\n              FOCUS_RING\n            )}\n          >\n            <CompanyMark seed={SITE.name} size='lg' />\n            {SITE.name}\n          </a>\n          <span className='flex-1' />\n          <ReplayButton isShown={canReplay} onReplay={restart} label='Replay' />\n        </header>\n\n        <main className='flex flex-1 flex-col items-center px-4 pt-4 pb-16 @2xl:pt-8'>\n          <div className='flex w-full max-w-xl flex-col items-center gap-8'>\n            <TrailMap isFound={isFound} />\n\n            <div className='flex flex-col items-center gap-3 text-center'>\n              <p className='text-muted-foreground text-xs tabular-nums'>\n                Error 404\n              </p>\n              <h1 className='text-2xl font-semibold text-balance @sm:text-3xl'>\n                Page not found\n              </h1>\n              <p className='text-muted-foreground max-w-md text-sm text-pretty'>\n                The link may be old, or the guide moved when we grouped the\n                routes by region. Search for it, or start from a popular page.\n              </p>\n              <p className='text-muted-foreground font-mono text-xs break-all'>\n                {SITE.missingAddress}\n              </p>\n            </div>\n\n            <PageSearch\n              query={state.query}\n              isOpen={state.isOpen}\n              activeIndex={state.activeIndex}\n              suggestions={suggestions}\n              pressed={pressed}\n              isDemonstrating={isAutoplaying}\n              onType={(value) => act({ type: 'typed', value })}\n              onFocus={() => act({ type: 'focused' })}\n              onMove={(by) => act({ type: 'moved', by })}\n              onEscape={() => act({ type: 'escaped' })}\n              onClose={close}\n            />\n\n            <section\n              aria-labelledby={popularId}\n              className='flex w-full flex-col gap-2'\n            >\n              <h2 id={popularId} className='px-2 text-[13px] font-medium'>\n                Popular pages\n              </h2>\n              <ul className='bg-foreground/[0.025] grid gap-1 rounded-2xl p-1.5 @md:grid-cols-2'>\n                {POPULAR.map((page) => (\n                  <PopularRow key={page.id} page={page} />\n                ))}\n              </ul>\n            </section>\n\n            <Button\n              size='lg'\n              nativeButton={false}\n              render={<a href={SITE.homeHref} />}\n            >\n              Go home\n            </Button>\n          </div>\n        </main>\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/error-pages-01/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/error-pages/error-pages-01/page-search.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\nimport { useEffect, useId, useRef } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { pressedQuietOf } from '@/registry/ndeko/lib/demonstration';\nimport { ArrowRightIcon, SearchIcon } from '@/registry/ndeko/lib/icons';\nimport { EASE_OUT_STRONG, SPRING } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Kbd } from '@/registry/ndeko/ui/kbd';\n\nimport type { SitePage } from './data';\nimport { markedPartsOf, wordsOf } from './match';\n\nconst LIST_SHOWN = { opacity: 1, scale: 1 };\n\nconst LIST_HIDDEN = { opacity: 0, scale: 0.97 };\n\nconst LIST_FADED = { opacity: 0, scale: 1 };\n\nconst LIST_ARRIVE: Transition = { duration: 0.15, ease: EASE_OUT_STRONG };\n\nconst LIST_LEAVE: Transition = { duration: 0.1, ease: EASE_OUT_STRONG };\n\nconst INSTANT: Transition = { duration: 0 };\n\nconst KEY_MOTION = 'transition-[scale] duration-150';\n\nfunction listStartOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return LIST_FADED;\n  }\n  return LIST_HIDDEN;\n}\n\nfunction travelOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return SPRING;\n}\n\nfunction optionIdOf(listId: string, index: number) {\n  return `${listId}-${index}`;\n}\n\nfunction activeIdOf(listId: string, activeIndex: number, isShown: boolean) {\n  const hasActive = activeIndex >= 0;\n  if (!isShown || !hasActive) {\n    return undefined;\n  }\n  return optionIdOf(listId, activeIndex);\n}\n\nfunction MarkedTitle({ title, words }: { title: string; words: string[] }) {\n  const parts = markedPartsOf(title, words);\n\n  return (\n    <span className='min-w-0 truncate'>\n      {parts.map((part) => {\n        if (part.isMatch) {\n          return (\n            <mark\n              key={part.key}\n              className='bg-primary/15 text-foreground rounded-[3px]'\n            >\n              {part.text}\n            </mark>\n          );\n        }\n        return <span key={part.key}>{part.text}</span>;\n      })}\n    </span>\n  );\n}\n\ntype PageSearchProps = {\n  query: string;\n  isOpen: boolean;\n  activeIndex: number;\n  suggestions: SitePage[];\n  pressed: string | null;\n  /** While the demonstration plays, the list shows without the focus and a click elsewhere leaves it be. */\n  isDemonstrating: boolean;\n  onType: (value: string) => void;\n  onFocus: () => void;\n  onMove: (by: 1 | -1) => void;\n  onEscape: () => void;\n  onClose: () => void;\n};\n\nexport function PageSearch({\n  query,\n  isOpen,\n  activeIndex,\n  suggestions,\n  pressed,\n  isDemonstrating,\n  onType,\n  onFocus,\n  onMove,\n  onEscape,\n  onClose,\n}: PageSearchProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const wrapperRef = useRef<HTMLDivElement>(null);\n  const inputId = useId();\n  const listId = useId();\n  const words = wordsOf(query);\n  const hasWords = words.length > 0;\n  const isShown = isOpen && hasWords;\n  const hasSuggestions = suggestions.length > 0;\n  const isListed = isShown && hasSuggestions;\n  const activeId = activeIdOf(listId, activeIndex, isListed);\n  const listensOutside = isShown && !isDemonstrating;\n\n  useEffect(() => {\n    if (!listensOutside) {\n      return;\n    }\n    function closeFromOutside(event: PointerEvent) {\n      const wrapper = wrapperRef.current;\n      const target = event.target;\n      const isInside = target instanceof Node && wrapper?.contains(target);\n      if (!isInside) {\n        onClose();\n      }\n    }\n    document.addEventListener('pointerdown', closeFromOutside);\n    return () => document.removeEventListener('pointerdown', closeFromOutside);\n  }, [listensOutside, onClose]);\n\n  function openActive() {\n    let index = activeIndex;\n    if (index < 0) {\n      index = 0;\n    }\n    const optionId = optionIdOf(listId, index);\n    const option = document.getElementById(optionId);\n    option?.click();\n  }\n\n  function handleKeys(event: React.KeyboardEvent<HTMLInputElement>) {\n    if (event.key === 'ArrowDown') {\n      event.preventDefault();\n      onMove(1);\n      return;\n    }\n    if (event.key === 'ArrowUp') {\n      event.preventDefault();\n      onMove(-1);\n      return;\n    }\n    if (event.key === 'Escape') {\n      event.preventDefault();\n      onEscape();\n      return;\n    }\n    const isEnter = event.key === 'Enter';\n    const opens = isEnter && isListed;\n    if (opens) {\n      event.preventDefault();\n      openActive();\n    }\n  }\n\n  function closeWhenLeaving(event: React.FocusEvent<HTMLDivElement>) {\n    const next = event.relatedTarget;\n    const staysInside =\n      next instanceof Node && event.currentTarget.contains(next);\n    if (!staysInside) {\n      onClose();\n    }\n  }\n\n  return (\n    <div ref={wrapperRef} onBlur={closeWhenLeaving} className='relative w-full'>\n      <label htmlFor={inputId} className='sr-only'>\n        Search Larchway\n      </label>\n      <SearchIcon className='text-muted-foreground pointer-events-none absolute start-3.5 top-1/2 size-4 -translate-y-1/2' />\n      <Input\n        id={inputId}\n        type='search'\n        role='combobox'\n        autoComplete='off'\n        spellCheck={false}\n        aria-autocomplete='list'\n        aria-expanded={isListed}\n        aria-controls={listId}\n        aria-activedescendant={activeId}\n        placeholder='Search routes, guides and help'\n        value={query}\n        onChange={(event) => onType(event.target.value)}\n        onFocus={onFocus}\n        onKeyDown={handleKeys}\n        className='h-11 rounded-xl ps-10 pe-3 md:text-sm'\n      />\n      <AnimatePresence initial={false}>\n        {isShown && (\n          <motion.div\n            key='suggestions'\n            initial={listStartOf(shouldReduceMotion)}\n            animate={LIST_SHOWN}\n            exit={{\n              ...listStartOf(shouldReduceMotion),\n              transition: LIST_LEAVE,\n            }}\n            transition={LIST_ARRIVE}\n            className='surface-raised absolute inset-x-0 top-full z-20 mt-2 flex origin-top flex-col rounded-xl p-1'\n          >\n            {hasSuggestions && (\n              <ul\n                id={listId}\n                role='listbox'\n                aria-label='Suggested pages'\n                className='flex flex-col'\n              >\n                {suggestions.map((page, index) => {\n                  const isActive = index === activeIndex;\n                  return (\n                    <li key={page.id} role='none'>\n                      <a\n                        id={optionIdOf(listId, index)}\n                        role='option'\n                        aria-selected={isActive}\n                        href={page.href}\n                        tabIndex={-1}\n                        onMouseDown={(event) => event.preventDefault()}\n                        className='relative isolate flex h-10 items-center gap-3 rounded-lg px-2.5 text-[13px] outline-none'\n                      >\n                        {isActive && (\n                          <motion.span\n                            layoutId={`${listId}-highlight`}\n                            transition={travelOf(shouldReduceMotion)}\n                            className='bg-foreground/[0.06] absolute inset-0 -z-10 rounded-lg'\n                          />\n                        )}\n                        <span className='text-muted-foreground w-16 shrink-0 text-xs'>\n                          {page.section}\n                        </span>\n                        <MarkedTitle title={page.title} words={words} />\n                        <ArrowRightIcon\n                          className={cn(\n                            'text-muted-foreground ms-auto size-3.5 shrink-0 opacity-0 transition-opacity duration-150',\n                            isActive && 'opacity-100'\n                          )}\n                        />\n                      </a>\n                    </li>\n                  );\n                })}\n              </ul>\n            )}\n            {!hasSuggestions && (\n              <p className='text-muted-foreground px-2.5 py-3 text-[13px] text-pretty'>\n                No page matches these words. Try one place or one activity, such\n                as dolomites or huts.\n              </p>\n            )}\n            <p\n              aria-hidden='true'\n              className='text-muted-foreground flex flex-wrap items-center gap-x-3 gap-y-1 px-2.5 pt-2 pb-1.5 text-xs'\n            >\n              <span className='inline-flex items-center gap-1'>\n                <Kbd\n                  className={cn(\n                    KEY_MOTION,\n                    pressedQuietOf(pressed === 'key-up')\n                  )}\n                >\n                  ↑\n                </Kbd>\n                <Kbd\n                  className={cn(\n                    KEY_MOTION,\n                    pressedQuietOf(pressed === 'key-down')\n                  )}\n                >\n                  ↓\n                </Kbd>\n                move\n              </span>\n              <span className='inline-flex items-center gap-1'>\n                <Kbd>Enter</Kbd>\n                opens\n              </span>\n              <span className='inline-flex items-center gap-1'>\n                <Kbd\n                  className={cn(\n                    KEY_MOTION,\n                    pressedQuietOf(pressed === 'key-escape')\n                  )}\n                >\n                  Esc\n                </Kbd>\n                closes\n              </span>\n            </p>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/error-pages-01/page-search.tsx"
    },
    {
      "path": "registry/ndeko/blocks/error-pages/error-pages-01/trail-map.tsx",
      "content": "'use client';\n\nimport { motion, type Transition } from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { EASE_OUT_STRONG } from '@/registry/ndeko/lib/motion-presets';\n\nconst LEFT_PANEL = '24,34 88,22 88,126 24,138';\nconst MIDDLE_PANEL = '88,22 152,34 152,138 88,126';\nconst RIGHT_PANEL = '152,34 216,22 216,126 152,138';\n\nconst CONTOURS = [\n  'M28 62C44 54 62 60 86 48',\n  'M28 84C46 78 60 86 86 74',\n  'M92 104C110 96 128 108 150 100',\n  'M156 110C174 100 190 106 214 94',\n  'M156 82C176 74 194 80 214 70',\n];\n\nconst WALKED = 'M44 112C56 98 66 100 74 88S82 72 86 68';\n\nconst LOST = 'M86 68C100 60 112 76 126 70S146 52 160 56S186 66 194 50';\n\nconst BREAK_POINT = { x: 86, y: 68 };\n\nconst END_POINT = { x: 194, y: 50 };\n\nconst PIN = 'M0 0C-2-4-6-7-6-11A6 6 0 1 1 6-11C6-7 2-4 0 0Z';\n\nconst FOUND = { pathLength: 1, opacity: 1 };\n\nconst LOST_TRAIL = { pathLength: 0, opacity: 0 };\n\nconst DRAW: Transition = { duration: 0.7, ease: EASE_OUT_STRONG };\n\nconst LET_GO: Transition = {\n  opacity: { duration: 0.15 },\n  pathLength: { duration: 0, delay: 0.15 },\n};\n\nconst FADE: Transition = { duration: 0.2 };\n\n/** Under reduced motion the trail is whole at once and only fades in. */\nconst SHOW_STILL: Transition = {\n  opacity: { duration: 0.2 },\n  pathLength: { duration: 0 },\n};\n\nconst PIN_SHOWN = { opacity: 1, scale: 1 };\n\nconst PIN_HIDDEN = { opacity: 0, scale: 0.8 };\n\nconst PIN_FADED = { opacity: 0, scale: 1 };\n\nconst PIN_ARRIVE: Transition = {\n  duration: 0.3,\n  ease: EASE_OUT_STRONG,\n  delay: 0.5,\n};\n\nconst PIN_LEAVE: Transition = { duration: 0.12 };\n\n/** The pin grows from its tip, where it touches the map. */\nconst PIN_ORIGIN = { originX: 0.5, originY: 1 };\n\nfunction trailOf(isFound: boolean) {\n  if (isFound) {\n    return FOUND;\n  }\n  return LOST_TRAIL;\n}\n\nfunction trailMotionOf(isFound: boolean, shouldReduceMotion: boolean) {\n  if (!isFound) {\n    return LET_GO;\n  }\n  if (shouldReduceMotion) {\n    return SHOW_STILL;\n  }\n  return DRAW;\n}\n\nfunction pinOf(isFound: boolean, shouldReduceMotion: boolean) {\n  if (isFound) {\n    return PIN_SHOWN;\n  }\n  if (shouldReduceMotion) {\n    return PIN_FADED;\n  }\n  return PIN_HIDDEN;\n}\n\nfunction pinMotionOf(isFound: boolean, shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return FADE;\n  }\n  if (isFound) {\n    return PIN_ARRIVE;\n  }\n  return PIN_LEAVE;\n}\n\nfunction breakOpacityOf(isFound: boolean) {\n  if (isFound) {\n    return 0;\n  }\n  return 1;\n}\n\ntype TrailMapProps = {\n  isFound: boolean;\n};\n\nexport function TrailMap({ isFound }: TrailMapProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const endTransform = `translate(${END_POINT.x} ${END_POINT.y})`;\n\n  return (\n    <svg\n      viewBox='0 0 240 152'\n      aria-hidden='true'\n      className='w-full max-w-[17rem] overflow-visible'\n    >\n      <ellipse\n        cx='120'\n        cy='144'\n        rx='96'\n        ry='5'\n        className='fill-foreground/[0.05]'\n      />\n      <polygon\n        points={LEFT_PANEL}\n        strokeWidth='1'\n        vectorEffect='non-scaling-stroke'\n        className='fill-card stroke-border'\n      />\n      <polygon\n        points={MIDDLE_PANEL}\n        strokeWidth='1'\n        vectorEffect='non-scaling-stroke'\n        className='fill-card stroke-border'\n      />\n      <polygon points={MIDDLE_PANEL} className='fill-foreground/[0.045]' />\n      <polygon\n        points={RIGHT_PANEL}\n        strokeWidth='1'\n        vectorEffect='non-scaling-stroke'\n        className='fill-card stroke-border'\n      />\n      {CONTOURS.map((contour) => (\n        <path\n          key={contour}\n          d={contour}\n          fill='none'\n          strokeWidth='1'\n          vectorEffect='non-scaling-stroke'\n          className='stroke-foreground/10'\n        />\n      ))}\n      <path\n        d={LOST}\n        fill='none'\n        strokeWidth='1.5'\n        strokeDasharray='2 5'\n        strokeLinecap='round'\n        className='stroke-foreground/20'\n      />\n      <path\n        d={WALKED}\n        fill='none'\n        strokeWidth='2.5'\n        strokeLinecap='round'\n        className='stroke-primary'\n      />\n      <motion.path\n        d={LOST}\n        fill='none'\n        strokeWidth='2.5'\n        strokeLinecap='round'\n        className='stroke-primary'\n        initial={false}\n        animate={trailOf(isFound)}\n        transition={trailMotionOf(isFound, shouldReduceMotion)}\n      />\n      <motion.circle\n        cx={BREAK_POINT.x}\n        cy={BREAK_POINT.y}\n        r='3.5'\n        strokeWidth='1.5'\n        className='fill-background stroke-foreground/40'\n        initial={false}\n        animate={{ opacity: breakOpacityOf(isFound) }}\n        transition={FADE}\n      />\n      <circle cx='44' cy='112' r='5' className='fill-primary' />\n      <circle cx='44' cy='112' r='2' className='fill-primary-foreground' />\n      <g transform={endTransform}>\n        <motion.g\n          style={PIN_ORIGIN}\n          initial={false}\n          animate={pinOf(isFound, shouldReduceMotion)}\n          transition={pinMotionOf(isFound, shouldReduceMotion)}\n        >\n          <path d={PIN} className='fill-primary' />\n          <circle cx='0' cy='-11' r='2.2' className='fill-primary-foreground' />\n        </motion.g>\n      </g>\n    </svg>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/error-pages-01/trail-map.tsx"
    },
    {
      "path": "registry/ndeko/blocks/error-pages/error-pages-01/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\nimport { keyDelayOf, prefixesOf } from '@/registry/ndeko/lib/demonstration';\n\nimport { PAGES } from './data';\nimport { suggestionsOf } from './match';\n\nexport type SearchState = {\n  query: string;\n  isOpen: boolean;\n  /** The suggestion Enter opens. Nothing is highlighted before the arrows are used. */\n  activeIndex: number;\n};\n\nexport type SearchAction =\n  | { type: 'typed'; value: string }\n  | { type: 'focused' }\n  | { type: 'moved'; by: 1 | -1 }\n  | { type: 'escaped' }\n  | { type: 'closed' };\n\ntype Step = SessionStep<SearchState, SearchAction>;\n\nexport const SUGGESTION_LIMIT = 5;\n\nconst NOTHING_HIGHLIGHTED = -1;\n\nexport const INITIAL: SearchState = {\n  query: '',\n  isOpen: false,\n  activeIndex: NOTHING_HIGHLIGHTED,\n};\n\nexport function suggestionsIn(state: SearchState) {\n  return suggestionsOf(PAGES, state.query, SUGGESTION_LIMIT);\n}\n\n/** The first arrow lands on the first or the last row, then the highlight wraps around the list. */\nfunction nextIndexOf(current: number, by: 1 | -1, count: number) {\n  if (current === NOTHING_HIGHLIGHTED) {\n    if (by === 1) {\n      return 0;\n    }\n    return count - 1;\n  }\n  const moved = current + by + count;\n  return moved % count;\n}\n\nfunction moved(state: SearchState, by: 1 | -1): SearchState {\n  const count = suggestionsIn(state).length;\n  if (count === 0) {\n    return state;\n  }\n  if (!state.isOpen) {\n    const firstIndex = nextIndexOf(NOTHING_HIGHLIGHTED, by, count);\n    return { ...state, isOpen: true, activeIndex: firstIndex };\n  }\n  const activeIndex = nextIndexOf(state.activeIndex, by, count);\n  return { ...state, activeIndex };\n}\n\n/** Escape closes the list first, and clears the field when the list is already closed. */\nfunction escaped(state: SearchState): SearchState {\n  if (state.isOpen) {\n    return { ...state, isOpen: false, activeIndex: NOTHING_HIGHLIGHTED };\n  }\n  return INITIAL;\n}\n\nexport function reducer(state: SearchState, action: SearchAction) {\n  switch (action.type) {\n    case 'typed':\n      return {\n        query: action.value,\n        isOpen: true,\n        activeIndex: NOTHING_HIGHLIGHTED,\n      };\n    case 'focused':\n      return { ...state, isOpen: true };\n    case 'moved':\n      return moved(state, action.by);\n    case 'escaped':\n      return escaped(state);\n    case 'closed':\n      return { ...state, isOpen: false, activeIndex: NOTHING_HIGHLIGHTED };\n  }\n}\n\nconst QUERY = 'winter dolomites';\n\nconst KEY_MS = 70;\n\nfunction typing(text: string, startAfter: number): Step[] {\n  const prefixes = prefixesOf(text);\n  return prefixes.map((value, index) => ({\n    after: keyDelayOf(index, startAfter, KEY_MS),\n    by: 'demo',\n    action: { type: 'typed', value },\n  }));\n}\n\nfunction arrow(after: number, by: 1 | -1): Step {\n  let press = 'key-down';\n  if (by === -1) {\n    press = 'key-up';\n  }\n  return { after, by: 'demo', press, action: { type: 'moved', by } };\n}\n\n/**\n * A person types the words of the link they followed, walks the suggestions with the arrows and\n * leaves with Escape twice: the round ends on the empty field it started from.\n */\nexport const SCRIPT: Step[] = [\n  ...typing(QUERY, 1400),\n  arrow(1200, 1),\n  arrow(700, 1),\n  arrow(700, -1),\n  {\n    after: 1900,\n    by: 'demo',\n    press: 'key-escape',\n    action: { type: 'escaped' },\n  },\n  { after: 800, by: 'demo', action: { type: 'escaped' } },\n];\n\n/** Under reduced motion the words are in the field and the best page is highlighted. */\nexport const RESTING: SearchState = {\n  query: QUERY,\n  isOpen: true,\n  activeIndex: 0,\n};\n\nexport const LOOP_AFTER_MS = 2600;\n",
      "type": "registry:component",
      "target": "components/blocks/error-pages-01/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/error-pages/error-pages-01/match.ts",
      "content": "import type { SitePage } from './data';\n\nexport type MarkedPart = {\n  key: string;\n  text: string;\n  isMatch: boolean;\n};\n\ntype Range = {\n  start: number;\n  end: number;\n};\n\ntype Scored = {\n  page: SitePage;\n  order: number;\n  score: number;\n};\n\n/** A single letter matches half the site, so a word counts from two letters. */\nconst MIN_WORD_LENGTH = 2;\n\nexport function wordsOf(query: string) {\n  const lowered = query.toLowerCase();\n  const pieces = lowered.split(/\\s+/);\n  return pieces.filter((piece) => piece.length >= MIN_WORD_LENGTH);\n}\n\nfunction rangesOfWord(lowered: string, word: string) {\n  const ranges: Range[] = [];\n  let start = lowered.indexOf(word);\n  while (start !== -1) {\n    const end = start + word.length;\n    ranges.push({ start, end });\n    start = lowered.indexOf(word, end);\n  }\n  return ranges;\n}\n\nfunction byStart(first: Range, second: Range) {\n  return first.start - second.start;\n}\n\nfunction mergedRanges(ranges: Range[]) {\n  const sorted = [...ranges].sort(byStart);\n  const merged: Range[] = [];\n  for (const range of sorted) {\n    const last = merged.at(-1);\n    const overlaps = last !== undefined && range.start <= last.end;\n    if (overlaps) {\n      last.end = Math.max(last.end, range.end);\n      continue;\n    }\n    merged.push({ ...range });\n  }\n  return merged;\n}\n\nfunction rangesOf(text: string, words: string[]) {\n  const lowered = text.toLowerCase();\n  const ranges = words.flatMap((word) => rangesOfWord(lowered, word));\n  return mergedRanges(ranges);\n}\n\nexport function markedPartsOf(text: string, words: string[]) {\n  const parts: MarkedPart[] = [];\n  let cursor = 0;\n  for (const range of rangesOf(text, words)) {\n    if (range.start > cursor) {\n      const plain = text.slice(cursor, range.start);\n      parts.push({ key: String(cursor), text: plain, isMatch: false });\n    }\n    const match = text.slice(range.start, range.end);\n    parts.push({ key: String(range.start), text: match, isMatch: true });\n    cursor = range.end;\n  }\n  if (cursor < text.length) {\n    const rest = text.slice(cursor);\n    parts.push({ key: String(cursor), text: rest, isMatch: false });\n  }\n  return parts;\n}\n\nfunction scoreOf(page: SitePage, words: string[]) {\n  const lowered = page.title.toLowerCase();\n  const found = words.filter((word) => lowered.includes(word));\n  return found.length;\n}\n\nfunction byScoreThenOrder(first: Scored, second: Scored) {\n  const scoreGap = second.score - first.score;\n  if (scoreGap !== 0) {\n    return scoreGap;\n  }\n  return first.order - second.order;\n}\n\n/** Pages whose title holds the most typed words come first; ties keep the order of the site. */\nexport function suggestionsOf(\n  pages: readonly SitePage[],\n  query: string,\n  limit: number\n) {\n  const words = wordsOf(query);\n  if (words.length === 0) {\n    return [];\n  }\n  const scored = pages.map((page, order) => ({\n    page,\n    order,\n    score: scoreOf(page, words),\n  }));\n  const matching = scored.filter((entry) => entry.score > 0);\n  matching.sort(byScoreThenOrder);\n  const best = matching.slice(0, limit);\n  return best.map((entry) => entry.page);\n}\n",
      "type": "registry:component",
      "target": "components/blocks/error-pages-01/match.ts"
    },
    {
      "path": "registry/ndeko/blocks/error-pages/error-pages-01/data.ts",
      "content": "import {\n  CloudIcon,\n  LifeBuoyIcon,\n  MapPinIcon,\n  RouteIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\n\nexport type SitePage = {\n  id: string;\n  title: string;\n  section: string;\n  href: string;\n};\n\nexport type PopularPage = {\n  id: string;\n  title: string;\n  lead: string;\n  href: string;\n  icon: Icon;\n};\n\nexport const SITE = {\n  name: 'Larchway',\n  homeHref: '#',\n  missingAddress: 'larchway.example/guides/winter-routes-dolomites',\n};\n\nexport const PAGES: SitePage[] = [\n  {\n    id: 'winter-dolomites',\n    title: 'Winter routes in the Dolomites',\n    section: 'Guides',\n    href: '#guides-winter-routes-in-the-dolomites',\n  },\n  {\n    id: 'planning-winter',\n    title: 'Planning a winter route',\n    section: 'Help',\n    href: '#help-planning-a-winter-route',\n  },\n  {\n    id: 'huts-dolomites',\n    title: 'Huts and bivouacs in the Dolomites',\n    section: 'Guides',\n    href: '#guides-huts-and-bivouacs',\n  },\n  {\n    id: 'snow-layers',\n    title: 'Snow and avalanche layers',\n    section: 'Maps',\n    href: '#maps-snow-and-avalanche-layers',\n  },\n  {\n    id: 'offline-alps',\n    title: 'Offline maps for the Alps',\n    section: 'Maps',\n    href: '#maps-offline-alps',\n  },\n  {\n    id: 'grades',\n    title: 'Route difficulty grades explained',\n    section: 'Guides',\n    href: '#guides-difficulty-grades',\n  },\n  {\n    id: 'gpx',\n    title: 'Import a GPX file',\n    section: 'Help',\n    href: '#help-import-gpx',\n  },\n  {\n    id: 'share-group',\n    title: 'Share a route with your group',\n    section: 'Help',\n    href: '#help-share-a-route',\n  },\n  {\n    id: 'download-offline',\n    title: 'Download routes for offline use',\n    section: 'Help',\n    href: '#help-download-routes',\n  },\n  {\n    id: 'conditions',\n    title: 'Trail conditions this week',\n    section: 'Community',\n    href: '#community-trail-conditions',\n  },\n  {\n    id: 'pricing',\n    title: 'Plans and pricing',\n    section: 'Larchway',\n    href: '#pricing',\n  },\n];\n\nexport const POPULAR: PopularPage[] = [\n  {\n    id: 'plan',\n    title: 'Plan a route',\n    lead: 'Draw it on the map and check the climb',\n    href: '#plan-a-route',\n    icon: RouteIcon,\n  },\n  {\n    id: 'offline',\n    title: 'Offline maps',\n    lead: 'Download a region before you lose signal',\n    href: '#offline-maps',\n    icon: MapPinIcon,\n  },\n  {\n    id: 'conditions',\n    title: 'Trail conditions',\n    lead: 'Snow, closures and reports from this week',\n    href: '#trail-conditions',\n    icon: CloudIcon,\n  },\n  {\n    id: 'help',\n    title: 'Help center',\n    lead: 'GPX import, groups and billing',\n    href: '#help-center',\n    icon: LifeBuoyIcon,\n  },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/error-pages-01/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "error-pages"
  ],
  "type": "registry:block"
}