| 1 | import { type PlateSlide } from "@/components/notebook/presentation/utils/parser"; |
| 2 | |
| 3 | export type PresentationGenerationAspectRatio = "dynamic" | "16:9"; |
| 4 | |
| 5 | export const DEFAULT_PRESENTATION_GENERATION_ASPECT_RATIO: PresentationGenerationAspectRatio = |
| 6 | "dynamic"; |
| 7 | |
| 8 | export const DEFAULT_PRESENTATION_SLIDE_ASPECT_RATIO: NonNullable< |
| 9 | PlateSlide["aspectRatio"] |
| 10 | > = { type: "fluid" }; |
| 11 | |
| 12 | export const PRESENTATION_GENERATION_ASPECT_RATIO_OPTIONS = [ |
| 13 | { |
| 14 | label: "Dynamic", |
| 15 | shortLabel: "Dynamic", |
| 16 | value: "dynamic", |
| 17 | }, |
| 18 | { |
| 19 | label: "16:9", |
| 20 | shortLabel: "16:9", |
| 21 | value: "16:9", |
| 22 | }, |
| 23 | ] as const; |
| 24 | |
| 25 | export function normalizePresentationGenerationAspectRatio( |
| 26 | value: unknown, |
| 27 | ): PresentationGenerationAspectRatio { |
| 28 | return value === "16:9" ? "16:9" : "dynamic"; |
| 29 | } |
| 30 | |
| 31 | export function getPresentationGenerationAspectRatioLabel( |
| 32 | value: PresentationGenerationAspectRatio, |
| 33 | ): string { |
| 34 | return value === "16:9" ? "16:9" : "Dynamic"; |
| 35 | } |
| 36 | |
| 37 | export function getSlideAspectRatioForGenerationAspectRatio( |
| 38 | value: PresentationGenerationAspectRatio, |
| 39 | ): NonNullable<PlateSlide["aspectRatio"]> { |
| 40 | return value === "16:9" |
| 41 | ? { type: "ratio", value: "16:9" } |
| 42 | : DEFAULT_PRESENTATION_SLIDE_ASPECT_RATIO; |
| 43 | } |
| 44 | |
| 45 | export function applyGenerationAspectRatioToSlides( |
| 46 | slides: PlateSlide[], |
| 47 | value: PresentationGenerationAspectRatio, |
| 48 | ): PlateSlide[] { |
| 49 | const aspectRatio = getSlideAspectRatioForGenerationAspectRatio(value); |
| 50 | |
| 51 | return slides.map((slide) => ({ |
| 52 | ...slide, |
| 53 | formatCategory: "presentation", |
| 54 | aspectRatio, |
| 55 | })); |
| 56 | } |
| 57 |