返回 presentation-ai
typography.ts
根目录 / src / components / notebook / presentation / editor / utils / typography.ts
1 export type PresentationFontSize = "S" | "M" | "L" | undefined;
2
3 // Returns CSS variables for heading/paragraph sizes based on slide font size.
4 // Current values reflect the previous M defaults and act as fallback when size is undefined.
5 export function getTypographyCSSVariables(size: PresentationFontSize) {
6 // M defaults match previous static values
7 const baseM = {
8 h1: 3,
9 h2: 1.875,
10 h3: 1.5,
11 h4: 1.25,
12 h5: 1.125,
13 h6: 1,
14 p: 1,
15 } as const;
16
17 // Scale factors derived from container base font px: S=12, M=16, L=18
18 // Relative to M: S = 12/16 = 0.75, L = 18/16 = 1.125
19 const factor = size === "S" ? 0.75 : size === "L" ? 1.125 : 1;
20
21 const scaled = {
22 h1: `${round(baseM.h1 * factor)}em`,
23 h2: `${round(baseM.h2 * factor)}em`,
24 h3: `${round(baseM.h3 * factor)}em`,
25 h4: `${round(baseM.h4 * factor)}em`,
26 h5: `${round(baseM.h5 * factor)}em`,
27 h6: `${round(baseM.h6 * factor)}em`,
28 p: `${round(baseM.p * factor)}em`,
29 } as const;
30
31 return {
32 "--presentation-h1-size": scaled.h1,
33 "--presentation-h2-size": scaled.h2,
34 "--presentation-h3-size": scaled.h3,
35 "--presentation-h4-size": scaled.h4,
36 "--presentation-h5-size": scaled.h5,
37 "--presentation-h6-size": scaled.h6,
38 "--presentation-p-size": scaled.p,
39 } as Record<string, string>;
40 }
41
42 function round(value: number): string {
43 // Keep up to 3 decimals to avoid noisy values like 2.109375
44 return Number(Math.round((value + Number.EPSILON) * 1000) / 1000).toString();
45 }
46
46 lines TYPESCRIPT