1 line
2.8 KiB
JavaScript
1 line
2.8 KiB
JavaScript
(()=>{Path2D.prototype.roundRect??=e,globalThis.CanvasRenderingContext2D&&(globalThis.CanvasRenderingContext2D.prototype.roundRect??=e),globalThis.OffscreenCanvasRenderingContext2D&&(globalThis.OffscreenCanvasRenderingContext2D.prototype.roundRect??=e);function e(e,n,r,i,a){if(![e,n,r,i].every(e=>Number.isFinite(e)))return;a=p(a);let o,s,c,l;if(a.length===4)o=h(a[0]),s=h(a[1]),c=h(a[2]),l=h(a[3]);else if(a.length===3)o=h(a[0]),s=h(a[1]),l=h(a[1]),c=h(a[2]);else if(a.length===2)o=h(a[0]),c=h(a[0]),s=h(a[1]),l=h(a[1]);else if(a.length===1)o=h(a[0]),s=h(a[0]),c=h(a[0]),l=h(a[0]);else throw RangeError(`${t(this)} ${a.length} is not a valid size for radii sequence.`);let u=[o,s,c,l],d=u.find(({x:e,y:t})=>e<0||t<0);if(d?.x<0?d.x:d?.y,u.some(({x:e,y:t})=>!Number.isFinite(e)||!Number.isFinite(t)))return;if(d)throw RangeError(`${t(this)} Radius value ${d} is negative.`);g(u),r<0&&i<0?(this.moveTo(e-o.x,n),this.ellipse(e+r+s.x,n-s.y,s.x,s.y,0,-Math.PI*1.5,-Math.PI),this.ellipse(e+r+c.x,n+i+c.y,c.x,c.y,0,-Math.PI,-Math.PI/2),this.ellipse(e-l.x,n+i+l.y,l.x,l.y,0,-Math.PI/2,0),this.ellipse(e-o.x,n-o.y,o.x,o.y,0,0,-Math.PI/2)):r<0?(this.moveTo(e-o.x,n),this.ellipse(e+r+s.x,n+s.y,s.x,s.y,0,-Math.PI/2,-Math.PI,1),this.ellipse(e+r+c.x,n+i-c.y,c.x,c.y,0,-Math.PI,-Math.PI*1.5,1),this.ellipse(e-l.x,n+i-l.y,l.x,l.y,0,Math.PI/2,0,1),this.ellipse(e-o.x,n+o.y,o.x,o.y,0,0,-Math.PI/2,1)):i<0?(this.moveTo(e+o.x,n),this.ellipse(e+r-s.x,n-s.y,s.x,s.y,0,Math.PI/2,0,1),this.ellipse(e+r-c.x,n+i+c.y,c.x,c.y,0,0,-Math.PI/2,1),this.ellipse(e+l.x,n+i+l.y,l.x,l.y,0,-Math.PI/2,-Math.PI,1),this.ellipse(e+o.x,n-o.y,o.x,o.y,0,-Math.PI,-Math.PI*1.5,1)):(this.moveTo(e+o.x,n),this.ellipse(e+r-s.x,n+s.y,s.x,s.y,0,-Math.PI/2,0),this.ellipse(e+r-c.x,n+i-c.y,c.x,c.y,0,0,Math.PI/2),this.ellipse(e+l.x,n+i-l.y,l.x,l.y,0,Math.PI/2,Math.PI),this.ellipse(e+o.x,n+o.y,o.x,o.y,0,Math.PI,Math.PI*1.5)),this.closePath(),this.moveTo(e,n);function f(e){let{x:t,y:n,z:r,w:i}=e;return{x:t,y:n,z:r,w:i}}function p(e){let t=typeof e;return t===`undefined`||e===null?[0]:t===`function`?[NaN]:t===`object`?typeof e[Symbol.iterator]==`function`?[...e].map(e=>{let t=typeof e;return t===`undefined`||e===null?0:t===`function`?NaN:t===`object`?f(e):m(e)}):[f(e)]:[m(e)]}function m(e){return+e}function h(e){let t=m(e);return Number.isFinite(t)?{x:t,y:t}:Object(e)===e?{x:m(e.x??0),y:m(e.y??0)}:{x:NaN,y:NaN}}function g(e){let[t,n,a,o]=e,s=[Math.abs(r)/(t.x+n.x),Math.abs(i)/(n.y+a.y),Math.abs(r)/(a.x+o.x),Math.abs(i)/(t.y+o.y)],c=Math.min(...s);if(c<=1)for(let t of e)t.x*=c,t.y*=c}}function t(e){return`Failed to execute 'roundRect' on '${n(e)}':`}function n(e){return Object(e)===e&&e instanceof Path2D?`Path2D`:e instanceof globalThis?.CanvasRenderingContext2D?`CanvasRenderingContext2D`:e instanceof globalThis?.OffscreenCanvasRenderingContext2D?`OffscreenCanvasRenderingContext2D`:e?.constructor.name||e}})(); |