All files / packages/core/src/catalog entries.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                              2x     2x       86x  
// SPDX-License-Identifier: MIT
/**
 * Lightweight theme catalog for picker UIs.
 *
 * Contains only the metadata needed to render theme selectors (id, label,
 * vendor, appearance, preview colors) — not full design tokens. Prefer this
 * export over `flavors` / `tokens.json` when you do not need token values.
 *
 * Filterable fields (`id`, `vendor`, `appearance`) match full {@link ThemeFlavor}
 * entries, so the same vendor/appearance/include/exclude selection patterns
 * used by `createThemeCatalog()` (#495) apply to these slim entries for
 * UI-only consumers. Full token access still requires `flavors` / `getTheme()`.
 */
 
import catalogJson from './catalog.json' with { type: 'json' };
 
/** Preview swatch colors for a theme picker entry. */
export interface ThemeCatalogPreview {
  bg: string;
  surface: string;
  accent: string;
  text: string;
}
 
/**
 * Slim theme metadata (~200 bytes/theme vs full tokens).
 *
 * Shares `id` / `vendor` / `appearance` with {@link ThemeFlavor} so catalogs
 * can be filtered with the same selection rules as the full flavor list.
 */
export interface ThemeCatalogEntry {
  id: string;
  label: string;
  vendor: string;
  appearance: 'light' | 'dark';
  iconUrl?: string;
  preview: ThemeCatalogPreview;
}
 
const catalogData = catalogJson as ThemeCatalogEntry[];
 
/** All theme catalog entries in canonical theme order. */
export const catalog: readonly ThemeCatalogEntry[] = catalogData;
 
/** O(1) catalog entry lookup by theme ID. */
export const catalogById: Readonly<Record<string, ThemeCatalogEntry>> =
  /*#__PURE__*/ Object.fromEntries(catalog.map((entry) => [entry.id, entry]));