UNPKG

@krisdages/d3-path

Version:

Serialize Canvas path commands to SVG.

4 lines (3 loc) 2.05 kB
// https://d3js.org/d3-path/ v3.0.1 Copyright 2015-2021 Mike Bostock "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=Math.PI,i=2*t,s=i-1e-6;function h(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function _(){return new h}h.prototype=_.prototype={constructor:h,moveTo:function(t,i){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+i)},closePath:function(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(t,i){this._+="L"+(this._x1=+t)+","+(this._y1=+i)},quadraticCurveTo:function(t,i,s,h){this._+="Q"+ +t+","+ +i+","+(this._x1=+s)+","+(this._y1=+h)},bezierCurveTo:function(t,i,s,h,_,e){this._+="C"+ +t+","+ +i+","+ +s+","+ +h+","+(this._x1=+_)+","+(this._y1=+e)},arcTo:function(i,s,h,_,e){i=+i,s=+s,h=+h,_=+_,e=+e;var n=this._x1,o=this._y1,r=h-i,a=_-s,u=n-i,c=o-s,x=u*u+c*c;if(e<0)throw new Error("negative radius: "+e);if(null===this._x1)this._+="M"+(this._x1=i)+","+(this._y1=s);else if(x>1e-6)if(Math.abs(c*r-a*u)>1e-6&&e){var y=h-n,M=_-o,f=r*r+a*a,l=y*y+M*M,v=Math.sqrt(f),p=Math.sqrt(x),b=e*Math.tan((t-Math.acos((f+x-l)/(2*v*p)))/2),d=b/p,w=b/v;Math.abs(d-1)>1e-6&&(this._+="L"+(i+d*u)+","+(s+d*c)),this._+="A"+e+","+e+",0,0,"+ +(c*y>u*M)+","+(this._x1=i+w*r)+","+(this._y1=s+w*a)}else this._+="L"+(this._x1=i)+","+(this._y1=s);else;},arc:function(h,_,e,n,o,r){h=+h,_=+_,r=!!r;var a=(e=+e)*Math.cos(n),u=e*Math.sin(n),c=h+a,x=_+u,y=1^r,M=r?n-o:o-n;if(e<0)throw new Error("negative radius: "+e);null===this._x1?this._+="M"+c+","+x:(Math.abs(this._x1-c)>1e-6||Math.abs(this._y1-x)>1e-6)&&(this._+="L"+c+","+x),e&&(M<0&&(M=M%i+i),M>s?this._+="A"+e+","+e+",0,1,"+y+","+(h-a)+","+(_-u)+"A"+e+","+e+",0,1,"+y+","+(this._x1=c)+","+(this._y1=x):M>1e-6&&(this._+="A"+e+","+e+",0,"+ +(M>=t)+","+y+","+(this._x1=h+e*Math.cos(o))+","+(this._y1=_+e*Math.sin(o))))},rect:function(t,i,s,h){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+i)+"h"+ +s+"v"+ +h+"h"+-s+"Z"},toString:function(){return this._}},exports.path=_; //# sourceMappingURL=d3-path.min.cjs.map