{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"image-trail-cursor","type":"registry:ui","title":"ImageTrailCursor","description":"Trail of images that spawn and animate along the cursor's path, powered by GSAP timelines, with 18 selectable variants: fades, momentum drift, rotation flings, 3D perspective tilt, a hard-edge pixelated snap, a bouncy scale pop, images that fall or bounce under gravity, a flame flicker, and five fragment reveals (venetian, curtain, hexagon, liquid, zoom split)","author":"fancy-ui <https://fancy-ui.rama.app>","categories":["effects"],"dependencies":["gsap@^3.14.2"],"registryDependencies":["https://fancy-ui.rama.app/r/internals.json","https://fancy-ui.rama.app/r/internals-dom.json","https://fancy-ui.rama.app/r/internals-motion.json","https://fancy-ui.rama.app/r/utils.json"],"docs":"Installs gsap as a dependency.","files":[{"path":"react/src/components/image-trail-cursor/ImageTrailCursor.tsx","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"../../internals/motion/media-query\";\nimport { cn } from \"../../utils\";\nimport { variantMap, type ImageTrailVariant, type VariantType } from \"./trail-variants\";\n\n/**\n * ImageTrailCursor - Cursor-following image trail with 9 animation variants.\n *\n * The trail images are rendered by React; the motion is driven imperatively by\n * a variant class that owns its own pointer listeners, rAF loop and GSAP\n * timelines. Only the variant switch tears that instance down and rebuilds it,\n * which is what the Svelte `$effect` tracks.\n */\nexport interface ImageTrailCursorProps {\n\timages?: string[];\n\tvariant?: VariantType;\n\tclassName?: string;\n}\n\n/**\n * Clears the inline styles GSAP wrote on the trail elements so a newly\n * constructed variant starts from the stylesheet's own values. The inner\n * element's `background-image` is written by the render, not by GSAP, so it is\n * restored after the wipe.\n */\nfunction resetImageStyles(container: HTMLDivElement) {\n\tconst imgEls = container.querySelectorAll<HTMLDivElement>(\".content__img\");\n\tfor (const el of imgEls) {\n\t\tel.style.cssText = \"\";\n\t\t// reveal variants add fragment children; drop any left behind\n\t\tfor (const frag of el.querySelectorAll(\".content__img-frag\")) frag.remove();\n\t\tconst inner = el.querySelector<HTMLDivElement>(\".content__img-inner\");\n\t\tif (inner) {\n\t\t\t// Preserve background-image set by the render, only clear GSAP residue\n\t\t\tconst bgImage = inner.style.backgroundImage;\n\t\t\tinner.style.cssText = \"\";\n\t\t\tif (bgImage) inner.style.backgroundImage = bgImage;\n\t\t}\n\t}\n}\n\nexport function ImageTrailCursor({\n\timages = [],\n\tvariant = \"type1\",\n\tclassName = \"\",\n}: ImageTrailCursorProps) {\n\tconst containerRef = useRef<HTMLDivElement | null>(null);\n\tconst instanceRef = useRef<ImageTrailVariant | null>(null);\n\t// Live, not just read at mount: flipping the OS setting mid-session starts\n\t// or stops the trail without remounting the component.\n\tconst reduced = useReducedMotion();\n\n\t// `variant` and the reduced-motion preference are the only dependencies,\n\t// exactly as on the Svelte side: a changed `images` array adds or removes\n\t// trail elements without rebuilding the running instance (which keeps the\n\t// element list it captured at construction). Reproduced rather than\n\t// corrected — the Svelte behaviour is the contract. Under reduced motion no\n\t// instance exists at all: no pointer listeners, no rAF loop, no timelines,\n\t// and the trail images stay hidden.\n\tuseEffect(() => {\n\t\tconst container = containerRef.current;\n\t\tif (!container || reduced) return;\n\n\t\tif (instanceRef.current) {\n\t\t\tinstanceRef.current.destroy();\n\t\t\tinstanceRef.current = null;\n\t\t}\n\n\t\tresetImageStyles(container);\n\n\t\tconst Variant = variantMap[variant] || variantMap.type1;\n\t\tinstanceRef.current = new Variant(container);\n\n\t\treturn () => {\n\t\t\tif (instanceRef.current) {\n\t\t\t\tinstanceRef.current.destroy();\n\t\t\t\tinstanceRef.current = null;\n\t\t\t}\n\t\t\t// Wipe what the instance wrote, so a trail stopped by the\n\t\t\t// preference leaves no frozen image on screen.\n\t\t\tresetImageStyles(container);\n\t\t};\n\t}, [variant, reduced]);\n\n\treturn (\n\t\t<div\n\t\t\tref={containerRef}\n\t\t\tclassName={cn(\n\t\t\t\t\"relative z-[100] h-full w-full overflow-visible rounded-lg bg-transparent\",\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tstyle={{ touchAction: \"pan-y pinch-zoom\" }}\n\t\t>\n\t\t\t{images.map((image, i) => (\n\t\t\t\t// Keyed on `variant + i` like the Svelte `{#each}`: switching\n\t\t\t\t// variant remounts every trail element, so no GSAP-written\n\t\t\t\t// inline style survives the switch.\n\t\t\t\t<div\n\t\t\t\t\tkey={variant + i}\n\t\t\t\t\tclassName=\"content__img absolute top-0 left-0 aspect-[1.1] w-[120px] overflow-hidden rounded-[10px] opacity-0 [will-change:transform,filter] sm:w-[190px] sm:rounded-[15px]\"\n\t\t\t\t>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"content__img-inner absolute top-[-10px] left-[-10px] h-[calc(100%+20px)] w-[calc(100%+20px)] bg-cover bg-center\"\n\t\t\t\t\t\tstyle={{ backgroundImage: `url(${image})` }}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t))}\n\t\t</div>\n\t);\n}\n","type":"registry:ui","target":"@ui/fancy/components/image-trail-cursor/ImageTrailCursor.tsx"},{"path":"react/src/components/image-trail-cursor/index.ts","content":"\"use client\";\n\nexport { ImageTrailCursor } from \"./ImageTrailCursor\";\nexport type { ImageTrailCursorProps } from \"./ImageTrailCursor\";\nexport type { VariantType } from \"./trail-variants\";\n","type":"registry:ui","target":"@ui/fancy/components/image-trail-cursor/index.ts"},{"path":"react/src/components/image-trail-cursor/trail-variants.ts","content":"\"use client\";\n\nimport { gsap } from \"gsap\";\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type VariantType =\n\t| \"type1\"\n\t| \"type2\"\n\t| \"type3\"\n\t| \"type4\"\n\t| \"type5\"\n\t| \"type6\"\n\t| \"type7\"\n\t| \"type8\"\n\t| \"pixelated\"\n\t| \"scale\"\n\t| \"fall\"\n\t| \"gravity\"\n\t| \"flame\"\n\t| \"venetian\"\n\t| \"curtain\"\n\t| \"hexagon\"\n\t| \"liquid\"\n\t| \"zoom-split\";\n\nexport interface ImageTrailVariant {\n\tdestroy(): void;\n}\n\n// =============================================================================\n// Helpers\n// =============================================================================\n\nfunction lerp(a: number, b: number, n: number): number {\n\treturn (1 - n) * a + n * b;\n}\n\nfunction getLocalPointerPos(e: MouseEvent | TouchEvent, rect: DOMRect): { x: number; y: number } {\n\tlet clientX = 0;\n\tlet clientY = 0;\n\tif (\"touches\" in e && e.touches.length > 0) {\n\t\t// Non-null: guarded by `e.touches.length > 0` on this same line.\n\t\tconst touch = e.touches[0]!;\n\t\tclientX = touch.clientX;\n\t\tclientY = touch.clientY;\n\t} else if (\"clientX\" in e) {\n\t\tclientX = e.clientX;\n\t\tclientY = e.clientY;\n\t}\n\treturn {\n\t\tx: clientX - rect.left,\n\t\ty: clientY - rect.top,\n\t};\n}\n\nfunction getMouseDistance(p1: { x: number; y: number }, p2: { x: number; y: number }): number {\n\tconst dx = p1.x - p2.x;\n\tconst dy = p1.y - p2.y;\n\treturn Math.hypot(dx, dy);\n}\n\nfunction getNewPosition(position: number, offset: number, arr: ImageItem[]) {\n\tconst realOffset = Math.abs(offset) % arr.length;\n\tif (position - realOffset >= 0) {\n\t\treturn position - realOffset;\n\t} else {\n\t\treturn arr.length - (realOffset - position);\n\t}\n}\n\n// =============================================================================\n// ImageItem\n// =============================================================================\n\nexport class ImageItem {\n\tpublic DOM: { el: HTMLDivElement; inner: HTMLDivElement | null } = {\n\t\tel: null as unknown as HTMLDivElement,\n\t\tinner: null,\n\t};\n\t// `private`, not `public`: the animation library declares `TweenVars` inside a\n\t// GLOBAL namespace with no module-level export, so a public `gsap.TweenVars`\n\t// member emits a bare `gsap.` reference into the shipped .d.ts while tsc drops\n\t// the value-only `import { gsap }` — deep-importing consumers then hit TS2503\n\t// \"Cannot find namespace 'gsap'\". A private member emits no type at all, and it\n\t// is read only by initEvents() below, so nothing outside this class loses access.\n\tprivate defaultStyle: gsap.TweenVars = { scale: 1, x: 0, y: 0, opacity: 0 };\n\tpublic rect: DOMRect | null = null;\n\tprivate resizeHandler: (() => void) | null = null;\n\n\tconstructor(DOM_el: HTMLDivElement) {\n\t\tthis.DOM.el = DOM_el;\n\t\tthis.DOM.inner = this.DOM.el.querySelector(\".content__img-inner\");\n\t\tthis.getRect();\n\t\tthis.initEvents();\n\t}\n\n\tprivate initEvents() {\n\t\tthis.resizeHandler = () => {\n\t\t\tgsap.set(this.DOM.el, this.defaultStyle);\n\t\t\tthis.getRect();\n\t\t};\n\t\twindow.addEventListener(\"resize\", this.resizeHandler);\n\t}\n\n\tprivate getRect() {\n\t\tthis.rect = this.DOM.el.getBoundingClientRect();\n\t}\n\n\tdestroy() {\n\t\tif (this.resizeHandler) {\n\t\t\twindow.removeEventListener(\"resize\", this.resizeHandler);\n\t\t\tthis.resizeHandler = null;\n\t\t}\n\t}\n}\n\n// =============================================================================\n// Base class for shared variant logic\n// =============================================================================\n\nabstract class BaseVariant implements ImageTrailVariant {\n\tprotected container: HTMLDivElement;\n\tprotected DOM: { el: HTMLDivElement };\n\tprotected images: ImageItem[];\n\tprotected imagesTotal: number;\n\tprotected imgPosition: number;\n\tprotected zIndexVal: number;\n\tprotected activeImagesCount: number;\n\tprotected isIdle: boolean;\n\tprotected mousePos: { x: number; y: number };\n\tprotected lastMousePos: { x: number; y: number };\n\tprotected cacheMousePos: { x: number; y: number };\n\n\tprotected touchActive = false;\n\tprivate positionHistory: { x: number; y: number; t: number }[] = [];\n\tprivate static readonly HISTORY_MAX_AGE = 100; // ms\n\tprivate static readonly HISTORY_MAX_LEN = 5;\n\n\tprivate rafId: number | null = null;\n\tprivate rafStarted = false;\n\tprivate destroyed = false;\n\tprivate handlePointerMove: ((ev: MouseEvent | TouchEvent) => void) | null = null;\n\tprivate initRender: ((ev: MouseEvent | TouchEvent) => void) | null = null;\n\tprivate handleTouchStart: ((ev: TouchEvent) => void) | null = null;\n\tprivate handleTouchEnd: ((ev: TouchEvent) => void) | null = null;\n\n\tconstructor(container: HTMLDivElement) {\n\t\tthis.container = container;\n\t\tthis.DOM = { el: container };\n\t\tthis.images = [...container.querySelectorAll(\".content__img\")].map(\n\t\t\t(img) => new ImageItem(img as HTMLDivElement)\n\t\t);\n\t\tthis.imagesTotal = this.images.length;\n\t\tthis.imgPosition = 0;\n\t\tthis.zIndexVal = 1;\n\t\tthis.activeImagesCount = 0;\n\t\tthis.isIdle = true;\n\t\tthis.mousePos = { x: 0, y: 0 };\n\t\tthis.lastMousePos = { x: 0, y: 0 };\n\t\tthis.cacheMousePos = { x: 0, y: 0 };\n\n\t\tthis.handlePointerMove = (ev: MouseEvent | TouchEvent) => {\n\t\t\tconst rect = this.container.getBoundingClientRect();\n\t\t\tthis.mousePos = getLocalPointerPos(ev, rect);\n\t\t\tif (this.touchActive) {\n\t\t\t\tthis.pushPositionHistory(this.mousePos.x, this.mousePos.y);\n\t\t\t}\n\t\t};\n\t\tcontainer.addEventListener(\"mousemove\", this.handlePointerMove);\n\t\tcontainer.addEventListener(\"touchmove\", this.handlePointerMove, { passive: true });\n\n\t\tthis.initRender = (ev: MouseEvent | TouchEvent) => {\n\t\t\tconst rect = this.container.getBoundingClientRect();\n\t\t\tthis.mousePos = getLocalPointerPos(ev, rect);\n\t\t\tthis.cacheMousePos = { ...this.mousePos };\n\t\t\tthis.startRafLoop();\n\t\t\tcontainer.removeEventListener(\"mousemove\", this.initRender as EventListener);\n\t\t\tcontainer.removeEventListener(\"touchmove\", this.initRender as EventListener);\n\t\t};\n\t\tcontainer.addEventListener(\"mousemove\", this.initRender as EventListener);\n\t\tcontainer.addEventListener(\"touchmove\", this.initRender as EventListener, { passive: true });\n\n\t\t// Touch lifecycle handlers\n\t\tthis.handleTouchStart = (ev: TouchEvent) => {\n\t\t\tthis.touchActive = true;\n\t\t\tconst rect = this.container.getBoundingClientRect();\n\t\t\tconst pos = getLocalPointerPos(ev, rect);\n\t\t\tthis.mousePos = pos;\n\t\t\tthis.cacheMousePos = { ...pos };\n\t\t\tthis.lastMousePos = { ...pos };\n\t\t\tthis.positionHistory = [];\n\t\t\tthis.pushPositionHistory(pos.x, pos.y);\n\t\t\tthis.startRafLoop();\n\t\t};\n\t\tcontainer.addEventListener(\"touchstart\", this.handleTouchStart, { passive: true });\n\n\t\tthis.handleTouchEnd = () => {\n\t\t\tthis.touchActive = false;\n\t\t\tthis.lastMousePos = { ...this.mousePos };\n\t\t\tthis.cacheMousePos = { ...this.mousePos };\n\t\t\tthis.positionHistory = [];\n\t\t};\n\t\tcontainer.addEventListener(\"touchend\", this.handleTouchEnd);\n\t\tcontainer.addEventListener(\"touchcancel\", this.handleTouchEnd);\n\t}\n\n\tprivate startRafLoop() {\n\t\tif (this.rafStarted) return;\n\t\t// Nothing to animate when the container holds no trail elements: leaving the\n\t\t// loop unstarted keeps an empty trail (`images` defaults to `[]`) from\n\t\t// rescheduling a requestAnimationFrame every frame until unmount.\n\t\tif (this.imagesTotal === 0) return;\n\t\tthis.rafStarted = true;\n\t\t// Remove initRender listeners since we're starting the loop\n\t\tif (this.initRender) {\n\t\t\tthis.container.removeEventListener(\"mousemove\", this.initRender as EventListener);\n\t\t\tthis.container.removeEventListener(\"touchmove\", this.initRender as EventListener);\n\t\t}\n\t\tthis.rafId = requestAnimationFrame(() => this.render());\n\t}\n\n\tprivate pushPositionHistory(x: number, y: number) {\n\t\tconst now = performance.now();\n\t\tthis.positionHistory.push({ x, y, t: now });\n\t\t// Trim by age and length\n\t\tconst cutoff = now - BaseVariant.HISTORY_MAX_AGE;\n\t\twhile (\n\t\t\tthis.positionHistory.length > BaseVariant.HISTORY_MAX_LEN ||\n\t\t\t// Non-null: `length > 1` on this same clause proves index 0 exists.\n\t\t\t(this.positionHistory.length > 1 && this.positionHistory[0]!.t < cutoff)\n\t\t) {\n\t\t\tthis.positionHistory.shift();\n\t\t}\n\t}\n\n\tprotected getTouchVelocity(): { dx: number; dy: number } {\n\t\tif (!this.touchActive || this.positionHistory.length < 2) {\n\t\t\t// Mouse fallback: same as original behavior\n\t\t\treturn {\n\t\t\t\tdx: this.mousePos.x - this.cacheMousePos.x,\n\t\t\t\tdy: this.mousePos.y - this.cacheMousePos.y,\n\t\t\t};\n\t\t}\n\t\t// Cumulative displacement over the buffer\n\t\tlet dx = 0;\n\t\tlet dy = 0;\n\t\tfor (let i = 1; i < this.positionHistory.length; i++) {\n\t\t\t// Non-null: `i < length` and `i - 1 >= 0` keep both indices in bounds.\n\t\t\tdx += this.positionHistory[i]!.x - this.positionHistory[i - 1]!.x;\n\t\t\tdy += this.positionHistory[i]!.y - this.positionHistory[i - 1]!.y;\n\t\t}\n\t\treturn { dx, dy };\n\t}\n\n\tprotected get threshold(): number {\n\t\treturn this.touchActive ? 40 : 80;\n\t}\n\n\tprotected render() {\n\t\tif (this.destroyed) return;\n\t\tconst distance = getMouseDistance(this.mousePos, this.lastMousePos);\n\t\tthis.updateCache();\n\n\t\tif (distance > this.threshold) {\n\t\t\tthis.showNextImage();\n\t\t\tthis.lastMousePos = { ...this.mousePos };\n\t\t}\n\t\tif (this.isIdle && this.zIndexVal !== 1) {\n\t\t\tthis.zIndexVal = 1;\n\t\t}\n\t\tthis.rafId = requestAnimationFrame(() => this.render());\n\t}\n\n\tprotected updateCache() {\n\t\tthis.cacheMousePos.x = lerp(this.cacheMousePos.x, this.mousePos.x, 0.1);\n\t\tthis.cacheMousePos.y = lerp(this.cacheMousePos.y, this.mousePos.y, 0.1);\n\t}\n\n\tprotected abstract showNextImage(): void;\n\n\t/** Advance to the next image in the ring. */\n\tprotected nextImage(): ImageItem | undefined {\n\t\tthis.imgPosition = this.imgPosition < this.imagesTotal - 1 ? this.imgPosition + 1 : 0;\n\t\treturn this.images[this.imgPosition];\n\t}\n\n\tprotected onImageActivated() {\n\t\tthis.activeImagesCount++;\n\t\tthis.isIdle = false;\n\t}\n\n\tprotected onImageDeactivated() {\n\t\tthis.activeImagesCount--;\n\t\tif (this.activeImagesCount === 0) {\n\t\t\tthis.isIdle = true;\n\t\t}\n\t}\n\n\tdestroy() {\n\t\tthis.destroyed = true;\n\n\t\tif (this.rafId !== null) {\n\t\t\tcancelAnimationFrame(this.rafId);\n\t\t\tthis.rafId = null;\n\t\t}\n\n\t\tif (this.handlePointerMove) {\n\t\t\tthis.container.removeEventListener(\"mousemove\", this.handlePointerMove);\n\t\t\tthis.container.removeEventListener(\"touchmove\", this.handlePointerMove);\n\t\t}\n\t\tif (this.initRender) {\n\t\t\tthis.container.removeEventListener(\"mousemove\", this.initRender as EventListener);\n\t\t\tthis.container.removeEventListener(\"touchmove\", this.initRender as EventListener);\n\t\t}\n\t\tif (this.handleTouchStart) {\n\t\t\tthis.container.removeEventListener(\"touchstart\", this.handleTouchStart);\n\t\t}\n\t\tif (this.handleTouchEnd) {\n\t\t\tthis.container.removeEventListener(\"touchend\", this.handleTouchEnd);\n\t\t\tthis.container.removeEventListener(\"touchcancel\", this.handleTouchEnd);\n\t\t}\n\t\tthis.positionHistory = [];\n\n\t\tfor (const img of this.images) {\n\t\t\tgsap.killTweensOf(img.DOM.el);\n\t\t\tif (img.DOM.inner) gsap.killTweensOf(img.DOM.inner);\n\t\t\timg.destroy();\n\t\t}\n\t}\n}\n\n// =============================================================================\n// Variant 1 — Basic fade & scale trail\n// =============================================================================\n\nexport class ImageTrailVariant1 extends BaseVariant {\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tthis.imgPosition = this.imgPosition < this.imagesTotal - 1 ? this.imgPosition + 1 : 0;\n\t\t// Guard, not an assertion: `images` is built from the container's\n\t\t// `.content__img` children, so an empty container leaves this index\n\t\t// unpopulated — the invariant needed for `!` does not hold here.\n\t\tconst img = this.images[this.imgPosition];\n\t\tif (!img) return;\n\n\t\tgsap.killTweensOf(img.DOM.el);\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\topacity: 1,\n\t\t\t\t\tscale: 1,\n\t\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\t\tx: this.cacheMousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.cacheMousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power1\",\n\t\t\t\t\tx: this.mousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.mousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.to(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power3\",\n\t\t\t\t\topacity: 0,\n\t\t\t\t\tscale: 0.2,\n\t\t\t\t},\n\t\t\t\t0.4\n\t\t\t);\n\t}\n}\n\n// =============================================================================\n// Variant 2 — Scale-up with brightness burst\n// =============================================================================\n\nexport class ImageTrailVariant2 extends BaseVariant {\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tthis.imgPosition = this.imgPosition < this.imagesTotal - 1 ? this.imgPosition + 1 : 0;\n\t\t// Guard, not an assertion: `images` is built from the container's\n\t\t// `.content__img` children, so an empty container leaves this index\n\t\t// unpopulated — the invariant needed for `!` does not hold here.\n\t\tconst img = this.images[this.imgPosition];\n\t\tif (!img) return;\n\n\t\tgsap.killTweensOf(img.DOM.el);\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\topacity: 1,\n\t\t\t\t\tscale: 0,\n\t\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\t\tx: this.cacheMousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.cacheMousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power1\",\n\t\t\t\t\tscale: 1,\n\t\t\t\t\tx: this.mousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.mousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.inner,\n\t\t\t\t{ scale: 2.8, filter: \"brightness(250%)\" },\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power1\",\n\t\t\t\t\tscale: 1,\n\t\t\t\t\tfilter: \"brightness(100%)\",\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.to(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power2\",\n\t\t\t\t\topacity: 0,\n\t\t\t\t\tscale: 0.2,\n\t\t\t\t},\n\t\t\t\t0.45\n\t\t\t);\n\t}\n}\n\n// =============================================================================\n// Variant 3 — Float-up exit with random x drift\n// =============================================================================\n\nexport class ImageTrailVariant3 extends BaseVariant {\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tthis.imgPosition = this.imgPosition < this.imagesTotal - 1 ? this.imgPosition + 1 : 0;\n\t\t// Guard, not an assertion: `images` is built from the container's\n\t\t// `.content__img` children, so an empty container leaves this index\n\t\t// unpopulated — the invariant needed for `!` does not hold here.\n\t\tconst img = this.images[this.imgPosition];\n\t\tif (!img) return;\n\n\t\tgsap.killTweensOf(img.DOM.el);\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\topacity: 1,\n\t\t\t\t\tscale: 0,\n\t\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\t\txPercent: 0,\n\t\t\t\t\tyPercent: 0,\n\t\t\t\t\tx: this.cacheMousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.cacheMousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power1\",\n\t\t\t\t\tscale: 1,\n\t\t\t\t\tx: this.mousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.mousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.inner,\n\t\t\t\t{ scale: 1.2 },\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power1\",\n\t\t\t\t\tscale: 1,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.to(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\tduration: 0.6,\n\t\t\t\t\tease: \"power2\",\n\t\t\t\t\topacity: 0,\n\t\t\t\t\tscale: 0.2,\n\t\t\t\t\txPercent: () => gsap.utils.random(-30, 30),\n\t\t\t\t\tyPercent: -200,\n\t\t\t\t},\n\t\t\t\t0.6\n\t\t\t);\n\t}\n}\n\n// =============================================================================\n// Variant 4 — Momentum-based drift with brightness/contrast\n// =============================================================================\n\nexport class ImageTrailVariant4 extends BaseVariant {\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tthis.imgPosition = this.imgPosition < this.imagesTotal - 1 ? this.imgPosition + 1 : 0;\n\t\t// Guard, not an assertion: `images` is built from the container's\n\t\t// `.content__img` children, so an empty container leaves this index\n\t\t// unpopulated — the invariant needed for `!` does not hold here.\n\t\tconst img = this.images[this.imgPosition];\n\t\tif (!img) return;\n\t\tgsap.killTweensOf(img.DOM.el);\n\n\t\tconst vel = this.getTouchVelocity();\n\t\tlet dx = vel.dx;\n\t\tlet dy = vel.dy;\n\t\tconst distance = Math.sqrt(dx * dx + dy * dy);\n\t\tif (distance !== 0) {\n\t\t\tdx /= distance;\n\t\t\tdy /= distance;\n\t\t}\n\t\tdx *= distance / 100;\n\t\tdy *= distance / 100;\n\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\topacity: 1,\n\t\t\t\t\tscale: 0,\n\t\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\t\tx: this.cacheMousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.cacheMousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power1\",\n\t\t\t\t\tscale: 1,\n\t\t\t\t\tx: this.mousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.mousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.inner,\n\t\t\t\t{\n\t\t\t\t\tscale: 2,\n\t\t\t\t\tfilter: `brightness(${Math.max((400 * distance) / 100, 100)}%) contrast(${Math.max(\n\t\t\t\t\t\t(400 * distance) / 100,\n\t\t\t\t\t\t100\n\t\t\t\t\t)}%)`,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power1\",\n\t\t\t\t\tscale: 1,\n\t\t\t\t\tfilter: \"brightness(100%) contrast(100%)\",\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.to(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power3\",\n\t\t\t\t\topacity: 0,\n\t\t\t\t},\n\t\t\t\t0.4\n\t\t\t)\n\t\t\t.to(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\tduration: 1.5,\n\t\t\t\t\tease: \"power4\",\n\t\t\t\t\tx: `+=${dx * 110}`,\n\t\t\t\t\ty: `+=${dy * 110}`,\n\t\t\t\t},\n\t\t\t\t0.05\n\t\t\t);\n\t}\n}\n\n// =============================================================================\n// Variant 5 — Rotation + momentum fling\n// =============================================================================\n\nexport class ImageTrailVariant5 extends BaseVariant {\n\tprivate lastAngle = 0;\n\n\tprotected showNextImage() {\n\t\tconst vel = this.getTouchVelocity();\n\t\tlet dx = vel.dx;\n\t\tlet dy = vel.dy;\n\t\tlet angle = Math.atan2(dy, dx) * (180 / Math.PI);\n\t\tif (angle < 0) angle += 360;\n\t\tif (angle > 90 && angle <= 270) angle += 180;\n\t\tconst isMovingClockwise = angle >= this.lastAngle;\n\t\tthis.lastAngle = angle;\n\t\tconst startAngle = isMovingClockwise ? angle - 10 : angle + 10;\n\t\tconst distance = Math.sqrt(dx * dx + dy * dy);\n\t\tif (distance !== 0) {\n\t\t\tdx /= distance;\n\t\t\tdy /= distance;\n\t\t}\n\t\tdx *= distance / 150;\n\t\tdy *= distance / 150;\n\n\t\t++this.zIndexVal;\n\t\tthis.imgPosition = this.imgPosition < this.imagesTotal - 1 ? this.imgPosition + 1 : 0;\n\t\t// Guard, not an assertion: `images` is built from the container's\n\t\t// `.content__img` children, so an empty container leaves this index\n\t\t// unpopulated — the invariant needed for `!` does not hold here.\n\t\tconst img = this.images[this.imgPosition];\n\t\tif (!img) return;\n\t\tgsap.killTweensOf(img.DOM.el);\n\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\topacity: 1,\n\t\t\t\t\tfilter: \"brightness(80%)\",\n\t\t\t\t\tscale: 0.1,\n\t\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\t\tx: this.cacheMousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.cacheMousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t\trotation: startAngle,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tduration: 1,\n\t\t\t\t\tease: \"power2\",\n\t\t\t\t\tscale: 1,\n\t\t\t\t\tfilter: \"brightness(100%)\",\n\t\t\t\t\tx: this.mousePos.x - (img.rect?.width ?? 0) / 2 + dx * 70,\n\t\t\t\t\ty: this.mousePos.y - (img.rect?.height ?? 0) / 2 + dy * 70,\n\t\t\t\t\trotation: this.lastAngle,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.to(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"expo\",\n\t\t\t\t\topacity: 0,\n\t\t\t\t},\n\t\t\t\t0.5\n\t\t\t)\n\t\t\t.to(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\tduration: 1.5,\n\t\t\t\t\tease: \"power4\",\n\t\t\t\t\tx: `+=${dx * 120}`,\n\t\t\t\t\ty: `+=${dy * 120}`,\n\t\t\t\t},\n\t\t\t\t0.05\n\t\t\t);\n\t}\n}\n\n// =============================================================================\n// Variant 6 — Speed-reactive size, blur, grayscale\n// =============================================================================\n\nexport class ImageTrailVariant6 extends BaseVariant {\n\tprotected override updateCache() {\n\t\tthis.cacheMousePos.x = lerp(this.cacheMousePos.x, this.mousePos.x, 0.3);\n\t\tthis.cacheMousePos.y = lerp(this.cacheMousePos.y, this.mousePos.y, 0.3);\n\t}\n\n\tprivate mapSpeedToSize(speed: number, minSize: number, maxSize: number) {\n\t\tconst maxSpeed = 200;\n\t\treturn minSize + (maxSize - minSize) * Math.min(speed / maxSpeed, 1);\n\t}\n\n\tprivate mapSpeedToBrightness(speed: number, minB: number, maxB: number) {\n\t\tconst maxSpeed = 70;\n\t\treturn minB + (maxB - minB) * Math.min(speed / maxSpeed, 1);\n\t}\n\n\tprivate mapSpeedToBlur(speed: number, minBlur: number, maxBlur: number) {\n\t\tconst maxSpeed = 90;\n\t\treturn minBlur + (maxBlur - minBlur) * Math.min(speed / maxSpeed, 1);\n\t}\n\n\tprivate mapSpeedToGrayscale(speed: number, minG: number, maxG: number) {\n\t\tconst maxSpeed = 90;\n\t\treturn minG + (maxG - minG) * Math.min(speed / maxSpeed, 1);\n\t}\n\n\tprotected showNextImage() {\n\t\tconst vel = this.getTouchVelocity();\n\t\tconst speed = Math.sqrt(vel.dx * vel.dx + vel.dy * vel.dy);\n\n\t\t++this.zIndexVal;\n\t\tthis.imgPosition = this.imgPosition < this.imagesTotal - 1 ? this.imgPosition + 1 : 0;\n\t\t// Guard, not an assertion: `images` is built from the container's\n\t\t// `.content__img` children, so an empty container leaves this index\n\t\t// unpopulated — the invariant needed for `!` does not hold here.\n\t\tconst img = this.images[this.imgPosition];\n\t\tif (!img) return;\n\n\t\tconst scaleFactor = this.mapSpeedToSize(speed, 0.3, 2);\n\t\tconst brightnessValue = this.mapSpeedToBrightness(speed, 0, 1.3);\n\t\tconst blurValue = this.mapSpeedToBlur(speed, 20, 0);\n\t\tconst grayscaleValue = this.mapSpeedToGrayscale(speed, 600, 0);\n\n\t\tgsap.killTweensOf(img.DOM.el);\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\topacity: 1,\n\t\t\t\t\tscale: 0,\n\t\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\t\tx: this.cacheMousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.cacheMousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tduration: 0.8,\n\t\t\t\t\tease: \"power3\",\n\t\t\t\t\tscale: scaleFactor,\n\t\t\t\t\tfilter: `grayscale(${grayscaleValue * 100}%) brightness(${\n\t\t\t\t\t\tbrightnessValue * 100\n\t\t\t\t\t}%) blur(${blurValue}px)`,\n\t\t\t\t\tx: this.mousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.mousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.inner,\n\t\t\t\t{ scale: 2 },\n\t\t\t\t{\n\t\t\t\t\tduration: 0.8,\n\t\t\t\t\tease: \"power3\",\n\t\t\t\t\tscale: 1,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.to(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power3.in\",\n\t\t\t\t\topacity: 0,\n\t\t\t\t\tscale: 0.2,\n\t\t\t\t},\n\t\t\t\t0.45\n\t\t\t);\n\t}\n}\n\n// =============================================================================\n// Variant 7 — Stacking trail with visible queue\n// =============================================================================\n\nexport class ImageTrailVariant7 extends BaseVariant {\n\tprivate visibleImagesCount: number;\n\tprivate visibleImagesTotal: number;\n\n\tconstructor(container: HTMLDivElement) {\n\t\tsuper(container);\n\t\tthis.visibleImagesCount = 0;\n\t\tthis.visibleImagesTotal = 9;\n\t\tthis.visibleImagesTotal = Math.min(this.visibleImagesTotal, this.imagesTotal - 1);\n\t}\n\n\tprotected override updateCache() {\n\t\tthis.cacheMousePos.x = lerp(this.cacheMousePos.x, this.mousePos.x, 0.3);\n\t\tthis.cacheMousePos.y = lerp(this.cacheMousePos.y, this.mousePos.y, 0.3);\n\t}\n\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tthis.imgPosition = this.imgPosition < this.imagesTotal - 1 ? this.imgPosition + 1 : 0;\n\t\t// Guard, not an assertion: `images` is built from the container's\n\t\t// `.content__img` children, so an empty container leaves this index\n\t\t// unpopulated — the invariant needed for `!` does not hold here.\n\t\tconst img = this.images[this.imgPosition];\n\t\tif (!img) return;\n\t\t++this.visibleImagesCount;\n\n\t\tgsap.killTweensOf(img.DOM.el);\n\t\tconst scaleValue = gsap.utils.random(0.5, 1.6);\n\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\tscale: scaleValue - Math.max(gsap.utils.random(0.2, 0.6), 0),\n\t\t\t\t\trotationZ: 0,\n\t\t\t\t\topacity: 1,\n\t\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\t\tx: this.cacheMousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.cacheMousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power3\",\n\t\t\t\t\tscale: scaleValue,\n\t\t\t\t\trotationZ: gsap.utils.random(-3, 3),\n\t\t\t\t\tx: this.mousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.mousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t);\n\n\t\tif (this.visibleImagesCount >= this.visibleImagesTotal) {\n\t\t\tconst lastInQueue = getNewPosition(this.imgPosition, this.visibleImagesTotal, this.images);\n\t\t\t// Non-null: the `img` guard above proves `images` is non-empty, and\n\t\t\t// getNewPosition() returns a value in [0, images.length) for a non-empty\n\t\t\t// array, so this index is populated.\n\t\t\tconst oldImg = this.images[lastInQueue]!;\n\t\t\tgsap.to(oldImg.DOM.el, {\n\t\t\t\tduration: 0.4,\n\t\t\t\tease: \"power4\",\n\t\t\t\topacity: 0,\n\t\t\t\tscale: 1.3,\n\t\t\t\tonComplete: () => {\n\t\t\t\t\tif (this.activeImagesCount === 0) {\n\t\t\t\t\t\tthis.isIdle = true;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n}\n\n// =============================================================================\n// Variant 8 — 3D perspective based on cursor position\n// =============================================================================\n\nexport class ImageTrailVariant8 extends BaseVariant {\n\tprivate rotation: { x: number; y: number };\n\tprivate cachedRotation: { x: number; y: number };\n\tprivate zValue: number;\n\tprivate cachedZValue: number;\n\n\tconstructor(container: HTMLDivElement) {\n\t\tsuper(container);\n\t\tthis.rotation = { x: 0, y: 0 };\n\t\tthis.cachedRotation = { x: 0, y: 0 };\n\t\tthis.zValue = 0;\n\t\tthis.cachedZValue = 0;\n\t}\n\n\tprotected showNextImage() {\n\t\tconst rect = this.container.getBoundingClientRect();\n\t\tconst centerX = rect.width / 2;\n\t\tconst centerY = rect.height / 2;\n\t\tconst relX = this.mousePos.x - centerX;\n\t\tconst relY = this.mousePos.y - centerY;\n\n\t\tthis.rotation.x = -(relY / centerY) * 30;\n\t\tthis.rotation.y = (relX / centerX) * 30;\n\t\tthis.cachedRotation = { ...this.rotation };\n\n\t\tconst distanceFromCenter = Math.sqrt(relX * relX + relY * relY);\n\t\tconst maxDistance = Math.sqrt(centerX * centerX + centerY * centerY);\n\t\tconst proportion = distanceFromCenter / maxDistance;\n\t\tthis.zValue = proportion * 1200 - 600;\n\t\tthis.cachedZValue = this.zValue;\n\t\tconst normalizedZ = (this.zValue + 600) / 1200;\n\t\tconst brightness = 0.2 + normalizedZ * 2.3;\n\n\t\t++this.zIndexVal;\n\t\tthis.imgPosition = this.imgPosition < this.imagesTotal - 1 ? this.imgPosition + 1 : 0;\n\t\t// Guard, not an assertion: `images` is built from the container's\n\t\t// `.content__img` children, so an empty container leaves this index\n\t\t// unpopulated — the invariant needed for `!` does not hold here.\n\t\tconst img = this.images[this.imgPosition];\n\t\tif (!img) return;\n\t\tgsap.killTweensOf(img.DOM.el);\n\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.set(this.DOM.el, { perspective: 1000 }, 0)\n\t\t\t.fromTo(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\topacity: 1,\n\t\t\t\t\tz: 0,\n\t\t\t\t\tscale: 1 + this.cachedZValue / 1000,\n\t\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\t\tx: this.cacheMousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.cacheMousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t\trotationX: this.cachedRotation.x,\n\t\t\t\t\trotationY: this.cachedRotation.y,\n\t\t\t\t\tfilter: `brightness(${brightness})`,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tduration: 1,\n\t\t\t\t\tease: \"expo\",\n\t\t\t\t\tscale: 1 + this.zValue / 1000,\n\t\t\t\t\tx: this.mousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.mousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t\trotationX: this.rotation.x,\n\t\t\t\t\trotationY: this.rotation.y,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.to(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\tduration: 0.4,\n\t\t\t\t\tease: \"power2\",\n\t\t\t\t\topacity: 0,\n\t\t\t\t\tz: -800,\n\t\t\t\t},\n\t\t\t\t0.3\n\t\t\t);\n\t}\n}\n\n// =============================================================================\n// Variant Pixelated — hard-snap pop-in/pop-out, pixelated + bordered images\n// =============================================================================\n\nexport class ImageTrailVariantPixelated extends BaseVariant {\n\tprivate static readonly HOLD = 0.15; // seconds the image stays visible before snapping out\n\n\tconstructor(container: HTMLDivElement) {\n\t\tsuper(container);\n\t\tfor (const img of this.images) {\n\t\t\timg.DOM.el.style.imageRendering = \"pixelated\";\n\t\t\timg.DOM.el.style.border = \"2px solid #191308\";\n\t\t}\n\t}\n\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tthis.imgPosition = this.imgPosition < this.imagesTotal - 1 ? this.imgPosition + 1 : 0;\n\t\t// Guard, not an assertion: `images` is built from the container's\n\t\t// `.content__img` children, so an empty container leaves this index\n\t\t// unpopulated — the invariant needed for `!` does not hold here.\n\t\tconst img = this.images[this.imgPosition];\n\t\tif (!img) return;\n\n\t\tgsap.killTweensOf(img.DOM.el);\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.set(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\topacity: 1,\n\t\t\t\t\tscale: 1,\n\t\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\t\tx: this.mousePos.x - (img.rect?.width ?? 0) / 2,\n\t\t\t\t\ty: this.mousePos.y - (img.rect?.height ?? 0) / 2,\n\t\t\t\t},\n\t\t\t\t0\n\t\t\t)\n\t\t\t.set(img.DOM.el, { opacity: 0, scale: 0.2 }, ImageTrailVariantPixelated.HOLD);\n\t}\n}\n\n// =============================================================================\n// Shared helpers for the physical and reveal variants\n// =============================================================================\n\nfunction randomBetween(min: number, max: number): number {\n\treturn min + Math.random() * (max - min);\n}\n\n// =============================================================================\n// Variant Scale — pops in with a bouncy scale, then shrinks away behind the cursor\n// =============================================================================\n\nexport class ImageTrailVariantScale extends BaseVariant {\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tconst img = this.nextImage();\n\t\tif (!img) return;\n\t\tconst w = img.rect?.width ?? 0;\n\t\tconst h = img.rect?.height ?? 0;\n\n\t\tgsap.killTweensOf(img.DOM.el);\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.set(img.DOM.el, {\n\t\t\t\topacity: 1,\n\t\t\t\tscale: 0,\n\t\t\t\trotation: randomBetween(-20, 20),\n\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\tx: this.mousePos.x - w / 2,\n\t\t\t\ty: this.mousePos.y - h / 2,\n\t\t\t})\n\t\t\t.to(img.DOM.el, { scale: 1, duration: 0.6, ease: \"back.out(2)\" }, 0)\n\t\t\t.to(img.DOM.el, { scale: 0, duration: 0.6, ease: \"power2.in\" }, 0.75)\n\t\t\t.set(img.DOM.el, { opacity: 0 });\n\t}\n}\n\n// =============================================================================\n// Variant Fall — springs in, spins, and drops out through the bottom\n// =============================================================================\n\nexport class ImageTrailVariantFall extends BaseVariant {\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tconst img = this.nextImage();\n\t\tif (!img) return;\n\t\tconst w = img.rect?.width ?? 0;\n\t\tconst h = img.rect?.height ?? 0;\n\t\tconst floor = this.container.getBoundingClientRect().height;\n\n\t\tgsap.killTweensOf(img.DOM.el);\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.set(img.DOM.el, {\n\t\t\t\topacity: 1,\n\t\t\t\tscale: 0,\n\t\t\t\trotation: 0,\n\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\tx: this.mousePos.x - w / 2,\n\t\t\t\ty: this.mousePos.y - h / 2,\n\t\t\t})\n\t\t\t.to(img.DOM.el, { scale: 1, duration: 0.8, ease: \"elastic.out(1, 0.3)\" }, 0)\n\t\t\t.to(img.DOM.el, { rotation: randomBetween(-360, 360), duration: 1.1, ease: \"power1.out\" }, 0)\n\t\t\t// all the way past the bottom edge, gathering speed\n\t\t\t.to(img.DOM.el, { y: floor * 1.2 + h, duration: 1, ease: \"back.in(0.4)\" }, 0)\n\t\t\t.set(img.DOM.el, { opacity: 0 });\n\t}\n}\n\n// =============================================================================\n// Variant Gravity — cascades from the cursor, lands on the bottom edge, bounces\n// =============================================================================\n\nexport class ImageTrailVariantGravity extends BaseVariant {\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tconst img = this.nextImage();\n\t\tif (!img) return;\n\t\tconst w = img.rect?.width ?? 0;\n\t\tconst h = img.rect?.height ?? 0;\n\t\tconst height = this.container.getBoundingClientRect().height;\n\t\tconst startY = this.mousePos.y - h / 2;\n\t\tconst floorY = Math.max(startY, height - h);\n\t\tconst drop = floorY - startY;\n\t\t// thrown sideways by the pointer, capped so nothing flies off\n\t\tconst push = Math.max(-140, Math.min(140, (this.mousePos.x - this.lastMousePos.x) * 1.4));\n\t\tconst fall = 0.3 + 0.35 * Math.sqrt(drop / Math.max(1, height));\n\t\tconst bounce = drop * 0.32;\n\n\t\tgsap.killTweensOf(img.DOM.el);\n\t\tconst el = img.DOM.el;\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.set(el, {\n\t\t\t\topacity: 1,\n\t\t\t\tscale: 0,\n\t\t\t\trotation: randomBetween(-10, 10),\n\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\tx: this.mousePos.x - w / 2,\n\t\t\t\ty: startY,\n\t\t\t})\n\t\t\t.to(el, { scale: 1, duration: 0.4, ease: \"elastic.out(2, 0.6)\" }, 0)\n\t\t\t// drifting sideways the whole way down and across the bounces\n\t\t\t.to(\n\t\t\t\tel,\n\t\t\t\t{\n\t\t\t\t\tx: `+=${push}`,\n\t\t\t\t\trotation: randomBetween(-30, 30),\n\t\t\t\t\tduration: fall + 0.9,\n\t\t\t\t\tease: \"power1.out\",\n\t\t\t\t},\n\t\t\t\t0.1\n\t\t\t)\n\t\t\t// the fall and two bounces that lose height each time\n\t\t\t.to(el, { y: floorY, duration: fall, ease: \"power2.in\" }, 0.15)\n\t\t\t.to(el, { y: floorY - bounce, duration: 0.28, ease: \"power2.out\" })\n\t\t\t.to(el, { y: floorY, duration: 0.28, ease: \"power2.in\" })\n\t\t\t.to(el, { y: floorY - bounce * 0.3, duration: 0.16, ease: \"power2.out\" })\n\t\t\t.to(el, { y: floorY, duration: 0.16, ease: \"power2.in\" })\n\t\t\t.to(el, { opacity: 0, scale: 0.7, duration: 0.3, ease: \"power2.in\" }, \"+=0.15\");\n\t}\n}\n\n// =============================================================================\n// Variant Flame — flickers up; the faster the pointer, the wilder the tilt\n// =============================================================================\n\nexport class ImageTrailVariantFlame extends BaseVariant {\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tconst img = this.nextImage();\n\t\tif (!img) return;\n\t\tconst w = img.rect?.width ?? 0;\n\t\tconst h = img.rect?.height ?? 0;\n\t\tconst { dx, dy } = this.getTouchVelocity();\n\t\tconst speed = Math.min(1, Math.hypot(dx, dy) / 160);\n\t\tconst rotation = (Math.random() - 0.5) * 30 * (1 + speed * 2);\n\n\t\tgsap.killTweensOf(img.DOM.el);\n\t\tgsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.set(img.DOM.el, {\n\t\t\t\topacity: 1,\n\t\t\t\tscale: 0,\n\t\t\t\trotation,\n\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\tx: this.mousePos.x - w / 2,\n\t\t\t\ty: this.mousePos.y - h / 2,\n\t\t\t})\n\t\t\t.to(img.DOM.el, { scale: 1, duration: 0.35, ease: \"back.out(1.6)\" }, 0)\n\t\t\t// then it rises and burns away, like a flame\n\t\t\t.to(\n\t\t\t\timg.DOM.el,\n\t\t\t\t{\n\t\t\t\t\ty: `-=${40 + speed * 40}`,\n\t\t\t\t\tscale: 0,\n\t\t\t\t\topacity: 0,\n\t\t\t\t\trotation: rotation * 1.6,\n\t\t\t\t\tduration: 0.55,\n\t\t\t\t\tease: \"power2.in\",\n\t\t\t\t},\n\t\t\t\t0.55\n\t\t\t);\n\t}\n}\n\n// =============================================================================\n// Reveal variants — the image opens from fragments, then closes again\n// =============================================================================\n\nexport type RevealPattern = \"venetian\" | \"curtain\" | \"hexagon\" | \"liquid\" | \"zoom-split\";\n\nexport interface RevealFragment {\n\t/** clip-path while hidden */\n\tclosed: string;\n\t/** clip-path once revealed */\n\topen: string;\n\t/** 0 (first) … 1 (last): when the fragment opens within the stagger */\n\torder: number;\n}\n\n/** Neighbouring fragments overlap by this much (%), or anti-aliasing leaves hairlines at the seams. */\nconst SEAM = 0.6;\nconst lo = (n: number) => Math.max(0, n - SEAM);\nconst hi = (n: number) => Math.min(100, n + SEAM);\nconst pc = (n: number) => `${Math.round(n * 100) / 100}%`;\nconst poly = (pts: [number, number][]) =>\n\t`polygon(${pts.map(([x, y]) => `${pc(x)} ${pc(y)}`).join(\", \")})`;\n\n/**\n * The fragments of each reveal, as clip-paths in the image's own box.\n * `closed` and `open` always have the same shape and point count, so the\n * tween between them is a straight interpolation.\n */\nexport function revealFragments(pattern: RevealPattern): RevealFragment[] {\n\tswitch (pattern) {\n\t\tcase \"venetian\": {\n\t\t\t// horizontal slats, each dropping open from its top edge, top to bottom\n\t\t\tconst n = 6;\n\t\t\treturn Array.from({ length: n }, (_, i) => {\n\t\t\t\tconst y0 = lo((i * 100) / n);\n\t\t\t\tconst y1 = hi(((i + 1) * 100) / n);\n\t\t\t\treturn {\n\t\t\t\t\tclosed: poly([\n\t\t\t\t\t\t[0, y0],\n\t\t\t\t\t\t[100, y0],\n\t\t\t\t\t\t[100, y0],\n\t\t\t\t\t\t[0, y0],\n\t\t\t\t\t]),\n\t\t\t\t\topen: poly([\n\t\t\t\t\t\t[0, y0],\n\t\t\t\t\t\t[100, y0],\n\t\t\t\t\t\t[100, y1],\n\t\t\t\t\t\t[0, y1],\n\t\t\t\t\t]),\n\t\t\t\t\torder: i / (n - 1),\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\t\tcase \"curtain\": {\n\t\t\t// vertical strips opening from their centre line, middle strips first\n\t\t\tconst n = 6;\n\t\t\tconst mid = (n - 1) / 2;\n\t\t\treturn Array.from({ length: n }, (_, i) => {\n\t\t\t\tconst x0 = lo((i * 100) / n);\n\t\t\t\tconst x1 = hi(((i + 1) * 100) / n);\n\t\t\t\tconst cx = (x0 + x1) / 2;\n\t\t\t\treturn {\n\t\t\t\t\tclosed: poly([\n\t\t\t\t\t\t[cx, 0],\n\t\t\t\t\t\t[cx, 0],\n\t\t\t\t\t\t[cx, 100],\n\t\t\t\t\t\t[cx, 100],\n\t\t\t\t\t]),\n\t\t\t\t\topen: poly([\n\t\t\t\t\t\t[x0, 0],\n\t\t\t\t\t\t[x1, 0],\n\t\t\t\t\t\t[x1, 100],\n\t\t\t\t\t\t[x0, 100],\n\t\t\t\t\t]),\n\t\t\t\t\torder: Math.abs(i - mid) / mid,\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\t\tcase \"hexagon\": {\n\t\t\t// a 3×3 honeycomb, each cell growing from its centre, centre cell first\n\t\t\tconst centres = [16.67, 50, 83.33];\n\t\t\tconst r = 31; // circumradius wide enough that the cells overlap and cover the box\n\t\t\tconst cells: RevealFragment[] = [];\n\t\t\tfor (const cy of centres) {\n\t\t\t\tfor (const cx of centres) {\n\t\t\t\t\tconst hex: [number, number][] = Array.from({ length: 6 }, (_, k) => {\n\t\t\t\t\t\tconst a = (Math.PI / 3) * k + Math.PI / 6;\n\t\t\t\t\t\treturn [cx + r * Math.cos(a), cy + r * Math.sin(a)];\n\t\t\t\t\t});\n\t\t\t\t\tcells.push({\n\t\t\t\t\t\tclosed: poly(hex.map(() => [cx, cy] as [number, number])),\n\t\t\t\t\t\topen: poly(hex),\n\t\t\t\t\t\torder: Math.hypot(cx - 50, cy - 50) / Math.hypot(33.33, 33.33),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn cells;\n\t\t}\n\t\tcase \"liquid\": {\n\t\t\t// blobs of different sizes swelling out and merging\n\t\t\tconst blobs: [number, number, number][] = [\n\t\t\t\t[50, 50, 48],\n\t\t\t\t[22, 26, 36],\n\t\t\t\t[80, 24, 36],\n\t\t\t\t[26, 80, 36],\n\t\t\t\t[78, 78, 38],\n\t\t\t];\n\t\t\treturn blobs.map(([x, y, r], i) => ({\n\t\t\t\tclosed: `circle(0% at ${pc(x)} ${pc(y)})`,\n\t\t\t\topen: `circle(${pc(r)} at ${pc(x)} ${pc(y)})`,\n\t\t\t\torder: i / (blobs.length - 1),\n\t\t\t}));\n\t\t}\n\t\tcase \"zoom-split\": {\n\t\t\t// four quadrants flying out of the centre point\n\t\t\tconst quads: [number, number][] = [\n\t\t\t\t[0, 0],\n\t\t\t\t[50, 0],\n\t\t\t\t[0, 50],\n\t\t\t\t[50, 50],\n\t\t\t];\n\t\t\treturn quads.map(([x, y], i) => ({\n\t\t\t\tclosed: poly([\n\t\t\t\t\t[50, 50],\n\t\t\t\t\t[50, 50],\n\t\t\t\t\t[50, 50],\n\t\t\t\t\t[50, 50],\n\t\t\t\t]),\n\t\t\t\topen: poly([\n\t\t\t\t\t[lo(x), lo(y)],\n\t\t\t\t\t[hi(x + 50), lo(y)],\n\t\t\t\t\t[hi(x + 50), hi(y + 50)],\n\t\t\t\t\t[lo(x), hi(y + 50)],\n\t\t\t\t]),\n\t\t\t\torder: i / 3,\n\t\t\t}));\n\t\t}\n\t}\n}\n\nconst FRAG_CLASS = \"content__img-frag\";\n\nexport class ImageTrailVariantReveal extends BaseVariant {\n\tprivate static readonly STAGGER = 0.22; // seconds from first to last fragment\n\tprivate readonly fragments: RevealFragment[];\n\n\tconstructor(container: HTMLDivElement, pattern: RevealPattern) {\n\t\tsuper(container);\n\t\tthis.fragments = revealFragments(pattern);\n\t\tfor (const img of this.images) {\n\t\t\tconst bg = img.DOM.inner?.style.backgroundImage ?? \"\";\n\t\t\tfor (const f of this.fragments) {\n\t\t\t\tconst frag = document.createElement(\"div\");\n\t\t\t\tfrag.className = FRAG_CLASS;\n\t\t\t\tfrag.style.cssText = `position:absolute;inset:0;background-image:${bg};background-size:cover;background-position:center;clip-path:${f.closed};`;\n\t\t\t\timg.DOM.el.appendChild(frag);\n\t\t\t}\n\t\t\t// the fragments are the picture now\n\t\t\tif (img.DOM.inner) img.DOM.inner.style.opacity = \"0\";\n\t\t}\n\t}\n\n\tprotected showNextImage() {\n\t\t++this.zIndexVal;\n\t\tconst img = this.nextImage();\n\t\tif (!img) return;\n\t\tconst w = img.rect?.width ?? 0;\n\t\tconst h = img.rect?.height ?? 0;\n\t\tconst frags = [...img.DOM.el.querySelectorAll<HTMLDivElement>(`.${FRAG_CLASS}`)];\n\t\tconst stagger = ImageTrailVariantReveal.STAGGER;\n\n\t\tgsap.killTweensOf([img.DOM.el, ...frags]);\n\t\tconst tl = gsap\n\t\t\t.timeline({\n\t\t\t\tonStart: () => this.onImageActivated(),\n\t\t\t\tonComplete: () => this.onImageDeactivated(),\n\t\t\t})\n\t\t\t.set(img.DOM.el, {\n\t\t\t\topacity: 1,\n\t\t\t\tscale: 0.85,\n\t\t\t\trotation: 0,\n\t\t\t\tzIndex: this.zIndexVal,\n\t\t\t\tx: this.mousePos.x - w / 2,\n\t\t\t\ty: this.mousePos.y - h / 2,\n\t\t\t})\n\t\t\t.to(img.DOM.el, { scale: 1, duration: 0.5, ease: \"power3.out\" }, 0);\n\t\tfrags.forEach((frag, i) => {\n\t\t\tconst f = this.fragments[i]!;\n\t\t\ttl.fromTo(\n\t\t\t\tfrag,\n\t\t\t\t{ clipPath: f.closed },\n\t\t\t\t{ clipPath: f.open, duration: 0.45, ease: \"power3.out\" },\n\t\t\t\tf.order * stagger\n\t\t\t);\n\t\t\t// and closes in reverse order\n\t\t\ttl.to(\n\t\t\t\tfrag,\n\t\t\t\t{ clipPath: f.closed, duration: 0.35, ease: \"power3.in\" },\n\t\t\t\t0.95 + (1 - f.order) * stagger\n\t\t\t);\n\t\t});\n\t\ttl.set(img.DOM.el, { opacity: 0 });\n\t}\n\n\toverride destroy() {\n\t\tfor (const img of this.images) {\n\t\t\tconst frags = img.DOM.el.querySelectorAll(`.${FRAG_CLASS}`);\n\t\t\tgsap.killTweensOf([...frags]);\n\t\t\tfrags.forEach((f) => f.remove());\n\t\t\tif (img.DOM.inner) img.DOM.inner.style.opacity = \"\";\n\t\t}\n\t\tsuper.destroy();\n\t}\n}\n\nfunction revealVariant(pattern: RevealPattern) {\n\treturn class extends ImageTrailVariantReveal {\n\t\tconstructor(container: HTMLDivElement) {\n\t\t\tsuper(container, pattern);\n\t\t}\n\t};\n}\n\n// =============================================================================\n// Variant Map\n// =============================================================================\n\nexport const variantMap: Record<VariantType, new (container: HTMLDivElement) => ImageTrailVariant> =\n\t{\n\t\ttype1: ImageTrailVariant1,\n\t\ttype2: ImageTrailVariant2,\n\t\ttype3: ImageTrailVariant3,\n\t\ttype4: ImageTrailVariant4,\n\t\ttype5: ImageTrailVariant5,\n\t\ttype6: ImageTrailVariant6,\n\t\ttype7: ImageTrailVariant7,\n\t\ttype8: ImageTrailVariant8,\n\t\tpixelated: ImageTrailVariantPixelated,\n\t\tscale: ImageTrailVariantScale,\n\t\tfall: ImageTrailVariantFall,\n\t\tgravity: ImageTrailVariantGravity,\n\t\tflame: ImageTrailVariantFlame,\n\t\tvenetian: revealVariant(\"venetian\"),\n\t\tcurtain: revealVariant(\"curtain\"),\n\t\thexagon: revealVariant(\"hexagon\"),\n\t\tliquid: revealVariant(\"liquid\"),\n\t\t\"zoom-split\": revealVariant(\"zoom-split\"),\n\t};\n","type":"registry:ui","target":"@ui/fancy/components/image-trail-cursor/trail-variants.ts"}],"meta":{"license":"MIT","package":"fancy-ui-react","version":"0.7.0","source":"https://fancy-ui.rama.app/docs/components/image-trail-cursor?framework=react"}}