UNPKG

mount-css

Version:
8 lines (7 loc) 801 B
/*! * mount-css v1.2.0 * A simple function for mounting css * (c) 2021-2023 saqqdy<https://github.com/saqqdy> * Released under the MIT License. */ this.mountCss=function(){"use strict";return function(e,t){if(void 0===t&&(t={}),!e)throw new Error("[mountCss]: url is required");var n=t.attrs,r=t.props,o=t.force,a=void 0!==o&&o;return new Promise((function(t,o){if(a||!document.querySelector('link[href="'.concat(e,'"]'))){var i,s,c=document.createElement("link");if(n)for(i in n)c[i]=n[i];if(r)for(s in r)c[s]=r[s];c.rel="stylesheet",c.type="text/css",c.href=e,document.getElementsByTagName("head")[0].appendChild(c),c.onload=c.onreadystatechange=function(){c.readyState&&!["loaded","complete"].includes(c.readyState)||(c.onload=c.onreadystatechange=null,t(!0))},c.onerror=o}else t(!0)}))}}();