{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-60",
  "title": "Password with morphing reveal",
  "description": "Showing the password turns each dot into its character one after the other, in a monospace face.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "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/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/input/input-60.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useEffect, useId, useRef, useState, type ChangeEvent } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { EyeIcon, EyeOffIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Field, FieldLabel } from '@/registry/ndeko/ui/field';\nimport { Input } from '@/registry/ndeko/ui/input';\n\ntype Morph = { id: number; durationMs: number };\n\nconst SWAP_MS = 150;\nconst STAGGER_MS = 14;\nconst MAX_STAGGER_MS = 210;\n\nconst FIELD_BUTTON =\n  'text-muted-foreground hover:bg-foreground/5 hover:text-foreground focus-visible:ring-ring/25 absolute inset-y-0 end-1 my-auto flex size-6 items-center justify-center rounded-md outline-none transition-[color,background-color,box-shadow] focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50';\n\nconst OVERLAY =\n  'text-foreground pointer-events-none absolute inset-y-0 start-px end-8 flex items-center overflow-hidden ps-2.5 font-mono text-base md:text-[13px]';\n\nconst SWAP_TRANSITION: Transition = {\n  duration: SWAP_MS / 1000,\n  ease: [0.2, 0, 0, 1],\n};\n\nconst SWAP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nfunction swapVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\nfunction inputTypeOf(isVisible: boolean) {\n  if (isVisible) {\n    return 'text';\n  }\n  return 'password';\n}\n\nfunction visibilityGlyphOf(isVisible: boolean) {\n  if (isVisible) {\n    return { key: 'hide', icon: <EyeOffIcon className='size-4' /> };\n  }\n  return { key: 'show', icon: <EyeIcon className='size-4' /> };\n}\n\nfunction staggerOf(index: number) {\n  const stagger = index * STAGGER_MS;\n  return Math.min(stagger, MAX_STAGGER_MS);\n}\n\nfunction cellTransitionOf(index: number): Transition {\n  const delay = staggerOf(index) / 1000;\n  return { ...SWAP_TRANSITION, delay };\n}\n\nfunction nextMorphOf(current: Morph | null, length: number): Morph {\n  const previousId = current?.id ?? 0;\n  const lastStagger = staggerOf(length);\n  return { id: previousId + 1, durationMs: lastStagger + SWAP_MS };\n}\n\nfunction MaskCell({\n  character,\n  index,\n  isVisible,\n}: {\n  character: string;\n  index: number;\n  isVisible: boolean;\n}) {\n  if (isVisible) {\n    return (\n      <MorphingCell index={index} cellKey='character'>\n        {character}\n      </MorphingCell>\n    );\n  }\n  return (\n    <MorphingCell index={index} cellKey='dot'>\n      <span className='size-[0.35em] rounded-full bg-current' />\n    </MorphingCell>\n  );\n}\n\nfunction MorphingCell({\n  index,\n  cellKey,\n  children,\n}: {\n  index: number;\n  cellKey: string;\n  children: React.ReactNode;\n}) {\n  return (\n    <span className='relative inline-flex w-[1ch] items-center justify-center'>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={cellKey}\n          className='inline-flex items-center justify-center'\n          variants={SWAP_VARIANTS}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          transition={cellTransitionOf(index)}\n        >\n          {children}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nexport default function Input60() {\n  const inputId = useId();\n  const inputRef = useRef<HTMLInputElement>(null);\n  const [password, setPassword] = useState('');\n  const [isVisible, setIsVisible] = useState(false);\n  const [morph, setMorph] = useState<Morph | null>(null);\n  const [scrollOffset, setScrollOffset] = useState(0);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const swapVariants = swapVariantsOf(shouldReduceMotion);\n  const visibilityGlyph = visibilityGlyphOf(isVisible);\n  const characters = Array.from(password);\n  const isMorphing = morph !== null;\n  const rendersOverlay = !shouldReduceMotion;\n  const rowOffset = -scrollOffset;\n  const rowStyle = { translate: `${rowOffset}px 0` };\n\n  useEffect(() => {\n    if (!morph) {\n      return;\n    }\n    const timeout = window.setTimeout(() => {\n      setMorph(null);\n    }, morph.durationMs);\n    return () => window.clearTimeout(timeout);\n  }, [morph]);\n\n  function changePassword(event: ChangeEvent<HTMLInputElement>) {\n    setPassword(event.currentTarget.value);\n  }\n\n  function toggleVisibility() {\n    setIsVisible((current) => !current);\n    if (shouldReduceMotion) {\n      return;\n    }\n    const scrollLeft = inputRef.current?.scrollLeft ?? 0;\n    setScrollOffset(scrollLeft);\n    setMorph((current) => nextMorphOf(current, characters.length));\n  }\n\n  return (\n    <Field className='w-full max-w-xs'>\n      <FieldLabel>Password</FieldLabel>\n      <div className='relative'>\n        <Input\n          ref={inputRef}\n          id={inputId}\n          className={cn(\n            'caret-foreground pe-8 font-mono',\n            isMorphing && 'text-transparent'\n          )}\n          type={inputTypeOf(isVisible)}\n          autoComplete='new-password'\n          spellCheck={false}\n          placeholder='At least 12 characters'\n          value={password}\n          onChange={changePassword}\n        />\n        {rendersOverlay && (\n          <span\n            aria-hidden='true'\n            className={cn(OVERLAY, !isMorphing && 'invisible')}\n          >\n            <span className='flex whitespace-pre' style={rowStyle}>\n              {characters.map((character, index) => (\n                <MaskCell\n                  key={index}\n                  character={character}\n                  index={index}\n                  isVisible={isVisible}\n                />\n              ))}\n            </span>\n          </span>\n        )}\n        <button\n          type='button'\n          className={FIELD_BUTTON}\n          onClick={toggleVisibility}\n          aria-label='Show password'\n          aria-pressed={isVisible}\n          aria-controls={inputId}\n        >\n          <AnimatePresence mode='popLayout' initial={false}>\n            <motion.span\n              key={visibilityGlyph.key}\n              className='flex'\n              variants={swapVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n            >\n              {visibilityGlyph.icon}\n            </motion.span>\n          </AnimatePresence>\n        </button>\n      </div>\n    </Field>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "input"
  ],
  "type": "registry:component"
}