mirror of
https://github.com/rough-stuff/rough.git
synced 2026-04-22 03:00:28 -04:00
2 lines
38 KiB
JavaScript
2 lines
38 KiB
JavaScript
"use strict";var t="http://www.w3.org/2000/svg";function e(t,e,r){if(t&&t.length){var n=e[0],i=e[1],a=Math.PI/180*r,o=Math.cos(a),s=Math.sin(a);t.forEach((function(t){var e=t[0],r=t[1];t[0]=(e-n)*o-(r-i)*s+n,t[1]=(e-n)*s+(r-i)*o+i}))}}function r(t){var e=t[0],r=t[1];return Math.sqrt(Math.pow(e[0]-r[0],2)+Math.pow(e[1]-r[1],2))}function n(t,e,r){return[t[0]+(e[0]-t[0])*r,t[1]+(e[1]-t[1])*r]}function i(t,e){var r=t[0]-e[0],n=t[1]-e[1];return r*r+n*n}function a(t,e,r){var a=i(e,r);if(0===a)return i(t,e);var o=((t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]))/a;return i(t,n(e,r,o=Math.max(0,Math.min(1,o))))}function o(t,e){return t.type===e}var s={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},h=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[];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),r=0,n=e[r],i="BOD";for(this.segments=new Array;!o(n,this.EOD);){var a=void 0,h=new Array;if("BOD"===i){if("M"!==n.text&&"m"!==n.text)return void this.parseData("M0,0"+t);r++,a=s[n.text],i=n.text}else o(n,this.NUMBER)?a=s[i]:(r++,a=s[n.text],i=n.text);if(r+a<e.length){for(var u=r;u<r+a;u++){var c=e[u];if(!o(c,this.NUMBER))return void console.error("Param not a number: "+i+","+c.text);h[h.length]=+c.text}if("number"!=typeof s[i])return void console.error("Bad segment: "+i);var l={key:i,data:h};this.segments.push(l),n=e[r+=a],"M"===i&&(i="L"),"m"===i&&(i="l")}else console.error("Path data ended short")}},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],r=0;r<this.segments.length;r++){var n=this.segments[r];switch(n.key){case"M":case"L":case"T":n.point=[n.data[0],n.data[1]];break;case"m":case"l":case"t":n.point=[n.data[0]+e[0],n.data[1]+e[1]];break;case"H":n.point=[n.data[0],e[1]];break;case"h":n.point=[n.data[0]+e[0],e[1]];break;case"V":n.point=[e[0],n.data[0]];break;case"v":n.point=[e[0],n.data[0]+e[1]];break;case"z":case"Z":t&&(n.point=[t[0],t[1]]);break;case"C":n.point=[n.data[4],n.data[5]];break;case"c":n.point=[n.data[4]+e[0],n.data[5]+e[1]];break;case"S":n.point=[n.data[2],n.data[3]];break;case"s":n.point=[n.data[2]+e[0],n.data[3]+e[1]];break;case"Q":n.point=[n.data[2],n.data[3]];break;case"q":n.point=[n.data[2]+e[0],n.data[3]+e[1]];break;case"A":n.point=[n.data[5],n.data[6]];break;case"a":n.point=[n.data[5]+e[0],n.data[6]+e[1]]}"m"!==n.key&&"M"!==n.key||(t=null),n.point&&(e=n.point,t||(t=n.point)),"z"!==n.key&&"Z"!==n.key||(t=null)}},t}(),u=function(){function t(t){this._position=[0,0],this._first=null,this.bezierReflectionPoint=null,this.quadReflectionPoint=null,this.parsed=new h(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=[],r=0,n=this.parsed.segments;r<n.length;r++){var i=n[r],a=i.key.toLowerCase();("m"!==a&&"z"!==a||(e.length&&(t.push(e),e=[]),"z"!==a))&&(i.point&&e.push(i.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}(),c=function(){function t(t,e,r,n,i,a){if(this._segIndex=0,this._numSegs=0,this._rx=0,this._ry=0,this._sinPhi=0,this._cosPhi=0,this._C=[0,0],this._theta=0,this._delta=0,this._T=0,this._from=t,t[0]!==e[0]||t[1]!==e[1]){var o=Math.PI/180;this._rx=Math.abs(r[0]),this._ry=Math.abs(r[1]),this._sinPhi=Math.sin(n*o),this._cosPhi=Math.cos(n*o);var s=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,u=0,c=this._rx*this._rx*this._ry*this._ry-this._rx*this._rx*h*h-this._ry*this._ry*s*s;if(c<0){var l=Math.sqrt(1-c/(this._rx*this._rx*this._ry*this._ry));this._rx=this._rx*l,this._ry=this._ry*l,u=0}else u=(i===a?-1:1)*Math.sqrt(c/(this._rx*this._rx*h*h+this._ry*this._ry*s*s));var f=u*this._rx*h/this._ry,p=-u*this._ry*s/this._rx;this._C=[0,0],this._C[0]=this._cosPhi*f-this._sinPhi*p+(t[0]+e[0])/2,this._C[1]=this._sinPhi*f+this._cosPhi*p+(t[1]+e[1])/2,this._theta=this.calculateVectorAngle(1,0,(s-f)/this._rx,(h-p)/this._ry);var d=this.calculateVectorAngle((s-f)/this._rx,(h-p)/this._ry,(-s-f)/this._rx,(-h-p)/this._ry);!a&&d>0?d-=2*Math.PI:a&&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),r=this._theta+this._delta,n=Math.cos(r),i=Math.sin(r),a=[this._cosPhi*this._rx*n-this._sinPhi*this._ry*i+this._C[0],this._sinPhi*this._rx*n+this._cosPhi*this._ry*i+this._C[1]],o=[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)],s=[a[0]+this._T*(this._cosPhi*this._rx*i+this._sinPhi*this._ry*n),a[1]+this._T*(this._sinPhi*this._rx*i-this._cosPhi*this._ry*n)];return this._theta=r,this._from=[a[0],a[1]],this._segIndex++,{cp1:o,cp2:s,to:a}},t.prototype.calculateVectorAngle=function(t,e,r,n){var i=Math.atan2(e,t),a=Math.atan2(n,r);return a>=i?a-i:2*Math.PI-(i-a)},t}(),l=function(){function t(t,e){this.sets=t,this.closed=e}return t.prototype.fit=function(t){for(var e=[],r=0,n=this.sets;r<n.length;r++){var i=(u=n[r]).length,a=Math.floor(t*i);if(a<5){if(i<=5)continue;a=5}e.push(this.reduce(u,a))}for(var o="",s=0,h=e;s<h.length;s++){for(var u=h[s],c=0;c<u.length;c++){var l=u[c];o+=0===c?"M"+l[0]+","+l[1]:"L"+l[0]+","+l[1]}this.closed&&(o+="z ")}return o},t.prototype.reduce=function(t,e){if(t.length<=e)return t;for(var n=t.slice(0);n.length>e;){for(var i=[],a=-1,o=-1,s=1;s<n.length-1;s++){var h=r([n[s-1],n[s]]),u=r([n[s],n[s+1]]),c=r([n[s-1],n[s+1]]),l=(h+u+c)/2,f=Math.sqrt(l*(l-h)*(l-u)*(l-c));i.push(f),(a<0||f<a)&&(a=f,o=s)}if(!(o>0))break;n.splice(o,1)}return n},t}(),f=function(t,e){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function p(t,e){function r(){this.constructor=t}f(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function d(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),i=0;for(e=0;e<r;e++)for(var a=arguments[e],o=0,s=a.length;o<s;o++,i++)n[i]=a[o];return n}function v(t,r){var n=[0,0],i=Math.round(r.hachureAngle+90);i&&e(t,n,i);var a=function(t,e){var r=d(t);r[0].join(",")!==r[r.length-1].join(",")&&r.push([r[0][0],r[0][1]]);var n=[];if(r&&r.length>2){var i=e.hachureGap;i<0&&(i=4*e.strokeWidth),i=Math.max(i,.1);for(var a=[],o=0;o<r.length-1;o++){var s=r[o],h=r[o+1];if(s[1]!==h[1]){var u=Math.min(s[1],h[1]);a.push({ymin:u,ymax:Math.max(s[1],h[1]),x:u===s[1]?s[0]:h[0],islope:(h[0]-s[0])/(h[1]-s[1])})}}if(a.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)})),!a.length)return n;for(var c=[],l=a[0].ymin;c.length||a.length;){if(a.length){var f=-1;for(o=0;o<a.length&&!(a[o].ymin>l);o++)f=o;a.splice(0,f+1).forEach((function(t){c.push({s:l,edge:t})}))}if((c=c.filter((function(t){return!(t.edge.ymax<=l)}))).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)})),c.length>1)for(o=0;o<c.length;o+=2){var p=o+1;if(p>=c.length)break;var v=c[o].edge,g=c[p].edge;n.push([[Math.round(v.x),l],[Math.round(g.x),l]])}l+=i,c.forEach((function(t){t.edge.x=t.edge.x+i*t.edge.islope}))}}return n}(t,r);return i&&(e(t,n,-i),function(t,r,n){var i=[];t.forEach((function(t){return i.push.apply(i,t)})),e(i,r,n)}(a,n,-i)),a}var g=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,r){void 0===r&&(r=!1);var n=v(t,e);return{type:"fillSketch",ops:this.renderLines(n,e,r)}},t.prototype.renderLines=function(t,e,r){for(var n=[],i=null,a=0,o=t;a<o.length;a++){var s=o[a];n=n.concat(this.helper.doubleLineOps(s[0][0],s[0][1],s[1][0],s[1][1],e)),r&&i&&(n=n.concat(this.helper.doubleLineOps(i[0],i[1],s[0][0],s[0][1],e))),i=s[1]}return n},t}(),y=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return p(e,t),e.prototype.fillPolygon=function(t,e){return this._fillPolygon(t,e,!0)},e}(g),m=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return p(e,t),e.prototype.fillPolygon=function(t,e){var r=this._fillPolygon(t,e),n=Object.assign({},e,{hachureAngle:e.hachureAngle+90}),i=this._fillPolygon(t,n);return r.ops=r.ops.concat(i.ops),r},e}(g),b=function(){function t(t){this.helper=t}return t.prototype.fillPolygon=function(t,e){var r=v(t,e=Object.assign({},e,{curveStepCount:4,hachureAngle:0,roughness:1}));return this.dotsOnLines(r,e)},t.prototype.dotsOnLines=function(t,e){var n=[],i=e.hachureGap;i<0&&(i=4*e.strokeWidth),i=Math.max(i,.1);var a=e.fillWeight;a<0&&(a=e.strokeWidth/2);for(var o=0,s=t;o<s.length;o++)for(var h=s[o],u=r(h)/i,c=Math.ceil(u)-1,l=Math.atan((h[1][1]-h[0][1])/(h[1][0]-h[0][0])),f=0;f<c;f++){var p=i*(f+1),d=p*Math.sin(l),v=p*Math.cos(l),g=[h[0][0]-v,h[0][1]+d],y=this.helper.randOffsetWithRange(g[0]-i/4,g[0]+i/4,e),m=this.helper.randOffsetWithRange(g[1]-i/4,g[1]+i/4,e),b=this.helper.ellipse(y,m,a,a,e);n=n.concat(b.ops)}return{type:"fillSketch",ops:n}},t}(),_=function(){function t(t){this.helper=t}return t.prototype.fillPolygon=function(t,e){var r=v(t,e);return{type:"fillSketch",ops:this.dashedLine(r,e)}},t.prototype.dashedLine=function(t,e){var n=this,i=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,o=[];return t.forEach((function(t){var s=r(t),h=Math.floor(s/(i+a)),u=(s+a-h*(i+a))/2,c=t[0],l=t[1];c[0]>l[0]&&(c=t[1],l=t[0]);for(var f=Math.atan((l[1]-c[1])/(l[0]-c[0])),p=0;p<h;p++){var d=p*(i+a),v=d+i,g=[c[0]+d*Math.cos(f)+u*Math.cos(f),c[1]+d*Math.sin(f)+u*Math.sin(f)],y=[c[0]+v*Math.cos(f)+u*Math.cos(f),c[1]+v*Math.sin(f)+u*Math.sin(f)];o=o.concat(n.helper.doubleLineOps(g[0],g[1],y[0],y[1],e))}})),o},t}(),M=function(){function t(t){this.helper=t}return t.prototype.fillPolygon=function(t,e){var r=e.hachureGap<0?4*e.strokeWidth:e.hachureGap,n=e.zigzagOffset<0?r:e.zigzagOffset,i=v(t,e=Object.assign({},e,{hachureGap:r+n}));return{type:"fillSketch",ops:this.zigzagLines(i,n,e)}},t.prototype.zigzagLines=function(t,e,n){var i=this,a=[];return t.forEach((function(t){var o=r(t),s=Math.round(o/(2*e)),h=t[0],u=t[1];h[0]>u[0]&&(h=t[1],u=t[0]);for(var c=Math.atan((u[1]-h[1])/(u[0]-h[0])),l=0;l<s;l++){var f=2*l*e,p=2*(l+1)*e,d=Math.sqrt(2*Math.pow(e,2)),v=[h[0]+f*Math.cos(c),h[1]+f*Math.sin(c)],g=[h[0]+p*Math.cos(c),h[1]+p*Math.sin(c)],y=[v[0]+d*Math.cos(c+Math.PI/4),v[1]+d*Math.sin(c+Math.PI/4)];a=(a=a.concat(i.helper.doubleLineOps(v[0],v[1],y[0],y[1],n))).concat(i.helper.doubleLineOps(y[0],y[1],g[0],g[1],n))}})),a},t}(),x={};var P=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}(),k={randOffset:function(t,e){return W(t,e)},randOffsetWithRange:function(t,e,r){return I(t,e,r)},ellipse:function(t,e,r,n,i){var a=A(r,n,i);return C(t,e,i,a).opset},doubleLineOps:function(t,e,r,n,i){return N(t,e,r,n,i)}};function w(t,e,r,n,i){return{type:"path",ops:N(t,e,r,n,i)}}function O(t,e,r){var n=(t||[]).length;if(n>2){for(var i=[],a=0;a<n-1;a++)i=i.concat(N(t[a][0],t[a][1],t[a+1][0],t[a+1][1],r));return e&&(i=i.concat(N(t[n-1][0],t[n-1][1],t[0][0],t[0][1],r))),{type:"path",ops:i}}return 2===n?w(t[0][0],t[0][1],t[1][0],t[1][1],r):{type:"path",ops:[]}}function S(t,e,r,n,i){return function(t,e){return O(t,!0,e)}([[t,e],[t+r,e],[t+r,e+n],[t,e+n]],i)}function T(t,e){var r=D(t,1*(1+.2*e.roughness),e),n=D(t,1.5*(1+.22*e.roughness),e);return{type:"path",ops:r.concat(n)}}function A(t,e,r){var n=Math.sqrt(2*Math.PI*Math.sqrt((Math.pow(t/2,2)+Math.pow(e/2,2))/2)),i=Math.max(r.curveStepCount,r.curveStepCount/Math.sqrt(200)*n),a=2*Math.PI/i,o=Math.abs(t/2),s=Math.abs(e/2),h=1-r.curveFitting;return{increment:a,rx:o+=W(o*h,r),ry:s+=W(s*h,r)}}function C(t,e,r,n){var i=F(n.increment,t,e,n.rx,n.ry,1,n.increment*I(.1,I(.4,1,r),r),r),a=i[0],o=i[1],s=F(n.increment,t,e,n.rx,n.ry,1.5,0,r)[0],h=q(a,null,r),u=q(s,null,r);return{estimatedPoints:o,opset:{type:"path",ops:h.concat(u)}}}function E(t,e,r,n,i,a,o,s,h){var u=t,c=e,l=Math.abs(r/2),f=Math.abs(n/2);l+=W(.01*l,h),f+=W(.01*f,h);for(var p=i,d=a;p<0;)p+=2*Math.PI,d+=2*Math.PI;d-p>2*Math.PI&&(p=0,d=2*Math.PI);var v=2*Math.PI/h.curveStepCount,g=Math.min(v/2,(d-p)/2),y=j(g,u,c,l,f,p,d,1,h),m=j(g,u,c,l,f,p,d,1.5,h),b=y.concat(m);return o&&(s?b=(b=b.concat(N(u,c,u+l*Math.cos(p),c+f*Math.sin(p),h))).concat(N(u,c,u+l*Math.cos(d),c+f*Math.sin(d),h)):(b.push({op:"lineTo",data:[u,c]}),b.push({op:"lineTo",data:[u+l*Math.cos(p),c+f*Math.sin(p)]}))),{type:"path",ops:b}}function z(t,e){var r=[];if(t.length){var n=e.maxRandomnessOffset||0,i=t.length;if(i>2){r.push({op:"move",data:[t[0][0]+W(n,e),t[0][1]+W(n,e)]});for(var a=1;a<i;a++)r.push({op:"lineTo",data:[t[a][0]+W(n,e),t[a][1]+W(n,e)]})}}return{type:"fillPath",ops:r}}function L(t,e){return function(t,e){var r=t.fillStyle||"hachure";if(!x[r])switch(r){case"zigzag":x[r]||(x[r]=new y(e));break;case"cross-hatch":x[r]||(x[r]=new m(e));break;case"dots":x[r]||(x[r]=new b(e));break;case"dashed":x[r]||(x[r]=new _(e));break;case"zigzag-line":x[r]||(x[r]=new M(e));break;case"hachure":default:x[r="hachure"]||(x[r]=new g(e))}return x[r]}(e,k).fillPolygon(t,e)}function R(t){return t.randomizer||(t.randomizer=new P(t.seed||0)),t.randomizer.next()}function I(t,e,r){return r.roughness*r.roughnessGain*(R(r)*(e-t)+t)}function W(t,e){return I(-t,t,e)}function N(t,e,r,n,i){var a=B(t,e,r,n,i,!0,!1),o=B(t,e,r,n,i,!0,!0);return a.concat(o)}function B(t,e,r,n,i,a,o){var s=Math.pow(t-r,2)+Math.pow(e-n,2),h=Math.sqrt(s);i.roughnessGain=h<200?1:h>500?.4:-.0016668*h+1.233334;var u=i.maxRandomnessOffset||0;u*u*100>s&&(u=h/10);var c=u/2,l=.2+.2*R(i),f=i.bowing*i.maxRandomnessOffset*(n-e)/200,p=i.bowing*i.maxRandomnessOffset*(t-r)/200;f=W(f,i),p=W(p,i);var d=[],v=function(){return W(c,i)},g=function(){return W(u,i)};return a&&(o?d.push({op:"move",data:[t+v(),e+v()]}):d.push({op:"move",data:[t+W(u,i),e+W(u,i)]})),o?d.push({op:"bcurveTo",data:[f+t+(r-t)*l+v(),p+e+(n-e)*l+v(),f+t+2*(r-t)*l+v(),p+e+2*(n-e)*l+v(),r+v(),n+v()]}):d.push({op:"bcurveTo",data:[f+t+(r-t)*l+g(),p+e+(n-e)*l+g(),f+t+2*(r-t)*l+g(),p+e+2*(n-e)*l+g(),r+g(),n+g()]}),d}function D(t,e,r){var n=[];n.push([t[0][0]+W(e,r),t[0][1]+W(e,r)]),n.push([t[0][0]+W(e,r),t[0][1]+W(e,r)]);for(var i=1;i<t.length;i++)n.push([t[i][0]+W(e,r),t[i][1]+W(e,r)]),i===t.length-1&&n.push([t[i][0]+W(e,r),t[i][1]+W(e,r)]);return q(n,null,r)}function q(t,e,r){var n=t.length,i=[];if(n>3){var a=[],o=1-r.curveTightness;i.push({op:"move",data:[t[1][0],t[1][1]]});for(var s=1;s+2<n;s++){var h=t[s];a[0]=[h[0],h[1]],a[1]=[h[0]+(o*t[s+1][0]-o*t[s-1][0])/6,h[1]+(o*t[s+1][1]-o*t[s-1][1])/6],a[2]=[t[s+1][0]+(o*t[s][0]-o*t[s+2][0])/6,t[s+1][1]+(o*t[s][1]-o*t[s+2][1])/6],a[3]=[t[s+1][0],t[s+1][1]],i.push({op:"bcurveTo",data:[a[1][0],a[1][1],a[2][0],a[2][1],a[3][0],a[3][1]]})}if(e&&2===e.length){var u=r.maxRandomnessOffset;i.push({op:"lineTo",data:[e[0]+W(u,r),e[1]+W(u,r)]})}}else 3===n?(i.push({op:"move",data:[t[1][0],t[1][1]]}),i.push({op:"bcurveTo",data:[t[1][0],t[1][1],t[2][0],t[2][1],t[2][0],t[2][1]]})):2===n&&(i=i.concat(N(t[0][0],t[0][1],t[1][0],t[1][1],r)));return i}function F(t,e,r,n,i,a,o,s){var h=[],u=[],c=W(.5,s)-Math.PI/2;u.push([W(a,s)+e+.9*n*Math.cos(c-t),W(a,s)+r+.9*i*Math.sin(c-t)]);for(var l=c;l<2*Math.PI+c-.01;l+=t){var f=[W(a,s)+e+n*Math.cos(l),W(a,s)+r+i*Math.sin(l)];h.push(f),u.push(f)}return u.push([W(a,s)+e+n*Math.cos(c+2*Math.PI+.5*o),W(a,s)+r+i*Math.sin(c+2*Math.PI+.5*o)]),u.push([W(a,s)+e+.98*n*Math.cos(c+o),W(a,s)+r+.98*i*Math.sin(c+o)]),u.push([W(a,s)+e+.9*n*Math.cos(c+.5*o),W(a,s)+r+.9*i*Math.sin(c+.5*o)]),[u,h]}function j(t,e,r,n,i,a,o,s,h){var u=a+W(.1,h),c=[];c.push([W(s,h)+e+.9*n*Math.cos(u-t),W(s,h)+r+.9*i*Math.sin(u-t)]);for(var l=u;l<=o;l+=t)c.push([W(s,h)+e+n*Math.cos(l),W(s,h)+r+i*Math.sin(l)]);return c.push([e+n*Math.cos(o),r+i*Math.sin(o)]),c.push([e+n*Math.cos(o),r+i*Math.sin(o)]),q(c,null,h)}function V(t,e,r,n,i,a,o,s){for(var h=[],u=[s.maxRandomnessOffset||1,(s.maxRandomnessOffset||1)+.5],c=[0,0],l=0;l<2;l++)0===l?h.push({op:"move",data:[o.x,o.y]}):h.push({op:"move",data:[o.x+W(u[0],s),o.y+W(u[0],s)]}),c=[i+W(u[l],s),a+W(u[l],s)],h.push({op:"bcurveTo",data:[t+W(u[l],s),e+W(u[l],s),r+W(u[l],s),n+W(u[l],s),c[0],c[1]]});return o.setPosition(c[0],c[1]),h}function G(t,e,r,n){var i=[];switch(e.key){case"M":case"m":var a="m"===e.key;if(e.data.length>=2){var o=+e.data[0],s=+e.data[1];a&&(o+=t.x,s+=t.y);var h=1*(n.maxRandomnessOffset||0);o+=W(h,n),s+=W(h,n),t.setPosition(o,s),i.push({op:"move",data:[o,s]})}break;case"L":case"l":a="l"===e.key;if(e.data.length>=2){o=+e.data[0],s=+e.data[1];a&&(o+=t.x,s+=t.y),i=i.concat(N(t.x,t.y,o,s,n)),t.setPosition(o,s)}break;case"H":case"h":a="h"===e.key;if(e.data.length){o=+e.data[0];a&&(o+=t.x),i=i.concat(N(t.x,t.y,o,t.y,n)),t.setPosition(o,t.y)}break;case"V":case"v":a="v"===e.key;if(e.data.length){s=+e.data[0];a&&(s+=t.y),i=i.concat(N(t.x,t.y,t.x,s,n)),t.setPosition(t.x,s)}break;case"Z":case"z":t.first&&(i=i.concat(N(t.x,t.y,t.first[0],t.first[1],n)),t.setPosition(t.first[0],t.first[1]),t.first=null);break;case"C":case"c":a="c"===e.key;if(e.data.length>=6){var u=+e.data[0],l=+e.data[1],f=+e.data[2],p=+e.data[3];o=+e.data[4],s=+e.data[5];a&&(u+=t.x,f+=t.x,o+=t.x,l+=t.y,p+=t.y,s+=t.y);var d=V(u,l,f,p,o,s,t,n);i=i.concat(d),t.bezierReflectionPoint=[o+(o-f),s+(s-p)]}break;case"S":case"s":a="s"===e.key;if(e.data.length>=4){f=+e.data[0],p=+e.data[1],o=+e.data[2],s=+e.data[3];a&&(f+=t.x,o+=t.x,p+=t.y,s+=t.y);u=f,l=p;var v=null;"c"!==(b=r?r.key:"")&&"C"!==b&&"s"!==b&&"S"!==b||(v=t.bezierReflectionPoint),v&&(u=v[0],l=v[1]);d=V(u,l,f,p,o,s,t,n);i=i.concat(d),t.bezierReflectionPoint=[o+(o-f),s+(s-p)]}break;case"Q":case"q":a="q"===e.key;if(e.data.length>=4){u=+e.data[0],l=+e.data[1],o=+e.data[2],s=+e.data[3];a&&(u+=t.x,o+=t.x,l+=t.y,s+=t.y);var g=1*(1+.2*n.roughness),y=1.5*(1+.22*n.roughness);i.push({op:"move",data:[t.x+W(g,n),t.y+W(g,n)]});var m=[o+W(g,n),s+W(g,n)];i.push({op:"qcurveTo",data:[u+W(g,n),l+W(g,n),m[0],m[1]]}),i.push({op:"move",data:[t.x+W(y,n),t.y+W(y,n)]}),m=[o+W(y,n),s+W(y,n)],i.push({op:"qcurveTo",data:[u+W(y,n),l+W(y,n),m[0],m[1]]}),t.setPosition(m[0],m[1]),t.quadReflectionPoint=[o+(o-u),s+(s-l)]}break;case"T":case"t":a="t"===e.key;if(e.data.length>=2){o=+e.data[0],s=+e.data[1];a&&(o+=t.x,s+=t.y);var b;u=o,l=s,v=null;"q"!==(b=r?r.key:"")&&"Q"!==b&&"t"!==b&&"T"!==b||(v=t.quadReflectionPoint),v&&(u=v[0],l=v[1]);g=1*(1+.2*n.roughness),y=1.5*(1+.22*n.roughness);i.push({op:"move",data:[t.x+W(g,n),t.y+W(g,n)]});m=[o+W(g,n),s+W(g,n)];i.push({op:"qcurveTo",data:[u+W(g,n),l+W(g,n),m[0],m[1]]}),i.push({op:"move",data:[t.x+W(y,n),t.y+W(y,n)]}),m=[o+W(y,n),s+W(y,n)],i.push({op:"qcurveTo",data:[u+W(y,n),l+W(y,n),m[0],m[1]]}),t.setPosition(m[0],m[1]),t.quadReflectionPoint=[o+(o-u),s+(s-l)]}break;case"A":case"a":a="a"===e.key;if(e.data.length>=7){var _=+e.data[0],M=+e.data[1],x=+e.data[2],P=+e.data[3],k=+e.data[4];o=+e.data[5],s=+e.data[6];if(a&&(o+=t.x,s+=t.y),o===t.x&&s===t.y)break;if(0===_||0===M)i=i.concat(N(t.x,t.y,o,s,n)),t.setPosition(o,s);else for(var w=0;w<1;w++)for(var O=new c([t.x,t.y],[o,s],[_,M],x,!!P,!!k),S=O.getNextSegment();S;){d=V(S.cp1[0],S.cp1[1],S.cp2[0],S.cp2[1],S.to[0],S.to[1],t,n);i=i.concat(d),S=O.getNextSegment()}}}return i}var U="undefined"!=typeof self,H="none",Q={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,roughnessGain:1},Z=function(){function e(t,e){this.defaultOptions=JSON.parse(JSON.stringify(Q)),this.config=t||{},this.surface=e,this.config.options&&(this.defaultOptions=this._options(this.config.options))}return e.newSeed=function(){return Math.floor(Math.random()*Math.pow(2,31))},e.prototype._options=function(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions},e.prototype._drawable=function(t,e,r){return{shape:t,sets:e||[],options:r||this.defaultOptions}},e.prototype.line=function(t,e,r,n,i){var a=this._options(i);return this._drawable("line",[w(t,e,r,n,a)],a)},e.prototype.rectangle=function(t,e,r,n,i){var a=this._options(i),o=[],s=S(t,e,r,n,a);if(a.fill){var h=[[t,e],[t+r,e],[t+r,e+n],[t,e+n]];"solid"===a.fillStyle?o.push(z(h,a)):o.push(L(h,a))}return a.stroke!==H&&o.push(s),this._drawable("rectangle",o,a)},e.prototype.ellipse=function(t,e,r,n,i){var a=this._options(i),o=[],s=A(r,n,a),h=C(t,e,a,s);if(a.fill)if("solid"===a.fillStyle){var u=C(t,e,a,s).opset;u.type="fillPath",o.push(u)}else o.push(L(h.estimatedPoints,a));return a.stroke!==H&&o.push(h.opset),this._drawable("ellipse",o,a)},e.prototype.circle=function(t,e,r,n){var i=this.ellipse(t,e,r,r,n);return i.shape="circle",i},e.prototype.linearPath=function(t,e){var r=this._options(e);return this._drawable("linearPath",[O(t,!1,r)],r)},e.prototype.arc=function(t,e,r,n,i,a,o,s){void 0===o&&(o=!1);var h=this._options(s),u=[],c=E(t,e,r,n,i,a,o,!0,h);if(o&&h.fill)if("solid"===h.fillStyle){var l=E(t,e,r,n,i,a,!0,!1,h);l.type="fillPath",u.push(l)}else u.push(function(t,e,r,n,i,a,o){var s=t,h=e,u=Math.abs(r/2),c=Math.abs(n/2);u+=W(.01*u,o),c+=W(.01*c,o);for(var l=i,f=a;l<0;)l+=2*Math.PI,f+=2*Math.PI;f-l>2*Math.PI&&(l=0,f=2*Math.PI);for(var p=(f-l)/o.curveStepCount,d=[],v=l;v<=f;v+=p)d.push([s+u*Math.cos(v),h+c*Math.sin(v)]);return d.push([s+u*Math.cos(f),h+c*Math.sin(f)]),d.push([s,h]),L(d,o)}(t,e,r,n,i,a,h));return h.stroke!==H&&u.push(c),this._drawable("arc",u,h)},e.prototype.curve=function(t,e){var r=this._options(e);return this._drawable("curve",[T(t,r)],r)},e.prototype.polygon=function(t,e){var r=this._options(e),n=[],i=O(t,!0,r);return r.fill&&("solid"===r.fillStyle?n.push(z(t,r)):n.push(L(t,r))),r.stroke!==H&&n.push(i),this._drawable("polygon",n,r)},e.prototype.path=function(t,e){var r=this._options(e),n=[];if(!t)return this._drawable("path",n,r);var i=function(t,e){t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");var r=new u(t);if(e.simplification){var n=new l(r.linearPoints,r.closed).fit(e.simplification);r=new u(n)}for(var i=[],a=r.segments||[],o=0;o<a.length;o++){var s=G(r,a[o],o>0?a[o-1]:null,e);s&&s.length&&(i=i.concat(s))}return{type:"path",ops:i}}(t,r);if(r.fill)if("solid"===r.fillStyle){var a={type:"path2Dfill",path:t,ops:[]};n.push(a)}else{var o=this.computePathSize(t);(a=L([[0,0],[o[0],0],[o[0],o[1]],[0,o[1]]],r)).type="path2Dpattern",a.size=o,a.path=t,n.push(a)}return r.stroke!==H&&n.push(i),this._drawable("path",n,r)},e.prototype.computePathSize=function(e){var r=[0,0];if(U&&self.document)try{var n=self.document.createElementNS(t,"svg");n.setAttribute("width","0"),n.setAttribute("height","0");var i=self.document.createElementNS(t,"path");i.setAttribute("d",e),n.appendChild(i),self.document.body.appendChild(n);var a=i.getBBox();a&&(r[0]=a.width||0,r[1]=a.height||0),self.document.body.removeChild(n)}catch(t){}var o=this.getCanvasSize();return r[0]*r[1]||(r=o),r},e.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]},e.prototype.opsToPath=function(t){for(var e="",r=0,n=t.ops;r<n.length;r++){var i=n[r],a=i.data;switch(i.op){case"move":e+="M"+a[0]+" "+a[1]+" ";break;case"bcurveTo":e+="C"+a[0]+" "+a[1]+", "+a[2]+" "+a[3]+", "+a[4]+" "+a[5]+" ";break;case"qcurveTo":e+="Q"+a[0]+" "+a[1]+", "+a[2]+" "+a[3]+" ";break;case"lineTo":e+="L"+a[0]+" "+a[1]+" "}}return e.trim()},e.prototype.toPaths=function(t){for(var e=t.sets||[],r=t.options||this.defaultOptions,n=[],i=0,a=e;i<a.length;i++){var o=a[i],s=null;switch(o.type){case"path":s={d:this.opsToPath(o),stroke:r.stroke,strokeWidth:r.strokeWidth,fill:H};break;case"fillPath":s={d:this.opsToPath(o),stroke:H,strokeWidth:0,fill:r.fill||H};break;case"fillSketch":s=this.fillSketch(o,r);break;case"path2Dfill":s={d:o.path||"",stroke:H,strokeWidth:0,fill:r.fill||H};break;case"path2Dpattern":var h=o.size,u={x:0,y:0,width:1,height:1,viewBox:"0 0 "+Math.round(h[0])+" "+Math.round(h[1]),patternUnits:"objectBoundingBox",path:this.fillSketch(o,r)};s={d:o.path,stroke:H,strokeWidth:0,pattern:u}}s&&n.push(s)}return n},e.prototype.fillSketch=function(t,e){var r=e.fillWeight;return r<0&&(r=e.strokeWidth/2),{d:this.opsToPath(t),stroke:e.fill||H,strokeWidth:r,fill:H}},e}(),$="undefined"!=typeof document,J=function(){function e(t,e){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new Z(e,this.canvas)}return e.prototype.draw=function(t){for(var e=t.sets||[],r=t.options||this.getDefaultOptions(),n=this.ctx,i=0,a=e;i<a.length;i++){var o=a[i];switch(o.type){case"path":n.save(),n.strokeStyle="none"===r.stroke?"transparent":r.stroke,n.lineWidth=r.strokeWidth,this._drawToContext(n,o),n.restore();break;case"fillPath":n.save(),n.fillStyle=r.fill||"",this._drawToContext(n,o),n.restore();break;case"fillSketch":this.fillSketch(n,o,r);break;case"path2Dfill":this.ctx.save(),this.ctx.fillStyle=r.fill||"";var s=new Path2D(o.path);this.ctx.fill(s),this.ctx.restore();break;case"path2Dpattern":var h=this.canvas.ownerDocument||$&&document;if(h){var u=o.size,c=h.createElement("canvas"),l=c.getContext("2d"),f=this.computeBBox(o.path);f&&(f.width||f.height)?(c.width=this.canvas.width,c.height=this.canvas.height,l.translate(f.x||0,f.y||0)):(c.width=u[0],c.height=u[1]),this.fillSketch(l,o,r),this.ctx.save(),this.ctx.fillStyle=this.ctx.createPattern(c,"repeat");s=new Path2D(o.path);this.ctx.fill(s),this.ctx.restore()}else console.error("Pattern fill fail: No defs")}}},e.prototype.computeBBox=function(e){if($)try{var r=document.createElementNS(t,"svg");r.setAttribute("width","0"),r.setAttribute("height","0");var n=self.document.createElementNS(t,"path");n.setAttribute("d",e),r.appendChild(n),document.body.appendChild(r);var i=n.getBBox();return document.body.removeChild(r),i}catch(t){}return null},e.prototype.fillSketch=function(t,e,r){var n=r.fillWeight;n<0&&(n=r.strokeWidth/2),t.save(),t.strokeStyle=r.fill||"",t.lineWidth=n,this._drawToContext(t,e),t.restore()},e.prototype._drawToContext=function(t,e){t.beginPath();for(var r=0,n=e.ops;r<n.length;r++){var i=n[r],a=i.data;switch(i.op){case"move":t.moveTo(a[0],a[1]);break;case"bcurveTo":t.bezierCurveTo(a[0],a[1],a[2],a[3],a[4],a[5]);break;case"qcurveTo":t.quadraticCurveTo(a[0],a[1],a[2],a[3]);break;case"lineTo":t.lineTo(a[0],a[1])}}"fillPath"===e.type?t.fill():t.stroke()},Object.defineProperty(e.prototype,"generator",{get:function(){return this.gen},enumerable:!0,configurable:!0}),e.prototype.getDefaultOptions=function(){return this.gen.defaultOptions},e.prototype.line=function(t,e,r,n,i){var a=this.gen.line(t,e,r,n,i);return this.draw(a),a},e.prototype.rectangle=function(t,e,r,n,i){var a=this.gen.rectangle(t,e,r,n,i);return this.draw(a),a},e.prototype.ellipse=function(t,e,r,n,i){var a=this.gen.ellipse(t,e,r,n,i);return this.draw(a),a},e.prototype.circle=function(t,e,r,n){var i=this.gen.circle(t,e,r,n);return this.draw(i),i},e.prototype.linearPath=function(t,e){var r=this.gen.linearPath(t,e);return this.draw(r),r},e.prototype.polygon=function(t,e){var r=this.gen.polygon(t,e);return this.draw(r),r},e.prototype.arc=function(t,e,r,n,i,a,o,s){void 0===o&&(o=!1);var h=this.gen.arc(t,e,r,n,i,a,o,s);return this.draw(h),h},e.prototype.curve=function(t,e){var r=this.gen.curve(t,e);return this.draw(r),r},e.prototype.path=function(t,e){var r=this.gen.path(t,e);return this.draw(r),r},e}(),Y="undefined"!=typeof document,X=function(){function e(t,e){this.svg=t,this.gen=new Z(e,this.svg)}return Object.defineProperty(e.prototype,"defs",{get:function(){var e=this.svg.ownerDocument||Y&&document;if(e&&!this._defs){var r=e.createElementNS(t,"defs");this.svg.firstChild?this.svg.insertBefore(r,this.svg.firstChild):this.svg.appendChild(r),this._defs=r}return this._defs||null},enumerable:!0,configurable:!0}),e.prototype.draw=function(e){for(var r=e.sets||[],n=e.options||this.getDefaultOptions(),i=this.svg.ownerDocument||window.document,a=i.createElementNS(t,"g"),o=0,s=r;o<s.length;o++){var h=s[o],u=null;switch(h.type){case"path":(u=i.createElementNS(t,"path")).setAttribute("d",this.opsToPath(h)),u.style.stroke=n.stroke,u.style.strokeWidth=n.strokeWidth+"",u.style.fill="none";break;case"fillPath":(u=i.createElementNS(t,"path")).setAttribute("d",this.opsToPath(h)),u.style.stroke="none",u.style.strokeWidth="0",u.style.fill=n.fill||"";break;case"fillSketch":u=this.fillSketch(i,h,n);break;case"path2Dfill":(u=i.createElementNS(t,"path")).setAttribute("d",h.path||""),u.style.stroke="none",u.style.strokeWidth="0",u.style.fill=n.fill||"";break;case"path2Dpattern":if(this.defs){var c=h.size,l=i.createElementNS(t,"pattern"),f="rough-"+Math.floor(Math.random()*(Number.MAX_SAFE_INTEGER||999999));l.setAttribute("id",f),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(i,h,n);l.appendChild(p),this.defs.appendChild(l),(u=i.createElementNS(t,"path")).setAttribute("d",h.path||""),u.style.stroke="none",u.style.strokeWidth="0",u.style.fill="url(#"+f+")"}else console.error("Pattern fill fail: No defs")}u&&a.appendChild(u)}return a},e.prototype.fillSketch=function(e,r,n){var i=n.fillWeight;i<0&&(i=n.strokeWidth/2);var a=e.createElementNS(t,"path");return a.setAttribute("d",this.opsToPath(r)),a.style.stroke=n.fill||"",a.style.strokeWidth=i+"",a.style.fill="none",a},Object.defineProperty(e.prototype,"generator",{get:function(){return this.gen},enumerable:!0,configurable:!0}),e.prototype.getDefaultOptions=function(){return this.gen.defaultOptions},e.prototype.opsToPath=function(t){return this.gen.opsToPath(t)},e.prototype.line=function(t,e,r,n,i){var a=this.gen.line(t,e,r,n,i);return this.draw(a)},e.prototype.rectangle=function(t,e,r,n,i){var a=this.gen.rectangle(t,e,r,n,i);return this.draw(a)},e.prototype.ellipse=function(t,e,r,n,i){var a=this.gen.ellipse(t,e,r,n,i);return this.draw(a)},e.prototype.circle=function(t,e,r,n){var i=this.gen.circle(t,e,r,n);return this.draw(i)},e.prototype.linearPath=function(t,e){var r=this.gen.linearPath(t,e);return this.draw(r)},e.prototype.polygon=function(t,e){var r=this.gen.polygon(t,e);return this.draw(r)},e.prototype.arc=function(t,e,r,n,i,a,o,s){void 0===o&&(o=!1);var h=this.gen.arc(t,e,r,n,i,a,o,s);return this.draw(h)},e.prototype.curve=function(t,e){var r=this.gen.curve(t,e);return this.draw(r)},e.prototype.path=function(t,e){var r=this.gen.path(t,e);return this.draw(r)},e}();function K(t,e,r){var n=tt(t,t.VERTEX_SHADER,e),i=tt(t,t.FRAGMENT_SHADER,r),a=t.createProgram();if(t.attachShader(a,n),t.attachShader(a,i),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS)){var o=new Error("Unable to initialize the shader program: "+t.getProgramInfoLog(a));throw t.deleteProgram(a),o}return a}function tt(t,e,r){var n=t.createShader(e);if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){var i=new Error("An error occurred compiling the shaders: "+t.getShaderInfoLog(n));throw t.deleteShader(n),i}return n}function et(t,e){for(var r=function(e,r){var n=t.getUniformLocation(e,r.name),i=r.type,a=r.size>1&&"[0]"===r.name.substr(-3);if(i===t.FLOAT&&a)return function(e){t.uniform1fv(n,e)};if(i===t.FLOAT)return function(e){t.uniform1f(n,e)};if(i===t.FLOAT_VEC2)return function(e){t.uniform2fv(n,e)};if(i===t.FLOAT_VEC3)return function(e){t.uniform3fv(n,e)};if(i===t.FLOAT_VEC4)return function(e){t.uniform4fv(n,e)};if(i===t.INT&&a)return function(e){t.uniform1iv(n,e)};if(i===t.INT)return function(e){t.uniform1i(n,e)};if(i===t.INT_VEC2)return function(e){t.uniform2iv(n,e)};if(i===t.INT_VEC3)return function(e){t.uniform3iv(n,e)};if(i===t.INT_VEC4)return function(e){t.uniform4iv(n,e)};if(i===t.BOOL)return function(e){t.uniform1iv(n,e)};if(i===t.BOOL_VEC2)return function(e){t.uniform2iv(n,e)};if(i===t.BOOL_VEC3)return function(e){t.uniform3iv(n,e)};if(i===t.BOOL_VEC4)return function(e){t.uniform4iv(n,e)};if(i===t.FLOAT_MAT2)return function(e){t.uniformMatrix2fv(n,!1,e)};if(i===t.FLOAT_MAT3)return function(e){t.uniformMatrix3fv(n,!1,e)};if(i===t.FLOAT_MAT4)return function(e){t.uniformMatrix4fv(n,!1,e)};throw"unknown type: 0x"+i.toString(16)},n={},i=t.getProgramParameter(e,t.ACTIVE_UNIFORMS),a=0;a<i;++a){var o=t.getActiveUniform(e,a);if(!o)break;var s=o.name;"[0]"===s.substr(-3)&&(s=s.substr(0,s.length-3));var h=r(e,o);n[s]=h}return n}function rt(t,e){var r={};function n(e){return function(r){t.bindBuffer(t.ARRAY_BUFFER,r.buffer),t.enableVertexAttribArray(e),t.vertexAttribPointer(e,r.numComponents,r.type||t.FLOAT,r.normalize||!1,r.stride||0,r.offset||0)}}for(var i=t.getProgramParameter(e,t.ACTIVE_ATTRIBUTES),a=0;a<i;++a){var o=t.getActiveAttrib(e,a);if(!o)break;var s=t.getAttribLocation(e,o.name);r[o.name]=n(s)}return r}function nt(t,e){var r=K.apply(void 0,d([t],e));return{program:r,uniformSetters:et(t,r),attribSetters:rt(t,r)}}function it(t,e){var r=t.createBuffer(),n=t.ARRAY_BUFFER;return t.bindBuffer(n,r),t.bufferData(n,e,t.STATIC_DRAW),r}function at(t,e){var r={};for(var n in e){var i=e[n],a=new Float32Array(i.data);r["a_"+n]={buffer:it(t,a),numComponents:i.numComponents,type:t.FLOAT}}return r}function ot(t,e){for(var r=[],n=(t.length-1)/3,i=0;i<n;i++){ht(t,3*i,e,r)}return r}function st(t,e,r,n,i){for(var o=i||[],s=t[e],h=t[r-1],u=0,c=1,l=e+1;l<r-1;++l){var f=a(t[l],s,h);f>u&&(u=f,c=l)}return Math.sqrt(u)>n?(st(t,e,c+1,n,o),st(t,c,r,n,o)):o.push.apply(o,d(s,h)),o}function ht(t,e,r,i){var a=i||[];if(function(t,e){var r=t[e+0],n=t[e+1],i=t[e+2],a=t[e+3],o=3*n[0]-2*r[0]-a[0];o*=o;var s=3*n[1]-2*r[1]-a[1];s*=s;var h=3*i[0]-2*a[0]-r[0];h*=h;var u=3*i[1]-2*a[1]-r[1];return o<h&&(o=h),s<(u*=u)&&(s=u),o+s}(t,e)<r)a.push(t[e+0]),a.push(t[e+3]);else{var o=.5,s=t[e+0],h=t[e+1],u=t[e+2],c=t[e+3],l=n(s,h,o),f=n(h,u,o),p=n(u,c,o),d=n(l,f,o),v=n(f,p,o),g=n(d,v,o);ht([s,l,d,g],0,r,a),ht([g,v,p,c],0,r,a)}return a}function ut(t){var e=null;if(0===(t=t.toLowerCase().trim()||"").indexOf("rgb")){var r=(/\(([^)]+)\)/.exec(t)[1]||"").trim().split(",").map((function(t){return+t.trim()}));4===r.length?e=r:3===r.length&&(e=d(r,[1]))}return e||(e=function(t){var e=[0,0,0,0];(4===t.length||t.length>6)&&(t=t.substring(1));3===t.length?e=[+("0x"+t[0]+t[0]),+("0x"+t[1]+t[1]),+("0x"+t[2]+t[2]),1]:t.length>=6&&(e=[+("0x"+t[0]+t[1]),+("0x"+t[2]+t[3]),+("0x"+t[4]+t[5]),1]);return e}(t)),[e[0]/255,e[1]/255,e[2]/255,e[3]]}var ct={tolerance:.15,distance:.4},lt=function(){function t(t){if(this.defaultOptions=JSON.parse(JSON.stringify(Q)),this.canvas=t,this.gl=t.getContext("webgl"),!this.gl)throw new Error("Unable to initialize WebGL. Your browser or machine may not support it.");this.pi=nt(this.gl,["\nattribute vec2 a_position;\nuniform vec2 u_resolution;\n\nvoid main() {\n vec2 zeroToOne = a_position / u_resolution;\n vec2 zeroToTwo = zeroToOne * 2.0;\n vec2 clipSpace = zeroToTwo - 1.0;\n gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);\n}\n","\nprecision mediump float;\nuniform vec4 u_color;\n\nvoid main() {\n gl_FragColor = u_color;\n}\n"])}return t.prototype.draw=function(t,e){void 0===e&&(e=!1);var r=Array.isArray(t)?t:[t];e&&this.clearCanvas(),this.initializeCanvas();for(var n=0,i=r;n<i.length;n++){var a=i[n];console.log(a);for(var o=a.sets||[],s=a.options||this.defaultOptions,h=0,u=o;h<u.length;h++){var c=u[h];switch(c.type){case"path":var l=this.extractCurvePoints(c.ops);this.drawCurves(l,s.strokeWidth,"none"===s.stroke?"transparent":s.stroke);break;case"fillSketch":var f=s.fillWeight;f<0&&(f=s.strokeWidth/2);var p=this.extractCurvePoints(c.ops);this.drawCurves(p,f,s.fill||"")}}}},t.prototype.extractCurvePoints=function(t){for(var e=[],r=[],n=0,i=t;n<i.length;n++){var a=i[n];switch(a.op){case"move":r.length>1&&(e.push(r),r=[]),r.push(a.data);break;case"bcurveTo":r.push([a.data[0],a.data[1]]),r.push([a.data[2],a.data[3]]),r.push([a.data[4],a.data[5]])}}return r.length>1&&(e.push(r),r=[]),e},t.prototype.clearCanvas=function(){this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT)},t.prototype.initializeCanvas=function(){!function(t,e){void 0===e&&(e=1);var r=t.clientWidth*e|0,n=t.clientHeight*e|0;(t.width!==r||t.height!==n)&&(t.width=r,t.height=n)}(this.canvas),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height)},t.prototype.drawCurves=function(t,e,r,n){for(var i=n||ct,a=[],o=0,s=t;o<s.length;o++){var h=ot(s[o],i.tolerance);a=st(h,0,h.length,i.distance,a)}var u,c,l,f=(u=this.gl,l=(c={position:{numComponents:2,data:a}})[Object.keys(c)[0]],{attribs:at(u,c),numElements:l?l.data.length/l.numComponents:0});this.gl.useProgram(this.pi.program),function(t,e){for(var r in e){var n=t[r];n&&n(e[r])}}(this.pi.attribSetters,f.attribs);var p={u_resolution:[this.gl.canvas.width,this.gl.canvas.height],u_color:ut(r)};!function(t,e){for(var r in e){var n=t[r];n&&n(e[r])}}(this.pi.uniformSetters,p),this.gl.drawArrays(this.gl.LINES,0,f.numElements)},t}(),ft={canvas:function(t,e){return new J(t,e)},svg:function(t,e){return new X(t,e)},webGl:function(t){return new lt(t)},generator:function(t,e){return new Z(t,e)},newSeed:function(){return Z.newSeed()}};module.exports=ft;
|