1
- import type { CustomizationDefaultFont } from '@gitbook/api' ;
1
+ import type { CustomizationFont , FontSource } from '@gitbook/api' ;
2
2
import { generateFontFacesCSS , getFontSourcesToPreload } from './custom' ;
3
3
import { fonts } from './default' ;
4
4
5
- export * from './default' ;
6
- export * from './custom' ;
7
-
8
- /**
9
- * The human-readable font-family name used in CSS (e.g., "Open Sans", "Playfair Display").
10
- * @minLength 1
11
- * @maxLength 50
12
- */
13
- export type FontFamily = string ;
14
-
15
- /**
16
- * Numeric representation of the font weight (400=regular, 500=medium, 700=bold, 900=black).
17
- * @min 1
18
- * @max 1000
19
- */
20
- export type FontWeight = number ;
21
-
22
- /** A font file referenced within a font-face declaration, specifying the file's location and format. */
23
- export interface FontSource {
24
- /** The absolute or relative URL pointing to the font file. */
25
- url : string ;
26
- /** The format of the font file. Prefer 'woff2' for modern browsers. */
27
- format ?: 'woff2' | 'woff' ;
28
- }
29
-
30
- /** A single font-face declaration specifying the weight and source files for a particular variation of the font. */
31
- export interface FontFace {
32
- /** Numeric representation of the font weight (400=regular, 500=medium, 700=bold, 900=black). */
33
- weight : FontWeight ;
34
- /**
35
- * Font source files provided in supported formats (e.g., woff2, woff).
36
- * @minItems 1
37
- */
38
- sources : FontSource [ ] ;
39
- }
40
-
41
- /** Defines a font family along with its various font-face declarations for use in CSS '@font-face' rules. */
42
- export interface CustomizationFontDefinition {
43
- /** A globally unique identifier for the font definition. */
44
- id : string ;
45
- /** The human-readable font-family name used in CSS (e.g., "Open Sans", "Playfair Display"). */
46
- fontFamily : FontFamily ;
47
- /**
48
- * A list of font-face definitions, specifying variations such as weight and style.
49
- * @minItems 1
50
- */
51
- fontFaces : FontFace [ ] ;
52
- }
53
-
54
- /**
55
- * The path of the file in the storage bucket
56
- * @minLength 1
57
- * @maxLength 512
58
- */
59
- export type StorageFileKey = string ;
60
-
61
- export type CustomizationFont = CustomizationDefaultFont | CustomizationFontDefinition ;
62
5
/**
63
6
* Represents font data for either a default font or a custom font
64
7
*/
65
8
type FontData = DefaultFontData | CustomFontData ;
66
9
67
10
/**
68
- * Font data for a default font from next/font
11
+ * Font data for a default font, currently handle with next/font
69
12
*/
70
13
interface DefaultFontData {
71
14
type : 'default' ;
72
15
variable : string ;
73
16
}
74
17
75
18
/**
76
- * Font data for a custom font with @font-face definitions
19
+ * Font data for a custom font with @font-face rules
77
20
*/
78
21
interface CustomFontData {
79
22
type : 'custom' ;
@@ -86,14 +29,12 @@ interface CustomFontData {
86
29
*/
87
30
export function getFontData ( font : CustomizationFont ) : FontData {
88
31
if ( typeof font === 'string' ) {
89
- // Default font from next/font
90
32
return {
91
33
type : 'default' ,
92
34
variable : fonts [ font ] . variable ,
93
35
} ;
94
36
}
95
37
96
- // Custom font with @font -face rules
97
38
return {
98
39
type : 'custom' ,
99
40
fontFaceRules : generateFontFacesCSS ( font ) ,
0 commit comments