/** * 获取展示区域的 HTML 内容 */ export function getExampleShowcaseContent(): string { return `
`; } /** * 获取展示区域的样式 */ export function getExampleShowcaseStyles(): string { return ` .example-showcase { margin-top: 24px; padding: 0; opacity: 1; transition: opacity 0.3s ease; } .example-showcase.hidden { display: none; } .showcase-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; } .showcase-title { font-size: 14px; font-weight: 600; color: var(--vscode-foreground); } .refresh-button { background: transparent; border: none; color: var(--vscode-foreground); cursor: pointer; padding: 4px; display: flex; align-items: center; justify-content: center; border-radius: 4px; transition: all 0.2s ease; opacity: 0.6; } .refresh-button:hover { opacity: 1; background: var(--vscode-input-background); } .refresh-button svg { transition: transform 0.3s ease; } .refresh-button:active svg { transform: rotate(180deg); } .example-cards { display: flex; flex-direction: row; gap: 12px; margin-bottom: 20px; } .example-card { flex: 1; min-width: 0; background: var(--vscode-input-background); border: 1px solid var(--vscode-input-border); border-radius: 8px; padding: 12px; cursor: pointer; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); display: flex; flex-direction: row; align-items: center; gap: 10px; position: relative; overflow: hidden; } .example-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: linear-gradient(135deg, rgba(79, 172, 254, 0.1) 0%, rgba(0, 242, 254, 0.1) 50%, rgba(168, 85, 247, 0.1) 100%); opacity: 0; transition: opacity 0.3s ease; } .example-card:hover::before { opacity: 1; } .example-card:hover { border-color: var(--vscode-focusBorder); transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); } .example-icon { flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--vscode-foreground); } .example-icon svg { width: 20px; height: 20px; } .example-content { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; position: relative; z-index: 1; } .example-title { font-size: 13px; font-weight: 600; color: var(--vscode-foreground); line-height: 1.4; transition: all 0.3s ease; } .example-card:hover .example-title { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 50%, #a855f7 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; } .example-desc { font-size: 11px; color: var(--vscode-descriptionForeground); line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; } .web-link { display: flex; justify-content: center; padding-top: 20px; border-top: 1px solid var(--vscode-panel-border); margin-top: 8px; } .web-link-button { display: flex; align-items: center; gap: 8px; padding: 10px 20px; background: transparent; border: none; text-decoration: none; font-size: 14px; font-weight: 600; transition: all 0.2s ease; background: linear-gradient(135deg, #4facfe 0%, #00f2fe 50%, #a855f7 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; outline: none; } .web-link-button:focus { outline: none; } .web-link-button:hover { transform: translateY(-1px); opacity: 0.8; } .link-icon { font-size: 16px; } .link-arrow { font-size: 16px; transition: transform 0.2s ease; } .web-link-button:hover .link-arrow { transform: translateX(3px); } `; } /** * 获取展示区域的脚本 */ export function getExampleShowcaseScript(): string { return ` // 所有可用的示例 const allExamples = [ '设计一个算术逻辑单元,完成常见运算', '实现一个优先编码器,多个输入同时有效时,只输出优先级最高的那个编号', '实现一个译码器,把二进制编号转换成 one-hot 输出', '实现一个移位寄存器,完成串行/并行数据移位与装载', '实现一个按键消抖模块,解决机械按键抖动问题', '实现一个跑马灯控制器,控制 LED 形成不同流动效果', '实现一个序列检测器,检测串行输入中是否出现指定比特序列', '实现一个LFSR 伪随机数发生器', '实现一个自动售货机,模拟一个简单售货逻辑', '实现一个交通灯控制器,控制两方向交通灯的切换', '实现一个先进先出的数据缓冲区', '单端口 RAM 读写控制器', '实现一个移位加法乘法器,不用 * 运算符' ]; // 当前显示的示例文本 let exampleTexts = ['生成一个SPI控制器', '生成一个GMII接口的以太网UDP通信模块']; // 存储待发送的示例索引 let pendingExampleIndex = -1; // 节流控制 let refreshing = false; // 刷新示例 function refreshExamples() { if (refreshing) return; refreshing = true; const used = new Set(); const newExamples = []; while (newExamples.length < 2) { const idx = Math.floor(Math.random() * allExamples.length); if (!used.has(idx)) { used.add(idx); newExamples.push(allExamples[idx]); } } exampleTexts = newExamples; updateExampleCards(); setTimeout(() => { refreshing = false; }, 500); } // 更新示例卡片显示 function updateExampleCards() { const container = document.querySelector('.example-cards'); if (!container) return; container.innerHTML = exampleTexts.map((text, i) => \`