返回 presentation-ai
customize-theme.ts
根目录 / src / components / presentation / edit-panel / sections / theme / customize-theme.ts
1 "use client";
2
3 import { nanoid } from "nanoid";
4
5 import { resolvePresentationThemeData } from "@/lib/presentation/theme-resolution";
6 import { themes } from "@/lib/presentation/themes";
7 import { usePresentationState } from "@/states/presentation-state";
8 import { useThemePanelState } from "./theme-panel-state";
9
10 export function openThemeCustomizer() {
11 const { setEditingTheme, setIsCustomizing, setOpenCreateThemeModal } =
12 useThemePanelState.getState();
13 const { theme, customThemeData, generatedThemeData } =
14 usePresentationState.getState();
15 const builtInTheme = themes[theme as keyof typeof themes];
16 const themeData = resolvePresentationThemeData({ customThemeData, theme });
17 const baseThemeData =
18 (theme === "auto" ? generatedThemeData : null) ??
19 resolvePresentationThemeData({ customThemeData: null, theme }) ??
20 themeData;
21
22 if (!themeData) {
23 console.error("Could not find theme data for:", theme);
24 return;
25 }
26
27 const themeName =
28 builtInTheme?.name ||
29 themeData.name ||
30 customThemeData?.name ||
31 "Custom Theme";
32
33 setEditingTheme({
34 id: nanoid(),
35 name: themeName,
36 description: themeData.description,
37 themeData,
38 baseThemeData: baseThemeData ?? themeData,
39 isPublic: false,
40 logoUrl: null,
41 userId: "",
42 });
43 setIsCustomizing(true);
44 setOpenCreateThemeModal(true);
45 }
46
46 lines TYPESCRIPT