/** * STEM Flashcard Template * * Features: * - Client-side KaTeX rendering (token-efficient: raw LaTeX input) * - Three-layer cognitive framework (L1/L2/L3) * - Starred cards functionality * - Topic and layer filtering * - Shuffle mode * * Usage: * 1. Replace the `flashcards` array with generated content * 2. Update TITLE constant * 3. Update topicNames mapping * 4. Each card needs: id, layer, topic, starred, q (question), a (raw LaTeX or plain text) */ import React, { useState, useEffect, useMemo, useRef } from 'react'; // ============================================================ // CONFIGURATION - UPDATE THESE // ============================================================ const TITLE = '齿轮章节 · 三层闪卡'; const topicNames = {"law": "啮合原理与渐开线", "geometry": "直齿轮几何与啮合", "contact": "重合度与相对滑动", "shift": "加工、根切与变位", "helical": "斜齿圆柱齿轮", "spatial": "蜗杆与锥齿轮基础", "failure": "失效与设计准则", "force": "受力与载荷系数", "strength": "疲劳强度与计算判断"}; // ============================================================ // REPLACE THIS ARRAY WITH GENERATED FLASHCARDS // ============================================================ const flashcards = [{"id": 1, "layer": "L1", "topic": "law", "starred": false, "q": "什么叫共轭齿廓?", "a": "能够实现预定传动比规律的一对相互啮合齿廓。"}, {"id": 2, "layer": "L1", "topic": "law", "starred": false, "q": "齿廓啮合基本定律怎样表示传动比大小?", "a": "i_{12}=\\left|\\frac{\\omega_1}{\\omega_2}\\right|=\\frac{O_2P}{O_1P}"}, {"id": 3, "layer": "L2", "topic": "law", "starred": false, "q": "为什么公法线与连心线交于固定点就能保证定传动比?", "a": "交点固定,两段连心线长度之比就固定,因而瞬时传动比固定。"}, {"id": 4, "layer": "L1", "topic": "law", "starred": false, "q": "渐开线怎样形成?", "a": "发生线沿基圆作纯滚动时,发生线上一点的轨迹。"}, {"id": 5, "layer": "L1", "topic": "law", "starred": false, "q": "渐开线上一点的法线与基圆有什么关系?", "a": "该点法线与基圆相切。"}, {"id": 6, "layer": "L1", "topic": "law", "starred": false, "q": "渐开线上任意点 K 的压力角如何计算?", "a": "\\cos\\alpha_K=\\frac{r_b}{r_K}"}, {"id": 7, "layer": "L2", "topic": "law", "starred": false, "q": "为什么渐开线上越靠外的点压力角越大?", "a": "基圆半径不变,点所在圆的半径越大,压力角的余弦越小。"}, {"id": 8, "layer": "L3", "topic": "law", "starred": false, "q": "基圆以内是否存在渐开线齿廓?", "a": "不存在渐开线;齿根处可能由其他过渡曲线连接。"}, {"id": 9, "layer": "L1", "topic": "law", "starred": false, "q": "渐开线函数 inv α 的表达式是什么?", "a": "\\operatorname{inv}\\alpha=\\tan\\alpha-\\alpha\\quad(\\alpha\\text{ 用弧度})"}, {"id": 10, "layer": "L2", "topic": "law", "starred": false, "q": "渐开线齿轮为什么具有中心距可分性?", "a": "两基圆不变时,传动比由基圆半径之比决定;中心距小幅改变不改变这一比值。"}, {"id": 11, "layer": "L3", "topic": "law", "starred": false, "q": "中心距可分性是否意味着中心距可以任意增大?", "a": "不能;仍须满足实际啮合、重合度和齿顶等几何限制。"}, {"id": 12, "layer": "L1", "topic": "geometry", "starred": false, "q": "模数与分度圆齿距的关系是什么?", "a": "m=\\frac{p}{\\pi}"}, {"id": 13, "layer": "L1", "topic": "geometry", "starred": false, "q": "直齿圆柱齿轮的分度圆直径如何计算?", "a": "d=mz"}, {"id": 14, "layer": "L1", "topic": "geometry", "starred": false, "q": "标准正常齿制的压力角通常取多少?", "a": "20°。"}, {"id": 15, "layer": "L1", "topic": "geometry", "starred": false, "q": "标准正常齿制的齿顶高系数与顶隙系数分别是多少?", "a": "h_a^*=1,\\qquad c^*=0.25"}, {"id": 16, "layer": "L1", "topic": "geometry", "starred": false, "q": "标准外齿直齿轮的齿顶圆直径如何计算?", "a": "d_a=m(z+2h_a^*)"}, {"id": 17, "layer": "L1", "topic": "geometry", "starred": false, "q": "标准外齿直齿轮的齿根圆直径如何计算?", "a": "d_f=m[z-2(h_a^*+c^*)]"}, {"id": 18, "layer": "L1", "topic": "geometry", "starred": false, "q": "基圆直径如何由分度圆参数计算?", "a": "d_b=d\\cos\\alpha"}, {"id": 19, "layer": "L1", "topic": "geometry", "starred": false, "q": "直齿轮的基圆齿距如何计算?", "a": "p_b=\\pi m\\cos\\alpha"}, {"id": 20, "layer": "L1", "topic": "geometry", "starred": false, "q": "无侧隙标准齿轮分度圆齿厚是多少?", "a": "s=\\frac{\\pi m}{2}"}, {"id": 21, "layer": "L1", "topic": "geometry", "starred": false, "q": "标准外啮合直齿轮副的中心距如何计算?", "a": "a=\\frac{m(z_1+z_2)}{2}"}, {"id": 22, "layer": "L1", "topic": "geometry", "starred": false, "q": "一对渐开线直齿轮的正确啮合条件是什么?", "a": "m_1=m_2,\\qquad\\alpha_1=\\alpha_2"}, {"id": 23, "layer": "L2", "topic": "geometry", "starred": false, "q": "分度圆与节圆的主要区别是什么?", "a": "分度圆由单个齿轮的基本参数确定;节圆由两个齿轮的实际啮合关系确定。"}, {"id": 24, "layer": "L3", "topic": "geometry", "starred": false, "q": "分度圆与节圆是否总重合?", "a": "不总重合;标准安装的标准齿轮副中才有这种特定关系。"}, {"id": 25, "layer": "L1", "topic": "geometry", "starred": false, "q": "外啮合齿轮中心距与啮合角满足什么关系?", "a": "a\\cos\\alpha=a^{\\prime}\\cos\\alpha^{\\prime}"}, {"id": 26, "layer": "L2", "topic": "geometry", "starred": false, "q": "基圆不变时,实际中心距增大,啮合角怎样变化?", "a": "啮合角增大。"}, {"id": 27, "layer": "L1", "topic": "geometry", "starred": false, "q": "内齿轮的齿顶圆、分度圆、齿根圆直径怎样排序?", "a": "d_a { const containerRef = useRef(null); const [katexLoaded, setKatexLoaded] = useState(false); // Load KaTeX library dynamically useEffect(() => { if (window.katex) { setKatexLoaded(true); return; } const script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js'; script.onload = () => setKatexLoaded(true); script.onerror = () => console.error('Failed to load KaTeX'); document.head.appendChild(script); }, []); // Render math when KaTeX is loaded useEffect(() => { if (!katexLoaded || !containerRef.current || !content) return; const container = containerRef.current; // Check if content looks like pure LaTeX (contains LaTeX commands but no $ delimiters) const isPureLaTeX = /\\[a-zA-Z]+/.test(content) && !content.includes('$'); if (isPureLaTeX) { // Render entire content as display math try { window.katex.render(content, container, { throwOnError: false, displayMode: true }); } catch (e) { container.textContent = content; } return; } // Handle mixed content with $ delimiters for inline math // Split on $...$ patterns const parts = content.split(/(\$[^$]+\$)/g); container.innerHTML = ''; parts.forEach(part => { if (part.startsWith('$') && part.endsWith('$')) { // Inline math const latex = part.slice(1, -1); const span = document.createElement('span'); try { window.katex.render(latex, span, { throwOnError: false, displayMode: false }); } catch (e) { span.textContent = latex; } container.appendChild(span); } else if (part) { // Plain text const textNode = document.createTextNode(part); container.appendChild(textNode); } }); }, [content, katexLoaded]); // Show loading state or plain content while KaTeX loads if (!katexLoaded) { return
{content}
; } return
; }; const AtomicFlashcards = () => { const [currentLayer, setCurrentLayer] = useState('all'); const [currentTopic, setCurrentTopic] = useState('all'); const [showAnswer, setShowAnswer] = useState(false); const [currentIndex, setCurrentIndex] = useState(0); const [shuffled, setShuffled] = useState(false); const [starredIds, setStarredIds] = useState([]); const [showStarred, setShowStarred] = useState(false); const layers = ['all', 'L1', 'L2', 'L3']; const topics = ['all', ...new Set(flashcards.map(c => c.topic))]; const layerNames = { 'L1': 'Recall', 'L2': 'Understanding', 'L3': 'Boundaries' }; const layerColors = { 'L1': 'border-blue-400', 'L2': 'border-green-400', 'L3': 'border-red-400' }; // Load starred cards from pre-baked data on mount // Note: localStorage removed for Claude artifact compatibility useEffect(() => { const preBaked = flashcards.filter(c => c.starred).map(c => c.id); setStarredIds(preBaked); }, []); // Toggle star (session-only, no localStorage) const toggleStar = (id, e) => { e.stopPropagation(); setStarredIds(prev => prev.includes(id) ? prev.filter(x => x !== id) : [...prev, id] ); }; const filteredCards = useMemo(() => { let cards = flashcards; if (showStarred) { cards = cards.filter(c => starredIds.includes(c.id)); } cards = cards.filter(c => (currentLayer === 'all' || c.layer === currentLayer) && (currentTopic === 'all' || c.topic === currentTopic) ); if (shuffled) { cards = [...cards].sort(() => Math.random() - 0.5); } return cards; }, [currentLayer, currentTopic, shuffled, showStarred, starredIds]); const currentCard = filteredCards[currentIndex] || null; const nextCard = () => { setShowAnswer(false); setCurrentIndex((currentIndex + 1) % filteredCards.length); }; const prevCard = () => { setShowAnswer(false); setCurrentIndex((currentIndex - 1 + filteredCards.length) % filteredCards.length); }; const resetDeck = () => { setCurrentIndex(0); setShowAnswer(false); }; const topicCounts = {}; topics.filter(t => t !== 'all').forEach(t => { topicCounts[t] = flashcards.filter(c => c.topic === t).length; }); return ( <>

{TITLE}

{flashcards.length} cards across 3 layers covering {topics.length - 1} topics

{/* Controls */}
{/* Stats */}
Card {filteredCards.length > 0 ? currentIndex + 1 : 0} of {filteredCards.length}
L1: {flashcards.filter(c => c.layer === 'L1').length} L2: {flashcards.filter(c => c.layer === 'L2').length} L3: {flashcards.filter(c => c.layer === 'L3').length}
{/* Flashcard */} {currentCard ? (
setShowAnswer(!showAnswer)} >
{currentCard.layer}: {layerNames[currentCard.layer]}
{topicNames[currentCard.topic] || currentCard.topic}

{currentCard.q}

{showAnswer ? (
) : (

Click to reveal answer...

)}
) : (

No cards match current filters

)} {/* Navigation */}
{/* Layer Guide */}

Three-Layer System

L1: Recall

Facts, definitions, formulas

L2: Understanding

Why and how things work

L3: Boundaries

Limitations and edge cases

{/* Topic Coverage Grid */}

Topic Coverage ({flashcards.length} total cards)

{/* Starred tile */}
{ setShowStarred(true); setCurrentTopic('all'); resetDeck(); }} >
★ Starred
{starredIds.length} cards
{/* Topic tiles */} {topics.filter(t => t !== 'all').map(topic => (
{ setShowStarred(false); setCurrentTopic(topic); resetDeck(); }} >
{topicNames[topic] || topic}
{topicCounts[topic]} cards
))}
); }; export default AtomicFlashcards;