UNPKG

ant-design-x-vue

Version:

Craft AI-driven interfaces effortlessly

2 lines (1 loc) 1 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=t=>t.indexOf("image/")===0,a=200;function p(t){return new Promise(i=>{if(!t||!t.type||!d(t.type)){i("");return}const n=new Image;if(n.onload=()=>{const{width:e,height:g}=n,o=e/g,r=o>1?a:a*o,c=o>1?a/o:a,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),i(m)},n.crossOrigin="anonymous",t.type.startsWith("image/svg+xml")){const e=new FileReader;e.onload=()=>{e.result&&typeof e.result=="string"&&(n.src=e.result)},e.readAsDataURL(t)}else if(t.type.startsWith("image/gif")){const e=new FileReader;e.onload=()=>{e.result&&i(e.result)},e.readAsDataURL(t)}else n.src=window.URL.createObjectURL(t)})}exports.isImageFileType=d;exports.previewImage=p;