import { mapValues } from 'es-toolkit' import type { Target } from '../build.ts' import type { Palette } from '../roles.ts' // references // - https://opencode.ai/docs/themes (theme selection, global/project files, format) // - https://opencode.ai/v2/theme.json (the live schema for this flat format) // note: opencode accepts the flat V1 theme format: one settings object whose values are {dark, light} // pairs, migrated on load to its nested theme. A single file therefore follows `mode: system`. const colors = ({ ansi, site, syntax, terminal, ui }: Palette): Record => ({ // Core UI. The accent drives active tabs and selections. // Like vscodium's editor, the transcript is white and the input box sits on the sidebar green. primary: site.accent, secondary: site.back_2, accent: ui.mark, error: ui.error, warning: ui.warning, success: ui.added, info: ui.info, text: site.text_1, textMuted: ui.muted, selectedListItemText: ui.onAccent, background: ui.surface, // The transcript scrollbar's thumb is drawn from `border`, its track from a darkened // `backgroundPanel`. Keep the panel green and make the border a readable sage so the thumb // stands out against the track (scrolled vs unscrolled). backgroundPanel: ui.chrome, backgroundElement: ui.chrome, border: site.text_3, // Used as the scrollbar thumb in the diff and side panels, so match the transcript's border. borderActive: site.text_3, borderSubtle: ui.whitespace, // Diffs use the same added/removed hues as the editor; context matches the transcript. diffAdded: ansi.Green, diffRemoved: ansi.Red, diffContext: ui.muted, diffHunkHeader: site.text_3, diffHighlightAdded: ui.diffInserted, diffHighlightRemoved: ui.diffRemoved, diffAddedBg: ui.diffInserted, diffRemovedBg: ui.diffRemoved, diffContextBg: ui.surface, // Text-3, not the editor's line-number color, which falls below 3:1 on the opaque fills. diffLineNumber: site.text_3, diffAddedLineNumberBg: ui.diffInserted, diffRemovedLineNumberBg: ui.diffRemoved, // Markdown: links follow the terminal link color, code follows syntax. markdownText: site.text_1, markdownHeading: ui.mark, markdownLink: terminal.link, markdownLinkText: terminal.link, markdownCode: syntax.string, markdownBlockQuote: site.text_3, markdownEmph: ui.muted, markdownStrong: site.text_1, markdownHorizontalRule: site.back_2, markdownListItem: ui.mark, markdownListEnumeration: ui.mark, markdownImage: terminal.link, markdownImageText: ui.muted, markdownCodeBlock: syntax.string, // Minimal syntax, following the editor: only strings, constants, comments and definitions. syntaxComment: syntax.comment, syntaxKeyword: site.text_1, syntaxFunction: site.text_1, syntaxVariable: site.text_1, syntaxString: syntax.string, syntaxNumber: syntax.constant, syntaxType: syntax.definition, syntaxOperator: ui.muted, syntaxPunctuation: ui.muted, }) export default async ({ themes, write }: Target) => { const [light, dark] = themes const light_colors = colors(light.srgb) const dark_colors = colors(dark.srgb) const theme = mapValues(light_colors, (color, key) => ({ dark: dark_colors[key], light: color, })) await write( 'linkplay-space.json', JSON.stringify({ $schema: 'https://opencode.ai/v2/theme.json', theme }) ) }