var rough=function(){"use strict";const t="undefined"!=typeof self;class e{constructor(t,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=e,this.config.options&&(this.defaultOptions=this._options(this.config.options))}_options(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_drawable(t,e,s){return{shape:t,sets:e||[],options:s||this.defaultOptions}}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]}computePolygonSize(t){if(t.length){let e=t[0][0],s=t[0][0],i=t[0][1],n=t[0][1];for(let a=1;aa};const s=t.remote({type:"GET",path:e});return s.then.bind(s)}return s(t,e.concat(n))},set:(s,i,n)=>t.remote({type:"SET",path:e.concat(i),value:n}),apply:(s,i,n)=>t.remote({type:"APPLY",path:e,args:n}),construct:(e,s)=>t.remote({type:"CONSTRUCT",args:s})})}class i{constructor(t,e){this.w=t,this.uid=e||`${Date.now()}-${n()}`,this.c=0,this.cbs={},t.addEventListener("message",e=>{if(this.w.oURL)try{URL.revokeObjectURL(this.w.oURL)}catch(t){}finally{delete this.w.oURL}let n=e.data&&e.data.id,a=n&&this.cbs[n];a&&(delete this.cbs[n],e.data.error?a[1](new Error(e.data.error)):a[0](e.data.targetId?s(new i(t,e.data.targetId)):e.data.value))})}remote(t){const e=t.args||[],s=`${this.uid}-${++this.c}`;return new Promise((i,n)=>{this.cbs[s]=[i,n],this.w.postMessage(Object.assign({},t,{id:s,args:e,target:this.uid}))})}}function n(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)}function a(t){const e=t,s={};self.addEventListener("message",async t=>{let i=t.data||{};i.path=i.path||[];let a=i.target&&s[i.target]||e;const h=t=>t.reduce((t,e)=>t?t[e]:t,a),r=i&&i.id;if(r&&i.type){const t={id:r},e=h(i.path),a=h(i.path.slice(0,-1));switch(i.type){case"GET":t.value=e;break;case"SET":let h=i.path.length&&i.path[i.path.length-1];h&&(a[h]=i.value),t.value=!!h;break;case"APPLY":try{t.value=await e.apply(a,i.args||[])}catch(e){t.error=e.toString()}break;case"CONSTRUCT":try{t.value=new e(...i.args),t.targetId=(t=>{const e=`${Date.now()}-${n()}`;return s[e]=t,e})(t.value)}catch(e){t.error=e.toString()}}self.postMessage(t)}})}function h(t,e){return t.type===e}const r={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 o{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 console.error("Unrecognized segment command: "+t),[];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,i=e[s],n="BOD";for(this.segments=new Array;!h(i,this.EOD);){let a;const o=new Array;if("BOD"===n){if("M"!==i.text&&"m"!==i.text)return void this.parseData("M0,0"+t);s++,a=r[i.text],n=i.text}else h(i,this.NUMBER)?a=r[n]:(s++,a=r[i.text],n=i.text);if(s+a0?d-=2*Math.PI:a&&d<0&&(d+=2*Math.PI),this._numSegs=Math.ceil(Math.abs(d/(Math.PI/2))),this._delta=d/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,i=Math.cos(s),n=Math.sin(s),a=[this._cosPhi*this._rx*i-this._sinPhi*this._ry*n+this._C[0],this._sinPhi*this._rx*i+this._cosPhi*this._ry*n+this._C[1]],h=[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)],r=[a[0]+this._T*(this._cosPhi*this._rx*n+this._sinPhi*this._ry*i),a[1]+this._T*(this._sinPhi*this._rx*n-this._cosPhi*this._ry*i)];return this._theta=s,this._from=[a[0],a[1]],this._segIndex++,{cp1:h,cp2:r,to:a}}calculateVectorAngle(t,e,s,i){const n=Math.atan2(e,t),a=Math.atan2(i,s);return a>=n?a-n:2*Math.PI-(n-a)}}class p{constructor(t,e){this.sets=t,this.closed=e}fit(t){const e=[];for(const s of this.sets){const i=s.length;let n=Math.floor(t*i);if(n<5){if(i<=5)continue;n=5}e.push(this.reduce(s,n))}let s="";for(const t of e){for(let e=0;ee;){let t=-1,e=-1;for(let i=1;i0))break;s.splice(e,1)}return s}}class u{constructor(t,e){this.xi=Number.MAX_VALUE,this.yi=Number.MAX_VALUE,this.px1=t[0],this.py1=t[1],this.px2=e[0],this.py2=e[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}isUndefined(){return this._undefined}intersects(t){if(this.isUndefined()||t.isUndefined())return!1;let e=Number.MAX_VALUE,s=Number.MAX_VALUE,i=0,n=0;const a=this.a,h=this.b,r=this.c;return Math.abs(h)>1e-5&&(e=-a/h,i=-r/h),Math.abs(t.b)>1e-5&&(s=-t.a/t.b,n=-t.c/t.b),e===Number.MAX_VALUE?s===Number.MAX_VALUE?-r/a==-t.c/t.a&&(this.py1>=Math.min(t.py1,t.py2)&&this.py1<=Math.max(t.py1,t.py2)?(this.xi=this.px1,this.yi=this.py1,!0):this.py2>=Math.min(t.py1,t.py2)&&this.py2<=Math.max(t.py1,t.py2)&&(this.xi=this.px2,this.yi=this.py2,!0)):(this.xi=this.px1,this.yi=s*this.xi+n,!((this.py1-this.yi)*(this.yi-this.py2)<-1e-5||(t.py1-this.yi)*(this.yi-t.py2)<-1e-5)&&(!(Math.abs(t.a)<1e-5)||!((t.px1-this.xi)*(this.xi-t.px2)<-1e-5))):s===Number.MAX_VALUE?(this.xi=t.px1,this.yi=e*this.xi+i,!((t.py1-this.yi)*(this.yi-t.py2)<-1e-5||(this.py1-this.yi)*(this.yi-this.py2)<-1e-5)&&(!(Math.abs(a)<1e-5)||!((this.px1-this.xi)*(this.xi-this.px2)<-1e-5))):e===s?i===n&&(this.px1>=Math.min(t.px1,t.px2)&&this.px1<=Math.max(t.py1,t.py2)?(this.xi=this.px1,this.yi=this.py1,!0):this.px2>=Math.min(t.px1,t.px2)&&this.px2<=Math.max(t.px1,t.px2)&&(this.xi=this.px2,this.yi=this.py2,!0)):(this.xi=(n-i)/(e-s),this.yi=e*this.xi+i,!((this.px1-this.xi)*(this.xi-this.px2)<-1e-5||(t.px1-this.xi)*(this.xi-t.px2)<-1e-5))}}class d{constructor(t,e,s,i,n,a,h,r){this.deltaX=0,this.hGap=0,this.top=t,this.bottom=e,this.left=s,this.right=i,this.gap=n,this.sinAngle=a,this.tanAngle=r,Math.abs(a)<1e-4?this.pos=s+n:Math.abs(a)>.9999?this.pos=t+n:(this.deltaX=(e-t)*Math.abs(r),this.pos=s-Math.abs(this.deltaX),this.hGap=Math.abs(n/h),this.sLeft=new u([s,e],[s,t]),this.sRight=new u([i,e],[i,t]))}nextLine(){if(Math.abs(this.sinAngle)<1e-4){if(this.pos.9999){if(this.posthis.right&&e>this.right;)if(this.pos+=this.hGap,t=this.pos-this.deltaX/2,e=this.pos+this.deltaX/2,this.pos>this.right+this.deltaX)return null;const n=new u([t,s],[e,i]);this.sLeft&&n.intersects(this.sLeft)&&(t=n.xi,s=n.yi),this.sRight&&n.intersects(this.sRight)&&(e=n.xi,i=n.yi),this.tanAngle>0&&(t=this.right-(t-this.left),e=this.right-(e-this.left));const a=[t,s,e,i];return this.pos+=this.hGap,a}}return null}}function f(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 g(t,e){const s=[],i=new u([t[0],t[1]],[t[2],t[3]]);for(let t=0;t2){let n=[];for(let e=0;er&&(o=Math.sqrt(r)/10);const l=o/2,c=.2+.2*Math.random();let p=n.bowing*n.maxRandomnessOffset*(i-e)/200,u=n.bowing*n.maxRandomnessOffset*(t-s)/200;p=N(p,n),u=N(u,n);const d=[],f=()=>N(l,n),g=()=>N(o,n);return a&&(h?d.push({op:"move",data:[t+f(),e+f()]}):d.push({op:"move",data:[t+N(o,n),e+N(o,n)]})),h?d.push({op:"bcurveTo",data:[p+t+(s-t)*c+f(),u+e+(i-e)*c+f(),p+t+2*(s-t)*c+f(),u+e+2*(i-e)*c+f(),s+f(),i+f()]}):d.push({op:"bcurveTo",data:[p+t+(s-t)*c+g(),u+e+(i-e)*c+g(),p+t+2*(s-t)*c+g(),u+e+2*(i-e)*c+g(),s+g(),i+g()]}),d}function z(t,e,s){const i=[];i.push([t[0][0]+N(e,s),t[0][1]+N(e,s)]),i.push([t[0][0]+N(e,s),t[0][1]+N(e,s)]);for(let n=1;n3){const a=[],h=1-s.curveTightness;n.push({op:"move",data:[t[1][0],t[1][1]]});for(let e=1;e+2=2){let a=+e.data[0],h=+e.data[1];s&&(a+=t.x,h+=t.y);const r=1*(i.maxRandomnessOffset||0);a+=N(r,i),h+=N(r,i),t.setPosition(a,h),n.push({op:"move",data:[a,h]})}break}case"L":case"l":{const s="l"===e.key;if(e.data.length>=2){let a=+e.data[0],h=+e.data[1];s&&(a+=t.x,h+=t.y),n=n.concat(W(t.x,t.y,a,h,i)),t.setPosition(a,h)}break}case"H":case"h":{const s="h"===e.key;if(e.data.length){let a=+e.data[0];s&&(a+=t.x),n=n.concat(W(t.x,t.y,a,t.y,i)),t.setPosition(a,t.y)}break}case"V":case"v":{const s="v"===e.key;if(e.data.length){let a=+e.data[0];s&&(a+=t.y),n=n.concat(W(t.x,t.y,t.x,a,i)),t.setPosition(t.x,a)}break}case"Z":case"z":t.first&&(n=n.concat(W(t.x,t.y,t.first[0],t.first[1],i)),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 a=+e.data[0],h=+e.data[1],r=+e.data[2],o=+e.data[3],l=+e.data[4],c=+e.data[5];s&&(a+=t.x,r+=t.x,l+=t.x,h+=t.y,o+=t.y,c+=t.y);const p=B(a,h,r,o,l,c,t,i);n=n.concat(p),t.bezierReflectionPoint=[l+(l-r),c+(c-o)]}break}case"S":case"s":{const a="s"===e.key;if(e.data.length>=4){let h=+e.data[0],r=+e.data[1],o=+e.data[2],l=+e.data[3];a&&(h+=t.x,o+=t.x,r+=t.y,l+=t.y);let c=h,p=r;const u=s?s.key:"";let d=null;"c"!==u&&"C"!==u&&"s"!==u&&"S"!==u||(d=t.bezierReflectionPoint),d&&(c=d[0],p=d[1]);const f=B(c,p,h,r,o,l,t,i);n=n.concat(f),t.bezierReflectionPoint=[o+(o-h),l+(l-r)]}break}case"Q":case"q":{const s="q"===e.key;if(e.data.length>=4){let a=+e.data[0],h=+e.data[1],r=+e.data[2],o=+e.data[3];s&&(a+=t.x,r+=t.x,h+=t.y,o+=t.y);const l=1*(1+.2*i.roughness),c=1.5*(1+.22*i.roughness);n.push({op:"move",data:[t.x+N(l,i),t.y+N(l,i)]});let p=[r+N(l,i),o+N(l,i)];n.push({op:"qcurveTo",data:[a+N(l,i),h+N(l,i),p[0],p[1]]}),n.push({op:"move",data:[t.x+N(c,i),t.y+N(c,i)]}),p=[r+N(c,i),o+N(c,i)],n.push({op:"qcurveTo",data:[a+N(c,i),h+N(c,i),p[0],p[1]]}),t.setPosition(p[0],p[1]),t.quadReflectionPoint=[r+(r-a),o+(o-h)]}break}case"T":case"t":{const a="t"===e.key;if(e.data.length>=2){let h=+e.data[0],r=+e.data[1];a&&(h+=t.x,r+=t.y);let o=h,l=r;const c=s?s.key:"";let p=null;"q"!==c&&"Q"!==c&&"t"!==c&&"T"!==c||(p=t.quadReflectionPoint),p&&(o=p[0],l=p[1]);const u=1*(1+.2*i.roughness),d=1.5*(1+.22*i.roughness);n.push({op:"move",data:[t.x+N(u,i),t.y+N(u,i)]});let f=[h+N(u,i),r+N(u,i)];n.push({op:"qcurveTo",data:[o+N(u,i),l+N(u,i),f[0],f[1]]}),n.push({op:"move",data:[t.x+N(d,i),t.y+N(d,i)]}),f=[h+N(d,i),r+N(d,i)],n.push({op:"qcurveTo",data:[o+N(d,i),l+N(d,i),f[0],f[1]]}),t.setPosition(f[0],f[1]),t.quadReflectionPoint=[h+(h-o),r+(r-l)]}break}case"A":case"a":{const s="a"===e.key;if(e.data.length>=7){const a=+e.data[0],h=+e.data[1],r=+e.data[2],o=+e.data[3],l=+e.data[4];let p=+e.data[5],u=+e.data[6];if(s&&(p+=t.x,u+=t.y),p===t.x&&u===t.y)break;if(0===a||0===h)n=n.concat(W(t.x,t.y,p,u,i)),t.setPosition(p,u);else for(let e=0;e<1;e++){const e=new c([t.x,t.y],[p,u],[a,h],r,!!o,!!l);let s=e.getNextSegment();for(;s;){const a=B(s.cp1[0],s.cp1[1],s.cp2[0],s.cp2[1],s.to[0],s.to[1],t,i);n=n.concat(a),s=e.getNextSegment()}}}break}}return n}var V=Object.freeze({line:S,linearPath:A,polygon:T,rectangle:function(t,e,s,i,n){return T([[t,e],[t+s,e],[t+s,e+i],[t,e+i]],n)},curve:function(t,e){const s=z(t,1*(1+.2*e.roughness),e),i=z(t,1.5*(1+.22*e.roughness),e);return{type:"path",ops:s.concat(i)}},ellipse:E,arc:function(t,e,s,i,n,a,h,r,o){const l=t,c=e;let p=Math.abs(s/2),u=Math.abs(i/2);p+=N(.01*p,o),u+=N(.01*u,o);let d=n,f=a;for(;d<0;)d+=2*Math.PI,f+=2*Math.PI;f-d>2*Math.PI&&(d=0,f=2*Math.PI);const g=2*Math.PI/o.curveStepCount,y=Math.min(g/2,(f-d)/2),w=q(y,l,c,p,u,d,f,1,o),x=q(y,l,c,p,u,d,f,1.5,o);let b=w.concat(x);return h&&(r?b=(b=b.concat(W(l,c,l+p*Math.cos(d),c+u*Math.sin(d),o))).concat(W(l,c,l+p*Math.cos(f),c+u*Math.sin(f),o)):(b.push({op:"lineTo",data:[l,c]}),b.push({op:"lineTo",data:[l+p*Math.cos(d),c+u*Math.sin(d)]}))),{type:"path",ops:b}},svgPath:function(t,e){t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let s=new l(t);if(e.simplification){const t=new p(s.linearPoints,s.closed).fit(e.simplification);s=new l(t)}let i=[];const n=s.segments||[];for(let t=0;t0?n[t-1]:null,e);a&&a.length&&(i=i.concat(a))}return{type:"path",ops:i}},solidFillPolygon:function(t,e){const s=[];if(t.length){const i=e.maxRandomnessOffset||0,n=t.length;if(n>2){s.push({op:"move",data:[t[0][0]+N(i,e),t[0][1]+N(i,e)]});for(let a=1;a2*Math.PI&&(p=0,u=2*Math.PI);const d=(u-p)/h.curveStepCount,f=[];for(let t=p;t<=u;t+=d)f.push([r+l*Math.cos(t),o+c*Math.sin(t)]);return f.push([r+l*Math.cos(u),o+c*Math.sin(u)]),f.push([r,o]),O(f,h)},randOffset:C,randOffsetWithRange:R,doubleLineOps:L});class F extends e{constructor(t,e){super(t,e),t&&t.workerURL?this.renderer=function(t){let e,h;if("function"==typeof t){const s=Function.prototype.toString;e=h=URL.createObjectURL(new Blob([`${s.call(n)}\n(${s.call(a)})(${s.call(t)})`]))}else"string"==typeof t&&(e=t,0===t.indexOf("blob:")&&(h=e));if(e){let t=new Worker(e);return h&&(t.oURL=h),s(new i(t))}throw"Workly only supports functions, classes, urls"}(t.workerURL):this.renderer=V}async line(t,e,s,i,n){const a=this._options(n);return this._drawable("line",[await this.renderer.line(t,e,s,i,a)],a)}async rectangle(t,e,s,i,n){const a=this._options(n),h=[];if(a.fill){const n=[[t,e],[t+s,e],[t+s,e+i],[t,e+i]];"solid"===a.fillStyle?h.push(await this.renderer.solidFillPolygon(n,a)):h.push(await this.renderer.patternFillPolygon(n,a))}return h.push(await this.renderer.rectangle(t,e,s,i,a)),this._drawable("rectangle",h,a)}async ellipse(t,e,s,i,n){const a=this._options(n),h=[];if(a.fill)if("solid"===a.fillStyle){const n=await this.renderer.ellipse(t,e,s,i,a);n.type="fillPath",h.push(n)}else h.push(await this.renderer.patternFillEllipse(t,e,s,i,a));return h.push(await this.renderer.ellipse(t,e,s,i,a)),this._drawable("ellipse",h,a)}async circle(t,e,s,i){const n=await this.ellipse(t,e,s,s,i);return n.shape="circle",n}async linearPath(t,e){const s=this._options(e);return this._drawable("linearPath",[await this.renderer.linearPath(t,!1,s)],s)}async arc(t,e,s,i,n,a,h=!1,r){const o=this._options(r),l=[];if(h&&o.fill)if("solid"===o.fillStyle){const h=await this.renderer.arc(t,e,s,i,n,a,!0,!1,o);h.type="fillPath",l.push(h)}else l.push(await this.renderer.patternFillArc(t,e,s,i,n,a,o));return l.push(await this.renderer.arc(t,e,s,i,n,a,h,!0,o)),this._drawable("arc",l,o)}async curve(t,e){const s=this._options(e);return this._drawable("curve",[await this.renderer.curve(t,s)],s)}async polygon(t,e){const s=this._options(e),i=[];if(s.fill)if("solid"===s.fillStyle)i.push(await this.renderer.solidFillPolygon(t,s));else{const e=this.computePolygonSize(t),n=[[0,0],[e[0],0],[e[0],e[1]],[0,e[1]]],a=await this.renderer.patternFillPolygon(n,s);a.type="path2Dpattern",a.size=e,a.path=this.polygonPath(t),i.push(a)}return i.push(await this.renderer.linearPath(t,!0,s)),this._drawable("polygon",i,s)}async path(t,e){const s=this._options(e),i=[];if(!t)return this._drawable("path",i,s);if(s.fill)if("solid"===s.fillStyle){const e={type:"path2Dfill",path:t,ops:[]};i.push(e)}else{const e=this.computePathSize(t),n=[[0,0],[e[0],0],[e[0],e[1]],[0,e[1]]],a=await this.renderer.patternFillPolygon(n,s);a.type="path2Dpattern",a.size=e,a.path=t,i.push(a)}return i.push(await this.renderer.svgPath(t,s)),this._drawable("path",i,s)}}const j="undefined"!=typeof document;class G{constructor(t){this.canvas=t,this.ctx=this.canvas.getContext("2d")}draw(t){const e=t.sets||[],s=t.options||this.getDefaultOptions(),i=this.ctx;for(const t of e)switch(t.type){case"path":i.save(),i.strokeStyle=s.stroke,i.lineWidth=s.strokeWidth,this._drawToContext(i,t),i.restore();break;case"fillPath":i.save(),i.fillStyle=s.fill||"",this._drawToContext(i,t),i.restore();break;case"fillSketch":this.fillSketch(i,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 i=t.size,n=e.createElement("canvas"),a=n.getContext("2d"),h=this.computeBBox(t.path);h&&(h.width||h.height)?(n.width=this.canvas.width,n.height=this.canvas.height,a.translate(h.x||0,h.y||0)):(n.width=i[0],n.height=i[1]),this.fillSketch(a,t,s),this.ctx.save(),this.ctx.fillStyle=this.ctx.createPattern(n,"repeat");const r=new Path2D(t.path);this.ctx.fill(r),this.ctx.restore()}else console.error("Cannot render path2Dpattern. No defs/document defined.");break}}}computeBBox(t){if(j)try{const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("width","0"),s.setAttribute("height","0");const i=self.document.createElementNS(e,"path");i.setAttribute("d",t),s.appendChild(i),document.body.appendChild(s);const n=i.getBBox();return document.body.removeChild(s),n}catch(t){}return null}fillSketch(t,e,s){let i=s.fillWeight;i<0&&(i=s.strokeWidth/2),t.save(),t.strokeStyle=s.fill||"",t.lineWidth=i,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()}}class Q extends G{constructor(t,e){super(t),this.gen=new F(e||null,this.canvas)}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}async line(t,e,s,i,n){const a=await this.gen.line(t,e,s,i,n);return this.draw(a),a}async rectangle(t,e,s,i,n){const a=await this.gen.rectangle(t,e,s,i,n);return this.draw(a),a}async ellipse(t,e,s,i,n){const a=await this.gen.ellipse(t,e,s,i,n);return this.draw(a),a}async circle(t,e,s,i){const n=await this.gen.circle(t,e,s,i);return this.draw(n),n}async linearPath(t,e){const s=await this.gen.linearPath(t,e);return this.draw(s),s}async polygon(t,e){const s=await this.gen.polygon(t,e);return this.draw(s),s}async arc(t,e,s,i,n,a,h=!1,r){const o=await this.gen.arc(t,e,s,i,n,a,h,r);return this.draw(o),o}async curve(t,e){const s=await this.gen.curve(t,e);return this.draw(s),s}async path(t,e){const s=await this.gen.path(t,e);return this.draw(s),s}}const Z="undefined"!=typeof document;class H{constructor(t){this.svg=t}get defs(){const t=this.svg.ownerDocument||Z&&document;if(t&&!this._defs){const e=t.createElementNS("http://www.w3.org/2000/svg","defs");this.svg.firstChild?this.svg.insertBefore(e,this.svg.firstChild):this.svg.appendChild(e),this._defs=e}return this._defs||null}draw(t){const e=t.sets||[],s=t.options||this.getDefaultOptions(),i=this.svg.ownerDocument||window.document,n=i.createElementNS("http://www.w3.org/2000/svg","g");for(const t of e){let e=null;switch(t.type){case"path":(e=i.createElementNS("http://www.w3.org/2000/svg","path")).setAttribute("d",this.opsToPath(t)),e.style.stroke=s.stroke,e.style.strokeWidth=s.strokeWidth+"",e.style.fill="none";break;case"fillPath":(e=i.createElementNS("http://www.w3.org/2000/svg","path")).setAttribute("d",this.opsToPath(t)),e.style.stroke="none",e.style.strokeWidth="0",e.style.fill=s.fill||null;break;case"fillSketch":e=this.fillSketch(i,t,s);break;case"path2Dfill":(e=i.createElementNS("http://www.w3.org/2000/svg","path")).setAttribute("d",t.path||""),e.style.stroke="none",e.style.strokeWidth="0",e.style.fill=s.fill||null;break;case"path2Dpattern":if(this.defs){const n=t.size,a=i.createElementNS("http://www.w3.org/2000/svg","pattern"),h=`rough-${Math.floor(Math.random()*(Number.MAX_SAFE_INTEGER||999999))}`;a.setAttribute("id",h),a.setAttribute("x","0"),a.setAttribute("y","0"),a.setAttribute("width","1"),a.setAttribute("height","1"),a.setAttribute("height","1"),a.setAttribute("viewBox",`0 0 ${Math.round(n[0])} ${Math.round(n[1])}`),a.setAttribute("patternUnits","objectBoundingBox");const r=this.fillSketch(i,t,s);a.appendChild(r),this.defs.appendChild(a),(e=i.createElementNS("http://www.w3.org/2000/svg","path")).setAttribute("d",t.path||""),e.style.stroke="none",e.style.strokeWidth="0",e.style.fill=`url(#${h})`}else console.error("Cannot render path2Dpattern. No defs/document defined.")}e&&n.appendChild(e)}return n}fillSketch(t,e,s){let i=s.fillWeight;i<0&&(i=s.strokeWidth/2);const n=t.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d",this.opsToPath(e)),n.style.stroke=s.fill||null,n.style.strokeWidth=i+"",n.style.fill="none",n}}class Y extends H{constructor(t,e){super(t),this.gen=new F(e||null,this.svg)}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t){return this.gen.opsToPath(t)}async line(t,e,s,i,n){const a=await this.gen.line(t,e,s,i,n);return this.draw(a)}async rectangle(t,e,s,i,n){const a=await this.gen.rectangle(t,e,s,i,n);return this.draw(a)}async ellipse(t,e,s,i,n){const a=await this.gen.ellipse(t,e,s,i,n);return this.draw(a)}async circle(t,e,s,i){const n=await this.gen.circle(t,e,s,i);return this.draw(n)}async linearPath(t,e){const s=await this.gen.linearPath(t,e);return this.draw(s)}async polygon(t,e){const s=await this.gen.polygon(t,e);return this.draw(s)}async arc(t,e,s,i,n,a,h=!1,r){const o=await this.gen.arc(t,e,s,i,n,a,h,r);return this.draw(o)}async curve(t,e){const s=await this.gen.curve(t,e);return this.draw(s)}async path(t,e){const s=await this.gen.path(t,e);return this.draw(s)}}return{canvas:(t,e)=>new Q(t,e),svg:(t,e)=>new Y(t,e),generator:(t,e)=>new F(t,e)}}();