{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "help-center-01",
  "title": "Help center",
  "description": "A help center with a search hero, topics, popular articles and a person to write to: as you type, suggestions land under the field with your words marked, and the count on every topic rolls down to the articles that match while the topics with none step back.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "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-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.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",
    "https://ui.ndekocode.dev/r/wash.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/help-center/help-center-01/index.tsx",
      "content": "'use client';\n\nimport { useCallback, useId } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll } from '@/components/core/word-roll';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { ChevronRightIcon } from '@/registry/ndeko/lib/icons';\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 { 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';\nimport { Wash } from '@/registry/ndeko/ui/wash';\n\nimport {\n  ARTICLES,\n  CATEGORIES,\n  CATEGORY_GLYPH,\n  CONTACT,\n  POPULAR_IDS,\n  SITE,\n  type Article,\n  type Category,\n} from './data';\nimport { HelpSearch } from './help-search';\nimport { countIn, matchesOf, totalIn, wordsOf } from './match';\nimport {\n  INITIAL,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  suggestionsIn,\n  type HelpState,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nconst CARD =\n  'bg-card hairline-ring ring-border dark:bg-foreground/[0.03] rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)]';\n\nconst UNIT_LABELS = ['articles', 'article', 'matching'];\n\nfunction isPopular(article: Article) {\n  return POPULAR_IDS.includes(article.id);\n}\n\nconst POPULAR = ARTICLES.filter(isPopular);\n\nfunction unitOf(count: number, isSearching: boolean) {\n  if (isSearching) {\n    return 'matching';\n  }\n  if (count === 1) {\n    return 'article';\n  }\n  return 'articles';\n}\n\nfunction categoryTitleOf(article: Article) {\n  const category = CATEGORIES.find(\n    (candidate) => candidate.id === article.category\n  );\n  return category?.title ?? '';\n}\n\nfunction matchLineOf(state: HelpState, 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 article matches';\n  }\n  if (count === 1) {\n    return '1 article matches';\n  }\n  return `${count} articles match`;\n}\n\ntype CategoryCardProps = {\n  category: Category;\n  count: number;\n  isSearching: boolean;\n};\n\nfunction CategoryCard({ category, count, isSearching }: CategoryCardProps) {\n  const Glyph = CATEGORY_GLYPH[category.id];\n  const hasNone = isSearching && count === 0;\n\n  return (\n    <li>\n      <a\n        href={category.href}\n        className={cn(\n          CARD,\n          'group hover:bg-foreground/[0.02] flex h-full items-start gap-3 p-4 transition-[opacity,background-color] duration-200',\n          hasNone && 'opacity-45',\n          FOCUS_RING\n        )}\n      >\n        <span className='keycap-3d flex size-9 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-1 flex-col gap-0.5'>\n          <span className='text-[13px] font-medium'>{category.title}</span>\n          <span className='text-muted-foreground text-xs text-pretty'>\n            {category.lead}\n          </span>\n        </span>\n        <span className='text-muted-foreground flex shrink-0 items-baseline gap-1 text-xs tabular-nums'>\n          <MotionNumber value={count} />\n          <WordRoll text={unitOf(count, isSearching)} labels={UNIT_LABELS} />\n        </span>\n      </a>\n    </li>\n  );\n}\n\nexport default function HelpCenter01() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const topicsId = useId();\n  const popularId = useId();\n  const matches = matchesOf(state.query);\n  const suggestions = suggestionsIn(state);\n  const isSearching = wordsOf(state.query).length > 0;\n  const matchLine = matchLineOf(state, matches.length);\n  const message = spokenUnless(isAutoplaying, matchLine);\n  const canReplay = isFinished && !isAutoplaying;\n\n  const close = useCallback(() => act({ type: 'closed' }), [act]);\n\n  function countOf(category: Category) {\n    if (isSearching) {\n      return countIn(matches, category.id);\n    }\n    return totalIn(category.id);\n  }\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-background text-foreground @container min-h-dvh w-full'\n      >\n        <div className='mx-auto flex max-w-5xl flex-col gap-10 px-4 py-6 @2xl:px-8 @2xl:py-8'>\n          <header className='flex min-h-8 items-center gap-2'>\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='text-muted-foreground text-sm'>Help</span>\n            <span className='flex-1' />\n            <ReplayButton\n              isShown={canReplay}\n              onReplay={restart}\n              label='Replay'\n            />\n          </header>\n\n          <section className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] relative isolate z-10 flex flex-col items-center gap-4 rounded-2xl px-5 py-10 text-center shadow-[0_1px_2px_rgb(0_0_0/0.04)] @2xl:py-14'>\n            <Wash />\n            <h1 className='text-2xl font-semibold text-balance @sm:text-3xl'>\n              How can we help?\n            </h1>\n            <p className='text-muted-foreground max-w-md text-sm text-pretty'>\n              Search the guides, or start from a topic below.\n            </p>\n            <HelpSearch\n              query={state.query}\n              isOpen={state.isOpen}\n              activeIndex={state.activeIndex}\n              suggestions={suggestions}\n              matchCount={matches.length}\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          </section>\n\n          <section aria-labelledby={topicsId} className='flex flex-col gap-3'>\n            <h2 id={topicsId} className='px-1 text-[13px] font-medium'>\n              Topics\n            </h2>\n            <ul className='grid gap-3 @lg:grid-cols-2 @3xl:grid-cols-3'>\n              {CATEGORIES.map((category) => (\n                <CategoryCard\n                  key={category.id}\n                  category={category}\n                  count={countOf(category)}\n                  isSearching={isSearching}\n                />\n              ))}\n            </ul>\n          </section>\n\n          <div className='grid gap-10 @3xl:grid-cols-[minmax(0,1fr)_20rem] @3xl:gap-8'>\n            <section\n              aria-labelledby={popularId}\n              className='flex flex-col gap-3'\n            >\n              <h2 id={popularId} className='px-1 text-[13px] font-medium'>\n                Popular articles\n              </h2>\n              <ul className={cn(CARD, 'flex flex-col p-1')}>\n                {POPULAR.map((article) => (\n                  <li key={article.id}>\n                    <a\n                      href={article.href}\n                      className={cn(\n                        'group hover:bg-foreground/[0.03] flex items-center gap-3 rounded-lg px-3 py-2.5 transition-colors duration-100',\n                        FOCUS_RING\n                      )}\n                    >\n                      <span className='flex min-w-0 flex-1 flex-col gap-0.5'>\n                        <span className='truncate text-[13px] font-medium'>\n                          {article.title}\n                        </span>\n                        <span className='text-muted-foreground text-xs'>\n                          {categoryTitleOf(article)}\n                        </span>\n                      </span>\n                      <ChevronRightIcon className='text-muted-foreground size-4 shrink-0 transition-transform duration-100 group-hover:translate-x-0.5' />\n                    </a>\n                  </li>\n                ))}\n              </ul>\n            </section>\n\n            <section\n              aria-label='Contact support'\n              className={cn(CARD, 'flex flex-col gap-4 self-start p-5')}\n            >\n              <div className='flex items-center gap-3'>\n                <Avatar seed={CONTACT.person} className='size-10' />\n                <div className='flex min-w-0 flex-col'>\n                  <p className='text-sm font-medium'>{CONTACT.person}</p>\n                  <p className='text-muted-foreground text-xs'>\n                    {CONTACT.role}\n                  </p>\n                </div>\n              </div>\n              <div className='flex flex-col gap-1'>\n                <p className='text-[13px] font-medium'>Still stuck?</p>\n                <p className='text-muted-foreground text-[13px] text-pretty'>\n                  {CONTACT.lead}\n                </p>\n                <p className='text-muted-foreground text-xs'>{CONTACT.hours}</p>\n              </div>\n              <div className='flex flex-wrap gap-2'>\n                <Button\n                  nativeButton={false}\n                  render={<a href={CONTACT.chatHref} />}\n                >\n                  Start a chat\n                </Button>\n                <Button\n                  variant='outline'\n                  nativeButton={false}\n                  render={<a href={CONTACT.emailHref} />}\n                >\n                  Email us\n                </Button>\n              </div>\n            </section>\n          </div>\n        </div>\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/help-center-01/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/help-center/help-center-01/help-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 {\n  EASE_OUT_STRONG,\n  INSTANT,\n  SPRING,\n} from '@/registry/ndeko/lib/motion-presets';\nimport { FOCUS_RING } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Kbd } from '@/registry/ndeko/ui/kbd';\n\nimport { CATEGORIES, SITE, type Article } 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 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, isListed: boolean) {\n  const hasActive = activeIndex >= 0;\n  if (!isListed || !hasActive) {\n    return undefined;\n  }\n  return optionIdOf(listId, activeIndex);\n}\n\nfunction categoryTitleOf(article: Article) {\n  const category = CATEGORIES.find(\n    (candidate) => candidate.id === article.category\n  );\n  return category?.title ?? '';\n}\n\nfunction allResultsLineOf(count: number, query: string) {\n  const trimmed = query.trim();\n  if (count === 1) {\n    return `See the 1 result for “${trimmed}”`;\n  }\n  return `See all ${count} results for “${trimmed}”`;\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 HelpSearchProps = {\n  query: string;\n  isOpen: boolean;\n  activeIndex: number;\n  suggestions: Article[];\n  /** All the articles that match, of which the first few are suggested. */\n  matchCount: number;\n  pressed: string | null;\n  /** While the demonstration plays, the suggestions show without the focus and a click elsewhere leaves them 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 HelpSearch({\n  query,\n  isOpen,\n  activeIndex,\n  suggestions,\n  matchCount,\n  pressed,\n  isDemonstrating,\n  onType,\n  onFocus,\n  onMove,\n  onEscape,\n  onClose,\n}: HelpSearchProps) {\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    if (isEnter && isListed) {\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\n      ref={wrapperRef}\n      onBlur={closeWhenLeaving}\n      className='relative w-full max-w-xl text-start'\n    >\n      <label htmlFor={inputId} className='sr-only'>\n        Search the help center\n      </label>\n      <SearchIcon className='text-muted-foreground pointer-events-none absolute start-4 top-1/2 size-[18px] -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 payroll, people, taxes'\n        value={query}\n        onChange={(event) => onType(event.target.value)}\n        onFocus={onFocus}\n        onKeyDown={handleKeys}\n        className='h-12 rounded-xl ps-11 pe-4 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 articles'\n                className='flex flex-col'\n              >\n                {suggestions.map((article, index) => {\n                  const isActive = index === activeIndex;\n                  return (\n                    <li key={article.id} role='none'>\n                      <a\n                        id={optionIdOf(listId, index)}\n                        role='option'\n                        aria-selected={isActive}\n                        href={article.href}\n                        tabIndex={-1}\n                        onMouseDown={(event) => event.preventDefault()}\n                        className='relative isolate flex min-h-11 flex-col justify-center gap-0.5 rounded-lg px-3 py-1.5 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='flex items-center gap-2 text-[13px] font-medium'>\n                          <MarkedTitle title={article.title} words={words} />\n                        </span>\n                        <span className='text-muted-foreground text-xs'>\n                          {categoryTitleOf(article)}\n                        </span>\n                      </a>\n                    </li>\n                  );\n                })}\n              </ul>\n            )}\n            {!hasSuggestions && (\n              <p className='text-muted-foreground px-3 py-3 text-[13px] text-pretty'>\n                No article mentions these words yet. Try another word, or write\n                to us below.\n              </p>\n            )}\n            <div className='flex flex-wrap items-center gap-x-3 gap-y-2 px-3 pt-2 pb-1.5'>\n              {hasSuggestions && (\n                <a\n                  href={SITE.searchHref}\n                  className={cn(\n                    'text-primary-ink inline-flex items-center gap-1 rounded-sm text-xs font-medium',\n                    FOCUS_RING\n                  )}\n                >\n                  {allResultsLineOf(matchCount, query)}\n                  <ArrowRightIcon className='size-3.5' />\n                </a>\n              )}\n              <p\n                aria-hidden='true'\n                className='text-muted-foreground ms-auto flex items-center gap-1 text-xs'\n              >\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                <Kbd\n                  className={cn(\n                    KEY_MOTION,\n                    pressedQuietOf(pressed === 'key-escape')\n                  )}\n                >\n                  Esc\n                </Kbd>\n              </p>\n            </div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/help-center-01/help-search.tsx"
    },
    {
      "path": "registry/ndeko/blocks/help-center/help-center-01/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\nimport { keyDelayOf, prefixesOf } from '@/registry/ndeko/lib/demonstration';\n\nimport { matchesOf } from './match';\n\nexport type HelpState = {\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 HelpAction =\n  | { type: 'typed'; value: string }\n  | { type: 'focused' }\n  | { type: 'moved'; by: 1 | -1 }\n  | { type: 'escaped' }\n  | { type: 'closed' };\n\ntype Step = SessionStep<HelpState, HelpAction>;\n\nexport const SUGGESTION_LIMIT = 5;\n\nconst NOTHING_HIGHLIGHTED = -1;\n\nexport const INITIAL: HelpState = {\n  query: '',\n  isOpen: false,\n  activeIndex: NOTHING_HIGHLIGHTED,\n};\n\nexport function suggestionsIn(state: HelpState) {\n  const matches = matchesOf(state.query);\n  return matches.slice(0, 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: HelpState, by: 1 | -1): HelpState {\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 suggestions first, and clears the field when they are already closed. */\nfunction escaped(state: HelpState): HelpState {\n  if (state.isOpen) {\n    return { ...state, isOpen: false, activeIndex: NOTHING_HIGHLIGHTED };\n  }\n  return INITIAL;\n}\n\nexport function reducer(state: HelpState, action: HelpAction): HelpState {\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 = 'payslip';\n\nconst KEY_MS = 110;\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 * Someone types a word slowly enough for the counts below to follow each letter, walks the\n * suggestions, and leaves with Escape twice: the round ends on the empty field it started from.\n */\nexport const SCRIPT: Step[] = [\n  ...typing(QUERY, 1500),\n  arrow(1400, 1),\n  arrow(700, 1),\n  {\n    after: 2000,\n    by: 'demo',\n    press: 'key-escape',\n    action: { type: 'escaped' },\n  },\n  { after: 900, by: 'demo', action: { type: 'escaped' } },\n];\n\n/** Under reduced motion the word is typed, the counts show the matches and the best one is highlighted. */\nexport const RESTING: HelpState = {\n  query: QUERY,\n  isOpen: true,\n  activeIndex: 0,\n};\n\nexport const LOOP_AFTER_MS = 2600;\n",
      "type": "registry:component",
      "target": "components/blocks/help-center-01/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/help-center/help-center-01/match.ts",
      "content": "import { ARTICLES, type Article, type CategoryId } 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  article: Article;\n  order: number;\n  score: number;\n};\n\n/** A single letter matches half the help center, 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\nexport function markedPartsOf(text: string, words: string[]) {\n  const lowered = text.toLowerCase();\n  const ranges = words.flatMap((word) => rangesOfWord(lowered, word));\n  const parts: MarkedPart[] = [];\n  let cursor = 0;\n  for (const range of mergedRanges(ranges)) {\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\n/** Every typed word must be found in the title or in the other words people use for it. */\nfunction scoreOf(article: Article, words: string[]) {\n  const title = article.title.toLowerCase();\n  const haystack = `${title} ${article.terms}`;\n  const isMatch = words.every((word) => haystack.includes(word));\n  if (!isMatch) {\n    return 0;\n  }\n  const inTitle = words.filter((word) => title.includes(word));\n  return 1 + inTitle.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/** Articles that hold every typed word, the ones that say it in their title first. */\nexport function matchesOf(query: string) {\n  const words = wordsOf(query);\n  if (words.length === 0) {\n    return [];\n  }\n  const scored = ARTICLES.map((article, order) => ({\n    article,\n    order,\n    score: scoreOf(article, words),\n  }));\n  const matching = scored.filter((entry) => entry.score > 0);\n  matching.sort(byScoreThenOrder);\n  return matching.map((entry) => entry.article);\n}\n\nexport function totalIn(category: CategoryId) {\n  const inCategory = ARTICLES.filter(\n    (article) => article.category === category\n  );\n  return inCategory.length;\n}\n\nexport function countIn(matches: Article[], category: CategoryId) {\n  const inCategory = matches.filter((article) => article.category === category);\n  return inCategory.length;\n}\n",
      "type": "registry:component",
      "target": "components/blocks/help-center-01/match.ts"
    },
    {
      "path": "registry/ndeko/blocks/help-center/help-center-01/data.ts",
      "content": "import {\n  CalendarCheckIcon,\n  ReceiptIcon,\n  RocketIcon,\n  ShieldCheckIcon,\n  UsersIcon,\n  WalletIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\n\nexport type CategoryId =\n  'start' | 'payroll' | 'people' | 'taxes' | 'payments' | 'account';\n\nexport type Category = {\n  id: CategoryId;\n  title: string;\n  lead: string;\n  href: string;\n};\n\nexport type Article = {\n  id: string;\n  title: string;\n  category: CategoryId;\n  /** Other words people type for the same thing. */\n  terms: string;\n  href: string;\n};\n\nexport const SITE = {\n  name: 'Pennywort',\n  homeHref: '#',\n  searchHref: '#search',\n};\n\nexport const CATEGORIES: Category[] = [\n  {\n    id: 'start',\n    title: 'Getting started',\n    lead: 'Company details, pay schedule and your bank',\n    href: '#getting-started',\n  },\n  {\n    id: 'payroll',\n    title: 'Running payroll',\n    lead: 'Runs, payslips, bonuses and corrections',\n    href: '#running-payroll',\n  },\n  {\n    id: 'people',\n    title: 'People',\n    lead: 'Starters, leavers, salaries and leave',\n    href: '#people',\n  },\n  {\n    id: 'taxes',\n    title: 'Taxes and filings',\n    lead: 'Tax codes, monthly returns and year end',\n    href: '#taxes',\n  },\n  {\n    id: 'payments',\n    title: 'Payments',\n    lead: 'Bank accounts, pending payments and refunds',\n    href: '#payments',\n  },\n  {\n    id: 'account',\n    title: 'Account and security',\n    lead: 'Admins, sign-in and your plan',\n    href: '#account',\n  },\n];\n\nexport const CATEGORY_GLYPH: Record<CategoryId, Icon> = {\n  start: RocketIcon,\n  payroll: CalendarCheckIcon,\n  people: UsersIcon,\n  taxes: ReceiptIcon,\n  payments: WalletIcon,\n  account: ShieldCheckIcon,\n};\n\nexport const ARTICLES: Article[] = [\n  {\n    id: 'set-up-company',\n    title: 'Set up your company',\n    category: 'start',\n    terms: 'begin new account details',\n    href: '#set-up-company',\n  },\n  {\n    id: 'invite-accountant',\n    title: 'Invite your accountant',\n    category: 'start',\n    terms: 'bookkeeper access share',\n    href: '#invite-accountant',\n  },\n  {\n    id: 'import-employees',\n    title: 'Import employees from a spreadsheet',\n    category: 'start',\n    terms: 'csv upload staff people',\n    href: '#import-employees',\n  },\n  {\n    id: 'pay-schedule',\n    title: 'Choose your pay schedule',\n    category: 'start',\n    terms: 'monthly weekly payday frequency',\n    href: '#pay-schedule',\n  },\n  {\n    id: 'connect-bank',\n    title: 'Connect your bank',\n    category: 'start',\n    terms: 'bank account link payments',\n    href: '#connect-bank',\n  },\n  {\n    id: 'first-payroll',\n    title: 'Run your first payroll',\n    category: 'payroll',\n    terms: 'pay salaries start',\n    href: '#first-payroll',\n  },\n  {\n    id: 'correct-payslip',\n    title: 'Correct a payslip after it was sent',\n    category: 'payroll',\n    terms: 'mistake wrong amount fix edit',\n    href: '#correct-payslip',\n  },\n  {\n    id: 'pay-bonus',\n    title: 'Pay a bonus outside the usual run',\n    category: 'payroll',\n    terms: 'extra one-off commission',\n    href: '#pay-bonus',\n  },\n  {\n    id: 'undo-run',\n    title: 'Undo a payroll run before payday',\n    category: 'payroll',\n    terms: 'cancel revert mistake',\n    href: '#undo-run',\n  },\n  {\n    id: 'preview-payslips',\n    title: 'Preview payslips before you approve a run',\n    category: 'payroll',\n    terms: 'check review draft',\n    href: '#preview-payslips',\n  },\n  {\n    id: 'change-payday',\n    title: 'Move the payday of one run',\n    category: 'payroll',\n    terms: 'date holiday earlier',\n    href: '#change-payday',\n  },\n  {\n    id: 'payslip-access',\n    title: 'Let employees see their payslips',\n    category: 'payroll',\n    terms: 'portal download send email',\n    href: '#payslip-access',\n  },\n  {\n    id: 'new-starter',\n    title: 'Add a new starter',\n    category: 'people',\n    terms: 'hire employee joiner onboarding',\n    href: '#new-starter',\n  },\n  {\n    id: 'leaver',\n    title: 'Record a leaver and their final pay',\n    category: 'people',\n    terms: 'resign quit last payslip',\n    href: '#leaver',\n  },\n  {\n    id: 'change-salary',\n    title: 'Change a salary',\n    category: 'people',\n    terms: 'raise pay rise rate',\n    href: '#change-salary',\n  },\n  {\n    id: 'unpaid-leave',\n    title: 'Set up unpaid leave',\n    category: 'people',\n    terms: 'absence time off',\n    href: '#unpaid-leave',\n  },\n  {\n    id: 'home-address',\n    title: 'Update a home address',\n    category: 'people',\n    terms: 'moved contact details',\n    href: '#home-address',\n  },\n  {\n    id: 'tax-code',\n    title: 'Change a tax code',\n    category: 'taxes',\n    terms: 'code notice update',\n    href: '#tax-code',\n  },\n  {\n    id: 'monthly-return',\n    title: 'File the monthly tax return',\n    category: 'taxes',\n    terms: 'submission filing deadline',\n    href: '#monthly-return',\n  },\n  {\n    id: 'year-end',\n    title: 'Download a year-end summary',\n    category: 'taxes',\n    terms: 'annual report payslip totals',\n    href: '#year-end',\n  },\n  {\n    id: 'rejected-filing',\n    title: 'Fix a rejected filing',\n    category: 'taxes',\n    terms: 'error refused resubmit',\n    href: '#rejected-filing',\n  },\n  {\n    id: 'pension',\n    title: 'How pension contributions are worked out',\n    category: 'taxes',\n    terms: 'retirement deduction',\n    href: '#pension',\n  },\n  {\n    id: 'student-loans',\n    title: 'Student loan deductions',\n    category: 'taxes',\n    terms: 'repayment plan',\n    href: '#student-loans',\n  },\n  {\n    id: 'change-bank',\n    title: 'Change the bank account salaries are paid from',\n    category: 'payments',\n    terms: 'switch account details',\n    href: '#change-bank',\n  },\n  {\n    id: 'pending-payment',\n    title: 'Why a payment is still pending',\n    category: 'payments',\n    terms: 'late delayed not arrived salary',\n    href: '#pending-payment',\n  },\n  {\n    id: 'overpayment',\n    title: 'Recover an overpayment',\n    category: 'payments',\n    terms: 'refund paid too much payslip',\n    href: '#overpayment',\n  },\n  {\n    id: 'direct-debit',\n    title: 'Pay your plan by direct debit',\n    category: 'payments',\n    terms: 'billing invoice card',\n    href: '#direct-debit',\n  },\n  {\n    id: 'two-step',\n    title: 'Turn on two-step sign-in',\n    category: 'account',\n    terms: 'security code login',\n    href: '#two-step',\n  },\n  {\n    id: 'another-admin',\n    title: 'Add another admin',\n    category: 'account',\n    terms: 'permissions owner access',\n    href: '#another-admin',\n  },\n  {\n    id: 'change-plan',\n    title: 'Change your plan',\n    category: 'account',\n    terms: 'upgrade downgrade price',\n    href: '#change-plan',\n  },\n];\n\nexport const POPULAR_IDS = [\n  'first-payroll',\n  'correct-payslip',\n  'new-starter',\n  'change-bank',\n  'year-end',\n];\n\nexport const CONTACT = {\n  person: 'Dana Whitfield',\n  role: 'Support lead',\n  lead: 'Dana and the support team answer within one working day.',\n  hours: 'Monday to Friday, 8:00 to 18:00 CET',\n  chatHref: '#chat',\n  emailHref: 'mailto:help@pennywort.example',\n};\n",
      "type": "registry:component",
      "target": "components/blocks/help-center-01/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "help-center"
  ],
  "type": "registry:block"
}