theme_config.ts

 1import { Scale, Color } from "chroma-js"
 2import { SyntaxHighlightStyle, SyntaxProperty } from "../types/syntax"
 3
 4interface ThemeMeta {
 5    /** The name of the theme */
 6    name: string
 7    /** The theme's appearance. Either `light` or `dark`. */
 8    appearance: ThemeAppearance
 9    /** The author of the theme
10     *
11     * Ideally formatted as `Full Name <email>`
12     *
13     * Example: `John Doe <john@doe.com>`
14     */
15    author: string
16    /** SPDX License string
17     *
18     * Example: `MIT`
19     */
20    license_type?: string | ThemeLicenseType
21    license_url?: string
22    license_file: string
23    theme_url?: string
24}
25
26export type ThemeFamilyMeta = Pick<
27    ThemeMeta,
28    "name" | "author" | "license_type" | "license_url"
29>
30
31export interface ThemeConfigInputColors {
32    neutral: Scale<Color>
33    red: Scale<Color>
34    orange: Scale<Color>
35    yellow: Scale<Color>
36    green: Scale<Color>
37    cyan: Scale<Color>
38    blue: Scale<Color>
39    violet: Scale<Color>
40    magenta: Scale<Color>
41}
42
43export type ThemeConfigInputColorsKeys = keyof ThemeConfigInputColors
44
45/** Allow any part of a syntax highlight style to be overriden by the theme
46 *
47 * Example:
48 * ```ts
49 * override: {
50 *   syntax: {
51 *     boolean: {
52 *       underline: true,
53 *     },
54 *   },
55 * }
56 * ```
57 */
58export type ThemeConfigInputSyntax = Partial<
59    Record<SyntaxProperty, Partial<SyntaxHighlightStyle>>
60>
61
62interface ThemeConfigOverrides {
63    syntax: ThemeConfigInputSyntax
64}
65
66type ThemeConfigProperties = ThemeMeta & {
67    input_color: ThemeConfigInputColors
68    override: ThemeConfigOverrides
69}
70
71export type ThemeConfig = {
72    [K in keyof ThemeConfigProperties]: ThemeConfigProperties[K]
73}
74
75export enum ThemeAppearance {
76    Light = "light",
77    Dark = "dark",
78}
79
80export enum ThemeLicenseType {
81    MIT = "MIT",
82    Apache2 = "Apache License 2.0",
83}