UNPKG

@sctg/fontminify

Version:

Minify font seamlessly, font subsetter, webfont (eot, woff, svg) converter.

133 lines (132 loc) 3.87 kB
/** * @file fontmin * @author junmer eltorio */ /// <reference types="node" /> /// <reference types="node" /> /// <reference types="node" /> import * as stream from "stream"; import { EventEmitter } from "events"; declare type FontminifyPlugin = typeof Fontminify.css | typeof Fontminify.glyph | typeof Fontminify.otf2ttf | typeof Fontminify.svg2ttf | typeof Fontminify.svgs2ttf | typeof Fontminify.ttf2eot | typeof Fontminify.ttf2svg | typeof Fontminify.ttf2woff | typeof Fontminify.ttf2woff2 | stream.Transform; declare type FontminifyAsSrc = string[] | string | Buffer; export interface PluginCloneOption { clone?: boolean; } export interface PluginHintOption { hinting?: boolean; } export interface PluginFromSVGOption extends PluginHintOption { fontName?: string; adjust?: { leftSidebearing: number; rightSidebearing: number; ajdustToEmBox: boolean; ajdustToEmPadding: number; }; name?: { fontFamily?: string; fontSubFamily?: string; uniqueSubFamily?: string; postScriptName?: string; }; } export interface FontInfo { fontFile: string; fontPath: string; base64: boolean | string; glyph: boolean; iconPrefix: string; local: boolean; fontFamily?: string; } export interface CssOption { glyph?: boolean; base64?: boolean; iconPrefix?: string; fontFamily?: string | ((fontinfo: FontInfo, ttf: any) => string); filename?: string; fontPath?: string; asFileName?: boolean; local?: boolean; tpl?: string; } export interface GlyphOption { text?: string; basicText?: boolean; hinting?: boolean; use?: FontminifyPlugin; } export interface FontminifyFile extends File { _contents: stream.Readable; } /** * Initialize Fontminify */ declare class Fontminify<SrcType extends FontminifyAsSrc> extends EventEmitter { streams: stream[]; _src: any; _dest: any; constructor(); /** * Get or set the source files */ src(...file: any[]): Fontminify<SrcType>; /** * Get or set the destination folder */ dest(...dir: any): Fontminify<SrcType>; /** * Add a plugin to the middleware stack */ use(plugin: FontminifyPlugin): Fontminify<SrcType>; /** * Optimize files */ run(cb: (err: Error, files: Array<FontminifyFile>, stream: stream.Stream) => void): stream; /** * Create stream * * @return {Stream} file stream * @api private */ createStream(): any; /** * Get files * * @return {Stream} file stream * @api private */ getFiles(): any; static glyph: (opts: GlyphOption) => stream.Transform; static ttf2eot: (opts?: PluginCloneOption) => stream.Transform; static ttf2woff: (opts?: PluginCloneOption) => stream.Transform; static ttf2woff2: (opts?: PluginCloneOption) => stream.Transform; static ttf2svg: (opts?: PluginCloneOption) => stream.Transform; static css: (opts?: CssOption) => stream.Transform; static svg2ttf: (opts?: PluginCloneOption & PluginHintOption) => stream.Transform; static svgs2ttf: (file: string, opts?: PluginFromSVGOption) => stream.Transform; static otf2ttf: (opts?: PluginCloneOption & PluginHintOption) => stream.Transform; static util: { getFontFolder: () => string; getFonts: () => string[]; getPureText: (str: string) => string; getUniqText: (str: string) => string; getSubsetText: (opts: any) => any; string2unicodes: (str: string) => number[]; }; static plugins: string[]; static mime: { ".*": string; ttf: string; otf: string; woff: string; woff2: string; eot: string; svg: string; svgz: string; }; } /** * Module exports */ export default Fontminify;