You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
1021 B

import{ak as P}from"./index-f4658ae7.js";const W=({canvas:e,logo:o})=>{if(!o)return new Promise(g=>{g(e.toDataURL())});const t=e.width,{logoSize:i=.15,bgColor:c="#ffffff",borderSize:r=.05,crossOrigin:f,borderRadius:b=8,logoRadius:m=0}=o,C=P(o)?o:o.src,a=t*i,s=t*(1-i)/2,u=t*(i+r),h=t*(1-i-r)/2,n=e.getContext("2d");if(!n)return;R(n)(h,h,u,u,b),n.fillStyle=c,n.fill();const l=new Image;(f||m)&&l.setAttribute("crossOrigin",f||"anonymous"),l.src=C;const I=g=>{n.drawImage(g,s,s,a,a)},L=g=>{const d=document.createElement("canvas");d.width=s+a,d.height=s+a;const S=d.getContext("2d");if(!S||!n||(S.drawImage(g,s,s,a,a),R(n)(s,s,a,a,m),!n))return;const w=n.createPattern(d,"no-repeat");w&&(n.fillStyle=w,n.fill())};return new Promise(g=>{l.onload=()=>{m?L(l):I(l),g(e.toDataURL())}})};function R(e){return(o,t,i,c,r)=>{const f=Math.min(i,c);return r>f/2&&(r=f/2),e.beginPath(),e.moveTo(o+r,t),e.arcTo(o+i,t,o+i,t+c,r),e.arcTo(o+i,t+c,o,t+c,r),e.arcTo(o,t+c,o,t,r),e.arcTo(o,t,o+i,t,r),e.closePath(),e}}export{W as drawLogo};