-
Notifications
You must be signed in to change notification settings - Fork 40
/
svgmixer.d.ts
134 lines (119 loc) · 3.65 KB
/
svgmixer.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
import postsvg from 'postsvg';
declare function svgmixer(files: string | string[], config?: svgmixer.CompilerConfig)
: Promise<svgmixer.CompilerResult>;
declare namespace svgmixer {
interface CompilerConfig {
prettify: boolean,
spriteType: 'classic' | 'stack';
spriteConfig: SpriteConfig | StackSpriteConfig;
generateSymbolId: (path: string, query: string = '') => string;
spriteClass: Sprite | StackSprite;
symbolClass: SpriteSymbol;
}
interface SpriteConfig {
filename: string;
attrs: Object;
usages: boolean;
spacing: number;
}
interface StackSpriteConfig extends SpriteConfig {
usageClassName: string;
styles: string;
}
class Compiler {
static readonly defaultConfig: CompilerConfig;
static create(config?: CompilerConfig): Compiler;
constructor(public config?: CompilerConfig);
get symbols(): SpriteSymbol[];
addSymbol(symbol: SpriteSymbol): void;
addSymbolFromFile(path: string): Promise;
createSymbol(opts: { path: string, content: string, id?: string }): SpriteSymbol;
compile(): Promise<CompilerResult>;
glob(pattern: string | string[]): Promise;
}
class CompilerResult {
constructor(public content: string, public sprite: Sprite);
get filename(): string;
write(path: string): Promise;
}
class Image {
constructor(path: string, content: string);
path: string;
query: string;
get viewBox(): number[] | undefined;
get width(): number | undefined;
get height(): number | undefined;
get content(): string;
get tree(): postsvg.Tree;
toString(): string;
}
class Sprite {
static readonly defaultConfig: SpriteConfig;
static readonly TYPE: 'classic' | 'stack';
constructor(config?: SpriteConfig, symbols?: SpriteSymbol[]);
get width(): number;
get height(): number;
get symbols(): SpriteSymbol[];
addSymbol(symbol: SpriteSymbol): void;
calculateSymbolPosition(symbol: SpriteSymbol, format?: boolean = false): SpriteSymbolPosition;
calculateSymbolPosition(symbol: SpriteSymbol, format?: 'px' | 'percent'): StringifiedSpriteSymbolPosition;
generate(): Promise<postsvg.Tree>;
render(): Promise<string>;
}
class SpriteSymbol {
constructor(public id: string, public image: Image);
get width(): number | undefined;
get height(): number | undefined;
get viewBox(): number[] | undefined;
get request(): string | undefined;
generate(): Promise<postsvg.Tree>
render(): Promise<string>;
}
class SpriteSymbolsMap extends Map {
constructor(symbols?: SpriteSymbol[]);
add(symbol: SpriteSymbol): this;
toArray(): SpriteSymbol[];
}
class SpriteValue extends Number {
static create(value: number, base: number): SpriteValue;
constructor(value: number, public base: number);
get factor(): number;
toPx(decimalPlaces: number = 2): string;
toPercent(decimalPlaces: number = 2): string;
}
class StackSprite extends Sprite {
static readonly defaultConfig: StackSpriteConfig;
constructor(config?: StackSpriteConfig, symbols?: SpriteSymbol[]);
}
type SpriteSymbolPosition = {
width: SpriteValue;
height: SpriteValue;
aspectRatio: SpriteValue;
left: SpriteValue;
top: SpriteValue;
bgSize: {
width: SpriteValue;
height: SpriteValue;
};
bgPosition: {
left: SpriteValue;
top: SpriteValue;
};
};
type StringifiedSpriteSymbolPosition = {
width: string;
height: string;
aspectRatio: string;
left: string;
top: string;
bgSize: {
width: string;
height: string;
};
bgPosition: {
left: string;
top: string;
};
};
}
export = svgmixer;