openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 1.39 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{na as t}from"./_4____________________________.js";function n(e,t,n){return new Promise(r=>{e.toBlob(r,t,n)})}async function r(e){if(![`image/png`,`image/jpeg`,`image/webp`].includes(e.type))throw new s(`invalid-image`);if(e.size>o)throw new s(`source-too-large`);let r=URL.createObjectURL(e),c;try{c=new Image,c.decoding=`async`,c.src=r,await c.decode()}catch{throw new s(`invalid-image`)}finally{URL.revokeObjectURL(r)}let{naturalWidth:l,naturalHeight:u}=c;if(!Number.isFinite(l)||!Number.isFinite(u)||l<=0||u<=0)throw new s(`invalid-image`);let d=Math.min(l,u),f=Math.min(1,i/d),p=Math.max(1,Math.round(d*f)),m=document.createElement(`canvas`);m.width=p,m.height=p;let h=m.getContext(`2d`);if(!h)throw new s(`invalid-image`);h.drawImage(c,Math.max(0,Math.round((l-d)/2)),Math.max(0,Math.round((u-d)/2)),d,d,0,0,p,p);let g=e.type===`image/webp`?`image/webp`:`image/png`,_=await n(m,g,g===`image/webp`?.9:void 0);if((!_||_.type!==g||_.size>a)&&(g=`image/webp`,_=await n(m,g,.82)),!_||_.type!==g)throw new s(`invalid-image`);if(_.size>a)throw new s(`too-large`);let v=new Uint8Array(await _.arrayBuffer());return{mime:g,avatarBase64:t(v)}}var i,a,o,s;function c(){return(c=e((()=>{i=512,a=524288,o=10485760,s=class extends Error{constructor(e){super(e),this.code=e,this.name=`ProfileAvatarError`}}})))()}export{c as n,r,s as t};