| 84 | } |
| 85 | |
| 86 | async function fetchThemes() { |
| 87 | themeListResponse = await fetch(`${DEFAULT_THEME_API}/themes`) |
| 88 | if (!themeListResponse.ok) { |
| 89 | error( |
| 90 | `Failed to fetch themes from ${DEFAULT_THEME_API}/themes (${themeListResponse.status}). The theme server may be temporarily unavailable.` |
| 91 | ) |
| 92 | } |
| 93 | const data = await themeListResponse.json() |
| 94 | if (!Array.isArray(data)) { |
| 95 | error( |
| 96 | `Unexpected response from theme API. Expected an array of themes but received: ${JSON.stringify(data).slice(0, 100)}` |
| 97 | ) |
| 98 | } |
| 99 | themes = data |
| 100 | } |
| 101 | |
| 102 | export async function buildTheme(options: Partial<BuildThemeOptions> = {}) { |
| 103 | if (!themes.length) await fetchThemes() |