rollup-plugin-svg-icons
Version:
Bundles all svg icons from the speciefed folder to the single spritesheet svg file
3 lines (2 loc) • 3.23 kB
JavaScript
import t from"fs";import n from"path";import r from"cheerio";import e from"pretty";import{minify as o}from"html-minifier";import i from"svgo";function u(t){return function(t){if(Array.isArray(t)){for(var n=0,r=new Array(t.length);n<t.length;n++)r[n]=t[n];return r}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var f="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function a(t,n,r){if(!t.s){if(r instanceof c){if(!r.s)return void(r.o=a.bind(null,t,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(a.bind(null,t,n),a.bind(null,t,2));t.s=n,t.v=r;var e=t.o;e&&e(t)}}var c=function(){function t(){}return t.prototype.then=function(n,r){var e=new t,o=this.s;if(o){var i=1&o?n:r;if(i){try{a(e,1,i(this.v))}catch(t){a(e,2,t)}return e}return this}return this.o=function(t){try{var o=t.v;1&t.s?a(e,1,n?n(o):o):r?a(e,1,r(o)):a(e,2,o)}catch(t){a(e,2,t)}},e},t}();function l(t){return t instanceof c&&1&t.s}function h(t,n,r){if("function"==typeof t[f]){var e,o,i,u=t[f]();if(function t(f){try{for(;!((e=u.next()).done||r&&r());)if((f=n(e.value))&&f.then){if(!l(f))return void f.then(t,i||(i=a.bind(null,o=new c,2)));f=f.v}o?a(o,1,f):o=f}catch(t){a(o||(o=new Pact),2,t)}}(),u.return){var h=function(t){try{e.done||u.return()}catch(t){}return t};if(o&&o.then)return o.then(h,function(t){throw h(t)});h()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var s=[],v=0;v<t.length;v++)s.push(t[v]);return function(t,n,r){var e,o,i=-1;return function u(f){try{for(;++i<t.length&&(!r||!r());)if((f=n(i))&&f.then){if(!l(f))return void f.then(u,o||(o=a.bind(null,e=new c,2)));f=f.v}e?a(e,1,f):e=f}catch(t){a(e||(e=new Pact),2,t)}}(),e}(s,function(t){return n(s[t])},r)}function s(t){return r.load(t,{xmlMode:!0})}function v(t,n){var r=s(n)("svg"),e=s("<symbol/>");return e("symbol").append(r.children()).attr("id",t).attr("viewBox",r.attr("viewBox")),e.html()}function m(t,n){var r=s('<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" />');return t.forEach(function(t){r("svg").append(t)}),n?o(r.html(),{collapseWhitespace:!0}):e(r.html())}export default function(){var r,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=e.minify||!1,f=e.inputFolder||"src/icons",a=e.output||"dist/bundle.svg",c=e.svgo&&new i(e.svgo);return{name:"svelte-svgicons",generateBundle:(r=function(){var r,e,i=[],l=n.resolve(f);return r=h(t.readdirSync(l),function(r){var e,o,f,a=n.parse(r).name,h=n.join(l,r),s=t.readFileSync(h,"utf8");return e=function(){if(c)return t=c.optimize(s,{path:h}),n=function(t){var n=t.data;s=n},r?n?n(t):t:(t&&t.then||(t=Promise.resolve(t)),n?t.then(n):t);var t,n,r},o=function(){i=[].concat(u(i),[v(a,s)])},(f=e())&&f.then?f.then(o):o(f)}),e=function(){i.length>0&&t.writeFileSync(n.resolve(a),m(i,o))},r&&r.then?r.then(e):e(r)},function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return Promise.resolve(r.apply(this,t))}catch(t){return Promise.reject(t)}})}}
//# sourceMappingURL=index.esm.min.js.map