mount-css
Version:
A simple function for mounting css
8 lines (7 loc) • 775 B
JavaScript
/*!
* mount-css v1.2.0
* A simple function for mounting css
* (c) 2021-2023 saqqdy<https://github.com/saqqdy>
* Released under the MIT License.
*/
function e(e,t){if(void 0===t&&(t={}),!e)throw new Error("[mountCss]: url is required");var r=t.attrs,n=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 d,i,l=document.createElement("link");if(r)for(d in r)l[d]=r[d];if(n)for(i in n)l[i]=n[i];l.rel="stylesheet",l.type="text/css",l.href=e,document.getElementsByTagName("head")[0].appendChild(l),l.onload=l.onreadystatechange=function(){l.readyState&&!["loaded","complete"].includes(l.readyState)||(l.onload=l.onreadystatechange=null,t(!0))},l.onerror=o}else t(!0)}))}export{e as default};