UNPKG

767 BJavaScriptView Raw
1const { renderer } = require('posthtml-svg-mode');
2const defaultFactory = require('./sprite-factory');
3
4class Sprite {
5 constructor({ tree, filename }) {
6 this.tree = tree;
7 this.filename = filename;
8 }
9
10 /**
11 * @param {Object} options
12 * @param {Array<SpriteSymbol>} options.symbols
13 * @param {string} options.filename Output sprite filename
14 * @param {Function<Promise<PostHTMLProcessingResult>>} [options.factory]
15 * @return {Promise<Sprite>}
16 */
17 static create(options) {
18 const { symbols, filename, factory = defaultFactory } = options;
19 return factory({ symbols }).then(({ tree }) => new Sprite({ tree, filename }));
20 }
21
22 /**
23 * @return {string}
24 */
25 render() {
26 return renderer(this.tree);
27 }
28}
29
30module.exports = Sprite;