pierre-themes.ts
This file
Path
apps/web/src/server/pierre-themes.ts
46 lines · 1.2 KiB · TypeScript
Last changed by
Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647// `@pierre/theming/themes` for the Worker: its collections map every theme to a dynamic import, about 1.7 MB,// and the server draws in the token theme alone, so these collections hold nothing.import { Effect } from "effect";import { normalizeTheme } from "shiki/core";import type { ThemeRegistrationAny, ThemeRegistrationResolved,} from "shiki/core";
interface Descriptor { readonly name: string; readonly load: () => Promise<ThemeRegistrationResolved>;}
const empty = { getTheme: (_name: string): Descriptor | undefined => undefined, getThemes: (): readonly Descriptor[] => [],};
export const pierreThemes = empty;
export const shikiThemes = empty;
export const themes = empty;
const unwrap = ( loaded: ThemeRegistrationAny | { default: ThemeRegistrationAny }) => ("default" in loaded ? loaded.default : loaded);
export const createTheme = ({ load, name,}: { readonly name: string; readonly load: () => Promise< ThemeRegistrationAny | { default: ThemeRegistrationAny } >;}): Descriptor => ({ load: () => Effect.runPromise( Effect.promise(load).pipe( Effect.map((loaded) => normalizeTheme(unwrap(loaded))) ) ), name,});