{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "add-square",
  "title": "add-square",
  "description": "Animated add square icon",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "icons/add-square.tsx",
      "content": "'use client';\n\nimport type { Variants } from 'motion/react';\nimport { motion, useAnimation } from 'motion/react';\nimport type { HTMLAttributes } from 'react';\nimport { forwardRef } from 'react';\nimport { useIconAnimation } from '@/lib/use-icon-animation';\nimport { cn } from '@/lib/utils';\n\nexport interface AddSquareIconHandle {\n  startAnimation: () => void;\n  stopAnimation: () => void;\n}\n\ninterface AddSquareIconProps extends HTMLAttributes<HTMLDivElement> {\n  size?: number;\n}\n\n// the boundary makes room, then the add mark resolves at its center\nconst containerVariants: Variants = {\n  normal: { scale: 1 },\n  animate: {\n    scale: [1, 0.96, 1.025, 1],\n    transition: { duration: 0.48, ease: [0.23, 1, 0.32, 1] },\n  },\n};\n\nconst plusVariants: Variants = {\n  normal: { rotate: 0, scale: 1 },\n  animate: {\n    rotate: [0, -10, 3, 0],\n    scale: [1, 0.82, 1.08, 1],\n    transition: { duration: 0.42, delay: 0.04, ease: [0.23, 1, 0.32, 1] },\n  },\n};\n\nconst AddSquareIcon = forwardRef<AddSquareIconHandle, AddSquareIconProps>(\n  ({ onMouseEnter, onMouseLeave, className, size = 28, ...props }, ref) => {\n    const controls = useAnimation();\n    const { handleMouseEnter, handleMouseLeave } = useIconAnimation({\n      controls,\n      loops: false,\n      onMouseEnter,\n      onMouseLeave,\n      ref,\n    });\n\n    return (\n      <div\n        className={cn(className)}\n        onMouseEnter={handleMouseEnter}\n        onMouseLeave={handleMouseLeave}\n        {...props}\n      >\n        <svg\n          xmlns=\"http://www.w3.org/2000/svg\"\n          width={size}\n          height={size}\n          viewBox=\"0 0 24 24\"\n          fill=\"none\"\n          overflow=\"visible\"\n        >\n          <motion.g\n            variants={containerVariants}\n            animate={controls}\n            initial=\"normal\"\n            style={{ transformBox: 'view-box', originX: 0.5, originY: 0.5 }}\n          >\n            <path\n              d=\"M2.5 12.0001C2.5 7.52171 2.5 5.28254 3.89124 3.8913C5.28249 2.50005 7.52166 2.50005 12 2.50005C16.4783 2.50005 18.7175 2.50005 20.1088 3.8913C21.5 5.28254 21.5 7.52171 21.5 12.0001C21.5 16.4784 21.5 18.7176 20.1088 20.1088C18.7175 21.5001 16.4783 21.5001 12 21.5001C7.52166 21.5001 5.28249 21.5001 3.89124 20.1088C2.5 18.7176 2.5 16.4784 2.5 12.0001Z\"\n              stroke=\"currentColor\"\n              strokeLinecap=\"round\"\n              strokeLinejoin=\"round\"\n              strokeWidth=\"1.5\"\n            />\n          </motion.g>\n          <motion.path\n            d=\"M12 8.00005V16.0001M16 12.0001L8 12.0001\"\n            stroke=\"currentColor\"\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            strokeWidth=\"1.5\"\n            variants={plusVariants}\n            animate={controls}\n            initial=\"normal\"\n            style={{ transformBox: 'view-box', originX: 0.5, originY: 0.5 }}\n          />\n        </svg>\n      </div>\n    );\n  }\n);\n\nAddSquareIcon.displayName = 'AddSquareIcon';\n\nexport { AddSquareIcon };\n",
      "type": "registry:ui"
    },
    {
      "path": "lib/use-icon-animation.ts",
      "content": "'use client';\n\nimport type { LegacyAnimationControls } from 'motion/react';\nimport { spring, useReducedMotion } from 'motion/react';\nimport type {\n  ForwardedRef,\n  MouseEventHandler,\n} from 'react';\nimport { useCallback, useImperativeHandle, useRef } from 'react';\n\n/**\n * A damped spring as the easing of one keyframe segment: the value overshoots\n * its target and settles on it. Use it for landings so every icon shares the\n * same physical bounce. Higher `bounce` gives more oscillation.\n */\nexport function springEase(bounce = 0.45, visualDuration = 0.35) {\n  const generator = spring({ keyframes: [0, 1], bounce, visualDuration });\n  let settle = 0;\n  while (!generator.next(settle).done && settle < 5000) settle += 10;\n  return (progress: number) =>\n    progress >= 1 ? 1 : generator.next(progress * settle).value;\n}\n\nconst NUMBER = /-?\\d*\\.?\\d+/g;\n\n/**\n * The path at position `t` along a row of poses that share the same path\n * commands: `t = 1` is the second pose, `t = 1.5` is halfway to the third.\n * Waves use it to move along their own curvature instead of scaling, so the\n * stroke keeps its width.\n */\nexport function pathAt(poses: string[], t: number) {\n  const i = Math.min(Math.max(Math.floor(t), 0), poses.length - 2);\n  const to = poses[i + 1].match(NUMBER) ?? [];\n  let k = 0;\n  return poses[i].replace(NUMBER, (from) => {\n    const value = Number(from) + (Number(to[k++]) - Number(from)) * (t - i);\n    return String(Math.round(value * 10000) / 10000);\n  });\n}\n\nexport interface AnimatedIconHandle {\n  startAnimation: () => void;\n  stopAnimation: () => void;\n}\n\ninterface UseIconAnimationOptions {\n  controls: LegacyAnimationControls;\n  loops?: boolean;\n  onMouseEnter?: MouseEventHandler<HTMLDivElement>;\n  onMouseLeave?: MouseEventHandler<HTMLDivElement>;\n  ref: ForwardedRef<AnimatedIconHandle>;\n}\n\nexport function useIconAnimation({\n  controls,\n  loops = false,\n  onMouseEnter,\n  onMouseLeave,\n  ref,\n}: UseIconAnimationOptions) {\n  const shouldReduceMotion = useReducedMotion();\n  const isControlledRef = useRef(false);\n  const isPlayingRef = useRef(false);\n  const runRef = useRef(0);\n\n  const startAnimation = useCallback(() => {\n    if (shouldReduceMotion || isPlayingRef.current) return;\n\n    isPlayingRef.current = true;\n    const run = ++runRef.current;\n    controls.set('normal');\n    void controls.start('animate').then(() => {\n      if (runRef.current === run) isPlayingRef.current = false;\n    });\n  }, [controls, shouldReduceMotion]);\n\n  const stopAnimation = useCallback(() => {\n    if (!loops) return;\n\n    runRef.current++;\n    isPlayingRef.current = false;\n    void controls.start('normal');\n  }, [controls, loops]);\n\n  useImperativeHandle(\n    ref,\n    () => {\n      isControlledRef.current = true;\n      return { startAnimation, stopAnimation };\n    },\n    [startAnimation, stopAnimation]\n  );\n\n  const handleMouseEnter = useCallback<MouseEventHandler<HTMLDivElement>>(\n    (event) => {\n      onMouseEnter?.(event);\n      if (!isControlledRef.current) startAnimation();\n    },\n    [onMouseEnter, startAnimation]\n  );\n\n  const handleMouseLeave = useCallback<MouseEventHandler<HTMLDivElement>>(\n    (event) => {\n      onMouseLeave?.(event);\n      if (!isControlledRef.current) stopAnimation();\n    },\n    [onMouseLeave, stopAnimation]\n  );\n\n  return { handleMouseEnter, handleMouseLeave };\n}\n",
      "type": "registry:lib"
    }
  ],
  "type": "registry:ui"
}