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