\n \n \n ${' '}\n \n \n
'use client';\n\nimport { useState } from 'react';\nimport ElasticSlider from '@/components/tweenui/elastic-slider';\n\nexport default function Example() {\n const [budget, setBudget] = useState(7500);\n return (\n <ElasticSlider\n label=\"Monthly budget\"\n min={0}\n max={20000}\n step={100}\n buttonStep={100}\n value={budget}\n onValueChange={setBudget}\n prefix=\"$\"\n />\n );\n}"
}
},
+ "package-command": {
+ "react": {
+ "code": "import PackageCommand from '@/components/tweenui/package-command';\n\nexport default function Example() {\n return import PackageCommand from '@/components/tweenui/package-command';\n\nexport default function Example() {\n return <PackageCommand packages={['gsap', '@gsap/react']} />;\n}"
+ }
+ },
"pricing-plan-switch": {
"react": {
"code": "import PricingPlanSwitch from '@/components/tweenui/pricing-plan-switch';\n\nexport default function Example() {\n return 'use client';\n\nimport {\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ComponentPropsWithoutRef,\n type PointerEvent as ReactPointerEvent,\n} from 'react';\nimport { useGSAP } from '@gsap/react';\nimport NumberFlow, { type Format } from '@number-flow/react';\nimport gsap from 'gsap';\nimport { cn } from '@/lib/utils';\n\ngsap.registerPlugin(useGSAP);\n\nconst prefersReducedMotion = () =>\n typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n\nconst MAX_STRETCH = 28;\nconst WAVE_WIDTH = 30;\nconst LIFT = { idle: 0.6, hover: 1.1, drag: 1.7 };\n\nconst STEP_BUTTON =\n 'grid size-9 cursor-pointer place-items-center transition-colors duration-200 hover:bg-current/10 focus-visible:bg-current/10 focus-visible:outline-none disabled:cursor-not-allowed disabled:hover:bg-transparent';\n\nconst clamp = (value: number, low: number, high: number) => Math.min(high, Math.max(low, value));\n\nconst rubberBand = (overdrag: number) =>\n Math.sign(overdrag) * MAX_STRETCH * (1 - Math.exp(-Math.abs(overdrag) / (MAX_STRETCH * 2.5)));\n\nconst decimalsOf = (step: number) => {\n const [, fraction = ''] = String(step).split('.');\n return fraction.length;\n};\n\nconst MinusIcon = () => (\n <svg viewBox=\"0 0 24 24\" className=\"size-4\" fill=\"none\" aria-hidden=\"true\">\n <path d=\"M5 12h14\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" />\n </svg>\n);\n\nconst PlusIcon = () => (\n <svg viewBox=\"0 0 24 24\" className=\"size-4\" fill=\"none\" aria-hidden=\"true\">\n <path d=\"M12 5v14M5 12h14\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" />\n </svg>\n);\n\nexport interface ElasticSliderProps extends Omit<\n ComponentPropsWithoutRef<'div'>,\n 'defaultValue' | 'onChange'\n> {\n label: string;\n min?: number;\n max?: number;\n step?: number;\n value?: number;\n defaultValue?: number;\n onValueChange?: (value: number) => void;\n format?: Format;\n prefix?: string;\n suffix?: string;\n buttonStep?: number;\n ticks?: number;\n disabled?: boolean;\n}\n\nconst ElasticSlider = ({\n label,\n min = 0,\n max = 100,\n step = 1,\n value: controlledValue,\n defaultValue = 50,\n onValueChange,\n format,\n prefix,\n suffix,\n buttonStep,\n ticks = 41,\n disabled = false,\n className,\n ...props\n}: ElasticSliderProps) => {\n const inputId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const railRef = useRef<HTMLDivElement>(null);\n const tickRefs = useRef<(HTMLSpanElement | null)[]>([]);\n const indicatorRef = useRef<HTMLSpanElement>(null);\n const decreaseRef = useRef<HTMLSpanElement>(null);\n const increaseRef = useRef<HTMLSpanElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n\n const motion = useRef({ progress: 0, stretch: 0, focus: 0, lift: LIFT.idle });\n const moveTo = useRef<((progress: number) => void) | null>(null);\n const focusTo = useRef<((x: number) => void) | null>(null);\n const liftTo = useRef<((lift: number) => void) | null>(null);\n const hoverX = useRef<number | null>(null);\n\n const [innerValue, setInnerValue] = useState(defaultValue);\n const [dragging, setDragging] = useState(false);\n const [reduced, setReduced] = useState(false);\n\n const value = clamp(controlledValue ?? innerValue, min, max);\n const span = max - min || 1;\n const progress = (value - min) / span;\n const numberFormat = { useGrouping: true, ...format };\n const formatter = new Intl.NumberFormat(undefined, numberFormat);\n const formatText = (number: number) =>\n `${prefix ?? ''}${formatter.format(number)}${suffix ?? ''}`;\n\n const render = useCallback(() => {\n const rail = railRef.current;\n if (!rail) return;\n const width = rail.offsetWidth;\n const { progress: current, stretch, focus, lift } = motion.current;\n const offset = (t: number) => (stretch > 0 ? stretch * t : stretch * (1 - t));\n const count = tickRefs.current.length;\n\n tickRefs.current.forEach((tick, index) => {\n if (!tick) return;\n const t = count > 1 ? index / (count - 1) : 0;\n const base = t * width;\n const wave = Math.exp(-(((base - focus) / WAVE_WIDTH) ** 2));\n gsap.set(tick, { x: base + offset(t), scaleY: 1 + lift * wave });\n tick.toggleAttribute('data-on', t <= current + 0.0001);\n });\n\n gsap.set(indicatorRef.current, {\n x: current * width + offset(current),\n scaleY: 1 + (lift - LIFT.idle) * 0.12,\n });\n }, []);\n\n useGSAP(\n () => {\n const isReduced = prefersReducedMotion();\n setReduced(isReduced);\n const width = railRef.current?.offsetWidth ?? 0;\n motion.current.progress = progress;\n motion.current.focus = progress * width;\n motion.current.lift = isReduced ? 0 : LIFT.idle;\n moveTo.current = gsap.quickTo(motion.current, 'progress', {\n duration: isReduced ? 0 : 0.4,\n ease: 'power3.out',\n onUpdate: render,\n });\n focusTo.current = gsap.quickTo(motion.current, 'focus', {\n duration: isReduced ? 0 : 0.5,\n ease: 'power3.out',\n onUpdate: render,\n });\n liftTo.current = gsap.quickTo(motion.current, 'lift', {\n duration: isReduced ? 0 : 0.45,\n ease: 'power2.out',\n onUpdate: render,\n });\n render();\n\n const rail = railRef.current;\n if (!rail || typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(render);\n observer.observe(rail);\n return () => observer.disconnect();\n },\n { scope: rootRef, dependencies: [ticks] }\n );\n\n useEffect(() => {\n moveTo.current?.(progress);\n if (hoverX.current === null) focusTo.current?.(progress * (railRef.current?.offsetWidth ?? 0));\n }, [progress]);\n\n const setLift = (state: keyof typeof LIFT) => {\n if (!reduced) liftTo.current?.(LIFT[state]);\n };\n\n const commit = (next: number) => {\n const snapped = clamp(\n Number((Math.round((next - min) / step) * step + min).toFixed(decimalsOf(step))),\n min,\n max\n );\n if (snapped === value) return;\n if (controlledValue === undefined) setInnerValue(snapped);\n onValueChange?.(snapped);\n };\n\n const stretchTo = (amount: number, release = false) => {\n if (reduced) return;\n gsap.to(motion.current, {\n stretch: amount,\n duration: release ? 0.9 : 0.2,\n ease: release ? 'elastic.out(1, 0.32)' : 'power3.out',\n overwrite: 'auto',\n onUpdate: render,\n });\n };\n\n const bump = (direction: number) => {\n if (reduced) return;\n gsap.to(motion.current, {\n stretch: direction * 14,\n duration: 0.14,\n ease: 'power2.out',\n overwrite: 'auto',\n onUpdate: render,\n onComplete: () => stretchTo(0, true),\n });\n };\n\n const nudge = (direction: number) => {\n if (disabled || !buttonStep) return;\n if (!reduced) {\n gsap.fromTo(\n direction < 0 ? decreaseRef.current : increaseRef.current,\n { scale: 0.6 },\n { scale: 1, duration: 0.5, ease: 'back.out(3)', overwrite: true }\n );\n }\n const atEdge = direction < 0 ? value <= min : value >= max;\n if (atEdge) bump(direction);\n else commit(value + direction * buttonStep);\n };\n\n const track = (clientX: number) => {\n const rail = railRef.current;\n if (!rail) return;\n const rect = rail.getBoundingClientRect();\n const overdrag =\n clientX < rect.left ? clientX - rect.left : clientX > rect.right ? clientX - rect.right : 0;\n commit(min + clamp((clientX - rect.left) / (rect.width || 1), 0, 1) * span);\n stretchTo(rubberBand(overdrag));\n hoverX.current = clamp(clientX - rect.left, 0, rect.width);\n focusTo.current?.(hoverX.current);\n };\n\n const handlePointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (disabled || (event.pointerType === 'mouse' && event.button !== 0)) return;\n event.preventDefault();\n event.currentTarget.setPointerCapture(event.pointerId);\n inputRef.current?.focus({ preventScroll: true });\n setDragging(true);\n setLift('drag');\n track(event.clientX);\n };\n\n const handlePointerMove = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (dragging) {\n track(event.clientX);\n return;\n }\n if (disabled || event.pointerType !== 'mouse') return;\n const rect = railRef.current?.getBoundingClientRect();\n if (!rect) return;\n hoverX.current = clamp(event.clientX - rect.left, 0, rect.width);\n focusTo.current?.(hoverX.current);\n setLift('hover');\n };\n\n const settle = () => {\n hoverX.current = null;\n focusTo.current?.(progress * (railRef.current?.offsetWidth ?? 0));\n setLift('idle');\n };\n\n const handlePointerEnd = () => {\n if (!dragging) return;\n setDragging(false);\n stretchTo(0, true);\n settle();\n };\n\n return (\n <div\n ref={rootRef}\n data-elastic-slider\n data-dragging={dragging || undefined}\n className={cn(\n 'w-full max-w-md touch-none select-none [--elastic-accent:#045f64] motion-reduce:transition-none dark:[--elastic-accent:#c6f56f]',\n disabled && 'opacity-50',\n className\n )}\n {...props}\n >\n <div className=\"flex items-end justify-between gap-4\">\n <div className=\"min-w-0\">\n <label htmlFor={inputId} className=\"block text-xs tracking-wide uppercase opacity-60\">\n {label}\n </label>\n <NumberFlow\n aria-hidden=\"true\"\n value={value}\n format={numberFormat}\n prefix={prefix}\n suffix={suffix}\n animated={!reduced}\n willChange\n className=\"mt-1 block text-4xl font-medium tracking-tight tabular-nums\"\n />\n </div>\n\n {buttonStep && (\n <div className=\"flex shrink-0 overflow-hidden rounded-full border border-current/15\">\n <button\n type=\"button\"\n disabled={disabled}\n aria-label={`Decrease ${label} by ${formatText(buttonStep)}`}\n onClick={() => nudge(-1)}\n className={STEP_BUTTON}\n >\n <span ref={decreaseRef} className=\"flex\">\n <MinusIcon />\n </span>\n </button>\n <span aria-hidden=\"true\" className=\"w-px bg-current/15\" />\n <button\n type=\"button\"\n disabled={disabled}\n aria-label={`Increase ${label} by ${formatText(buttonStep)}`}\n onClick={() => nudge(1)}\n className={STEP_BUTTON}\n >\n <span ref={increaseRef} className=\"flex\">\n <PlusIcon />\n </span>\n </button>\n </div>\n )}\n </div>\n\n <div\n className={cn(\n 'relative mt-5 h-14',\n disabled ? 'cursor-not-allowed' : dragging ? 'cursor-grabbing' : 'cursor-grab'\n )}\n onPointerDown={handlePointerDown}\n onPointerMove={handlePointerMove}\n onPointerLeave={() => !dragging && settle()}\n onPointerUp={handlePointerEnd}\n onPointerCancel={handlePointerEnd}\n onLostPointerCapture={handlePointerEnd}\n >\n <input\n ref={inputRef}\n id={inputId}\n type=\"range\"\n min={min}\n max={max}\n step={step}\n value={value}\n disabled={disabled}\n aria-valuetext={formatText(value)}\n onChange={(event) => commit(Number(event.target.value))}\n className=\"peer sr-only\"\n />\n <div\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute -inset-x-3 -inset-y-1 rounded-xl outline-2 outline-transparent peer-focus-visible:outline-current\"\n />\n <div ref={railRef} aria-hidden=\"true\" className=\"absolute inset-0\">\n {Array.from({ length: ticks }, (_, index) => (\n <span\n key={index}\n ref={(node) => {\n tickRefs.current[index] = node;\n }}\n className={cn(\n 'absolute top-1/2 left-0 -ml-px w-0.5 rounded-full bg-current/20 transition-colors duration-200 will-change-transform data-on:bg-(--elastic-accent)',\n index % 5 === 0 ? '-mt-2.5 h-5' : '-mt-1.5 h-3'\n )}\n />\n ))}\n <span\n ref={indicatorRef}\n className=\"absolute top-1/2 left-0 -mt-6 -ml-[3px] h-12 w-1.5 rounded-full bg-(--elastic-accent) shadow-[0_0_0_3px_var(--color-white)] will-change-transform dark:shadow-[0_0_0_3px_#12161f]\"\n />\n </div>\n </div>\n\n <div aria-hidden=\"true\" className=\"mt-1 flex justify-between text-xs tabular-nums opacity-50\">\n <span>{formatText(min)}</span>\n <span>{formatText(max)}</span>\n </div>\n </div>\n );\n};\n\nexport default ElasticSlider;\n"
}
},
+ "package-command": {
+ "react": {
+ "code": "'use client';\n\nimport {\n useEffect,\n useId,\n useRef,\n useState,\n useSyncExternalStore,\n type ComponentPropsWithoutRef,\n type KeyboardEvent,\n} from 'react';\nimport { useGSAP } from '@gsap/react';\nimport gsap from 'gsap';\nimport { cn } from '@/lib/utils';\n\ngsap.registerPlugin(useGSAP);\n\nexport const PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn', 'bun'] as const;\n\nexport type PackageManager = (typeof PACKAGE_MANAGERS)[number];\n\nexport type PackageCommandKind = 'install' | 'execute';\n\nconst STORAGE_KEY = 'tweenui:package-manager';\nconst COPIED_FOR = 1600;\n\nconst listeners = new Set<() => void>();\nlet chosen: PackageManager | null = null;\nlet chosenByUser = false;\n\nconst toManager = (value: unknown) => PACKAGE_MANAGERS.find((manager) => manager === value);\n\nconst readManager = (): PackageManager => {\n if (chosen) return chosen;\n try {\n chosen = toManager(window.localStorage.getItem(STORAGE_KEY)) ?? 'npm';\n } catch {\n chosen = 'npm';\n }\n return chosen;\n};\n\nconst chooseManager = (manager: PackageManager) => {\n if (manager === chosen) return;\n chosen = manager;\n chosenByUser = true;\n try {\n window.localStorage.setItem(STORAGE_KEY, manager);\n } catch {}\n listeners.forEach((listener) => listener());\n};\n\nconst subscribe = (listener: () => void) => {\n const onStorage = (event: StorageEvent) => {\n if (event.key !== STORAGE_KEY) return;\n const next = toManager(event.newValue);\n if (!next || next === chosen) return;\n chosen = next;\n chosenByUser = true;\n listeners.forEach((each) => each());\n };\n listeners.add(listener);\n window.addEventListener('storage', onStorage);\n return () => {\n listeners.delete(listener);\n window.removeEventListener('storage', onStorage);\n };\n};\n\nconst prefersReducedMotion = () =>\n typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n\nconst runner = (manager: PackageManager, kind: PackageCommandKind, dev: boolean) => {\n if (kind === 'execute') {\n if (manager === 'npm') return 'npx';\n if (manager === 'bun') return 'bunx';\n return `${manager} dlx`;\n }\n const verb = manager === 'npm' ? 'npm install' : `${manager} add`;\n return dev ? `${verb} -D` : verb;\n};\n\nconst splitHead = (head: string) => {\n const space = head.indexOf(' ');\n return space === -1 ? [head, ''] : [head.slice(0, space), head.slice(space)];\n};\n\nconst FlipCells = ({ from, to }: { from: string; to: string }) => (\n \n {Array.from(to, (character, index) => (\n \n {character}\n \n ))}\n {Array.from(from, (character, index) =>\n character === to[index] || character === ' ' ? null : (\n \n {character}\n \n )\n )}\n \n);\n\nconst ClipboardIcon = () => (\n \n);\n\nexport interface PackageCommandProps extends Omit\n \n \n ${' '}\n \n \n
'use client';\n\nimport {\n useEffect,\n useId,\n useRef,\n useState,\n useSyncExternalStore,\n type ComponentPropsWithoutRef,\n type KeyboardEvent,\n} from 'react';\nimport { useGSAP } from '@gsap/react';\nimport gsap from 'gsap';\nimport { cn } from '@/lib/utils';\n\ngsap.registerPlugin(useGSAP);\n\nexport const PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn', 'bun'] as const;\n\nexport type PackageManager = (typeof PACKAGE_MANAGERS)[number];\n\nexport type PackageCommandKind = 'install' | 'execute';\n\nconst STORAGE_KEY = 'tweenui:package-manager';\nconst COPIED_FOR = 1600;\n\nconst listeners = new Set<() => void>();\nlet chosen: PackageManager | null = null;\nlet chosenByUser = false;\n\nconst toManager = (value: unknown) => PACKAGE_MANAGERS.find((manager) => manager === value);\n\nconst readManager = (): PackageManager => {\n if (chosen) return chosen;\n try {\n chosen = toManager(window.localStorage.getItem(STORAGE_KEY)) ?? 'npm';\n } catch {\n chosen = 'npm';\n }\n return chosen;\n};\n\nconst chooseManager = (manager: PackageManager) => {\n if (manager === chosen) return;\n chosen = manager;\n chosenByUser = true;\n try {\n window.localStorage.setItem(STORAGE_KEY, manager);\n } catch {}\n listeners.forEach((listener) => listener());\n};\n\nconst subscribe = (listener: () => void) => {\n const onStorage = (event: StorageEvent) => {\n if (event.key !== STORAGE_KEY) return;\n const next = toManager(event.newValue);\n if (!next || next === chosen) return;\n chosen = next;\n chosenByUser = true;\n listeners.forEach((each) => each());\n };\n listeners.add(listener);\n window.addEventListener('storage', onStorage);\n return () => {\n listeners.delete(listener);\n window.removeEventListener('storage', onStorage);\n };\n};\n\nconst prefersReducedMotion = () =>\n typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n\nconst runner = (manager: PackageManager, kind: PackageCommandKind, dev: boolean) => {\n if (kind === 'execute') {\n if (manager === 'npm') return 'npx';\n if (manager === 'bun') return 'bunx';\n return `${manager} dlx`;\n }\n const verb = manager === 'npm' ? 'npm install' : `${manager} add`;\n return dev ? `${verb} -D` : verb;\n};\n\nconst splitHead = (head: string) => {\n const space = head.indexOf(' ');\n return space === -1 ? [head, ''] : [head.slice(0, space), head.slice(space)];\n};\n\nconst FlipCells = ({ from, to }: { from: string; to: string }) => (\n <span className=\"relative inline-flex items-center [clip-path:inset(0_-100vw)]\">\n {Array.from(to, (character, index) => (\n <span\n key={index}\n data-in\n data-changed={character !== from[index] || undefined}\n className=\"block w-[1ch]\"\n >\n {character}\n </span>\n ))}\n {Array.from(from, (character, index) =>\n character === to[index] || character === ' ' ? null : (\n <span\n key={`out-${index}`}\n data-out\n style={{ left: `${index}ch` }}\n className=\"absolute inset-y-0 block w-[1ch]\"\n >\n {character}\n </span>\n )\n )}\n </span>\n);\n\nconst ClipboardIcon = () => (\n <svg viewBox=\"0 0 24 24\" className=\"size-4\" fill=\"none\" aria-hidden=\"true\">\n <rect x=\"8\" y=\"3\" width=\"8\" height=\"4\" rx=\"1\" stroke=\"currentColor\" strokeWidth=\"1.75\" />\n <path\n d=\"M16 5h1.5A1.5 1.5 0 0 1 19 6.5v12a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 5 18.5v-12A1.5 1.5 0 0 1 6.5 5H8\"\n stroke=\"currentColor\"\n strokeWidth=\"1.75\"\n strokeLinecap=\"round\"\n />\n </svg>\n);\n\nexport interface PackageCommandProps extends Omit<ComponentPropsWithoutRef<'div'>, 'onCopy'> {\n packages: string | string[];\n kind?: PackageCommandKind;\n dev?: boolean;\n managers?: readonly PackageManager[];\n onCopy?: (command: string) => void;\n}\n\nconst PackageCommand = ({\n packages,\n kind = 'install',\n dev = false,\n managers = PACKAGE_MANAGERS,\n onCopy,\n className,\n ...props\n}: PackageCommandProps) => {\n const id = useId();\n const panelId = `${id}-panel`;\n const rootRef = useRef<HTMLDivElement>(null);\n const tabRefs = useRef<(HTMLButtonElement | null)[]>([]);\n const pillRef = useRef<HTMLSpanElement>(null);\n const tailRef = useRef<HTMLSpanElement>(null);\n const listRef = useRef<HTMLSpanElement>(null);\n const sweepRef = useRef<HTMLSpanElement>(null);\n const clipboardRef = useRef<HTMLSpanElement>(null);\n const checkRef = useRef<SVGSVGElement>(null);\n const checkPathRef = useRef<SVGPathElement>(null);\n const copyTimer = useRef<number | undefined>(undefined);\n const flipTimeline = useRef<gsap.core.Timeline | null>(null);\n\n const stored = useSyncExternalStore(subscribe, readManager, () => 'npm');\n const manager = managers.find((each) => each === stored) ?? managers[0] ?? 'npm';\n const activeIndex = Math.max(0, managers.indexOf(manager));\n const list = Array.isArray(packages) ? packages.join(' ') : packages.trim();\n const head = runner(manager, kind, dev);\n const command = `${head} ${list}`;\n\n const [flip, setFlip] = useState({ from: head, to: head });\n const [copied, setCopied] = useState(false);\n\n if (flip.to !== head) setFlip({ from: flip.to, to: head });\n\n const [fromTool, fromTail] = splitHead(flip.from);\n const [toTool, toTail] = splitHead(flip.to);\n\n const { contextSafe } = useGSAP({ scope: rootRef });\n\n const highlight = (index: number) => {\n tabRefs.current.forEach((tab, each) => {\n if (tab) tab.dataset.highlighted = String(each === index);\n });\n };\n\n const movePill = (index: number, animate: boolean) => {\n const tab = tabRefs.current[index];\n if (!tab) return;\n highlight(index);\n const bounds = { x: tab.offsetLeft, width: tab.offsetWidth };\n if (!animate || prefersReducedMotion()) {\n gsap.killTweensOf(pillRef.current);\n gsap.set(pillRef.current, bounds);\n return;\n }\n gsap.to(pillRef.current, { ...bounds, duration: 0.35, ease: 'power2.out', overwrite: 'auto' });\n };\n\n const followPointer = contextSafe((target: EventTarget) => {\n if (!(target instanceof Element)) return;\n const tab = target.closest('[role=\"tab\"]');\n const index = tabRefs.current.findIndex((each) => each === tab);\n if (index !== -1) movePill(index, true);\n });\n\n const returnToActive = contextSafe(() => movePill(activeIndex, true));\n\n useGSAP(\n () => {\n movePill(activeIndex, chosenByUser);\n },\n { scope: rootRef, dependencies: [activeIndex, managers.length] }\n );\n\n useEffect(() => {\n const tablist = tabRefs.current[0]?.parentElement;\n if (!tablist || typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(() => movePill(activeIndex, false));\n observer.observe(tablist);\n return () => observer.disconnect();\n }, [activeIndex, managers]);\n\n useGSAP(\n () => {\n if (flip.from === flip.to) {\n gsap.set(\n [tailRef.current, listRef.current, ...gsap.utils.toArray('[data-in]', rootRef.current)],\n {\n clearProps: 'transform,opacity',\n }\n );\n return;\n }\n flipTimeline.current?.kill();\n const root = rootRef.current;\n const listElement = listRef.current;\n const incoming = gsap.utils.toArray<HTMLElement>('[data-in]', root);\n gsap.set(incoming, { yPercent: 0, opacity: 1 });\n const settle = () => setFlip((current) => ({ from: current.to, to: current.to }));\n if (!chosenByUser || prefersReducedMotion()) {\n gsap.set([tailRef.current, listElement], { x: 0 });\n settle();\n return;\n }\n const charWidth = incoming[0]?.getBoundingClientRect().width ?? 0;\n const timeline = gsap.timeline({ onComplete: settle });\n flipTimeline.current = timeline;\n const slide = (element: HTMLElement | null, shift: number) => {\n const currentX = Number(gsap.getProperty(element, 'x')) || 0;\n timeline.fromTo(\n element,\n { x: shift * charWidth + currentX },\n { x: 0, duration: 0.55, ease: 'power3.inOut' },\n 0\n );\n };\n slide(tailRef.current, fromTool.length - toTool.length);\n slide(listElement, flip.from.length - flip.to.length);\n timeline.fromTo(\n gsap.utils.toArray<HTMLElement>('[data-out]', root),\n { yPercent: 0, opacity: 1 },\n { yPercent: -70, opacity: 0, duration: 0.2, ease: 'power2.in' },\n 0\n );\n incoming\n .filter((element) => element.hasAttribute('data-changed'))\n .forEach((element, order) => {\n timeline.fromTo(\n element,\n { yPercent: 100, opacity: 0 },\n { yPercent: 0, opacity: 1, duration: 0.42, ease: 'power3.out' },\n order * 0.03 + 0.1\n );\n });\n },\n { scope: rootRef, dependencies: [flip.from, flip.to] }\n );\n\n useEffect(() => () => window.clearTimeout(copyTimer.current), []);\n\n const select = (index: number, focus = false) => {\n const next = managers[(index + managers.length) % managers.length];\n if (!next) return;\n chooseManager(next);\n if (focus) tabRefs.current[managers.indexOf(next)]?.focus();\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n const moves: Record<string, number> = {\n ArrowRight: activeIndex + 1,\n ArrowLeft: activeIndex - 1,\n Home: 0,\n End: managers.length - 1,\n };\n const target = moves[event.key];\n if (target === undefined) return;\n event.preventDefault();\n select(target, true);\n };\n\n const playCopied = contextSafe(() => {\n if (prefersReducedMotion()) {\n gsap.set(clipboardRef.current, { opacity: 0 });\n gsap.set(checkRef.current, { opacity: 1 });\n gsap.set(checkPathRef.current, { strokeDashoffset: 0 });\n return;\n }\n gsap\n .timeline({ defaults: { overwrite: 'auto' } })\n .to(clipboardRef.current, { scale: 0.6, opacity: 0, duration: 0.2, ease: 'power2.in' }, 0)\n .set(checkRef.current, { opacity: 1 }, 0.12)\n .fromTo(\n checkPathRef.current,\n { strokeDashoffset: 1 },\n { strokeDashoffset: 0, duration: 0.4, ease: 'power3.out' },\n 0.12\n )\n .fromTo(\n sweepRef.current,\n { scaleX: 0, opacity: 1 },\n { scaleX: 1, duration: 0.5, ease: 'power3.out' },\n 0\n )\n .to(sweepRef.current, { opacity: 0, duration: 0.5, ease: 'power2.out' }, 0.7);\n });\n\n const playReset = contextSafe(() => {\n const reduced = prefersReducedMotion();\n gsap.to(checkRef.current, { opacity: 0, duration: reduced ? 0 : 0.2, ease: 'power2.out' });\n gsap.fromTo(\n clipboardRef.current,\n { scale: reduced ? 1 : 0.6 },\n {\n scale: 1,\n opacity: 1,\n duration: reduced ? 0 : 0.35,\n ease: 'power3.out',\n delay: reduced ? 0 : 0.1,\n }\n );\n });\n\n const copy = async () => {\n try {\n await navigator.clipboard.writeText(command);\n } catch {\n return;\n }\n onCopy?.(command);\n setCopied(true);\n playCopied();\n window.clearTimeout(copyTimer.current);\n copyTimer.current = window.setTimeout(() => {\n setCopied(false);\n playReset();\n }, COPIED_FOR);\n };\n\n return (\n <div\n ref={rootRef}\n data-package-command\n className={cn(\n 'w-full max-w-lg overflow-hidden rounded-xl border border-current/10 bg-current/[0.03] [--package-accent:#045f64] dark:[--package-accent:#c6f56f]',\n className\n )}\n {...props}\n >\n <div className=\"flex items-center justify-between gap-3 border-b border-current/10 px-1.5 py-1.5\">\n <div\n role=\"tablist\"\n aria-label=\"Package manager\"\n className=\"relative flex\"\n onPointerOver={(event) => followPointer(event.target)}\n onPointerLeave={returnToActive}\n onFocus={(event) => followPointer(event.target)}\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget)) returnToActive();\n }}\n >\n <span\n ref={pillRef}\n aria-hidden=\"true\"\n className=\"absolute inset-y-0 left-0 rounded-md bg-current/[0.08]\"\n />\n {managers.map((each, index) => {\n const selected = index === activeIndex;\n return (\n <button\n key={each}\n ref={(node) => {\n tabRefs.current[index] = node;\n }}\n id={`${id}-${each}`}\n type=\"button\"\n role=\"tab\"\n aria-selected={selected}\n aria-controls={panelId}\n tabIndex={selected ? 0 : -1}\n onClick={() => select(index)}\n onKeyDown={handleKeyDown}\n data-highlighted={selected}\n className=\"relative cursor-pointer rounded-md px-3 py-1.5 font-mono text-xs opacity-55 transition-opacity duration-300 focus-visible:outline-2 focus-visible:outline-current data-[highlighted=true]:opacity-100 motion-reduce:transition-none\"\n >\n {each}\n </button>\n );\n })}\n </div>\n\n <button\n type=\"button\"\n onClick={copy}\n aria-label={copied ? 'Copied' : 'Copy command'}\n className=\"relative grid size-8 shrink-0 cursor-pointer place-items-center rounded-md opacity-70 transition-[opacity,background-color] duration-200 hover:bg-current/[0.08] hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-2 focus-visible:outline-current\"\n >\n <span ref={clipboardRef} className=\"flex\">\n <ClipboardIcon />\n </span>\n <svg\n ref={checkRef}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n aria-hidden=\"true\"\n className=\"absolute size-4 text-(--package-accent) opacity-0\"\n >\n <path\n ref={checkPathRef}\n d=\"M5 12.5l4.5 4.5L19 7.5\"\n pathLength={1}\n stroke=\"currentColor\"\n strokeWidth=\"2.25\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeDasharray=\"1\"\n strokeDashoffset=\"1\"\n />\n </svg>\n </button>\n </div>\n\n <div\n id={panelId}\n role=\"tabpanel\"\n aria-labelledby={`${id}-${manager}`}\n className=\"overflow-x-auto px-4 py-3.5\"\n >\n <p className=\"relative inline-flex items-center font-mono text-sm leading-6 whitespace-pre\">\n <span\n ref={sweepRef}\n aria-hidden=\"true\"\n className=\"absolute -inset-x-1 -inset-y-0.5 origin-left scale-x-0 rounded bg-(--package-accent)/15\"\n />\n <span aria-hidden=\"true\" className=\"relative text-(--package-accent) select-none\">\n ${' '}\n </span>\n <span aria-hidden=\"true\" className=\"relative inline-flex items-center\">\n <FlipCells from={fromTool} to={toTool} />\n <span ref={tailRef} className=\"inline-flex items-center\">\n <FlipCells from={fromTail} to={toTail} />\n </span>\n <span ref={listRef} className=\"block opacity-70\">\n {' '}\n {list}\n </span>\n </span>\n <span className=\"sr-only\">{command}</span>\n </p>\n </div>\n\n <span role=\"status\" className=\"sr-only\">\n {copied ? 'Copied to clipboard' : ''}\n </span>\n </div>\n );\n};\n\nexport default PackageCommand;\n"
+ }
+ },
"pricing-plan-switch": {
"react": {
"code": "'use client';\n\nimport { useRef, useState, type ComponentPropsWithoutRef } from 'react';\nimport { useGSAP } from '@gsap/react';\nimport NumberFlow from '@number-flow/react';\nimport gsap from 'gsap';\nimport { cn } from '@/lib/utils';\n\ngsap.registerPlugin(useGSAP);\n\nconst prefersReducedMotion = () =>\n typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n\nexport interface PricingPlan {\n /** Stable id used as the animation key. */\n id: string;\n /** Plan name, shown in the left selector and the morphing card badge. */\n name: string;\n /** Supporting line under the name in the selector. */\n subtitle: string;\n /** Body copy that crossfades in when the plan is selected. */\n description: string;\n /** Price billed monthly. */\n monthly: number;\n /** Price billed yearly. */\n yearly: number;\n /** How many of `features` are included (the rest render dimmed). */\n includedCount: number;\n}\n\nexport interface PricingPlanSwitchProps extends Omit\n {description}\n
\n\n {currency}\n
{\n descriptionRefs.current[plan.id] = el ?? undefined;\n }}\n className={cn(\n 'col-start-1 row-start-1 text-sm text-[#045f64]/70 dark:text-[#9fd4d6]/80',\n index !== 0 && 'opacity-0'\n )}\n >\n {plan.description}\n
\n ))}\n \n+ + + + {command} +
+