---
name: theme_switcher_build.aicomponent
description: 主题切换构建辅助 skill。提供 src/theme/index.ts 入口文件模板，构建时由 builds.config.js 自动替换为当前激活的主题变体导入。
triggers: 需要配置多主题构建的主题入口文件时触发。
---

# 主题切换构建器（Theme Switcher Build Helper）

## 说明

`src/theme/index.ts` 是主题系统的统一入口：

- 运行时和其他模块通过 `import Theme from 'src/theme'` 获取当前主题配置
- **构建时**由 `builds.config.js` 脚本自动修改此文件，切换到对应主题的导入路径
- 每个主题目录放在 `src/theme/<主题名>/` 下（见 `theme_variant.aiconfig` skill）

## Scaffold

| 目标路径 | 来源 | 说明 |
|---------|-----|-----|
| `src/theme/index.ts` | `ref/theme-index.ts` | 主题入口文件（默认导入开发主题） |

## Recipe

| 决策 | 原因 |
|------|------|
| **构建时替换而非运行时切换** | 运行时 if/else 主题切换会把所有主题变体打包进产物，增大体积；构建时替换 import 路径使每个主题产物只包含自身变体 |
| **单入口文件作为换点** | `src/theme/index.ts` 是唯一需要修改的文件；构建脚本只改一行 import，不触碰其他业务代码 |
| **开发时默认 Dev 主题** | `import Theme from "./Dev"` 是开发时默认；构建脚本在 CI 中替换为对应变体，开发者本地无需操作 |

## Adapter

- **Role**: `themeSwitcherBuild` — 多主题构建入口文件（构建时脚本动态替换导入路径）
- **Provides**: `src/theme/index.ts` 主题入口模板（`export default Theme`）
- **Requires**: `playable_scripts_build.aicomponent`（builds.config.js 在构建时修改此文件）
- **Consumed by**: 所有运行时读取主题配置的组件（`theme_state.aicomponent`、`level_state.aicomponent` 等通过 `import Theme from 'src/theme'` 使用）
- **Integration point**: `src/theme/index.ts` —— 构建时被 `builds.config.js` 将 `./Dev` 替换为对应变体路径

## Imports

- `playable_scripts_build.aicomponent`（硬依赖：builds.config.js 自动修改此文件）

## Skill Definition

```yaml
tools:
  - read_file
  - write_file
inputs:
  - source: src/theme/index.ts
outputs:
  - themeIndex: src/theme/index.ts theme entry file
```

## 文件内容

```typescript
// src/theme/index.ts
// 注意: 构建时由 builds 脚本自动修改，不要手动改
import Theme from "./Dev";
export default Theme;
```
