返回 presentation-ai
useAntvInfographicTheme.ts
根目录 / src / hooks / presentation / infographic / useAntvInfographicTheme.ts
1 "use client";
2
3 import { useMemo } from "react";
4
5 import {
6 applyThemeToSyntax,
7 type InfographicPaletteThemeColors,
8 } from "@/components/notebook/presentation/editor/utils/infographic-utils";
9 import { usePresentationTheme } from "@/components/presentation/providers/PresentationThemeProvider";
10 import { resolvePresentationThemeData } from "@/lib/presentation/theme-resolution";
11 import { usePresentationState } from "@/states/presentation-state";
12
13 export function useAntvInfographicTheme(syntax?: string) {
14 const { resolvedTheme } = usePresentationTheme();
15 const isDark = resolvedTheme === "dark";
16 const presentationTheme = usePresentationState((state) => state.theme);
17 const customThemeData = usePresentationState(
18 (state) => state.customThemeData,
19 );
20
21 const themeColors = useMemo<InfographicPaletteThemeColors | null>(() => {
22 return (
23 resolvePresentationThemeData({
24 customThemeData,
25 theme: presentationTheme,
26 })?.colors ?? null
27 );
28 }, [customThemeData, presentationTheme]);
29
30 const themedSyntax = useMemo(() => {
31 return applyThemeToSyntax(syntax ?? "", isDark, themeColors);
32 }, [syntax, isDark, themeColors]);
33
34 return { isDark, themedSyntax, themeColors };
35 }
36
36 lines TYPESCRIPT