Files
rough/dist/rough.es5.min.js
2018-07-13 20:12:29 -07:00

2 lines
44 KiB
JavaScript

var rough=function(){"use strict";function e(e,t){return e.type===t}function t(e){var t=e[0],l=e[1];return y(f(t[0]-l[0],2)+f(t[1]-l[1],2))}function l(e,t){for(var l,a=[],n=new z([e[0],e[1]],[e[2],e[3]]),s=0;s<t.length;s++)l=new z(t[s],t[(s+1)%t.length]),n.intersects(l)&&a.push([n.xi,n.yi]);return a}function a(e,t,l,a,n,i,s){return[-l*i-a*n+l+i*e+n*t,s*(l*n-a*i)+a+-s*n*e+s*i*t]}function n(e,t){var a=[];if(e&&e.length){for(var n=e[0][0],s=e[0][0],o=e[0][1],r=e[0][1],f=1;f<e.length;f++)n=u(n,e[f][0]),s=d(s,e[f][0]),o=u(o,e[f][1]),r=d(r,e[f][1]);var h=t.hachureAngle,g=t.hachureGap;0>g&&(g=4*t.strokeWidth),g=d(g,.1);for(var y=h%180*(c/180),k=v(y),x=_(y),b=p(y),O=new E(o-1,r+1,n-1,s+1,g,x,k,b),m=void 0;null!=(m=O.nextLine());)for(var P=l(m,e),w=0;w<P.length;w++)if(w<P.length-1){var S=P[w],A=P[w+1];a.push([S,A])}}return a}function i(e,t,l,n,i,s){var o=[],r=k(l/2),d=k(n/2);r+=s.getOffset(.05*-r,.05*r,i),d+=s.getOffset(.05*-d,.05*d,i);var u=i.hachureAngle,f=i.hachureGap;0>=f&&(f=4*i.strokeWidth);var h=i.fillWeight;0>h&&(h=i.strokeWidth/2);for(var g=p(u%180*(c/180)),v=d/r,_=y(v*g*v*g+1),x=v*g/_,b=1/_,O=f/(r*d/y(d*b*(d*b)+r*x*(r*x))/r),m=y(r*r-(e-r+O)*(e-r+O)),P=e-r+O;P<e+r;P+=O){m=y(r*r-(e-P)*(e-P));var w=a(P,t-m,e,t,x,b,v),S=a(P,t+m,e,t,x,b,v);o.push([w,S])}return o}function s(e,t){var l=t.fillStyle||"hachure";if(!R[l])switch(l){case"zigzag":R[l]||(R[l]=new W(e));break;case"cross-hatch":R[l]||(R[l]=new N(e));break;case"dots":R[l]||(R[l]=new D(e));break;case"hachure":default:l="hachure",R[l]||(R[l]=new L(e));}return R[l]}function o(e){if(F&&M&&self&&self.workly&&e.async&&!e.noWorker){var t=e.worklyURL||"https://cdn.jsdelivr.net/gh/pshihn/workly/dist/workly.min.js";if(t){var l=URL.createObjectURL(new Blob(["importScripts('"+t+"', '"+M+"');\nworkly.expose(self.rough.createRenderer());"]));return self.workly.proxy(l)}}return new B}var r=Math.round,p=Math.tan,d=Math.max,u=Math.min,f=Math.pow,h=Math.floor,g=Math.ceil,y=Math.sqrt,v=Math.cos,_=Math.sin,k=Math.abs,c=Math.PI,x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},b=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},O=function(){function e(e,t){for(var l,a=0;a<t.length;a++)l=t[a],l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(e,l.key,l)}return function(t,l,a){return l&&e(t.prototype,l),a&&e(t,a),t}}(),m=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},P=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t&&("object"==typeof t||"function"==typeof t)?t:e},w={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:4,t:2,V:1,v:1,Z:0,z:0},S=function(){function t(e){b(this,t),this.COMMAND=0,this.NUMBER=1,this.EOD=2,this.segments=[],this.parseData(e),this.processPoints()}return O(t,[{key:"tokenize",value:function(e){for(var t=[];""!==e;)if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([aAcChHlLmMqQsStTvVzZ])/))t[t.length]={type:this.COMMAND,text:RegExp.$1},e=e.substr(RegExp.$1.length);else if(e.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))t[t.length]={type:this.NUMBER,text:""+parseFloat(RegExp.$1)},e=e.substr(RegExp.$1.length);else return console.error("Unrecognized segment command: "+e),[];return t[t.length]={type:this.EOD,text:""},t}},{key:"parseData",value:function(t){var l=this.tokenize(t),a=0,n=l[a],s="BOD";for(this.segments=[];!e(n,this.EOD);){var o=void 0,r=[];if("BOD"!==s)e(n,this.NUMBER)?o=w[s]:(a++,o=w[n.text],s=n.text);else if("M"===n.text||"m"===n.text)a++,o=w[n.text],s=n.text;else return void this.parseData("M0,0"+t);if(a+o<l.length){for(var p,d=a;d<a+o;d++)if(p=l[d],e(p,this.NUMBER))r[r.length]=+p.text;else return void console.error("Parameter type is not a number: "+s+","+p.text);if("number"==typeof w[s]){var u={key:s,data:r};this.segments.push(u),a+=o,n=l[a],"M"===s&&(s="L"),"m"===s&&(s="l")}else return void console.error("Unsupported segment type: "+s)}else console.error("Path data ended before all parameters were found")}}},{key:"processPoints",value:function(){for(var e,t=null,l=[0,0],a=0;a<this.segments.length;a++){switch(e=this.segments[a],e.key){case"M":case"L":case"T":e.point=[e.data[0],e.data[1]];break;case"m":case"l":case"t":e.point=[e.data[0]+l[0],e.data[1]+l[1]];break;case"H":e.point=[e.data[0],l[1]];break;case"h":e.point=[e.data[0]+l[0],l[1]];break;case"V":e.point=[l[0],e.data[0]];break;case"v":e.point=[l[0],e.data[0]+l[1]];break;case"z":case"Z":t&&(e.point=[t[0],t[1]]);break;case"C":e.point=[e.data[4],e.data[5]];break;case"c":e.point=[e.data[4]+l[0],e.data[5]+l[1]];break;case"S":e.point=[e.data[2],e.data[3]];break;case"s":e.point=[e.data[2]+l[0],e.data[3]+l[1]];break;case"Q":e.point=[e.data[2],e.data[3]];break;case"q":e.point=[e.data[2]+l[0],e.data[3]+l[1]];break;case"A":e.point=[e.data[5],e.data[6]];break;case"a":e.point=[e.data[5]+l[0],e.data[6]+l[1]];}("m"===e.key||"M"===e.key)&&(t=null),e.point&&(l=e.point,!t&&(t=e.point)),("z"===e.key||"Z"===e.key)&&(t=null)}}},{key:"closed",get:function(){if("undefined"==typeof this._closed){this._closed=!1;var e=!0,t=!1,l=void 0;try{for(var a,n,i=this.segments[Symbol.iterator]();!(e=(a=i.next()).done);e=!0)n=a.value,"z"===n.key.toLowerCase()&&(this._closed=!0)}catch(e){t=!0,l=e}finally{try{!e&&i.return&&i.return()}finally{if(t)throw l}}}return this._closed}}]),t}(),A=function(){function e(t){b(this,e),this._position=[0,0],this._first=null,this.bezierReflectionPoint=null,this.quadReflectionPoint=null,this.parsed=new S(t)}return O(e,[{key:"setPosition",value:function(e,t){this._position=[e,t],this._first||(this._first=[e,t])}},{key:"segments",get:function(){return this.parsed.segments}},{key:"closed",get:function(){return this.parsed.closed}},{key:"linearPoints",get:function(){if(!this._linearPoints){var e=[],t=[],l=!0,a=!1,n=void 0;try{for(var i,o=this.parsed.segments[Symbol.iterator]();!(l=(i=o.next()).done);l=!0){var r=i.value,s=r.key.toLowerCase();("m"===s||"z"===s)&&(t.length&&(e.push(t),t=[]),"z"===s)||r.point&&t.push(r.point)}}catch(e){a=!0,n=e}finally{try{!l&&o.return&&o.return()}finally{if(a)throw n}}t.length&&(e.push(t),t=[]),this._linearPoints=e}return this._linearPoints}},{key:"first",get:function(){return this._first},set:function(e){this._first=e}},{key:"position",get:function(){return this._position}},{key:"x",get:function(){return this._position[0]}},{key:"y",get:function(){return this._position[1]}}]),e}(),T=function(){function e(t,l,a,n,i,o){if(b(this,e),this._segIndex=0,this._numSegs=0,this._rx=0,this._ry=0,this._sinPhi=0,this._cosPhi=0,this._C=[0,0],this._theta=0,this._delta=0,this._T=0,this._from=t,t[0]!==l[0]||t[1]!==l[1]){var r=c/180;this._rx=k(a[0]),this._ry=k(a[1]),this._sinPhi=_(n*r),this._cosPhi=v(n*r);var p=this._cosPhi*(t[0]-l[0])/2+this._sinPhi*(t[1]-l[1])/2,d=-this._sinPhi*(t[0]-l[0])/2+this._cosPhi*(t[1]-l[1])/2,u=0,f=this._rx*this._rx*this._ry*this._ry-this._rx*this._rx*d*d-this._ry*this._ry*p*p;if(0>f){var h=y(1-f/(this._rx*this._rx*this._ry*this._ry));this._rx*=h,this._ry*=h,u=0}else u=(i===o?-1:1)*y(f/(this._rx*this._rx*d*d+this._ry*this._ry*p*p));var s=u*this._rx*d/this._ry,x=-u*this._ry*p/this._rx;this._C=[0,0],this._C[0]=this._cosPhi*s-this._sinPhi*x+(t[0]+l[0])/2,this._C[1]=this._sinPhi*s+this._cosPhi*x+(t[1]+l[1])/2,this._theta=this.calculateVectorAngle(1,0,(p-s)/this._rx,(d-x)/this._ry);var O=this.calculateVectorAngle((p-s)/this._rx,(d-x)/this._ry,(-p-s)/this._rx,(-d-x)/this._ry);!o&&0<O?O-=2*c:o&&0>O&&(O+=2*c),this._numSegs=g(k(O/(c/2))),this._delta=O/this._numSegs,this._T=8/3*_(this._delta/4)*_(this._delta/4)/_(this._delta/2)}}return O(e,[{key:"getNextSegment",value:function(){if(this._segIndex===this._numSegs)return null;var e=v(this._theta),t=_(this._theta),l=this._theta+this._delta,a=v(l),n=_(l),i=[this._cosPhi*this._rx*a-this._sinPhi*this._ry*n+this._C[0],this._sinPhi*this._rx*a+this._cosPhi*this._ry*n+this._C[1]],s=[this._from[0]+this._T*(-this._cosPhi*this._rx*t-this._sinPhi*this._ry*e),this._from[1]+this._T*(-this._sinPhi*this._rx*t+this._cosPhi*this._ry*e)],o=[i[0]+this._T*(this._cosPhi*this._rx*n+this._sinPhi*this._ry*a),i[1]+this._T*(this._sinPhi*this._rx*n-this._cosPhi*this._ry*a)];return this._theta=l,this._from=[i[0],i[1]],this._segIndex++,{cp1:s,cp2:o,to:i}}},{key:"calculateVectorAngle",value:function(e,t,l,a){var n=Math.atan2,i=n(t,e),s=n(a,l);return s>=i?s-i:2*c-(i-s)}}]),e}(),C=function(){function e(t,l){b(this,e),this.sets=t,this.closed=l}return O(e,[{key:"fit",value:function(e){var t=[],l=!0,a=!1,n=void 0;try{for(var s,o=this.sets[Symbol.iterator]();!(l=(s=o.next()).done);l=!0){var r=s.value,p=r.length,u=h(e*p);if(5>u){if(5>=p)continue;u=5}t.push(this.reduce(r,u))}}catch(e){a=!0,n=e}finally{try{!l&&o.return&&o.return()}finally{if(a)throw n}}var f="",g=!0,y=!1,c=void 0;try{for(var v,_,k=t[Symbol.iterator]();!(g=(v=k.next()).done);g=!0){_=v.value;for(var x,b=0;b<_.length;b++)x=_[b],f+=0===b?"M"+x[0]+","+x[1]:"L"+x[0]+","+x[1];this.closed&&(f+="z ")}}catch(e){y=!0,c=e}finally{try{!g&&k.return&&k.return()}finally{if(y)throw c}}return f}},{key:"distance",value:function(e,t){return y(f(e[0]-t[0],2)+f(e[1]-t[1],2))}},{key:"reduce",value:function(e,t){if(e.length<=t)return e;for(var l=e.slice(0);l.length>t;){for(var n=-1,o=-1,r=1;r<l.length-1;r++){var p=this.distance(l[r-1],l[r]),a=this.distance(l[r],l[r+1]),d=this.distance(l[r-1],l[r+1]),u=(p+a+d)/2,s=y(u*(u-p)*(u-a)*(u-d));(0>n||s<n)&&(n=s,o=r)}if(0<o)l.splice(o,1);else break}return l}}]),e}(),z=function(){function e(l,a){b(this,e),this.xi=t,this.yi=t,this.px1=l[0],this.py1=l[1],this.px2=a[0],this.py2=a[1],this.a=this.py2-this.py1,this.b=this.px1-this.px2,this.c=this.px2*this.py1-this.px1*this.py2,this._undefined=0===this.a&&0===this.b&&0===this.c}var t=Number.MAX_VALUE;return O(e,[{key:"isUndefined",value:function(){return this._undefined}},{key:"intersects",value:function(e){if(this.isUndefined()||e.isUndefined())return!1;var l=t,n=t,i=0,s=0,o=this.a,a=this.b,r=this.c;return(1e-5<k(a)&&(l=-o/a,i=-r/a),1e-5<k(e.b)&&(n=-e.a/e.b,s=-e.c/e.b),l===t)?n===t?-r/o==-e.c/e.a&&(this.py1>=u(e.py1,e.py2)&&this.py1<=d(e.py1,e.py2)?(this.xi=this.px1,this.yi=this.py1,!0):!!(this.py2>=u(e.py1,e.py2)&&this.py2<=d(e.py1,e.py2))&&(this.xi=this.px2,this.yi=this.py2,!0)):(this.xi=this.px1,this.yi=n*this.xi+s,!(-1e-5>(this.py1-this.yi)*(this.yi-this.py2)||-1e-5>(e.py1-this.yi)*(this.yi-e.py2))&&(!(1e-5>k(e.a))||!(-1e-5>(e.px1-this.xi)*(this.xi-e.px2)))):n===t?(this.xi=e.px1,this.yi=l*this.xi+i,!(-1e-5>(e.py1-this.yi)*(this.yi-e.py2)||-1e-5>(this.py1-this.yi)*(this.yi-this.py2))&&(!(1e-5>k(o))||!(-1e-5>(this.px1-this.xi)*(this.xi-this.px2)))):l===n?i==s&&(this.px1>=u(e.px1,e.px2)&&this.px1<=d(e.py1,e.py2)?(this.xi=this.px1,this.yi=this.py1,!0):!!(this.px2>=u(e.px1,e.px2)&&this.px2<=d(e.px1,e.px2))&&(this.xi=this.px2,this.yi=this.py2,!0)):(this.xi=(s-i)/(l-n),this.yi=l*this.xi+i,!(-1e-5>(this.px1-this.xi)*(this.xi-this.px2)||-1e-5>(e.px1-this.xi)*(this.xi-e.px2)))}}]),e}(),E=function(){function e(t,l,a,n,i,s,o,r){b(this,e),this.deltaX=0,this.hGap=0,this.top=t,this.bottom=l,this.left=a,this.right=n,this.gap=i,this.sinAngle=s,this.tanAngle=r,1e-4>k(s)?this.pos=a+i:.9999<k(s)?this.pos=t+i:(this.deltaX=(l-t)*k(r),this.pos=a-k(this.deltaX),this.hGap=k(i/o),this.sLeft=new z([a,l],[a,t]),this.sRight=new z([n,l],[n,t]))}return O(e,[{key:"nextLine",value:function(){if(1e-4>k(this.sinAngle)){if(this.pos<this.right){var e=[this.pos,this.top,this.pos,this.bottom];return this.pos+=this.gap,e}}else if(!(.9999<k(this.sinAngle))){var t=this.pos-this.deltaX/2,l=this.pos+this.deltaX/2,a=this.bottom,n=this.top;if(this.pos<this.right+this.deltaX){for(;t<this.left&&l<this.left||t>this.right&&l>this.right;)if(this.pos+=this.hGap,t=this.pos-this.deltaX/2,l=this.pos+this.deltaX/2,this.pos>this.right+this.deltaX)return null;var i=new z([t,a],[l,n]);this.sLeft&&i.intersects(this.sLeft)&&(t=i.xi,a=i.yi),this.sRight&&i.intersects(this.sRight)&&(l=i.xi,n=i.yi),0<this.tanAngle&&(t=this.right-(t-this.left),l=this.right-(l-this.left));var s=[t,a,l,n];return this.pos+=this.hGap,s}}else if(this.pos<this.bottom){var o=[this.left,this.pos,this.right,this.pos];return this.pos+=this.gap,o}return null}}]),e}(),L=function(){function e(t){b(this,e),this.renderer=t}return O(e,[{key:"fillPolygon",value:function(e,t){return this._fillPolygon(e,t)}},{key:"fillEllipse",value:function(e,t,l,a,n){return this._fillEllipse(e,t,l,a,n)}},{key:"_fillPolygon",value:function(e,t){var l=!!(2<arguments.length&&void 0!==arguments[2])&&arguments[2],a=n(e,t),i=this.renderLines(a,t,l);return{type:"fillSketch",ops:i}}},{key:"_fillEllipse",value:function(e,t,l,a,n){var s=!!(5<arguments.length&&void 0!==arguments[5])&&arguments[5],o=i(e,t,l,a,n,this.renderer),r=this.renderLines(o,n,s);return{type:"fillSketch",ops:r}}},{key:"renderLines",value:function(e,t,l){var a=[],n=null,i=!0,s=!1,o=void 0;try{for(var r,p,d=e[Symbol.iterator]();!(i=(r=d.next()).done);i=!0)p=r.value,a=a.concat(this.renderer.doubleLine(p[0][0],p[0][1],p[1][0],p[1][1],t)),l&&n&&(a=a.concat(this.renderer.doubleLine(n[0],n[1],p[0][0],p[0][1],t))),n=p[1]}catch(e){s=!0,o=e}finally{try{!i&&d.return&&d.return()}finally{if(s)throw o}}return a}}]),e}(),W=function(e){function t(){return b(this,t),P(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return m(t,e),O(t,[{key:"fillPolygon",value:function(e,t){return this._fillPolygon(e,t,!0)}},{key:"fillEllipse",value:function(e,t,l,a,n){return this._fillEllipse(e,t,l,a,n,!0)}}]),t}(L),N=function(e){function t(){return b(this,t),P(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return m(t,e),O(t,[{key:"fillPolygon",value:function(e,t){var l=this._fillPolygon(e,t),a=Object.assign({},t,{hachureAngle:t.hachureAngle+90}),n=this._fillPolygon(e,a);return l.ops=l.ops.concat(n.ops),l}},{key:"fillEllipse",value:function(e,t,l,a,n){var i=this._fillEllipse(e,t,l,a,n),s=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),o=this._fillEllipse(e,t,l,a,s);return i.ops=i.ops.concat(o.ops),i}}]),t}(L),D=function(){function e(t){b(this,e),this.renderer=t}return O(e,[{key:"fillPolygon",value:function(e,t){t=Object.assign({},t,{curveStepCount:4,hachureAngle:0});var l=n(e,t);return this.dotsOnLines(l,t)}},{key:"fillEllipse",value:function(e,t,l,a,n){n=Object.assign({},n,{curveStepCount:4,hachureAngle:0});var s=i(e,t,l,a,n,this.renderer);return this.dotsOnLines(s,n)}},{key:"dotsOnLines",value:function(e,a){var n=[],s=a.hachureGap;0>s&&(s=4*a.strokeWidth),s=d(s,.1);var o=a.fillWeight;0>o&&(o=a.strokeWidth/2);var r=!0,p=!1,u=void 0;try{for(var f,h=e[Symbol.iterator]();!(r=(f=h.next()).done);r=!0)for(var y=f.value,k=t(y),x=k/s,b=g(x)-1,O=Math.atan((y[1][1]-y[0][1])/(y[1][0]-y[0][0])),m=0;m<b;m++){var P=s*(m+1),l=P*_(O),w=P*v(O),S=[y[0][0]-w,y[0][1]+l],c=this.renderer.getOffset(S[0]-s/4,S[0]+s/4,a),A=this.renderer.getOffset(S[1]-s/4,S[1]+s/4,a),T=this.renderer.ellipse(c,A,o,o,a);n=n.concat(T.ops)}}catch(e){p=!0,u=e}finally{try{!r&&h.return&&h.return()}finally{if(p)throw u}}return{type:"fillSketch",ops:n}}}]),e}(),R={},B=function(){function e(){b(this,e)}return O(e,[{key:"line",value:function(e,t,l,a,n){var i=this.doubleLine(e,t,l,a,n);return{type:"path",ops:i}}},{key:"linearPath",value:function(e,t,l){var a=(e||[]).length;if(2<a){for(var n=[],s=0;s<a-1;s++)n=n.concat(this.doubleLine(e[s][0],e[s][1],e[s+1][0],e[s+1][1],l));return t&&(n=n.concat(this.doubleLine(e[a-1][0],e[a-1][1],e[0][0],e[0][1],l))),{type:"path",ops:n}}return 2===a?this.line(e[0][0],e[0][1],e[1][0],e[1][1],l):{type:"path",ops:[]}}},{key:"polygon",value:function(e,t){return this.linearPath(e,!0,t)}},{key:"rectangle",value:function(e,t,l,a,n){return this.polygon([[e,t],[e+l,t],[e+l,t+a],[e,t+a]],n)}},{key:"curve",value:function(e,t){var l=this._curveWithOffset(e,1*(1+.2*t.roughness),t),a=this._curveWithOffset(e,1.5*(1+.22*t.roughness),t);return{type:"path",ops:l.concat(a)}}},{key:"ellipse",value:function(e,t,l,a,n){var i=2*c/n.curveStepCount,s=k(l/2),o=k(a/2);s+=this.getOffset(.05*-s,.05*s,n),o+=this.getOffset(.05*-o,.05*o,n);var r=this._ellipse(i,e,t,s,o,1,i*this.getOffset(.1,this.getOffset(.4,1,n),n),n),p=this._ellipse(i,e,t,s,o,1.5,0,n);return{type:"path",ops:r.concat(p)}}},{key:"arc",value:function(e,t,l,a,n,i,s,r,p){var o=e,d=t,f=k(l/2),h=k(a/2);f+=this.getOffset(.01*-f,.01*f,p),h+=this.getOffset(.01*-h,.01*h,p);for(var g=n,y=i;0>g;)g+=2*c,y+=2*c;y-g>2*c&&(g=0,y=2*c);var x=2*c/p.curveStepCount,b=u(x/2,(y-g)/2),O=this._arc(b,o,d,f,h,g,y,1,p),m=this._arc(b,o,d,f,h,g,y,1.5,p),P=O.concat(m);return s&&(r?(P=P.concat(this.doubleLine(o,d,o+f*v(g),d+h*_(g),p)),P=P.concat(this.doubleLine(o,d,o+f*v(y),d+h*_(y),p))):(P.push({op:"lineTo",data:[o,d]}),P.push({op:"lineTo",data:[o+f*v(g),d+h*_(g)]}))),{type:"path",ops:P}}},{key:"svgPath",value:function(e,t){e=(e||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");var l=new A(e);if(t.simplification){var a=new C(l.linearPoints,l.closed),n=a.fit(t.simplification);l=new A(n)}for(var o=[],r=l.segments||[],d=0;d<r.length;d++){var u=r[d],s=0<d?r[d-1]:null,f=this._processSegment(l,u,s,t);f&&f.length&&(o=o.concat(f))}return{type:"path",ops:o}}},{key:"solidFillPolygon",value:function(e,t){var l=[];if(e.length){var a=t.maxRandomnessOffset||0,n=e.length;if(2<n){l.push({op:"move",data:[e[0][0]+this.getOffset(-a,a,t),e[0][1]+this.getOffset(-a,a,t)]});for(var s=1;s<n;s++)l.push({op:"lineTo",data:[e[s][0]+this.getOffset(-a,a,t),e[s][1]+this.getOffset(-a,a,t)]})}}return{type:"fillPath",ops:l}}},{key:"patternFillPolygon",value:function(e,t){var l=s(this,t);return l.fillPolygon(e,t)}},{key:"patternFillEllipse",value:function(e,t,l,a,n){var i=s(this,n);return i.fillEllipse(e,t,l,a,n)}},{key:"patternFillArc",value:function(e,t,l,a,n,i,s){var o=e,r=t,p=k(l/2),d=k(a/2);p+=this.getOffset(.01*-p,.01*p,s),d+=this.getOffset(.01*-d,.01*d,s);for(var u=n,f=i;0>u;)u+=2*c,f+=2*c;f-u>2*c&&(u=0,f=2*c);for(var h=(f-u)/s.curveStepCount,g=[],y=u;y<=f;y+=h)g.push([o+p*v(y),r+d*_(y)]);return g.push([o+p*v(f),r+d*_(f)]),g.push([o,r]),this.patternFillPolygon(g,s)}},{key:"getOffset",value:function(e,t,l){return l.roughness*(Math.random()*(t-e)+e)}},{key:"doubleLine",value:function(e,t,l,a,n){var i=this._line(e,t,l,a,n,!0,!1),s=this._line(e,t,l,a,n,!0,!0);return i.concat(s)}},{key:"_line",value:function(e,t,l,a,n,i,s){var o=f(e-l,2)+f(t-a,2),r=n.maxRandomnessOffset||0;100*(r*r)>o&&(r=y(o)/10);var p=r/2,d=.2+.2*Math.random(),u=n.bowing*n.maxRandomnessOffset*(a-t)/200,h=n.bowing*n.maxRandomnessOffset*(e-l)/200;u=this.getOffset(-u,u,n),h=this.getOffset(-h,h,n);var g=[];return i&&(s?g.push({op:"move",data:[e+this.getOffset(-p,p,n),t+this.getOffset(-p,p,n)]}):g.push({op:"move",data:[e+this.getOffset(-r,r,n),t+this.getOffset(-r,r,n)]})),s?g.push({op:"bcurveTo",data:[u+e+(l-e)*d+this.getOffset(-p,p,n),h+t+(a-t)*d+this.getOffset(-p,p,n),u+e+2*(l-e)*d+this.getOffset(-p,p,n),h+t+2*(a-t)*d+this.getOffset(-p,p,n),l+this.getOffset(-p,p,n),a+this.getOffset(-p,p,n)]}):g.push({op:"bcurveTo",data:[u+e+(l-e)*d+this.getOffset(-r,r,n),h+t+(a-t)*d+this.getOffset(-r,r,n),u+e+2*(l-e)*d+this.getOffset(-r,r,n),h+t+2*(a-t)*d+this.getOffset(-r,r,n),l+this.getOffset(-r,r,n),a+this.getOffset(-r,r,n)]}),g}},{key:"_curve",value:function(e,t,l){var a=e.length,n=[];if(3<a){var o=[],r=1-l.curveTightness;n.push({op:"move",data:[e[1][0],e[1][1]]});for(var s,p=1;p+2<a;p++)s=e[p],o[0]=[s[0],s[1]],o[1]=[s[0]+(r*e[p+1][0]-r*e[p-1][0])/6,s[1]+(r*e[p+1][1]-r*e[p-1][1])/6],o[2]=[e[p+1][0]+(r*e[p][0]-r*e[p+2][0])/6,e[p+1][1]+(r*e[p][1]-r*e[p+2][1])/6],o[3]=[e[p+1][0],e[p+1][1]],n.push({op:"bcurveTo",data:[o[1][0],o[1][1],o[2][0],o[2][1],o[3][0],o[3][1]]});if(t&&2===t.length){var d=l.maxRandomnessOffset;n.push({op:"lineTo",data:[t[0]+this.getOffset(-d,d,l),t[1]+ +this.getOffset(-d,d,l)]})}}else 3===a?(n.push({op:"move",data:[e[1][0],e[1][1]]}),n.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):2===a&&(n=n.concat(this.doubleLine(e[0][0],e[0][1],e[1][0],e[1][1],l)));return n}},{key:"_ellipse",value:function(e,t,l,a,n,i,s,r){var o=this.getOffset(-.5,.5,r)-c/2,p=[];p.push([this.getOffset(-i,i,r)+t+.9*a*v(o-e),this.getOffset(-i,i,r)+l+.9*n*_(o-e)]);for(var d=o;d<2*c+o-.01;d+=e)p.push([this.getOffset(-i,i,r)+t+a*v(d),this.getOffset(-i,i,r)+l+n*_(d)]);return p.push([this.getOffset(-i,i,r)+t+a*v(o+2*c+.5*s),this.getOffset(-i,i,r)+l+n*_(o+2*c+.5*s)]),p.push([this.getOffset(-i,i,r)+t+.98*a*v(o+s),this.getOffset(-i,i,r)+l+.98*n*_(o+s)]),p.push([this.getOffset(-i,i,r)+t+.9*a*v(o+.5*s),this.getOffset(-i,i,r)+l+.9*n*_(o+.5*s)]),this._curve(p,null,r)}},{key:"_curveWithOffset",value:function(e,t,l){for(var a=[[e[0][0]+this.getOffset(-t,t,l),e[0][1]+this.getOffset(-t,t,l)],[e[0][0]+this.getOffset(-t,t,l),e[0][1]+this.getOffset(-t,t,l)]],n=1;n<e.length;n++)a.push([e[n][0]+this.getOffset(-t,t,l),e[n][1]+this.getOffset(-t,t,l)]),n===e.length-1&&a.push([e[n][0]+this.getOffset(-t,t,l),e[n][1]+this.getOffset(-t,t,l)]);return this._curve(a,null,l)}},{key:"_arc",value:function(e,t,l,a,n,i,s,r,p){var o=i+this.getOffset(-.1,.1,p),d=[];d.push([this.getOffset(-r,r,p)+t+.9*a*v(o-e),this.getOffset(-r,r,p)+l+.9*n*_(o-e)]);for(var u=o;u<=s;u+=e)d.push([this.getOffset(-r,r,p)+t+a*v(u),this.getOffset(-r,r,p)+l+n*_(u)]);return d.push([t+a*v(s),l+n*_(s)]),d.push([t+a*v(s),l+n*_(s)]),this._curve(d,null,p)}},{key:"_bezierTo",value:function(e,t,l,a,n,s,r,p){for(var o=[],d=[p.maxRandomnessOffset||1,(p.maxRandomnessOffset||1)+.5],u=[0,0],h=0;2>h;h++)0===h?o.push({op:"move",data:[r.x,r.y]}):o.push({op:"move",data:[r.x+this.getOffset(-d[0],d[0],p),r.y+this.getOffset(-d[0],d[0],p)]}),u=[n+this.getOffset(-d[h],d[h],p),s+this.getOffset(-d[h],d[h],p)],o.push({op:"bcurveTo",data:[e+this.getOffset(-d[h],d[h],p),t+this.getOffset(-d[h],d[h],p),l+this.getOffset(-d[h],d[h],p),a+this.getOffset(-d[h],d[h],p),u[0],u[1]]});return r.setPosition(u[0],u[1]),o}},{key:"_processSegment",value:function(e,t,l,a){var n=[];switch(t.key){case"M":case"m":{var s="m"===t.key;if(2<=t.data.length){var o=+t.data[0],r=+t.data[1];s&&(o+=e.x,r+=e.y);var p=1*(a.maxRandomnessOffset||0);o+=this.getOffset(-p,p,a),r+=this.getOffset(-p,p,a),e.setPosition(o,r),n.push({op:"move",data:[o,r]})}break}case"L":case"l":{var d="l"===t.key;if(2<=t.data.length){var u=+t.data[0],h=+t.data[1];d&&(u+=e.x,h+=e.y),n=n.concat(this.doubleLine(e.x,e.y,u,h,a)),e.setPosition(u,h)}break}case"H":case"h":{var g="h"===t.key;if(t.data.length){var c=+t.data[0];g&&(c+=e.x),n=n.concat(this.doubleLine(e.x,e.y,c,e.y,a)),e.setPosition(c,e.y)}break}case"V":case"v":{var v="v"===t.key;if(t.data.length){var _=+t.data[0];v&&(_+=e.y),n=n.concat(this.doubleLine(e.x,e.y,e.x,_,a)),e.setPosition(e.x,_)}break}case"Z":case"z":{e.first&&(n=n.concat(this.doubleLine(e.x,e.y,e.first[0],e.first[1],a)),e.setPosition(e.first[0],e.first[1]),e.first=null);break}case"C":case"c":{var k="c"===t.key;if(6<=t.data.length){var b=+t.data[0],O=+t.data[1],m=+t.data[2],P=+t.data[3],w=+t.data[4],S=+t.data[5];k&&(b+=e.x,m+=e.x,w+=e.x,O+=e.y,P+=e.y,S+=e.y);var A=this._bezierTo(b,O,m,P,w,S,e,a);n=n.concat(A),e.bezierReflectionPoint=[w+(w-m),S+(S-P)]}break}case"S":case"s":{var C="s"===t.key;if(4<=t.data.length){var z=+t.data[0],E=+t.data[1],L=+t.data[2],W=+t.data[3];C&&(z+=e.x,L+=e.x,E+=e.y,W+=e.y);var N=z,D=E,R=l?l.key:"",B=null;("c"===R||"C"===R||"s"===R||"S"===R)&&(B=e.bezierReflectionPoint),B&&(N=B[0],D=B[1]);var F=this._bezierTo(N,D,z,E,L,W,e,a);n=n.concat(F),e.bezierReflectionPoint=[L+(L-z),W+(W-E)]}break}case"Q":case"q":{var M="q"===t.key;if(4<=t.data.length){var q=+t.data[0],U=+t.data[1],X=+t.data[2],V=+t.data[3];M&&(q+=e.x,X+=e.x,U+=e.y,V+=e.y);var G=1*(1+.2*a.roughness),j=1.5*(1+.22*a.roughness);n.push({op:"move",data:[e.x+this.getOffset(-G,G,a),e.y+this.getOffset(-G,G,a)]});var I=[X+this.getOffset(-G,G,a),V+this.getOffset(-G,G,a)];n.push({op:"qcurveTo",data:[q+this.getOffset(-G,G,a),U+this.getOffset(-G,G,a),I[0],I[1]]}),n.push({op:"move",data:[e.x+this.getOffset(-j,j,a),e.y+this.getOffset(-j,j,a)]}),I=[X+this.getOffset(-j,j,a),V+this.getOffset(-j,j,a)],n.push({op:"qcurveTo",data:[q+this.getOffset(-j,j,a),U+this.getOffset(-j,j,a),I[0],I[1]]}),e.setPosition(I[0],I[1]),e.quadReflectionPoint=[X+(X-q),V+(V-U)]}break}case"T":case"t":{var Q="t"===t.key;if(2<=t.data.length){var $=+t.data[0],Z=+t.data[1];Q&&($+=e.x,Z+=e.y);var H=$,J=Z,Y=l?l.key:"",K=null;("q"===Y||"Q"===Y||"t"===Y||"T"===Y)&&(K=e.quadReflectionPoint),K&&(H=K[0],J=K[1]);var ee=1*(1+.2*a.roughness),te=1.5*(1+.22*a.roughness);n.push({op:"move",data:[e.x+this.getOffset(-ee,ee,a),e.y+this.getOffset(-ee,ee,a)]});var le=[$+this.getOffset(-ee,ee,a),Z+this.getOffset(-ee,ee,a)];n.push({op:"qcurveTo",data:[H+this.getOffset(-ee,ee,a),J+this.getOffset(-ee,ee,a),le[0],le[1]]}),n.push({op:"move",data:[e.x+this.getOffset(-te,te,a),e.y+this.getOffset(-te,te,a)]}),le=[$+this.getOffset(-te,te,a),Z+this.getOffset(-te,te,a)],n.push({op:"qcurveTo",data:[H+this.getOffset(-te,te,a),J+this.getOffset(-te,te,a),le[0],le[1]]}),e.setPosition(le[0],le[1]),e.quadReflectionPoint=[$+($-H),Z+(Z-J)]}break}case"A":case"a":{var ae="a"===t.key;if(7<=t.data.length){var ne=+t.data[0],ie=+t.data[1],se=+t.data[2],oe=+t.data[3],re=+t.data[4],pe=+t.data[5],de=+t.data[6];if(ae&&(pe+=e.x,de+=e.y),pe===e.x&&de===e.y)break;if(0==ne||0==ie)n=n.concat(this.doubleLine(e.x,e.y,pe,de,a)),e.setPosition(pe,de);else for(var ue=0;1>ue;ue++)for(var fe,he=new T([e.x,e.y],[pe,de],[ne,ie],se,!!oe,!!re),ge=he.getNextSegment();ge;)fe=this._bezierTo(ge.cp1[0],ge.cp1[1],ge.cp2[0],ge.cp2[1],ge.to[0],ge.to[1],e,a),n=n.concat(fe),ge=he.getNextSegment()}break}default:}return n}}]),e}(),F="undefined"!=typeof self,M=F&&self&&self.document&&self.document.currentScript&&self.document.currentScript.src,q="undefined"!=typeof self,U=function(){function e(t,l){b(this,e),this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1},this.config=t||{},this.surface=l,this.renderer=o(this.config),this.config.options&&(this.defaultOptions=this._options(this.config.options))}return O(e,[{key:"_options",value:function(e){return e?Object.assign({},this.defaultOptions,e):this.defaultOptions}},{key:"_drawable",value:function(e,t,l){return{shape:e,sets:t||[],options:l||this.defaultOptions}}},{key:"getCanvasSize",value:function(){var e=function(e){return e&&"object"===("undefined"==typeof e?"undefined":x(e))&&e.baseVal&&e.baseVal.value?e.baseVal.value:e||100};return this.surface?[e(this.surface.width),e(this.surface.height)]:[100,100]}},{key:"computePolygonSize",value:function(e){if(e.length){for(var t=e[0][0],l=e[0][0],a=e[0][1],n=e[0][1],s=1;s<e.length;s++)t=u(t,e[s][0]),l=d(l,e[s][0]),a=u(a,e[s][1]),n=d(n,e[s][1]);return[l-t,n-a]}return[0,0]}},{key:"polygonPath",value:function(e){var t="";if(e.length){t="M"+e[0][0]+","+e[0][1];for(var l=1;l<e.length;l++)t=t+" L"+e[l][0]+","+e[l][1]}return t}},{key:"computePathSize",value:function(e){var t=[0,0];if(q&&self.document)try{var l=self.document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("width","0"),l.setAttribute("height","0");var a=self.document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",e),l.appendChild(a),self.document.body.appendChild(l);var n=a.getBBox();n&&(t[0]=n.width||0,t[1]=n.height||0),self.document.body.removeChild(l)}catch(e){}var i=this.getCanvasSize();return t[0]*t[1]||(t=i),t}},{key:"toPaths",value:function(e){var t=e.sets||[],l=e.options||this.defaultOptions,a=[],n=!0,i=!1,s=void 0;try{for(var o,p=t[Symbol.iterator]();!(n=(o=p.next()).done);n=!0){var d=o.value,u=null;switch(d.type){case"path":u={d:this.opsToPath(d),stroke:l.stroke,strokeWidth:l.strokeWidth,fill:"none"};break;case"fillPath":u={d:this.opsToPath(d),stroke:"none",strokeWidth:0,fill:l.fill||"none"};break;case"fillSketch":u=this.fillSketch(d,l);break;case"path2Dfill":u={d:d.path||"",stroke:"none",strokeWidth:0,fill:l.fill||"none"};break;case"path2Dpattern":{var f=d.size,h={x:0,y:0,width:1,height:1,viewBox:"0 0 "+r(f[0])+" "+r(f[1]),patternUnits:"objectBoundingBox",path:this.fillSketch(d,l)};u={d:d.path,stroke:"none",strokeWidth:0,pattern:h};break}}u&&a.push(u)}}catch(e){i=!0,s=e}finally{try{!n&&p.return&&p.return()}finally{if(i)throw s}}return a}},{key:"fillSketch",value:function(e,t){var l=t.fillWeight;return 0>l&&(l=t.strokeWidth/2),{d:this.opsToPath(e),stroke:t.fill||"none",strokeWidth:l,fill:"none"}}},{key:"opsToPath",value:function(e){var t="",l=!0,a=!1,n=void 0;try{for(var i,s=e.ops[Symbol.iterator]();!(l=(i=s.next()).done);l=!0){var o=i.value,r=o.data;switch(o.op){case"move":t+="M"+r[0]+" "+r[1]+" ";break;case"bcurveTo":t+="C"+r[0]+" "+r[1]+", "+r[2]+" "+r[3]+", "+r[4]+" "+r[5]+" ";break;case"qcurveTo":t+="Q"+r[0]+" "+r[1]+", "+r[2]+" "+r[3]+" ";break;case"lineTo":t+="L"+r[0]+" "+r[1]+" ";}}}catch(e){a=!0,n=e}finally{try{!l&&s.return&&s.return()}finally{if(a)throw n}}return t.trim()}},{key:"lib",get:function(){return this.renderer}}]),e}(),X=function(e){function t(e,l){return b(this,t),P(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,l))}return m(t,e),O(t,[{key:"line",value:function(e,t,l,a,n){var i=this._options(n);return this._drawable("line",[this.lib.line(e,t,l,a,i)],i)}},{key:"rectangle",value:function(e,t,l,a,n){var i=this._options(n),s=[];if(i.fill){var o=[[e,t],[e+l,t],[e+l,t+a],[e,t+a]];"solid"===i.fillStyle?s.push(this.lib.solidFillPolygon(o,i)):s.push(this.lib.patternFillPolygon(o,i))}return s.push(this.lib.rectangle(e,t,l,a,i)),this._drawable("rectangle",s,i)}},{key:"ellipse",value:function(e,t,l,a,n){var i=this._options(n),s=[];if(i.fill)if("solid"===i.fillStyle){var o=this.lib.ellipse(e,t,l,a,i);o.type="fillPath",s.push(o)}else s.push(this.lib.patternFillEllipse(e,t,l,a,i));return s.push(this.lib.ellipse(e,t,l,a,i)),this._drawable("ellipse",s,i)}},{key:"circle",value:function(e,t,l,a){var n=this.ellipse(e,t,l,l,a);return n.shape="circle",n}},{key:"linearPath",value:function(e,t){var l=this._options(t);return this._drawable("linearPath",[this.lib.linearPath(e,!1,l)],l)}},{key:"arc",value:function(e,t,l,a,n,i){var s=!!(6<arguments.length&&void 0!==arguments[6])&&arguments[6],r=arguments[7],p=this._options(r),o=[];if(s&&p.fill)if("solid"===p.fillStyle){var d=this.lib.arc(e,t,l,a,n,i,!0,!1,p);d.type="fillPath",o.push(d)}else o.push(this.lib.patternFillArc(e,t,l,a,n,i,p));return o.push(this.lib.arc(e,t,l,a,n,i,s,!0,p)),this._drawable("arc",o,p)}},{key:"curve",value:function(e,t){var l=this._options(t);return this._drawable("curve",[this.lib.curve(e,l)],l)}},{key:"polygon",value:function(e,t){var l=this._options(t),a=[];if(l.fill)if("solid"===l.fillStyle)a.push(this.lib.solidFillPolygon(e,l));else{var n=this.computePolygonSize(e),i=[[0,0],[n[0],0],[n[0],n[1]],[0,n[1]]],s=this.lib.patternFillPolygon(i,l);s.type="path2Dpattern",s.size=n,s.path=this.polygonPath(e),a.push(s)}return a.push(this.lib.linearPath(e,!0,l)),this._drawable("polygon",a,l)}},{key:"path",value:function(e,t){var l=this._options(t),a=[];if(!e)return this._drawable("path",a,l);if(l.fill)if("solid"===l.fillStyle)a.push({type:"path2Dfill",path:e,ops:[]});else{var n=this.computePathSize(e),i=[[0,0],[n[0],0],[n[0],n[1]],[0,n[1]]],s=this.lib.patternFillPolygon(i,l);s.type="path2Dpattern",s.size=n,s.path=e,a.push(s)}return a.push(this.lib.svgPath(e,l)),this._drawable("path",a,l)}}]),t}(U),V="undefined"!=typeof document,G=function(){function e(t){b(this,e),this.canvas=t,this.ctx=this.canvas.getContext("2d")}return O(e,[{key:"draw",value:function(e){var t=e.sets||[],l=e.options||this.getDefaultOptions(),a=this.ctx,n=!0,i=!1,s=void 0;try{for(var o,r,p=t[Symbol.iterator]();!(n=(o=p.next()).done);n=!0)switch(r=o.value,r.type){case"path":a.save(),a.strokeStyle=l.stroke,a.lineWidth=l.strokeWidth,this._drawToContext(a,r),a.restore();break;case"fillPath":a.save(),a.fillStyle=l.fill||"",this._drawToContext(a,r),a.restore();break;case"fillSketch":this.fillSketch(a,r,l);break;case"path2Dfill":{this.ctx.save(),this.ctx.fillStyle=l.fill||"";var d=new Path2D(r.path);this.ctx.fill(d),this.ctx.restore();break}case"path2Dpattern":{var u=this.canvas.ownerDocument||V&&document;if(u){var f=r.size,h=u.createElement("canvas"),g=h.getContext("2d"),y=this.computeBBox(r.path);y&&(y.width||y.height)?(h.width=this.canvas.width,h.height=this.canvas.height,g.translate(y.x||0,y.y||0)):(h.width=f[0],h.height=f[1]),this.fillSketch(g,r,l),this.ctx.save(),this.ctx.fillStyle=this.ctx.createPattern(h,"repeat");var c=new Path2D(r.path);this.ctx.fill(c),this.ctx.restore()}else console.error("Cannot render path2Dpattern. No defs/document defined.");break}}}catch(e){i=!0,s=e}finally{try{!n&&p.return&&p.return()}finally{if(i)throw s}}}},{key:"computeBBox",value:function(e){if(V)try{var t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width","0"),t.setAttribute("height","0");var l=self.document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",e),t.appendChild(l),document.body.appendChild(t);var a=l.getBBox();return document.body.removeChild(t),a}catch(e){}return null}},{key:"fillSketch",value:function(e,t,l){var a=l.fillWeight;0>a&&(a=l.strokeWidth/2),e.save(),e.strokeStyle=l.fill||"",e.lineWidth=a,this._drawToContext(e,t),e.restore()}},{key:"_drawToContext",value:function(e,t){e.beginPath();var l=!0,a=!1,n=void 0;try{for(var i,s=t.ops[Symbol.iterator]();!(l=(i=s.next()).done);l=!0){var o=i.value,r=o.data;switch(o.op){case"move":e.moveTo(r[0],r[1]);break;case"bcurveTo":e.bezierCurveTo(r[0],r[1],r[2],r[3],r[4],r[5]);break;case"qcurveTo":e.quadraticCurveTo(r[0],r[1],r[2],r[3]);break;case"lineTo":e.lineTo(r[0],r[1]);}}}catch(e){a=!0,n=e}finally{try{!l&&s.return&&s.return()}finally{if(a)throw n}}"fillPath"===t.type?e.fill():e.stroke()}}],[{key:"createRenderer",value:function(){return new B}}]),e}(),j=function(e){function t(e,l){b(this,t);var a=P(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return a.gen=new X(l||null,a.canvas),a}return m(t,e),O(t,[{key:"getDefaultOptions",value:function(){return this.gen.defaultOptions}},{key:"line",value:function(e,t,l,a,n){var i=this.gen.line(e,t,l,a,n);return this.draw(i),i}},{key:"rectangle",value:function(e,t,l,a,n){var i=this.gen.rectangle(e,t,l,a,n);return this.draw(i),i}},{key:"ellipse",value:function(e,t,l,a,n){var i=this.gen.ellipse(e,t,l,a,n);return this.draw(i),i}},{key:"circle",value:function(e,t,l,a){var n=this.gen.circle(e,t,l,a);return this.draw(n),n}},{key:"linearPath",value:function(e,t){var l=this.gen.linearPath(e,t);return this.draw(l),l}},{key:"polygon",value:function(e,t){var l=this.gen.polygon(e,t);return this.draw(l),l}},{key:"arc",value:function(e,t,l,a,n,i){var s=!!(6<arguments.length&&void 0!==arguments[6])&&arguments[6],o=arguments[7],r=this.gen.arc(e,t,l,a,n,i,s,o);return this.draw(r),r}},{key:"curve",value:function(e,t){var l=this.gen.curve(e,t);return this.draw(l),l}},{key:"path",value:function(e,t){var l=this.gen.path(e,t);return this.draw(l),l}},{key:"generator",get:function(){return this.gen}}]),t}(G),I=function(e){function t(){return b(this,t),P(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return m(t,e),O(t,[{key:"line",value:async function(e,t,l,a,n){var i=this._options(n);return this._drawable("line",[await this.lib.line(e,t,l,a,i)],i)}},{key:"rectangle",value:async function(e,t,l,a,n){var i=this._options(n),s=[];if(i.fill){var o=[[e,t],[e+l,t],[e+l,t+a],[e,t+a]];"solid"===i.fillStyle?s.push((await this.lib.solidFillPolygon(o,i))):s.push((await this.lib.patternFillPolygon(o,i)))}return s.push((await this.lib.rectangle(e,t,l,a,i))),this._drawable("rectangle",s,i)}},{key:"ellipse",value:async function(e,t,l,a,n){var i=this._options(n),s=[];if(i.fill)if("solid"===i.fillStyle){var o=await this.lib.ellipse(e,t,l,a,i);o.type="fillPath",s.push(o)}else s.push((await this.lib.patternFillEllipse(e,t,l,a,i)));return s.push((await this.lib.ellipse(e,t,l,a,i))),this._drawable("ellipse",s,i)}},{key:"circle",value:async function(e,t,l,a){var n=await this.ellipse(e,t,l,l,a);return n.shape="circle",n}},{key:"linearPath",value:async function(e,t){var l=this._options(t);return this._drawable("linearPath",[await this.lib.linearPath(e,!1,l)],l)}},{key:"arc",value:async function(e,t,l,a,n,i){var s=!!(6<arguments.length&&void 0!==arguments[6])&&arguments[6],r=arguments[7],p=this._options(r),o=[];if(s&&p.fill)if("solid"===p.fillStyle){var d=await this.lib.arc(e,t,l,a,n,i,!0,!1,p);d.type="fillPath",o.push(d)}else o.push((await this.lib.patternFillArc(e,t,l,a,n,i,p)));return o.push((await this.lib.arc(e,t,l,a,n,i,s,!0,p))),this._drawable("arc",o,p)}},{key:"curve",value:async function(e,t){var l=this._options(t);return this._drawable("curve",[await this.lib.curve(e,l)],l)}},{key:"polygon",value:async function(e,t){var l=this._options(t),a=[];if(l.fill)if("solid"===l.fillStyle)a.push((await this.lib.solidFillPolygon(e,l)));else{var n=this.computePolygonSize(e),i=[[0,0],[n[0],0],[n[0],n[1]],[0,n[1]]],s=await this.lib.patternFillPolygon(i,l);s.type="path2Dpattern",s.size=n,s.path=this.polygonPath(e),a.push(s)}return a.push((await this.lib.linearPath(e,!0,l))),this._drawable("polygon",a,l)}},{key:"path",value:async function(e,t){var l=this._options(t),a=[];if(!e)return this._drawable("path",a,l);if(l.fill)if("solid"===l.fillStyle)a.push({type:"path2Dfill",path:e,ops:[]});else{var n=this.computePathSize(e),i=[[0,0],[n[0],0],[n[0],n[1]],[0,n[1]]],s=await this.lib.patternFillPolygon(i,l);s.type="path2Dpattern",s.size=n,s.path=e,a.push(s)}return a.push((await this.lib.svgPath(e,l))),this._drawable("path",a,l)}}]),t}(U),Q=function(e){function t(e,l){b(this,t);var a=P(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return a.genAsync=new I(l||null,a.canvas),a}return m(t,e),O(t,[{key:"getDefaultOptions",value:function(){return this.genAsync.defaultOptions}},{key:"line",value:async function(e,t,l,a,n){var i=await this.genAsync.line(e,t,l,a,n);return this.draw(i),i}},{key:"rectangle",value:async function(e,t,l,a,n){var i=await this.genAsync.rectangle(e,t,l,a,n);return this.draw(i),i}},{key:"ellipse",value:async function(e,t,l,a,n){var i=await this.genAsync.ellipse(e,t,l,a,n);return this.draw(i),i}},{key:"circle",value:async function(e,t,l,a){var n=await this.genAsync.circle(e,t,l,a);return this.draw(n),n}},{key:"linearPath",value:async function(e,t){var l=await this.genAsync.linearPath(e,t);return this.draw(l),l}},{key:"polygon",value:async function(e,t){var l=await this.genAsync.polygon(e,t);return this.draw(l),l}},{key:"arc",value:async function(e,t,l,a,n,i){var s=!!(6<arguments.length&&void 0!==arguments[6])&&arguments[6],o=arguments[7],r=await this.genAsync.arc(e,t,l,a,n,i,s,o);return this.draw(r),r}},{key:"curve",value:async function(e,t){var l=await this.genAsync.curve(e,t);return this.draw(l),l}},{key:"path",value:async function(e,t){var l=await this.genAsync.path(e,t);return this.draw(l),l}},{key:"generator",get:function(){return this.genAsync}}]),t}(G),$="undefined"!=typeof document,Z=function(){function e(t){b(this,e),this.svg=t}return O(e,[{key:"draw",value:function(e){var t=e.sets||[],l=e.options||this.getDefaultOptions(),a=this.svg.ownerDocument||$&&document,n=a.createElementNS("http://www.w3.org/2000/svg","g"),i=!0,s=!1,o=void 0;try{for(var p,d=t[Symbol.iterator]();!(i=(p=d.next()).done);i=!0){var u=p.value,f=null;switch(u.type){case"path":{f=a.createElementNS("http://www.w3.org/2000/svg","path"),f.setAttribute("d",this.opsToPath(u)),f.style.stroke=l.stroke,f.style.strokeWidth=l.strokeWidth+"",f.style.fill="none";break}case"fillPath":{f=a.createElementNS("http://www.w3.org/2000/svg","path"),f.setAttribute("d",this.opsToPath(u)),f.style.stroke="none",f.style.strokeWidth="0",f.style.fill=l.fill||null;break}case"fillSketch":{f=this.fillSketch(a,u,l);break}case"path2Dfill":{f=a.createElementNS("http://www.w3.org/2000/svg","path"),f.setAttribute("d",u.path||""),f.style.stroke="none",f.style.strokeWidth="0",f.style.fill=l.fill||null;break}case"path2Dpattern":{if(!this.defs)console.error("Cannot render path2Dpattern. No defs/document defined.");else{var g=u.size,y=a.createElementNS("http://www.w3.org/2000/svg","pattern"),c="rough-"+h(Math.random()*(Number.MAX_SAFE_INTEGER||999999));y.setAttribute("id",c),y.setAttribute("x","0"),y.setAttribute("y","0"),y.setAttribute("width","1"),y.setAttribute("height","1"),y.setAttribute("height","1"),y.setAttribute("viewBox","0 0 "+r(g[0])+" "+r(g[1])),y.setAttribute("patternUnits","objectBoundingBox");var v=this.fillSketch(a,u,l);y.appendChild(v),this.defs.appendChild(y),f=a.createElementNS("http://www.w3.org/2000/svg","path"),f.setAttribute("d",u.path||""),f.style.stroke="none",f.style.strokeWidth="0",f.style.fill="url(#"+c+")"}break}}f&&n.appendChild(f)}}catch(e){s=!0,o=e}finally{try{!i&&d.return&&d.return()}finally{if(s)throw o}}return n}},{key:"fillSketch",value:function(e,t,l){var a=l.fillWeight;0>a&&(a=l.strokeWidth/2);var n=e.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d",this.opsToPath(t)),n.style.stroke=l.fill||null,n.style.strokeWidth=a+"",n.style.fill="none",n}},{key:"defs",get:function(){var e=this.svg.ownerDocument||$&&document;if(e&&!this._defs){var t=e.createElementNS("http://www.w3.org/2000/svg","defs");this.svg.firstChild?this.svg.insertBefore(t,this.svg.firstChild):this.svg.appendChild(t),this._defs=t}return this._defs||null}}],[{key:"createRenderer",value:function(){return new B}}]),e}(),H=function(e){function t(e,l){b(this,t);var a=P(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return a.gen=new X(l||null,a.svg),a}return m(t,e),O(t,[{key:"getDefaultOptions",value:function(){return this.gen.defaultOptions}},{key:"opsToPath",value:function(e){return this.gen.opsToPath(e)}},{key:"line",value:function(e,t,l,a,n){var i=this.gen.line(e,t,l,a,n);return this.draw(i)}},{key:"rectangle",value:function(e,t,l,a,n){var i=this.gen.rectangle(e,t,l,a,n);return this.draw(i)}},{key:"ellipse",value:function(e,t,l,a,n){var i=this.gen.ellipse(e,t,l,a,n);return this.draw(i)}},{key:"circle",value:function(e,t,l,a){var n=this.gen.circle(e,t,l,a);return this.draw(n)}},{key:"linearPath",value:function(e,t){var l=this.gen.linearPath(e,t);return this.draw(l)}},{key:"polygon",value:function(e,t){var l=this.gen.polygon(e,t);return this.draw(l)}},{key:"arc",value:function(e,t,l,a,n,i){var s=!!(6<arguments.length&&void 0!==arguments[6])&&arguments[6],o=arguments[7],r=this.gen.arc(e,t,l,a,n,i,s,o);return this.draw(r)}},{key:"curve",value:function(e,t){var l=this.gen.curve(e,t);return this.draw(l)}},{key:"path",value:function(e,t){var l=this.gen.path(e,t);return this.draw(l)}},{key:"generator",get:function(){return this.gen}}]),t}(Z),J=function(e){function t(e,l){b(this,t);var a=P(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return a.genAsync=new I(l||null,a.svg),a}return m(t,e),O(t,[{key:"getDefaultOptions",value:function(){return this.genAsync.defaultOptions}},{key:"opsToPath",value:function(e){return this.genAsync.opsToPath(e)}},{key:"line",value:async function(e,t,l,a,n){var i=await this.genAsync.line(e,t,l,a,n);return this.draw(i)}},{key:"rectangle",value:async function(e,t,l,a,n){var i=await this.genAsync.rectangle(e,t,l,a,n);return this.draw(i)}},{key:"ellipse",value:async function(e,t,l,a,n){var i=await this.genAsync.ellipse(e,t,l,a,n);return this.draw(i)}},{key:"circle",value:async function(e,t,l,a){var n=await this.genAsync.circle(e,t,l,a);return this.draw(n)}},{key:"linearPath",value:async function(e,t){var l=await this.genAsync.linearPath(e,t);return this.draw(l)}},{key:"polygon",value:async function(e,t){var l=await this.genAsync.polygon(e,t);return this.draw(l)}},{key:"arc",value:async function(e,t,l,a,n,i){var s=!!(6<arguments.length&&void 0!==arguments[6])&&arguments[6],o=arguments[7],r=await this.genAsync.arc(e,t,l,a,n,i,s,o);return this.draw(r)}},{key:"curve",value:async function(e,t){var l=await this.genAsync.curve(e,t);return this.draw(l)}},{key:"path",value:async function(e,t){var l=await this.genAsync.path(e,t);return this.draw(l)}},{key:"generator",get:function(){return this.genAsync}}]),t}(Z);return{canvas:function(e,t){return t&&t.async?new Q(e,t):new j(e,t)},svg:function(e,t){return t&&t.async?new J(e,t):new H(e,t)},createRenderer:function(){return j.createRenderer()},generator:function(e,t){return e&&e.async?new I(e,t):new X(e,t)}}}();