chat/assets/index-B9fWrEk-.js
2025-06-19 22:14:16 +02:00

1 line
6 KiB
JavaScript

var C={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},H=/([astvzqmhlc])([^astvzqmhlc]*)/gi,N=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function V(n){const s=n.match(N);return s?s.map(Number):[]}function F(n){const s=[],e=String(n).trim();return e[0]!=="M"&&e[0]!=="m"||e.replace(H,(a,r,c)=>{const i=V(c);let o=r.toLowerCase(),u=r;if(o==="m"&&i.length>2&&(s.push([u,...i.splice(0,2)]),o="l",u=u==="m"?"l":"L"),i.length<C[o])return"";for(s.push([u,...i.splice(0,C[o])]);i.length>=C[o]&&i.length&&C[o];)s.push([u,...i.splice(0,C[o])]);return""}),s}function Z(n,s){const e=n.x*Math.cos(s)-n.y*Math.sin(s),a=n.y*Math.cos(s)+n.x*Math.sin(s);n.x=e,n.y=a}function j(n,s,e){n.x+=s,n.y+=e}function B(n,s){n.x*=s,n.y*=s}var E=class L{constructor(s){this.commands=[],s&&s instanceof L?this.commands.push(...s.commands):s&&(this.commands=F(s))}addPath(s){s&&s instanceof L&&this.commands.push(...s.commands)}moveTo(s,e){this.commands.push(["M",s,e])}lineTo(s,e){this.commands.push(["L",s,e])}arc(s,e,a,r,c,i){this.commands.push(["AC",s,e,a,r,c,!!i])}arcTo(s,e,a,r,c){this.commands.push(["AT",s,e,a,r,c])}ellipse(s,e,a,r,c,i,o,u){this.commands.push(["E",s,e,a,r,c,i,o,!!u])}closePath(){this.commands.push(["Z"])}bezierCurveTo(s,e,a,r,c,i){this.commands.push(["C",s,e,a,r,c,i])}quadraticCurveTo(s,e,a,r){this.commands.push(["Q",s,e,a,r])}rect(s,e,a,r){this.commands.push(["R",s,e,a,r])}roundRect(s,e,a,r,c){typeof c>"u"?this.commands.push(["RR",s,e,a,r,0]):this.commands.push(["RR",s,e,a,r,c])}};function P(n,s){let e=0,a=0,r,c,i,o,u,h,v,M,$,g,D,Q,z,p,m,q,w,f,b,A,S,T=null,x=null,d=null,y=null,k=null,R=null;n.beginPath();for(let l=0;l<s.length;++l){f=s[l][0],f!=="S"&&f!=="s"&&f!=="C"&&f!=="c"&&(T=null,x=null),f!=="T"&&f!=="t"&&f!=="Q"&&f!=="q"&&(d=null,y=null);let t;switch(f){case"m":case"M":t=s[l],f==="m"?(e+=t[1],a+=t[2]):(e=t[1],a=t[2]),(f==="M"||!k)&&(k={x:e,y:a}),n.moveTo(e,a);break;case"l":t=s[l],e+=t[1],a+=t[2],n.lineTo(e,a);break;case"L":t=s[l],e=t[1],a=t[2],n.lineTo(e,a);break;case"H":t=s[l],e=t[1],n.lineTo(e,a);break;case"h":t=s[l],e+=t[1],n.lineTo(e,a);break;case"V":t=s[l],a=t[1],n.lineTo(e,a);break;case"v":t=s[l],a+=t[1],n.lineTo(e,a);break;case"a":case"A":if(t=s[l],R===null)throw new Error("This should never happen");f==="a"?(e+=t[6],a+=t[7]):(e=t[6],a=t[7]),p=t[1],m=t[2],v=t[3]*Math.PI/180,i=!!t[4],o=!!t[5],u={x:e,y:a},h={x:(R.x-u.x)/2,y:(R.y-u.y)/2},Z(h,-v),M=h.x*h.x/(p*p)+h.y*h.y/(m*m),M>1&&(M=Math.sqrt(M),p*=M,m*=M),b={x:p*h.y/m,y:-(m*h.x)/p},$=p*p*m*m,g=p*p*h.y*h.y+m*m*h.x*h.x,o!==i?B(b,Math.sqrt(($-g)/g)||0):B(b,-Math.sqrt(($-g)/g)||0),c=Math.atan2((h.y-b.y)/m,(h.x-b.x)/p),r=Math.atan2(-(h.y+b.y)/m,-(h.x+b.x)/p),Z(b,v),j(b,(u.x+R.x)/2,(u.y+R.y)/2),n.save(),n.translate(b.x,b.y),n.rotate(v),n.scale(p,m),n.arc(0,0,1,c,r,!o),n.restore();break;case"C":t=s[l],T=t[3],x=t[4],e=t[5],a=t[6],n.bezierCurveTo(t[1],t[2],T,x,e,a);break;case"c":t=s[l],n.bezierCurveTo(t[1]+e,t[2]+a,t[3]+e,t[4]+a,t[5]+e,t[6]+a),T=t[3]+e,x=t[4]+a,e+=t[5],a+=t[6];break;case"S":t=s[l],(T===null||x===null)&&(T=e,x=a),n.bezierCurveTo(2*e-T,2*a-x,t[1],t[2],t[3],t[4]),T=t[1],x=t[2],e=t[3],a=t[4];break;case"s":t=s[l],(T===null||x===null)&&(T=e,x=a),n.bezierCurveTo(2*e-T,2*a-x,t[1]+e,t[2]+a,t[3]+e,t[4]+a),T=t[1]+e,x=t[2]+a,e+=t[3],a+=t[4];break;case"Q":t=s[l],d=t[1],y=t[2],e=t[3],a=t[4],n.quadraticCurveTo(d,y,e,a);break;case"q":t=s[l],d=t[1]+e,y=t[2]+a,e+=t[3],a+=t[4],n.quadraticCurveTo(d,y,e,a);break;case"T":t=s[l],(d===null||y===null)&&(d=e,y=a),d=2*e-d,y=2*a-y,e=t[1],a=t[2],n.quadraticCurveTo(d,y,e,a);break;case"t":t=s[l],(d===null||y===null)&&(d=e,y=a),d=2*e-d,y=2*a-y,e+=t[1],a+=t[2],n.quadraticCurveTo(d,y,e,a);break;case"z":case"Z":k&&(e=k.x,a=k.y),k=null,n.closePath();break;case"AC":t=s[l],e=t[1],a=t[2],z=t[3],c=t[4],r=t[5],A=t[6],n.arc(e,a,z,c,r,A);break;case"AT":t=s[l],D=t[1],Q=t[2],e=t[3],a=t[4],z=t[5],n.arcTo(D,Q,e,a,z);break;case"E":t=s[l],e=t[1],a=t[2],p=t[3],m=t[4],v=t[5],c=t[6],r=t[7],A=t[8],n.save(),n.translate(e,a),n.rotate(v),n.scale(p,m),n.arc(0,0,1,c,r,A),n.restore();break;case"R":t=s[l],e=t[1],a=t[2],q=t[3],w=t[4],k={x:e,y:a},n.rect(e,a,q,w);break;case"RR":t=s[l],e=t[1],a=t[2],q=t[3],w=t[4],S=t[5],k={x:e,y:a},n.roundRect(e,a,q,w,S);break;default:throw new Error(`Invalid path command: ${f}`)}R?(R.x=e,R.y=a):R={x:e,y:a}}}function I(n,s,e,a,r=0){if(typeof r=="number"&&(r=[r]),Array.isArray(r)){if(r.length===0||r.length>4)throw new RangeError(`Failed to execute 'roundRect' on '${this.constructor.name}': ${r.length} radii provided. Between one and four radii are necessary.`);r.forEach(v=>{if(v<0)throw new RangeError(`Failed to execute 'roundRect' on '${this.constructor.name}': Radius value ${v} is negative.`)})}else return;if(r.length===1&&r[0]===0){this.rect(n,s,e,a);return}const c=Math.min(e,a)/2,i=Math.min(c,r[0]);let o=i,u=i,h=i;r.length===2&&(o=Math.min(c,r[1]),h=o),r.length===3&&(o=Math.min(c,r[1]),h=o,u=Math.min(c,r[2])),r.length===4&&(o=Math.min(c,r[1]),u=Math.min(c,r[2]),h=Math.min(c,r[3])),this.moveTo(n,s+a-h),this.arcTo(n,s,n+i,s,i),this.arcTo(n+e,s,n+e,s+o,o),this.arcTo(n+e,s+a,n+e-u,s+a,u),this.arcTo(n,s+a,n,s+a-h,h),this.closePath()}function G(n){if(!n)return;const s=n.prototype.clip,e=n.prototype.fill,a=n.prototype.stroke,r=n.prototype.isPointInPath;n.prototype.clip=function(...c){if(c[0]instanceof E){const o=c[0],u=c[1]||"nonzero";return P(this,o.commands),s.apply(this,[u])}const i=c[0]||"nonzero";return s.apply(this,[i])},n.prototype.fill=function(...c){if(c[0]instanceof E){const o=c[0],u=c[1]||"nonzero";return P(this,o.commands),e.apply(this,[u])}const i=c[0]||"nonzero";return e.apply(this,[i])},n.prototype.stroke=function(c){c&&P(this,c.commands),a.apply(this)},n.prototype.isPointInPath=function(...c){if(c[0]instanceof E){const i=c[0],o=c[1],u=c[2],h=c[3]||"nonzero";return P(this,i.commands),r.apply(this,[o,u,h])}return r.apply(this,c)}}function J(n){n&&!n.prototype.roundRect&&(n.prototype.roundRect=I)}function K(n){n&&!n.prototype.roundRect&&(n.prototype.roundRect=I)}export{E as Path2D,G as applyPath2DToCanvasRenderingContext,J as applyRoundRectToCanvasRenderingContext2D,K as applyRoundRectToPath2D,P as buildPath,F as parsePath,I as roundRect};