Files
rough/dist/rough-async.es5.js
Preet Shihn 1eec028ec7 es5 build
2019-01-07 00:29:05 -08:00

2 lines
41 KiB
JavaScript

var rough=function(){"use strict";var t=function(e,i){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(e,i)};function e(e,i){function r(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}function i(t,e,i,r){return new(i||(i=Promise))(function(n,s){function a(t){try{h(r.next(t))}catch(t){s(t)}}function o(t){try{h(r.throw(t))}catch(t){s(t)}}function h(t){t.done?n(t.value):new i(function(e){e(t.value)}).then(a,o)}h((r=r.apply(t,e||[])).next())})}function r(t,e){var i,r,n,s,a={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function o(s){return function(o){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,r&&(n=2&s[0]?r.return:s[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,s[1])).done)return n;switch(r=0,n&&(s=[2&s[0],n.value]),s[0]){case 0:case 1:n=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(n=(n=a.trys).length>0&&n[n.length-1])&&(6===s[0]||2===s[0])){a=0;continue}if(3===s[0]&&(!n||s[1]>n[0]&&s[1]<n[3])){a.label=s[1];break}if(6===s[0]&&a.label<n[1]){a.label=n[1],n=s;break}if(n&&a.label<n[2]){a.label=n[2],a.ops.push(s);break}n[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{i=n=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,o])}}}var n="undefined"!=typeof self,s=function(){function t(t,e){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1},this.config=t||{},this.surface=e,this.config.options&&(this.defaultOptions=this._options(this.config.options))}return t.prototype._options=function(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions},t.prototype._drawable=function(t,e,i){return{shape:t,sets:e||[],options:i||this.defaultOptions}},t.prototype.getCanvasSize=function(){var t=function(t){return t&&"object"==typeof t&&t.baseVal&&t.baseVal.value?t.baseVal.value:t||100};return this.surface?[t(this.surface.width),t(this.surface.height)]:[100,100]},t.prototype.computePolygonSize=function(t){if(t.length){for(var e=t[0][0],i=t[0][0],r=t[0][1],n=t[0][1],s=1;s<t.length;s++)e=Math.min(e,t[s][0]),i=Math.max(i,t[s][0]),r=Math.min(r,t[s][1]),n=Math.max(n,t[s][1]);return[i-e,n-r]}return[0,0]},t.prototype.polygonPath=function(t){var e="";if(t.length){e="M"+t[0][0]+","+t[0][1];for(var i=1;i<t.length;i++)e=e+" L"+t[i][0]+","+t[i][1]}return e},t.prototype.computePathSize=function(t){var e=[0,0];if(n&&self.document)try{var i="http://www.w3.org/2000/svg",r=self.document.createElementNS(i,"svg");r.setAttribute("width","0"),r.setAttribute("height","0");var s=self.document.createElementNS(i,"path");s.setAttribute("d",t),r.appendChild(s),self.document.body.appendChild(r);var a=s.getBBox();a&&(e[0]=a.width||0,e[1]=a.height||0),self.document.body.removeChild(r)}catch(t){}var o=this.getCanvasSize();return e[0]*e[1]||(e=o),e},t.prototype.toPaths=function(t){for(var e=t.sets||[],i=t.options||this.defaultOptions,r=[],n=0,s=e;n<s.length;n++){var a=s[n],o=null;switch(a.type){case"path":o={d:this.opsToPath(a),stroke:i.stroke,strokeWidth:i.strokeWidth,fill:"none"};break;case"fillPath":o={d:this.opsToPath(a),stroke:"none",strokeWidth:0,fill:i.fill||"none"};break;case"fillSketch":o=this.fillSketch(a,i);break;case"path2Dfill":o={d:a.path||"",stroke:"none",strokeWidth:0,fill:i.fill||"none"};break;case"path2Dpattern":var h=a.size,c={x:0,y:0,width:1,height:1,viewBox:"0 0 "+Math.round(h[0])+" "+Math.round(h[1]),patternUnits:"objectBoundingBox",path:this.fillSketch(a,i)};o={d:a.path,stroke:"none",strokeWidth:0,pattern:c}}o&&r.push(o)}return r},t.prototype.fillSketch=function(t,e){var i=e.fillWeight;return i<0&&(i=e.strokeWidth/2),{d:this.opsToPath(t),stroke:e.fill||"none",strokeWidth:i,fill:"none"}},t.prototype.opsToPath=function(t){for(var e="",i=0,r=t.ops;i<r.length;i++){var n=r[i],s=n.data;switch(n.op){case"move":e+="M"+s[0]+" "+s[1]+" ";break;case"bcurveTo":e+="C"+s[0]+" "+s[1]+", "+s[2]+" "+s[3]+", "+s[4]+" "+s[5]+" ";break;case"qcurveTo":e+="Q"+s[0]+" "+s[1]+", "+s[2]+" "+s[3]+" ";break;case"lineTo":e+="L"+s[0]+" "+s[1]+" "}}return e.trim()},t}();function a(t,e){return e=e||[],new Proxy(function(){},{get(i,r,n){if("then"===r){if(0===e.length)return{then:()=>n};const i=t.remote({type:"GET",path:e});return i.then.bind(i)}return a(t,e.concat(r))},set:(i,r,n)=>t.remote({type:"SET",path:e.concat(r),value:n}),apply:(i,r,n)=>t.remote({type:"APPLY",path:e,args:n}),construct:(e,i)=>t.remote({type:"CONSTRUCT",args:i})})}class o{constructor(t,e){this.w=t,this.uid=e||`${Date.now()}-${h()}`,this.c=0,this.cbs={},t.addEventListener("message",e=>{if(this.w.oURL)try{URL.revokeObjectURL(this.w.oURL)}catch(t){}finally{delete this.w.oURL}let i=e.data&&e.data.id,r=i&&this.cbs[i];r&&(delete this.cbs[i],e.data.error?r[1](new Error(e.data.error)):r[0](e.data.targetId?a(new o(t,e.data.targetId)):e.data.value))})}remote(t){const e=t.args||[],i=`${this.uid}-${++this.c}`;return new Promise((r,n)=>{this.cbs[i]=[r,n],this.w.postMessage(Object.assign({},t,{id:i,args:e,target:this.uid}))})}}function h(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)}function c(t){const e=t,i={};self.addEventListener("message",async t=>{let r=t.data||{};r.path=r.path||[];let n=r.target&&i[r.target]||e;const s=t=>t.reduce((t,e)=>t?t[e]:t,n),a=r&&r.id;if(a&&r.type){const t={id:a},e=s(r.path),n=s(r.path.slice(0,-1));switch(r.type){case"GET":t.value=e;break;case"SET":let s=r.path.length&&r.path[r.path.length-1];s&&(n[s]=r.value),t.value=!!s;break;case"APPLY":try{t.value=await e.apply(n,r.args||[])}catch(e){t.error=e.toString()}break;case"CONSTRUCT":try{t.value=new e(...r.args),t.targetId=(t=>{const e=`${Date.now()}-${h()}`;return i[e]=t,e})(t.value)}catch(e){t.error=e.toString()}}self.postMessage(t)}})}function l(t,e){return t.type===e}var u={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:4,t:2,V:1,v:1,Z:0,z:0},p=function(){function t(t){this.COMMAND=0,this.NUMBER=1,this.EOD=2,this.segments=[],this.parseData(t),this.processPoints()}return t.prototype.tokenize=function(t){for(var e=new Array;""!==t;)if(t.match(/^([ \t\r\n,]+)/))t=t.substr(RegExp.$1.length);else if(t.match(/^([aAcChHlLmMqQsStTvVzZ])/))e[e.length]={type:this.COMMAND,text:RegExp.$1},t=t.substr(RegExp.$1.length);else{if(!t.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))return console.error("Unrecognized segment command: "+t),[];e[e.length]={type:this.NUMBER,text:""+parseFloat(RegExp.$1)},t=t.substr(RegExp.$1.length)}return e[e.length]={type:this.EOD,text:""},e},t.prototype.parseData=function(t){var e=this.tokenize(t),i=0,r=e[i],n="BOD";for(this.segments=new Array;!l(r,this.EOD);){var s=void 0,a=new Array;if("BOD"===n){if("M"!==r.text&&"m"!==r.text)return void this.parseData("M0,0"+t);i++,s=u[r.text],n=r.text}else l(r,this.NUMBER)?s=u[n]:(i++,s=u[r.text],n=r.text);if(i+s<e.length){for(var o=i;o<i+s;o++){var h=e[o];if(!l(h,this.NUMBER))return void console.error("Parameter type is not a number: "+n+","+h.text);a[a.length]=+h.text}if("number"!=typeof u[n])return void console.error("Unsupported segment type: "+n);var c={key:n,data:a};this.segments.push(c),r=e[i+=s],"M"===n&&(n="L"),"m"===n&&(n="l")}else console.error("Path data ended before all parameters were found")}},Object.defineProperty(t.prototype,"closed",{get:function(){if(void 0===this._closed){this._closed=!1;for(var t=0,e=this.segments;t<e.length;t++){"z"===e[t].key.toLowerCase()&&(this._closed=!0)}}return this._closed},enumerable:!0,configurable:!0}),t.prototype.processPoints=function(){for(var t=null,e=[0,0],i=0;i<this.segments.length;i++){var r=this.segments[i];switch(r.key){case"M":case"L":case"T":r.point=[r.data[0],r.data[1]];break;case"m":case"l":case"t":r.point=[r.data[0]+e[0],r.data[1]+e[1]];break;case"H":r.point=[r.data[0],e[1]];break;case"h":r.point=[r.data[0]+e[0],e[1]];break;case"V":r.point=[e[0],r.data[0]];break;case"v":r.point=[e[0],r.data[0]+e[1]];break;case"z":case"Z":t&&(r.point=[t[0],t[1]]);break;case"C":r.point=[r.data[4],r.data[5]];break;case"c":r.point=[r.data[4]+e[0],r.data[5]+e[1]];break;case"S":r.point=[r.data[2],r.data[3]];break;case"s":r.point=[r.data[2]+e[0],r.data[3]+e[1]];break;case"Q":r.point=[r.data[2],r.data[3]];break;case"q":r.point=[r.data[2]+e[0],r.data[3]+e[1]];break;case"A":r.point=[r.data[5],r.data[6]];break;case"a":r.point=[r.data[5]+e[0],r.data[6]+e[1]]}"m"!==r.key&&"M"!==r.key||(t=null),r.point&&(e=r.point,t||(t=r.point)),"z"!==r.key&&"Z"!==r.key||(t=null)}},t}(),f=function(){function t(t){this._position=[0,0],this._first=null,this.bezierReflectionPoint=null,this.quadReflectionPoint=null,this.parsed=new p(t)}return Object.defineProperty(t.prototype,"segments",{get:function(){return this.parsed.segments},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"closed",{get:function(){return this.parsed.closed},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"linearPoints",{get:function(){if(!this._linearPoints){for(var t=[],e=[],i=0,r=this.parsed.segments;i<r.length;i++){var n=r[i],s=n.key.toLowerCase();("m"!==s&&"z"!==s||(e.length&&(t.push(e),e=[]),"z"!==s))&&(n.point&&e.push(n.point))}e.length&&(t.push(e),e=[]),this._linearPoints=t}return this._linearPoints},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"first",{get:function(){return this._first},set:function(t){this._first=t},enumerable:!0,configurable:!0}),t.prototype.setPosition=function(t,e){this._position=[t,e],this._first||(this._first=[t,e])},Object.defineProperty(t.prototype,"position",{get:function(){return this._position},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"x",{get:function(){return this._position[0]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._position[1]},enumerable:!0,configurable:!0}),t}(),d=function(){function t(t,e,i,r,n,s){if(this._segIndex=0,this._numSegs=0,this._rx=0,this._ry=0,this._sinPhi=0,this._cosPhi=0,this._C=[0,0],this._theta=0,this._delta=0,this._T=0,this._from=t,t[0]!==e[0]||t[1]!==e[1]){var a=Math.PI/180;this._rx=Math.abs(i[0]),this._ry=Math.abs(i[1]),this._sinPhi=Math.sin(r*a),this._cosPhi=Math.cos(r*a);var o=this._cosPhi*(t[0]-e[0])/2+this._sinPhi*(t[1]-e[1])/2,h=-this._sinPhi*(t[0]-e[0])/2+this._cosPhi*(t[1]-e[1])/2,c=0,l=this._rx*this._rx*this._ry*this._ry-this._rx*this._rx*h*h-this._ry*this._ry*o*o;if(l<0){var u=Math.sqrt(1-l/(this._rx*this._rx*this._ry*this._ry));this._rx=this._rx*u,this._ry=this._ry*u,c=0}else c=(n===s?-1:1)*Math.sqrt(l/(this._rx*this._rx*h*h+this._ry*this._ry*o*o));var p=c*this._rx*h/this._ry,f=-c*this._ry*o/this._rx;this._C=[0,0],this._C[0]=this._cosPhi*p-this._sinPhi*f+(t[0]+e[0])/2,this._C[1]=this._sinPhi*p+this._cosPhi*f+(t[1]+e[1])/2,this._theta=this.calculateVectorAngle(1,0,(o-p)/this._rx,(h-f)/this._ry);var d=this.calculateVectorAngle((o-p)/this._rx,(h-f)/this._ry,(-o-p)/this._rx,(-h-f)/this._ry);!s&&d>0?d-=2*Math.PI:s&&d<0&&(d+=2*Math.PI),this._numSegs=Math.ceil(Math.abs(d/(Math.PI/2))),this._delta=d/this._numSegs,this._T=8/3*Math.sin(this._delta/4)*Math.sin(this._delta/4)/Math.sin(this._delta/2)}}return t.prototype.getNextSegment=function(){if(this._segIndex===this._numSegs)return null;var t=Math.cos(this._theta),e=Math.sin(this._theta),i=this._theta+this._delta,r=Math.cos(i),n=Math.sin(i),s=[this._cosPhi*this._rx*r-this._sinPhi*this._ry*n+this._C[0],this._sinPhi*this._rx*r+this._cosPhi*this._ry*n+this._C[1]],a=[this._from[0]+this._T*(-this._cosPhi*this._rx*e-this._sinPhi*this._ry*t),this._from[1]+this._T*(-this._sinPhi*this._rx*e+this._cosPhi*this._ry*t)],o=[s[0]+this._T*(this._cosPhi*this._rx*n+this._sinPhi*this._ry*r),s[1]+this._T*(this._sinPhi*this._rx*n-this._cosPhi*this._ry*r)];return this._theta=i,this._from=[s[0],s[1]],this._segIndex++,{cp1:a,cp2:o,to:s}},t.prototype.calculateVectorAngle=function(t,e,i,r){var n=Math.atan2(e,t),s=Math.atan2(r,i);return s>=n?s-n:2*Math.PI-(n-s)},t}(),y=function(){function t(t,e){this.sets=t,this.closed=e}return t.prototype.fit=function(t){for(var e=[],i=0,r=this.sets;i<r.length;i++){var n=(c=r[i]).length,s=Math.floor(t*n);if(s<5){if(n<=5)continue;s=5}e.push(this.reduce(c,s))}for(var a="",o=0,h=e;o<h.length;o++){for(var c=h[o],l=0;l<c.length;l++){var u=c[l];a+=0===l?"M"+u[0]+","+u[1]:"L"+u[0]+","+u[1]}this.closed&&(a+="z ")}return a},t.prototype.distance=function(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2))},t.prototype.reduce=function(t,e){if(t.length<=e)return t;for(var i=t.slice(0);i.length>e;){for(var r=[],n=-1,s=-1,a=1;a<i.length-1;a++){var o=this.distance(i[a-1],i[a]),h=this.distance(i[a],i[a+1]),c=this.distance(i[a-1],i[a+1]),l=(o+h+c)/2,u=Math.sqrt(l*(l-o)*(l-h)*(l-c));r.push(u),(n<0||u<n)&&(n=u,s=a)}if(!(s>0))break;i.splice(s,1)}return i},t}(),g=function(){function t(t,e){this.xi=Number.MAX_VALUE,this.yi=Number.MAX_VALUE,this.px1=t[0],this.py1=t[1],this.px2=e[0],this.py2=e[1],this.a=this.py2-this.py1,this.b=this.px1-this.px2,this.c=this.px2*this.py1-this.px1*this.py2,this._undefined=0===this.a&&0===this.b&&0===this.c}return t.prototype.isUndefined=function(){return this._undefined},t.prototype.intersects=function(t){if(this.isUndefined()||t.isUndefined())return!1;var e=Number.MAX_VALUE,i=Number.MAX_VALUE,r=0,n=0,s=this.a,a=this.b,o=this.c;return Math.abs(a)>1e-5&&(e=-s/a,r=-o/a),Math.abs(t.b)>1e-5&&(i=-t.a/t.b,n=-t.c/t.b),e===Number.MAX_VALUE?i===Number.MAX_VALUE?-o/s==-t.c/t.a&&(this.py1>=Math.min(t.py1,t.py2)&&this.py1<=Math.max(t.py1,t.py2)?(this.xi=this.px1,this.yi=this.py1,!0):this.py2>=Math.min(t.py1,t.py2)&&this.py2<=Math.max(t.py1,t.py2)&&(this.xi=this.px2,this.yi=this.py2,!0)):(this.xi=this.px1,this.yi=i*this.xi+n,!((this.py1-this.yi)*(this.yi-this.py2)<-1e-5||(t.py1-this.yi)*(this.yi-t.py2)<-1e-5)&&(!(Math.abs(t.a)<1e-5)||!((t.px1-this.xi)*(this.xi-t.px2)<-1e-5))):i===Number.MAX_VALUE?(this.xi=t.px1,this.yi=e*this.xi+r,!((t.py1-this.yi)*(this.yi-t.py2)<-1e-5||(this.py1-this.yi)*(this.yi-this.py2)<-1e-5)&&(!(Math.abs(s)<1e-5)||!((this.px1-this.xi)*(this.xi-this.px2)<-1e-5))):e===i?r===n&&(this.px1>=Math.min(t.px1,t.px2)&&this.px1<=Math.max(t.py1,t.py2)?(this.xi=this.px1,this.yi=this.py1,!0):this.px2>=Math.min(t.px1,t.px2)&&this.px2<=Math.max(t.px1,t.px2)&&(this.xi=this.px2,this.yi=this.py2,!0)):(this.xi=(n-r)/(e-i),this.yi=e*this.xi+r,!((this.px1-this.xi)*(this.xi-this.px2)<-1e-5||(t.px1-this.xi)*(this.xi-t.px2)<-1e-5))},t}(),v=function(){function t(t,e,i,r,n,s,a,o){this.deltaX=0,this.hGap=0,this.top=t,this.bottom=e,this.left=i,this.right=r,this.gap=n,this.sinAngle=s,this.tanAngle=o,Math.abs(s)<1e-4?this.pos=i+n:Math.abs(s)>.9999?this.pos=t+n:(this.deltaX=(e-t)*Math.abs(o),this.pos=i-Math.abs(this.deltaX),this.hGap=Math.abs(n/a),this.sLeft=new g([i,e],[i,t]),this.sRight=new g([r,e],[r,t]))}return t.prototype.nextLine=function(){if(Math.abs(this.sinAngle)<1e-4){if(this.pos<this.right){var t=[this.pos,this.top,this.pos,this.bottom];return this.pos+=this.gap,t}}else if(Math.abs(this.sinAngle)>.9999){if(this.pos<this.bottom){t=[this.left,this.pos,this.right,this.pos];return this.pos+=this.gap,t}}else{var e=this.pos-this.deltaX/2,i=this.pos+this.deltaX/2,r=this.bottom,n=this.top;if(this.pos<this.right+this.deltaX){for(;e<this.left&&i<this.left||e>this.right&&i>this.right;)if(this.pos+=this.hGap,e=this.pos-this.deltaX/2,i=this.pos+this.deltaX/2,this.pos>this.right+this.deltaX)return null;var s=new g([e,r],[i,n]);this.sLeft&&s.intersects(this.sLeft)&&(e=s.xi,r=s.yi),this.sRight&&s.intersects(this.sRight)&&(i=s.xi,n=s.yi),this.tanAngle>0&&(e=this.right-(e-this.left),i=this.right-(i-this.left));t=[e,r,i,n];return this.pos+=this.hGap,t}}return null},t}();function b(t){var e=t[0],i=t[1];return Math.sqrt(Math.pow(e[0]-i[0],2)+Math.pow(e[1]-i[1],2))}function m(t,e){for(var i=[],r=new g([t[0],t[1]],[t[2],t[3]]),n=0;n<e.length;n++){var s=new g(e[n],e[(n+1)%e.length]);r.intersects(s)&&i.push([r.xi,r.yi])}return i}function w(t,e,i,r,n,s,a){return[-i*s-r*n+i+s*t+n*e,a*(i*n-r*s)+r+-a*n*t+a*s*e]}function x(t,e){var i=[];if(t&&t.length){for(var r=t[0][0],n=t[0][0],s=t[0][1],a=t[0][1],o=1;o<t.length;o++)r=Math.min(r,t[o][0]),n=Math.max(n,t[o][0]),s=Math.min(s,t[o][1]),a=Math.max(a,t[o][1]);var h=e.hachureAngle,c=e.hachureGap;c<0&&(c=4*e.strokeWidth),c=Math.max(c,.1);for(var l=h%180*(Math.PI/180),u=Math.cos(l),p=Math.sin(l),f=Math.tan(l),d=new v(s-1,a+1,r-1,n+1,c,p,u,f),y=void 0;null!=(y=d.nextLine());){var g=m(y,t);for(o=0;o<g.length;o++)if(o<g.length-1){var b=g[o],w=g[o+1];i.push([b,w])}}}return i}function _(t,e,i,r,n,s){var a=[],o=Math.abs(r/2),h=Math.abs(n/2);o+=t.randOffset(.05*o,s),h+=t.randOffset(.05*h,s);var c=s.hachureAngle,l=s.hachureGap;l<=0&&(l=4*s.strokeWidth);var u=s.fillWeight;u<0&&(u=s.strokeWidth/2);for(var p=c%180*(Math.PI/180),f=Math.tan(p),d=h/o,y=Math.sqrt(d*f*d*f+1),g=d*f/y,v=1/y,b=l/(o*h/Math.sqrt(h*v*(h*v)+o*g*(o*g))/o),m=Math.sqrt(o*o-(e-o+b)*(e-o+b)),x=e-o+b;x<e+o;x+=b){var _=w(x,i-(m=Math.sqrt(o*o-(e-x)*(e-x))),e,i,g,v,d),P=w(x,i+m,e,i,g,v,d);a.push([_,P])}return a}var P=function(){function t(t){this.helper=t}return t.prototype.fillPolygon=function(t,e){return this._fillPolygon(t,e)},t.prototype.fillEllipse=function(t,e,i,r,n){return this._fillEllipse(t,e,i,r,n)},t.prototype._fillPolygon=function(t,e,i){void 0===i&&(i=!1);var r=x(t,e);return{type:"fillSketch",ops:this.renderLines(r,e,i)}},t.prototype._fillEllipse=function(t,e,i,r,n,s){void 0===s&&(s=!1);var a=_(this.helper,t,e,i,r,n);return{type:"fillSketch",ops:this.renderLines(a,n,s)}},t.prototype.renderLines=function(t,e,i){for(var r=[],n=null,s=0,a=t;s<a.length;s++){var o=a[s];r=r.concat(this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],e)),i&&n&&(r=r.concat(this.helper.doubleLineOps(n[0],n[1],o[0][0],o[0][1],e))),n=o[1]}return r},t}(),M=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return e(i,t),i.prototype.fillPolygon=function(t,e){return this._fillPolygon(t,e,!0)},i.prototype.fillEllipse=function(t,e,i,r,n){return this._fillEllipse(t,e,i,r,n,!0)},i}(P),k=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return e(i,t),i.prototype.fillPolygon=function(t,e){var i=this._fillPolygon(t,e),r=Object.assign({},e,{hachureAngle:e.hachureAngle+90}),n=this._fillPolygon(t,r);return i.ops=i.ops.concat(n.ops),i},i.prototype.fillEllipse=function(t,e,i,r,n){var s=this._fillEllipse(t,e,i,r,n),a=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),o=this._fillEllipse(t,e,i,r,a);return s.ops=s.ops.concat(o.ops),s},i}(P),S=function(){function t(t){this.helper=t}return t.prototype.fillPolygon=function(t,e){var i=x(t,e=Object.assign({},e,{curveStepCount:4,hachureAngle:0}));return this.dotsOnLines(i,e)},t.prototype.fillEllipse=function(t,e,i,r,n){n=Object.assign({},n,{curveStepCount:4,hachureAngle:0});var s=_(this.helper,t,e,i,r,n);return this.dotsOnLines(s,n)},t.prototype.dotsOnLines=function(t,e){var i=[],r=e.hachureGap;r<0&&(r=4*e.strokeWidth),r=Math.max(r,.1);var n=e.fillWeight;n<0&&(n=e.strokeWidth/2);for(var s=0,a=t;s<a.length;s++)for(var o=a[s],h=b(o)/r,c=Math.ceil(h)-1,l=Math.atan((o[1][1]-o[0][1])/(o[1][0]-o[0][0])),u=0;u<c;u++){var p=r*(u+1),f=p*Math.sin(l),d=p*Math.cos(l),y=[o[0][0]-d,o[0][1]+f],g=this.helper.randOffsetWithRange(y[0]-r/4,y[0]+r/4,e),v=this.helper.randOffsetWithRange(y[1]-r/4,y[1]+r/4,e),m=this.helper.ellipse(g,v,n,n,e);i=i.concat(m.ops)}return{type:"fillSketch",ops:i}},t}(),O={};function A(t,e){var i=t.fillStyle||"hachure";if(!O[i])switch(i){case"zigzag":O[i]||(O[i]=new M(e));break;case"cross-hatch":O[i]||(O[i]=new k(e));break;case"dots":O[i]||(O[i]=new S(e));break;case"hachure":default:O[i="hachure"]||(O[i]=new P(e))}return O[i]}var T={randOffset:W,randOffsetWithRange:D,ellipse:L,doubleLineOps:z};function E(t,e,i,r,n){return{type:"path",ops:q(t,e,i,r,n)}}function C(t,e,i){var r=(t||[]).length;if(r>2){for(var n=[],s=0;s<r-1;s++)n=n.concat(q(t[s][0],t[s][1],t[s+1][0],t[s+1][1],i));return e&&(n=n.concat(q(t[r-1][0],t[r-1][1],t[0][0],t[0][1],i))),{type:"path",ops:n}}return 2===r?E(t[0][0],t[0][1],t[1][0],t[1][1],i):{type:"path",ops:[]}}function R(t,e){return C(t,!0,e)}function L(t,e,i,r,n){var s=2*Math.PI/n.curveStepCount,a=Math.abs(i/2),o=Math.abs(r/2),h=V(s,t,e,a+=I(.05*a,n),o+=I(.05*o,n),1,s*U(.1,U(.4,1,n),n),n),c=V(s,t,e,a,o,1.5,0,n);return{type:"path",ops:h.concat(c)}}function N(t,e){return A(e,T).fillPolygon(t,e)}function W(t,e){return I(t,e)}function D(t,e,i){return U(t,e,i)}function z(t,e,i,r,n){return q(t,e,i,r,n)}function U(t,e,i){return i.roughness*(Math.random()*(e-t)+t)}function I(t,e){return U(-t,t,e)}function q(t,e,i,r,n){var s=j(t,e,i,r,n,!0,!1),a=j(t,e,i,r,n,!0,!0);return s.concat(a)}function j(t,e,i,r,n,s,a){var o=Math.pow(t-i,2)+Math.pow(e-r,2),h=n.maxRandomnessOffset||0;h*h*100>o&&(h=Math.sqrt(o)/10);var c=h/2,l=.2+.2*Math.random(),u=n.bowing*n.maxRandomnessOffset*(r-e)/200,p=n.bowing*n.maxRandomnessOffset*(t-i)/200;u=I(u,n),p=I(p,n);var f=[],d=function(){return I(c,n)},y=function(){return I(h,n)};return s&&(a?f.push({op:"move",data:[t+d(),e+d()]}):f.push({op:"move",data:[t+I(h,n),e+I(h,n)]})),a?f.push({op:"bcurveTo",data:[u+t+(i-t)*l+d(),p+e+(r-e)*l+d(),u+t+2*(i-t)*l+d(),p+e+2*(r-e)*l+d(),i+d(),r+d()]}):f.push({op:"bcurveTo",data:[u+t+(i-t)*l+y(),p+e+(r-e)*l+y(),u+t+2*(i-t)*l+y(),p+e+2*(r-e)*l+y(),i+y(),r+y()]}),f}function B(t,e,i){var r=[];r.push([t[0][0]+I(e,i),t[0][1]+I(e,i)]),r.push([t[0][0]+I(e,i),t[0][1]+I(e,i)]);for(var n=1;n<t.length;n++)r.push([t[n][0]+I(e,i),t[n][1]+I(e,i)]),n===t.length-1&&r.push([t[n][0]+I(e,i),t[n][1]+I(e,i)]);return X(r,null,i)}function X(t,e,i){var r=t.length,n=[];if(r>3){var s=[],a=1-i.curveTightness;n.push({op:"move",data:[t[1][0],t[1][1]]});for(var o=1;o+2<r;o++){var h=t[o];s[0]=[h[0],h[1]],s[1]=[h[0]+(a*t[o+1][0]-a*t[o-1][0])/6,h[1]+(a*t[o+1][1]-a*t[o-1][1])/6],s[2]=[t[o+1][0]+(a*t[o][0]-a*t[o+2][0])/6,t[o+1][1]+(a*t[o][1]-a*t[o+2][1])/6],s[3]=[t[o+1][0],t[o+1][1]],n.push({op:"bcurveTo",data:[s[1][0],s[1][1],s[2][0],s[2][1],s[3][0],s[3][1]]})}if(e&&2===e.length){var c=i.maxRandomnessOffset;n.push({op:"lineTo",data:[e[0]+I(c,i),e[1]+I(c,i)]})}}else 3===r?(n.push({op:"move",data:[t[1][0],t[1][1]]}),n.push({op:"bcurveTo",data:[t[1][0],t[1][1],t[2][0],t[2][1],t[2][0],t[2][1]]})):2===r&&(n=n.concat(q(t[0][0],t[0][1],t[1][0],t[1][1],i)));return n}function V(t,e,i,r,n,s,a,o){var h=I(.5,o)-Math.PI/2,c=[];c.push([I(s,o)+e+.9*r*Math.cos(h-t),I(s,o)+i+.9*n*Math.sin(h-t)]);for(var l=h;l<2*Math.PI+h-.01;l+=t)c.push([I(s,o)+e+r*Math.cos(l),I(s,o)+i+n*Math.sin(l)]);return c.push([I(s,o)+e+r*Math.cos(h+2*Math.PI+.5*a),I(s,o)+i+n*Math.sin(h+2*Math.PI+.5*a)]),c.push([I(s,o)+e+.98*r*Math.cos(h+a),I(s,o)+i+.98*n*Math.sin(h+a)]),c.push([I(s,o)+e+.9*r*Math.cos(h+.5*a),I(s,o)+i+.9*n*Math.sin(h+.5*a)]),X(c,null,o)}function F(t,e,i,r,n,s,a,o,h){var c=s+I(.1,h),l=[];l.push([I(o,h)+e+.9*r*Math.cos(c-t),I(o,h)+i+.9*n*Math.sin(c-t)]);for(var u=c;u<=a;u+=t)l.push([I(o,h)+e+r*Math.cos(u),I(o,h)+i+n*Math.sin(u)]);return l.push([e+r*Math.cos(a),i+n*Math.sin(a)]),l.push([e+r*Math.cos(a),i+n*Math.sin(a)]),X(l,null,h)}function $(t,e,i,r,n,s,a,o){for(var h=[],c=[o.maxRandomnessOffset||1,(o.maxRandomnessOffset||1)+.5],l=[0,0],u=0;u<2;u++)0===u?h.push({op:"move",data:[a.x,a.y]}):h.push({op:"move",data:[a.x+I(c[0],o),a.y+I(c[0],o)]}),l=[n+I(c[u],o),s+I(c[u],o)],h.push({op:"bcurveTo",data:[t+I(c[u],o),e+I(c[u],o),i+I(c[u],o),r+I(c[u],o),l[0],l[1]]});return a.setPosition(l[0],l[1]),h}function G(t,e,i,r){var n=[];switch(e.key){case"M":case"m":var s="m"===e.key;if(e.data.length>=2){var a=+e.data[0],o=+e.data[1];s&&(a+=t.x,o+=t.y);var h=1*(r.maxRandomnessOffset||0);a+=I(h,r),o+=I(h,r),t.setPosition(a,o),n.push({op:"move",data:[a,o]})}break;case"L":case"l":s="l"===e.key;if(e.data.length>=2){a=+e.data[0],o=+e.data[1];s&&(a+=t.x,o+=t.y),n=n.concat(q(t.x,t.y,a,o,r)),t.setPosition(a,o)}break;case"H":case"h":s="h"===e.key;if(e.data.length){a=+e.data[0];s&&(a+=t.x),n=n.concat(q(t.x,t.y,a,t.y,r)),t.setPosition(a,t.y)}break;case"V":case"v":s="v"===e.key;if(e.data.length){o=+e.data[0];s&&(o+=t.y),n=n.concat(q(t.x,t.y,t.x,o,r)),t.setPosition(t.x,o)}break;case"Z":case"z":t.first&&(n=n.concat(q(t.x,t.y,t.first[0],t.first[1],r)),t.setPosition(t.first[0],t.first[1]),t.first=null);break;case"C":case"c":s="c"===e.key;if(e.data.length>=6){var c=+e.data[0],l=+e.data[1],u=+e.data[2],p=+e.data[3];a=+e.data[4],o=+e.data[5];s&&(c+=t.x,u+=t.x,a+=t.x,l+=t.y,p+=t.y,o+=t.y);var f=$(c,l,u,p,a,o,t,r);n=n.concat(f),t.bezierReflectionPoint=[a+(a-u),o+(o-p)]}break;case"S":case"s":s="s"===e.key;if(e.data.length>=4){u=+e.data[0],p=+e.data[1],a=+e.data[2],o=+e.data[3];s&&(u+=t.x,a+=t.x,p+=t.y,o+=t.y);c=u,l=p;var y=null;"c"!==(m=i?i.key:"")&&"C"!==m&&"s"!==m&&"S"!==m||(y=t.bezierReflectionPoint),y&&(c=y[0],l=y[1]);f=$(c,l,u,p,a,o,t,r);n=n.concat(f),t.bezierReflectionPoint=[a+(a-u),o+(o-p)]}break;case"Q":case"q":s="q"===e.key;if(e.data.length>=4){c=+e.data[0],l=+e.data[1],a=+e.data[2],o=+e.data[3];s&&(c+=t.x,a+=t.x,l+=t.y,o+=t.y);var g=1*(1+.2*r.roughness),v=1.5*(1+.22*r.roughness);n.push({op:"move",data:[t.x+I(g,r),t.y+I(g,r)]});var b=[a+I(g,r),o+I(g,r)];n.push({op:"qcurveTo",data:[c+I(g,r),l+I(g,r),b[0],b[1]]}),n.push({op:"move",data:[t.x+I(v,r),t.y+I(v,r)]}),b=[a+I(v,r),o+I(v,r)],n.push({op:"qcurveTo",data:[c+I(v,r),l+I(v,r),b[0],b[1]]}),t.setPosition(b[0],b[1]),t.quadReflectionPoint=[a+(a-c),o+(o-l)]}break;case"T":case"t":s="t"===e.key;if(e.data.length>=2){a=+e.data[0],o=+e.data[1];s&&(a+=t.x,o+=t.y);var m;c=a,l=o,y=null;"q"!==(m=i?i.key:"")&&"Q"!==m&&"t"!==m&&"T"!==m||(y=t.quadReflectionPoint),y&&(c=y[0],l=y[1]);g=1*(1+.2*r.roughness),v=1.5*(1+.22*r.roughness);n.push({op:"move",data:[t.x+I(g,r),t.y+I(g,r)]});b=[a+I(g,r),o+I(g,r)];n.push({op:"qcurveTo",data:[c+I(g,r),l+I(g,r),b[0],b[1]]}),n.push({op:"move",data:[t.x+I(v,r),t.y+I(v,r)]}),b=[a+I(v,r),o+I(v,r)],n.push({op:"qcurveTo",data:[c+I(v,r),l+I(v,r),b[0],b[1]]}),t.setPosition(b[0],b[1]),t.quadReflectionPoint=[a+(a-c),o+(o-l)]}break;case"A":case"a":s="a"===e.key;if(e.data.length>=7){var w=+e.data[0],x=+e.data[1],_=+e.data[2],P=+e.data[3],M=+e.data[4];a=+e.data[5],o=+e.data[6];if(s&&(a+=t.x,o+=t.y),a===t.x&&o===t.y)break;if(0===w||0===x)n=n.concat(q(t.x,t.y,a,o,r)),t.setPosition(a,o);else for(var k=0;k<1;k++)for(var S=new d([t.x,t.y],[a,o],[w,x],_,!!P,!!M),O=S.getNextSegment();O;){f=$(O.cp1[0],O.cp1[1],O.cp2[0],O.cp2[1],O.to[0],O.to[1],t,r);n=n.concat(f),O=S.getNextSegment()}}}return n}var Q=Object.freeze({line:E,linearPath:C,polygon:R,rectangle:function(t,e,i,r,n){return R([[t,e],[t+i,e],[t+i,e+r],[t,e+r]],n)},curve:function(t,e){var i=B(t,1*(1+.2*e.roughness),e),r=B(t,1.5*(1+.22*e.roughness),e);return{type:"path",ops:i.concat(r)}},ellipse:L,arc:function(t,e,i,r,n,s,a,o,h){var c=t,l=e,u=Math.abs(i/2),p=Math.abs(r/2);u+=I(.01*u,h),p+=I(.01*p,h);for(var f=n,d=s;f<0;)f+=2*Math.PI,d+=2*Math.PI;d-f>2*Math.PI&&(f=0,d=2*Math.PI);var y=2*Math.PI/h.curveStepCount,g=Math.min(y/2,(d-f)/2),v=F(g,c,l,u,p,f,d,1,h),b=F(g,c,l,u,p,f,d,1.5,h),m=v.concat(b);return a&&(o?m=(m=m.concat(q(c,l,c+u*Math.cos(f),l+p*Math.sin(f),h))).concat(q(c,l,c+u*Math.cos(d),l+p*Math.sin(d),h)):(m.push({op:"lineTo",data:[c,l]}),m.push({op:"lineTo",data:[c+u*Math.cos(f),l+p*Math.sin(f)]}))),{type:"path",ops:m}},svgPath:function(t,e){t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");var i=new f(t);if(e.simplification){var r=new y(i.linearPoints,i.closed).fit(e.simplification);i=new f(r)}for(var n=[],s=i.segments||[],a=0;a<s.length;a++){var o=G(i,s[a],a>0?s[a-1]:null,e);o&&o.length&&(n=n.concat(o))}return{type:"path",ops:n}},solidFillPolygon:function(t,e){var i=[];if(t.length){var r=e.maxRandomnessOffset||0,n=t.length;if(n>2){i.push({op:"move",data:[t[0][0]+I(r,e),t[0][1]+I(r,e)]});for(var s=1;s<n;s++)i.push({op:"lineTo",data:[t[s][0]+I(r,e),t[s][1]+I(r,e)]})}}return{type:"fillPath",ops:i}},patternFillPolygon:N,patternFillEllipse:function(t,e,i,r,n){return A(n,T).fillEllipse(t,e,i,r,n)},patternFillArc:function(t,e,i,r,n,s,a){var o=t,h=e,c=Math.abs(i/2),l=Math.abs(r/2);c+=I(.01*c,a),l+=I(.01*l,a);for(var u=n,p=s;u<0;)u+=2*Math.PI,p+=2*Math.PI;p-u>2*Math.PI&&(u=0,p=2*Math.PI);for(var f=(p-u)/a.curveStepCount,d=[],y=u;y<=p;y+=f)d.push([o+c*Math.cos(y),h+l*Math.sin(y)]);return d.push([o+c*Math.cos(p),h+l*Math.sin(p)]),d.push([o,h]),N(d,a)},randOffset:W,randOffsetWithRange:D,doubleLineOps:z}),Z=function(t){function n(e,i){var r=t.call(this,e,i)||this;return e&&e.workerURL?r.renderer=function(t){let e,i;if("function"==typeof t){const r=Function.prototype.toString;e=i=URL.createObjectURL(new Blob([`${r.call(h)}\n(${r.call(c)})(${r.call(t)})`]))}else"string"==typeof t&&(e=t,0===t.indexOf("blob:")&&(i=e));if(e){let t=new Worker(e);return i&&(t.oURL=i),a(new o(t))}throw"Workly only supports functions, classes, urls"}(e.workerURL):r.renderer=Q,r}return e(n,t),n.prototype.line=function(t,e,n,s,a){return i(this,void 0,Promise,function(){var i,o,h;return r(this,function(r){switch(r.label){case 0:return i=this._options(a),o=this._drawable,h=["line"],[4,this.renderer.line(t,e,n,s,i)];case 1:return[2,o.apply(this,h.concat([[r.sent()],i]))]}})})},n.prototype.rectangle=function(t,e,n,s,a){return i(this,void 0,Promise,function(){var i,o,h,c,l,u,p,f,d;return r(this,function(r){switch(r.label){case 0:return i=this._options(a),o=[],i.fill?(h=[[t,e],[t+n,e],[t+n,e+s],[t,e+s]],"solid"!==i.fillStyle?[3,2]:(l=(c=o).push,[4,this.renderer.solidFillPolygon(h,i)])):[3,4];case 1:return l.apply(c,[r.sent()]),[3,4];case 2:return p=(u=o).push,[4,this.renderer.patternFillPolygon(h,i)];case 3:p.apply(u,[r.sent()]),r.label=4;case 4:return d=(f=o).push,[4,this.renderer.rectangle(t,e,n,s,i)];case 5:return d.apply(f,[r.sent()]),[2,this._drawable("rectangle",o,i)]}})})},n.prototype.ellipse=function(t,e,n,s,a){return i(this,void 0,Promise,function(){var i,o,h,c,l,u,p;return r(this,function(r){switch(r.label){case 0:return i=this._options(a),o=[],i.fill?"solid"!==i.fillStyle?[3,2]:[4,this.renderer.ellipse(t,e,n,s,i)]:[3,4];case 1:return(h=r.sent()).type="fillPath",o.push(h),[3,4];case 2:return l=(c=o).push,[4,this.renderer.patternFillEllipse(t,e,n,s,i)];case 3:l.apply(c,[r.sent()]),r.label=4;case 4:return p=(u=o).push,[4,this.renderer.ellipse(t,e,n,s,i)];case 5:return p.apply(u,[r.sent()]),[2,this._drawable("ellipse",o,i)]}})})},n.prototype.circle=function(t,e,n,s){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.ellipse(t,e,n,n,s)];case 1:return(i=r.sent()).shape="circle",[2,i]}})})},n.prototype.linearPath=function(t,e){return i(this,void 0,Promise,function(){var i,n,s;return r(this,function(r){switch(r.label){case 0:return i=this._options(e),n=this._drawable,s=["linearPath"],[4,this.renderer.linearPath(t,!1,i)];case 1:return[2,n.apply(this,s.concat([[r.sent()],i]))]}})})},n.prototype.arc=function(t,e,n,s,a,o,h,c){return void 0===h&&(h=!1),i(this,void 0,Promise,function(){var i,l,u,p,f,d,y;return r(this,function(r){switch(r.label){case 0:return i=this._options(c),l=[],h&&i.fill?"solid"!==i.fillStyle?[3,2]:[4,this.renderer.arc(t,e,n,s,a,o,!0,!1,i)]:[3,4];case 1:return(u=r.sent()).type="fillPath",l.push(u),[3,4];case 2:return f=(p=l).push,[4,this.renderer.patternFillArc(t,e,n,s,a,o,i)];case 3:f.apply(p,[r.sent()]),r.label=4;case 4:return y=(d=l).push,[4,this.renderer.arc(t,e,n,s,a,o,h,!0,i)];case 5:return y.apply(d,[r.sent()]),[2,this._drawable("arc",l,i)]}})})},n.prototype.curve=function(t,e){return i(this,void 0,Promise,function(){var i,n,s;return r(this,function(r){switch(r.label){case 0:return i=this._options(e),n=this._drawable,s=["curve"],[4,this.renderer.curve(t,i)];case 1:return[2,n.apply(this,s.concat([[r.sent()],i]))]}})})},n.prototype.polygon=function(t,e){return i(this,void 0,Promise,function(){var i,n,s,a,o,h,c,l,u;return r(this,function(r){switch(r.label){case 0:return i=this._options(e),n=[],i.fill?"solid"!==i.fillStyle?[3,2]:(a=(s=n).push,[4,this.renderer.solidFillPolygon(t,i)]):[3,4];case 1:return a.apply(s,[r.sent()]),[3,4];case 2:return o=this.computePolygonSize(t),h=[[0,0],[o[0],0],[o[0],o[1]],[0,o[1]]],[4,this.renderer.patternFillPolygon(h,i)];case 3:(c=r.sent()).type="path2Dpattern",c.size=o,c.path=this.polygonPath(t),n.push(c),r.label=4;case 4:return u=(l=n).push,[4,this.renderer.linearPath(t,!0,i)];case 5:return u.apply(l,[r.sent()]),[2,this._drawable("polygon",n,i)]}})})},n.prototype.path=function(t,e){return i(this,void 0,Promise,function(){var i,n,s,a,o,h,c;return r(this,function(r){switch(r.label){case 0:return i=this._options(e),n=[],t?i.fill?"solid"!==i.fillStyle?[3,1]:(o={type:"path2Dfill",path:t,ops:[]},n.push(o),[3,3]):[3,3]:[2,this._drawable("path",n,i)];case 1:return s=this.computePathSize(t),a=[[0,0],[s[0],0],[s[0],s[1]],[0,s[1]]],[4,this.renderer.patternFillPolygon(a,i)];case 2:(o=r.sent()).type="path2Dpattern",o.size=s,o.path=t,n.push(o),r.label=3;case 3:return c=(h=n).push,[4,this.renderer.svgPath(t,i)];case 4:return c.apply(h,[r.sent()]),[2,this._drawable("path",n,i)]}})})},n}(s),H="undefined"!=typeof document,Y=function(t){function n(e,i){var r=t.call(this,e)||this;return r.gen=new Z(i||null,r.canvas),r}return e(n,t),Object.defineProperty(n.prototype,"generator",{get:function(){return this.gen},enumerable:!0,configurable:!0}),n.prototype.getDefaultOptions=function(){return this.gen.defaultOptions},n.prototype.line=function(t,e,n,s,a){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.line(t,e,n,s,a)];case 1:return i=r.sent(),this.draw(i),[2,i]}})})},n.prototype.rectangle=function(t,e,n,s,a){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.rectangle(t,e,n,s,a)];case 1:return i=r.sent(),this.draw(i),[2,i]}})})},n.prototype.ellipse=function(t,e,n,s,a){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.ellipse(t,e,n,s,a)];case 1:return i=r.sent(),this.draw(i),[2,i]}})})},n.prototype.circle=function(t,e,n,s){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.circle(t,e,n,s)];case 1:return i=r.sent(),this.draw(i),[2,i]}})})},n.prototype.linearPath=function(t,e){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.linearPath(t,e)];case 1:return i=r.sent(),this.draw(i),[2,i]}})})},n.prototype.polygon=function(t,e){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.polygon(t,e)];case 1:return i=r.sent(),this.draw(i),[2,i]}})})},n.prototype.arc=function(t,e,n,s,a,o,h,c){return void 0===h&&(h=!1),i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.arc(t,e,n,s,a,o,h,c)];case 1:return i=r.sent(),this.draw(i),[2,i]}})})},n.prototype.curve=function(t,e){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.curve(t,e)];case 1:return i=r.sent(),this.draw(i),[2,i]}})})},n.prototype.path=function(t,e){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.path(t,e)];case 1:return i=r.sent(),this.draw(i),[2,i]}})})},n}(function(){function t(t){this.canvas=t,this.ctx=this.canvas.getContext("2d")}return t.prototype.draw=function(t){for(var e=t.sets||[],i=t.options||this.getDefaultOptions(),r=this.ctx,n=0,s=e;n<s.length;n++){var a=s[n];switch(a.type){case"path":r.save(),r.strokeStyle=i.stroke,r.lineWidth=i.strokeWidth,this._drawToContext(r,a),r.restore();break;case"fillPath":r.save(),r.fillStyle=i.fill||"",this._drawToContext(r,a),r.restore();break;case"fillSketch":this.fillSketch(r,a,i);break;case"path2Dfill":this.ctx.save(),this.ctx.fillStyle=i.fill||"";var o=new Path2D(a.path);this.ctx.fill(o),this.ctx.restore();break;case"path2Dpattern":var h=this.canvas.ownerDocument||H&&document;if(h){var c=a.size,l=h.createElement("canvas"),u=l.getContext("2d"),p=this.computeBBox(a.path);p&&(p.width||p.height)?(l.width=this.canvas.width,l.height=this.canvas.height,u.translate(p.x||0,p.y||0)):(l.width=c[0],l.height=c[1]),this.fillSketch(u,a,i),this.ctx.save(),this.ctx.fillStyle=this.ctx.createPattern(l,"repeat");o=new Path2D(a.path);this.ctx.fill(o),this.ctx.restore()}else console.error("Cannot render path2Dpattern. No defs/document defined.")}}},t.prototype.computeBBox=function(t){if(H)try{var e="http://www.w3.org/2000/svg",i=document.createElementNS(e,"svg");i.setAttribute("width","0"),i.setAttribute("height","0");var r=self.document.createElementNS(e,"path");r.setAttribute("d",t),i.appendChild(r),document.body.appendChild(i);var n=r.getBBox();return document.body.removeChild(i),n}catch(t){}return null},t.prototype.fillSketch=function(t,e,i){var r=i.fillWeight;r<0&&(r=i.strokeWidth/2),t.save(),t.strokeStyle=i.fill||"",t.lineWidth=r,this._drawToContext(t,e),t.restore()},t.prototype._drawToContext=function(t,e){t.beginPath();for(var i=0,r=e.ops;i<r.length;i++){var n=r[i],s=n.data;switch(n.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"qcurveTo":t.quadraticCurveTo(s[0],s[1],s[2],s[3]);break;case"lineTo":t.lineTo(s[0],s[1])}}"fillPath"===e.type?t.fill():t.stroke()},t}()),J="undefined"!=typeof document,K=function(t){function n(e,i){var r=t.call(this,e)||this;return r.gen=new Z(i||null,r.svg),r}return e(n,t),Object.defineProperty(n.prototype,"generator",{get:function(){return this.gen},enumerable:!0,configurable:!0}),n.prototype.getDefaultOptions=function(){return this.gen.defaultOptions},n.prototype.opsToPath=function(t){return this.gen.opsToPath(t)},n.prototype.line=function(t,e,n,s,a){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.line(t,e,n,s,a)];case 1:return i=r.sent(),[2,this.draw(i)]}})})},n.prototype.rectangle=function(t,e,n,s,a){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.rectangle(t,e,n,s,a)];case 1:return i=r.sent(),[2,this.draw(i)]}})})},n.prototype.ellipse=function(t,e,n,s,a){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.ellipse(t,e,n,s,a)];case 1:return i=r.sent(),[2,this.draw(i)]}})})},n.prototype.circle=function(t,e,n,s){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.circle(t,e,n,s)];case 1:return i=r.sent(),[2,this.draw(i)]}})})},n.prototype.linearPath=function(t,e){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.linearPath(t,e)];case 1:return i=r.sent(),[2,this.draw(i)]}})})},n.prototype.polygon=function(t,e){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.polygon(t,e)];case 1:return i=r.sent(),[2,this.draw(i)]}})})},n.prototype.arc=function(t,e,n,s,a,o,h,c){return void 0===h&&(h=!1),i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.arc(t,e,n,s,a,o,h,c)];case 1:return i=r.sent(),[2,this.draw(i)]}})})},n.prototype.curve=function(t,e){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.curve(t,e)];case 1:return i=r.sent(),[2,this.draw(i)]}})})},n.prototype.path=function(t,e){return i(this,void 0,Promise,function(){var i;return r(this,function(r){switch(r.label){case 0:return[4,this.gen.path(t,e)];case 1:return i=r.sent(),[2,this.draw(i)]}})})},n}(function(){function t(t){this.svg=t}return Object.defineProperty(t.prototype,"defs",{get:function(){var t=this.svg.ownerDocument||J&&document;if(t&&!this._defs){var e=t.createElementNS("http://www.w3.org/2000/svg","defs");this.svg.firstChild?this.svg.insertBefore(e,this.svg.firstChild):this.svg.appendChild(e),this._defs=e}return this._defs||null},enumerable:!0,configurable:!0}),t.prototype.draw=function(t){for(var e=t.sets||[],i=t.options||this.getDefaultOptions(),r=this.svg.ownerDocument||window.document,n=r.createElementNS("http://www.w3.org/2000/svg","g"),s=0,a=e;s<a.length;s++){var o=a[s],h=null;switch(o.type){case"path":(h=r.createElementNS("http://www.w3.org/2000/svg","path")).setAttribute("d",this.opsToPath(o)),h.style.stroke=i.stroke,h.style.strokeWidth=i.strokeWidth+"",h.style.fill="none";break;case"fillPath":(h=r.createElementNS("http://www.w3.org/2000/svg","path")).setAttribute("d",this.opsToPath(o)),h.style.stroke="none",h.style.strokeWidth="0",h.style.fill=i.fill||null;break;case"fillSketch":h=this.fillSketch(r,o,i);break;case"path2Dfill":(h=r.createElementNS("http://www.w3.org/2000/svg","path")).setAttribute("d",o.path||""),h.style.stroke="none",h.style.strokeWidth="0",h.style.fill=i.fill||null;break;case"path2Dpattern":if(this.defs){var c=o.size,l=r.createElementNS("http://www.w3.org/2000/svg","pattern"),u="rough-"+Math.floor(Math.random()*(Number.MAX_SAFE_INTEGER||999999));l.setAttribute("id",u),l.setAttribute("x","0"),l.setAttribute("y","0"),l.setAttribute("width","1"),l.setAttribute("height","1"),l.setAttribute("height","1"),l.setAttribute("viewBox","0 0 "+Math.round(c[0])+" "+Math.round(c[1])),l.setAttribute("patternUnits","objectBoundingBox");var p=this.fillSketch(r,o,i);l.appendChild(p),this.defs.appendChild(l),(h=r.createElementNS("http://www.w3.org/2000/svg","path")).setAttribute("d",o.path||""),h.style.stroke="none",h.style.strokeWidth="0",h.style.fill="url(#"+u+")"}else console.error("Cannot render path2Dpattern. No defs/document defined.")}h&&n.appendChild(h)}return n},t.prototype.fillSketch=function(t,e,i){var r=i.fillWeight;r<0&&(r=i.strokeWidth/2);var n=t.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d",this.opsToPath(e)),n.style.stroke=i.fill||null,n.style.strokeWidth=r+"",n.style.fill="none",n},t}());return{canvas:function(t,e){return new Y(t,e)},svg:function(t,e){return new K(t,e)},generator:function(t,e){return new Z(t,e)}}}();