-
Notifications
You must be signed in to change notification settings - Fork 317
/
index.d.ts
176 lines (155 loc) · 3.89 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* @file fontmin
* @author kekee000([email protected])
*/
import {Transform} from 'stream';
import {TTF} from 'fonteditor-core'
type PluginDesc = (...args: any[]) => Transform;
type InternalPlugin<T extends Record<string, any> = {}> = (opts?: T) => PluginDesc;
interface GlyphPluginOptions {
/**
* use this text to generate compressed font
*/
text: string;
/**
* add basic chars to glyph, default false
* @example "!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}"
*/
basicText?: boolean;
/**
* keep gylph hinting, defaul true
*/
hinting?: boolean;
/**
* use other plugin
*/
use?: PluginDesc;
}
interface FontInfo {
fontFile: string;
fontPath: string;
base64: string;
glyph: boolean;
iconPrefix: string;
local: boolean;
}
interface CssPluginOptions {
/**
* generate class for each glyph. default = false
*/
glyph?: boolean;
/**
* inject base64 data:application/x-font-ttf; (gzip font with css). default = false
*/
base64?: boolean;
/**
* class prefix, only work when glyph is `true`. default = "icon"
*/
iconPrefix?: string;
/**
* rewrite fontFamily from filename force. default = false
*/
asFileName?: boolean;
/**
* location of font file
*/
fontPath?: string;
/**
* custom fontFamily, default = ttf.fontFamily or filename
*
* if opts.fontFamily is funciton, then fontFamily will be function return value
*/
fontFamily?: string | ((fontInfo: FontInfo, ttf: TTF.TTFObject) => string);
/**
* add local font. default = false
*/
local?: boolean;
}
interface Svgs2ttfPluginOptions {
/**
* set svg font name
*/
fontName?: string;
}
declare namespace Fontmin {
/*
* get font subset with giving text
*/
const glyph: InternalPlugin<GlyphPluginOptions>;
/*
* convert ttf to eot
*/
const ttf2eot: InternalPlugin;
/*
* convert ttf to woff
*/
const ttf2woff: InternalPlugin<{
/**
* use deflate to transform woff, default false
*/
deflate: boolean;
}>;
/*
* convert ttf to woff2
*/
const ttf2woff2: InternalPlugin;
/*
* convert ttf to svg text
*/
const ttf2svg: InternalPlugin;
/*
* Generate css from ttf, often used to make iconfont.
*/
const css: InternalPlugin<CssPluginOptions>;
/**
* convert font format svg to ttf
*/
const svg2ttf: InternalPlugin<{hinting?: boolean}>;
/**
* concat svg files to a ttf, just like css sprite
*/
const svgs2ttf: (file: string, opts?: Svgs2ttfPluginOptions) => PluginDesc;
/**
* convert otf to ttf
*/
const otf2ttf: InternalPlugin;
}
type PluginNames = keyof typeof Fontmin;
declare class Fontmin {
static plugins: PluginNames[];
/**
* Get or set the source files
* @param file files to be optimized
*/
src(src: ArrayLike<number> | Buffer | string): this;
/**
* Get or set the destination folder
* @param dir folder to written
*/
dest(dest: string): this;
/**
* Add a plugin to the middleware stack
* @param plugin plugin function
*/
use(plugin: PluginDesc): this;
/**
* run Optimize files with callback
* @param callback plugin function
*/
run(callback: (e: Error, files: Buffer[]) => void): Transform;
/**
* run Optimize files with return Promise
*/
runAsync(): Promise<Buffer[]>;
}
export default Fontmin;
export const mime: {
'.*': 'application/octet-stream',
'ttf': 'application/font-sfnt',
'otf': 'application/font-sfnt',
'woff': 'application/font-woff',
'woff2': 'application/font-woff2',
'eot': 'application/octet-stream',
'svg': 'image/svg+xml',
'svgz': 'image/svg+xml'
};