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