forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svg-sprite.d.ts
362 lines (342 loc) · 15.5 KB
/
svg-sprite.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// Type definitions for svg-sprite
// Project: https://github.com/jkphl/svg-sprite
// Definitions by: Qubo <https://github.com/tkqubo>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/// <reference path="../vinyl/vinyl.d.ts" />
/// <reference path="../winston/winston.d.ts" />
declare module "svg-sprite" {
import File = require('vinyl');
import winston = require('winston');
namespace sprite {
interface SVGSpriterConstructor extends NodeJS.EventEmitter {
/**
* The spriter's constructor (always the entry point)
* @param config Main configuration for the spriting process
*/
new(config: Config): SVGSpriter;
}
interface SVGSpriter {
/**
* Registering source SVG files
* @param file Absolute path to the SVG file or a vinyl file object carrying all the necessary values (the following arguments are ignored then).
* @param name The "local" part of the file path, possibly including subdirectories which will get traversed to CSS selectors using the shape.id.separator configuration option.
* @param svg SVG file content.
*/
add(file: string|File, name: string, svg: string): SVGSpriter;
/**
* Registering source SVG files
* @param file Absolute path to the SVG file or a vinyl file object carrying all the necessary values (the following arguments are ignored then).
*/
add(file: File): SVGSpriter;
/**
* Triggering the sprite compilation
* @param config Configuration object setting the output mode parameters for a single compilation run. If omitted, the mode property of the main configuration used for the constructor will be used.
* @param callback Callback triggered when the compilation has finished.
*/
compile(config: Config, callback: CompileCallback): SVGSpriter;
/**
* Triggering the sprite compilation
* @param callback Callback triggered when the compilation has finished.
*/
compile(callback: CompileCallback): void;
/**
* Accessing the intermediate SVG resources
* @param dest Base directory for the SVG files in case the will be written to disk.
* @param callback Callback triggered when the shapes are available.
*/
getShapes(dest: string, callback: GetShapesCallback): void;
}
interface Config {
/**
* Main output directory
* @default '.'
*/
dest?: string;
/**
* Logging verbosity or custom logger
*/
log?: string|winston.LoggerInstance;
/**
* SVG shape configuration
*/
shape?: Shape;
/**
* Sprite SVG options
*/
svg?: Svg;
/**
* Custom templating variables
*/
variables?: any;
/**
* Output mode configurations
*/
mode?: Mode;
}
/**
* All settings affecting the SVG shapes of the sprite
*/
interface Shape {
/**
* SVG shape ID related options
*/
id?: {
/**
* Separator for directory name traversal
*/
separator?: string;
/**
* SVG shape ID generator callback
*/
generator?: string|((svg: string) => string);
/**
* File name separator for shape states (e.g. ':hover')
*/
pseudo?: string;
/**
* Whitespace replacement for shape IDs
*/
whitespace?: string;
};
/**
* Dimension related options
*/
dimension?: {
/**
* Max. shape width
*/
maxWidth?: number;
/**
* Max. shape height
*/
maxHeight?: number;
/**
* Floating point precision
*/
precision?: number;
/**
* Width and height attributes on embedded shapes
*/
attributes?: boolean;
};
/**
* Spacing related options
*/
spacing?: {
/**
* Padding around all shapes
*/
padding?: number|number[];
/**
* Padding strategy (similar to CSS `box-sizing`)
*/
box?: string;
};
/**
* List of transformations / optimizations
*/
transform?: (string|CustomConfigurationTransform|CustomCallbackTransform)[];
/**
* Path to YAML file with meta / accessibility data
*/
meta?: string;
/**
* Path to YAML file with extended alignment data
*/
align?: string;
/**
* Output directory for optimized intermediate SVG shapes
*/
dest?: string;
}
/**
* Pre-defined shape transformation with custom configuration
*/
interface CustomConfigurationTransform {
[transformationName: string]: {
plugins?: { [transformationName: string]: boolean }[];
}
}
/**
* Custom callback transformation
*/
interface CustomCallbackTransform {
[transformationName: string]: {
/**
* Custom callback transformation
* @param shape SVG shape object
* @param sprite SVG spriter
* @param callback Callback
*/
(shape: any, sprite: SVGSpriter, callback: Function): any;
}
}
interface Svg {
/**
* Output an XML declaration at the very beginning of each compiled sprite.
* If you provide a non-empty string here, it will be used one-to-one as declaration (e.g. <?xml version="1.0" encoding="utf-8"?>).
* If you set this to TRUE, *svg-sprite* will look at the registered shapes for an XML declaration and use the first one it can find.
* @default true
*/
xmlDeclaration?: boolean|string;
/**
* Include a <DOCTYPE> declaration in each compiled sprite. If you provide a non-empty string here,
* it will be used one-to-one as declaration (e.g. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">).
* If you set this to TRUE, *svg-sprite* will look at the registered shapes for a DOCTYPE declaration and use the first one it can find.
* @default true
*/
doctypeDeclaration?: boolean|string;
/**
* In order to avoid ID clashes, the default behavior is to namespace all IDs in the source SVGs before compiling them into a sprite.
* Each ID is prepended with a unique string. In some situations, it might be desirable to disable ID namespacing, e.g. when you want to script the resulting sprite.
* Just set svg.namespaceIDs to FALSE then and be aware that you might also want to disable SVGO's ID minification (shape.transform.svgo.plugins: [{cleanupIDs: false}]).
* @default true
*/
namespaceIDs?: boolean;
/**
* In order to avoid CSS class name ambiguities, the default behavior is to namespace CSS class names in the source SVGs before compiling them into a sprite.
* Each class name is prepended with a unique string. Disable this option to keep the class names untouched.
* @default true
*/
namespaceClassnames?: boolean;
/**
* If truthy, width and height attributes will be set on the sprite's <svg> element (where applicable).
* @default true
*/
dimensionAttributes?: boolean;
/**
* Shorthand for applying custom attributes to the outermost <svg> element.
* Please be aware that certain attributes (e.g. viewBox) will be calculated dynamically and override custom rootAttributes in any case.
*/
rootAttributes?: any;
/**
* Floating point precision for CSS positioning values (defaults to -1 meaning highest possible precision).
*/
precision?: number;
/**
* Callback (or list of callbacks) that will be applied to the resulting SVG sprites as global [post-processing transformation](#svg-sprite-customization).
* transform: Function∣Array
*/
transform?: SvgTransformer|SvgTransformer[];
}
interface SvgTransformer {
/**
* Custom sprite SVG transformation
* @param svg Sprite SVG
* @return Processed SVG
*/
(svg: string): string;
}
interface Mode {
css?: CssAndViewSpecificModeConfig|boolean;
view?: CssAndViewSpecificModeConfig|boolean;
defs?: DefsAndSymbolSpecificModeConfig|boolean;
symbol?: DefsAndSymbolSpecificModeConfig|boolean;
stack?: ModeConfig|boolean;
[customConfigName: string]: ModeConfig;
}
interface ModeConfig {
/**
* Base directory for sprite and CSS file output. If not absolute, the path will be resolved using the main output directory (see global dest option).
* @default "<mode>"
*/
dest?: string;
/**
* Used for prefixing the [shape ID](#shape-ids) during CSS selector construction. If the value is empty,
* no prefix will be used. The prefix may contain the placeholder "%s" (e.g. ".svg %s-svg"),
* which will then get replaced by the shape ID. Please be aware that "%" is a special character
* in this context and that you'll have to escape it by another percent sign ("%%") in case you want
* to output it to your stylesheets (e.g. for a [Sass placeholder selector](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#placeholder_selectors_)).
* @default ".svg-%s"
*/
prefix?: string;
/**
* A non-empty string value will trigger the creation of additional CSS rules specifying the dimensions of each shape in the sprite.
* The string will be used as suffix to mode.<mode>.prefix during CSS selector construction and may contain the placeholder "%s",
* which will get replaced by the value of mode.<mode>.prefix.
* A boolean TRUE will cause the dimensions to be included directly into each shape's CSS rule (only available for «css» and «view» sprites).
* @default "-dims"
*/
dimensions?: string|boolean;
/**
* SVG sprite path and file name, relative to the mode.<mode>.dest directory.
* You may omit the file extension, in which case it will be set to ".svg" automatically.
* @default "svg/sprite.<mode>.svg"
*/
sprite?: string;
/**
* Add a content based hash to the name of the sprite file so that clients reliably reload the sprite
* when it's content changes («cache busting»). Defaults to false except for «css» and «view» sprites.
* @default true∣false
*/
bust?: boolean;
/**
* Collection of [stylesheet rendering configurations](#rendering-configurations).
* The keys are used as file extensions as well as file return keys. At present,
* there are default templates for the file extensions css ([CSS](http://www.w3.org/Style/CSS/)),
* scss ([Sass](http://sass-lang.com/)), less ([Less](http://lesscss.org/)) and styl ([Stylus](http://learnboost.github.io/stylus/)),
* which all reside in the directory tmpl/css. Example: {css: true, scss: {dest: '_sprite.scss'}}
* @default {}
*/
render?: { [key: string]: RenderingConfiguration|boolean };
/**
* Enabling this will trigger the creation of an HTML document demoing the usage of the sprite. Please see below for details on [rendering configurations](#rendering-configurations).
* @default false
*/
example?: RenderingConfiguration|boolean;
/**
* Specify svg-sprite which output mode to use with this configuration
*/
mode?: string;
}
interface RenderingConfiguration {
/**
* HTML document Mustache template
* @default "tmpl/<mode>/sprite.html"
*/
template?: string;
/**
* HTML document destination
* @default "sprite.<mode>.html"
*/
dest?: string;
}
interface CssAndViewSpecificModeConfig extends ModeConfig {
/**
* The arrangement of the shapes within the sprite. Might be "vertical", "horizontal", "diagonal" or "packed"
* (with the latter being the most compact type). It depends on your project which layout is best for you.
* @default "packed"
*/
layout?: string;
/**
* If given and not empty, this will be the selector name of a CSS rule commonly specifying the background-image
* and background-repeat properties for all the shapes in the sprite (thus saving some bytes by not unnecessarily repeating them for each shape)
*/
common?: string;
/**
* If given and not empty, a mixin with this name will be added to supporting output formats (e.g. Sass, LESS, Stylus),
* specifying the background-image and background-repeat properties for all the shapes in the sprite.
* You may use it for creating custom CSS within @media rules. The mixin acts much like the common rule.
* In fact, you can even combine the two - if both are enabled, the common rule will use the mixin internally.
*/
mixin?: string;
}
interface DefsAndSymbolSpecificModeConfig extends ModeConfig {
/**
* If you want to embed the sprite into your HTML source, you will want to set this to true
* in order to prevent the creation of SVG namespace declarations and to set some other attributes for effectively hiding the library sprite.
* @default false
*/
inline?: boolean;
}
interface CompileCallback {
(error: Error, result: any, data: any): any;
}
interface GetShapesCallback {
(error: Error, result: File[]): any;
}
}
var sprite: sprite.SVGSpriterConstructor;
export = sprite;
}