var rough=function(){"use strict";const t="http://www.w3.org/2000/svg";function e(t,e,s){if(t&&t.length){const[n,i]=e,o=Math.PI/180*s,r=Math.cos(o),a=Math.sin(o);t.forEach(t=>{const[e,s]=t;t[0]=(e-n)*r-(s-i)*a+n,t[1]=(e-n)*a+(s-i)*r+i})}}function s(t){const e=t[0],s=t[1];return Math.sqrt(Math.pow(e[0]-s[0],2)+Math.pow(e[1]-s[1],2))}function n(t,e,s){return[t[0]+(e[0]-t[0])*s,t[1]+(e[1]-t[1])*s]}function i(t,e){const s=t[0]-e[0],n=t[1]-e[1];return s*s+n*n}function o(t,e,s){const o=i(e,s);if(0===o)return i(t,e);let r=((t[0]-e[0])*(s[0]-e[0])+(t[1]-e[1])*(s[1]-e[1]))/o;return r=Math.max(0,Math.min(1,r)),i(t,n(e,s,r))}function r(t,e){return t.type===e}const a={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};class h{constructor(t){this.COMMAND=0,this.NUMBER=1,this.EOD=2,this.segments=[],this.parseData(t),this.processPoints()}tokenize(t){const e=new Array;for(;""!==t;)if(t.match(/^([ \t\r\n,]+)/))t=t.substr(RegExp.$1.length);else if(t.match(/^([aAcChHlLmMqQsStTvVzZ])/))e[e.length]={type:this.COMMAND,text:RegExp.$1},t=t.substr(RegExp.$1.length);else{if(!t.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))return[];e[e.length]={type:this.NUMBER,text:`${parseFloat(RegExp.$1)}`},t=t.substr(RegExp.$1.length)}return e[e.length]={type:this.EOD,text:""},e}parseData(t){const e=this.tokenize(t);let s=0,n=e[s],i="BOD";for(this.segments=new Array;!r(n,this.EOD);){let o;const h=new Array;if("BOD"===i){if("M"!==n.text&&"m"!==n.text)return void this.parseData("M0,0"+t);s++,o=a[n.text],i=n.text}else r(n,this.NUMBER)?o=a[i]:(s++,o=a[n.text],i=n.text);if(s+o0?p-=2*Math.PI:o&&p<0&&(p+=2*Math.PI),this._numSegs=Math.ceil(Math.abs(p/(Math.PI/2))),this._delta=p/this._numSegs,this._T=8/3*Math.sin(this._delta/4)*Math.sin(this._delta/4)/Math.sin(this._delta/2)}getNextSegment(){if(this._segIndex===this._numSegs)return null;const t=Math.cos(this._theta),e=Math.sin(this._theta),s=this._theta+this._delta,n=Math.cos(s),i=Math.sin(s),o=[this._cosPhi*this._rx*n-this._sinPhi*this._ry*i+this._C[0],this._sinPhi*this._rx*n+this._cosPhi*this._ry*i+this._C[1]],r=[this._from[0]+this._T*(-this._cosPhi*this._rx*e-this._sinPhi*this._ry*t),this._from[1]+this._T*(-this._sinPhi*this._rx*e+this._cosPhi*this._ry*t)],a=[o[0]+this._T*(this._cosPhi*this._rx*i+this._sinPhi*this._ry*n),o[1]+this._T*(this._sinPhi*this._rx*i-this._cosPhi*this._ry*n)];return this._theta=s,this._from=[o[0],o[1]],this._segIndex++,{cp1:r,cp2:a,to:o}}calculateVectorAngle(t,e,s,n){const i=Math.atan2(e,t),o=Math.atan2(n,s);return o>=i?o-i:2*Math.PI-(i-o)}}class u{constructor(t,e){this.sets=t,this.closed=e}fit(t){const e=[];for(const s of this.sets){const n=s.length;let i=Math.floor(t*n);if(i<5){if(n<=5)continue;i=5}e.push(this.reduce(s,i))}let s="";for(const t of e){for(let e=0;ee;){let t=-1,e=-1;for(let i=1;i0))break;n.splice(e,1)}return n}}function f(t,s){const n=[0,0],i=Math.round(s.hachureAngle+90);i&&e(t,n,i);const o=function(t,e){const s=[...t];s[0].join(",")!==s[s.length-1].join(",")&&s.push([s[0][0],s[0][1]]);const n=[];if(s&&s.length>2){let t=e.hachureGap;t<0&&(t=4*e.strokeWidth),t=Math.max(t,.1);const i=[];for(let t=0;tt.ymine.ymin?1:t.xe.x?1:t.ymax===e.ymax?0:(t.ymax-e.ymax)/Math.abs(t.ymax-e.ymax)),!i.length)return n;let o=[],r=i[0].ymin;for(;o.length||i.length;){if(i.length){let t=-1;for(let e=0;er);e++)t=e;i.splice(0,t+1).forEach(t=>{o.push({s:r,edge:t})})}if(o=o.filter(t=>!(t.edge.ymax<=r)),o.sort((t,e)=>t.edge.x===e.edge.x?0:(t.edge.x-e.edge.x)/Math.abs(t.edge.x-e.edge.x)),o.length>1)for(let t=0;t=o.length)break;const s=o[t].edge,i=o[e].edge;n.push([[Math.round(s.x),r],[Math.round(i.x),r]])}r+=t,o.forEach(e=>{e.edge.x=e.edge.x+t*e.edge.islope})}}return n}(t,s);return i&&(e(t,n,-i),function(t,s,n){const i=[];t.forEach(t=>i.push(...t)),e(i,s,n)}(o,n,-i)),o}class p{constructor(t){this.helper=t}fillPolygon(t,e){return this._fillPolygon(t,e)}_fillPolygon(t,e,s=!1){const n=f(t,e);return{type:"fillSketch",ops:this.renderLines(n,e,s)}}renderLines(t,e,s){let n=[],i=null;for(const o of t)n=n.concat(this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],e)),s&&i&&(n=n.concat(this.helper.doubleLineOps(i[0],i[1],o[0][0],o[0][1],e))),i=o[1];return n}}class d extends p{fillPolygon(t,e){return this._fillPolygon(t,e,!0)}}class g extends p{fillPolygon(t,e){const s=this._fillPolygon(t,e),n=Object.assign({},e,{hachureAngle:e.hachureAngle+90}),i=this._fillPolygon(t,n);return s.ops=s.ops.concat(i.ops),s}}class m{constructor(t){this.helper=t}fillPolygon(t,e){const s=f(t,e=Object.assign({},e,{curveStepCount:4,hachureAngle:0,roughness:1}));return this.dotsOnLines(s,e)}dotsOnLines(t,e){let n=[],i=e.hachureGap;i<0&&(i=4*e.strokeWidth),i=Math.max(i,.1);let o=e.fillWeight;o<0&&(o=e.strokeWidth/2);for(const r of t){const t=s(r)/i,a=Math.ceil(t)-1,h=Math.atan((r[1][1]-r[0][1])/(r[1][0]-r[0][0]));for(let t=0;t{const r=s(t),a=Math.floor(r/(n+i)),h=(r+i-a*(n+i))/2;let c=t[0],l=t[1];c[0]>l[0]&&(c=t[1],l=t[0]);const u=Math.atan((l[1]-c[1])/(l[0]-c[0]));for(let t=0;t{const o=s(t),r=Math.round(o/(2*e));let a=t[0],h=t[1];a[0]>h[0]&&(a=t[1],h=t[0]);const c=Math.atan((h[1]-a[1])/(h[0]-a[0]));for(let t=0;t2){let i=[];for(let e=0;e2*Math.PI&&(p=0,d=2*Math.PI);const g=2*Math.PI/h.curveStepCount,m=Math.min(g/2,(d-p)/2),_=B(m,c,l,u,f,p,d,1,h),y=B(m,c,l,u,f,p,d,1.5,h);let b=_.concat(y);return r&&(a?(b=b.concat(R(c,l,c+u*Math.cos(p),l+f*Math.sin(p),h)),b=b.concat(R(c,l,c+u*Math.cos(d),l+f*Math.sin(d),h))):(b.push({op:"lineTo",data:[c,l]}),b.push({op:"lineTo",data:[c+u*Math.cos(p),l+f*Math.sin(p)]}))),{type:"path",ops:b}}function A(t,e){const s=[];if(t.length){const n=e.maxRandomnessOffset||0,i=t.length;if(i>2){s.push({op:"move",data:[t[0][0]+L(n,e),t[0][1]+L(n,e)]});for(let o=1;o500?.4:-.0016668*h+1.233334;let c=i.maxRandomnessOffset||0;c*c*100>a&&(c=h/10);const l=c/2,u=.2+.2*E(i);let f=i.bowing*i.maxRandomnessOffset*(n-e)/200,p=i.bowing*i.maxRandomnessOffset*(t-s)/200;f=L(f,i),p=L(p,i);const d=[],g=()=>L(l,i),m=()=>L(c,i);return o&&(r?d.push({op:"move",data:[t+g(),e+g()]}):d.push({op:"move",data:[t+L(c,i),e+L(c,i)]})),r?d.push({op:"bcurveTo",data:[f+t+(s-t)*u+g(),p+e+(n-e)*u+g(),f+t+2*(s-t)*u+g(),p+e+2*(n-e)*u+g(),s+g(),n+g()]}):d.push({op:"bcurveTo",data:[f+t+(s-t)*u+m(),p+e+(n-e)*u+m(),f+t+2*(s-t)*u+m(),p+e+2*(n-e)*u+m(),s+m(),n+m()]}),d}function W(t,e,s){const n=[];n.push([t[0][0]+L(e,s),t[0][1]+L(e,s)]),n.push([t[0][0]+L(e,s),t[0][1]+L(e,s)]);for(let i=1;i3){const o=[],r=1-s.curveTightness;i.push({op:"move",data:[t[1][0],t[1][1]]});for(let e=1;e+2=2){let o=+e.data[0],r=+e.data[1];s&&(o+=t.x,r+=t.y);const a=1*(n.maxRandomnessOffset||0);o+=L(a,n),r+=L(a,n),t.setPosition(o,r),i.push({op:"move",data:[o,r]})}break}case"L":case"l":{const s="l"===e.key;if(e.data.length>=2){let o=+e.data[0],r=+e.data[1];s&&(o+=t.x,r+=t.y),i=i.concat(R(t.x,t.y,o,r,n)),t.setPosition(o,r)}break}case"H":case"h":{const s="h"===e.key;if(e.data.length){let o=+e.data[0];s&&(o+=t.x),i=i.concat(R(t.x,t.y,o,t.y,n)),t.setPosition(o,t.y)}break}case"V":case"v":{const s="v"===e.key;if(e.data.length){let o=+e.data[0];s&&(o+=t.y),i=i.concat(R(t.x,t.y,t.x,o,n)),t.setPosition(t.x,o)}break}case"Z":case"z":t.first&&(i=i.concat(R(t.x,t.y,t.first[0],t.first[1],n)),t.setPosition(t.first[0],t.first[1]),t.first=null);break;case"C":case"c":{const s="c"===e.key;if(e.data.length>=6){let o=+e.data[0],r=+e.data[1],a=+e.data[2],h=+e.data[3],c=+e.data[4],l=+e.data[5];s&&(o+=t.x,a+=t.x,c+=t.x,r+=t.y,h+=t.y,l+=t.y);const u=D(o,r,a,h,c,l,t,n);i=i.concat(u),t.bezierReflectionPoint=[c+(c-a),l+(l-h)]}break}case"S":case"s":{const o="s"===e.key;if(e.data.length>=4){let r=+e.data[0],a=+e.data[1],h=+e.data[2],c=+e.data[3];o&&(r+=t.x,h+=t.x,a+=t.y,c+=t.y);let l=r,u=a;const f=s?s.key:"";let p=null;"c"!==f&&"C"!==f&&"s"!==f&&"S"!==f||(p=t.bezierReflectionPoint),p&&(l=p[0],u=p[1]);const d=D(l,u,r,a,h,c,t,n);i=i.concat(d),t.bezierReflectionPoint=[h+(h-r),c+(c-a)]}break}case"Q":case"q":{const s="q"===e.key;if(e.data.length>=4){let o=+e.data[0],r=+e.data[1],a=+e.data[2],h=+e.data[3];s&&(o+=t.x,a+=t.x,r+=t.y,h+=t.y);const c=1*(1+.2*n.roughness),l=1.5*(1+.22*n.roughness);i.push({op:"move",data:[t.x+L(c,n),t.y+L(c,n)]});let u=[a+L(c,n),h+L(c,n)];i.push({op:"qcurveTo",data:[o+L(c,n),r+L(c,n),u[0],u[1]]}),i.push({op:"move",data:[t.x+L(l,n),t.y+L(l,n)]}),u=[a+L(l,n),h+L(l,n)],i.push({op:"qcurveTo",data:[o+L(l,n),r+L(l,n),u[0],u[1]]}),t.setPosition(u[0],u[1]),t.quadReflectionPoint=[a+(a-o),h+(h-r)]}break}case"T":case"t":{const o="t"===e.key;if(e.data.length>=2){let r=+e.data[0],a=+e.data[1];o&&(r+=t.x,a+=t.y);let h=r,c=a;const l=s?s.key:"";let u=null;"q"!==l&&"Q"!==l&&"t"!==l&&"T"!==l||(u=t.quadReflectionPoint),u&&(h=u[0],c=u[1]);const f=1*(1+.2*n.roughness),p=1.5*(1+.22*n.roughness);i.push({op:"move",data:[t.x+L(f,n),t.y+L(f,n)]});let d=[r+L(f,n),a+L(f,n)];i.push({op:"qcurveTo",data:[h+L(f,n),c+L(f,n),d[0],d[1]]}),i.push({op:"move",data:[t.x+L(p,n),t.y+L(p,n)]}),d=[r+L(p,n),a+L(p,n)],i.push({op:"qcurveTo",data:[h+L(p,n),c+L(p,n),d[0],d[1]]}),t.setPosition(d[0],d[1]),t.quadReflectionPoint=[r+(r-h),a+(a-c)]}break}case"A":case"a":{const s="a"===e.key;if(e.data.length>=7){const o=+e.data[0],r=+e.data[1],a=+e.data[2],h=+e.data[3],c=+e.data[4];let u=+e.data[5],f=+e.data[6];if(s&&(u+=t.x,f+=t.y),u===t.x&&f===t.y)break;if(0===o||0===r)i=i.concat(R(t.x,t.y,u,f,n)),t.setPosition(u,f);else for(let e=0;e<1;e++){const e=new l([t.x,t.y],[u,f],[o,r],a,!!h,!!c);let s=e.getNextSegment();for(;s;){const o=D(s.cp1[0],s.cp1[1],s.cp2[0],s.cp2[1],s.to[0],s.to[1],t,n);i=i.concat(o),s=e.getNextSegment()}}}break}}return i}const F="undefined"!=typeof self,V="none",G={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,roughnessGain:1};class U{constructor(t,e){this.defaultOptions=JSON.parse(JSON.stringify(G)),this.config=t||{},this.surface=e,this.config.options&&(this.defaultOptions=this._options(this.config.options))}static newSeed(){return Math.floor(Math.random()*2**31)}_options(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_drawable(t,e,s){return{shape:t,sets:e||[],options:s||this.defaultOptions}}line(t,e,s,n,i){const o=this._options(i);return this._drawable("line",[k(t,e,s,n,o)],o)}rectangle(t,e,s,n,i){const o=this._options(i),r=[],a=v(t,e,s,n,o);if(o.fill){const i=[[t,e],[t+s,e],[t+s,e+n],[t,e+n]];"solid"===o.fillStyle?r.push(A(i,o)):r.push(C(i,o))}return o.stroke!==V&&r.push(a),this._drawable("rectangle",r,o)}ellipse(t,e,s,n,i){const o=this._options(i),r=[],a=S(s,n,o),h=T(t,e,o,a);if(o.fill)if("solid"===o.fillStyle){const s=T(t,e,o,a).opset;s.type="fillPath",r.push(s)}else r.push(C(h.estimatedPoints,o));return o.stroke!==V&&r.push(h.opset),this._drawable("ellipse",r,o)}circle(t,e,s,n){const i=this.ellipse(t,e,s,s,n);return i.shape="circle",i}linearPath(t,e){const s=this._options(e);return this._drawable("linearPath",[P(t,!1,s)],s)}arc(t,e,s,n,i,o,r=!1,a){const h=this._options(a),c=[],l=O(t,e,s,n,i,o,r,!0,h);if(r&&h.fill)if("solid"===h.fillStyle){const r=O(t,e,s,n,i,o,!0,!1,h);r.type="fillPath",c.push(r)}else c.push(function(t,e,s,n,i,o,r){const a=t,h=e;let c=Math.abs(s/2),l=Math.abs(n/2);c+=L(.01*c,r),l+=L(.01*l,r);let u=i,f=o;for(;u<0;)u+=2*Math.PI,f+=2*Math.PI;f-u>2*Math.PI&&(u=0,f=2*Math.PI);const p=(f-u)/r.curveStepCount,d=[];for(let t=u;t<=f;t+=p)d.push([a+c*Math.cos(t),h+l*Math.sin(t)]);return d.push([a+c*Math.cos(f),h+l*Math.sin(f)]),d.push([a,h]),C(d,r)}(t,e,s,n,i,o,h));return h.stroke!==V&&c.push(l),this._drawable("arc",c,h)}curve(t,e){const s=this._options(e);return this._drawable("curve",[w(t,s)],s)}polygon(t,e){const s=this._options(e),n=[],i=P(t,!0,s);return s.fill&&("solid"===s.fillStyle?n.push(A(t,s)):n.push(C(t,s))),s.stroke!==V&&n.push(i),this._drawable("polygon",n,s)}path(t,e){const s=this._options(e),n=[];if(!t)return this._drawable("path",n,s);const i=function(t,e){t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let s=new c(t);if(e.simplification){const t=new u(s.linearPoints,s.closed).fit(e.simplification);s=new c(t)}let n=[];const i=s.segments||[];for(let t=0;t0?i[t-1]:null,e);o&&o.length&&(n=n.concat(o))}return{type:"path",ops:n}}(t,s);if(s.fill)if("solid"===s.fillStyle){const e={type:"path2Dfill",path:t,ops:[]};n.push(e)}else{const e=this.computePathSize(t),i=C([[0,0],[e[0],0],[e[0],e[1]],[0,e[1]]],s);i.type="path2Dpattern",i.size=e,i.path=t,n.push(i)}return s.stroke!==V&&n.push(i),this._drawable("path",n,s)}computePathSize(e){let s=[0,0];if(F&&self.document)try{const n=self.document.createElementNS(t,"svg");n.setAttribute("width","0"),n.setAttribute("height","0");const i=self.document.createElementNS(t,"path");i.setAttribute("d",e),n.appendChild(i),self.document.body.appendChild(n);const o=i.getBBox();o&&(s[0]=o.width||0,s[1]=o.height||0),self.document.body.removeChild(n)}catch(t){}const n=this.getCanvasSize();return s[0]*s[1]||(s=n),s}getCanvasSize(){const t=t=>t&&"object"==typeof t&&t.baseVal&&t.baseVal.value?t.baseVal.value:t||100;return this.surface?[t(this.surface.width),t(this.surface.height)]:[100,100]}opsToPath(t){let e="";for(const s of t.ops){const t=s.data;switch(s.op){case"move":e+=`M${t[0]} ${t[1]} `;break;case"bcurveTo":e+=`C${t[0]} ${t[1]}, ${t[2]} ${t[3]}, ${t[4]} ${t[5]} `;break;case"qcurveTo":e+=`Q${t[0]} ${t[1]}, ${t[2]} ${t[3]} `;break;case"lineTo":e+=`L${t[0]} ${t[1]} `}}return e.trim()}toPaths(t){const e=t.sets||[],s=t.options||this.defaultOptions,n=[];for(const t of e){let e=null;switch(t.type){case"path":e={d:this.opsToPath(t),stroke:s.stroke,strokeWidth:s.strokeWidth,fill:V};break;case"fillPath":e={d:this.opsToPath(t),stroke:V,strokeWidth:0,fill:s.fill||V};break;case"fillSketch":e=this.fillSketch(t,s);break;case"path2Dfill":e={d:t.path||"",stroke:V,strokeWidth:0,fill:s.fill||V};break;case"path2Dpattern":{const n=t.size,i={x:0,y:0,width:1,height:1,viewBox:`0 0 ${Math.round(n[0])} ${Math.round(n[1])}`,patternUnits:"objectBoundingBox",path:this.fillSketch(t,s)};e={d:t.path,stroke:V,strokeWidth:0,pattern:i};break}}e&&n.push(e)}return n}fillSketch(t,e){let s=e.fillWeight;return s<0&&(s=e.strokeWidth/2),{d:this.opsToPath(t),stroke:e.fill||V,strokeWidth:s,fill:V}}}const j="undefined"!=typeof document;class H{constructor(t,e){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new U(e,this.canvas)}draw(t){const e=t.sets||[],s=t.options||this.getDefaultOptions(),n=this.ctx;for(const t of e)switch(t.type){case"path":n.save(),n.strokeStyle="none"===s.stroke?"transparent":s.stroke,n.lineWidth=s.strokeWidth,this._drawToContext(n,t),n.restore();break;case"fillPath":n.save(),n.fillStyle=s.fill||"",this._drawToContext(n,t),n.restore();break;case"fillSketch":this.fillSketch(n,t,s);break;case"path2Dfill":{this.ctx.save(),this.ctx.fillStyle=s.fill||"";const e=new Path2D(t.path);this.ctx.fill(e),this.ctx.restore();break}case"path2Dpattern":{const e=this.canvas.ownerDocument||j&&document;if(e){const n=t.size,i=e.createElement("canvas"),o=i.getContext("2d"),r=this.computeBBox(t.path);r&&(r.width||r.height)?(i.width=this.canvas.width,i.height=this.canvas.height,o.translate(r.x||0,r.y||0)):(i.width=n[0],i.height=n[1]),this.fillSketch(o,t,s),this.ctx.save(),this.ctx.fillStyle=this.ctx.createPattern(i,"repeat");const a=new Path2D(t.path);this.ctx.fill(a),this.ctx.restore()}else console.error("Pattern fill fail: No defs");break}}}computeBBox(e){if(j)try{const s=document.createElementNS(t,"svg");s.setAttribute("width","0"),s.setAttribute("height","0");const n=self.document.createElementNS(t,"path");n.setAttribute("d",e),s.appendChild(n),document.body.appendChild(s);const i=n.getBBox();return document.body.removeChild(s),i}catch(t){}return null}fillSketch(t,e,s){let n=s.fillWeight;n<0&&(n=s.strokeWidth/2),t.save(),t.strokeStyle=s.fill||"",t.lineWidth=n,this._drawToContext(t,e),t.restore()}_drawToContext(t,e){t.beginPath();for(const s of e.ops){const e=s.data;switch(s.op){case"move":t.moveTo(e[0],e[1]);break;case"bcurveTo":t.bezierCurveTo(e[0],e[1],e[2],e[3],e[4],e[5]);break;case"qcurveTo":t.quadraticCurveTo(e[0],e[1],e[2],e[3]);break;case"lineTo":t.lineTo(e[0],e[1])}}"fillPath"===e.type?t.fill():t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,e,s,n,i){const o=this.gen.line(t,e,s,n,i);return this.draw(o),o}rectangle(t,e,s,n,i){const o=this.gen.rectangle(t,e,s,n,i);return this.draw(o),o}ellipse(t,e,s,n,i){const o=this.gen.ellipse(t,e,s,n,i);return this.draw(o),o}circle(t,e,s,n){const i=this.gen.circle(t,e,s,n);return this.draw(i),i}linearPath(t,e){const s=this.gen.linearPath(t,e);return this.draw(s),s}polygon(t,e){const s=this.gen.polygon(t,e);return this.draw(s),s}arc(t,e,s,n,i,o,r=!1,a){const h=this.gen.arc(t,e,s,n,i,o,r,a);return this.draw(h),h}curve(t,e){const s=this.gen.curve(t,e);return this.draw(s),s}path(t,e){const s=this.gen.path(t,e);return this.draw(s),s}}const Q="undefined"!=typeof document;class Z{constructor(t,e){this.svg=t,this.gen=new U(e,this.svg)}get defs(){const e=this.svg.ownerDocument||Q&&document;if(e&&!this._defs){const s=e.createElementNS(t,"defs");this.svg.firstChild?this.svg.insertBefore(s,this.svg.firstChild):this.svg.appendChild(s),this._defs=s}return this._defs||null}draw(e){const s=e.sets||[],n=e.options||this.getDefaultOptions(),i=this.svg.ownerDocument||window.document,o=i.createElementNS(t,"g");for(const e of s){let s=null;switch(e.type){case"path":s=i.createElementNS(t,"path"),s.setAttribute("d",this.opsToPath(e)),s.style.stroke=n.stroke,s.style.strokeWidth=n.strokeWidth+"",s.style.fill="none";break;case"fillPath":s=i.createElementNS(t,"path"),s.setAttribute("d",this.opsToPath(e)),s.style.stroke="none",s.style.strokeWidth="0",s.style.fill=n.fill||"";break;case"fillSketch":s=this.fillSketch(i,e,n);break;case"path2Dfill":s=i.createElementNS(t,"path"),s.setAttribute("d",e.path||""),s.style.stroke="none",s.style.strokeWidth="0",s.style.fill=n.fill||"";break;case"path2Dpattern":if(this.defs){const o=e.size,r=i.createElementNS(t,"pattern"),a=`rough-${Math.floor(Math.random()*(Number.MAX_SAFE_INTEGER||999999))}`;r.setAttribute("id",a),r.setAttribute("x","0"),r.setAttribute("y","0"),r.setAttribute("width","1"),r.setAttribute("height","1"),r.setAttribute("height","1"),r.setAttribute("viewBox",`0 0 ${Math.round(o[0])} ${Math.round(o[1])}`),r.setAttribute("patternUnits","objectBoundingBox");const h=this.fillSketch(i,e,n);r.appendChild(h),this.defs.appendChild(r),s=i.createElementNS(t,"path"),s.setAttribute("d",e.path||""),s.style.stroke="none",s.style.strokeWidth="0",s.style.fill=`url(#${a})`}else console.error("Pattern fill fail: No defs")}s&&o.appendChild(s)}return o}fillSketch(e,s,n){let i=n.fillWeight;i<0&&(i=n.strokeWidth/2);const o=e.createElementNS(t,"path");return o.setAttribute("d",this.opsToPath(s)),o.style.stroke=n.fill||"",o.style.strokeWidth=i+"",o.style.fill="none",o}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t){return this.gen.opsToPath(t)}line(t,e,s,n,i){const o=this.gen.line(t,e,s,n,i);return this.draw(o)}rectangle(t,e,s,n,i){const o=this.gen.rectangle(t,e,s,n,i);return this.draw(o)}ellipse(t,e,s,n,i){const o=this.gen.ellipse(t,e,s,n,i);return this.draw(o)}circle(t,e,s,n){const i=this.gen.circle(t,e,s,n);return this.draw(i)}linearPath(t,e){const s=this.gen.linearPath(t,e);return this.draw(s)}polygon(t,e){const s=this.gen.polygon(t,e);return this.draw(s)}arc(t,e,s,n,i,o,r=!1,a){const h=this.gen.arc(t,e,s,n,i,o,r,a);return this.draw(h)}curve(t,e){const s=this.gen.curve(t,e);return this.draw(s)}path(t,e){const s=this.gen.path(t,e);return this.draw(s)}}function J(t,e,s){const n=t.createShader(e);if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){const e=new Error("An error occurred compiling the shaders: "+t.getShaderInfoLog(n));throw t.deleteShader(n),e}return n}function Y(t,e){const s=(e,s)=>{const n=t.getUniformLocation(e,s.name),i=s.type,o=s.size>1&&"[0]"===s.name.substr(-3);if(i===t.FLOAT&&o)return function(e){t.uniform1fv(n,e)};if(i===t.FLOAT)return function(e){t.uniform1f(n,e)};if(i===t.FLOAT_VEC2)return function(e){t.uniform2fv(n,e)};if(i===t.FLOAT_VEC3)return function(e){t.uniform3fv(n,e)};if(i===t.FLOAT_VEC4)return function(e){t.uniform4fv(n,e)};if(i===t.INT&&o)return function(e){t.uniform1iv(n,e)};if(i===t.INT)return function(e){t.uniform1i(n,e)};if(i===t.INT_VEC2)return function(e){t.uniform2iv(n,e)};if(i===t.INT_VEC3)return function(e){t.uniform3iv(n,e)};if(i===t.INT_VEC4)return function(e){t.uniform4iv(n,e)};if(i===t.BOOL)return function(e){t.uniform1iv(n,e)};if(i===t.BOOL_VEC2)return function(e){t.uniform2iv(n,e)};if(i===t.BOOL_VEC3)return function(e){t.uniform3iv(n,e)};if(i===t.BOOL_VEC4)return function(e){t.uniform4iv(n,e)};if(i===t.FLOAT_MAT2)return function(e){t.uniformMatrix2fv(n,!1,e)};if(i===t.FLOAT_MAT3)return function(e){t.uniformMatrix3fv(n,!1,e)};if(i===t.FLOAT_MAT4)return function(e){t.uniformMatrix4fv(n,!1,e)};throw"unknown type: 0x"+i.toString(16)},n={},i=t.getProgramParameter(e,t.ACTIVE_UNIFORMS);for(let o=0;oc&&(c=e,l=n)}return Math.sqrt(c)>n?(nt(t,e,l+1,n,r),nt(t,l,s,n,r)):r.push(...a,...h),r}function it(t,e,s,i){const o=i||[];if(function(t,e){const s=t[e+0],n=t[e+1],i=t[e+2],o=t[e+3];let r=3*n[0]-2*s[0]-o[0];r*=r;let a=3*n[1]-2*s[1]-o[1];a*=a;let h=3*i[0]-2*o[0]-s[0];h*=h;let c=3*i[1]-2*o[1]-s[1];return c*=c,r+t.trim());4===s.length?e=s:3===s.length&&(e=[...s,1])}return e||(e=function(t){let e=[0,0,0,0];(4===t.length||t.length>6)&&(t=t.substring(1));3===t.length?e=[+`0x${t[0]}${t[0]}`,+`0x${t[1]}${t[1]}`,+`0x${t[2]}${t[2]}`,1]:t.length>=6&&(e=[+`0x${t[0]}${t[1]}`,+`0x${t[2]}${t[3]}`,+`0x${t[4]}${t[5]}`,1]);return e}(t)),[e[0]/255,e[1]/255,e[2]/255,e[3]]}const rt={tolerance:.15,distance:.4};class at{constructor(t){if(this.defaultOptions=JSON.parse(JSON.stringify(G)),this.canvas=t,this.gl=t.getContext("webgl"),!this.gl)throw new Error("Unable to initialize WebGL. Your browser or machine may not support it.");this.pi=K(this.gl,["\nattribute vec2 a_position;\nuniform vec2 u_resolution;\n\nvoid main() {\n vec2 zeroToOne = a_position / u_resolution;\n vec2 zeroToTwo = zeroToOne * 2.0;\n vec2 clipSpace = zeroToTwo - 1.0;\n gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);\n}\n","\nprecision mediump float;\nuniform vec4 u_color;\n\nvoid main() {\n gl_FragColor = u_color;\n}\n"])}draw(t,e=!1){const s=Array.isArray(t)?t:[t];e&&this.clearCanvas(),this.initializeCanvas();for(const t of s){console.log(t);const e=t.sets||[],s=t.options||this.defaultOptions;for(const t of e)switch(t.type){case"path":const e=this.extractCurvePoints(t.ops);this.drawCurves(e,s.strokeWidth,"none"===s.stroke?"transparent":s.stroke);break;case"fillSketch":{let e=s.fillWeight;e<0&&(e=s.strokeWidth/2);const n=this.extractCurvePoints(t.ops);this.drawCurves(n,e,s.fill||"");break}}}}extractCurvePoints(t){const e=[];let s=[];for(const n of t)switch(n.op){case"move":s.length>1&&(e.push(s),s=[]),s.push(n.data);break;case"bcurveTo":s.push([n.data[0],n.data[1]]),s.push([n.data[2],n.data[3]]),s.push([n.data[4],n.data[5]])}return s.length>1&&(e.push(s),s=[]),e}clearCanvas(){this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}initializeCanvas(){!function(t,e=1){const s=t.clientWidth*e|0,n=t.clientHeight*e|0;(t.width!==s||t.height!==n)&&(t.width=s,t.height=n)}(this.canvas),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height)}drawCurves(t,e,s,n){const i=n||rt;let o=[];for(const e of t){const t=st(e,i.tolerance);o=nt(t,0,t.length,i.distance,o)}const r=function(t,e){const s=e[Object.keys(e)[0]];return{attribs:et(t,e),numElements:s?s.data.length/s.numComponents:0}}(this.gl,{position:{numComponents:2,data:o}});this.gl.useProgram(this.pi.program),function(t,e){for(const s in e){const n=t[s];n&&n(e[s])}}(this.pi.attribSetters,r.attribs);const a={u_resolution:[this.gl.canvas.width,this.gl.canvas.height],u_color:ot(s)};!function(t,e){for(const s in e){const n=t[s];n&&n(e[s])}}(this.pi.uniformSetters,a),this.gl.drawArrays(this.gl.LINES,0,r.numElements)}}return{canvas:(t,e)=>new H(t,e),svg:(t,e)=>new Z(t,e),webGl:t=>new at(t),generator:(t,e)=>new U(t,e),newSeed:()=>U.newSeed()}}();