"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=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;ie.ymin?1:t.xe.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;ic);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)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;r1)for(var r=1;r3){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;ky&&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;kl[0]&&(p=t[1],l=t[0]);for(var c=Math.atan((l[1]-p[1])/(l[0]-p[0])),f=0;fp[0]&&(u=t[1],p=t[0]);for(var l=Math.atan((p[1]-u[1])/(p[0]-u[0])),c=0;cr%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))),td&&(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;e2){for(var a=[],o=0;o2*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;c2){n.push({op:"move",data:[t[0][0]+G(r,e),t[0][1]+G(r,e)]});for(var o=1;o500?.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;a3){var o=[],s=1-n.curveTightness;a.push({op:"move",data:[t[1][0],t[1][1]]});for(var i=1;i+21&&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;rh&&(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;n0?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{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