diff --git a/packages/jaamd/package.json b/packages/jaamd/package.json index 87d5300..8e06c37 100644 --- a/packages/jaamd/package.json +++ b/packages/jaamd/package.json @@ -35,7 +35,10 @@ "./styles.css": "./src/styles/markdown.css", "./shiki-dual": "./src/styles/shiki-dual.css", "./shiki-dual.css": "./src/styles/shiki-dual.css", - "./themes": "./src/themes/index.ts", + "./themes": { + "types": "./src/themes/index.d.ts", + "default": "./src/themes/index.js" + }, "./themes/*/dark.css": "./src/themes/*/dark.css", "./themes/*/dark": "./src/themes/*/dark.css", "./themes/*.css": "./src/themes/*/index.css", diff --git a/packages/jaamd/src/themes/index.d.ts b/packages/jaamd/src/themes/index.d.ts new file mode 100644 index 0000000..9a1fa48 --- /dev/null +++ b/packages/jaamd/src/themes/index.d.ts @@ -0,0 +1,20 @@ +/** + * `light` and `dark` are single palettes that apply in both modes; `dual` carries + * both, a `:root` block and an `html.dark` one, and follows whatever decides the + * mode. A `dual` theme has no `/dark` variant — its own file already does that. + */ +export type JaamdThemeMode = "light" | "dark" | "dual"; + +export interface JaamdTheme { + /** Directory name, and the value a `data-jaamd-theme` attribute would carry. */ + slug: string; + /** Human-readable name, for pickers. */ + name: string; + mode: JaamdThemeMode; + /** Shiki theme that pairs with this palette, or a pair for a `dual` one. */ + shiki: string | { light: string; dark: string }; +} + +export declare const themes: JaamdTheme[]; + +export declare const REQUIRED_TOKENS: string[]; diff --git a/packages/jaamd/src/themes/index.ts b/packages/jaamd/src/themes/index.js similarity index 60% rename from packages/jaamd/src/themes/index.ts rename to packages/jaamd/src/themes/index.js index 03e0fab..8c49347 100644 --- a/packages/jaamd/src/themes/index.ts +++ b/packages/jaamd/src/themes/index.js @@ -1,27 +1,15 @@ -/* - * Theme manifest. Consumers build pickers from this instead of hardcoding a - * list; `tests/unit/themes.mjs` checks each entry against a directory that - * honours the token contract. - */ - /** - * `light` and `dark` are single palettes applying in both modes. `dual` carries - * both a `:root` block and an `html.dark` one, and follows the mode; it has no - * `/dark` variant. + * What every theme declares about itself. Consumers build theme pickers from + * this instead of hardcoding a list, and `tests/unit/themes.mjs` checks that + * each entry matches a directory that honours the token contract. + * + * Plain JavaScript on purpose: Node refuses to strip types from files under + * node_modules, so a TypeScript manifest would be readable by bundlers and by + * nothing else — tooling and test runners included. Types live in index.d.ts. */ -export type JaamdThemeMode = "light" | "dark" | "dual"; -export interface JaamdTheme { - /** Directory name, and the value a `data-jaamd-theme` attribute would carry. */ - slug: string; - /** Human-readable name, for pickers. */ - name: string; - mode: JaamdThemeMode; - /** Shiki theme that pairs with this palette, or a pair for a `dual` one. */ - shiki: string | { light: string; dark: string }; -} - -export const themes: JaamdTheme[] = [ +/** @type {import("./index.d.ts").JaamdTheme[]} */ +export const themes = [ { slug: "catppuccin", name: "Catppuccin", @@ -63,4 +51,4 @@ export const REQUIRED_TOKENS = [ "--jaamd-alert-important-color", "--jaamd-alert-warning-color", "--jaamd-alert-caution-color", -] as const; +]; diff --git a/scripts/build-themes.mjs b/scripts/build-themes.mjs index f737fe2..6f9260e 100644 --- a/scripts/build-themes.mjs +++ b/scripts/build-themes.mjs @@ -10,7 +10,7 @@ import { readdirSync, readFileSync, writeFileSync, rmSync, existsSync } from "no import { join } from "node:path"; import { fileURLToPath } from "node:url"; -import { themes } from "../packages/jaamd/src/themes/index.ts"; +import { themes } from "../packages/jaamd/src/themes/index.js"; const THEMES = join(process.cwd(), "packages", "jaamd", "src", "themes"); diff --git a/tests/build/smoke.mjs b/tests/build/smoke.mjs index b661769..5ddbf92 100644 --- a/tests/build/smoke.mjs +++ b/tests/build/smoke.mjs @@ -7,7 +7,7 @@ import { readFileSync, existsSync } from "node:fs"; import { join } from "node:path"; -import { themes } from "../../packages/jaamd/src/themes/index.ts"; +import { themes } from "../../packages/jaamd/src/themes/index.js"; const DIST = join(process.cwd(), "www", "dist"); const PAGE = join(DIST, "index.html"); diff --git a/tests/unit/themes.mjs b/tests/unit/themes.mjs index 36c8ad2..3971531 100644 --- a/tests/unit/themes.mjs +++ b/tests/unit/themes.mjs @@ -8,7 +8,7 @@ import { readdirSync, readFileSync, existsSync } from "node:fs"; import { join } from "node:path"; import { bundledThemes } from "shiki"; -import { themes, REQUIRED_TOKENS } from "../../packages/jaamd/src/themes/index.ts"; +import { themes, REQUIRED_TOKENS } from "../../packages/jaamd/src/themes/index.js"; import { darkVariant } from "../../scripts/build-themes.mjs"; const THEMES = join(process.cwd(), "packages", "jaamd", "src", "themes"); @@ -30,7 +30,7 @@ for (const slug of slugs) { check( `${slug}: declared in the manifest`, entry, - "add it to packages/jaamd/src/themes/index.ts, or pickers will never show it", + "add it to packages/jaamd/src/themes/index.js, or pickers will never show it", ); if (!entry) continue;