const fs = require('fs') const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/' function patch(file, pairs) { const p = base + file let c = fs.readFileSync(p, 'utf8') for (const [from, to] of pairs) { if (!c.includes(from)) { console.log('MISS in', file, '::', from.slice(0, 70).replace(/\n/g, '\\n')) continue } c = c.replace(from, to) } fs.writeFileSync(p, c, 'utf8') } // ---------- 1) 内置配色预设 { const p = base + 'shared/elements.ts' let c = fs.readFileSync(p, 'utf8') c += ` export interface PeriodicPreset { id: string name: string scheme: PeriodicScheme colors: Record } const SOFT_CATEGORY: Record = { alkali: '#ffc9b3', alkaline: '#ffe3a3', transition: '#d9f2e6', postmetal: '#cfe7ff', metalloid: '#e2f0c4', nonmetal: '#d3f0dd', halogen: '#ffe3bd', noble: '#ead9ff', lanthanide: '#ffd6e6', actinide: '#f9d2d2' } export const PERIODIC_PRESETS: PeriodicPreset[] = [ { id: 'spdf', name: '能级块 · 标准', scheme: 'block', colors: { s: '#ffd54a', p: '#6fc8ff', d: '#8ef0b0', f: '#cf9bff' } }, { id: 'spdf-soft', name: '能级块 · 柔和', scheme: 'block', colors: { s: '#ffe9a8', p: '#bfe4ff', d: '#cdf3dd', f: '#e6cbff' } }, { id: 'category', name: '元素分类 · 标准', scheme: 'category', colors: { ...CATEGORY_COLORS } }, { id: 'category-soft', name: '元素分类 · 柔和', scheme: 'category', colors: SOFT_CATEGORY } ] ` fs.writeFileSync(p, c, 'utf8') } // ---------- 2) 详情页:预设按钮 patch('renderer/src/detail/Detail.tsx', [ [ " periodicCellColor,\n type PeriodicStyle\n} from '../../../shared/elements'", " periodicCellColor,\n PERIODIC_PRESETS,\n type PeriodicPreset,\n type PeriodicStyle\n} from '../../../shared/elements'" ], [ " const [periodic, setPeriodic] = useState(DEFAULT_PERIODIC_STYLE)", " const [periodic, setPeriodic] = useState(DEFAULT_PERIODIC_STYLE)\n const [customPresets, setCustomPresets] = useState([])" ], [ ` setPeriodic( ((cat as { periodic?: PeriodicStyle }).periodic ?? DEFAULT_PERIODIC_STYLE) as PeriodicStyle )`, ` const catPeriodic = (cat as { periodic?: PeriodicStyle & { presets?: PeriodicPreset[] } }) .periodic setPeriodic((catPeriodic ?? DEFAULT_PERIODIC_STYLE) as PeriodicStyle) setCustomPresets(catPeriodic?.presets ?? [])` ], // 顶部预设按钮(放在切换化学/普通之后) [ `
`, `
{[...PERIODIC_PRESETS, ...customPresets].map((ps) => ( ))}
` ] ]) console.log('periodic presets patched')