You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
30 KiB
JavaScript

"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};function e(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t}).apply(this,arguments)};function r(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),a=0;for(e=0;e<n;e++)for(var o=arguments[e],s=0,i=o.length;s<i;s++,a++)r[a]=o[s];return r}function a(t,e,n){if(t&&t.length){var r=e[0],a=e[1],o=Math.PI/180*n,s=Math.cos(o),i=Math.sin(o);t.forEach((function(t){var e=t[0],n=t[1];t[0]=(e-r)*s-(n-a)*i+r,t[1]=(e-r)*i+(n-a)*s+a}))}}function o(t){var e=t[0],n=t[1];return Math.sqrt(Math.pow(e[0]-n[0],2)+Math.pow(e[1]-n[1],2))}function s(t,e,n){var r=t.length;if(r<3)return!1;for(var a=[Number.MAX_SAFE_INTEGER,n],o=[e,n],s=0,p=0;p<r;p++){var l=t[p],c=t[(p+1)%r];if(u(l,c,o,a)){if(0===h(l,o,c))return i(l,o,c);s++}}return s%2==1}function i(t,e,n){return e[0]<=Math.max(t[0],n[0])&&e[0]>=Math.min(t[0],n[0])&&e[1]<=Math.max(t[1],n[1])&&e[1]>=Math.min(t[1],n[1])}function h(t,e,n){var r=(e[1]-t[1])*(n[0]-e[0])-(e[0]-t[0])*(n[1]-e[1]);return 0===r?0:r>0?1:2}function u(t,e,n,r){var a=h(t,e,n),o=h(t,e,r),s=h(n,r,t),u=h(n,r,e);return a!==o&&s!==u||(!(0!==a||!i(t,n,e))||(!(0!==o||!i(t,r,e))||(!(0!==s||!i(n,t,r))||!(0!==u||!i(n,e,r)))))}function p(t,e){var n=[0,0],o=Math.round(e.hachureAngle+90);o&&a(t,n,o);var s=function(t,e){var n=r(t);n[0].join(",")!==n[n.length-1].join(",")&&n.push([n[0][0],n[0][1]]);var a=[];if(n&&n.length>2){var o=e.hachureGap;o<0&&(o=4*e.strokeWidth),o=Math.max(o,.1);for(var s=[],i=0;i<n.length-1;i++){var h=n[i],u=n[i+1];if(h[1]!==u[1]){var p=Math.min(h[1],u[1]);s.push({ymin:p,ymax:Math.max(h[1],u[1]),x:p===h[1]?h[0]:u[0],islope:(u[0]-h[0])/(u[1]-h[1])})}}if(s.sort((function(t,e){return t.ymin<e.ymin?-1:t.ymin>e.ymin?1:t.x<e.x?-1:t.x>e.x?1:t.ymax===e.ymax?0:(t.ymax-e.ymax)/Math.abs(t.ymax-e.ymax)})),!s.length)return a;for(var l=[],c=s[0].ymin;l.length||s.length;){if(s.length){var f=-1;for(i=0;i<s.length&&!(s[i].ymin>c);i++)f=i;s.splice(0,f+1).forEach((function(t){l.push({s:c,edge:t})}))}if((l=l.filter((function(t){return!(t.edge.ymax<=c)}))).sort((function(t,e){return t.edge.x===e.edge.x?0:(t.edge.x-e.edge.x)/Math.abs(t.edge.x-e.edge.x)})),l.length>1)for(i=0;i<l.length;i+=2){var d=i+1;if(d>=l.length)break;var v=l[i].edge,g=l[d].edge;a.push([[Math.round(v.x),c],[Math.round(g.x),c]])}c+=o,l.forEach((function(t){t.edge.x=t.edge.x+o*t.edge.islope}))}}return a}(t,e);return o&&(a(t,n,-o),function(t,e,n){var r=[];t.forEach((function(t){return r.push.apply(r,t)})),a(r,e,n)}(s,n,-o)),s}var l=function(){function t(t){this.helper=t}return t.prototype.fillPolygon=function(t,e){return this._fillPolygon(t,e)},t.prototype._fillPolygon=function(t,e,n){void 0===n&&(n=!1);var r=p(t,e);if(n){var a=this.connectingLines(t,r);r=r.concat(a)}return{type:"fillSketch",ops:this.renderLines(r,e)}},t.prototype.renderLines=function(t,e){for(var n=[],r=0,a=t;r<a.length;r++){var o=a[r];n.push.apply(n,this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],e))}return n},t.prototype.connectingLines=function(t,e){var n=[];if(e.length>1)for(var r=1;r<e.length;r++){var a=e[r-1];if(!(o(a)<3)){var s=[e[r][0],a[1]];if(o(s)>3){var i=this.splitOnIntersections(t,s);n.push.apply(n,i)}}}return n},t.prototype.midPointInPolygon=function(t,e){return s(t,(e[0][0]+e[1][0])/2,(e[0][1]+e[1][1])/2)},t.prototype.splitOnIntersections=function(t,e){for(var n,a,i,h,p,l,c,f,d,v,g,y=Math.max(5,.1*o(e)),M=[],k=0;k<t.length;k++){var b=t[k],m=t[(k+1)%t.length];if(u.apply(void 0,r([b,m],e))){var w=(n=b,a=m,i=e[0],h=e[1],p=void 0,l=void 0,c=void 0,f=void 0,d=void 0,v=void 0,g=void 0,p=a[1]-n[1],l=n[0]-a[0],c=p*n[0]+l*n[1],f=h[1]-i[1],d=i[0]-h[0],v=f*i[0]+d*i[1],(g=p*d-f*l)?[(d*c-l*v)/g,(p*v-f*c)/g]:null);if(w){var P=o([w,e[0]]),x=o([w,e[1]]);P>y&&x>y&&M.push({point:w,distance:P})}}}if(M.length>1){var O=M.sort((function(t,e){return t.distance-e.distance})).map((function(t){return t.point}));if(s.apply(void 0,r([t],e[0]))||O.shift(),s.apply(void 0,r([t],e[1]))||O.pop(),O.length<=1)return this.midPointInPolygon(t,e)?[e]:[];var S=r([e[0]],O,[e[1]]),L=[];for(k=0;k<S.length-1;k+=2){var T=[S[k],S[k+1]];this.midPointInPolygon(t,T)&&L.push(T)}return L}return this.midPointInPolygon(t,e)?[e]:[]},t}(),c=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.fillPolygon=function(t,e){return this._fillPolygon(t,e,!0)},n}(l),f=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.fillPolygon=function(t,e){var n=this._fillPolygon(t,e),r=Object.assign({},e,{hachureAngle:e.hachureAngle+90}),a=this._fillPolygon(t,r);return n.ops=n.ops.concat(a.ops),n},n}(l),d=function(){function t(t){this.helper=t}return t.prototype.fillPolygon=function(t,e){var n=p(t,e=Object.assign({},e,{curveStepCount:4,hachureAngle:0,roughness:1}));return this.dotsOnLines(n,e)},t.prototype.dotsOnLines=function(t,e){var n=[],r=e.hachureGap;r<0&&(r=4*e.strokeWidth),r=Math.max(r,.1);var a=e.fillWeight;a<0&&(a=e.strokeWidth/2);for(var s=r/4,i=0,h=t;i<h.length;i++)for(var u=h[i],p=o(u),l=p/r,c=Math.ceil(l)-1,f=p-c*r,d=(u[0][0]+u[1][0])/2-r/4,v=Math.min(u[0][1],u[1][1]),g=0;g<c;g++){var y=v+f+g*r,M=this.helper.randOffsetWithRange(d-s,d+s,e),k=this.helper.randOffsetWithRange(y-s,y+s,e),b=this.helper.ellipse(M,k,a,a,e);n.push.apply(n,b.ops)}return{type:"fillSketch",ops:n}},t}(),v=function(){function t(t){this.helper=t}return t.prototype.fillPolygon=function(t,e){var n=p(t,e);return{type:"fillSketch",ops:this.dashedLine(n,e)}},t.prototype.dashedLine=function(t,e){var n=this,r=e.dashOffset<0?e.hachureGap<0?4*e.strokeWidth:e.hachureGap:e.dashOffset,a=e.dashGap<0?e.hachureGap<0?4*e.strokeWidth:e.hachureGap:e.dashGap,s=[];return t.forEach((function(t){var i=o(t),h=Math.floor(i/(r+a)),u=(i+a-h*(r+a))/2,p=t[0],l=t[1];p[0]>l[0]&&(p=t[1],l=t[0]);for(var c=Math.atan((l[1]-p[1])/(l[0]-p[0])),f=0;f<h;f++){var d=f*(r+a),v=d+r,g=[p[0]+d*Math.cos(c)+u*Math.cos(c),p[1]+d*Math.sin(c)+u*Math.sin(c)],y=[p[0]+v*Math.cos(c)+u*Math.cos(c),p[1]+v*Math.sin(c)+u*Math.sin(c)];s.push.apply(s,n.helper.doubleLineOps(g[0],g[1],y[0],y[1],e))}})),s},t}(),g=function(){function t(t){this.helper=t}return t.prototype.fillPolygon=function(t,e){var n=e.hachureGap<0?4*e.strokeWidth:e.hachureGap,r=e.zigzagOffset<0?n:e.zigzagOffset,a=p(t,e=Object.assign({},e,{hachureGap:n+r}));return{type:"fillSketch",ops:this.zigzagLines(a,r,e)}},t.prototype.zigzagLines=function(t,e,n){var a=this,s=[];return t.forEach((function(t){var i=o(t),h=Math.round(i/(2*e)),u=t[0],p=t[1];u[0]>p[0]&&(u=t[1],p=t[0]);for(var l=Math.atan((p[1]-u[1])/(p[0]-u[0])),c=0;c<h;c++){var f=2*c*e,d=2*(c+1)*e,v=Math.sqrt(2*Math.pow(e,2)),g=[u[0]+f*Math.cos(l),u[1]+f*Math.sin(l)],y=[u[0]+d*Math.cos(l),u[1]+d*Math.sin(l)],M=[g[0]+v*Math.cos(l+Math.PI/4),g[1]+v*Math.sin(l+Math.PI/4)];s.push.apply(s,r(a.helper.doubleLineOps(g[0],g[1],M[0],M[1],n),a.helper.doubleLineOps(M[0],M[1],y[0],y[1],n)))}})),s},t}(),y={};var M=function(){function t(t){this.seed=t}return t.prototype.next=function(){return this.seed?(Math.pow(2,31)-1&(this.seed=Math.imul(48271,this.seed)))/Math.pow(2,31):Math.random()},t}();const k={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:2,t:2,V:1,v:1,Z:0,z:0};function b(t,e){return t.type===e}function m(t){const e=[],n=function(t){const e=new Array;for(;""!==t;)if(t.match(/^([ \t\r\n,]+)/))t=t.substr(RegExp.$1.length);else if(t.match(/^([aAcChHlLmMqQsStTvVzZ])/))e[e.length]={type:0,text:RegExp.$1},t=t.substr(RegExp.$1.length);else{if(!t.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))return[];e[e.length]={type:1,text:""+parseFloat(RegExp.$1)},t=t.substr(RegExp.$1.length)}return e[e.length]={type:2,text:""},e}(t);let r="BOD",a=0,o=n[a];for(;!b(o,2);){let s=0;const i=[];if("BOD"===r){if("M"!==o.text&&"m"!==o.text)return m("M0,0"+t);a++,s=k[o.text],r=o.text}else b(o,1)?s=k[r]:(a++,s=k[o.text],r=o.text);if(!(a+s<n.length))throw new Error("Path data ended short");for(let t=a;t<a+s;t++){const e=n[t];if(!b(e,1))throw new Error("Param not a number: "+r+","+e.text);i[i.length]=+e.text}if("number"!=typeof k[r])throw new Error("Bad segment: "+r);{const t={key:r,data:i};e.push(t),a+=s,o=n[a],"M"===r&&(r="L"),"m"===r&&(r="l")}}return e}function w(t){let e=0,n=0,r=0,a=0;const o=[];for(const{key:s,data:i}of t)switch(s){case"M":o.push({key:"M",data:[...i]}),[e,n]=i,[r,a]=i;break;case"m":e+=i[0],n+=i[1],o.push({key:"M",data:[e,n]}),r=e,a=n;break;case"L":o.push({key:"L",data:[...i]}),[e,n]=i;break;case"l":e+=i[0],n+=i[1],o.push({key:"L",data:[e,n]});break;case"C":o.push({key:"C",data:[...i]}),e=i[4],n=i[5];break;case"c":{const t=i.map((t,r)=>r%2?t+n:t+e);o.push({key:"C",data:t}),e=t[4],n=t[5];break}case"Q":o.push({key:"Q",data:[...i]}),e=i[2],n=i[3];break;case"q":{const t=i.map((t,r)=>r%2?t+n:t+e);o.push({key:"Q",data:t}),e=t[2],n=t[3];break}case"A":o.push({key:"A",data:[...i]}),e=i[5],n=i[6];break;case"a":e+=i[5],n+=i[6],o.push({key:"A",data:[i[0],i[1],i[2],i[3],i[4],e,n]});break;case"H":o.push({key:"H",data:[...i]}),e=i[0];break;case"h":e+=i[0],o.push({key:"H",data:[e]});break;case"V":o.push({key:"V",data:[...i]}),n=i[0];break;case"v":n+=i[0],o.push({key:"V",data:[n]});break;case"S":o.push({key:"S",data:[...i]}),e=i[2],n=i[3];break;case"s":{const t=i.map((t,r)=>r%2?t+n:t+e);o.push({key:"S",data:t}),e=t[2],n=t[3];break}case"T":o.push({key:"T",data:[...i]}),e=i[0],n=i[1];break;case"t":e+=i[0],n+=i[1],o.push({key:"T",data:[e,n]});break;case"Z":case"z":o.push({key:"Z",data:[]}),e=r,n=a}return o}function P(t){const e=[];let n="",r=0,a=0,o=0,s=0,i=0,h=0;for(const{key:u,data:p}of t){switch(u){case"M":e.push({key:"M",data:[...p]}),[r,a]=p,[o,s]=p;break;case"C":e.push({key:"C",data:[...p]}),r=p[4],a=p[5],i=p[2],h=p[3];break;case"L":e.push({key:"L",data:[...p]}),[r,a]=p;break;case"H":r=p[0],e.push({key:"L",data:[r,a]});break;case"V":a=p[0],e.push({key:"L",data:[r,a]});break;case"S":{let t=0,o=0;"C"===n||"S"===n?(t=r+(r-i),o=a+(a-h)):(t=r,o=a),e.push({key:"C",data:[t,o,...p]}),i=p[0],h=p[1],r=p[2],a=p[3];break}case"T":{const[t,o]=p;let s=0,u=0;"Q"===n||"T"===n?(s=r+(r-i),u=a+(a-h)):(s=r,u=a);const l=r+2*(s-r)/3,c=a+2*(u-a)/3,f=t+2*(s-t)/3,d=o+2*(u-o)/3;e.push({key:"C",data:[l,c,f,d,t,o]}),i=s,h=u,r=t,a=o;break}case"Q":{const[t,n,o,s]=p,u=r+2*(t-r)/3,l=a+2*(n-a)/3,c=o+2*(t-o)/3,f=s+2*(n-s)/3;e.push({key:"C",data:[u,l,c,f,o,s]}),i=t,h=n,r=o,a=s;break}case"A":{const t=Math.abs(p[0]),n=Math.abs(p[1]),o=p[2],s=p[3],i=p[4],h=p[5],u=p[6];if(0===t||0===n)e.push({key:"C",data:[r,a,h,u,h,u]}),r=h,a=u;else if(r!==h||a!==u){O(r,a,h,u,t,n,o,s,i).forEach((function(t){e.push({key:"C",data:t})})),r=h,a=u}break}case"Z":e.push({key:"Z",data:[]}),r=o,a=s}n=u}return e}function x(t,e,n){return[t*Math.cos(n)-e*Math.sin(n),t*Math.sin(n)+e*Math.cos(n)]}function O(t,e,n,r,a,o,s,i,h,u){const p=(l=s,Math.PI*l/180);var l;let c=[],f=0,d=0,v=0,g=0;if(u)[f,d,v,g]=u;else{[t,e]=x(t,e,-p),[n,r]=x(n,r,-p);const s=(t-n)/2,u=(e-r)/2;let l=s*s/(a*a)+u*u/(o*o);l>1&&(l=Math.sqrt(l),a*=l,o*=l);const c=a*a,y=o*o,M=c*y-c*u*u-y*s*s,k=c*u*u+y*s*s,b=(i===h?-1:1)*Math.sqrt(Math.abs(M/k));v=b*a*u/o+(t+n)/2,g=b*-o*s/a+(e+r)/2,f=Math.asin(parseFloat(((e-g)/o).toFixed(9))),d=Math.asin(parseFloat(((r-g)/o).toFixed(9))),t<v&&(f=Math.PI-f),n<v&&(d=Math.PI-d),f<0&&(f=2*Math.PI+f),d<0&&(d=2*Math.PI+d),h&&f>d&&(f-=2*Math.PI),!h&&d>f&&(d-=2*Math.PI)}let y=d-f;if(Math.abs(y)>120*Math.PI/180){const t=d,e=n,i=r;d=h&&d>f?f+120*Math.PI/180*1:f+120*Math.PI/180*-1,c=O(n=v+a*Math.cos(d),r=g+o*Math.sin(d),e,i,a,o,s,0,h,[d,t,v,g])}y=d-f;const M=Math.cos(f),k=Math.sin(f),b=Math.cos(d),m=Math.sin(d),w=Math.tan(y/4),P=4/3*a*w,S=4/3*o*w,L=[t,e],T=[t+P*k,e-S*M],_=[n+P*m,r-S*b],I=[n,r];if(T[0]=2*L[0]-T[0],T[1]=2*L[1]-T[1],u)return[T,_,I].concat(c);{c=[T,_,I].concat(c);const t=[];for(let e=0;e<c.length;e+=3){const n=x(c[e][0],c[e][1],p),r=x(c[e+1][0],c[e+1][1],p),a=x(c[e+2][0],c[e+2][1],p);t.push([n[0],n[1],r[0],r[1],a[0],a[1]])}return t}}var S={randOffset:function(t,e){return G(t,e)},randOffsetWithRange:function(t,e,n){return j(t,e,n)},ellipse:function(t,e,n,r,a){var o=A(n,r,a);return C(t,e,a,o).opset},doubleLineOps:function(t,e,n,r,a){return q(t,e,n,r,a,!0)}};function L(t,e,n,r,a){return{type:"path",ops:q(t,e,n,r,a)}}function T(t,e,n){var r=(t||[]).length;if(r>2){for(var a=[],o=0;o<r-1;o++)a.push.apply(a,q(t[o][0],t[o][1],t[o+1][0],t[o+1][1],n));return e&&a.push.apply(a,q(t[r-1][0],t[r-1][1],t[0][0],t[0][1],n)),{type:"path",ops:a}}return 2===r?L(t[0][0],t[0][1],t[1][0],t[1][1],n):{type:"path",ops:[]}}function _(t,e,n,r,a){return function(t,e){return T(t,!0,e)}([[t,e],[t+n,e],[t+n,e+r],[t,e+r]],a)}function I(t,e){var r=N(t,1*(1+.2*e.roughness),e);if(!e.disableMultiStroke){var a=N(t,1.5*(1+.22*e.roughness),function(t){var e=n({},t);e.randomizer=void 0,t.seed&&(e.seed=t.seed+1);return e}(e));r=r.concat(a)}return{type:"path",ops:r}}function A(t,e,n){var r=Math.sqrt(2*Math.PI*Math.sqrt((Math.pow(t/2,2)+Math.pow(e/2,2))/2)),a=Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*r),o=2*Math.PI/a,s=Math.abs(t/2),i=Math.abs(e/2),h=1-n.curveFitting;return{increment:o,rx:s+=G(s*h,n),ry:i+=G(i*h,n)}}function C(t,e,n,r){var a=Q(r.increment,t,e,r.rx,r.ry,1,r.increment*j(.1,j(.4,1,n),n),n),o=a[0],s=a[1],i=Z(o,null,n);if(!n.disableMultiStroke){var h=Z(Q(r.increment,t,e,r.rx,r.ry,1.5,0,n)[0],null,n);i=i.concat(h)}return{estimatedPoints:s,opset:{type:"path",ops:i}}}function D(t,e,n,a,o,s,i,h,u){var p=t,l=e,c=Math.abs(n/2),f=Math.abs(a/2);c+=G(.01*c,u),f+=G(.01*f,u);for(var d=o,v=s;d<0;)d+=2*Math.PI,v+=2*Math.PI;v-d>2*Math.PI&&(d=0,v=2*Math.PI);var g=2*Math.PI/u.curveStepCount,y=Math.min(g/2,(v-d)/2),M=H(y,p,l,c,f,d,v,1,u);if(!u.disableMultiStroke){var k=H(y,p,l,c,f,d,v,1.5,u);M.push.apply(M,k)}return i&&(h?M.push.apply(M,r(q(p,l,p+c*Math.cos(d),l+f*Math.sin(d),u),q(p,l,p+c*Math.cos(v),l+f*Math.sin(v),u))):M.push({op:"lineTo",data:[p,l]},{op:"lineTo",data:[p+c*Math.cos(d),l+f*Math.sin(d)]})),{type:"path",ops:M}}function E(t,e){for(var n=P(w(m(t))),r=[],a=[0,0],o=[0,0],s=function(t,n){switch(t){case"M":var s=1*(e.maxRandomnessOffset||0);r.push({op:"move",data:n.map((function(t){return t+G(s,e)}))}),o=[n[0],n[1]],a=[n[0],n[1]];break;case"L":r.push.apply(r,q(o[0],o[1],n[0],n[1],e)),o=[n[0],n[1]];break;case"C":var i=n[0],h=n[1],u=n[2],p=n[3],l=n[4],c=n[5];r.push.apply(r,function(t,e,n,r,a,o,s,i){for(var h=[],u=[i.maxRandomnessOffset||1,(i.maxRandomnessOffset||1)+.3],p=[0,0],l=i.disableMultiStroke?1:2,c=0;c<l;c++)0===c?h.push({op:"move",data:[s[0],s[1]]}):h.push({op:"move",data:[s[0]+G(u[0],i),s[1]+G(u[0],i)]}),p=[a+G(u[c],i),o+G(u[c],i)],h.push({op:"bcurveTo",data:[t+G(u[c],i),e+G(u[c],i),n+G(u[c],i),r+G(u[c],i),p[0],p[1]]});return h}(i,h,u,p,l,c,o,e)),o=[l,c];break;case"Z":r.push.apply(r,q(o[0],o[1],a[0],a[1],e)),o=[a[0],a[1]]}},i=0,h=n;i<h.length;i++){var u=h[i];s(u.key,u.data)}return{type:"path",ops:r}}function W(t,e){var n=[];if(t.length){var r=e.maxRandomnessOffset||0,a=t.length;if(a>2){n.push({op:"move",data:[t[0][0]+G(r,e),t[0][1]+G(r,e)]});for(var o=1;o<a;o++)n.push({op:"lineTo",data:[t[o][0]+G(r,e),t[o][1]+G(r,e)]})}}return{type:"fillPath",ops:n}}function z(t,e){return function(t,e){var n=t.fillStyle||"hachure";if(!y[n])switch(n){case"zigzag":y[n]||(y[n]=new c(e));break;case"cross-hatch":y[n]||(y[n]=new f(e));break;case"dots":y[n]||(y[n]=new d(e));break;case"dashed":y[n]||(y[n]=new v(e));break;case"zigzag-line":y[n]||(y[n]=new g(e));break;case"hachure":default:y[n="hachure"]||(y[n]=new l(e))}return y[n]}(e,S).fillPolygon(t,e)}function R(t){return t.randomizer||(t.randomizer=new M(t.seed||0)),t.randomizer.next()}function j(t,e,n,r){return void 0===r&&(r=1),n.roughness*r*(R(n)*(e-t)+t)}function G(t,e,n){return void 0===n&&(n=1),j(-t,t,e,n)}function q(t,e,n,r,a,o){void 0===o&&(o=!1);var s=o?a.disableMultiStrokeFill:a.disableMultiStroke,i=F(t,e,n,r,a,!0,!1);if(s)return i;var h=F(t,e,n,r,a,!0,!0);return i.concat(h)}function F(t,e,n,r,a,o,s){var i=Math.pow(t-n,2)+Math.pow(e-r,2),h=Math.sqrt(i),u=1;u=h<200?1:h>500?.4:-.0016668*h+1.233334;var p=a.maxRandomnessOffset||0;p*p*100>i&&(p=h/10);var l=p/2,c=.2+.2*R(a),f=a.bowing*a.maxRandomnessOffset*(r-e)/200,d=a.bowing*a.maxRandomnessOffset*(t-n)/200;f=G(f,a,u),d=G(d,a,u);var v=[],g=function(){return G(l,a,u)},y=function(){return G(p,a,u)};return o&&(s?v.push({op:"move",data:[t+g(),e+g()]}):v.push({op:"move",data:[t+G(p,a,u),e+G(p,a,u)]})),s?v.push({op:"bcurveTo",data:[f+t+(n-t)*c+g(),d+e+(r-e)*c+g(),f+t+2*(n-t)*c+g(),d+e+2*(r-e)*c+g(),n+g(),r+g()]}):v.push({op:"bcurveTo",data:[f+t+(n-t)*c+y(),d+e+(r-e)*c+y(),f+t+2*(n-t)*c+y(),d+e+2*(r-e)*c+y(),n+y(),r+y()]}),v}function N(t,e,n){var r=[];r.push([t[0][0]+G(e,n),t[0][1]+G(e,n)]),r.push([t[0][0]+G(e,n),t[0][1]+G(e,n)]);for(var a=1;a<t.length;a++)r.push([t[a][0]+G(e,n),t[a][1]+G(e,n)]),a===t.length-1&&r.push([t[a][0]+G(e,n),t[a][1]+G(e,n)]);return Z(r,null,n)}function Z(t,e,n){var r=t.length,a=[];if(r>3){var o=[],s=1-n.curveTightness;a.push({op:"move",data:[t[1][0],t[1][1]]});for(var i=1;i+2<r;i++){var h=t[i];o[0]=[h[0],h[1]],o[1]=[h[0]+(s*t[i+1][0]-s*t[i-1][0])/6,h[1]+(s*t[i+1][1]-s*t[i-1][1])/6],o[2]=[t[i+1][0]+(s*t[i][0]-s*t[i+2][0])/6,t[i+1][1]+(s*t[i][1]-s*t[i+2][1])/6],o[3]=[t[i+1][0],t[i+1][1]],a.push({op:"bcurveTo",data:[o[1][0],o[1][1],o[2][0],o[2][1],o[3][0],o[3][1]]})}if(e&&2===e.length){var u=n.maxRandomnessOffset;a.push({op:"lineTo",data:[e[0]+G(u,n),e[1]+G(u,n)]})}}else 3===r?(a.push({op:"move",data:[t[1][0],t[1][1]]}),a.push({op:"bcurveTo",data:[t[1][0],t[1][1],t[2][0],t[2][1],t[2][0],t[2][1]]})):2===r&&a.push.apply(a,q(t[0][0],t[0][1],t[1][0],t[1][1],n));return a}function Q(t,e,n,r,a,o,s,i){var h=[],u=[],p=G(.5,i)-Math.PI/2;u.push([G(o,i)+e+.9*r*Math.cos(p-t),G(o,i)+n+.9*a*Math.sin(p-t)]);for(var l=p;l<2*Math.PI+p-.01;l+=t){var c=[G(o,i)+e+r*Math.cos(l),G(o,i)+n+a*Math.sin(l)];h.push(c),u.push(c)}return u.push([G(o,i)+e+r*Math.cos(p+2*Math.PI+.5*s),G(o,i)+n+a*Math.sin(p+2*Math.PI+.5*s)]),u.push([G(o,i)+e+.98*r*Math.cos(p+s),G(o,i)+n+.98*a*Math.sin(p+s)]),u.push([G(o,i)+e+.9*r*Math.cos(p+.5*s),G(o,i)+n+.9*a*Math.sin(p+.5*s)]),[u,h]}function H(t,e,n,r,a,o,s,i,h){var u=o+G(.1,h),p=[];p.push([G(i,h)+e+.9*r*Math.cos(u-t),G(i,h)+n+.9*a*Math.sin(u-t)]);for(var l=u;l<=s;l+=t)p.push([G(i,h)+e+r*Math.cos(l),G(i,h)+n+a*Math.sin(l)]);return p.push([e+r*Math.cos(s),n+a*Math.sin(s)]),p.push([e+r*Math.cos(s),n+a*Math.sin(s)]),Z(p,null,h)}function V(t){return[...t]}function $(t,e){return Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)}function B(t,e,n){const r=$(e,n);if(0===r)return $(t,e);let a=((t[0]-e[0])*(n[0]-e[0])+(t[1]-e[1])*(n[1]-e[1]))/r;return a=Math.max(0,Math.min(1,a)),$(t,X(e,n,a))}function X(t,e,n){return[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n]}function J(t,e,n,r){const a=r||[];if(function(t,e){const n=t[e+0],r=t[e+1],a=t[e+2],o=t[e+3];let s=3*r[0]-2*n[0]-o[0];s*=s;let i=3*r[1]-2*n[1]-o[1];i*=i;let h=3*a[0]-2*o[0]-n[0];h*=h;let u=3*a[1]-2*o[1]-n[1];return u*=u,s<h&&(s=h),i<u&&(i=u),s+i}(t,e)<n){const n=t[e+0];if(a.length){(o=a[a.length-1],s=n,Math.sqrt($(o,s)))>1&&a.push(n)}else a.push(n);a.push(t[e+3])}else{const r=.5,o=t[e+0],s=t[e+1],i=t[e+2],h=t[e+3],u=X(o,s,r),p=X(s,i,r),l=X(i,h,r),c=X(u,p,r),f=X(p,l,r),d=X(c,f,r);J([o,u,c,d],0,n,a),J([d,f,l,h],0,n,a)}var o,s;return a}function K(t,e){return U(t,0,t.length,e)}function U(t,e,n,r,a){const o=a||[],s=t[e],i=t[n-1];let h=0,u=1;for(let r=e+1;r<n-1;++r){const e=B(t[r],s,i);e>h&&(h=e,u=r)}return Math.sqrt(h)>r?(U(t,e,u+1,r,o),U(t,u,n,r,o)):(o.length||o.push(s),o.push(i)),o}function Y(t,e=.15,n){const r=[],a=(t.length-1)/3;for(let n=0;n<a;n++){J(t,3*n,e,r)}return n&&n>0?U(r,0,r.length,n):r}var tt="none",et=function(){function t(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,combineNestedSvgPaths:!1,disableMultiStroke:!1,disableMultiStrokeFill:!1},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}return t.newSeed=function(){return Math.floor(Math.random()*Math.pow(2,31))},t.prototype._o=function(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions},t.prototype._d=function(t,e,n){return{shape:t,sets:e||[],options:n||this.defaultOptions}},t.prototype.line=function(t,e,n,r,a){var o=this._o(a);return this._d("line",[L(t,e,n,r,o)],o)},t.prototype.rectangle=function(t,e,n,r,a){var o=this._o(a),s=[],i=_(t,e,n,r,o);if(o.fill){var h=[[t,e],[t+n,e],[t+n,e+r],[t,e+r]];"solid"===o.fillStyle?s.push(W(h,o)):s.push(z(h,o))}return o.stroke!==tt&&s.push(i),this._d("rectangle",s,o)},t.prototype.ellipse=function(t,e,n,r,a){var o=this._o(a),s=[],i=A(n,r,o),h=C(t,e,o,i);if(o.fill)if("solid"===o.fillStyle){var u=C(t,e,o,i).opset;u.type="fillPath",s.push(u)}else s.push(z(h.estimatedPoints,o));return o.stroke!==tt&&s.push(h.opset),this._d("ellipse",s,o)},t.prototype.circle=function(t,e,n,r){var a=this.ellipse(t,e,n,n,r);return a.shape="circle",a},t.prototype.linearPath=function(t,e){var n=this._o(e);return this._d("linearPath",[T(t,!1,n)],n)},t.prototype.arc=function(t,e,n,r,a,o,s,i){void 0===s&&(s=!1);var h=this._o(i),u=[],p=D(t,e,n,r,a,o,s,!0,h);if(s&&h.fill)if("solid"===h.fillStyle){var l=D(t,e,n,r,a,o,!0,!1,h);l.type="fillPath",u.push(l)}else u.push(function(t,e,n,r,a,o,s){var i=t,h=e,u=Math.abs(n/2),p=Math.abs(r/2);u+=G(.01*u,s),p+=G(.01*p,s);for(var l=a,c=o;l<0;)l+=2*Math.PI,c+=2*Math.PI;c-l>2*Math.PI&&(l=0,c=2*Math.PI);for(var f=(c-l)/s.curveStepCount,d=[],v=l;v<=c;v+=f)d.push([i+u*Math.cos(v),h+p*Math.sin(v)]);return d.push([i+u*Math.cos(c),h+p*Math.sin(c)]),d.push([i,h]),z(d,s)}(t,e,n,r,a,o,h));return h.stroke!==tt&&u.push(p),this._d("arc",u,h)},t.prototype.curve=function(t,e){var n=this._o(e),r=[],a=I(t,n);if(n.fill&&n.fill!==tt&&t.length>=3){var o=Y(function(t,e=0){const n=t.length;if(n<3)throw new Error("A curve must have at least three points.");const r=[];if(3===n)r.push(V(t[0]),V(t[1]),V(t[2]),V(t[2]));else{const n=[];n.push(t[0],t[0]);for(let e=1;e<t.length;e++)n.push(t[e]),e===t.length-1&&n.push(t[e]);const a=[],o=1-e;r.push(V(n[0]));for(let t=1;t+2<n.length;t++){const e=n[t];a[0]=[e[0],e[1]],a[1]=[e[0]+(o*n[t+1][0]-o*n[t-1][0])/6,e[1]+(o*n[t+1][1]-o*n[t-1][1])/6],a[2]=[n[t+1][0]+(o*n[t][0]-o*n[t+2][0])/6,n[t+1][1]+(o*n[t][1]-o*n[t+2][1])/6],a[3]=[n[t+1][0],n[t+1][1]],r.push(a[1],a[2],a[3])}}return r}(t),10,(1+n.roughness)/2);"solid"===n.fillStyle?r.push(W(o,n)):r.push(z(o,n))}return n.stroke!==tt&&r.push(a),this._d("curve",r,n)},t.prototype.polygon=function(t,e){var n=this._o(e),r=[],a=T(t,!0,n);return n.fill&&("solid"===n.fillStyle?r.push(W(t,n)):r.push(z(t,n))),n.stroke!==tt&&r.push(a),this._d("polygon",r,n)},t.prototype.path=function(t,e){var n=this._o(e),r=[];if(!t)return this._d("path",r,n);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");var a=n.fill&&"transparent"!==n.fill&&n.fill!==tt,o=n.stroke!==tt,s=!!(n.simplification&&n.simplification<1),i=function(t,e,n){const r=P(w(m(t))),a=[];let o=[],s=[0,0],i=[];const h=()=>{i.length>=4&&o.push(...Y(i,e)),i=[]},u=()=>{h(),o.length&&(a.push(o),o=[])};for(const{key:t,data:e}of r)switch(t){case"M":u(),s=[e[0],e[1]],o.push(s);break;case"L":h(),o.push([e[0],e[1]]);break;case"C":if(!i.length){const t=o.length?o[o.length-1]:s;i.push([t[0],t[1]])}i.push([e[0],e[1]]),i.push([e[2],e[3]]),i.push([e[4],e[5]]);break;case"Z":h(),o.push([s[0],s[1]])}if(u(),!n)return a;const p=[];for(const t of a){const e=K(t,n);e.length&&p.push(e)}return p}(t,1,s?4-4*n.simplification:(1+n.roughness)/2);if(a)if(n.combineNestedSvgPaths){var h=[];i.forEach((function(t){return h.push.apply(h,t)})),"solid"===n.fillStyle?r.push(W(h,n)):r.push(z(h,n))}else i.forEach((function(t){"solid"===n.fillStyle?r.push(W(t,n)):r.push(z(t,n))}));return o&&(s?i.forEach((function(t){r.push(T(t,!1,n))})):r.push(E(t,n))),this._d("path",r,n)},t.prototype.opsToPath=function(t){for(var e="",n=0,r=t.ops;n<r.length;n++){var a=r[n],o=a.data;switch(a.op){case"move":e+="M"+o[0]+" "+o[1]+" ";break;case"bcurveTo":e+="C"+o[0]+" "+o[1]+", "+o[2]+" "+o[3]+", "+o[4]+" "+o[5]+" ";break;case"lineTo":e+="L"+o[0]+" "+o[1]+" "}}return e.trim()},t.prototype.toPaths=function(t){for(var e=t.sets||[],n=t.options||this.defaultOptions,r=[],a=0,o=e;a<o.length;a++){var s=o[a],i=null;switch(s.type){case"path":i={d:this.opsToPath(s),stroke:n.stroke,strokeWidth:n.strokeWidth,fill:tt};break;case"fillPath":i={d:this.opsToPath(s),stroke:tt,strokeWidth:0,fill:n.fill||tt};break;case"fillSketch":i=this.fillSketch(s,n)}i&&r.push(i)}return r},t.prototype.fillSketch=function(t,e){var n=e.fillWeight;return n<0&&(n=e.strokeWidth/2),{d:this.opsToPath(t),stroke:e.fill||tt,strokeWidth:n,fill:tt}},t}(),nt=function(){function t(t,e){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new et(e)}return t.prototype.draw=function(t){for(var e=t.sets||[],n=t.options||this.getDefaultOptions(),r=this.ctx,a=0,o=e;a<o.length;a++){var s=o[a];switch(s.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,s),r.restore();break;case"fillPath":r.save(),r.fillStyle=n.fill||"";var i="curve"===t.shape||"polygon"===t.shape?"evenodd":"nonzero";this._drawToContext(r,s,i),r.restore();break;case"fillSketch":this.fillSketch(r,s,n)}}},t.prototype.fillSketch=function(t,e,n){var 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),t.restore()},t.prototype._drawToContext=function(t,e,n){void 0===n&&(n="nonzero"),t.beginPath();for(var r=0,a=e.ops;r<a.length;r++){var o=a[r],s=o.data;switch(o.op){case"move":t.moveTo(s[0],s[1]);break;case"bcurveTo":t.bezierCurveTo(s[0],s[1],s[2],s[3],s[4],s[5]);break;case"lineTo":t.lineTo(s[0],s[1])}}"fillPath"===e.type?t.fill(n):t.stroke()},Object.defineProperty(t.prototype,"generator",{get:function(){return this.gen},enumerable:!0,configurable:!0}),t.prototype.getDefaultOptions=function(){return this.gen.defaultOptions},t.prototype.line=function(t,e,n,r,a){var o=this.gen.line(t,e,n,r,a);return this.draw(o),o},t.prototype.rectangle=function(t,e,n,r,a){var o=this.gen.rectangle(t,e,n,r,a);return this.draw(o),o},t.prototype.ellipse=function(t,e,n,r,a){var o=this.gen.ellipse(t,e,n,r,a);return this.draw(o),o},t.prototype.circle=function(t,e,n,r){var a=this.gen.circle(t,e,n,r);return this.draw(a),a},t.prototype.linearPath=function(t,e){var n=this.gen.linearPath(t,e);return this.draw(n),n},t.prototype.polygon=function(t,e){var n=this.gen.polygon(t,e);return this.draw(n),n},t.prototype.arc=function(t,e,n,r,a,o,s,i){void 0===s&&(s=!1);var h=this.gen.arc(t,e,n,r,a,o,s,i);return this.draw(h),h},t.prototype.curve=function(t,e){var n=this.gen.curve(t,e);return this.draw(n),n},t.prototype.path=function(t,e){var n=this.gen.path(t,e);return this.draw(n),n},t}(),rt="http://www.w3.org/2000/svg",at=function(){function t(t,e){this.svg=t,this.gen=new et(e)}return t.prototype.draw=function(t){for(var e=t.sets||[],n=t.options||this.getDefaultOptions(),r=this.svg.ownerDocument||window.document,a=r.createElementNS(rt,"g"),o=0,s=e;o<s.length;o++){var i=s[o],h=null;switch(i.type){case"path":(h=r.createElementNS(rt,"path")).setAttribute("d",this.opsToPath(i)),h.setAttribute("stroke",n.stroke),h.setAttribute("stroke-width",n.strokeWidth+""),h.setAttribute("fill","none"),n.strokeLineDash&&h.setAttribute("stroke-dasharray",n.strokeLineDash.join(" ").trim()),n.strokeLineDashOffset&&h.setAttribute("stroke-dashoffset",""+n.strokeLineDashOffset);break;case"fillPath":(h=r.createElementNS(rt,"path")).setAttribute("d",this.opsToPath(i)),h.setAttribute("stroke","none"),h.setAttribute("stroke-width","0"),h.setAttribute("fill",n.fill||""),"curve"!==t.shape&&"polygon"!==t.shape||h.setAttribute("fill-rule","evenodd");break;case"fillSketch":h=this.fillSketch(r,i,n)}h&&a.appendChild(h)}return a},t.prototype.fillSketch=function(t,e,n){var r=n.fillWeight;r<0&&(r=n.strokeWidth/2);var a=t.createElementNS(rt,"path");return a.setAttribute("d",this.opsToPath(e)),a.setAttribute("stroke",n.fill||""),a.setAttribute("stroke-width",r+""),a.setAttribute("fill","none"),n.fillLineDash&&a.setAttribute("stroke-dasharray",n.fillLineDash.join(" ").trim()),n.fillLineDashOffset&&a.setAttribute("stroke-dashoffset",""+n.fillLineDashOffset),a},Object.defineProperty(t.prototype,"generator",{get:function(){return this.gen},enumerable:!0,configurable:!0}),t.prototype.getDefaultOptions=function(){return this.gen.defaultOptions},t.prototype.opsToPath=function(t){return this.gen.opsToPath(t)},t.prototype.line=function(t,e,n,r,a){var o=this.gen.line(t,e,n,r,a);return this.draw(o)},t.prototype.rectangle=function(t,e,n,r,a){var o=this.gen.rectangle(t,e,n,r,a);return this.draw(o)},t.prototype.ellipse=function(t,e,n,r,a){var o=this.gen.ellipse(t,e,n,r,a);return this.draw(o)},t.prototype.circle=function(t,e,n,r){var a=this.gen.circle(t,e,n,r);return this.draw(a)},t.prototype.linearPath=function(t,e){var n=this.gen.linearPath(t,e);return this.draw(n)},t.prototype.polygon=function(t,e){var n=this.gen.polygon(t,e);return this.draw(n)},t.prototype.arc=function(t,e,n,r,a,o,s,i){void 0===s&&(s=!1);var h=this.gen.arc(t,e,n,r,a,o,s,i);return this.draw(h)},t.prototype.curve=function(t,e){var n=this.gen.curve(t,e);return this.draw(n)},t.prototype.path=function(t,e){var n=this.gen.path(t,e);return this.draw(n)},t}(),ot={canvas:function(t,e){return new nt(t,e)},svg:function(t,e){return new at(t,e)},generator:function(t){return new et(t)},newSeed:function(){return et.newSeed()}};module.exports=ot;