mount-image
Version:
A simple function for mounting image
8 lines (7 loc) • 713 B
JavaScript
/*!
* mount-image v1.2.0
* A simple function for mounting image
* (c) 2021-2023 saqqdy<https://github.com/saqqdy>
* Released under the MIT License.
*/
function e(e,o){if(void 0===o&&(o={}),!e)throw new Error("[mountImage]: url is required");var r=o.attrs,n=o.props,t=o.force,a=void 0!==t&&t;return new Promise((function(o,t){if(a||!document.querySelector('img[src="'.concat(e,'"]'))){var d,i,c=document.createElement("img");if(r)for(d in r)c[d]=r[d];if(n)for(i in n)c[i]=n[i];c.src=e,document.body.appendChild(c),c.onload=c.onreadystatechange=function(){c.readyState&&!["loaded","complete"].includes(c.readyState)||(c.onload=c.onreadystatechange=null,o(!0))},c.onerror=t}else o(!0)}))}export{e as default};