animify/Minicons

View on GitHub
umd/minicons.min.js

Summary

Maintainability
A
0 mins
Test Coverage
(function(a,b){'object'==typeof exports&&'object'==typeof module?module.exports=b():'function'==typeof define&&define.amd?define([],b):'object'==typeof exports?exports.minicons=b():a.minicons=b()})(this,function(){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{configurable:!1,enumerable:!0,get:d})},b.n=function(a){var c=a&&a.__esModule?function(){return a['default']}:function(){return a};return b.d(c,'a',c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p='',b(b.s=0)}([function(a,b,c){a.exports=c(1)},function(a,b,c){'use strict';var d=c(2),e=function(a){return a&&a.__esModule?a:{default:a}}(d);a.exports=new e.default},function(a,b,c){'use strict';function d(a){return a&&a.__esModule?a:{default:a}}function e(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(b,'__esModule',{value:!0});var f=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),g=c(3),h=d(g),i=c(4),j=d(i),k=function(){function a(){e(this,a),this.firstRun=!0,this.canObserve=!0,this.config=h.default.config,this.icons=h.default.icons,this.defaultProps={xmlns:'http://www.w3.org/2000/svg'}}return f(a,[{key:'setOptions',value:function(a){var b=this;j.default.validateOptions(a,function(c){c?console.log('%cMinicons:','font-weight: bold; text-decoration: underline;','Oh oh! Something wrong when processing your options. '+c.message+' ['+c.type+']'):(a.config.props=Object.assign(b.config.props,a.config.props),b.config=a.config||b.config,b.canObserve=void 0===a.observe||a.observe)})}},{key:'find',value:function(a){return this.icons.find(function(b){var c=b.name===a,d=b.aliases.includes(a);return c||d})}},{key:'create',value:function(a,b){var c=[],d=this.find(a),e=Object.assign(b,this.defaultProps);if(d){Object.keys(e).forEach(function(a){e[a]&&c.push(a+'="'+e[a]+'"')});var f='<svg '+c.join(' ')+'>'+d.content+'</svg>',g=new DOMParser().parseFromString(f,'image/svg+xml'),h=g.querySelector('svg');if(d.hasOwnProperty('fillTag')){var i=h.getElementsByTagName(d.fillTag);i=Array.prototype.slice.call(i),i.forEach(function(a){a.setAttribute('fill',e.stroke),a.setAttribute('stroke-width',0)})}return h}}},{key:'swap',value:function(){var a=this,b=document.querySelectorAll('[data-minicon]');b.forEach(function(b){return a.swapElement(b)}),this.firstRun&&(this.canObserve&&this.setObserver(),this.firstRun=!1)}},{key:'swapElement',value:function(a){var b=Object.assign(this.config.props,{class:a.classList.value+' minicon minicon-'+a.dataset.minicon}),c=this.create(a.dataset.minicon,b);c&&a.parentNode.replaceChild(c,a)}},{key:'setObserver',value:async function(){await this.watch(document.getElementsByTagName('body')[0])}},{key:'watch',value:function(a){var b=this,c={attributes:!1,childList:!0,characterData:!1};return new Promise(function(d){new MutationObserver(function(a){a.forEach(function(a){return b.handleMutation(a)}),d(a)}).observe(a,c)})}},{key:'handleMutation',value:function(a){if(0!==a.addedNodes.length){var b=a.addedNodes[0],c=b.dataset&&b.dataset.minicon;c&&this.swapElement(b)}}}]),a}();b.default=k},function(a){a.exports={config:{name:'default',props:{width:24,height:24,viewBox:'0 0 24 24',fill:'none',stroke:'#000',"stroke-width":2,"stroke-linejoin":'round',"stroke-linecap":'round'}},icons:[]}},function(a,b){'use strict';function c(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(b,'__esModule',{value:!0});var d=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),e=function(){function a(){c(this,a)}return d(a,null,[{key:'validateOptions',value:function(a,b){var c={type:'',message:''};if(null===a)return c.type='Object',c.message='Options are null.',b(c);if(!a)return c.type='Object',c.message='Options are undefined.',b(c);if(a.hasOwnProperty('observe')&&'boolean'!=typeof a.observe)return c.type='options.observe',c.message='Observe property is not a boolean.',b(c);if(a.hasOwnProperty('config')){if(a.config.hasOwnProperty('name')&&'string'!=typeof a.config.name)return c.type='options.config.name',c.message='Config name is not a string.',b(c);a.config.hasOwnProperty('props')&&(['width','height','stroke-width'].forEach(function(d){if(a.config.props.hasOwnProperty(d)&&'number'!=typeof a.config.props[d])return c.type='options.config.props.'+d,c.message='Config '+d+' property is not a number.',b(c)}),['viewBox','fill','stroke','stroke-linecap','stroke-linejoin'].forEach(function(d){if(a.config.props.hasOwnProperty(d)&&'string'!=typeof a.config.props[d])return c.type='options.config.props.'+d,c.message='Config '+d+' property is not a string.',b(c)}))}return b()}},{key:'validateObject',value:function(){}}]),a}();b.default=e}])});