UI Cursor
An animated cursor that moves between waypoints, clicks (ripple), and drags. The Cursor renderer is a pure function of a numeric CursorStyle channel; useCursorPath reads the frame and eases the path, ripple, and press phases.
Source
components/kuchi/cursor.tsx
1"use client";23import { type KuchiTheme, useKuchiTheme } from "@/lib/kuchi-kit";45export type CursorVariant = "arrow" | "pointer";67export interface CursorStyle {8 x: number;9 y: number;10 scale: number;11 rippleOpacity: number;12 rippleScale: number;13 pressScale?: number;14}1516export interface CursorProps {17 style?: CursorStyle;18 variant?: CursorVariant;19 size?: number;20 theme?: Partial<KuchiTheme>;21 rippleColor?: string;22 className?: string;23}2425const REST: CursorStyle = {26 x: 0,27 y: 0,28 scale: 1,29 rippleOpacity: 0,30 rippleScale: 0,31};3233const ARROW_PATH =34 "M1 1 L1 18.5 L5.6 14.4 L8.7 21.6 L11.6 20.4 L8.5 13.2 L14.5 13.2 Z";35const POINTER_PATH =36 "M8 2.2 C8 1.3 8.7 0.7 9.5 0.7 C10.3 0.7 11 1.3 11 2.2 L11 9 " +37 "C11 9 11.3 8.4 12.2 8.4 C13 8.4 13.4 9 13.4 9.6 " +38 "C13.4 9.6 13.9 9.1 14.7 9.1 C15.5 9.1 15.9 9.7 15.9 10.3 " +39 "C15.9 10.3 16.4 9.9 17.1 9.9 C17.9 9.9 18.3 10.5 18.3 11.2 " +40 "L18.3 16.8 C18.3 19.8 16.3 22.3 12.8 22.3 L11.4 22.3 " +41 "C9 22.3 7.9 21.2 6.6 19.2 L4 15.2 C3.5 14.4 3.7 13.4 4.5 12.9 " +42 "C5.1 12.5 5.9 12.6 6.4 13.2 L8 15 Z";4344export function Cursor({45 style,46 variant = "arrow",47 size = 28,48 theme: themeOverride,49 rippleColor,50 className,51}: CursorProps) {52 const theme = useKuchiTheme(themeOverride, "light");53 const v = style ?? REST;5455 const press = v.pressScale ?? 1;56 const pressedScale = v.scale * (0.9 + 0.1 * press);5758 const ring = rippleColor ?? theme.primary;59 const fill = theme.foreground;60 const stroke = theme.background;61 const rippleSize = size * 1.8;6263 return (64 <div65 className={className}66 style={{67 position: "absolute",68 left: 0,69 top: 0,70 transform: `translate(${v.x}px, ${v.y}px)`,71 pointerEvents: "none",72 }}73 >74 {}75 <div76 style={{77 position: "absolute",78 left: -rippleSize / 2,79 top: -rippleSize / 2,80 width: rippleSize,81 height: rippleSize,82 borderRadius: "50%",83 border: `2px solid ${ring}`,84 opacity: v.rippleOpacity,85 transform: `scale(${v.rippleScale})`,86 transformOrigin: "center",87 }}88 />89 {}90 <svg91 width={size}92 height={size}93 viewBox="0 0 24 24"94 fill="none"95 style={{96 position: "absolute",97 left: 0,98 top: 0,99 transform: `scale(${pressedScale})`,100 transformOrigin: "0 0",101 filter: "drop-shadow(0 1px 2px rgba(0,0,0,0.3))",102 overflow: "visible",103 }}104 >105 <path106 d={variant === "pointer" ? POINTER_PATH : ARROW_PATH}107 fill={fill}108 stroke={stroke}109 strokeWidth={1.4}110 strokeLinejoin="round"111 />112 </svg>113 </div>114 );115}
components/kuchi/use-cursor-path.ts
1"use client";23import { useCurrentFrame } from "remotion";4import type { CursorStyle } from "@/components/kuchi/cursor";5import { clamp01, type EasingName, easings } from "@/lib/kuchi-kit";67export interface CursorWaypoint {8 at: number;9 x: number;10 y: number;11 duration?: number;12 click?: boolean;13 press?: boolean;14 easing?: EasingName;15}1617export const DEFAULT_DURATION = 24;1819export const CLICK_FRAMES = 16;2021export const PRESS_FRAMES = 8;2223export interface CursorPathOptions {24 speed?: number;25 defaultDuration?: number;26}2728function lerp(a: number, b: number, t: number): number {29 return a + (b - a) * t;30}3132export function ripplePhase(framesSinceClick: number): {33 rippleOpacity: number;34 rippleScale: number;35} {36 if (framesSinceClick < 0 || framesSinceClick >= CLICK_FRAMES) {37 return { rippleOpacity: 0, rippleScale: 0 };38 }39 const p = clamp01(framesSinceClick / CLICK_FRAMES);40 return {41 rippleOpacity: 0.5 * (1 - p),42 rippleScale: 2.5 * easings.out(p),43 };44}4546export function clickPress(framesSinceClick: number): number {47 if (framesSinceClick < 0 || framesSinceClick >= PRESS_FRAMES) return 1;48 const half = PRESS_FRAMES / 2;49 const p =50 framesSinceClick < half51 ? framesSinceClick / half52 : 1 - (framesSinceClick - half) / half;53 return 1 - clamp01(p);54}5556export function useCursorPath(57 waypoints: CursorWaypoint[],58 opts: CursorPathOptions = {},59): CursorStyle {60 const raw = useCurrentFrame();61 return cursorPathAt(waypoints, raw, opts);62}6364export function cursorPathAt(65 waypoints: CursorWaypoint[],66 raw: number,67 opts: CursorPathOptions = {},68): CursorStyle {69 const { speed = 1, defaultDuration = DEFAULT_DURATION } = opts;70 const effectiveFrame = raw * speed;7172 if (waypoints.length === 0) {73 return { x: 0, y: 0, scale: 1, rippleOpacity: 0, rippleScale: 0 };74 }7576 const first = waypoints[0];7778 if (effectiveFrame <= first.at) {79 return {80 x: first.x,81 y: first.y,82 scale: 1,83 rippleOpacity: 0,84 rippleScale: 0,85 pressScale: 1,86 };87 }8889 let toIndex = waypoints.length - 1;90 for (let i = 1; i < waypoints.length; i++) {91 if (waypoints[i].at > effectiveFrame) {92 toIndex = i;93 break;94 }95 }96 const pastLast = effectiveFrame >= waypoints[waypoints.length - 1].at;97 const to = pastLast ? waypoints[waypoints.length - 1] : waypoints[toIndex];98 const from = pastLast99 ? waypoints[waypoints.length - 1]100 : waypoints[toIndex - 1];101102 const dur = to.duration ?? defaultDuration;103 const ease = easings[to.easing ?? "inOut"];104 const start = to.at - dur;105 const t =106 pastLast || dur <= 0 ? 1 : ease(clamp01((effectiveFrame - start) / dur));107 const x = lerp(from.x, to.x, t);108 const y = lerp(from.y, to.y, t);109110 let lastClickAt = -Infinity;111 for (const wp of waypoints) {112 if (wp.click && wp.at <= effectiveFrame && wp.at > lastClickAt)113 lastClickAt = wp.at;114 }115 const sinceClick =116 lastClickAt === -Infinity ? -1 : effectiveFrame - lastClickAt;117 const ripple = ripplePhase(sinceClick);118 const clickDip = clickPress(sinceClick);119120 const holdWp = pastLast ? waypoints[waypoints.length - 1] : from;121 const heldPress = holdWp.press ? 0 : 1;122123 const pressScale = Math.min(clickDip, heldPress);124125 return {126 x,127 y,128 scale: 1,129 rippleOpacity: ripple.rippleOpacity,130 rippleScale: ripple.rippleScale,131 pressScale,132 };133}





