@artmate/chat
Version:
**开箱即用的AI组件库(基于 Vue3 + ElementPlus)**
2 lines (1 loc) • 1.07 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(t){return t.indexOf("image/")===0}const r=200;function u(t){return new Promise(i=>{if(!t||!t.type||!g(t.type)){i("");return}const n=new Image;if(n.addEventListener("load",()=>{const{width:e,height:m}=n,a=e/m,o=a>1?r:r*a,d=a>1?r/a:r,s=document.createElement("canvas");s.width=o,s.height=d,s.style.cssText=`position: fixed; left: 0; top: 0; width: ${o}px; height: ${d}px; z-index: 9999; display: none;`,document.body.append(s);const c=s.getContext("2d");c==null||c.drawImage(n,0,0,o,d);const p=s.toDataURL();s.remove(),window.URL.revokeObjectURL(n.src),i(p)}),n.crossOrigin="anonymous",t.type.startsWith("image/svg+xml")){const e=new FileReader;e.addEventListener("load",()=>{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.addEventListener("load",()=>{e.result&&i(e.result)}),e.readAsDataURL(t)}else n.src=window.URL.createObjectURL(t)})}exports.isImageFileType=g;exports.previewImage=u;