Skip to content

Commit 1c4bbcd

Browse files
committed
refactor: refactor
1 parent 216beed commit 1c4bbcd

5 files changed

Lines changed: 64 additions & 58 deletions

File tree

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@
276276
"markmap-lib": "^0.18.11",
277277
"markmap-view": "^0.18.10",
278278
"mermaid": "^11.6.0",
279-
"motion": "^12.16.0",
279+
"motion": "^12.23.12",
280280
"nanoid": "^5.1.5",
281281
"node-polyfill-webpack-plugin": "^4.1.0",
282282
"number-flow": "^0.5.7",

src/components/stateless/GradientTracing/index.tsx

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { motion } from 'motion/react'
2+
import { motion, easeInOut } from 'framer-motion'
33

44
interface GradientTracingProps {
55
width: number
@@ -12,38 +12,53 @@ interface GradientTracingProps {
1212
}
1313

1414
const GradientTracing: React.FC<GradientTracingProps> = ({
15-
width,
16-
height,
15+
width = 200,
16+
height = 200,
1717
baseColor = 'black',
1818
gradientColors = ['#2EB9DF', '#2EB9DF', '#9E00FF'],
1919
animationDuration = 2,
2020
strokeWidth = 2,
2121
path,
2222
}) => {
23-
const gradientId = `pulse-${Math.random().toString(36).substring(2, 9)}`
23+
const gradientId = `pulse-gradient-${Date.now()}`
24+
const gradientVariants = {
25+
initial: {
26+
x1: '0%',
27+
x2: '0%',
28+
},
29+
animate: {
30+
x1: `${width * 2}px`,
31+
x2: `${width}px`,
32+
transition: {
33+
duration: animationDuration,
34+
repeat: Infinity,
35+
ease: easeInOut,
36+
},
37+
},
38+
}
2439

2540
return (
2641
<div className="relative" style={{ width, height }}>
2742
<svg width={width} height={height} viewBox={`0 0 ${width} ${height}`} fill="none">
28-
<path d={path} stroke={baseColor} strokeOpacity="0.2" />
29-
<path d={path} stroke={`url(#${gradientId})`} strokeLinecap="round" strokeWidth={strokeWidth} />
43+
<path d={path} stroke={baseColor} strokeOpacity="0.2" strokeWidth={strokeWidth} fill="none" />
44+
45+
<path d={path} stroke={`url(#${gradientId})`} strokeLinecap="round" strokeWidth={strokeWidth} fill="none" />
46+
3047
<defs>
3148
<motion.linearGradient
32-
animate={{
33-
x1: [0, width * 2],
34-
x2: [0, width],
35-
}}
36-
transition={{
37-
duration: animationDuration,
38-
repeat: Infinity,
39-
ease: 'linear',
40-
}}
49+
variants={gradientVariants}
50+
initial="initial"
51+
animate="animate"
4152
id={gradientId}
4253
gradientUnits="userSpaceOnUse"
54+
x1="0%"
55+
y1="0%"
56+
x2="0%"
57+
y2="0%"
4358
>
44-
<stop stopColor={gradientColors[0]} stopOpacity="0" />
45-
<stop stopColor={gradientColors[1]} />
46-
<stop offset="1" stopColor={gradientColors[2]} stopOpacity="0" />
59+
<stop offset="0%" stopColor={gradientColors[0]} stopOpacity="0" />
60+
<stop offset="50%" stopColor={gradientColors[1]} stopOpacity="1" />
61+
<stop offset="100%" stopColor={gradientColors[2]} stopOpacity="0" />
4762
</motion.linearGradient>
4863
</defs>
4964
</svg>

src/components/stateless/ScratchToReveal/index.jsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ import { motion, useAnimation } from 'motion/react'
55
const ScratchToReveal = ({ width, height, minScratchPercentage = 50, onComplete, children, className }) => {
66
const canvasRef = useRef(null)
77
const [isScratching, setIsScratching] = useState(false)
8-
const [isComplete, setIsComplete] = useState(false) // New state to track completion
8+
const [isComplete, setIsComplete] = useState(false)
99

1010
const controls = useAnimation()
1111

1212
useEffect(() => {
1313
const canvas = canvasRef.current
14-
const ctx = canvas?.getContext('2d')
15-
if (canvas && ctx) {
16-
const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height)
17-
gradient.addColorStop(0, '#A97CF8')
18-
gradient.addColorStop(0.5, '#F38CB8')
19-
gradient.addColorStop(1, '#FDCC92')
20-
ctx.fillStyle = gradient
21-
ctx.fillRect(0, 0, canvas.width, canvas.height)
14+
if (canvas) {
15+
// 关键优化:添加willReadFrequently: true
16+
const ctx = canvas.getContext('2d', { willReadFrequently: true })
17+
if (ctx) {
18+
const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height)
19+
gradient.addColorStop(0, '#A97CF8')
20+
gradient.addColorStop(0.5, '#F38CB8')
21+
gradient.addColorStop(1, '#FDCC92')
22+
ctx.fillStyle = gradient
23+
ctx.fillRect(0, 0, canvas.width, canvas.height)
24+
}
2225
}
2326
}, [])
2427

src/pages/home/index.jsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,7 @@ const preCode = `
110110
);
111111
};
112112
`.trim()
113-
const slugs = [
114-
'typescript',
115-
'javascript',
116-
'react',
117-
'html5',
118-
'css3',
119-
'prisma',
120-
'nginx',
121-
'vercel',
122-
'docker',
123-
'git',
124-
'sonarqube',
125-
]
113+
const slugs = ['typescript', 'javascript', 'react', 'html5', 'css', 'prisma', 'nginx', 'vercel', 'docker', 'git']
126114

127115
const dataSteps = [
128116
{

0 commit comments

Comments
 (0)