Files
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

190 lines
4.2 KiB
TypeScript

"use client";
import type { HTMLAttributes, MouseEvent } from "react";
import {
forwardRef,
useCallback,
useEffect,
useImperativeHandle,
useRef
} from "react";
import {
motion,
useAnimation,
useReducedMotion,
type Variants
} from "framer-motion";
import { cn } from "../../lib/utils";
export interface FileTextIconHandle {
startAnimation: () => void;
stopAnimation: () => void;
}
interface FileTextIconProps extends HTMLAttributes<HTMLDivElement> {
size?: number;
active?: boolean;
}
const FILE_TEXT_LINE_VARIANTS: Variants = {
normal: {
pathLength: 1,
pathOffset: 0
},
animate: (delay: number) => ({
pathLength: [1, 0, 1],
pathOffset: [0, 1, 0],
transition: {
duration: 0.7,
delay,
ease: "easeInOut"
}
}),
active: (delay: number) => ({
pathLength: [1, 0, 1],
pathOffset: [0, 1, 0],
transition: {
duration: 0.7,
delay,
ease: "easeInOut",
repeat: Number.POSITIVE_INFINITY,
repeatDelay: 1.1
}
})
};
const FileTextIcon = forwardRef<FileTextIconHandle, FileTextIconProps>(
(
{
active = false,
onMouseEnter,
onMouseLeave,
className,
size = 28,
...props
},
ref
) => {
const controls = useAnimation();
const reduceMotion = useReducedMotion();
const isControlledRef = useRef(false);
const startAnimation = useCallback(() => {
if (reduceMotion) {
return;
}
void controls.start(active ? "active" : "animate");
}, [active, controls, reduceMotion]);
const stopAnimation = useCallback(() => {
void controls.start("normal");
}, [controls]);
useImperativeHandle(ref, () => {
isControlledRef.current = true;
return {
startAnimation,
stopAnimation
};
});
useEffect(() => {
if (active) {
startAnimation();
return;
}
stopAnimation();
}, [active, startAnimation, stopAnimation]);
const handleMouseEnter = useCallback(
(event: MouseEvent<HTMLDivElement>) => {
if (isControlledRef.current) {
onMouseEnter?.(event);
} else {
startAnimation();
}
},
[onMouseEnter, startAnimation]
);
const handleMouseLeave = useCallback(
(event: MouseEvent<HTMLDivElement>) => {
if (isControlledRef.current) {
onMouseLeave?.(event);
} else {
stopAnimation();
}
},
[onMouseLeave, stopAnimation]
);
return (
<div
className={cn("inline-flex items-center justify-center", className)}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
{...props}
>
<motion.svg
animate={controls}
fill="none"
height={size}
initial="normal"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
variants={{
normal: { scale: 1 },
animate: {
scale: 1.05,
transition: {
duration: 0.3,
ease: "easeOut"
}
},
active: {
scale: [1, 1.05, 1],
transition: {
duration: 0.9,
ease: "easeInOut",
repeat: Number.POSITIVE_INFINITY,
repeatDelay: 0.9
}
}
}}
viewBox="0 0 24 24"
width={size}
xmlns="http://www.w3.org/2000/svg"
>
<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z" />
<path d="M14 2v4a2 2 0 0 0 2 2h4" />
<motion.path
animate={controls}
custom={0.3}
d="M10 9H8"
variants={FILE_TEXT_LINE_VARIANTS}
/>
<motion.path
animate={controls}
custom={0.5}
d="M16 13H8"
variants={FILE_TEXT_LINE_VARIANTS}
/>
<motion.path
animate={controls}
custom={0.7}
d="M16 17H8"
variants={FILE_TEXT_LINE_VARIANTS}
/>
</motion.svg>
</div>
);
}
);
FileTextIcon.displayName = "FileTextIcon";
export { FileTextIcon };