feat: add fadeInWithBlur animation to Tailwind CSS and update Markdown component

- Introduced a new `fadeInWithBlur` keyframe animation in Tailwind CSS for enhanced visual effects.
- Removed inline fade animation styles from the `Markdown` component to streamline rendering.
- Updated the `SmoothFade` function to utilize the new animation, improving the user experience during content transitions.
This commit is contained in:
MyPrototypeWhat 2025-09-26 19:34:49 +08:00
parent 93e972a5da
commit d7e79353fc
2 changed files with 10 additions and 11 deletions

View File

@ -163,6 +163,13 @@
} }
} }
@layer components {
@keyframes fadeInWithBlur {
from { opacity: 0; filter: blur(2px); }
to { opacity: 1; filter: blur(0px); }
}
}
:root { :root {
background-color: unset; background-color: unset;
} }

View File

@ -154,7 +154,6 @@ const Markdown: FC<Props> = ({ block, postProcess }) => {
return ( return (
<div className="markdown"> <div className="markdown">
<style>{fadeStyle}</style>
<ReactMarkdown <ReactMarkdown
rehypePlugins={rehypePlugins} rehypePlugins={rehypePlugins}
remarkPlugins={remarkPlugins} remarkPlugins={remarkPlugins}
@ -174,18 +173,11 @@ const Markdown: FC<Props> = ({ block, postProcess }) => {
export default memo(Markdown) export default memo(Markdown)
const fadeStyle = `
@keyframes fadeIn {
from { opacity: 0; filter: blur(2px); }
to { opacity: 1; filter: blur(0px); }
}
`
const SmoothFade = (Comp: React.ElementType, isStreaming: boolean) => { const SmoothFade = (Comp: React.ElementType, isStreaming: boolean) => {
const handleAnimationEnd = (e: React.AnimationEvent) => { const handleAnimationEnd = (e: React.AnimationEvent) => {
// 动画结束后移除类名 // 动画结束后移除类名
if (e.animationName === 'fadeIn') { if (e.animationName === 'fadeInWithBlur') {
e.currentTarget.classList.remove('animate-[fadeIn_500ms_ease-out_forwards]') e.currentTarget.classList.remove('animate-[fadeInWithBlur_500ms_ease-out_forwards]')
e.currentTarget.classList.remove('opacity-0') e.currentTarget.classList.remove('opacity-0')
} }
} }
@ -193,7 +185,7 @@ const SmoothFade = (Comp: React.ElementType, isStreaming: boolean) => {
return ( return (
<Comp <Comp
{...rest} {...rest}
className={isStreaming ? 'animate-[fadeIn_500ms_ease-out_forwards] opacity-0' : ''} className={isStreaming ? 'animate-[fadeInWithBlur_500ms_ease-out_forwards] opacity-0' : ''}
onAnimationEnd={handleAnimationEnd}> onAnimationEnd={handleAnimationEnd}>
{children} {children}
</Comp> </Comp>