feat: 添加多个附录交互式组件和文档更新

- 添加浏览器前端组件:无障碍访问、国际化、实时通信
- 添加 Transformer 注意力机制系列组件
- 更新 Canvas、数据追踪等现有组件
- 修复 ESLint 变量名冲突问题
- 完善相关附录文档
This commit is contained in:
sanbuphy
2026-02-24 08:34:53 +08:00
parent 94f9db0834
commit 260d17ee8b
42 changed files with 5290 additions and 12173 deletions
@@ -90,41 +90,11 @@
/>
</div>
<div class="code-display">
<h4>Animation Loop Code / 动画循环代码</h4>
<pre><code>{{ animationCode }}</code></pre>
</div>
<div class="explanation">
<h4>Animation Principles / 动画原理</h4>
<ul>
<li>
<strong>requestAnimationFrame</strong>
浏览器提供的动画 API在每次重绘前调用回调函数通常为 60FPS
</li>
<li>
<strong>Clear & Redraw</strong>
每帧先清除画布再重新绘制所有内容
</li>
<li>
<strong>State Update</strong>
更新对象位置角度等状态
</li>
<li>
<strong>Performance</strong>
使用时间差计算位置确保不同刷新率下动画速度一致
</li>
</ul>
</div>
<div class="info-box">
<p>
<span class="icon">💡</span>
<strong>提示</strong>
动画的本质是快速连续绘制静态画面Canvas 每秒可以绘制 60
60FPS形成流畅的动画效果
</p>
</div>
</div>
</template>
@@ -565,11 +535,12 @@ onUnmounted(() => {
display: flex;
justify-content: center;
margin: 1.5rem 0;
padding: 1.5rem;
padding: 1rem;
background: var(--vp-c-bg);
border-radius: 12px;
border: 2px solid var(--vp-c-divider);
box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
overflow-x: auto;
}
canvas {
@@ -577,83 +548,7 @@ canvas {
border-radius: 6px;
background: #ffffff;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.code-display {
margin-top: 1.5rem;
padding: 1.25rem;
background: #1e293b;
border-radius: 12px;
overflow-x: auto;
border: 2px solid #334155;
}
.code-display h4 {
color: #f8fafc;
margin: 0 0 0.75rem 0;
font-size: 0.875rem;
font-weight: 600;
}
.code-display pre {
margin: 0;
}
.code-display code {
color: #e2e8f0;
font-family: var(--vp-font-family-mono);
font-size: 0.75rem;
line-height: 1.7;
}
.explanation {
margin: 1.5rem 0;
padding: 1.25rem;
background: var(--vp-c-bg);
border-radius: 6px;
border: 1px solid var(--vp-c-divider);
}
.explanation h4 {
margin: 0 0 0.75rem 0;
color: var(--vp-c-text-1);
font-size: 0.875rem;
font-weight: 600;
}
.explanation ul {
margin: 0;
padding-left: 1.25rem;
}
.explanation li {
margin-bottom: 0.5rem;
color: var(--vp-c-text-2);
font-size: 0.875rem;
line-height: 1.6;
}
.info-box {
margin-top: 1.5rem;
padding: 1rem 1.25rem;
background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
border-radius: 12px;
border-left: 4px solid #f59e0b;
box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}
.info-box p {
margin: 0;
font-size: 0.875rem;
color: #92400e;
display: flex;
align-items: flex-start;
gap: 0.5rem;
line-height: 1.6;
}
.info-box .icon {
font-size: 1.125rem;
flex-shrink: 0;
}
</style>
@@ -127,16 +127,10 @@
/>
</div>
<div class="code-display">
<h4>Code / 代码</h4>
<pre><code>{{ currentCode }}</code></pre>
</div>
</div>
<div class="info-box">
<span class="icon">💡</span>
<strong>核心思想</strong>Canvas 是一个位图画布所有绘制都是像素操作绘制后无法修改已有内容只能覆盖或清除重绘
</div>
</div>
</template>
@@ -433,75 +427,20 @@ onMounted(() => {
display: flex;
justify-content: center;
margin: 1.5rem 0;
padding: 1.5rem;
padding: 1rem;
background: var(--vp-c-bg);
border-radius: 12px;
border: 2px solid var(--vp-c-divider);
box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
overflow-x: auto;
}
canvas {
border: 3px solid var(--vp-c-divider);
border-radius: 6px;
background: #ffffff;
max-width: 100%;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.code-display {
margin-top: 1.5rem;
padding: 1.25rem;
background: #1e293b;
border-radius: 12px;
overflow-x: auto;
border: 2px solid #334155;
}
.code-display h4 {
color: #f8fafc;
margin: 0 0 0.75rem 0;
font-size: 0.875rem;
font-weight: 600;
}
.code-display pre {
margin: 0;
}
.code-display code {
color: #e2e8f0;
font-family: var(--vp-font-family-mono);
font-size: 0.75rem;
line-height: 1.7;
}
.info-box {
margin-top: 1.5rem;
background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
padding: 1rem 1.25rem;
border-radius: 12px;
font-size: 0.875rem;
color: #92400e;
border-left: 4px solid #f59e0b;
display: flex;
gap: 0.5rem;
box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}
.info-box p {
margin: 0;
display: flex;
align-items: flex-start;
gap: 0.625rem;
line-height: 1.6;
}
.info-box .icon {
font-size: 1.125rem;
flex-shrink: 0;
}
.info-box strong {
color: #78350f;
}
</style>
@@ -74,56 +74,11 @@
/>
</div>
<div class="explanation">
<h4>Canvas Coordinate System / Canvas 坐标系统</h4>
<ul>
<li><strong>Origin / 原点</strong>在左上角坐标为 (0, 0)</li>
<li>
<strong>X Axis / X </strong>向右为正方向 0 canvas.width
</li>
<li>
<strong>Y Axis / Y </strong>向下为正方向 0 canvas.height
</li>
<li><strong>Unit / 单位</strong>像素 (px) CSS 像素 1:1 对应</li>
</ul>
</div>
<div class="code-display">
<h4>Example Code / 示例代码</h4>
<pre><code>// 绘制坐标轴
const canvas = document.getElementById('myCanvas')
const ctx = canvas.getContext('2d')
// X 轴(红色)
ctx.strokeStyle = '#e74c3c'
ctx.lineWidth = 2
ctx.beginPath()
ctx.moveTo(0, 0)
ctx.lineTo(canvas.width, 0)
ctx.stroke()
// Y 轴(蓝色)
ctx.strokeStyle = '#3498db'
ctx.beginPath()
ctx.moveTo(0, 0)
ctx.lineTo(0, canvas.height)
ctx.stroke()
// 绘制点
ctx.fillStyle = '#2ecc71'
ctx.beginPath()
ctx.arc({{ Math.round(selectedPoint?.x || 100) }}, {{ Math.round(selectedPoint?.y || 100) }}, 5, 0, Math.PI * 2)
ctx.fill()</code></pre>
</div>
<div class="info-box">
<p>
<span class="icon">💡</span>
<strong>提示</strong>
Canvas Y
轴方向与传统数学坐标系相反向下为正这在处理图形定位时需要特别注意
</p>
</div>
</div>
</template>
@@ -360,11 +315,12 @@ onMounted(() => {
display: flex;
justify-content: center;
margin: 1.5rem 0;
padding: 1.5rem;
padding: 1rem;
background: var(--vp-c-bg);
border-radius: 12px;
border: 2px solid var(--vp-c-divider);
box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
overflow-x: auto;
}
canvas {
@@ -373,83 +329,7 @@ canvas {
cursor: crosshair;
background: #ffffff;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.explanation {
margin: 1.5rem 0;
padding: 1.25rem;
background: var(--vp-c-bg);
border-radius: 6px;
border: 1px solid var(--vp-c-divider);
}
.explanation h4 {
margin: 0 0 0.75rem 0;
color: var(--vp-c-text-1);
font-size: 0.875rem;
font-weight: 600;
}
.explanation ul {
margin: 0;
padding-left: 1.25rem;
}
.explanation li {
margin-bottom: 0.5rem;
color: var(--vp-c-text-2);
font-size: 0.875rem;
line-height: 1.6;
}
.code-display {
margin-top: 1.5rem;
padding: 1.25rem;
background: #1e293b;
border-radius: 12px;
overflow-x: auto;
border: 2px solid #334155;
}
.code-display h4 {
color: #f8fafc;
margin: 0 0 0.75rem 0;
font-size: 0.875rem;
font-weight: 600;
}
.code-display pre {
margin: 0;
}
.code-display code {
color: #e2e8f0;
font-family: var(--vp-font-family-mono);
font-size: 0.75rem;
line-height: 1.7;
}
.info-box {
margin-top: 1.5rem;
padding: 1rem 1.25rem;
background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
border-radius: 12px;
border-left: 4px solid #f59e0b;
box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}
.info-box p {
margin: 0;
font-size: 0.875rem;
color: #92400e;
display: flex;
align-items: flex-start;
gap: 0.5rem;
line-height: 1.6;
}
.info-box .icon {
font-size: 1.125rem;
flex-shrink: 0;
}
</style>
@@ -87,32 +87,9 @@
/>
</div>
<div class="code-display">
<h4>Event Handling Code / 事件处理代码</h4>
<pre><code>{{ currentCode }}</code></pre>
</div>
<div class="explanation">
<h4>Event Handling Tips / 事件处理要点</h4>
<ul>
<li>
<strong>坐标转换</strong>
使用 getBoundingClientRect() 获取 Canvas 在页面中的位置计算相对坐标
</li>
<li>
<strong>碰撞检测</strong>
对于圆形计算鼠标位置到圆心的距离对于矩形判断点是否在范围内
</li>
<li>
<strong>事件委托</strong>
Canvas 只有一个元素需要手动判断事件发生在哪个对象上
</li>
<li>
<strong>性能优化</strong>
使用 requestAnimationFrame 优化重绘避免频繁操作
</li>
</ul>
</div>
</div>
</template>
@@ -647,11 +624,12 @@ onMounted(() => {
display: flex;
justify-content: center;
margin: 1.5rem 0;
padding: 1.5rem;
padding: 1rem;
background: var(--vp-c-bg);
border-radius: 12px;
border: 2px solid var(--vp-c-divider);
box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
overflow-x: auto;
}
canvas {
@@ -661,63 +639,11 @@ canvas {
outline: none;
background: #ffffff;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
flex-shrink: 0;
}
canvas:focus {
border-color: var(--vp-c-brand);
}
.code-display {
margin-top: 1.5rem;
padding: 1.25rem;
background: #1e293b;
border-radius: 12px;
overflow-x: auto;
border: 2px solid #334155;
}
.code-display h4 {
color: #f8fafc;
margin: 0 0 0.75rem 0;
font-size: 0.875rem;
font-weight: 600;
}
.code-display pre {
margin: 0;
}
.code-display code {
color: #e2e8f0;
font-family: var(--vp-font-family-mono);
font-size: 0.75rem;
line-height: 1.7;
}
.explanation {
margin: 1.5rem 0;
padding: 1.25rem;
background: var(--vp-c-bg);
border-radius: 6px;
border: 1px solid var(--vp-c-divider);
}
.explanation h4 {
margin: 0 0 0.75rem 0;
color: var(--vp-c-text-1);
font-size: 0.875rem;
font-weight: 600;
}
.explanation ul {
margin: 0;
padding-left: 1.25rem;
}
.explanation li {
margin-bottom: 0.5rem;
color: var(--vp-c-text-2);
font-size: 0.875rem;
line-height: 1.6;
}
</style>
@@ -102,40 +102,11 @@
/>
</div>
<div class="code-display">
<h4>Particle System Code / 粒子系统代码</h4>
<pre><code>{{ particleCode }}</code></pre>
</div>
<div class="explanation">
<h4>Particle System Tips / 粒子系统要点</h4>
<ul>
<li>
<strong>粒子类</strong>
每个粒子是一个对象包含位置速度加速度生命周期等属性
</li>
<li>
<strong>更新循环</strong>
每帧更新所有粒子的位置和状态移除死亡的粒子
</li>
<li>
<strong>性能优化</strong>
限制粒子数量使用对象池复用粒子对象
</li>
<li>
<strong>视觉效果</strong>
使用透明度混合模式渐变等增强视觉效果
</li>
</ul>
</div>
<div class="info-box">
<p>
<span class="icon">💡</span>
<strong>提示</strong>
移动鼠标或点击画布来产生粒子不同的效果有不同的交互方式
</p>
</div>
</div>
</template>
@@ -513,11 +484,12 @@ onUnmounted(() => {
display: flex;
justify-content: center;
margin: 1.5rem 0;
padding: 1.5rem;
padding: 1rem;
background: var(--vp-c-bg);
border-radius: 12px;
border: 2px solid var(--vp-c-divider);
box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
overflow-x: auto;
}
canvas {
@@ -526,83 +498,7 @@ canvas {
cursor: crosshair;
background: #ffffff;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.code-display {
margin-top: 1.5rem;
padding: 1.25rem;
background: #1e293b;
border-radius: 12px;
overflow-x: auto;
border: 2px solid #334155;
}
.code-display h4 {
color: #f8fafc;
margin: 0 0 0.75rem 0;
font-size: 0.875rem;
font-weight: 600;
}
.code-display pre {
margin: 0;
}
.code-display code {
color: #e2e8f0;
font-family: var(--vp-font-family-mono);
font-size: 0.75rem;
line-height: 1.7;
}
.explanation {
margin: 1.5rem 0;
padding: 1.25rem;
background: var(--vp-c-bg);
border-radius: 6px;
border: 1px solid var(--vp-c-divider);
}
.explanation h4 {
margin: 0 0 0.75rem 0;
color: var(--vp-c-text-1);
font-size: 0.875rem;
font-weight: 600;
}
.explanation ul {
margin: 0;
padding-left: 1.25rem;
}
.explanation li {
margin-bottom: 0.5rem;
color: var(--vp-c-text-2);
font-size: 0.875rem;
line-height: 1.6;
}
.info-box {
margin-top: 1.5rem;
padding: 1rem 1.25rem;
background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
border-radius: 12px;
border-left: 4px solid #f59e0b;
box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}
.info-box p {
margin: 0;
font-size: 0.875rem;
color: #92400e;
display: flex;
align-items: flex-start;
gap: 0.5rem;
line-height: 1.6;
}
.info-box .icon {
font-size: 1.125rem;
flex-shrink: 0;
}
</style>
@@ -174,36 +174,9 @@
</div>
</div>
<div class="code-display">
<h4>Optimization Code / 优化代码</h4>
<pre><code>{{ optimizationCode }}</code></pre>
</div>
<div class="explanation">
<h4>Performance Tips / 性能优化要点</h4>
<ul>
<li>
<strong>减少重绘</strong>
只重绘变化的部分脏矩形技术避免不必要的 clearRect
</li>
<li>
<strong>离屏 Canvas</strong>
预渲染静态内容到离屏 Canvas减少每帧的绘制操作
</li>
<li>
<strong>批量渲染</strong>
减少状态切换fillStylestrokeStyle 批量处理相同类型的绘制
</li>
<li>
<strong>对象池</strong>
复用对象减少垃圾回收压力
</li>
<li>
<strong>requestAnimationFrame</strong>
使用浏览器提供的动画 API优化渲染时机
</li>
</ul>
</div>
</div>
</template>
@@ -755,11 +728,12 @@ onUnmounted(() => {
display: flex;
justify-content: center;
margin: 1.5rem 0;
padding: 1.5rem;
padding: 1rem;
background: var(--vp-c-bg);
border-radius: 12px;
border: 2px solid var(--vp-c-divider);
box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
overflow-x: auto;
}
canvas {
@@ -767,6 +741,7 @@ canvas {
border-radius: 6px;
background: #ffffff;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
flex-shrink: 0;
}
.comparison {
@@ -812,57 +787,4 @@ canvas {
color: var(--vp-c-text-2);
}
.code-display {
margin-top: 1.5rem;
padding: 1.25rem;
background: #1e293b;
border-radius: 12px;
overflow-x: auto;
border: 2px solid #334155;
}
.code-display h4 {
color: #f8fafc;
margin: 0 0 0.75rem 0;
font-size: 0.875rem;
font-weight: 600;
}
.code-display pre {
margin: 0;
}
.code-display code {
color: #e2e8f0;
font-family: var(--vp-font-family-mono);
font-size: 0.75rem;
line-height: 1.7;
}
.explanation {
margin: 1.5rem 0;
padding: 1.25rem;
background: var(--vp-c-bg);
border-radius: 6px;
border: 1px solid var(--vp-c-divider);
}
.explanation h4 {
margin: 0 0 0.75rem 0;
color: var(--vp-c-text-1);
font-size: 0.875rem;
font-weight: 600;
}
.explanation ul {
margin: 0;
padding-left: 1.25rem;
}
.explanation li {
margin-bottom: 0.5rem;
color: var(--vp-c-text-2);
font-size: 0.875rem;
line-height: 1.6;
}
</style>