!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).svg2roughjs={})}(this,(function(t){"use strict";function e(t,e,n){if(t&&t.length){const[r,s]=e,a=Math.PI/180*n,i=Math.cos(a),o=Math.sin(a);for(const e of t){const[t,n]=e;e[0]=(t-r)*i-(n-s)*o+r,e[1]=(t-r)*o+(n-s)*i+s}}}function n(t,e){return t[0]===e[0]&&t[1]===e[1]}function r(t,r,s,a=1){const i=s,o=Math.max(r,.1),l=t[0]&&t[0][0]&&"number"==typeof t[0][0]?[t]:t,h=[0,0];if(i)for(const t of l)e(t,h,i);const u=function(t,e,r){const s=[];for(const e of t){const t=[...e];n(t[0],t[t.length-1])||t.push([t[0][0],t[0][1]]),t.length>2&&s.push(t)}const a=[];e=Math.max(e,.1);const i=[];for(const t of s)for(let e=0;et.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 a;let o=[],l=i[0].ymin,h=0;for(;o.length||i.length;){if(i.length){let t=-1;for(let e=0;el);e++)t=e;i.splice(0,t+1).forEach((t=>{o.push({s:l,edge:t})}))}if(o=o.filter((t=>!(t.edge.ymax<=l))),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))),(1!==r||h%e==0)&&o.length>1)for(let t=0;t=o.length)break;const n=o[t].edge,r=o[e].edge;a.push([[Math.round(n.x),l],[Math.round(r.x),l]])}l+=r,o.forEach((t=>{t.edge.x=t.edge.x+r*t.edge.islope})),h++}return a}(l,o,a);if(i){for(const t of l)e(t,h,-i);!function(t,n,r){const s=[];t.forEach((t=>s.push(...t))),e(s,n,r)}(u,h,-i)}return u}function s(t,e){var n;const s=e.hachureAngle+90;let a=e.hachureGap;a<0&&(a=4*e.strokeWidth),a=Math.round(Math.max(a,.1));let i=1;return e.roughness>=1&&((null===(n=e.randomizer)||void 0===n?void 0:n.next())||Math.random())>.7&&(i=a),r(t,a,s,i||1)}class a{constructor(t){this.helper=t}fillPolygons(t,e){return this._fillPolygons(t,e)}_fillPolygons(t,e){const n=s(t,e);return{type:"fillSketch",ops:this.renderLines(n,e)}}renderLines(t,e){const n=[];for(const r of t)n.push(...this.helper.doubleLineOps(r[0][0],r[0][1],r[1][0],r[1][1],e));return n}}function i(t){const e=t[0],n=t[1];return Math.sqrt(Math.pow(e[0]-n[0],2)+Math.pow(e[1]-n[1],2))}class o extends a{fillPolygons(t,e){let n=e.hachureGap;n<0&&(n=4*e.strokeWidth),n=Math.max(n,.1);const r=s(t,Object.assign({},e,{hachureGap:n})),a=Math.PI/180*e.hachureAngle,o=[],l=.5*n*Math.cos(a),h=.5*n*Math.sin(a);for(const[t,e]of r)i([t,e])&&o.push([[t[0]-l,t[1]+h],[...e]],[[t[0]+l,t[1]-h],[...e]]);return{type:"fillSketch",ops:this.renderLines(o,e)}}}class l extends a{fillPolygons(t,e){const n=this._fillPolygons(t,e),r=Object.assign({},e,{hachureAngle:e.hachureAngle+90}),s=this._fillPolygons(t,r);return n.ops=n.ops.concat(s.ops),n}}class h{constructor(t){this.helper=t}fillPolygons(t,e){const n=s(t,e=Object.assign({},e,{hachureAngle:0}));return this.dotsOnLines(n,e)}dotsOnLines(t,e){const n=[];let r=e.hachureGap;r<0&&(r=4*e.strokeWidth),r=Math.max(r,.1);let s=e.fillWeight;s<0&&(s=e.strokeWidth/2);const a=r/4;for(const o of t){const t=i(o),l=t/r,h=Math.ceil(l)-1,u=t-h*r,c=(o[0][0]+o[1][0])/2-r/4,f=Math.min(o[0][1],o[1][1]);for(let t=0;t{const a=i(t),o=Math.floor(a/(n+r)),l=(a+r-o*(n+r))/2;let h=t[0],u=t[1];h[0]>u[0]&&(h=t[1],u=t[0]);const c=Math.atan((u[1]-h[1])/(u[0]-h[0]));for(let t=0;t{const s=i(t),a=Math.round(s/(2*e));let o=t[0],l=t[1];o[0]>l[0]&&(o=t[1],l=t[0]);const h=Math.atan((l[1]-o[1])/(l[0]-o[0]));for(let t=0;tr%2?t+n:t+e));a.push({key:"C",data:t}),e=t[4],n=t[5];break}case"Q":a.push({key:"Q",data:[...o]}),e=o[2],n=o[3];break;case"q":{const t=o.map(((t,r)=>r%2?t+n:t+e));a.push({key:"Q",data:t}),e=t[2],n=t[3];break}case"A":a.push({key:"A",data:[...o]}),e=o[5],n=o[6];break;case"a":e+=o[5],n+=o[6],a.push({key:"A",data:[o[0],o[1],o[2],o[3],o[4],e,n]});break;case"H":a.push({key:"H",data:[...o]}),e=o[0];break;case"h":e+=o[0],a.push({key:"H",data:[e]});break;case"V":a.push({key:"V",data:[...o]}),n=o[0];break;case"v":n+=o[0],a.push({key:"V",data:[n]});break;case"S":a.push({key:"S",data:[...o]}),e=o[2],n=o[3];break;case"s":{const t=o.map(((t,r)=>r%2?t+n:t+e));a.push({key:"S",data:t}),e=t[2],n=t[3];break}case"T":a.push({key:"T",data:[...o]}),e=o[0],n=o[1];break;case"t":e+=o[0],n+=o[1],a.push({key:"T",data:[e,n]});break;case"Z":case"z":a.push({key:"Z",data:[]}),e=r,n=s}return a}function M(t){const e=[];let n="",r=0,s=0,a=0,i=0,o=0,l=0;for(const{key:h,data:u}of t){switch(h){case"M":e.push({key:"M",data:[...u]}),[r,s]=u,[a,i]=u;break;case"C":e.push({key:"C",data:[...u]}),r=u[4],s=u[5],o=u[2],l=u[3];break;case"L":e.push({key:"L",data:[...u]}),[r,s]=u;break;case"H":r=u[0],e.push({key:"L",data:[r,s]});break;case"V":s=u[0],e.push({key:"L",data:[r,s]});break;case"S":{let t=0,a=0;"C"===n||"S"===n?(t=r+(r-o),a=s+(s-l)):(t=r,a=s),e.push({key:"C",data:[t,a,...u]}),o=u[0],l=u[1],r=u[2],s=u[3];break}case"T":{const[t,a]=u;let i=0,h=0;"Q"===n||"T"===n?(i=r+(r-o),h=s+(s-l)):(i=r,h=s);const c=r+2*(i-r)/3,f=s+2*(h-s)/3,p=t+2*(i-t)/3,d=a+2*(h-a)/3;e.push({key:"C",data:[c,f,p,d,t,a]}),o=i,l=h,r=t,s=a;break}case"Q":{const[t,n,a,i]=u,h=r+2*(t-r)/3,c=s+2*(n-s)/3,f=a+2*(t-a)/3,p=i+2*(n-i)/3;e.push({key:"C",data:[h,c,f,p,a,i]}),o=t,l=n,r=a,s=i;break}case"A":{const t=Math.abs(u[0]),n=Math.abs(u[1]),a=u[2],i=u[3],o=u[4],l=u[5],h=u[6];if(0===t||0===n)e.push({key:"C",data:[r,s,l,h,l,h]}),r=l,s=h;else if(r!==l||s!==h){A(r,s,l,h,t,n,a,i,o).forEach((function(t){e.push({key:"C",data:t})})),r=l,s=h}break}case"Z":e.push({key:"Z",data:[]}),r=a,s=i}n=h}return e}function w(t,e,n){return[t*Math.cos(n)-e*Math.sin(n),t*Math.sin(n)+e*Math.cos(n)]}function A(t,e,n,r,s,a,i,o,l,h){const u=(c=i,Math.PI*c/180);var c;let f=[],p=0,d=0,g=0,m=0;if(h)[p,d,g,m]=h;else{[t,e]=w(t,e,-u),[n,r]=w(n,r,-u);const i=(t-n)/2,h=(e-r)/2;let c=i*i/(s*s)+h*h/(a*a);c>1&&(c=Math.sqrt(c),s*=c,a*=c);const f=s*s,y=a*a,b=f*y-f*h*h-y*i*i,v=f*h*h+y*i*i,x=(o===l?-1:1)*Math.sqrt(Math.abs(b/v));g=x*s*h/a+(t+n)/2,m=x*-a*i/s+(e+r)/2,p=Math.asin(parseFloat(((e-m)/a).toFixed(9))),d=Math.asin(parseFloat(((r-m)/a).toFixed(9))),td&&(p-=2*Math.PI),!l&&d>p&&(d-=2*Math.PI)}let y=d-p;if(Math.abs(y)>120*Math.PI/180){const t=d,e=n,o=r;d=l&&d>p?p+120*Math.PI/180*1:p+120*Math.PI/180*-1,f=A(n=g+s*Math.cos(d),r=m+a*Math.sin(d),e,o,s,a,i,0,l,[d,t,g,m])}y=d-p;const b=Math.cos(p),v=Math.sin(p),x=Math.cos(d),M=Math.sin(d),_=Math.tan(y/4),O=4/3*s*_,S=4/3*a*_,E=[t,e],C=[t+O*v,e-S*b],T=[n+O*M,r-S*x],k=[n,r];if(C[0]=2*E[0]-C[0],C[1]=2*E[1]-C[1],h)return[C,T,k].concat(f);{f=[C,T,k].concat(f);const t=[];for(let e=0;e2){const s=[];for(let e=0;e2*Math.PI&&(p=0,d=2*Math.PI);const g=2*Math.PI/l.curveStepCount,m=Math.min(g/2,(d-p)/2),y=j(m,h,u,c,f,p,d,1,l);if(!l.disableMultiStroke){const t=j(m,h,u,c,f,p,d,1.5,l);y.push(...t)}return i&&(o?y.push(...H(h,u,h+c*Math.cos(p),u+f*Math.sin(p),l),...H(h,u,h+c*Math.cos(d),u+f*Math.sin(d),l)):y.push({op:"lineTo",data:[h,u]},{op:"lineTo",data:[h+c*Math.cos(p),u+f*Math.sin(p)]})),{type:"path",ops:y}}function V(t,e){const n=M(x(v(t))),r=[];let s=[0,0],a=[0,0];for(const{key:t,data:i}of n)switch(t){case"M":a=[i[0],i[1]],s=[i[0],i[1]];break;case"L":r.push(...H(a[0],a[1],i[0],i[1],e)),a=[i[0],i[1]];break;case"C":{const[t,n,s,o,l,h]=i;r.push(...q(t,n,s,o,l,h,a,e)),a=[l,h];break}case"Z":r.push(...H(a[0],a[1],s[0],s[1],e)),a=[s[0],s[1]]}return{type:"path",ops:r}}function R(t,e){const n=[];for(const r of t)if(r.length){const t=e.maxRandomnessOffset||0,s=r.length;if(s>2){n.push({op:"move",data:[r[0][0]+$(t,e),r[0][1]+$(t,e)]});for(let a=1;a500?.4:-.0016668*l+1.233334;let u=s.maxRandomnessOffset||0;u*u*100>o&&(u=l/10);const c=u/2,f=.2+.2*P(s);let p=s.bowing*s.maxRandomnessOffset*(r-e)/200,d=s.bowing*s.maxRandomnessOffset*(t-n)/200;p=$(p,s,h),d=$(d,s,h);const g=[],m=()=>$(c,s,h),y=()=>$(u,s,h),b=s.preserveVertices;return i?g.push({op:"move",data:[t+(b?0:m()),e+(b?0:m())]}):g.push({op:"move",data:[t+(b?0:$(u,s,h)),e+(b?0:$(u,s,h))]}),i?g.push({op:"bcurveTo",data:[p+t+(n-t)*f+m(),d+e+(r-e)*f+m(),p+t+2*(n-t)*f+m(),d+e+2*(r-e)*f+m(),n+(b?0:m()),r+(b?0:m())]}):g.push({op:"bcurveTo",data:[p+t+(n-t)*f+y(),d+e+(r-e)*f+y(),p+t+2*(n-t)*f+y(),d+e+2*(r-e)*f+y(),n+(b?0:y()),r+(b?0:y())]}),g}function U(t,e,n){if(!t.length)return[];const r=[];r.push([t[0][0]+$(e,n),t[0][1]+$(e,n)]),r.push([t[0][0]+$(e,n),t[0][1]+$(e,n)]);for(let s=1;s3){const e=[],a=1-n.curveTightness;s.push({op:"move",data:[t[1][0],t[1][1]]});for(let n=1;n+21&&s.push(n)}else s.push(n);s.push(t[e+3])}else{const r=.5,a=t[e+0],i=t[e+1],o=t[e+2],l=t[e+3],h=Z(a,i,r),u=Z(i,o,r),c=Z(o,l,r),f=Z(h,u,r),p=Z(u,c,r),d=Z(f,p,r);B([a,h,f,d],0,n,s),B([d,p,c,l],0,n,s)}var a,i;return s}function K(t,e){return J(t,0,t.length,e)}function J(t,e,n,r,s){const a=s||[],i=t[e],o=t[n-1];let l=0,h=1;for(let r=e+1;rl&&(l=e,h=r)}return Math.sqrt(l)>r?(J(t,e,h+1,r,a),J(t,h,n,r,a)):(a.length||a.push(i),a.push(o)),a}function tt(t,e=.15,n){const r=[],s=(t.length-1)/3;for(let n=0;n0?J(r,0,r.length,n):r}const et="none";class nt{constructor(t){this.defaultOptions={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,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Math.floor(Math.random()*2**31)}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,e,n){return{shape:t,sets:e||[],options:n||this.defaultOptions}}line(t,e,n,r,s){const a=this._o(s);return this._d("line",[O(t,e,n,r,a)],a)}rectangle(t,e,n,r,s){const a=this._o(s),i=[],o=E(t,e,n,r,a);if(a.fill){const s=[[t,e],[t+n,e],[t+n,e+r],[t,e+r]];"solid"===a.fillStyle?i.push(R([s],a)):i.push(I([s],a))}return a.stroke!==et&&i.push(o),this._d("rectangle",i,a)}ellipse(t,e,n,r,s){const a=this._o(s),i=[],o=T(n,r,a),l=k(t,e,a,o);if(a.fill)if("solid"===a.fillStyle){const n=k(t,e,a,o).opset;n.type="fillPath",i.push(n)}else i.push(I([l.estimatedPoints],a));return a.stroke!==et&&i.push(l.opset),this._d("ellipse",i,a)}circle(t,e,n,r){const s=this.ellipse(t,e,n,n,r);return s.shape="circle",s}linearPath(t,e){const n=this._o(e);return this._d("linearPath",[S(t,!1,n)],n)}arc(t,e,n,r,s,a,i=!1,o){const l=this._o(o),h=[],u=N(t,e,n,r,s,a,i,!0,l);if(i&&l.fill)if("solid"===l.fillStyle){const i=Object.assign({},l);i.disableMultiStroke=!0;const o=N(t,e,n,r,s,a,!0,!1,i);o.type="fillPath",h.push(o)}else h.push(function(t,e,n,r,s,a,i){const o=t,l=e;let h=Math.abs(n/2),u=Math.abs(r/2);h+=$(.01*h,i),u+=$(.01*u,i);let c=s,f=a;for(;c<0;)c+=2*Math.PI,f+=2*Math.PI;f-c>2*Math.PI&&(c=0,f=2*Math.PI);const p=(f-c)/i.curveStepCount,d=[];for(let t=c;t<=f;t+=p)d.push([o+h*Math.cos(t),l+u*Math.sin(t)]);return d.push([o+h*Math.cos(f),l+u*Math.sin(f)]),d.push([o,l]),I([d],i)}(t,e,n,r,s,a,l));return l.stroke!==et&&h.push(u),this._d("arc",h,l)}curve(t,e){const n=this._o(e),r=[],s=C(t,n);if(n.fill&&n.fill!==et)if("solid"===n.fillStyle){const e=C(t,Object.assign(Object.assign({},n),{disableMultiStroke:!0,roughness:n.roughness?n.roughness+n.fillShapeRoughnessGain:0}));r.push({type:"fillPath",ops:this._mergedShape(e.ops)})}else{const e=[],s=t;if(s.length){const t="number"==typeof s[0][0]?[s]:s;for(const r of t)r.length<3?e.push(...r):3===r.length?e.push(...tt(X([r[0],r[0],r[1],r[2]]),10,(1+n.roughness)/2)):e.push(...tt(X(r),10,(1+n.roughness)/2))}e.length&&r.push(I([e],n))}return n.stroke!==et&&r.push(s),this._d("curve",r,n)}polygon(t,e){const n=this._o(e),r=[],s=S(t,!0,n);return n.fill&&("solid"===n.fillStyle?r.push(R([t],n)):r.push(I([t],n))),n.stroke!==et&&r.push(s),this._d("polygon",r,n)}path(t,e){const n=this._o(e),r=[];if(!t)return this._d("path",r,n);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");const s=n.fill&&"transparent"!==n.fill&&n.fill!==et,a=n.stroke!==et,i=!!(n.simplification&&n.simplification<1),o=function(t,e,n){const r=M(x(v(t))),s=[];let a=[],i=[0,0],o=[];const l=()=>{o.length>=4&&a.push(...tt(o,e)),o=[]},h=()=>{l(),a.length&&(s.push(a),a=[])};for(const{key:t,data:e}of r)switch(t){case"M":h(),i=[e[0],e[1]],a.push(i);break;case"L":l(),a.push([e[0],e[1]]);break;case"C":if(!o.length){const t=a.length?a[a.length-1]:i;o.push([t[0],t[1]])}o.push([e[0],e[1]]),o.push([e[2],e[3]]),o.push([e[4],e[5]]);break;case"Z":l(),a.push([i[0],i[1]])}if(h(),!n)return s;const u=[];for(const t of s){const e=K(t,n);e.length&&u.push(e)}return u}(t,1,i?4-4*(n.simplification||1):(1+n.roughness)/2),l=V(t,n);if(s)if("solid"===n.fillStyle)if(1===o.length){const e=V(t,Object.assign(Object.assign({},n),{disableMultiStroke:!0,roughness:n.roughness?n.roughness+n.fillShapeRoughnessGain:0}));r.push({type:"fillPath",ops:this._mergedShape(e.ops)})}else r.push(R(o,n));else r.push(I(o,n));return a&&(i?o.forEach((t=>{r.push(S(t,!1,n))})):r.push(l)),this._d("path",r,n)}opsToPath(t,e){let n="";for(const r of t.ops){const t="number"==typeof e&&e>=0?r.data.map((t=>+t.toFixed(e))):r.data;switch(r.op){case"move":n+=`M${t[0]} ${t[1]} `;break;case"bcurveTo":n+=`C${t[0]} ${t[1]}, ${t[2]} ${t[3]}, ${t[4]} ${t[5]} `;break;case"lineTo":n+=`L${t[0]} ${t[1]} `}}return n.trim()}toPaths(t){const e=t.sets||[],n=t.options||this.defaultOptions,r=[];for(const t of e){let e=null;switch(t.type){case"path":e={d:this.opsToPath(t),stroke:n.stroke,strokeWidth:n.strokeWidth,fill:et};break;case"fillPath":e={d:this.opsToPath(t),stroke:et,strokeWidth:0,fill:n.fill||et};break;case"fillSketch":e=this.fillSketch(t,n)}e&&r.push(e)}return r}fillSketch(t,e){let n=e.fillWeight;return n<0&&(n=e.strokeWidth/2),{d:this.opsToPath(t),stroke:e.fill||et,strokeWidth:n,fill:et}}_mergedShape(t){return t.filter(((t,e)=>0===e||"move"!==t.op))}}class rt{constructor(t,e){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new nt(e)}draw(t){const e=t.sets||[],n=t.options||this.getDefaultOptions(),r=this.ctx,s=t.options.fixedDecimalPlaceDigits;for(const a of e)switch(a.type){case"path":r.save(),r.strokeStyle="none"===n.stroke?"transparent":n.stroke,r.lineWidth=n.strokeWidth,n.strokeLineDash&&r.setLineDash(n.strokeLineDash),n.strokeLineDashOffset&&(r.lineDashOffset=n.strokeLineDashOffset),this._drawToContext(r,a,s),r.restore();break;case"fillPath":{r.save(),r.fillStyle=n.fill||"";const e="curve"===t.shape||"polygon"===t.shape||"path"===t.shape?"evenodd":"nonzero";this._drawToContext(r,a,s,e),r.restore();break}case"fillSketch":this.fillSketch(r,a,n)}}fillSketch(t,e,n){let r=n.fillWeight;r<0&&(r=n.strokeWidth/2),t.save(),n.fillLineDash&&t.setLineDash(n.fillLineDash),n.fillLineDashOffset&&(t.lineDashOffset=n.fillLineDashOffset),t.strokeStyle=n.fill||"",t.lineWidth=r,this._drawToContext(t,e,n.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,e,n,r="nonzero"){t.beginPath();for(const r of e.ops){const e="number"==typeof n&&n>=0?r.data.map((t=>+t.toFixed(n))):r.data;switch(r.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"lineTo":t.lineTo(e[0],e[1])}}"fillPath"===e.type?t.fill(r):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,e,n,r,s){const a=this.gen.line(t,e,n,r,s);return this.draw(a),a}rectangle(t,e,n,r,s){const a=this.gen.rectangle(t,e,n,r,s);return this.draw(a),a}ellipse(t,e,n,r,s){const a=this.gen.ellipse(t,e,n,r,s);return this.draw(a),a}circle(t,e,n,r){const s=this.gen.circle(t,e,n,r);return this.draw(s),s}linearPath(t,e){const n=this.gen.linearPath(t,e);return this.draw(n),n}polygon(t,e){const n=this.gen.polygon(t,e);return this.draw(n),n}arc(t,e,n,r,s,a,i=!1,o){const l=this.gen.arc(t,e,n,r,s,a,i,o);return this.draw(l),l}curve(t,e){const n=this.gen.curve(t,e);return this.draw(n),n}path(t,e){const n=this.gen.path(t,e);return this.draw(n),n}}const st="http://www.w3.org/2000/svg";class at{constructor(t,e){this.svg=t,this.gen=new nt(e)}draw(t){const e=t.sets||[],n=t.options||this.getDefaultOptions(),r=this.svg.ownerDocument||window.document,s=r.createElementNS(st,"g"),a=t.options.fixedDecimalPlaceDigits;for(const i of e){let e=null;switch(i.type){case"path":e=r.createElementNS(st,"path"),e.setAttribute("d",this.opsToPath(i,a)),e.setAttribute("stroke",n.stroke),e.setAttribute("stroke-width",n.strokeWidth+""),e.setAttribute("fill","none"),n.strokeLineDash&&e.setAttribute("stroke-dasharray",n.strokeLineDash.join(" ").trim()),n.strokeLineDashOffset&&e.setAttribute("stroke-dashoffset",`${n.strokeLineDashOffset}`);break;case"fillPath":e=r.createElementNS(st,"path"),e.setAttribute("d",this.opsToPath(i,a)),e.setAttribute("stroke","none"),e.setAttribute("stroke-width","0"),e.setAttribute("fill",n.fill||""),"curve"!==t.shape&&"polygon"!==t.shape||e.setAttribute("fill-rule","evenodd");break;case"fillSketch":e=this.fillSketch(r,i,n)}e&&s.appendChild(e)}return s}fillSketch(t,e,n){let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);const s=t.createElementNS(st,"path");return s.setAttribute("d",this.opsToPath(e,n.fixedDecimalPlaceDigits)),s.setAttribute("stroke",n.fill||""),s.setAttribute("stroke-width",r+""),s.setAttribute("fill","none"),n.fillLineDash&&s.setAttribute("stroke-dasharray",n.fillLineDash.join(" ").trim()),n.fillLineDashOffset&&s.setAttribute("stroke-dashoffset",`${n.fillLineDashOffset}`),s}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,e){return this.gen.opsToPath(t,e)}line(t,e,n,r,s){const a=this.gen.line(t,e,n,r,s);return this.draw(a)}rectangle(t,e,n,r,s){const a=this.gen.rectangle(t,e,n,r,s);return this.draw(a)}ellipse(t,e,n,r,s){const a=this.gen.ellipse(t,e,n,r,s);return this.draw(a)}circle(t,e,n,r){const s=this.gen.circle(t,e,n,r);return this.draw(s)}linearPath(t,e){const n=this.gen.linearPath(t,e);return this.draw(n)}polygon(t,e){const n=this.gen.polygon(t,e);return this.draw(n)}arc(t,e,n,r,s,a,i=!1,o){const l=this.gen.arc(t,e,n,r,s,a,i,o);return this.draw(l)}curve(t,e){const n=this.gen.curve(t,e);return this.draw(n)}path(t,e){const n=this.gen.path(t,e);return this.draw(n)}}var it,ot={canvas:(t,e)=>new rt(t,e),svg:(t,e)=>new at(t,e),generator:t=>new nt(t),newSeed:()=>nt.newSeed()};function lt(t){if(void 0!==t.children)return t.children;let e,n=0;const r=t.childNodes,s=[];for(;e=r[n++];)1===e.nodeType&&s.push(e);return s}function ht(t){const e=t.parentNode;return e&&e.nodeType===Node.ELEMENT_NODE?e:null}function ut(t,e){for(;e.firstChild;)t.append(e.firstChild);return t}function ct(t){if(null===t)return null;const e=/url\('#?(.*?)'\)/.exec(t)||/url\("#?(.*?)"\)/.exec(t)||/url\(#?(.*?)\)/.exec(t);return e&&e.length>1?e[1]:null}t.OutputType=void 0,(it=t.OutputType||(t.OutputType={}))[it.SVG=0]="SVG",it[it.CANVAS=1]="CANVAS";const ft="data-sketchy-clip-path",pt=/[acsqt]/i;function dt(t){if(t.svgSketchDefs)return t.svgSketchDefs;const e=t.svgSketch,n=document.createElementNS("http://www.w3.org/2000/svg","defs");return e.childElementCount>0?e.insertBefore(n,e.firstElementChild):e.appendChild(n),t.svgSketchDefs=n,n}function gt(t){const e=t.getAttribute("points");if(!e)return[];let n;n=e.indexOf(" ")>0?/\s+/g:/,/g;const r=e.split(n),s=[];for(let t=0;t1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t}if(t=qt(t,360),e=qt(e,100),n=qt(n,100),0===e)r=s=a=n;else{var o=n<.5?n*(1+e):n+e-n*e,l=2*n-o;r=i(l,o,t+1/3),s=i(l,o,t),a=i(l,o,t-1/3)}return{r:255*r,g:255*s,b:255*a}}(t.h,r,a),i=!0,o="hsl"),t.hasOwnProperty("a")&&(n=t.a));return n=jt(n),{ok:i,format:t.format||o,r:Math.min(255,Math.max(e.r,0)),g:Math.min(255,Math.max(e.g,0)),b:Math.min(255,Math.max(e.b,0)),a:n}}(t);this._originalInput=t,this._r=n.r,this._g=n.g,this._b=n.b,this._a=n.a,this._roundA=Math.round(100*this._a)/100,this._format=e.format||n.format,this._gradientType=e.gradientType,this._r<1&&(this._r=Math.round(this._r)),this._g<1&&(this._g=Math.round(this._g)),this._b<1&&(this._b=Math.round(this._b)),this._ok=n.ok}function St(t,e,n){t=qt(t,255),e=qt(e,255),n=qt(n,255);var r,s,a=Math.max(t,e,n),i=Math.min(t,e,n),o=(a+i)/2;if(a==i)r=s=0;else{var l=a-i;switch(s=o>.5?l/(2-a-i):l/(a+i),a){case t:r=(e-n)/l+(e>1)+720)%360;--e;)r.h=(r.h+s)%360,a.push(Ot(r));return a}function Ut(t,e){e=e||6;for(var n=Ot(t).toHsv(),r=n.h,s=n.s,a=n.v,i=[],o=1/e;e--;)i.push(Ot({h:r,s:s,v:a})),a=(a+o)%1;return i}Ot.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return!this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var t=this.toRgb();return(299*t.r+587*t.g+114*t.b)/1e3},getLuminance:function(){var t,e,n,r=this.toRgb();return t=r.r/255,e=r.g/255,n=r.b/255,.2126*(t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4))+.7152*(e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4))+.0722*(n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4))},setAlpha:function(t){return this._a=jt(t),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var t=Et(this._r,this._g,this._b);return{h:360*t.h,s:t.s,v:t.v,a:this._a}},toHsvString:function(){var t=Et(this._r,this._g,this._b),e=Math.round(360*t.h),n=Math.round(100*t.s),r=Math.round(100*t.v);return 1==this._a?"hsv("+e+", "+n+"%, "+r+"%)":"hsva("+e+", "+n+"%, "+r+"%, "+this._roundA+")"},toHsl:function(){var t=St(this._r,this._g,this._b);return{h:360*t.h,s:t.s,l:t.l,a:this._a}},toHslString:function(){var t=St(this._r,this._g,this._b),e=Math.round(360*t.h),n=Math.round(100*t.s),r=Math.round(100*t.l);return 1==this._a?"hsl("+e+", "+n+"%, "+r+"%)":"hsla("+e+", "+n+"%, "+r+"%, "+this._roundA+")"},toHex:function(t){return Ct(this._r,this._g,this._b,t)},toHexString:function(t){return"#"+this.toHex(t)},toHex8:function(t){return function(t,e,n,r,s){var a=[Yt(Math.round(t).toString(16)),Yt(Math.round(e).toString(16)),Yt(Math.round(n).toString(16)),Yt(Zt(r))];if(s&&a[0].charAt(0)==a[0].charAt(1)&&a[1].charAt(0)==a[1].charAt(1)&&a[2].charAt(0)==a[2].charAt(1)&&a[3].charAt(0)==a[3].charAt(1))return a[0].charAt(0)+a[1].charAt(0)+a[2].charAt(0)+a[3].charAt(0);return a.join("")}(this._r,this._g,this._b,this._a,t)},toHex8String:function(t){return"#"+this.toHex8(t)},toRgb:function(){return{r:Math.round(this._r),g:Math.round(this._g),b:Math.round(this._b),a:this._a}},toRgbString:function(){return 1==this._a?"rgb("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+")":"rgba("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return{r:Math.round(100*qt(this._r,255))+"%",g:Math.round(100*qt(this._g,255))+"%",b:Math.round(100*qt(this._b,255))+"%",a:this._a}},toPercentageRgbString:function(){return 1==this._a?"rgb("+Math.round(100*qt(this._r,255))+"%, "+Math.round(100*qt(this._g,255))+"%, "+Math.round(100*qt(this._b,255))+"%)":"rgba("+Math.round(100*qt(this._r,255))+"%, "+Math.round(100*qt(this._g,255))+"%, "+Math.round(100*qt(this._b,255))+"%, "+this._roundA+")"},toName:function(){return 0===this._a?"transparent":!(this._a<1)&&(zt[Ct(this._r,this._g,this._b,!0)]||!1)},toFilter:function(t){var e="#"+Tt(this._r,this._g,this._b,this._a),n=e,r=this._gradientType?"GradientType = 1, ":"";if(t){var s=Ot(t);n="#"+Tt(s._r,s._g,s._b,s._a)}return"progid:DXImageTransform.Microsoft.gradient("+r+"startColorstr="+e+",endColorstr="+n+")"},toString:function(t){var e=!!t;t=t||this._format;var n=!1,r=this._a<1&&this._a>=0;return e||!r||"hex"!==t&&"hex6"!==t&&"hex3"!==t&&"hex4"!==t&&"hex8"!==t&&"name"!==t?("rgb"===t&&(n=this.toRgbString()),"prgb"===t&&(n=this.toPercentageRgbString()),"hex"!==t&&"hex6"!==t||(n=this.toHexString()),"hex3"===t&&(n=this.toHexString(!0)),"hex4"===t&&(n=this.toHex8String(!0)),"hex8"===t&&(n=this.toHex8String()),"name"===t&&(n=this.toName()),"hsl"===t&&(n=this.toHslString()),"hsv"===t&&(n=this.toHsvString()),n||this.toHexString()):"name"===t&&0===this._a?this.toName():this.toRgbString()},clone:function(){return Ot(this.toString())},_applyModification:function(t,e){var n=t.apply(null,[this].concat([].slice.call(e)));return this._r=n._r,this._g=n._g,this._b=n._b,this.setAlpha(n._a),this},lighten:function(){return this._applyModification(Rt,arguments)},brighten:function(){return this._applyModification(It,arguments)},darken:function(){return this._applyModification(Lt,arguments)},desaturate:function(){return this._applyModification(kt,arguments)},saturate:function(){return this._applyModification(Nt,arguments)},greyscale:function(){return this._applyModification(Vt,arguments)},spin:function(){return this._applyModification(Pt,arguments)},_applyCombination:function(t,e){return t.apply(null,[this].concat([].slice.call(e)))},analogous:function(){return this._applyCombination(Dt,arguments)},complement:function(){return this._applyCombination(Ft,arguments)},monochromatic:function(){return this._applyCombination(Ut,arguments)},splitcomplement:function(){return this._applyCombination(Ht,arguments)},triad:function(){return this._applyCombination($t,[3])},tetrad:function(){return this._applyCombination($t,[4])}},Ot.fromRatio=function(t,e){if("object"==wt(t)){var n={};for(var r in t)t.hasOwnProperty(r)&&(n[r]="a"===r?t[r]:Qt(t[r]));t=n}return Ot(t,e)},Ot.equals=function(t,e){return!(!t||!e)&&Ot(t).toRgbString()==Ot(e).toRgbString()},Ot.random=function(){return Ot.fromRatio({r:Math.random(),g:Math.random(),b:Math.random()})},Ot.mix=function(t,e,n){n=0===n?0:n||50;var r=Ot(t).toRgb(),s=Ot(e).toRgb(),a=n/100;return Ot({r:(s.r-r.r)*a+r.r,g:(s.g-r.g)*a+r.g,b:(s.b-r.b)*a+r.b,a:(s.a-r.a)*a+r.a})},Ot.readability=function(t,e){var n=Ot(t),r=Ot(e);return(Math.max(n.getLuminance(),r.getLuminance())+.05)/(Math.min(n.getLuminance(),r.getLuminance())+.05)},Ot.isReadable=function(t,e,n){var r,s,a=Ot.readability(t,e);switch(s=!1,(r=function(t){var e,n;e=((t=t||{level:"AA",size:"small"}).level||"AA").toUpperCase(),n=(t.size||"small").toLowerCase(),"AA"!==e&&"AAA"!==e&&(e="AA");"small"!==n&&"large"!==n&&(n="small");return{level:e,size:n}}(n)).level+r.size){case"AAsmall":case"AAAlarge":s=a>=4.5;break;case"AAlarge":s=a>=3;break;case"AAAsmall":s=a>=7}return s},Ot.mostReadable=function(t,e,n){var r,s,a,i,o=null,l=0;s=(n=n||{}).includeFallbackColors,a=n.level,i=n.size;for(var h=0;hl&&(l=r,o=Ot(e[h]));return Ot.isReadable(t,o,{level:a,size:i})||!s?o:(n.includeFallbackColors=!1,Ot.mostReadable(t,["#fff","#000"],n))};var Gt=Ot.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},zt=Ot.hexNames=function(t){var e={};for(var n in t)t.hasOwnProperty(n)&&(e[t[n]]=n);return e}(Gt);function jt(t){return t=parseFloat(t),(isNaN(t)||t<0||t>1)&&(t=1),t}function qt(t,e){(function(t){return"string"==typeof t&&-1!=t.indexOf(".")&&1===parseFloat(t)})(t)&&(t="100%");var n=function(t){return"string"==typeof t&&-1!=t.indexOf("%")}(t);return t=Math.min(e,Math.max(0,parseFloat(t))),n&&(t=parseInt(t*e,10)/100),Math.abs(t-e)<1e-6?1:t%e/parseFloat(e)}function Wt(t){return Math.min(1,Math.max(0,t))}function Xt(t){return parseInt(t,16)}function Yt(t){return 1==t.length?"0"+t:""+t}function Qt(t){return t<=1&&(t=100*t+"%"),t}function Zt(t){return Math.round(255*parseFloat(t)).toString(16)}function Bt(t){return Xt(t)/255}var Kt,Jt,te,ee=(Jt="[\\s|\\(]+("+(Kt="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)")+")[,|\\s]+("+Kt+")[,|\\s]+("+Kt+")\\s*\\)?",te="[\\s|\\(]+("+Kt+")[,|\\s]+("+Kt+")[,|\\s]+("+Kt+")[,|\\s]+("+Kt+")\\s*\\)?",{CSS_UNIT:new RegExp(Kt),rgb:new RegExp("rgb"+Jt),rgba:new RegExp("rgba"+te),hsl:new RegExp("hsl"+Jt),hsla:new RegExp("hsla"+te),hsv:new RegExp("hsv"+Jt),hsva:new RegExp("hsva"+te),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/});function ne(t){return!!ee.CSS_UNIT.exec(t)}const re=/^([+-]?(?:\d+|\d*\.\d+(?:[eE][+-]?\d+)?))([a-z]*|%)$/,se={in:96,cm:96/2.54,mm:96/25.4,pt:96/72,pc:16,px:1},ae=Math.sqrt(2);function ie(t,e,n,r){const{value:s,unit:a}=oe(n);return function(t){return!!se[t]}(a)?function(t,e){var n;const r=null!==(n=se[e])&&void 0!==n?n:1;return t*r}(s,a):function(t,e,n,r,s){var a;const i=null!==(a=t.viewBox)&&void 0!==a?a:{w:0,h:0};if("%"===s)return function(t,e,{w:n,h:r}={w:0,h:0}){const s=e/100;if("x"===t)return s*n;if("y"===t)return s*r;return s*(Math.sqrt(n*n+r*r)/ae)}(n,r,i);if("vw"===s||"vh"===s||"vmin"===s||"vmax"===s)return function(t,e,{w:n,h:r}={w:0,h:0}){var s,a;const i=t/100,o=null!==(s=window.innerWidth)&&void 0!==s?s:n,l=null!==(a=window.innerHeight)&&void 0!==a?a:r;if("vw"===e)return i*o;if("vh"===e)return i*l;if("vmin"===e)return i*Math.min(o,l);if("vmax"===e)return i*Math.max(o,l);throw new Error(`Not a viewport length unit: ${e}`)}(r,s,i);if("em"===s||"ex"===s||"ch"===s||"rem"===s)return function(t,e,n,r){var s;if("rem"===r){const t=document.documentElement,e=oe(getComputedStyle(t).fontSize);return n*("px"===e.unit?e.value:16)}if("ch"===r){const t=function(t){const e=ht(t);if(!e)return 1;const n=document.createElementNS("http://www.w3.org/2000/svg","text");n.style.visibility="hidden",n.appendChild(document.createTextNode("0")),e.appendChild(n);const r=n.getBBox();return e.removeChild(n),r.width}(e);return n*t}const a=null!==(s=bt(t,e,"font-size",t.useElementContext))&&void 0!==s?s:"16px",i=oe(a),o="px"===i.unit?i.value:16;if("em"===r)return n*o;if("ex"===r)return n*o*.5;throw new Error(`Not a font relative unit: ${r}`)}(t,e,r,s);throw new Error(`Unsupported relative length unit: ${s}`)}(t,e,r,s,a)}function oe(t){const e=t.match(re);if(null===e||3!==e.length)throw new Error(`Cannot parse dimension: ${t}`);return{value:parseFloat(e[1]),unit:e[2].toLowerCase()||"px"}}function le(t){if(!t)return!0;const e=t.matrix;return!e||1===e.a&&0===e.b&&0===e.c&&1===e.d&&0===e.e&&0===e.f}function he(t){if(!t)return!0;const e=t.matrix;return!e||1===e.a&&0===e.b&&0===e.c&&1===e.d}function ue(t,e){if(!e)return t;const n=e.matrix;return{x:n.a*t.x+n.c*t.y+n.e,y:n.b*t.x+n.d*t.y+n.f}}function ce(t){return t.transform&&t.transform.baseVal.numberOfItems>0?t.transform.baseVal.consolidate():null}function fe(t,e,n){if(!n)return ce(e);const r=ce(e);if(r){const e=r.matrix,s=n.matrix.multiply(e);return t.sourceSvg.createSVGTransformFromMatrix(s)}return n}function pe(t,e,n){if(e&&e.matrix&&!le(e)){const t=e.matrix;n.transform.baseVal.numberOfItems>0?n.transform.baseVal.getItem(0).setMatrix(t):n.transform.baseVal.appendItem(e)}}function de(t){var e;let n=t.getAttribute("stop-color");if(!n){const r=null!==(e=t.getAttribute("style"))&&void 0!==e?e:"",s=/stop-color:\s?(.*);?/.exec(r);s&&s.length>1&&(n=s[1])}return Ot(n||"white")}function ge(t){const e=t.length;let n=0,r=0,s=0,a=0;return t.forEach((t=>{const e=t.toRgb();n+=e.r*e.r,r+=e.g*e.g,s+=e.b*e.b,a+=e.a})),Ot({r:Math.sqrt(n/e),g:Math.sqrt(r/e),b:Math.sqrt(s/e),a:a/e})}function me(t){const e=t.getAttribute("offset");return e?e.indexOf("%")?parseFloat(e.substring(0,e.length-1)):100*parseFloat(e):0}function ye(t,e){if("solid"===t.roughConfig.fillStyle)return{angle:0,gap:0,weight:0};const{width:n,height:r}=e.getBoundingClientRect(),s=n/r,a=Math.sqrt(n*r),{angle:i,gap:o,weight:l}=function(t){const e={angle:{normal:[-30,-50],horizontal:[-30,-50],vertical:[-30,-50]},weight:{normal:[.5,3],small:[.5,3]},gap:{normal:[3,5],small:[3,5]}},n={angle:{normal:[-30,-50],horizontal:[-50,-75],vertical:[-30,-15]},weight:{normal:[1,3],small:[.5,1.7]},gap:{normal:[2,5],small:[1,3]}};switch(t){default:return n;case"zigzag":case"zigzag-line":return Object.assign(Object.assign({},n),{weight:{normal:[.5,3],small:[.5,2]},gap:{normal:[2,6],small:[2,5]}});case"cross-hatch":return Object.assign(Object.assign({},n),{weight:{normal:[1,3],small:[.5,1.3]},gap:{normal:[4,8],small:[2,5]}});case"dots":return e}}(t.roughConfig.fillStyle);return{angle:be(t,i,s),gap:ve(t,o,a),weight:xe(t,l,a)}}function be({rng:t},{normal:e,horizontal:n,vertical:r},s){if(isFinite(s)){if(s<.25)return t.next(n);if(s>6)return t.next(r)}return t.next(e)}function ve({rng:t},{normal:e,small:n},r){return r<45?t.next(n):t.next(e)}function xe({rng:t},{normal:e,small:n},r){return r<45?t.next(n):t.next(e)}function Me(t,e,n){var r;const s=null!==(r=t.roughConfig.fixedDecimalPlaceDigits)&&void 0!==r?r:15,a=Object.assign({},t.roughConfig);let i=1;if(!le(n)){const t=n.matrix,e=t.a*t.d-t.c*t.b;i=Math.sqrt(Math.abs(e))}const o=vt(t,e,1,t.useElementContext),l=bt(t,e,"fill",t.useElementContext)||"black",h=o*we(e,"fill-opacity");if(l)if(-1!==l.indexOf("url")){const e=Ae(t,l,h);"none"!==e?a.fill=e:delete a.fill}else if("none"===l)delete a.fill;else{const t=Ot(l);t.setAlpha(h),a.fill=t.toString()}const u=bt(t,e,"stroke",t.useElementContext),c=o*we(e,"stroke-opacity");if(u)if(-1!==u.indexOf("url"))a.stroke=Ae(t,u,c);else if("none"===u)a.stroke="none";else{const t=Ot(u);t.setAlpha(c),a.stroke=t.toString()}else a.stroke="none";const f=bt(t,e,"stroke-width",t.useElementContext);if(f){const n=ie(t,e,f,"stroke-width")*i;a.strokeWidth=parseFloat(n.toFixed(s))}else a.strokeWidth=1;const p=bt(t,e,"stroke-dasharray",t.useElementContext);p&&"none"!==p&&(a.strokeLineDash=p.split(/[\s,]+/).filter((t=>t.length>0)).map((n=>{const r=ie(t,e,n,"stroke-dasharray")*i;return Math.max(.5,parseFloat(r.toFixed(s)))})));const d=bt(t,e,"stroke-dashoffset",t.useElementContext);if(d){const n=ie(t,e,d,"stroke-dashoffset")*i;a.strokeLineDashOffset=parseFloat(n.toFixed(s))}if(a.fill&&"none"===a.stroke&&(a.stroke=a.fill,a.strokeWidth=1),t.randomize){const{angle:n,gap:r,weight:i}=ye(t,e);a.hachureAngle=n,a.hachureGap=Math.round(r),a.fillWeight=parseFloat(i.toFixed(s)),void 0===a.disableMultiStroke&&(a.disableMultiStroke=t.rng.next()>.3)}return a}function we(t,e){const n=getComputedStyle(t)[e]||t.getAttribute(e);return n?-1!==n.indexOf("%")?Math.min(1,Math.max(0,parseFloat(n.substring(0,n.length-1))/100)):Math.min(1,Math.max(0,parseFloat(n))):1}function Ae(t,e,n){const r=ct(e);if(!r)return"none";const s=t.idElements[r];if(!s)return"none";if("string"==typeof s)return s;if(s instanceof SVGLinearGradientElement||s instanceof SVGRadialGradientElement){const e=function(t,e){const n=Array.prototype.slice.apply(t.querySelectorAll("stop"));if(0===n.length)return"transparent";if(1===n.length){const t=de(n[0]);return t.setAlpha(e),t.toString()}{const t=10,r=[];let s=null;for(let e=0;e0;)r.push(o),l--;s=a}const a=ge(r);return a.setAlpha(e),a.toString()}}(s,n);return t.idElements[r]=e,e}return"none"}function _e(t){return`${t.x},${t.y}`} /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ var Oe=function(t,e){return(Oe=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function Se(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}Oe(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function Ee(t){var e="";Array.isArray(t)||(t=[t]);for(var n=0;nt.phi1&&(t.phi2-=2*ke),1===t.sweepFlag&&t.phi2r)return[];if(0===r)return[[t*n/(t*t+e*e),e*n/(t*t+e*e)]];var s=Math.sqrt(r);return[[(t*n+e*s)/(t*t+e*e),(e*n-t*s)/(t*t+e*e)],[(t*n-e*s)/(t*t+e*e),(e*n+t*s)/(t*t+e*e)]]}var Re,Ie=Math.PI/180;function Le(t,e,n){return(1-n)*t+n*e}function Pe(t,e,n,r){return t+Math.cos(r/180*ke)*e+Math.sin(r/180*ke)*n}function Fe(t,e,n,r){var s=1e-6,a=e-t,i=n-e,o=3*a+3*(r-n)-6*i,l=6*(i-a),h=3*a;return Math.abs(o)m&&(s.sweepFlag=+!s.sweepFlag),s}))}t.ROUND=function(t){function e(e){return Math.round(e*t)/t}return void 0===t&&(t=1e13),Te(t),function(t){return void 0!==t.x1&&(t.x1=e(t.x1)),void 0!==t.y1&&(t.y1=e(t.y1)),void 0!==t.x2&&(t.x2=e(t.x2)),void 0!==t.y2&&(t.y2=e(t.y2)),void 0!==t.x&&(t.x=e(t.x)),void 0!==t.y&&(t.y=e(t.y)),void 0!==t.rX&&(t.rX=e(t.rX)),void 0!==t.rY&&(t.rY=e(t.rY)),t}},t.TO_ABS=e,t.TO_REL=function(){return s((function(t,e,n){return t.relative||(void 0!==t.x1&&(t.x1-=e),void 0!==t.y1&&(t.y1-=n),void 0!==t.x2&&(t.x2-=e),void 0!==t.y2&&(t.y2-=n),void 0!==t.x&&(t.x-=e),void 0!==t.y&&(t.y-=n),t.relative=!0),t}))},t.NORMALIZE_HVZ=function(t,e,n){return void 0===t&&(t=!0),void 0===e&&(e=!0),void 0===n&&(n=!0),s((function(r,s,a,i,o){if(isNaN(i)&&!(r.type&je.MOVE_TO))throw new Error("path must start with moveto");return e&&r.type&je.HORIZ_LINE_TO&&(r.type=je.LINE_TO,r.y=r.relative?0:a),n&&r.type&je.VERT_LINE_TO&&(r.type=je.LINE_TO,r.x=r.relative?0:s),t&&r.type&je.CLOSE_PATH&&(r.type=je.LINE_TO,r.x=r.relative?i-s:i,r.y=r.relative?o-a:o),r.type&je.ARC&&(0===r.rX||0===r.rY)&&(r.type=je.LINE_TO,delete r.rX,delete r.rY,delete r.xRot,delete r.lArcFlag,delete r.sweepFlag),r}))},t.NORMALIZE_ST=n,t.QT_TO_C=r,t.INFO=s,t.SANITIZE=function(t){void 0===t&&(t=0),Te(t);var e=NaN,n=NaN,r=NaN,a=NaN;return s((function(s,i,o,l,h){var u=Math.abs,c=!1,f=0,p=0;if(s.type&je.SMOOTH_CURVE_TO&&(f=isNaN(e)?0:i-e,p=isNaN(n)?0:o-n),s.type&(je.CURVE_TO|je.SMOOTH_CURVE_TO)?(e=s.relative?i+s.x2:s.x2,n=s.relative?o+s.y2:s.y2):(e=NaN,n=NaN),s.type&je.SMOOTH_QUAD_TO?(r=isNaN(r)?i:2*i-r,a=isNaN(a)?o:2*o-a):s.type&je.QUAD_TO?(r=s.relative?i+s.x1:s.x1,a=s.relative?o+s.y1:s.y2):(r=NaN,a=NaN),s.type&je.LINE_COMMANDS||s.type&je.ARC&&(0===s.rX||0===s.rY||!s.lArcFlag)||s.type&je.CURVE_TO||s.type&je.SMOOTH_CURVE_TO||s.type&je.QUAD_TO||s.type&je.SMOOTH_QUAD_TO){var d=void 0===s.x?0:s.relative?s.x:s.x-i,g=void 0===s.y?0:s.relative?s.y:s.y-o;f=isNaN(r)?void 0===s.x1?f:s.relative?s.x:s.x1-i:r-i,p=isNaN(a)?void 0===s.y1?p:s.relative?s.y:s.y1-o:a-o;var m=void 0===s.x2?0:s.relative?s.x:s.x2-i,y=void 0===s.y2?0:s.relative?s.y:s.y2-o;u(d)<=t&&u(g)<=t&&u(f)<=t&&u(p)<=t&&u(m)<=t&&u(y)<=t&&(c=!0)}return s.type&je.CLOSE_PATH&&u(i-l)<=t&&u(o-h)<=t&&(c=!0),c?[]:s}))},t.MATRIX=a,t.ROTATE=function(t,e,n){void 0===e&&(e=0),void 0===n&&(n=0),Te(t,e,n);var r=Math.sin(t),s=Math.cos(t);return a(s,r,-r,s,e-e*s+n*r,n-e*r-n*s)},t.TRANSLATE=function(t,e){return void 0===e&&(e=0),Te(t,e),a(1,0,0,1,t,e)},t.SCALE=function(t,e){return void 0===e&&(e=t),Te(t,e),a(t,0,0,e,0,0)},t.SKEW_X=function(t){return Te(t),a(1,0,Math.atan(t),1,0,0)},t.SKEW_Y=function(t){return Te(t),a(1,Math.atan(t),0,1,0,0)},t.X_AXIS_SYMMETRY=function(t){return void 0===t&&(t=0),Te(t),a(-1,0,0,1,t,0)},t.Y_AXIS_SYMMETRY=function(t){return void 0===t&&(t=0),Te(t),a(1,0,0,-1,0,t)},t.A_TO_C=function(){return s((function(t,e,n){return je.ARC===t.type?function(t,e,n){var r,s,a,i;t.cX||Ne(t,e,n);for(var o=Math.min(t.phi1,t.phi2),l=Math.max(t.phi1,t.phi2)-o,h=Math.ceil(l/90),u=new Array(h),c=e,f=n,p=0;po.maxX&&(o.maxX=t),to.maxY&&(o.maxY=t),tE&&l($e(n,s.x1,s.x2,s.x,E));for(var f=0,p=Fe(r,s.y1,s.y2,s.y);fE&&h($e(r,s.y1,s.y2,s.y,E))}if(s.type&je.ARC){l(s.x),h(s.y),Ne(s,n,r);for(var d=s.xRot/180*Math.PI,g=Math.cos(d)*s.rX,m=Math.sin(d)*s.rX,y=-Math.sin(d)*s.rY,b=Math.cos(d)*s.rY,v=s.phi1s.phi2?[s.phi2+360,s.phi1+360]:[s.phi2,s.phi1],x=v[0],M=v[1],w=function(t){var e=t[0],n=t[1],r=180*Math.atan2(n,e)/Math.PI;return rx&&Ex&&El)throw new SyntaxError('Expected positive number, got "'+l+'" at index "'+s+'"')}else if((3===this.curArgs.length||4===this.curArgs.length)&&"0"!==this.curNumber&&"1"!==this.curNumber)throw new SyntaxError('Expected a flag, got "'+this.curNumber+'" at index "'+s+'"');this.curArgs.push(l),this.curArgs.length===qe[this.curCommandType]&&(je.HORIZ_LINE_TO===this.curCommandType?r({type:je.HORIZ_LINE_TO,relative:this.curCommandRelative,x:l}):je.VERT_LINE_TO===this.curCommandType?r({type:je.VERT_LINE_TO,relative:this.curCommandRelative,y:l}):this.curCommandType===je.MOVE_TO||this.curCommandType===je.LINE_TO||this.curCommandType===je.SMOOTH_QUAD_TO?(r({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),je.MOVE_TO===this.curCommandType&&(this.curCommandType=je.LINE_TO)):this.curCommandType===je.CURVE_TO?r({type:je.CURVE_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x2:this.curArgs[2],y2:this.curArgs[3],x:this.curArgs[4],y:this.curArgs[5]}):this.curCommandType===je.SMOOTH_CURVE_TO?r({type:je.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===je.QUAD_TO?r({type:je.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===je.ARC&&r({type:je.ARC,relative:this.curCommandRelative,rX:this.curArgs[0],rY:this.curArgs[1],xRot:this.curArgs[2],lArcFlag:this.curArgs[3],sweepFlag:this.curArgs[4],x:this.curArgs[5],y:this.curArgs[6]})),this.curNumber="",this.curNumberHasExpDigits=!1,this.curNumberHasExp=!1,this.curNumberHasDecimal=!1,this.canParseCommandOrComma=!0}if(!Ue(a))if(","===a&&this.canParseCommandOrComma)this.canParseCommandOrComma=!1;else if("+"!==a&&"-"!==a&&"."!==a)if(o)this.curNumber=a,this.curNumberHasDecimal=!1;else{if(0!==this.curArgs.length)throw new SyntaxError("Unterminated command at index "+s+".");if(!this.canParseCommandOrComma)throw new SyntaxError('Unexpected character "'+a+'" at index '+s+". Command cannot follow comma");if(this.canParseCommandOrComma=!1,"z"!==a&&"Z"!==a)if("h"===a||"H"===a)this.curCommandType=je.HORIZ_LINE_TO,this.curCommandRelative="h"===a;else if("v"===a||"V"===a)this.curCommandType=je.VERT_LINE_TO,this.curCommandRelative="v"===a;else if("m"===a||"M"===a)this.curCommandType=je.MOVE_TO,this.curCommandRelative="m"===a;else if("l"===a||"L"===a)this.curCommandType=je.LINE_TO,this.curCommandRelative="l"===a;else if("c"===a||"C"===a)this.curCommandType=je.CURVE_TO,this.curCommandRelative="c"===a;else if("s"===a||"S"===a)this.curCommandType=je.SMOOTH_CURVE_TO,this.curCommandRelative="s"===a;else if("q"===a||"Q"===a)this.curCommandType=je.QUAD_TO,this.curCommandRelative="q"===a;else if("t"===a||"T"===a)this.curCommandType=je.SMOOTH_QUAD_TO,this.curCommandRelative="t"===a;else{if("a"!==a&&"A"!==a)throw new SyntaxError('Unexpected character "'+a+'" at index '+s+".");this.curCommandType=je.ARC,this.curCommandRelative="a"===a}else e.push({type:je.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1}else this.curNumber=a,this.curNumberHasDecimal="."===a}else this.curNumber+=a,this.curNumberHasDecimal=!0;else this.curNumber+=a;else this.curNumber+=a,this.curNumberHasExp=!0;else this.curNumber+=a,this.curNumberHasExpDigits=this.curNumberHasExp}return e},e.prototype.transform=function(t){return Object.create(this,{parse:{value:function(e,n){void 0===n&&(n=[]);for(var r=0,s=Object.getPrototypeOf(this).parse.call(this,e);r1){let i=o.orientAngle.baseVal.value;const l=n[1],h=o.getAttribute("orient");if("auto"===h||"auto-start-reverse"===h){const t="auto"===h?0:180,e=n[n.length-2];if(Ye(n))i=Qe(e,a,l)-t;else{i=Ze({x:1,y:0},{x:l.x-s.x,y:l.y-s.y})-t}}const u=t.sourceSvg.createSVGMatrix().translate(s.x,s.y).rotate(i).scale(Xe(t,o,e)),c=r?r.matrix.multiply(u):u,f=t.sourceSvg.createSVGTransformFromMatrix(c);t.processElement(t,o,f)}const l=ct(e.getAttribute("marker-end")),h=l?t.idElements[l]:null;if(h){let s=h.orientAngle.baseVal.value;if(n.length>1){const t=h.getAttribute("orient");if("auto"===t||"auto-start-reverse"===t){const t=n[n.length-2];if(Ye(n)){s=Qe(t,a,n[1])}else{s=Ze({x:1,y:0},{x:a.x-t.x,y:a.y-t.y})}}}const i=t.sourceSvg.createSVGMatrix().translate(a.x,a.y).rotate(s).scale(Xe(t,h,e)),o=r?r.matrix.multiply(i):i,l=t.sourceSvg.createSVGTransformFromMatrix(o);t.processElement(t,h,l)}const u=ct(e.getAttribute("marker-mid")),c=u?t.idElements[u]:null;if(c&&n.length>2)for(let s=0;s{const t=document.createElementNS("http://www.w3.org/2000/svg","rect");return t.x.baseVal.value=n,t.y.baseVal.value=r,t.width.baseVal.value=s,t.height.baseVal.value=a,t}))}function Ke(t,e,n,r){const s=ct(n);if(!s)return;const a=t.idElements[s];if(!a)return;const i=dt(t),o=`${s}_${i.childElementCount}`,l=document.createElementNS("http://www.w3.org/2000/svg","clipPath");l.id=o,function(t,e){if("g"!==t.tagName)return void t.setAttribute(ft,e);const n=[],r=lt(t);for(let t=r.length-1;t>=0;t--)n.push(r[t]);for(;n.length>0;){const t=n.pop();t.setAttribute(ft,e);const r=lt(t);for(let t=r.length-1;t>=0;t--)n.push(r[t])}}(e,o);const h=[],u=lt(a);for(let e=u.length-1;e>=0;e--){const n=u[e],s=fe(t,n,r);h.push({element:n,transform:s})}for(;h.length>0;){const{element:e,transform:n}=h.pop();try{Je(t,e,l,n)}catch(t){console.error(t)}if("defs"===e.tagName||"svg"===e.tagName||"clipPath"===e.tagName||"text"===e.tagName)continue;const r=lt(e);for(let e=r.length-1;e>=0;e--){const s=r[e],a=fe(t,s,n);h.push({element:s,transform:a})}}l.childNodes.length>0&&i.appendChild(l)}function Je(t,e,n,r){switch(e.tagName){case"rect":!function(t,e,n,r){const s=e.x.baseVal.value,a=e.y.baseVal.value,i=e.width.baseVal.value,o=e.height.baseVal.value;if(0===i||0===o)return;const l=e.hasAttribute("rx")?e.rx.baseVal.value:null,h=e.hasAttribute("ry")?e.ry.baseVal.value:null,u=document.createElementNS("http://www.w3.org/2000/svg","rect");u.x.baseVal.value=s,u.y.baseVal.value=a,u.width.baseVal.value=i,u.height.baseVal.value=o,l&&(u.rx.baseVal.value=l),h&&(u.ry.baseVal.value=h),pe(0,r,u),n.appendChild(u)}(0,e,n,r);break;case"circle":!function(t,e,n,r){const s=e.cx.baseVal.value,a=e.cy.baseVal.value,i=e.r.baseVal.value;if(0===i)return;const o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.cx.baseVal.value=s,o.cy.baseVal.value=a,o.r.baseVal.value=i,pe(0,r,o),n.appendChild(o)}(0,e,n,r);break;case"ellipse":!function(t,e,n,r){const s=e.cx.baseVal.value,a=e.cy.baseVal.value,i=e.rx.baseVal.value,o=e.ry.baseVal.value;if(0===i||0===o)return;const l=document.createElementNS("http://www.w3.org/2000/svg","ellipse");l.cx.baseVal.value=s,l.cy.baseVal.value=a,l.rx.baseVal.value=i,l.ry.baseVal.value=o,pe(0,r,l),n.appendChild(l)}(0,e,n,r);break;case"polygon":!function(t,e,n,r){const s=document.createElementNS("http://www.w3.org/2000/svg","polygon");s.setAttribute("points",e.getAttribute("points")),pe(0,r,s),n.appendChild(s)}(0,e,n,r);break;case"path":!function(t,e,n,r){const s=document.createElementNS("http://www.w3.org/2000/svg","path");s.setAttribute("d",e.getAttribute("d")),pe(0,r,s),n.appendChild(s)}(0,e,n,r)}}function tn(t,e,n){const r=document.createElementNS("http://www.w3.org/2000/svg","g");r.setAttribute("class","text-container"),pe(0,n,r);const s=e.cloneNode(!0);s.transform.baseVal.numberOfItems>0&&s.transform.baseVal.clear(),s.removeAttribute("clip-path");const{cssFont:a,fontSize:i}=function(t,e,n=!1){const r={};let s="";const a=bt(t,e,"font-style",t.useElementContext);a&&(s+=n?`font-style: ${a};`:a,r.fontStyle=a);const i=bt(t,e,"font-weight",t.useElementContext);i&&(s+=n?`font-weight: ${i};`:` ${i}`,r.fontWeight=i);const o=bt(t,e,"font-size",t.useElementContext);o&&(s+=n?`font-size: ${o};`:` ${o}`,r.fontSize=o);if(t.fontFamily)s+=n?`font-family: ${t.fontFamily};`:` ${t.fontFamily}`,r.fontFamiliy=t.fontFamily;else{const a=bt(t,e,"font-family",t.useElementContext);a&&(s+=n?`font-family: ${a};`:` ${a}`,r.fontFamiliy=a)}return s=s.trim(),Object.assign(Object.assign({},r),{cssFont:s})}(t,e,!0);if(s.setAttribute("style",function(...t){let e="";t=t.filter((t=>null!==t));for(const n of t)e.length>0&&";"!==e[e.length-1]&&(e+=";"),e+=n;return e}(s.getAttribute("style"),a)),nn(t,e,s),s.childElementCount>0){const n=lt(s),r=lt(e);for(let e=0;e=0;e--){const r=p[e];if(r instanceof SVGSymbolElement||r instanceof SVGMarkerElement)continue;const s=fe(t,r,n);o.push({element:r,transform:s,viewBox:l})}}else o.push({element:e,transform:n,viewBox:l});for(;o.length>0;){const{element:e,transform:n,viewBox:r}=o.pop();try{t.viewBox=r,sn(t,e,n)}catch(t){console.error(t)}if("defs"===e.tagName||"symbol"===e.tagName||"marker"===e.tagName||"svg"===e.tagName||"clipPath"===e.tagName)continue;const s=lt(e);for(let e=s.length-1;e>=0;e--){const a=s[e],i=fe(t,a,n);o.push({element:a,transform:i,viewBox:r})}}}function sn(t,e,n){if(function(t){const e=t.style;return!!e&&("none"===e.display||"hidden"===e.visibility)}(e))return;const r=e.getAttribute("clip-path");switch(r&&Ke(t,e,r,n),e.tagName){case"svg":case"symbol":!function(t,e,n){let r=parseFloat(e.getAttribute("width")),s=parseFloat(e.getAttribute("height"));(isNaN(r)||isNaN(s))&&(r=s=void 0),rn(t,e,n,r,s)}(t,e,n);break;case"rect":!function(t,e,n){const r=e.x.baseVal.value,s=e.y.baseVal.value,a=e.width.baseVal.value,i=e.height.baseVal.value;if(0===a||0===i)return;let o=e.hasAttribute("rx")?Math.min(Math.max(0,e.rx.baseVal.value),a/2):null,l=e.hasAttribute("ry")?Math.min(Math.max(0,e.ry.baseVal.value),i/2):null;null===o&&null===l||(o=null===o?l:o,l=null===l?o:l);const h=ue({x:r,y:s},n),u=ue({x:r+a,y:s+i},n),c=u.x-h.x,f=u.y-h.y,p={x:h.x,y:h.y,w:c,h:f};if(!le(n)&&!he(n)||o||l){let h="";if(null!==o&&null!==l){const t=4/3*(Math.sqrt(2)-1),e=ue({x:r+o,y:s},n);h+=`M ${_e(e)}`,h+=`L ${_e(ue({x:r+a-o,y:s},n))}`;const u=ue({x:r+a-o+t*o,y:s},n),c=ue({x:r+a,y:s+t*l},n),f=ue({x:r+a,y:s+l},n);h+=`C ${_e(u)} ${_e(c)} ${_e(f)}`,h+=`L ${_e(ue({x:r+a,y:s+i-l},n))}`;const p=ue({x:r+a,y:s+i-l+t*l},n),d=ue({x:r+a-t*o,y:s+i},n),g=ue({x:r+a-o,y:s+i},n);h+=`C ${_e(p)} ${_e(d)} ${_e(g)}`,h+=`L ${_e(ue({x:r+o,y:s+i},n))}`;const m=ue({x:r+o-t*o,y:s+i},n),y=ue({x:r,y:s+i-t*l},n),b=ue({x:r,y:s+i-l},n);h+=`C ${_e(m)} ${_e(y)} ${_e(b)}`,h+=`L ${_e(ue({x:r,y:s+l},n))}`;const v=ue({x:r,y:s+t*l},n),x=ue({x:r+t*o,y:s},n);h+=`C ${_e(v)} ${_e(x)} ${_e(e)}`,h+="z"}else{const t=ue({x:r,y:s},n),e=ue({x:r+a,y:s},n),o=ue({x:r+a,y:s+i},n),l=ue({x:r,y:s+i},n);h+=`M ${_e(t)}`,h+=`L ${_e(e)}`,h+=`L ${_e(o)}`,h+=`L ${_e(l)}`,h+="z"}const u=yt(t,h,Me(t,e,n));Be(t,e,p),mt(t,e,u)}else{const r=t.rc.rectangle(p.x,p.y,p.w,p.h,Me(t,e,n));Be(t,e,p),mt(t,e,r)}}(t,e,n);break;case"path":!function(t,e,n){const r=e.getAttribute("d"),s=new je(r).toAbs().transform(Re.NORMALIZE_HVZ()).transform(Re.NORMALIZE_ST()),a=new je(s.commands.map((t=>Object.assign({},t))));n&&a.transform(Re.MATRIX(n.matrix.a,n.matrix.b,n.matrix.c,n.matrix.d,n.matrix.e,n.matrix.f));const i=Ee(a.commands);if(-1!==i.indexOf("undefined"))return void console.error("broken path data");const o=yt(t,i,Me(t,e,n));xt(t,e,(()=>{const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",i),t})),mt(t,e,o);const l=[];let h;s.commands.forEach((t=>{switch(t.type){case je.MOVE_TO:{const e={x:t.x,y:t.y};l.push(e),h=e;break}case je.LINE_TO:case je.QUAD_TO:case je.SMOOTH_QUAD_TO:case je.CURVE_TO:case je.SMOOTH_CURVE_TO:case je.ARC:l.push({x:t.x,y:t.y});break;case je.HORIZ_LINE_TO:l.push({x:t.x,y:0});break;case je.VERT_LINE_TO:l.push({x:0,y:t.y});break;case je.CLOSE_PATH:h&&l.push(h)}})),We(t,e,l,n)}(t,e,n);break;case"use":!function(t,e,n){let r=e.href.baseVal;r.startsWith("#")&&(r=r.substring(1));const s=t.idElements[r];if(s){let r,a;e.getAttribute("width")&&e.getAttribute("height")&&(r=e.width.baseVal.value,a=e.height.baseVal.value);const i=e.x.baseVal.value,o=e.y.baseVal.value;let l=t.sourceSvg.createSVGMatrix().translate(i,o);l=n?n.matrix.multiply(l):l;const h=t.sourceSvg.createSVGTransformFromMatrix(l);if(t.useElementContext){const n={root:e,referenced:s,parentContext:Object.assign({},t.useElementContext)};t.useElementContext=n}else t.useElementContext={root:e,referenced:s,parentContext:null};t.processElement(t,s,fe(t,s,h),r,a),t.useElementContext.parentContext?t.useElementContext=t.useElementContext.parentContext:t.useElementContext=null}}(t,e,n);break;case"line":!function(t,e,n){const r={x:e.x1.baseVal.value,y:e.y1.baseVal.value},s={x:e.x2.baseVal.value,y:e.y2.baseVal.value},{x:a,y:i}=ue(r,n),{x:o,y:l}=ue(s,n);if(a===o&&i===l)return;const h=t.rc.line(a,i,o,l,Me(t,e,n));xt(t,e,(()=>{const t=document.createElementNS("http://www.w3.org/2000/svg","line");return t.x1.baseVal.value=a,t.y1.baseVal.value=i,t.x2.baseVal.value=o,t.y2.baseVal.value=l,t})),mt(t,e,h),We(t,e,[r,s],n)}(t,e,n);break;case"circle":!function(t,e,n){const r=e.cx.baseVal.value,s=e.cy.baseVal.value,a=e.r.baseVal.value;if(0===a)return;const i=ue({x:r,y:s},n),o=ue({x:r+a,y:s+a},n).x-i.x;let l;if(le(n)||he(n))l=t.rc.circle(i.x,i.y,2*o,Object.assign(Object.assign({},Me(t,e,n)),{preserveVertices:!0}));else{const i=4/3*(Math.sqrt(2)-1),o=ue({x:r+a,y:s},n),h=ue({x:r,y:s+a},n),u=ue({x:r-a,y:s},n),c=ue({x:r,y:s-a},n),f=ue({x:r+a,y:s+i*a},n),p=ue({x:r+i*a,y:s+a},n),d=ue({x:r-a,y:s+i*a},n),g=ue({x:r-i*a,y:s-a},n),m=ue({x:r+a,y:s-i*a},n);l=yt(t,`M ${_e(o)} C ${_e(f)} ${_e(p)} ${_e(h)} S ${_e(d)} ${_e(u)} S ${_e(g)} ${_e(c)} S ${_e(m)} ${_e(o)}z`,Me(t,e,n))}xt(t,e,(()=>{const t=document.createElementNS("http://www.w3.org/2000/svg","circle");return t.cx.baseVal.value=i.x,t.cy.baseVal.value=i.y,t.r.baseVal.value=o,t})),mt(t,e,l)}(t,e,n);break;case"ellipse":!function(t,e,n){const r=e.cx.baseVal.value,s=e.cy.baseVal.value,a=e.rx.baseVal.value,i=e.ry.baseVal.value;if(0===a||0===i)return;const o=ue({x:r,y:s},n),l=ue({x:r+a,y:s+i},n),h=l.x-o.x,u=l.y-o.y;let c;if(le(n)||he(n))c=t.rc.ellipse(o.x,o.y,2*h,2*u,Object.assign(Object.assign({},Me(t,e,n)),{preserveVertices:!0}));else{const o=4/3*(Math.sqrt(2)-1),l=ue({x:r+a,y:s},n),h=ue({x:r,y:s+i},n),u=ue({x:r-a,y:s},n),f=ue({x:r,y:s-i},n),p=ue({x:r+a,y:s+o*i},n),d=ue({x:r+o*a,y:s+i},n),g=ue({x:r-a,y:s+o*i},n),m=ue({x:r-o*a,y:s-i},n),y=ue({x:r+a,y:s-o*i},n);c=yt(t,`M ${_e(l)} C ${_e(p)} ${_e(d)} ${_e(h)} S ${_e(g)} ${_e(u)} S ${_e(m)} ${_e(f)} S ${_e(y)} ${_e(l)}z`,Me(t,e,n))}xt(t,e,(()=>{const t=document.createElementNS("http://www.w3.org/2000/svg","ellipse");return t.cx.baseVal.value=o.x,t.cy.baseVal.value=o.y,t.rx.baseVal.value=h,t.ry.baseVal.value=u,t})),mt(t,e,c)}(t,e,n);break;case"polyline":!function(t,e,n){const r=gt(e),s=r.map((t=>{const e=ue(t,n);return[e.x,e.y]})),a=Me(t,e,n);if(xt(t,e,(()=>{const t=document.createElementNS("http://www.w3.org/2000/svg","polyline");return t.setAttribute("points",s.join(" ")),t})),a.fill&&"none"!==a.fill){const n=Object.assign(Object.assign({},a),{stroke:"none"});mt(t,e,t.rc.polygon(s,n))}mt(t,e,t.rc.linearPath(s,a)),We(t,e,r,n)}(t,e,n);break;case"polygon":!function(t,e,n){const r=gt(e),s=r.map((t=>{const e=ue(t,n);return[e.x,e.y]})),a=t.rc.polygon(s,Me(t,e,n));xt(t,e,(()=>{const t=document.createElementNS("http://www.w3.org/2000/svg","polygon");return t.setAttribute("points",s.join(" ")),t})),mt(t,e,a),r.length>0&&(r.push(r[0]),We(t,e,r,n))}(t,e,n);break;case"text":tn(t,e,n);break;case"image":!function(t,e,n){const r=e.href.baseVal,s=e.x.baseVal.value,a=e.y.baseVal.value;let i,o;if(e.getAttribute("width")&&e.getAttribute("height")&&(i=e.width.baseVal.value,o=e.height.baseVal.value),r.startsWith("data:")&&-1!==r.indexOf("image/svg+xml")){const e=/^data:([^,]*),(.*)/.exec(r);if(e&&e.length>2){const r=e[1];let l=e[2];const h=-1!==r.indexOf("base64"),u=-1!==r.indexOf("utf8");h&&(l=atob(l)),u||(l=decodeURIComponent(l));const c=(new DOMParser).parseFromString(l,"image/svg+xml").firstChild;let f=t.sourceSvg.createSVGMatrix().translate(s,a);f=n?n.matrix.multiply(f):f,t.processElement(t,c,t.sourceSvg.createSVGTransformFromMatrix(f),i,o)}}else{const r=e.cloneNode(),s=document.createElementNS("http://www.w3.org/2000/svg","g");pe(0,n,s),s.appendChild(r),mt(t,e,s)}}(t,e,n);break;case"foreignObject":!function(t,e,n){const r=e.cloneNode(!0),s=document.createElementNS("http://www.w3.org/2000/svg","g"),a=["color","font-family","font-size","font-style","font-variant","font-weight"],i=getComputedStyle(e);for(const t of a)s.style.setProperty(t,i.getPropertyValue(t));r.transform.baseVal.clear(),pe(0,n,s),s.appendChild(r),mt(t,r,s)}(t,e,n)}}class an{constructor(t){this.rng=t?new p(t):null}next(t){var e,n;const r=null!==(n=null===(e=this.rng)||void 0===e?void 0:e.next())&&void 0!==n?n:Math.random();if(t){const e=t[0];return r*(t[1]-e)+e}return r}}t.Svg2Roughjs=class{set svg(t){this.$svg!==t&&(this.$svg=t,this.sourceSvgChanged())}get svg(){return this.$svg}set outputType(e){if(this.$outputType===e)return;if(e===t.OutputType.CANVAS&&this.outputElement instanceof SVGSVGElement||e===t.OutputType.SVG&&this.outputElement instanceof HTMLCanvasElement)throw new Error(`Output format ${e} incompatible with given output element ${this.outputElement.tagName}`);this.$outputType=e}get outputType(){return this.$outputType}set roughConfig(t){void 0===t.fixedDecimalPlaceDigits&&(t.fixedDecimalPlaceDigits=3),this.$roughConfig=t}get roughConfig(){return this.$roughConfig}constructor(e,n=t.OutputType.SVG,r={}){if(this.backgroundColor=null,this.fontFamily="Comic Sans MS, cursive",this.randomize=!0,this.seed=null,this.sketchPatterns=!0,this.pencilFilter=!1,this.width=0,this.height=0,this.$roughConfig={},this.idElements={},this.lastResult=null,!e)throw new Error("No target provided");const s="string"==typeof e?document.querySelector(e):e;if(!s)throw new Error("Could not find target in document");this.roughConfig=r,this.outputElement=s,s instanceof HTMLCanvasElement?this.$outputType=t.OutputType.CANVAS:s instanceof SVGSVGElement?this.$outputType=t.OutputType.SVG:this.$outputType=n}sketch(e=!1){var n,r;if(!this.svg)return Promise.resolve(null);e&&this.sourceSvgChanged();const s=this.prepareRenderContainer(),a=this.createRenderContext(s);if(this.pencilFilter){dt(a).appendChild(function(){const t=document.createElementNS("http://www.w3.org/2000/svg","filter");t.setAttribute("id","pencilTextureFilter"),t.setAttribute("x","0%"),t.setAttribute("y","0%"),t.setAttribute("width","100%"),t.setAttribute("height","100%"),t.setAttribute("filterUnits","objectBoundingBox");const e=document.createElementNS("http://www.w3.org/2000/svg","feTurbulence");e.setAttribute("type","fractalNoise"),e.setAttribute("baseFrequency","2"),e.setAttribute("numOctaves","5"),e.setAttribute("stitchTiles","stitch"),e.setAttribute("result","f1"),t.appendChild(e);const n=document.createElementNS("http://www.w3.org/2000/svg","feColorMatrix");n.setAttribute("type","matrix"),n.setAttribute("values","0 0 0 0 0, 0 0 0 0 0, 0 0 0 0 0, 0 0 0 -1.5 1.5"),n.setAttribute("result","f2"),t.appendChild(n);const r=document.createElementNS("http://www.w3.org/2000/svg","feComposite");return r.setAttribute("operator","in"),r.setAttribute("in","SourceGraphic"),r.setAttribute("in2","f2"),r.setAttribute("result","f3"),t.appendChild(r),t}())}if(a.processElement(a,this.svg,null,this.width,this.height),this.outputElement instanceof SVGSVGElement)return Promise.resolve(this.outputElement);if(this.outputElement instanceof HTMLCanvasElement)return this.drawToCanvas(a,this.outputElement);if(null===(r=null===(n=this.lastResult)||void 0===n?void 0:n.parentNode)||void 0===r||r.removeChild(this.lastResult),this.outputType===t.OutputType.SVG){const t=a.svgSketch;return this.outputElement.appendChild(t),this.lastResult=t,Promise.resolve(t)}{const t=document.createElement("canvas");return this.outputElement.appendChild(t),this.lastResult=t,this.drawToCanvas(a,t)}}createRenderContext(t){if(!this.svg)throw new Error("No source SVG set yet.");let e=this.roughConfig;return null!==this.seed&&(e=Object.assign({seed:this.seed},e)),{rc:ot.svg(t,{options:e}),roughConfig:this.roughConfig,fontFamily:this.fontFamily,pencilFilter:this.pencilFilter,randomize:this.randomize,rng:new an(this.seed),sketchPatterns:this.sketchPatterns,idElements:this.idElements,sourceSvg:this.svg,svgSketch:t,svgSketchIsInDOM:document.body.contains(t),styleSheets:Array.from(this.svg.querySelectorAll("style")).map((t=>t.sheet)).filter((t=>null!==t)),processElement:rn}}drawToCanvas(t,e){e.width=this.width,e.height=this.height;const n=e.getContext("2d");return n.clearRect(0,0,this.width,this.height),new Promise((r=>{const s=(new XMLSerializer).serializeToString(t.svgSketch),a=new Image;a.onload=function(){n.drawImage(this,0,0),r(e)},a.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(s)}`}))}prepareRenderContainer(){let t,e;for(t=this.outputElement instanceof SVGSVGElement?this.outputElement:document.createElementNS("http://www.w3.org/2000/svg","svg"),t.setAttribute("xmlns","http://www.w3.org/2000/svg"),t.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink");t.firstChild;)t.removeChild(t.firstChild);return t.setAttribute("width",this.width.toString()),t.setAttribute("height",this.height.toString()),this.backgroundColor&&(e=document.createElementNS("http://www.w3.org/2000/svg","rect"),e.width.baseVal.value=this.width,e.height.baseVal.value=this.height,e.setAttribute("fill",this.backgroundColor),t.appendChild(e)),t.setAttribute("stroke-linecap","round"),t}sourceSvgChanged(){const t=this.$svg;if(t){const e=this.roughConfig.fixedDecimalPlaceDigits;this.width=parseFloat(this.coerceSize(t,"width",300).toFixed(e)),this.height=parseFloat(this.coerceSize(t,"height",150).toFixed(e)),this.collectElementsWithID()}}collectElementsWithID(){this.idElements={};const t=Array.prototype.slice.apply(this.svg.querySelectorAll("*[id]"));for(const e of t){const t=e.getAttribute("id");t&&(this.idElements[t]=e)}}coerceSize(t,e,n){let r=n;const s=t.hasAttribute("viewBox");return t.hasAttribute(e)?r=t[e].baseVal.unitType===SVGLength.SVG_LENGTHTYPE_PERCENTAGE&&s?t.viewBox.baseVal[e]:t[e].baseVal.value:s&&(r=t.viewBox.baseVal[e]),r}}})); //# sourceMappingURL=svg2roughjs.umd.min.js.map