Files

387 lines
34 KiB
React
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 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<d<d_f"}, {"id": 28, "layer": "L1", "topic": "contact", "starred": false, "q": "直齿轮端面重合度如何定义?", "a": "\\varepsilon_\\alpha=\\frac{\\text{实际啮合线长度}}{p_b}"}, {"id": 29, "layer": "L3", "topic": "contact", "starred": false, "q": "理想直齿轮连续传动的重合度条件是什么?", "a": "\\varepsilon_\\alpha\\geq1"}, {"id": 30, "layer": "L2", "topic": "contact", "starred": false, "q": "工程上为什么不能只让重合度恰好等于 1?", "a": "制造误差和变形可能使实际接触中断,因此需要留出重合度裕量。"}, {"id": 31, "layer": "L2", "topic": "contact", "starred": false, "q": "重合度在 1 与 2 之间时,一次啮合中承载齿对数如何变化?", "a": "单对齿承载与双对齿承载交替出现。"}, {"id": 32, "layer": "L3", "topic": "contact", "starred": false, "q": "齿数、压力角和齿高系数不变,只同比放大模数,会改变重合度吗?", "a": "不会;啮合线长度与基圆齿距按同一比例放大。"}, {"id": 33, "layer": "L1", "topic": "contact", "starred": false, "q": "齿面接触到哪个位置时相对滑动速度为零?", "a": "节点处;该处两齿面瞬时作纯滚动。"}, {"id": 34, "layer": "L1", "topic": "shift", "starred": false, "q": "范成法加工的基本原理是什么?", "a": "利用刀具与齿坯的相对啮合运动,由刀刃位置的包络形成齿廓。"}, {"id": 35, "layer": "L1", "topic": "shift", "starred": false, "q": "什么是根切?", "a": "范成加工时,刀具切去了齿根附近本应保留的一部分渐开线齿廓。"}, {"id": 36, "layer": "L2", "topic": "shift", "starred": false, "q": "根切为什么降低齿根弯曲强度?", "a": "齿根有效厚度减小,应力集中加重。"}, {"id": 37, "layer": "L1", "topic": "shift", "starred": false, "q": "标准齿条刀具加工外齿轮时,不根切最少齿数的理论表达式是什么?", "a": "z_{\\min}=\\frac{2h_a^*}{\\sin^2\\alpha}"}, {"id": 38, "layer": "L3", "topic": "shift", "starred": false, "q": "20°、正常齿制下,“最少齿数 17”应该怎样记?", "a": "课程常用近似结论为约 17;理论表达式约为 17.1,严格边界须按题目采用的约定判断。"}, {"id": 39, "layer": "L1", "topic": "shift", "starred": false, "q": "正变位时,齿条刀具向什么方向移动?", "a": "相对于标准位置,远离齿轮中心。"}, {"id": 40, "layer": "L3", "topic": "shift", "starred": false, "q": "模数、齿数、压力角不变,变位会改变分度圆和基圆吗?", "a": "不会;改变的是齿厚、齿高及齿廓所取的工作段等。"}, {"id": 41, "layer": "L1", "topic": "shift", "starred": false, "q": "外齿直齿轮变位后的分度圆齿厚公式是什么?", "a": "s=\\frac{\\pi m}{2}+2xm\\tan\\alpha"}, {"id": 42, "layer": "L2", "topic": "shift", "starred": false, "q": "正变位为什么有利于小齿数齿轮避免根切?", "a": "刀具远离轮心,减少对齿根渐开线的切除。"}, {"id": 43, "layer": "L3", "topic": "shift", "starred": false, "q": "正变位系数是否越大越好?", "a": "不是;齿顶会变薄,还要检查齿顶厚度和啮合性能。"}, {"id": 44, "layer": "L1", "topic": "shift", "starred": false, "q": "无侧隙外啮合变位直齿轮副中,啮合角如何与变位系数联系?", "a": "\\operatorname{inv}\\alpha^{\\prime}=\\operatorname{inv}\\alpha+\\frac{2(x_1+x_2)\\tan\\alpha}{z_1+z_2}"}, {"id": 45, "layer": "L3", "topic": "shift", "starred": false, "q": "零变位传动是否要求两个齿轮的变位系数都为零?", "a": "不要求;总变位系数为零即可,也可以一个正变位、一个负变位。"}, {"id": 46, "layer": "L1", "topic": "shift", "starred": false, "q": "中心距变动系数 y 的定义是什么?", "a": "y=\\frac{a^{\\prime}-a}{m}"}, {"id": 47, "layer": "L3", "topic": "shift", "starred": false, "q": "无侧隙外啮合条件下,总变位系数为正意味着中心距如何变化?", "a": "实际中心距大于对应的标准中心距。"}, {"id": 48, "layer": "L1", "topic": "helical", "starred": false, "q": "斜齿轮通常以哪个截面的模数和压力角作为标准参数?", "a": "法面。"}, {"id": 49, "layer": "L1", "topic": "helical", "starred": false, "q": "斜齿轮法面模数与端面模数的关系是什么?", "a": "m_n=m_t\\cos\\beta"}, {"id": 50, "layer": "L1", "topic": "helical", "starred": false, "q": "斜齿轮法面压力角与端面压力角的关系是什么?", "a": "\\tan\\alpha_n=\\tan\\alpha_t\\cos\\beta"}, {"id": 51, "layer": "L1", "topic": "helical", "starred": false, "q": "斜齿轮分度圆直径如何用法面模数计算?", "a": "d=\\frac{m_nz}{\\cos\\beta}"}, {"id": 52, "layer": "L3", "topic": "helical", "starred": false, "q": "平行轴外啮合斜齿轮的螺旋方向应怎样配合?", "a": "螺旋角绝对值相等,旋向相反;还须法面模数和法面压力角分别相等。"}, {"id": 53, "layer": "L1", "topic": "helical", "starred": false, "q": "斜齿轮当量齿数如何计算?", "a": "z_v=\\frac{z}{\\cos^3\\beta}"}, {"id": 54, "layer": "L1", "topic": "helical", "starred": false, "q": "斜齿轮总重合度由哪两部分组成?", "a": "\\varepsilon_\\gamma=\\varepsilon_\\alpha+\\varepsilon_\\beta"}, {"id": 55, "layer": "L1", "topic": "helical", "starred": false, "q": "斜齿轮轴向重合度如何计算?", "a": "\\varepsilon_\\beta=\\frac{b\\sin\\beta}{\\pi m_n}"}, {"id": 56, "layer": "L2", "topic": "helical", "starred": false, "q": "斜齿轮为什么通常比直齿轮运转平稳?", "a": "轮齿逐渐进入和退出啮合,并可借助轴向重合提高同时承载程度。"}, {"id": 57, "layer": "L3", "topic": "helical", "starred": false, "q": "增大螺旋角有什么必须权衡的受力代价?", "a": "轴向力增大,轴承与轴向定位负担加重。"}, {"id": 58, "layer": "L3", "topic": "helical", "starred": false, "q": "人字齿的轴向力在什么条件下可以相互抵消?", "a": "左右旋部分对称并理想均匀承载时。"}, {"id": 59, "layer": "L1", "topic": "spatial", "starred": false, "q": "蜗杆传动比如何由头数和齿数计算?", "a": "i=\\frac{z_2}{z_1}\\quad(z_1\\text{ 为蜗杆头数})"}, {"id": 60, "layer": "L3", "topic": "spatial", "starred": false, "q": "蜗杆传动比可以直接用蜗轮与蜗杆的分度圆直径之比计算吗?", "a": "不能;应使用蜗轮齿数与蜗杆头数之比。"}, {"id": 61, "layer": "L1", "topic": "spatial", "starred": false, "q": "圆柱蜗杆分度圆直径与直径系数的关系是什么?", "a": "d_1=mq"}, {"id": 62, "layer": "L1", "topic": "spatial", "starred": false, "q": "圆柱蜗杆导程角如何用头数和直径系数表示?", "a": "\\tan\\gamma=\\frac{z_1}{q}"}, {"id": 63, "layer": "L3", "topic": "spatial", "starred": false, "q": "单头蜗杆是否必然自锁?", "a": "不必然;还取决于导程角与当量摩擦角等条件。"}, {"id": 64, "layer": "L1", "topic": "spatial", "starred": false, "q": "轴交角为 90° 的锥齿轮副,两分锥角有什么关系?", "a": "\\delta_1+\\delta_2=90^\\circ"}, {"id": 65, "layer": "L1", "topic": "spatial", "starred": false, "q": "轴交角为 90° 的锥齿轮副,小轮分锥角如何由齿数求得?", "a": "\\tan\\delta_1=\\frac{z_1}{z_2}"}, {"id": 66, "layer": "L1", "topic": "spatial", "starred": false, "q": "直齿锥齿轮的当量齿数如何计算?", "a": "z_v=\\frac{z}{\\cos\\delta}"}, {"id": 67, "layer": "L3", "topic": "spatial", "starred": false, "q": "锥齿轮的标准模数通常在哪一端定义?", "a": "大端;受力及强度计算常使用齿宽中点处的尺寸。"}, {"id": 68, "layer": "L1", "topic": "failure", "starred": false, "q": "齿根折断主要对应哪类应力?", "a": "齿根弯曲应力;反复作用可导致弯曲疲劳折断。"}, {"id": 69, "layer": "L1", "topic": "failure", "starred": false, "q": "齿面点蚀主要对应哪类应力?", "a": "齿面反复接触应力引起的接触疲劳。"}, {"id": 70, "layer": "L1", "topic": "failure", "starred": false, "q": "齿面胶合的直接机理是什么?", "a": "润滑膜失效后,局部金属黏着并在相对滑动中被撕裂。"}, {"id": 71, "layer": "L1", "topic": "failure", "starred": false, "q": "开式齿轮为什么更容易出现磨粒磨损?", "a": "齿面易受外界硬质颗粒污染,润滑条件也较差。"}, {"id": 72, "layer": "L1", "topic": "failure", "starred": false, "q": "闭式软齿面齿轮的常用设计顺序是什么?", "a": "按齿面接触疲劳强度设计,再校核齿根弯曲疲劳强度。"}, {"id": 73, "layer": "L1", "topic": "failure", "starred": false, "q": "闭式硬齿面齿轮的常用设计顺序是什么?", "a": "按齿根弯曲疲劳强度设计,再校核齿面接触疲劳强度。"}, {"id": 74, "layer": "L3", "topic": "failure", "starred": false, "q": "按一种疲劳强度设计通过,是否可以省略另一种强度校核?", "a": "不能;两类失效的控制因素不同。"}, {"id": 75, "layer": "L2", "topic": "failure", "starred": false, "q": "齿轮材料为什么常要求齿面硬而心部韧?", "a": "硬齿面提高抗接触疲劳和耐磨能力,韧性心部有助于承受冲击与弯曲载荷。"}, {"id": 76, "layer": "L1", "topic": "force", "starred": false, "q": "已知功率 P(kW)和转速 n(r/min),转矩 T(N·mm)如何计算?", "a": "T=9.55\\times10^6\\frac{P}{n}"}, {"id": 77, "layer": "L1", "topic": "force", "starred": false, "q": "圆柱齿轮圆周力如何由转矩求得?(T 用 N·mm,d 用 mm)", "a": "F_t=\\frac{2T}{d}"}, {"id": 78, "layer": "L1", "topic": "force", "starred": false, "q": "直齿圆柱齿轮径向力如何计算?", "a": "F_r=F_t\\tan\\alpha"}, {"id": 79, "layer": "L3", "topic": "force", "starred": false, "q": "理想直齿圆柱齿轮啮合力有轴向分量吗?", "a": "没有;理想轴向力为零。"}, {"id": 80, "layer": "L1", "topic": "force", "starred": false, "q": "斜齿圆柱齿轮轴向力的大小如何计算?", "a": "F_a=F_t\\tan\\beta"}, {"id": 81, "layer": "L1", "topic": "force", "starred": false, "q": "斜齿圆柱齿轮径向力如何用法面压力角计算?", "a": "F_r=F_t\\frac{\\tan\\alpha_n}{\\cos\\beta}"}, {"id": 82, "layer": "L2", "topic": "force", "starred": false, "q": "主动轮所受圆周力与啮合点圆周速度方向有什么关系?", "a": "方向相反;该力形成阻碍主动轮运动的转矩。"}, {"id": 83, "layer": "L1", "topic": "force", "starred": false, "q": "使用系数 KA 主要考虑什么?", "a": "原动机和工作机等外部因素引起的载荷变化与冲击。"}, {"id": 84, "layer": "L1", "topic": "force", "starred": false, "q": "动载系数 KV 主要考虑什么?", "a": "齿轮啮合误差和弹性变形等引起的内部附加动载荷。"}, {"id": 85, "layer": "L1", "topic": "force", "starred": false, "q": "齿向载荷分布系数 Kβ 主要考虑什么?", "a": "载荷沿齿宽方向分布不均。"}, {"id": 86, "layer": "L1", "topic": "force", "starred": false, "q": "齿间载荷分配系数 Kα 主要考虑什么?", "a": "同时啮合的各齿对之间载荷分配不均。"}, {"id": 87, "layer": "L3", "topic": "force", "starred": false, "q": "齿向系数与齿间系数能否互换?", "a": "不能;一个针对沿齿宽的分布,一个针对多齿对之间的分配。"}, {"id": 88, "layer": "L1", "topic": "strength", "starred": false, "q": "接触疲劳强度的校核判据是什么?", "a": "\\sigma_H\\leq[\\sigma_H]"}, {"id": 89, "layer": "L1", "topic": "strength", "starred": false, "q": "齿根弯曲疲劳强度的校核判据是什么?", "a": "\\sigma_F\\leq[\\sigma_F]"}, {"id": 90, "layer": "L1", "topic": "strength", "starred": false, "q": "许用接触应力如何由接触疲劳极限求得?", "a": "[\\sigma_H]=\\frac{\\sigma_{H\\lim}Z_N}{S_H}"}, {"id": 91, "layer": "L1", "topic": "strength", "starred": false, "q": "许用弯曲应力如何计入寿命与尺寸影响?", "a": "[\\sigma_F]=\\frac{\\sigma_{F\\lim}Y_NY_X}{S_F}"}, {"id": 92, "layer": "L1", "topic": "strength", "starred": false, "q": "转速 n(r/min)、寿命 h(小时)、每转应力循环次数 γ 对应多少次循环?", "a": "N=60\\gamma nh"}, {"id": 93, "layer": "L1", "topic": "strength", "starred": false, "q": "接触强度计算的总载荷系数如何组合?", "a": "K_H=K_AK_VK_{H\\beta}K_{H\\alpha}"}, {"id": 94, "layer": "L1", "topic": "strength", "starred": false, "q": "直齿圆柱齿轮弯曲应力的常用计算式是什么?", "a": "\\sigma_F=\\frac{2K_FT}{bd_1m}Y_{Fa}Y_{Sa}Y_\\varepsilon"}, {"id": 95, "layer": "L2", "topic": "strength", "starred": false, "q": "弯曲设计中,怎样判断一对齿轮中哪一个更危险?", "a": "比较各自的齿形系数与应力修正系数乘积除以许用弯曲应力的比值,比值较大者控制设计。"}, {"id": 96, "layer": "L1", "topic": "strength", "starred": false, "q": "齿宽系数 ψd 如何定义?", "a": "\\psi_d=\\frac{b}{d_1}"}, {"id": 97, "layer": "L3", "topic": "strength", "starred": false, "q": "一对齿轮宽度不同时,强度式中的有效啮合齿宽通常取哪个?", "a": "取两者中较小的有效齿宽。"}, {"id": 98, "layer": "L2", "topic": "strength", "starred": false, "q": "为什么接触强度设计常主要确定小齿轮直径?", "a": "齿面曲率与接触载荷受整体尺寸控制,接触强度对分度圆直径十分敏感。"}, {"id": 99, "layer": "L3", "topic": "strength", "starred": false, "q": "“接触强度与模数无关”能脱离条件直接使用吗?", "a": "不能;固定分度圆直径时才可讨论模数与齿数的配合,固定齿数而增大模数会改变直径。"}, {"id": 100, "layer": "L3", "topic": "strength", "starred": false, "q": "计算出的模数能否任意取一个非标准小数?", "a": "通常应向上选取合适的标准模数,并按最终几何参数复核。"}, {"id": 101, "layer": "L3", "topic": "strength", "starred": false, "q": "疲劳强度通过,是否代表瞬时过载一定安全?", "a": "不能;显著过载时还应按最大载荷进行静强度校核。"}, {"id": 102, "layer": "L3", "topic": "strength", "starred": false, "q": "斜齿轮强度计算能否只把直齿公式中的 m 换成法面模数?", "a": "不能;还涉及螺旋角、当量齿数、重合度及相应修正系数。"}];
// ============================================================
// KaTeX CSS from CDN
const katexCSS = `@import url('https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css');`;
/**
* MathRenderer Component
*
* Renders content with LaTeX math using client-side KaTeX.
* Detects math patterns and renders them, passing through plain text.
*
* Supports:
* - Standalone LaTeX (entire string is a formula)
* - Inline math with $ delimiters
* - Mixed text and math
*/
const MathRenderer = ({ content }) => {
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 <div className="text-gray-700">{content}</div>;
}
return <div ref={containerRef} className="text-gray-700 overflow-x-auto" />;
};
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 (
<>
<style>{katexCSS}</style>
<div className="min-h-screen bg-gray-50 p-4">
<div className="max-w-4xl mx-auto">
<h1 className="text-2xl font-bold text-center mb-2 text-gray-800">{TITLE}</h1>
<p className="text-center text-gray-600 mb-4 text-sm">{flashcards.length} cards across 3 layers covering {topics.length - 1} topics</p>
{/* Controls */}
<div className="bg-white rounded-lg shadow p-4 mb-4">
<div className="grid grid-cols-2 md:grid-cols-5 gap-3">
<div>
<label className="block text-xs font-medium text-gray-600 mb-1">Layer</label>
<select
value={currentLayer}
onChange={(e) => { setCurrentLayer(e.target.value); resetDeck(); }}
className="w-full p-2 border rounded text-sm"
>
{layers.map(l => (
<option key={l} value={l}>{l === 'all' ? 'All Layers' : `${l}: ${layerNames[l]}`}</option>
))}
</select>
</div>
<div>
<label className="block text-xs font-medium text-gray-600 mb-1">Topic</label>
<select
value={currentTopic}
onChange={(e) => { setCurrentTopic(e.target.value); resetDeck(); }}
className="w-full p-2 border rounded text-sm"
>
<option value="all">All Topics</option>
{topics.filter(t => t !== 'all').map(t => (
<option key={t} value={t}>{topicNames[t] || t} ({topicCounts[t]})</option>
))}
</select>
</div>
<div className="flex items-end">
<button
onClick={() => { setShowStarred(!showStarred); resetDeck(); }}
className={`w-full p-2 rounded text-sm font-medium ${showStarred ? 'bg-yellow-400 text-yellow-900' : 'bg-gray-200 text-gray-700'}`}
>
{showStarred ? `★ Starred (${starredIds.length})` : '☆ Show Starred'}
</button>
</div>
<div className="flex items-end">
<button
onClick={() => { setShuffled(!shuffled); resetDeck(); }}
className={`w-full p-2 rounded text-sm font-medium ${shuffled ? 'bg-purple-500 text-white' : 'bg-gray-200 text-gray-700'}`}
>
{shuffled ? '🔀 Shuffled' : '📋 Ordered'}
</button>
</div>
<div className="flex items-end">
<button
onClick={resetDeck}
className="w-full p-2 bg-gray-200 rounded text-sm font-medium text-gray-700 hover:bg-gray-300"
>
🔄 Reset
</button>
</div>
</div>
</div>
{/* Stats */}
<div className="flex justify-between items-center mb-3 px-2">
<span className="text-sm text-gray-600">
Card {filteredCards.length > 0 ? currentIndex + 1 : 0} of {filteredCards.length}
</span>
<div className="flex gap-2">
<span className="text-xs px-2 py-1 bg-blue-100 text-blue-700 rounded">L1: {flashcards.filter(c => c.layer === 'L1').length}</span>
<span className="text-xs px-2 py-1 bg-green-100 text-green-700 rounded">L2: {flashcards.filter(c => c.layer === 'L2').length}</span>
<span className="text-xs px-2 py-1 bg-red-100 text-red-700 rounded">L3: {flashcards.filter(c => c.layer === 'L3').length}</span>
</div>
</div>
{/* Flashcard */}
{currentCard ? (
<div
className={`rounded-xl shadow-lg p-6 min-h-64 cursor-pointer border-l-4 ${layerColors[currentCard.layer]} bg-white`}
onClick={() => setShowAnswer(!showAnswer)}
>
<div className="flex justify-between items-start mb-4">
<span className={`text-xs font-bold px-2 py-1 rounded ${
currentCard.layer === 'L1' ? 'bg-blue-200 text-blue-800' :
currentCard.layer === 'L2' ? 'bg-green-200 text-green-800' :
'bg-red-200 text-red-800'
}`}>
{currentCard.layer}: {layerNames[currentCard.layer]}
</span>
<div className="flex items-center gap-2">
<span className="text-xs font-medium px-2 py-1 bg-gray-200 text-gray-700 rounded">
{topicNames[currentCard.topic] || currentCard.topic}
</span>
<button
onClick={(e) => toggleStar(currentCard.id, e)}
className={`text-xl transition-colors ${starredIds.includes(currentCard.id) ? 'text-yellow-400' : 'text-gray-300 hover:text-yellow-300'}`}
>
{starredIds.includes(currentCard.id) ? '★' : '☆'}
</button>
</div>
</div>
<div className="mt-4">
<p className="text-lg font-semibold text-gray-800 mb-4">{currentCard.q}</p>
{showAnswer ? (
<div className="mt-4 p-4 bg-gray-50 rounded-lg border">
<MathRenderer content={currentCard.a} />
</div>
) : (
<p className="text-gray-400 text-sm italic mt-8">Click to reveal answer...</p>
)}
</div>
</div>
) : (
<div className="bg-white rounded-xl shadow-lg p-8 text-center">
<p className="text-gray-500">No cards match current filters</p>
</div>
)}
{/* Navigation */}
<div className="flex justify-between mt-4">
<button
onClick={prevCard}
disabled={filteredCards.length === 0}
className="px-6 py-2 bg-gray-200 rounded-lg font-medium text-gray-700 hover:bg-gray-300 disabled:opacity-50"
>
← Previous
</button>
<button
onClick={() => setShowAnswer(!showAnswer)}
className="px-6 py-2 bg-indigo-500 text-white rounded-lg font-medium hover:bg-indigo-600"
>
{showAnswer ? 'Hide' : 'Show'} Answer
</button>
<button
onClick={nextCard}
disabled={filteredCards.length === 0}
className="px-6 py-2 bg-gray-200 rounded-lg font-medium text-gray-700 hover:bg-gray-300 disabled:opacity-50"
>
Next →
</button>
</div>
{/* Layer Guide */}
<div className="mt-6 bg-white rounded-lg shadow p-4">
<h3 className="font-bold text-sm text-gray-700 mb-2">Three-Layer System</h3>
<div className="grid grid-cols-3 gap-2 text-xs">
<div className="p-2 bg-blue-50 rounded border-l-2 border-blue-400">
<strong className="text-blue-700">L1: Recall</strong>
<p className="text-gray-600 mt-1">Facts, definitions, formulas</p>
</div>
<div className="p-2 bg-green-50 rounded border-l-2 border-green-400">
<strong className="text-green-700">L2: Understanding</strong>
<p className="text-gray-600 mt-1">Why and how things work</p>
</div>
<div className="p-2 bg-red-50 rounded border-l-2 border-red-400">
<strong className="text-red-700">L3: Boundaries</strong>
<p className="text-gray-600 mt-1">Limitations and edge cases</p>
</div>
</div>
</div>
{/* Topic Coverage Grid */}
<div className="mt-4 bg-white rounded-lg shadow p-4">
<h3 className="font-bold text-sm text-gray-700 mb-2">Topic Coverage ({flashcards.length} total cards)</h3>
<div className="grid grid-cols-4 md:grid-cols-5 gap-2">
{/* Starred tile */}
<div
className={`text-xs p-2 rounded cursor-pointer ${showStarred ? 'bg-yellow-100 border border-yellow-400' : 'bg-yellow-50 hover:bg-yellow-100'}`}
onClick={() => { setShowStarred(true); setCurrentTopic('all'); resetDeck(); }}
>
<div className="font-medium">★ Starred</div>
<div className="text-yellow-700">{starredIds.length} cards</div>
</div>
{/* Topic tiles */}
{topics.filter(t => t !== 'all').map(topic => (
<div
key={topic}
className={`text-xs p-2 rounded cursor-pointer ${currentTopic === topic && !showStarred ? 'bg-indigo-100 border border-indigo-300' : 'bg-gray-100 hover:bg-gray-200'}`}
onClick={() => { setShowStarred(false); setCurrentTopic(topic); resetDeck(); }}
>
<div className="font-medium truncate">{topicNames[topic] || topic}</div>
<div className="text-gray-500">{topicCounts[topic]} cards</div>
</div>
))}
</div>
</div>
</div>
</div>
</>
);
};
export default AtomicFlashcards;