{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "auth-04",
  "title": "Sign in and pick a workspace",
  "description": "Google or GitHub in one press, or an email and a six-digit code, then the workspaces with their members and a dashed row that creates one; the card resizes from step to step, and the mark of the workspace picked travels to the middle as it turns into Opening Brightmoor, then lands on a check.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/brand-logos.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/field.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/morph-button.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/otp-field.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/status-orb.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/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/auth/auth-04/index.tsx",
      "content": "'use client';\n\nimport { LayoutGroup } from 'motion/react';\nimport { useId } from 'react';\n\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\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 { AuthFrame, StepSwap } from './auth-frame';\nimport type { ProviderId } from './data';\nimport {\n  CHECK_MS,\n  INITIAL,\n  LOOP_AFTER_MS,\n  OPEN_MS,\n  PROVIDER_MS,\n  reducer,\n  RESENT_MS,\n  RESTING,\n  SCRIPT,\n  SEND_MS,\n  workspaceOf,\n  type AuthAction,\n  type AuthState,\n  type AuthStep,\n} from './session';\nimport {\n  CodeStep,\n  DoneStep,\n  OpeningStep,\n  StartStep,\n  WorkspaceStep,\n} from './steps';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nconst HEADING = '[data-step-heading]';\n\n/** A step that leaves stays in the page while it fades, ahead of the one that arrives: the last match is the one on screen. */\nfunction lastOf(elements: NodeListOf<HTMLElement> | undefined) {\n  if (!elements) {\n    return null;\n  }\n  const lastIndex = elements.length - 1;\n  return elements.item(lastIndex);\n}\n\nfunction pickedAt(state: AuthState, step: AuthStep) {\n  if (state.step !== step) {\n    return null;\n  }\n  return workspaceOf(state, state.pickedId) ?? null;\n}\n\nexport default function Auth04() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const { schedule, clearAll } = useTimeouts();\n  const groupId = useId();\n  const opening = pickedAt(state, 'opening');\n  const entered = pickedAt(state, 'done');\n  const message = spokenUnless(isAutoplaying, state.spoken);\n  const canReplay = isFinished && !isAutoplaying;\n\n  function focusLater(selector: string) {\n    requestAnimationFrame(() => {\n      const matches = ref.current?.querySelectorAll<HTMLElement>(selector);\n      const target = lastOf(matches);\n      target?.focus();\n    });\n  }\n\n  /** A person who moves to a new step lands on its title. */\n  function actAndLand(action: AuthAction) {\n    act(action);\n    focusLater(HEADING);\n  }\n\n  function requestCode() {\n    const after = reducer(state, { type: 'codeRequested' });\n    act({ type: 'codeRequested' });\n    if (!after.isSending) {\n      focusLater('[data-email]');\n      return;\n    }\n    schedule(() => actAndLand({ type: 'codeSent' }), SEND_MS);\n  }\n\n  function pressProvider(id: ProviderId) {\n    act({ type: 'providerPressed', id });\n    schedule(() => actAndLand({ type: 'providerReturned', id }), PROVIDER_MS);\n  }\n\n  /** The code is read only while it is checked, so the outcome is known when it is sent. */\n  function submitCode() {\n    const after = reducer(state, { type: 'codeSubmitted' });\n    act({ type: 'codeSubmitted' });\n    if (!after.isChecking) {\n      focusLater('[data-code-slot=\"0\"]');\n      return;\n    }\n    const checked = reducer(after, { type: 'codeChecked' });\n    const isIn = checked.step === 'workspace';\n    schedule(() => {\n      act({ type: 'codeChecked' });\n      if (isIn) {\n        focusLater(HEADING);\n        return;\n      }\n      focusLater('[data-code-slot=\"0\"]');\n    }, CHECK_MS);\n  }\n\n  function resend() {\n    act({ type: 'resendPressed' });\n    schedule(() => act({ type: 'resendFaded' }), RESENT_MS);\n  }\n\n  function restartSignIn() {\n    clearAll();\n    actAndLand({ type: 'restarted' });\n  }\n\n  function openWhenReady() {\n    schedule(() => actAndLand({ type: 'opened' }), OPEN_MS);\n  }\n\n  function pick(id: string) {\n    actAndLand({ type: 'workspacePicked', id });\n    openWhenReady();\n  }\n\n  function toggleCreate() {\n    const wasOpen = state.isCreating;\n    act({ type: 'createToggled' });\n    if (wasOpen) {\n      focusLater('[data-create-workspace]');\n      return;\n    }\n    focusLater('[data-new-workspace]');\n  }\n\n  function create() {\n    const after = reducer(state, { type: 'createSubmitted' });\n    act({ type: 'createSubmitted' });\n    if (after.step !== 'opening') {\n      focusLater('[data-new-workspace]');\n      return;\n    }\n    focusLater(HEADING);\n    openWhenReady();\n  }\n\n  function switchWorkspace() {\n    actAndLand({ type: 'switchPressed' });\n  }\n\n  /** A step on its way belongs to the round it was asked for in. */\n  function replay() {\n    clearAll();\n    restart();\n  }\n\n  return (\n    <ClockGate isActive={isInView}>\n      <LayoutGroup id={groupId}>\n        <AuthFrame\n          ref={ref}\n          aside={\n            <ReplayButton\n              isShown={canReplay}\n              onReplay={replay}\n              label='Replay'\n            />\n          }\n          footer='Trouble signing in? A workspace admin can send you a new invitation.'\n          announcer={<LiveRegion message={message} />}\n        >\n          <StepSwap stepKey={state.step}>\n            {state.step === 'start' && (\n              <StartStep\n                state={state}\n                pressed={pressed}\n                onAction={act}\n                onRequest={requestCode}\n                onProvider={pressProvider}\n              />\n            )}\n            {state.step === 'code' && (\n              <CodeStep\n                state={state}\n                pressed={pressed}\n                onAction={act}\n                onSubmit={submitCode}\n                onResend={resend}\n                onRestart={restartSignIn}\n              />\n            )}\n            {state.step === 'workspace' && (\n              <WorkspaceStep\n                state={state}\n                pressed={pressed}\n                onAction={act}\n                onPick={pick}\n                onToggleCreate={toggleCreate}\n                onCreate={create}\n                onRestart={restartSignIn}\n              />\n            )}\n            {opening && <OpeningStep workspace={opening} />}\n            {entered && (\n              <DoneStep\n                workspace={entered}\n                account={state.account}\n                onSwitch={switchWorkspace}\n                onRestart={restartSignIn}\n              />\n            )}\n          </StepSwap>\n        </AuthFrame>\n      </LayoutGroup>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/auth-04/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/auth/auth-04/steps.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { Fragment } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { BrandLogo } from '@/registry/ndeko/lib/brand-logos';\nimport {\n  pressedQuietOf,\n  pressedSolidOf,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  ChevronRightIcon,\n  LoaderCircleIcon,\n  MailIcon,\n  PlusIcon,\n  ShieldCheckIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\nimport { fadePresence, springOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport { Field, FieldLabel } from '@/registry/ndeko/ui/field';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\nimport {\n  OTPField,\n  OTPFieldInput,\n  OTPFieldSeparator,\n} from '@/registry/ndeko/ui/otp-field';\nimport { StatusOrb } from '@/registry/ndeko/ui/status-orb';\n\nimport { CardHead, FieldProblem } from './auth-frame';\nimport {\n  CODE_LENGTH,\n  EMAIL_PLACEHOLDER,\n  PERSON_NAME,\n  PREVIEW_CODE_LABEL,\n  PRODUCT_NAME,\n  PROVIDERS,\n  WORKSPACE_NAME_MAX_LENGTH,\n  type Provider,\n  type ProviderId,\n  type Workspace,\n} from './data';\nimport type { AuthAction, AuthState } from './session';\n\nconst SLOTS = Array.from({ length: CODE_LENGTH }, (_, index) => index);\n\nconst SEPARATOR_AFTER = 2;\n\nconst SEND_LABELS: Record<MorphState, string> = {\n  idle: 'Email me a code',\n  busy: 'Sending code',\n  done: 'Code sent',\n};\n\nconst SIGN_IN_LABELS: Record<MorphState, string> = {\n  idle: 'Sign in',\n  busy: 'Checking',\n  done: 'Signed in',\n};\n\nconst ROW = [\n  'bg-foreground/[0.03] flex w-full cursor-pointer items-center gap-3 rounded-lg px-2.5 py-2 text-start outline-none',\n  'transition-[background-color,scale] duration-150 ease-(--ease-out-strong) active:scale-[0.98]',\n  'hover:bg-foreground/[0.06] focus-visible:ring-ring/25 focus-visible:ring-[3px]',\n].join(' ');\n\nfunction busyOf(isBusy: boolean): MorphState {\n  if (isBusy) {\n    return 'busy';\n  }\n  return 'idle';\n}\n\nfunction membersOf(count: number) {\n  if (count === 1) {\n    return '1 member';\n  }\n  return `${count} members`;\n}\n\nfunction slotLabelOf(index: number) {\n  const position = index + 1;\n  return `Digit ${position} of ${CODE_LENGTH}`;\n}\n\nfunction resendLabelOf(isResent: boolean) {\n  if (isResent) {\n    return 'New code sent';\n  }\n  return 'Send a new code';\n}\n\nfunction providerLabelOf(provider: Provider, isConnecting: boolean) {\n  if (isConnecting) {\n    return `Waiting for ${provider.name}`;\n  }\n  return `Continue with ${provider.name}`;\n}\n\nfunction MarkTile({ icon: TileIcon }: { icon: Icon }) {\n  return (\n    <span className='keycap-3d text-muted-foreground flex size-10 items-center justify-center rounded-lg'>\n      <TileIcon className='size-5' />\n    </span>\n  );\n}\n\ntype ProviderButtonProps = {\n  provider: Provider;\n  connecting: ProviderId | null;\n  isLocked: boolean;\n  isPressed: boolean;\n  onPress: (id: ProviderId) => void;\n};\n\nfunction ProviderButton({\n  provider,\n  connecting,\n  isLocked,\n  isPressed,\n  onPress,\n}: ProviderButtonProps) {\n  const isConnecting = connecting === provider.id;\n  const label = providerLabelOf(provider, isConnecting);\n\n  return (\n    <Button\n      type='button'\n      variant='outline'\n      size='lg'\n      disabled={isLocked}\n      focusableWhenDisabled\n      onClick={() => onPress(provider.id)}\n      className={cn('w-full', pressedQuietOf(isPressed))}\n    >\n      <AnimatedSize\n        as='span'\n        axis='width'\n        contentClassName='relative flex items-center gap-2'\n      >\n        <Swap swapKey={String(isConnecting)}>\n          {isConnecting && <LoaderCircleIcon className='animate-spin' />}\n          {!isConnecting && <BrandLogo brand={provider.brand} />}\n        </Swap>\n        <Swap swapKey={label}>{label}</Swap>\n      </AnimatedSize>\n    </Button>\n  );\n}\n\ntype StartStepProps = {\n  state: AuthState;\n  pressed: string | null;\n  onAction: (action: AuthAction) => void;\n  onRequest: () => void;\n  onProvider: (id: ProviderId) => void;\n};\n\nexport function StartStep({\n  state,\n  pressed,\n  onAction,\n  onRequest,\n  onProvider,\n}: StartStepProps) {\n  const isWaiting = state.connecting !== null;\n  const isLocked = isWaiting || state.isSending;\n\n  function submit(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    onRequest();\n  }\n\n  return (\n    <>\n      <CardHead\n        mark={<MarkTile icon={MailIcon} />}\n        title={`Sign in to ${PRODUCT_NAME}`}\n      >\n        One press with an account you already have, or a code by email. No\n        password to remember.\n      </CardHead>\n      <div className='flex flex-col gap-2'>\n        {PROVIDERS.map((provider) => (\n          <ProviderButton\n            key={provider.id}\n            provider={provider}\n            connecting={state.connecting}\n            isLocked={isLocked}\n            isPressed={pressed === `provider-${provider.id}`}\n            onPress={onProvider}\n          />\n        ))}\n      </div>\n      <div className='text-muted-foreground flex items-center gap-3 text-xs'>\n        <span aria-hidden='true' className='bg-border h-(--hairline) flex-1' />\n        or with your email\n        <span aria-hidden='true' className='bg-border h-(--hairline) flex-1' />\n      </div>\n      <form noValidate onSubmit={submit} className='flex flex-col gap-4'>\n        <Field invalid={state.emailError !== null} className='gap-0'>\n          <FieldLabel className='mb-1.5'>Work email</FieldLabel>\n          <Input\n            type='email'\n            inputMode='email'\n            autoComplete='email'\n            data-email\n            placeholder={EMAIL_PLACEHOLDER}\n            value={state.email}\n            readOnly={isLocked}\n            onChange={(event) =>\n              onAction({ type: 'emailTyped', value: event.target.value })\n            }\n          />\n          <FieldProblem problem={state.emailError} />\n        </Field>\n        <MorphButton\n          type='submit'\n          size='lg'\n          state={busyOf(state.isSending)}\n          labels={SEND_LABELS}\n          disabled={isWaiting}\n          className={cn('w-full', pressedSolidOf(pressed === 'send'))}\n        />\n      </form>\n    </>\n  );\n}\n\ntype CodeStepProps = {\n  state: AuthState;\n  pressed: string | null;\n  onAction: (action: AuthAction) => void;\n  onSubmit: () => void;\n  onResend: () => void;\n  onRestart: () => void;\n};\n\nexport function CodeStep({\n  state,\n  pressed,\n  onAction,\n  onSubmit,\n  onResend,\n  onRestart,\n}: CodeStepProps) {\n  const email = state.email.trim();\n  const resendLabel = resendLabelOf(state.isResent);\n\n  function submit(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    onSubmit();\n  }\n\n  return (\n    <>\n      <CardHead\n        mark={<MarkTile icon={ShieldCheckIcon} />}\n        title='Check your email'\n      >\n        Enter the code sent to{' '}\n        <span className='text-foreground font-medium break-all'>{email}</span>.{' '}\n        <Button\n          type='button'\n          variant='link'\n          onClick={onRestart}\n          className='h-auto px-0 text-[13px]'\n        >\n          Use another email\n        </Button>\n      </CardHead>\n      <form noValidate onSubmit={submit} className='flex flex-col gap-5'>\n        <Field invalid={state.codeError !== null} className='gap-0'>\n          <FieldLabel className='mb-1.5'>{`${CODE_LENGTH}-digit code`}</FieldLabel>\n          <OTPField\n            length={CODE_LENGTH}\n            value={state.code}\n            autoComplete='one-time-code'\n            readOnly={state.isChecking}\n            onValueChange={(value) => onAction({ type: 'codeTyped', value })}\n            onValueComplete={onSubmit}\n            className='gap-1.5 @md:gap-2'\n          >\n            {SLOTS.map((index) => (\n              <Fragment key={index}>\n                <OTPFieldInput\n                  data-code-slot={index}\n                  aria-label={slotLabelOf(index)}\n                  className='@md:size-11'\n                />\n                {index === SEPARATOR_AFTER && <OTPFieldSeparator />}\n              </Fragment>\n            ))}\n          </OTPField>\n          <FieldProblem problem={state.codeError} />\n        </Field>\n        <p className='bg-foreground/[0.03] text-muted-foreground rounded-lg px-3 py-2 text-xs'>\n          This preview sends no email. The code it accepts is{' '}\n          <span className='text-foreground font-medium tabular-nums'>\n            {PREVIEW_CODE_LABEL}\n          </span>\n        </p>\n        <div className='flex flex-col-reverse gap-3 @sm:flex-row @sm:items-center @sm:justify-between'>\n          <Button\n            type='button'\n            variant='ghost'\n            size='sm'\n            disabled={state.isResent}\n            onClick={onResend}\n            className='text-muted-foreground self-center @sm:self-auto'\n          >\n            <AnimatedSize\n              as='span'\n              axis='width'\n              contentClassName='relative flex'\n            >\n              <Swap swapKey={resendLabel}>{resendLabel}</Swap>\n            </AnimatedSize>\n          </Button>\n          <MorphButton\n            type='submit'\n            size='lg'\n            state={busyOf(state.isChecking)}\n            labels={SIGN_IN_LABELS}\n            className={cn(\n              'w-full @sm:w-auto',\n              pressedSolidOf(pressed === 'sign-in')\n            )}\n          />\n        </div>\n      </form>\n    </>\n  );\n}\n\ntype CreateRowProps = {\n  state: AuthState;\n  onAction: (action: AuthAction) => void;\n  onToggle: () => void;\n  onCreate: () => void;\n};\n\n/** An empty slot that invites an addition: a dashed row that opens into a name and Create. */\nfunction CreateRow({ state, onAction, onToggle, onCreate }: CreateRowProps) {\n  const fade = fadePresence();\n\n  function submit(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    onCreate();\n  }\n\n  function closeOnEscape(event: React.KeyboardEvent<HTMLFormElement>) {\n    if (event.key !== 'Escape') {\n      return;\n    }\n    event.preventDefault();\n    onToggle();\n  }\n\n  return (\n    <AnimatePresence mode='popLayout' initial={false}>\n      {!state.isCreating && (\n        <motion.div key='row' {...fade}>\n          <button\n            type='button'\n            data-create-workspace\n            onClick={onToggle}\n            className='hairline-border border-foreground/20 text-muted-foreground hover:text-foreground hover:bg-foreground/[0.03] focus-visible:ring-ring/25 flex w-full cursor-pointer items-center gap-3 rounded-lg border-dashed px-2.5 py-2 text-start text-[13px] transition-colors duration-150 outline-none focus-visible:ring-[3px]'\n          >\n            <span className='bg-foreground/[0.05] flex size-7 items-center justify-center rounded-md'>\n              <PlusIcon className='size-4' />\n            </span>\n            Create workspace\n          </button>\n        </motion.div>\n      )}\n      {state.isCreating && (\n        <motion.form\n          key='form'\n          noValidate\n          onSubmit={submit}\n          onKeyDown={closeOnEscape}\n          className='bg-foreground/[0.03] flex flex-col gap-3 rounded-lg p-3'\n          {...fade}\n        >\n          <Field invalid={state.newNameError !== null} className='gap-0'>\n            <FieldLabel className='mb-1.5'>Workspace name</FieldLabel>\n            <Input\n              data-new-workspace\n              autoComplete='organization'\n              placeholder='Your team or company'\n              maxLength={WORKSPACE_NAME_MAX_LENGTH}\n              value={state.newName}\n              onChange={(event) =>\n                onAction({ type: 'newNameTyped', value: event.target.value })\n              }\n            />\n            <FieldProblem problem={state.newNameError} />\n          </Field>\n          <div className='flex justify-end gap-2'>\n            <Button type='button' variant='ghost' size='sm' onClick={onToggle}>\n              Cancel\n            </Button>\n            <Button type='submit' size='sm'>\n              Create and open\n            </Button>\n          </div>\n        </motion.form>\n      )}\n    </AnimatePresence>\n  );\n}\n\ntype WorkspaceMarkProps = {\n  workspace: Workspace;\n  isLarge?: boolean;\n};\n\nfunction markClassOf(isLarge: boolean) {\n  if (isLarge) {\n    return 'size-14 rounded-xl';\n  }\n  return undefined;\n}\n\n/** The mark of the workspace travels from its row to the middle of the card when it opens. */\nexport function WorkspaceMark({\n  workspace,\n  isLarge = false,\n}: WorkspaceMarkProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const travel = springOf(shouldReduceMotion);\n\n  return (\n    <motion.span\n      layoutId={`mark-${workspace.id}`}\n      layoutDependency={isLarge}\n      transition={travel}\n      className='flex shrink-0'\n    >\n      <CompanyMark\n        seed={workspace.name}\n        size='lg'\n        className={markClassOf(isLarge)}\n      />\n    </motion.span>\n  );\n}\n\ntype WorkspaceStepProps = {\n  state: AuthState;\n  pressed: string | null;\n  onAction: (action: AuthAction) => void;\n  onPick: (id: string) => void;\n  onToggleCreate: () => void;\n  onCreate: () => void;\n  onRestart: () => void;\n};\n\nexport function WorkspaceStep({\n  state,\n  pressed,\n  onAction,\n  onPick,\n  onToggleCreate,\n  onCreate,\n  onRestart,\n}: WorkspaceStepProps) {\n  return (\n    <>\n      <CardHead\n        mark={<Avatar seed={PERSON_NAME} className='size-10' />}\n        title='Pick a workspace'\n      >\n        Signed in as{' '}\n        <span className='text-foreground font-medium break-all'>\n          {state.account}\n        </span>\n        .{' '}\n        <Button\n          type='button'\n          variant='link'\n          onClick={onRestart}\n          className='h-auto px-0 text-[13px]'\n        >\n          Not you?\n        </Button>\n      </CardHead>\n      <div className='flex flex-col gap-1.5'>\n        <ul aria-label='Your workspaces' className='flex flex-col gap-1.5'>\n          {state.workspaces.map((workspace) => (\n            <li key={workspace.id}>\n              <button\n                type='button'\n                data-workspace={workspace.id}\n                onClick={() => onPick(workspace.id)}\n                className={cn(\n                  ROW,\n                  pressedQuietOf(pressed === `workspace-${workspace.id}`)\n                )}\n              >\n                <WorkspaceMark workspace={workspace} />\n                <span className='flex min-w-0 flex-1 flex-col'>\n                  <span className='truncate text-[13px] font-medium'>\n                    {workspace.name}\n                  </span>\n                  <span className='text-muted-foreground text-xs'>\n                    {membersOf(workspace.members)}\n                  </span>\n                </span>\n                <ChevronRightIcon className='text-muted-foreground size-4 shrink-0' />\n              </button>\n            </li>\n          ))}\n        </ul>\n        <CreateRow\n          state={state}\n          onAction={onAction}\n          onToggle={onToggleCreate}\n          onCreate={onCreate}\n        />\n      </div>\n    </>\n  );\n}\n\nexport function OpeningStep({ workspace }: { workspace: Workspace }) {\n  return (\n    <div className='flex flex-col items-center gap-4 py-4 text-center'>\n      <WorkspaceMark workspace={workspace} isLarge />\n      <div className='flex flex-col items-center gap-1.5'>\n        <h1\n          data-step-heading\n          tabIndex={-1}\n          className='flex items-center gap-2 text-xl font-semibold text-balance outline-none'\n        >\n          <LoaderCircleIcon className='text-muted-foreground size-5 shrink-0 animate-spin' />\n          {`Opening ${workspace.name}`}\n        </h1>\n        <p className='text-muted-foreground text-[13px]'>\n          Loading its projects and timesheets\n        </p>\n      </div>\n    </div>\n  );\n}\n\ntype DoneStepProps = {\n  workspace: Workspace;\n  account: string;\n  onSwitch: () => void;\n  onRestart: () => void;\n};\n\nexport function DoneStep({\n  workspace,\n  account,\n  onSwitch,\n  onRestart,\n}: DoneStepProps) {\n  return (\n    <div className='flex flex-col items-center gap-5 py-2 text-center'>\n      <span className='relative flex'>\n        <WorkspaceMark workspace={workspace} isLarge />\n        <StatusOrb\n          tone='success'\n          size='sm'\n          className='absolute -end-2.5 -bottom-2.5'\n        />\n      </span>\n      <div className='flex flex-col items-center gap-1.5'>\n        <h1\n          data-step-heading\n          tabIndex={-1}\n          className='text-xl font-semibold text-balance outline-none'\n        >\n          {`You are in ${workspace.name}`}\n        </h1>\n        <p className='text-muted-foreground text-[13px] text-pretty'>\n          {`${membersOf(workspace.members)}. Signed in as `}\n          <span className='text-foreground font-medium break-all'>\n            {account}\n          </span>\n        </p>\n      </div>\n      <div className='flex flex-wrap justify-center gap-2'>\n        <Button type='button' variant='outline' onClick={onSwitch}>\n          Switch workspace\n        </Button>\n        <Button type='button' variant='ghost' onClick={onRestart}>\n          Sign out\n        </Button>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/auth-04/steps.tsx"
    },
    {
      "path": "registry/ndeko/blocks/auth/auth-04/auth-frame.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type Variants } from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { EASE_OUT_STRONG } from '@/registry/ndeko/lib/motion-presets';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { FieldError } from '@/registry/ndeko/ui/field';\n\nimport { PRODUCT_NAME } from './data';\n\nconst STEP_IN = { duration: 0.2, ease: EASE_OUT_STRONG };\n\nconst STEP_OUT = { duration: 0.15, ease: EASE_OUT_STRONG };\n\nconst STEP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.98, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)', transition: STEP_IN },\n  exit: { opacity: 0, scale: 0.98, filter: 'blur(2px)', transition: STEP_OUT },\n};\n\nconst PROBLEM_VARIANTS: Variants = {\n  enter: { height: 0, opacity: 0 },\n  visible: { height: 'auto', opacity: 1, transition: STEP_IN },\n  exit: { height: 0, opacity: 0, transition: STEP_OUT },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1, transition: STEP_IN },\n  exit: { opacity: 0, transition: STEP_OUT },\n};\n\nfunction stepVariantsOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return STEP_VARIANTS;\n}\n\nfunction problemVariantsOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return PROBLEM_VARIANTS;\n}\n\nfunction ProductMark() {\n  return (\n    <svg viewBox='0 0 24 24' aria-hidden='true' className='size-6 shrink-0'>\n      <rect width='24' height='24' rx='6' className='fill-primary' />\n      <path\n        d='M5 10q1.75-2.6 3.5 0t3.5 0 3.5 0 3.5 0'\n        fill='none'\n        strokeOpacity='0.7'\n        strokeWidth='1.8'\n        strokeLinecap='round'\n        className='stroke-primary-foreground'\n      />\n      <path\n        d='M5 15.5q1.75-2.6 3.5 0t3.5 0 3.5 0 3.5 0'\n        fill='none'\n        strokeWidth='1.8'\n        strokeLinecap='round'\n        className='stroke-primary-foreground'\n      />\n    </svg>\n  );\n}\n\ntype AuthFrameProps = {\n  ref?: React.Ref<HTMLDivElement>;\n  /** Sits at the end of the top bar: the Replay of the demonstration. */\n  aside?: React.ReactNode;\n  footer: React.ReactNode;\n  /** The live region of the page, outside the card that resizes. */\n  announcer: React.ReactNode;\n  children: React.ReactNode;\n};\n\n/** A focused page that follows its own width: the window colour, the product mark, one card in the middle. */\nexport function AuthFrame({\n  ref,\n  aside,\n  footer,\n  announcer,\n  children,\n}: AuthFrameProps) {\n  return (\n    <div\n      ref={ref}\n      className='bg-sidebar text-foreground @container flex min-h-dvh w-full flex-col'\n    >\n      <header className='flex h-14 shrink-0 items-center gap-2 px-4 @xl:px-6'>\n        <ProductMark />\n        <span className='text-sm font-semibold'>{PRODUCT_NAME}</span>\n        <span className='ms-auto flex items-center'>{aside}</span>\n      </header>\n      <main className='flex flex-1 flex-col items-center px-4 pt-4 pb-16 @xl:justify-center @xl:pt-0'>\n        <div className='flex w-full max-w-[25rem] flex-col gap-4'>\n          <div className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] rounded-xl p-5 shadow-[0_1px_2px_rgb(0_0_0/0.04)] @md:p-7'>\n            <AnimatedSize contentClassName='relative'>{children}</AnimatedSize>\n          </div>\n          <p className='text-muted-foreground px-2 text-center text-xs text-balance'>\n            {footer}\n          </p>\n        </div>\n      </main>\n      {announcer}\n    </div>\n  );\n}\n\ntype StepSwapProps = {\n  stepKey: string;\n  children: React.ReactNode;\n};\n\n/** The card resizes around it while one step gives way to the next. */\nexport function StepSwap({ stepKey, children }: StepSwapProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = stepVariantsOf(shouldReduceMotion);\n\n  return (\n    <AnimatePresence mode='popLayout' initial={false}>\n      <motion.div\n        key={stepKey}\n        variants={variants}\n        initial='enter'\n        animate='visible'\n        exit='exit'\n        className='flex flex-col gap-6'\n      >\n        {children}\n      </motion.div>\n    </AnimatePresence>\n  );\n}\n\ntype CardHeadProps = {\n  mark: React.ReactNode;\n  title: string;\n  children: React.ReactNode;\n};\n\n/**\n * The title takes the focus when a person moves to its step, so a screen reader says where they\n * are. The demonstration never moves the focus there.\n */\nexport function CardHead({ mark, title, children }: CardHeadProps) {\n  return (\n    <div className='flex flex-col gap-4'>\n      {mark}\n      <div className='flex flex-col gap-1.5'>\n        <h1\n          data-step-heading\n          tabIndex={-1}\n          className='text-xl font-semibold text-balance outline-none'\n        >\n          {title}\n        </h1>\n        <div className='text-muted-foreground text-[13px] text-pretty'>\n          {children}\n        </div>\n      </div>\n    </div>\n  );\n}\n\n/** Rendered inside a `Field`, so the control points to it. It grows in and folds away. */\nexport function FieldProblem({ problem }: { problem: string | null }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = problemVariantsOf(shouldReduceMotion);\n\n  return (\n    <AnimatePresence initial={false}>\n      {problem && (\n        <motion.div\n          key='problem'\n          variants={variants}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          className='overflow-hidden'\n        >\n          <FieldError match className='pt-1.5'>\n            {problem}\n          </FieldError>\n        </motion.div>\n      )}\n    </AnimatePresence>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/auth-04/auth-frame.tsx"
    },
    {
      "path": "registry/ndeko/blocks/auth/auth-04/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\nimport { keyDelayOf, prefixesOf } from '@/registry/ndeko/lib/demonstration';\n\nimport {\n  CODE_LENGTH,\n  PREVIEW_CODE,\n  PROVIDERS,\n  WORKSPACES,\n  type ProviderId,\n  type Workspace,\n} from './data';\n\nexport type AuthStep = 'start' | 'code' | 'workspace' | 'opening' | 'done';\n\nexport type AuthState = {\n  step: AuthStep;\n  email: string;\n  emailError: string | null;\n  isSending: boolean;\n  /** The provider whose button is waiting for the person to come back. */\n  connecting: ProviderId | null;\n  /** Who the person is signed in as, once they are. */\n  account: string;\n  code: string;\n  codeError: string | null;\n  isChecking: boolean;\n  isResent: boolean;\n  /** Counts the refused entries, so a message that comes back nudges again. */\n  attempts: number;\n  workspaces: Workspace[];\n  pickedId: string | null;\n  isCreating: boolean;\n  newName: string;\n  newNameError: string | null;\n  spoken: string;\n};\n\nexport type AuthAction =\n  | { type: 'emailTyped'; value: string }\n  | { type: 'codeRequested' }\n  | { type: 'codeSent' }\n  | { type: 'providerPressed'; id: ProviderId }\n  | { type: 'providerReturned'; id: ProviderId }\n  | { type: 'codeTyped'; value: string }\n  | { type: 'codeSubmitted' }\n  | { type: 'codeChecked' }\n  | { type: 'resendPressed' }\n  | { type: 'resendFaded' }\n  | { type: 'restarted' }\n  | { type: 'workspacePicked'; id: string }\n  | { type: 'opened' }\n  | { type: 'createToggled' }\n  | { type: 'newNameTyped'; value: string }\n  | { type: 'createSubmitted' }\n  | { type: 'switchPressed' };\n\ntype Step = SessionStep<AuthState, AuthAction>;\n\n/** How long the email with the code takes to leave. */\nexport const SEND_MS = 900;\n\n/** How long a code takes to be checked. */\nexport const CHECK_MS = 800;\n\n/** How long a provider takes to send the person back. */\nexport const PROVIDER_MS = 1100;\n\n/** How long a workspace takes to open. */\nexport const OPEN_MS = 1400;\n\n/** How long \"New code sent\" stays on the button. */\nexport const RESENT_MS = 1600;\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@.]+(?:\\.[^\\s@.]+)+$/;\n\nexport const INITIAL: AuthState = {\n  step: 'start',\n  email: '',\n  emailError: null,\n  isSending: false,\n  connecting: null,\n  account: '',\n  code: '',\n  codeError: null,\n  isChecking: false,\n  isResent: false,\n  attempts: 0,\n  workspaces: WORKSPACES,\n  pickedId: null,\n  isCreating: false,\n  newName: '',\n  newNameError: null,\n  spoken: '',\n};\n\nexport function workspaceOf(state: AuthState, id: string | null) {\n  return state.workspaces.find((workspace) => workspace.id === id);\n}\n\nfunction providerOf(id: ProviderId) {\n  return PROVIDERS.find((provider) => provider.id === id);\n}\n\nfunction emailProblemOf(email: string) {\n  const trimmed = email.trim();\n  if (trimmed === '') {\n    return 'Enter your work email';\n  }\n  if (!EMAIL_PATTERN.test(trimmed)) {\n    return 'Enter an email like name@company.com';\n  }\n  return null;\n}\n\nfunction moved(state: AuthState, step: AuthStep, spoken: string): AuthState {\n  return { ...state, step, spoken };\n}\n\nfunction refused(\n  state: AuthState,\n  change: Partial<AuthState>,\n  problem: string\n): AuthState {\n  return {\n    ...state,\n    ...change,\n    attempts: state.attempts + 1,\n    spoken: problem,\n  };\n}\n\nfunction isBusy(state: AuthState) {\n  const isWaiting = state.isSending || state.isChecking;\n  const isConnecting = state.connecting !== null;\n  return isWaiting || isConnecting;\n}\n\nfunction codeRequested(state: AuthState): AuthState {\n  const isOnStart = state.step === 'start';\n  if (!isOnStart || isBusy(state)) {\n    return state;\n  }\n  const problem = emailProblemOf(state.email);\n  if (problem) {\n    return refused(state, { emailError: problem }, problem);\n  }\n  return { ...state, isSending: true, spoken: 'Sending the code' };\n}\n\nfunction codeSent(state: AuthState): AuthState {\n  if (!state.isSending) {\n    return state;\n  }\n  const email = state.email.trim();\n  const next = { ...state, isSending: false, code: '', codeError: null };\n  return moved(next, 'code', `Code sent to ${email}`);\n}\n\nfunction providerPressed(state: AuthState, id: ProviderId): AuthState {\n  const isOnStart = state.step === 'start';\n  if (!isOnStart || isBusy(state)) {\n    return state;\n  }\n  const provider = providerOf(id);\n  if (!provider) {\n    return state;\n  }\n  return { ...state, connecting: id, spoken: `Waiting for ${provider.name}` };\n}\n\nfunction providerReturned(state: AuthState, id: ProviderId): AuthState {\n  const provider = providerOf(id);\n  const isWaiting = state.connecting === id;\n  if (!provider || !isWaiting) {\n    return state;\n  }\n  const next = { ...state, connecting: null, account: provider.account };\n  return moved(next, 'workspace', 'Signed in. Pick a workspace');\n}\n\nfunction codeSubmitted(state: AuthState): AuthState {\n  const isOnCode = state.step === 'code';\n  if (!isOnCode || state.isChecking) {\n    return state;\n  }\n  const isComplete = state.code.length === CODE_LENGTH;\n  if (!isComplete) {\n    const problem = `Enter the ${CODE_LENGTH} digits from the email`;\n    return refused(state, { codeError: problem }, problem);\n  }\n  return { ...state, isChecking: true, spoken: 'Checking the code' };\n}\n\nfunction codeChecked(state: AuthState): AuthState {\n  if (!state.isChecking) {\n    return state;\n  }\n  const isRight = state.code === PREVIEW_CODE;\n  if (!isRight) {\n    const problem =\n      'That code does not match. Check the latest email or send a new one';\n    const change = { isChecking: false, code: '', codeError: problem };\n    return refused(state, change, problem);\n  }\n  const next = { ...state, isChecking: false, account: state.email.trim() };\n  return moved(next, 'workspace', 'Signed in. Pick a workspace');\n}\n\n/** The code being checked stays: clearing it would fail a check of the right code. */\nfunction resendPressed(state: AuthState): AuthState {\n  if (state.isChecking) {\n    return state;\n  }\n  return {\n    ...state,\n    isResent: true,\n    code: '',\n    codeError: null,\n    spoken: 'A new code is on its way',\n  };\n}\n\nfunction workspacePicked(state: AuthState, id: string): AuthState {\n  const workspace = workspaceOf(state, id);\n  const isOnList = state.step === 'workspace';\n  if (!workspace || !isOnList) {\n    return state;\n  }\n  const next = { ...state, pickedId: id, isCreating: false };\n  return moved(next, 'opening', `Opening ${workspace.name}`);\n}\n\nfunction opened(state: AuthState): AuthState {\n  const workspace = workspaceOf(state, state.pickedId);\n  const isOpening = state.step === 'opening';\n  if (!workspace || !isOpening) {\n    return state;\n  }\n  return moved(state, 'done', `You are in ${workspace.name}`);\n}\n\nfunction slugOf(name: string) {\n  const lowered = name.toLowerCase();\n  const joined = lowered.replace(/[^a-z0-9]+/g, '-');\n  return joined.replace(/^-|-$/g, '');\n}\n\nfunction newNameProblemOf(state: AuthState, name: string) {\n  if (name === '') {\n    return 'Name the workspace, for example after your team';\n  }\n  const lowered = name.toLowerCase();\n  const isTaken = state.workspaces.some(\n    (workspace) => workspace.name.toLowerCase() === lowered\n  );\n  if (isTaken) {\n    return `You are already in ${name}. Pick it above`;\n  }\n  return null;\n}\n\n/** A workspace made here has one member, the person, and opens straight away. */\nfunction createSubmitted(state: AuthState): AuthState {\n  const name = state.newName.trim();\n  const problem = newNameProblemOf(state, name);\n  if (problem) {\n    return refused(state, { newNameError: problem }, problem);\n  }\n  const id = `${slugOf(name)}-${state.workspaces.length + 1}`;\n  const workspace: Workspace = { id, name, members: 1 };\n  const next = {\n    ...state,\n    workspaces: [...state.workspaces, workspace],\n    pickedId: id,\n    isCreating: false,\n    newName: '',\n  };\n  return moved(next, 'opening', `Creating and opening ${name}`);\n}\n\nexport function reducer(state: AuthState, action: AuthAction): AuthState {\n  switch (action.type) {\n    case 'emailTyped':\n      return { ...state, email: action.value, emailError: null };\n    case 'codeRequested':\n      return codeRequested(state);\n    case 'codeSent':\n      return codeSent(state);\n    case 'providerPressed':\n      return providerPressed(state, action.id);\n    case 'providerReturned':\n      return providerReturned(state, action.id);\n    case 'codeTyped':\n      return { ...state, code: action.value, codeError: null };\n    case 'codeSubmitted':\n      return codeSubmitted(state);\n    case 'codeChecked':\n      return codeChecked(state);\n    case 'resendPressed':\n      return resendPressed(state);\n    case 'resendFaded':\n      return { ...state, isResent: false };\n    case 'restarted':\n      return { ...INITIAL, email: state.email, spoken: 'Sign in again' };\n    case 'workspacePicked':\n      return workspacePicked(state, action.id);\n    case 'opened':\n      return opened(state);\n    case 'createToggled':\n      return {\n        ...state,\n        isCreating: !state.isCreating,\n        newName: '',\n        newNameError: null,\n      };\n    case 'newNameTyped':\n      return { ...state, newName: action.value, newNameError: null };\n    case 'createSubmitted':\n      return createSubmitted(state);\n    case 'switchPressed':\n      return moved(state, 'workspace', 'Pick a workspace');\n  }\n}\n\nconst KEY_MS = 45;\n\nconst DIGIT_MS = 130;\n\nconst EMAIL = 'dana@tidewell.example';\n\nfunction emailSteps(startAfter: number): Step[] {\n  const prefixes = prefixesOf(EMAIL);\n  return prefixes.map((value, index) => ({\n    after: keyDelayOf(index, startAfter, KEY_MS),\n    by: 'demo',\n    action: { type: 'emailTyped', value },\n  }));\n}\n\nfunction codeSteps(startAfter: number): Step[] {\n  const prefixes = prefixesOf(PREVIEW_CODE);\n  return prefixes.map((value, index) => ({\n    after: keyDelayOf(index, startAfter, DIGIT_MS),\n    by: 'demo',\n    action: { type: 'codeTyped', value },\n  }));\n}\n\n/**\n * The email, the code it brings, then the workspaces. That is where the page rests under reduced\n * motion: signed in, every workspace and the way to make one in sight.\n */\nconst TO_WORKSPACES: Step[] = [\n  ...emailSteps(1200),\n  { after: 450, by: 'demo', press: 'send', action: { type: 'codeRequested' } },\n  { after: SEND_MS, action: { type: 'codeSent' } },\n  ...codeSteps(1100),\n  {\n    after: 450,\n    by: 'demo',\n    press: 'sign-in',\n    action: { type: 'codeSubmitted' },\n  },\n  { after: CHECK_MS, action: { type: 'codeChecked' } },\n];\n\nexport const SCRIPT: Step[] = [\n  ...TO_WORKSPACES,\n  {\n    after: 1700,\n    by: 'demo',\n    press: 'workspace-brightmoor',\n    action: { type: 'workspacePicked', id: 'brightmoor' },\n  },\n  { after: OPEN_MS, action: { type: 'opened' } },\n];\n\nfunction endOf(steps: Step[]) {\n  let state = INITIAL;\n  for (const step of steps) {\n    state = reducer(state, step.action);\n  }\n  return state;\n}\n\nexport const RESTING: AuthState = { ...endOf(TO_WORKSPACES), spoken: '' };\n\nexport const LOOP_AFTER_MS = 3000;\n",
      "type": "registry:component",
      "target": "components/blocks/auth-04/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/auth/auth-04/data.ts",
      "content": "import type { BrandSlug } from '@/registry/ndeko/lib/brand-logos';\n\nexport type ProviderId = 'google' | 'github';\n\nexport type Provider = {\n  id: ProviderId;\n  name: string;\n  brand: BrandSlug;\n  /** The account the provider hands back once it lets the person in. */\n  account: string;\n};\n\nexport type Workspace = {\n  id: string;\n  name: string;\n  members: number;\n};\n\nexport const PRODUCT_NAME = 'Tidewell';\n\nexport const PERSON_NAME = 'Dana Whitfield';\n\nexport const CODE_LENGTH = 6;\n\n/** The preview sends no email, so it says which code it accepts. */\nexport const PREVIEW_CODE = '428913';\n\nexport const PREVIEW_CODE_LABEL = '428 913';\n\nexport const EMAIL_PLACEHOLDER = 'name@company.com';\n\nexport const WORKSPACE_NAME_MAX_LENGTH = 40;\n\nexport const PROVIDERS: Provider[] = [\n  {\n    id: 'google',\n    name: 'Google',\n    brand: 'google',\n    account: 'dana@tidewell.example',\n  },\n  {\n    id: 'github',\n    name: 'GitHub',\n    brand: 'github',\n    account: 'dana-whitfield on GitHub',\n  },\n];\n\nexport const WORKSPACES: Workspace[] = [\n  { id: 'brightmoor', name: 'Brightmoor', members: 24 },\n  { id: 'saltmarsh-press', name: 'Saltmarsh Press', members: 6 },\n  { id: 'kettle-and-pine', name: 'Kettle and Pine', members: 1 },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/auth-04/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "auth"
  ],
  "type": "registry:block"
}