@izhann/react-cursor-fx
Version:
Interactive cursor effects for React and Next.js applications — zero runtime dependencies
1 lines • 141 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["../src/mouseStore.ts","../src/components/CursorProvider.tsx","../src/components/Cursor.tsx","../node_modules/tslib/tslib.es6.js","../src/hooks/useCursor.tsx","../src/plugins/CursorClickEffect.tsx","../src/plugins/CursorDraw.tsx","../src/plugins/CursorLens.tsx","../src/plugins/CursorReveal.tsx","../src/plugins/CursorSpotlight.tsx","../src/components/CursorTarget.tsx","../src/plugins/CursorTrail.tsx","../src/emitCursorEvent.ts","../src/themes.ts","../src/hooks/useCursorIdle.ts","../src/hooks/useCursorVariant.tsx","../src/hooks/useCursorZone.ts","../src/plugins/useMagnetic.ts","../src/hooks/useMousePosition.tsx","../src/hooks/useVelocityCursor.ts"],"sourcesContent":["/**\n * Module-level singleton mouse position store.\n *\n * Replaces 8+ independent window.mousemove listeners with a single shared one.\n * Listener is added lazily on first subscribe — safe for SSR and \"sideEffects\": false.\n * Subscribers receive raw (x, y) synchronously inside the event handler, with no\n * React state or re-render overhead in the hot path.\n */\n\ntype Listener = (x: number, y: number) => void\n\nlet _x = 0\nlet _y = 0\nlet _initialized = false\nconst _subs = new Set<Listener>()\n\nfunction _init(): void {\n if (_initialized || typeof window === \"undefined\") return\n _initialized = true\n window.addEventListener(\n \"mousemove\",\n (e: MouseEvent) => {\n _x = e.clientX\n _y = e.clientY\n if (_subs.size > 0) _subs.forEach((fn) => fn(_x, _y))\n },\n { passive: true },\n )\n}\n\nexport const mouseStore = {\n get x(): number { return _x },\n get y(): number { return _y },\n /** Subscribe to every mouse position change. Returns an unsubscribe function. */\n subscribe(fn: Listener): () => void {\n _init()\n _subs.add(fn)\n return () => { _subs.delete(fn) }\n },\n} as const\n","\"use client\"\n\nimport type React from \"react\"\nimport {\n createContext,\n useState,\n useContext,\n useEffect,\n useCallback,\n useMemo,\n type ReactNode,\n} from \"react\"\nimport type { CursorContextType, CursorConfig, CursorState } from \"../types\"\nimport { mouseStore } from \"../mouseStore\"\n\nexport const defaultCursorConfig: CursorConfig = {\n default: {\n width: 24,\n height: 24,\n scale: 1,\n shape: \"circle\",\n color: \"rgba(255, 255, 255, 0.8)\",\n opacity: 1,\n borderColor: \"rgba(0, 0, 0, 0)\",\n borderWidth: 0,\n borderStyle: \"solid\",\n label: \"\",\n fontSize: \"12px\",\n fontWeight: \"bold\",\n labelColor: \"#000\",\n transition: {\n stiffness: 800,\n damping: 80,\n mass: 1,\n },\n },\n}\n\nconst CursorContext = createContext<CursorContextType>({\n cursorState: { ...defaultCursorConfig.default, variant: \"default\" },\n setCursorVariant: () => {},\n config: defaultCursorConfig,\n mousePosition: { x: 0, y: 0 },\n resetCursorToDefault: () => {},\n setGlobalCursorVariant: () => {},\n clearGlobalCursorVariant: () => {},\n})\n\nexport const useCursorContext = () => useContext(CursorContext)\n\ninterface CursorProviderProps {\n children: ReactNode\n config?: CursorConfig\n hideNativeCursor?: boolean\n}\n\nexport const CursorProvider: React.FC<CursorProviderProps> = ({\n children,\n config = defaultCursorConfig,\n hideNativeCursor = true,\n}) => {\n const [variantStack, setVariantStack] = useState<string[]>([\"default\"])\n const [globalVariant, setGlobalVariant] = useState<string | null>(null)\n\n // All variant setters are stable (useCallback) so hooks that include them\n // in effect deps (useCursorIdle, useCursorZone) don't re-run every frame.\n const setCursorVariant = useCallback((variant: string, mode: \"push\" | \"pop\" | \"reset\" = \"push\") => {\n if (mode === \"reset\") {\n setVariantStack([\"default\"])\n } else if (mode === \"push\") {\n setVariantStack((prev) => [...prev, variant])\n } else {\n setVariantStack((prev) => {\n const next = prev.slice(0, -1)\n return next.length ? next : [\"default\"]\n })\n }\n }, [])\n\n const resetCursorToDefault = useCallback(() => {\n setVariantStack([\"default\"])\n }, [])\n\n const setGlobalCursorVariant = useCallback((variant: string) => {\n setGlobalVariant(variant)\n }, [])\n\n const clearGlobalCursorVariant = useCallback(() => {\n setGlobalVariant(null)\n }, [])\n\n // Hide native cursor\n useEffect(() => {\n if (!hideNativeCursor) return\n const style = document.createElement(\"style\")\n style.textContent = \"body,a,button,[role=\\\"button\\\"],*{cursor:none!important}\"\n document.head.appendChild(style)\n return () => { document.head.removeChild(style) }\n }, [hideNativeCursor])\n\n // Context value is only recreated when the cursor VARIANT or config changes —\n // never on mouse move. This stops 60fps re-renders of all context consumers\n // (CursorTarget, useMagnetic, useCursorIdle, useCursorZone, etc.).\n const contextValue = useMemo(() => {\n const topVariant = globalVariant ?? variantStack[variantStack.length - 1]\n const currentConfig = config[topVariant] ?? config.default\n const cursorState: CursorState = { ...currentConfig, variant: topVariant }\n\n return {\n cursorState,\n setCursorVariant,\n resetCursorToDefault,\n config,\n // Snapshot at render time. For live position use mouseStore directly\n // or the useMousePosition() hook. @deprecated for reactive use.\n mousePosition: { x: mouseStore.x, y: mouseStore.y },\n setGlobalCursorVariant,\n clearGlobalCursorVariant,\n }\n }, [\n variantStack,\n globalVariant,\n config,\n setCursorVariant,\n resetCursorToDefault,\n setGlobalCursorVariant,\n clearGlobalCursorVariant,\n ])\n\n return (\n <CursorContext.Provider value={contextValue}>\n {children}\n </CursorContext.Provider>\n )\n}\n","\"use client\"\n\nimport type React from \"react\"\nimport { useEffect, useState, useRef } from \"react\"\nimport { useCursorContext } from \"./CursorProvider\"\nimport { mouseStore } from \"../mouseStore\"\n\ninterface CursorProps {\n zIndex?: number\n showOnTouch?: boolean\n trailLength?: number\n /**\n * When true, the cursor squashes and stretches in the direction of travel\n * based on spring velocity. Applies only to circle shapes without a label.\n */\n elongate?: boolean\n}\n\n// Velocity Verlet spring integrator — stable at variable frame rates\nfunction stepSpring(\n pos: number,\n vel: number,\n target: number,\n stiffness: number,\n damping: number,\n mass: number,\n dt: number\n): [number, number] {\n const force = -stiffness * (pos - target) - damping * vel\n const acc = force / mass\n const newVel = vel + acc * dt\n const newPos = pos + vel * dt + 0.5 * acc * dt * dt\n return [newPos, newVel]\n}\n\nexport const Cursor: React.FC<CursorProps> = ({ zIndex = 9999, showOnTouch = false, trailLength = 10, elongate = false }) => {\n const { cursorState } = useCursorContext()\n const [isVisible, setIsVisible] = useState(false)\n const [isTouchDevice, setIsTouchDevice] = useState(false)\n const [reducedMotion, setReducedMotion] = useState(false)\n\n const outerRef = useRef<HTMLDivElement>(null)\n const positionHistoryRef = useRef<{ x: number; y: number }[]>([])\n\n // All mutable animation state lives in refs — never causes re-renders\n const springRef = useRef({ x: 0, y: 0, vx: 0, vy: 0 })\n const targetRef = useRef({ x: 0, y: 0 })\n const rafRef = useRef<number | null>(null)\n const lastTimeRef = useRef<number | null>(null)\n const springConfigRef = useRef({ stiffness: 800, damping: 80, mass: 1 })\n const reducedMotionRef = useRef(false)\n const elongateRef = useRef(elongate)\n const lastAngleRef = useRef(0)\n const cursorShapeRef = useRef({ shape: cursorState.shape, label: cursorState.label })\n // Refs to inner element wrapper divs so RAF can update their transforms directly\n const innerRefsRef = useRef<(HTMLDivElement | null)[]>([])\n\n useEffect(() => {\n springConfigRef.current = {\n stiffness: cursorState.transition?.stiffness ?? 800,\n damping: cursorState.transition?.damping ?? 80,\n mass: cursorState.transition?.mass ?? 1,\n }\n }, [cursorState.transition])\n\n useEffect(() => { elongateRef.current = elongate }, [elongate])\n useEffect(() => {\n cursorShapeRef.current = { shape: cursorState.shape, label: cursorState.label }\n }, [cursorState.shape, cursorState.label])\n\n // Subscribe to shared mouse store — no duplicate window.mousemove listener.\n // targetRef is updated synchronously; the RAF loop reads it on the next frame.\n useEffect(() => {\n return mouseStore.subscribe((x, y) => {\n targetRef.current = { x, y }\n positionHistoryRef.current = [\n { x, y },\n ...positionHistoryRef.current.slice(0, trailLength - 1),\n ]\n })\n }, [trailLength])\n\n // Single RAF loop — starts once, reads only from refs, writes only to DOM.\n // Inner element parallax is also updated here to avoid React re-renders.\n useEffect(() => {\n const animate = (time: number) => {\n if (lastTimeRef.current !== null) {\n if (reducedMotionRef.current) {\n const { x, y } = targetRef.current\n springRef.current = { x, y, vx: 0, vy: 0 }\n if (outerRef.current) outerRef.current.style.transform = `translate(${x}px, ${y}px)`\n } else {\n const dt = Math.min((time - lastTimeRef.current) / 1000, 0.064)\n const { stiffness, damping, mass } = springConfigRef.current\n const { x, y, vx, vy } = springRef.current\n const { x: tx, y: ty } = targetRef.current\n\n // Sub-step to keep Velocity Verlet stable for stiff spring configs.\n // Stability requires dt < sqrt(2)/omega where omega = sqrt(k/m).\n // 8ms sub-steps are stable up to omega ~= 177 rad/s (k/m ~= 31,000).\n const MAX_SUB_DT = 0.008\n const steps = Math.max(1, Math.ceil(dt / MAX_SUB_DT))\n const subDt = dt / steps\n let nx = x, nvx = vx, ny = y, nvy = vy\n for (let i = 0; i < steps; i++) {\n ;[nx, nvx] = stepSpring(nx, nvx, tx, stiffness, damping, mass, subDt)\n ;[ny, nvy] = stepSpring(ny, nvy, ty, stiffness, damping, mass, subDt)\n }\n\n springRef.current = { x: nx, y: ny, vx: nvx, vy: nvy }\n\n if (outerRef.current) {\n const canElongate =\n elongateRef.current &&\n cursorShapeRef.current.shape !== \"square\" &&\n !cursorShapeRef.current.label\n\n if (canElongate) {\n const speed = Math.sqrt(nvx * nvx + nvy * nvy)\n const elong = Math.min(1 + speed / 800, 1.35)\n const comp = 1 / Math.sqrt(elong)\n if (speed > 30) lastAngleRef.current = Math.atan2(nvy, nvx) * (180 / Math.PI)\n outerRef.current.style.transform =\n `translate(${nx}px, ${ny}px) rotate(${lastAngleRef.current}deg) scaleX(${elong}) scaleY(${comp})`\n } else {\n outerRef.current.style.transform = `translate(${nx}px, ${ny}px)`\n }\n }\n\n // Update inner element parallax via direct DOM — zero React re-renders\n const innerDivs = innerRefsRef.current\n if (innerDivs.length > 0) {\n const cur = targetRef.current\n for (let i = 0; i < innerDivs.length; i++) {\n const el = innerDivs[i]\n if (!el) continue\n const delayed = positionHistoryRef.current[Math.min(i + 1, positionHistoryRef.current.length - 1)] || cur\n const ox = -(cur.x - delayed.x) * 0.5\n const oy = -(cur.y - delayed.y) * 0.5\n el.style.transform = `translate(calc(-50% + ${ox}px), calc(-50% + ${oy}px))`\n }\n }\n }\n }\n lastTimeRef.current = time\n rafRef.current = requestAnimationFrame(animate)\n }\n\n rafRef.current = requestAnimationFrame(animate)\n return () => {\n if (rafRef.current !== null) cancelAnimationFrame(rafRef.current)\n }\n }, [])\n\n // Device + accessibility detection\n useEffect(() => {\n const touchMQ = window.matchMedia(\"(pointer: coarse)\")\n setIsTouchDevice(touchMQ.matches)\n\n const motionMQ = window.matchMedia(\"(prefers-reduced-motion: reduce)\")\n reducedMotionRef.current = motionMQ.matches\n setReducedMotion(motionMQ.matches)\n\n const onMotionChange = (e: MediaQueryListEvent) => {\n reducedMotionRef.current = e.matches\n setReducedMotion(e.matches)\n }\n motionMQ.addEventListener(\"change\", onMotionChange)\n\n const timer = setTimeout(() => setIsVisible(true), 50)\n\n return () => {\n motionMQ.removeEventListener(\"change\", onMotionChange)\n clearTimeout(timer)\n }\n }, [])\n\n if (isTouchDevice && !showOnTouch) return null\n\n const {\n width = 24,\n height = 24,\n scale = 1,\n shape = \"circle\",\n color = \"rgba(255, 255, 255, 0.8)\",\n opacity = 1,\n borderColor = \"rgba(0, 0, 0, 0)\",\n borderWidth = 0,\n borderStyle = \"solid\",\n mixBlendMode = \"normal\",\n label,\n fontSize = \"12px\",\n fontWeight = \"bold\",\n labelColor = \"#000\",\n customElement,\n innerElements,\n borderRadius: customBorderRadius,\n } = cursorState\n\n const borderRadius =\n shape === \"circle\" ? \"50%\" : shape === \"square\" ? `${customBorderRadius ?? 0}px` : \"0\"\n\n const bgColor = shape === \"custom\" ? \"transparent\" : color\n\n const shapeTransition = reducedMotion\n ? \"none\"\n : \"width 0.2s ease, height 0.2s ease, border-radius 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease, transform 0.15s ease\"\n\n // Keep the inner refs array in sync with the count of inner elements\n if (innerElements) {\n innerRefsRef.current = innerRefsRef.current.slice(0, innerElements.length)\n } else {\n innerRefsRef.current = []\n }\n\n return (\n <div\n ref={outerRef}\n aria-hidden=\"true\"\n style={{\n position: \"fixed\",\n left: 0,\n top: 0,\n zIndex,\n pointerEvents: \"none\",\n opacity: isVisible ? 1 : 0,\n willChange: \"transform\",\n mixBlendMode,\n transformOrigin: \"0 0\",\n }}\n >\n <div\n style={{\n width,\n height,\n borderRadius,\n backgroundColor: bgColor,\n opacity,\n borderColor,\n borderWidth,\n borderStyle,\n display: \"flex\",\n justifyContent: \"center\",\n alignItems: \"center\",\n transform: `translate(-50%, -50%) scale(${scale})`,\n transition: shapeTransition,\n willChange: \"width, height, background-color, transform\",\n }}\n >\n {shape === \"custom\" && customElement}\n\n {label && (\n <div\n style={{\n fontSize,\n fontWeight,\n color: labelColor,\n textAlign: \"center\",\n userSelect: \"none\",\n whiteSpace: \"nowrap\",\n pointerEvents: \"none\",\n }}\n >\n {label}\n </div>\n )}\n\n {innerElements?.map((item, index) => (\n <div\n key={`inner-${index}`}\n ref={(el) => { innerRefsRef.current[index] = el }}\n style={{\n position: \"absolute\",\n left: \"50%\",\n top: \"50%\",\n // Initial transform — RAF overwrites it every frame via direct DOM\n transform: \"translate(-50%, -50%)\",\n transition: reducedMotion ? \"none\" : \"transform 0.12s ease\",\n }}\n >\n {item.element}\n </div>\n ))}\n </div>\n </div>\n )\n}\n","/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol, Iterator */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === \"function\" ? Iterator : Object).prototype);\r\n return g.next = verb(0), g[\"throw\"] = verb(1), g[\"return\"] = verb(2), typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = Object.create((typeof AsyncIterator === \"function\" ? AsyncIterator : Object).prototype), verb(\"next\"), verb(\"throw\"), verb(\"return\", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }\r\n function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nvar ownKeys = function(o) {\r\n ownKeys = Object.getOwnPropertyNames || function (o) {\r\n var ar = [];\r\n for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;\r\n return ar;\r\n };\r\n return ownKeys(o);\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== \"default\") __createBinding(result, mod, k[i]);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose, inner;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n if (async) inner = dispose;\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n var r, s = 0;\r\n function next() {\r\n while (r = env.stack.pop()) {\r\n try {\r\n if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);\r\n if (r.dispose) {\r\n var result = r.dispose.call(r.value);\r\n if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n else s |= 1;\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport function __rewriteRelativeImportExtension(path, preserveJsx) {\r\n if (typeof path === \"string\" && /^\\.\\.?\\//.test(path)) {\r\n return path.replace(/\\.(tsx)$|((?:\\.d)?)((?:\\.[^./]+?)?)\\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {\r\n return tsx ? preserveJsx ? \".jsx\" : \".js\" : d && (!ext || !cm) ? m : (d + ext + \".\" + cm.toLowerCase() + \"js\");\r\n });\r\n }\r\n return path;\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __esDecorate: __esDecorate,\r\n __runInitializers: __runInitializers,\r\n __propKey: __propKey,\r\n __setFunctionName: __setFunctionName,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n __rewriteRelativeImportExtension: __rewriteRelativeImportExtension,\r\n};\r\n","\"use client\"\n\nimport { useRef } from \"react\"\nimport { useCursorContext } from \"../components/CursorProvider\"\n\ninterface UseCursorOptions {\n variant: string\n onEnter?: () => void\n onLeave?: () => void\n}\n\nexport const useCursor = ({ variant, onEnter, onLeave }: UseCursorOptions) => {\n const { setCursorVariant } = useCursorContext()\n // Prevent double-push when both mouseenter and focus fire on the same interaction\n // (e.g. clicking a button fires mouseenter → push, then focus → push again;\n // mouseleave only pops once, leaving a dangling stack entry).\n const isActiveRef = useRef(false)\n\n return {\n onMouseEnter() {\n if (!isActiveRef.current) { isActiveRef.current = true; setCursorVariant(variant, \"push\") }\n onEnter?.()\n },\n onMouseLeave() {\n if (isActiveRef.current) { isActiveRef.current = false; setCursorVariant(\"\", \"pop\") }\n onLeave?.()\n },\n onFocus() {\n if (!isActiveRef.current) { isActiveRef.current = true; setCursorVariant(variant, \"push\") }\n onEnter?.()\n },\n onBlur() {\n if (isActiveRef.current) { isActiveRef.current = false; setCursorVariant(\"\", \"pop\") }\n onLeave?.()\n },\n \"data-cursor-target\": true,\n }\n}\n","\"use client\"\n\nimport type React from \"react\"\nimport { useEffect, useRef } from \"react\"\n\ntype ClickEffectType = \"ripple\" | \"burst\" | \"sparkle\" | \"shockwave\" | \"confetti\" | \"implode\"\n\ninterface Particle {\n angle: number\n speedMult: number\n confettiColor: string\n rotSpeed: number\n pw: number\n ph: number\n}\n\ninterface ClickEffect {\n x: number\n y: number\n startTime: number\n id: number\n particles: Particle[]\n}\n\ninterface CursorClickEffectProps {\n /** Maximum diameter the effect expands to in px */\n size?: number\n /** Animation duration in ms */\n duration?: number\n /** CSS color string (ignored for confetti, use palette) */\n color?: string\n /** Stroke / particle width in px */\n strokeWidth?: number\n /** z-index */\n zIndex?: number\n /**\n * \"ripple\" — expanding ring (default)\n * \"burst\" — particles radiating outward\n * \"sparkle\" — star-ray lines\n * \"shockwave\" — two concentric rings with stagger\n * \"confetti\" — colored rectangles with gravity\n * \"implode\" — particles rush inward then explode outward\n */\n type?: ClickEffectType\n /** Number of particles / rays */\n particleCount?: number\n /** Color palette for \"confetti\" type */\n palette?: string[]\n}\n\nconst TAU = Math.PI * 2\n\nconst DEFAULT_PALETTE = [\n \"#ff6b6b\", \"#ffd93d\", \"#6bcb77\",\n \"#4d96ff\", \"#c77dff\", \"#ff9a3c\",\n]\n\nexport const CursorClickEffect: React.FC<CursorClickEffectProps> = ({\n size = 50,\n duration = 600,\n color = \"rgba(255, 255, 255, 0.8)\",\n strokeWidth = 2,\n zIndex = 9997,\n type = \"ripple\",\n particleCount = 12,\n palette,\n}) => {\n const canvasRef = useRef<HTMLCanvasElement>(null)\n const effectsRef = useRef<ClickEffect[]>([])\n const idRef = useRef(0)\n const rafRef = useRef<number | null>(null)\n\n useEffect(() => {\n const canvas = canvasRef.current\n if (!canvas) return\n const ctx = canvas.getContext(\"2d\")\n if (!ctx) return\n\n const resize = () => {\n canvas.width = window.innerWidth\n canvas.height = window.innerHeight\n }\n resize()\n window.addEventListener(\"resize\", resize, { passive: true })\n\n const effectivePalette = palette ?? DEFAULT_PALETTE\n\n // Animate only while there are active effects — idle-suspend between clicks.\n const animate = (time: number) => {\n ctx.clearRect(0, 0, canvas.width, canvas.height)\n\n effectsRef.current = effectsRef.current.filter((effect) => {\n const elapsed = Math.max(0, time - effect.startTime)\n if (elapsed >= duration) return false\n\n const progress = elapsed / duration\n\n if (type === \"ripple\") drawRipple(ctx, effect, progress, size, color, strokeWidth)\n else if (type === \"burst\") drawBurst(ctx, effect, progress, size, color, strokeWidth)\n else if (type === \"sparkle\") drawSparkle(ctx, effect, progress, size, color, strokeWidth)\n else if (type === \"shockwave\") drawShockwave(ctx, effect, elapsed, duration, size, color, strokeWidth)\n else if (type === \"confetti\") drawConfetti(ctx, effect, elapsed, duration, size)\n else if (type === \"implode\") drawImplode(ctx, effect, progress, size, color, strokeWidth)\n\n ctx.globalAlpha = 1\n return true\n })\n\n if (effectsRef.current.length > 0) {\n rafRef.current = requestAnimationFrame(animate)\n } else {\n // All effects finished — stop the loop until the next click\n rafRef.current = null\n }\n }\n\n const spawnEffect = (x: number, y: number) => {\n const particles: Particle[] = Array.from({ length: particleCount }, (_, i) => ({\n angle: (i / particleCount) * TAU + (Math.random() - 0.5) * (TAU / particleCount),\n speedMult: 0.6 + Math.random() * 0.4,\n confettiColor: effectivePalette[i % effectivePalette.length],\n rotSpeed: (Math.random() - 0.5) * 18,\n pw: 8 + Math.random() * 10,\n ph: 4 + Math.random() * 6,\n }))\n effectsRef.current.push({ x, y, startTime: performance.now(), id: idRef.current++, particles })\n // Wake the RAF loop if it was idle\n if (rafRef.current === null) {\n rafRef.current = requestAnimationFrame(animate)\n }\n }\n\n const onClick = (e: MouseEvent) => spawnEffect(e.clientX, e.clientY)\n const onCustomClick = (e: Event) => {\n const { x, y } = (e as CustomEvent<{ x: number; y: number }>).detail\n spawnEffect(x, y)\n }\n\n window.addEventListener(\"click\", onClick)\n window.addEventListener(\"cursor:click\", onCustomClick)\n\n return () => {\n window.removeEventListener(\"resize\", resize)\n window.removeEventListener(\"click\", onClick)\n window.removeEventListener(\"cursor:click\", onCustomClick)\n if (rafRef.current !== null) cancelAnimationFrame(rafRef.current)\n }\n }, [color, duration, palette, particleCount, size, strokeWidth, type])\n\n return (\n <canvas\n ref={canvasRef}\n aria-hidden=\"true\"\n style={{ position: \"fixed\", top: 0, left: 0, pointerEvents: \"none\", zIndex }}\n />\n )\n}\n\n// ─── effect renderers ─────────────────────────────────────────────────────────\n\nfunction drawRipple(ctx: CanvasRenderingContext2D, effect: ClickEffect, progress: number, size: number, color: string, strokeWidth: number) {\n const r = Math.max((size / 2) * (1 - Math.pow(1 - progress, 3)), 0.5)\n ctx.beginPath()\n ctx.arc(effect.x, effect.y, r, 0, TAU)\n ctx.strokeStyle = color\n ctx.globalAlpha = 1 - progress\n ctx.lineWidth = strokeWidth\n ctx.stroke()\n}\n\nfunction drawBurst(ctx: CanvasRenderingContext2D, effect: ClickEffect, progress: number, size: number, color: string, strokeWidth: number) {\n const eased = 1 - Math.pow(1 - progress, 2)\n ctx.fillStyle = color\n effect.particles.forEach((p) => {\n const dist = eased * (size / 2) * p.speedMult\n const x = effect.x + Math.cos(p.angle) * dist\n const y = effect.y + Math.sin(p.angle) * dist\n ctx.beginPath()\n ctx.arc(x, y, Math.max((1 - progress) * strokeWidth * 2.5, 0.5), 0, TAU)\n ctx.globalAlpha = (1 - progress) * 0.9\n ctx.fill()\n })\n}\n\nfunction drawSparkle(ctx: CanvasRenderingContext2D, effect: ClickEffect, progress: number, size: number, color: string, strokeWidth: number) {\n const eased = 1 - Math.pow(1 - progress, 2)\n ctx.strokeStyle = color\n ctx.lineCap = \"round\"\n effect.particles.forEach((p) => {\n const x1 = effect.x + Math.cos(p.angle) * eased * (size / 2) * 0.25\n const y1 = effect.y + Math.sin(p.angle) * eased * (size / 2) * 0.25\n const x2 = effect.x + Math.cos(p.angle) * eased * (size / 2) * p.speedMult\n const y2 = effect.y + Math.sin(p.angle) * eased * (size / 2) * p.speedMult\n ctx.beginPath()\n ctx.moveTo(x1, y1)\n ctx.lineTo(x2, y2)\n ctx.globalAlpha = (1 - progress) * 0.85\n ctx.lineWidth = Math.max(strokeWidth * (1 - progress * 0.5), 0.5)\n ctx.stroke()\n })\n ctx.beginPath()\n ctx.arc(effect.x, effect.y, Math.max((1 - progress) * 3, 0.5), 0, TAU)\n ctx.fillStyle = color\n ctx.globalAlpha = 1 - progress\n ctx.fill()\n}\n\nfunction drawShockwave(ctx: CanvasRenderingContext2D, effect: ClickEffect, elapsed: number, duration: number, size: number, color: string, strokeWidth: number) {\n const p1 = elapsed / duration\n ctx.beginPath()\n ctx.arc(effect.x, effect.y, Math.max((size / 2) * (1 - Math.pow(1 - p1, 3)), 0.5), 0, TAU)\n ctx.strokeStyle = color\n ctx.globalAlpha = (1 - p1) * 0.85\n ctx.lineWidth = strokeWidth * 1.5\n ctx.stroke()\n\n const DELAY = 0.15\n if (elapsed > duration * DELAY) {\n const p2 = Math.min((elapsed - duration * DELAY) / (duration * (1 - DELAY)), 1)\n ctx.beginPath()\n ctx.arc(effect.x, effect.y, Math.max((size / 2) * 0.65 * (1 - Math.pow(1 - p2, 3)), 0.5), 0, TAU)\n ctx.globalAlpha = (1 - p2) * 0.5\n ctx.lineWidth = strokeWidth\n ctx.stroke()\n }\n}\n\nfunction drawConfetti(ctx: CanvasRenderingContext2D, effect: ClickEffect, elapsed: number, duration: number, size: number) {\n const t = elapsed / 1000\n\n effect.particles.forEach((p) => {\n const speed = size * 4 + size * 3.5 * p.speedMult\n const vx0 = Math.cos(p.angle) * speed\n const vy0 = Math.sin(p.angle) * speed * 0.5 - size * 7.5\n\n const drag = Math.exp(-1.5 * t)\n const x = effect.x + vx0 * t * drag\n const y = effect.y + vy0 * t + 0.5 * 900 * t * t\n\n const alpha = Math.max(0, 1 - Math.pow(elapsed / duration, 1.5))\n const rot = p.rotSpeed * t\n\n ctx.save()\n ctx.translate(x, y)\n ctx.rotate(rot)\n ctx.fillStyle = p.confettiColor\n ctx.globalAlpha = alpha\n ctx.fillRect(-p.pw / 2, -p.ph / 2, p.pw, p.ph)\n ctx.restore()\n })\n}\n\nfunction drawImplode(ctx: CanvasRenderingContext2D, effect: ClickEffect, progress: number, size: number, color: string, strokeWidth: number) {\n const SPLIT = 0.3\n const maxDist = size / 2\n\n if (progress < SPLIT) {\n const p = progress / SPLIT\n const eased = p * p\n ctx.fillStyle = color\n effect.particles.forEach((part) => {\n const dist = maxDist * (1 - eased) * part.speedMult\n const x = effect.x + Math.cos(part.angle) * dist\n const y = effect.y + Math.sin(part.angle) * dist\n ctx.beginPath()\n ctx.arc(x, y, Math.max(strokeWidth * 2, 0.5), 0, TAU)\n ctx.globalAlpha = 0.7 + eased * 0.3\n ctx.fill()\n })\n ctx.beginPath()\n ctx.arc(effect.x, effect.y, Math.max(eased * 6, 0.5), 0, TAU)\n ctx.globalAlpha = eased\n ctx.fill()\n } else {\n const p = (progress - SPLIT) / (1 - SPLIT)\n const eased = 1 - Math.pow(1 - p, 2)\n ctx.fillStyle = color\n effect.particles.forEach((part) => {\n const dist = eased * maxDist * part.speedMult\n const x = effect.x + Math.cos(part.angle) * dist\n const y = effect.y + Math.sin(part.angle) * dist\n ctx.beginPath()\n ctx.arc(x, y, Math.max((1 - p) * strokeWidth * 2.5, 0.5), 0, TAU)\n ctx.globalAlpha = (1 - p) * 0.9\n ctx.fill()\n })\n }\n}\n","\"use client\"\n\nimport type React from \"react\"\nimport { useEffect, useRef } from \"react\"\nimport { mouseStore } from \"../mouseStore\"\n\ninterface CursorDrawProps {\n /** Ink color */\n color?: string\n /** Stroke width in px */\n width?: number\n /** z-index */\n zIndex?: number\n /**\n * How long strokes persist in ms before fading out.\n * 0 = permanent until double-click or unmount.\n */\n fadeTime?: number\n /** When false, drawing is paused but existing strokes are preserved */\n enabled?: boolean\n /** Eraser diameter in px (right-click drag to erase) */\n eraseWidth?: number\n /** Called after every draw stroke is completed */\n onStroke?: (points: { x: number; y: number }[]) => void\n}\n\ninterface Stroke {\n /** Points in page (document) coordinates — scroll-anchored */\n points: { x: number; y: number }[]\n color: string\n width: number\n createdAt: number\n /** When true, renders with destination-out to erase underlying pixels */\n erase: boolean\n}\n\nexport const CursorDraw: React.FC<CursorDrawProps> = ({\n color = \"rgba(255,255,255,0.85)\",\n width = 2,\n zIndex = 9996,\n fadeTime = 0,\n enabled = true,\n eraseWidth = 20,\n onStroke,\n}) => {\n const canvasRef = useRef<HTMLCanvasElement>(null)\n const strokesRef = useRef<Stroke[]>([])\n const currentRef = useRef<{ x: number; y: number }[] | null>(null)\n const isDownRef = useRef(false)\n const isErasingRef = useRef(false)\n const rafRef = useRef<number | null>(null)\n const enabledRef = useRef(enabled)\n\n useEffect(() => {\n enabledRef.current = enabled\n if (!enabled) {\n isDownRef.current = false\n if (currentRef.current && currentRef.current.length > 1) {\n strokesRef.current.push({\n points: currentRef.current,\n color,\n width,\n createdAt: performance.now(),\n erase: false,\n })\n }\n currentRef.current = null\n }\n }, [enabled, color, width])\n\n useEffect(() => {\n const canvas = canvasRef.current\n if (!canvas) return\n const ctx = canvas.getContext(\"2d\")\n if (!ctx) return\n\n const resize = () => {\n canvas.width = window.innerWidth\n canvas.height = window.innerHeight\n }\n resize()\n window.addEventListener(\"re