ant-design-x-vue
Version:
Craft AI-driven interfaces effortlessly
2 lines (1 loc) • 1.08 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=e=>e.indexOf("image/")===0,i=200;function u(e){return new Promise(a=>{if(!e||!e.type||!d(e.type)){a("");return}const n=new Image;if(n.onload=()=>{const{width:t,height:g}=n,o=t/g,r=o>1?i:i*o,c=o>1?i/o:i,s=document.createElement("canvas");s.width=r,s.height=c,s.style.cssText=`position: fixed; left: 0; top: 0; width: ${r}px; height: ${c}px; z-index: 9999; display: none;`,document.body.appendChild(s),s.getContext("2d").drawImage(n,0,0,r,c);const m=s.toDataURL();document.body.removeChild(s),window.URL.revokeObjectURL(n.src),a(m)},n.crossOrigin="anonymous",e.type.startsWith("image/svg+xml")){const t=new FileReader;t.onload=()=>{t.result&&typeof t.result=="string"&&(n.src=t.result)},t.readAsDataURL(e)}else if(e.type.startsWith("image/gif")){const t=new FileReader;t.onload=()=>{t.result&&a(t.result)},t.readAsDataURL(e)}else n.src=window.URL.createObjectURL(e)})}function p(e,a){return a.has(e.substring(1).toLowerCase())}exports.isImageFileType=d;exports.matchExt=p;exports.previewImage=u;