UNPKG

ranui

Version:

A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.

2 lines (1 loc) 27.9 kB
function U(t,s,e){if(t&&t.length){const[a,n]=s,o=Math.PI/180*e,h=Math.cos(o),r=Math.sin(o);for(const i of t){const[c,l]=i;i[0]=(c-a)*h-(l-n)*r+a,i[1]=(c-a)*r+(l-n)*h+n}}}function Ot(t,s){return t[0]===s[0]&&t[1]===s[1]}function Lt(t,s,e,a=1){const n=e,o=Math.max(s,.1),h=t[0]&&t[0][0]&&typeof t[0][0]=="number"?[t]:t,r=[0,0];if(n)for(const c of h)U(c,r,n);const i=(function(c,l,d){const f=[];for(const M of c){const y=[...M];Ot(y[0],y[y.length-1])||y.push([y[0][0],y[0][1]]),y.length>2&&f.push(y)}const u=[];l=Math.max(l,.1);const p=[];for(const M of f)for(let y=0;y<M.length-1;y++){const w=M[y],v=M[y+1];if(w[1]!==v[1]){const P=Math.min(w[1],v[1]);p.push({ymin:P,ymax:Math.max(w[1],v[1]),x:P===w[1]?w[0]:v[0],islope:(v[0]-w[0])/(v[1]-w[1])})}}if(p.sort(((M,y)=>M.ymin<y.ymin?-1:M.ymin>y.ymin?1:M.x<y.x?-1:M.x>y.x?1:M.ymax===y.ymax?0:(M.ymax-y.ymax)/Math.abs(M.ymax-y.ymax))),!p.length)return u;let k=[],g=p[0].ymin,m=0;for(;k.length||p.length;){if(p.length){let M=-1;for(let y=0;y<p.length&&!(p[y].ymin>g);y++)M=y;p.splice(0,M+1).forEach((y=>{k.push({s:g,edge:y})}))}if(k=k.filter((M=>!(M.edge.ymax<=g))),k.sort(((M,y)=>M.edge.x===y.edge.x?0:(M.edge.x-y.edge.x)/Math.abs(M.edge.x-y.edge.x))),(d!==1||m%l==0)&&k.length>1)for(let M=0;M<k.length;M+=2){const y=M+1;if(y>=k.length)break;const w=k[M].edge,v=k[y].edge;u.push([[Math.round(w.x),g],[Math.round(v.x),g]])}g+=d,k.forEach((M=>{M.edge.x=M.edge.x+d*M.edge.islope})),m++}return u})(h,o,a);if(n){for(const c of h)U(c,r,-n);(function(c,l,d){const f=[];c.forEach((u=>f.push(...u))),U(f,l,d)})(i,r,-n)}return i}function R(t,s){var e;const a=s.hachureAngle+90;let n=s.hachureGap;n<0&&(n=4*s.strokeWidth),n=Math.round(Math.max(n,.1));let o=1;return s.roughness>=1&&(((e=s.randomizer)===null||e===void 0?void 0:e.next())||Math.random())>.7&&(o=n),Lt(t,n,a,o||1)}var ot=class{constructor(t){this.helper=t}fillPolygons(t,s){return this._fillPolygons(t,s)}_fillPolygons(t,s){const e=R(t,s);return{type:"fillSketch",ops:this.renderLines(e,s)}}renderLines(t,s){const e=[];for(const a of t)e.push(...this.helper.doubleLineOps(a[0][0],a[0][1],a[1][0],a[1][1],s));return e}};function K(t){const s=t[0],e=t[1];return Math.sqrt(Math.pow(s[0]-e[0],2)+Math.pow(s[1]-e[1],2))}var Tt=class extends ot{fillPolygons(t,s){let e=s.hachureGap;e<0&&(e=4*s.strokeWidth),e=Math.max(e,.1);const a=R(t,Object.assign({},s,{hachureGap:e})),n=Math.PI/180*s.hachureAngle,o=[],h=.5*e*Math.cos(n),r=.5*e*Math.sin(n);for(const[i,c]of a)K([i,c])&&o.push([[i[0]-h,i[1]+r],[...c]],[[i[0]+h,i[1]-r],[...c]]);return{type:"fillSketch",ops:this.renderLines(o,s)}}},Dt=class extends ot{fillPolygons(t,s){const e=this._fillPolygons(t,s),a=Object.assign({},s,{hachureAngle:s.hachureAngle+90}),n=this._fillPolygons(t,a);return e.ops=e.ops.concat(n.ops),e}},At=class{constructor(t){this.helper=t}fillPolygons(t,s){const e=R(t,s=Object.assign({},s,{hachureAngle:0}));return this.dotsOnLines(e,s)}dotsOnLines(t,s){const e=[];let a=s.hachureGap;a<0&&(a=4*s.strokeWidth),a=Math.max(a,.1);let n=s.fillWeight;n<0&&(n=s.strokeWidth/2);const o=a/4;for(const h of t){const r=K(h),i=r/a,c=Math.ceil(i)-1,l=r-c*a,d=(h[0][0]+h[1][0])/2-a/4,f=Math.min(h[0][1],h[1][1]);for(let u=0;u<c;u++){const p=f+l+u*a,k=d-o+2*Math.random()*o,g=p-o+2*Math.random()*o,m=this.helper.ellipse(k,g,n,n,s);e.push(...m.ops)}}return{type:"fillSketch",ops:e}}},_t=class{constructor(t){this.helper=t}fillPolygons(t,s){const e=R(t,s);return{type:"fillSketch",ops:this.dashedLine(e,s)}}dashedLine(t,s){const e=s.dashOffset<0?s.hachureGap<0?4*s.strokeWidth:s.hachureGap:s.dashOffset,a=s.dashGap<0?s.hachureGap<0?4*s.strokeWidth:s.hachureGap:s.dashGap,n=[];return t.forEach((o=>{const h=K(o),r=Math.floor(h/(e+a)),i=(h+a-r*(e+a))/2;let c=o[0],l=o[1];c[0]>l[0]&&(c=o[1],l=o[0]);const d=Math.atan((l[1]-c[1])/(l[0]-c[0]));for(let f=0;f<r;f++){const u=f*(e+a),p=u+e,k=[c[0]+u*Math.cos(d)+i*Math.cos(d),c[1]+u*Math.sin(d)+i*Math.sin(d)],g=[c[0]+p*Math.cos(d)+i*Math.cos(d),c[1]+p*Math.sin(d)+i*Math.sin(d)];n.push(...this.helper.doubleLineOps(k[0],k[1],g[0],g[1],s))}})),n}},It=class{constructor(t){this.helper=t}fillPolygons(t,s){const e=s.hachureGap<0?4*s.strokeWidth:s.hachureGap,a=s.zigzagOffset<0?e:s.zigzagOffset,n=R(t,s=Object.assign({},s,{hachureGap:e+a}));return{type:"fillSketch",ops:this.zigzagLines(n,a,s)}}zigzagLines(t,s,e){const a=[];return t.forEach((n=>{const o=K(n),h=Math.round(o/(2*s));let r=n[0],i=n[1];r[0]>i[0]&&(r=n[1],i=n[0]);const c=Math.atan((i[1]-r[1])/(i[0]-r[0]));for(let l=0;l<h;l++){const d=2*l*s,f=2*(l+1)*s,u=Math.sqrt(2*Math.pow(s,2)),p=[r[0]+d*Math.cos(c),r[1]+d*Math.sin(c)],k=[r[0]+f*Math.cos(c),r[1]+f*Math.sin(c)],g=[p[0]+u*Math.cos(c+Math.PI/4),p[1]+u*Math.sin(c+Math.PI/4)];a.push(...this.helper.doubleLineOps(p[0],p[1],g[0],g[1],e),...this.helper.doubleLineOps(g[0],g[1],k[0],k[1],e))}})),a}},S={},Ct=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}},zt=0,X=1,lt=2,q={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function Y(t,s){return t.type===s}function rt(t){const s=[],e=(function(h){const r=new Array;for(;h!=="";)if(h.match(/^([ \t\r\n,]+)/))h=h.substr(RegExp.$1.length);else if(h.match(/^([aAcChHlLmMqQsStTvVzZ])/))r[r.length]={type:zt,text:RegExp.$1},h=h.substr(RegExp.$1.length);else{if(!h.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))return[];r[r.length]={type:X,text:`${parseFloat(RegExp.$1)}`},h=h.substr(RegExp.$1.length)}return r[r.length]={type:lt,text:""},r})(t);let a="BOD",n=0,o=e[n];for(;!Y(o,lt);){let h=0;const r=[];if(a==="BOD"){if(o.text!=="M"&&o.text!=="m")return rt("M0,0"+t);n++,h=q[o.text],a=o.text}else Y(o,X)?h=q[a]:(n++,h=q[o.text],a=o.text);if(!(n+h<e.length))throw new Error("Path data ended short");for(let i=n;i<n+h;i++){const c=e[i];if(!Y(c,X))throw new Error("Param not a number: "+a+","+c.text);r[r.length]=+c.text}if(typeof q[a]!="number")throw new Error("Bad segment: "+a);{const i={key:a,data:r};s.push(i),n+=h,o=e[n],a==="M"&&(a="L"),a==="m"&&(a="l")}}return s}function bt(t){let s=0,e=0,a=0,n=0;const o=[];for(const{key:h,data:r}of t)switch(h){case"M":o.push({key:"M",data:[...r]}),[s,e]=r,[a,n]=r;break;case"m":s+=r[0],e+=r[1],o.push({key:"M",data:[s,e]}),a=s,n=e;break;case"L":o.push({key:"L",data:[...r]}),[s,e]=r;break;case"l":s+=r[0],e+=r[1],o.push({key:"L",data:[s,e]});break;case"C":o.push({key:"C",data:[...r]}),s=r[4],e=r[5];break;case"c":{const i=r.map(((c,l)=>l%2?c+e:c+s));o.push({key:"C",data:i}),s=i[4],e=i[5];break}case"Q":o.push({key:"Q",data:[...r]}),s=r[2],e=r[3];break;case"q":{const i=r.map(((c,l)=>l%2?c+e:c+s));o.push({key:"Q",data:i}),s=i[2],e=i[3];break}case"A":o.push({key:"A",data:[...r]}),s=r[5],e=r[6];break;case"a":s+=r[5],e+=r[6],o.push({key:"A",data:[r[0],r[1],r[2],r[3],r[4],s,e]});break;case"H":o.push({key:"H",data:[...r]}),s=r[0];break;case"h":s+=r[0],o.push({key:"H",data:[s]});break;case"V":o.push({key:"V",data:[...r]}),e=r[0];break;case"v":e+=r[0],o.push({key:"V",data:[e]});break;case"S":o.push({key:"S",data:[...r]}),s=r[2],e=r[3];break;case"s":{const i=r.map(((c,l)=>l%2?c+e:c+s));o.push({key:"S",data:i}),s=i[2],e=i[3];break}case"T":o.push({key:"T",data:[...r]}),s=r[0],e=r[1];break;case"t":s+=r[0],e+=r[1],o.push({key:"T",data:[s,e]});break;case"Z":case"z":o.push({key:"Z",data:[]}),s=a,e=n}return o}function yt(t){const s=[];let e="",a=0,n=0,o=0,h=0,r=0,i=0;for(const{key:c,data:l}of t){switch(c){case"M":s.push({key:"M",data:[...l]}),[a,n]=l,[o,h]=l;break;case"C":s.push({key:"C",data:[...l]}),a=l[4],n=l[5],r=l[2],i=l[3];break;case"L":s.push({key:"L",data:[...l]}),[a,n]=l;break;case"H":a=l[0],s.push({key:"L",data:[a,n]});break;case"V":n=l[0],s.push({key:"L",data:[a,n]});break;case"S":{let d=0,f=0;e==="C"||e==="S"?(d=a+(a-r),f=n+(n-i)):(d=a,f=n),s.push({key:"C",data:[d,f,...l]}),r=l[0],i=l[1],a=l[2],n=l[3];break}case"T":{const[d,f]=l;let u=0,p=0;e==="Q"||e==="T"?(u=a+(a-r),p=n+(n-i)):(u=a,p=n);const k=a+2*(u-a)/3,g=n+2*(p-n)/3,m=d+2*(u-d)/3,M=f+2*(p-f)/3;s.push({key:"C",data:[k,g,m,M,d,f]}),r=u,i=p,a=d,n=f;break}case"Q":{const[d,f,u,p]=l,k=a+2*(d-a)/3,g=n+2*(f-n)/3,m=u+2*(d-u)/3,M=p+2*(f-p)/3;s.push({key:"C",data:[k,g,m,M,u,p]}),r=d,i=f,a=u,n=p;break}case"A":{const d=Math.abs(l[0]),f=Math.abs(l[1]),u=l[2],p=l[3],k=l[4],g=l[5],m=l[6];d===0||f===0?(s.push({key:"C",data:[a,n,g,m,g,m]}),a=g,n=m):(a!==g||n!==m)&&(mt(a,n,g,m,d,f,u,p,k).forEach((function(M){s.push({key:"C",data:M})})),a=g,n=m);break}case"Z":s.push({key:"Z",data:[]}),a=o,n=h}e=c}return s}function G(t,s,e){return[t*Math.cos(e)-s*Math.sin(e),t*Math.sin(e)+s*Math.cos(e)]}function mt(t,s,e,a,n,o,h,r,i,c){const l=(d=h,Math.PI*d/180);var d;let f=[],u=0,p=0,k=0,g=0;if(c)[u,p,k,g]=c;else{[t,s]=G(t,s,-l),[e,a]=G(e,a,-l);const L=(t-e)/2,x=(s-a)/2;let A=L*L/(n*n)+x*x/(o*o);A>1&&(A=Math.sqrt(A),n*=A,o*=A);const z=n*n,W=o*o,Pt=z*W-z*x*x-W*L*L,St=z*x*x+W*L*L,ct=(r===i?-1:1)*Math.sqrt(Math.abs(Pt/St));k=ct*n*x/o+(t+e)/2,g=ct*-o*L/n+(s+a)/2,u=Math.asin(parseFloat(((s-g)/o).toFixed(9))),p=Math.asin(parseFloat(((a-g)/o).toFixed(9))),t<k&&(u=Math.PI-u),e<k&&(p=Math.PI-p),u<0&&(u=2*Math.PI+u),p<0&&(p=2*Math.PI+p),i&&u>p&&(u-=2*Math.PI),!i&&p>u&&(p-=2*Math.PI)}let m=p-u;if(Math.abs(m)>120*Math.PI/180){const L=p,x=e,A=a;p=i&&p>u?u+120*Math.PI/180*1:u+120*Math.PI/180*-1,f=mt(e=k+n*Math.cos(p),a=g+o*Math.sin(p),x,A,n,o,h,0,i,[p,L,k,g])}m=p-u;const M=Math.cos(u),y=Math.sin(u),w=Math.cos(p),v=Math.sin(p),P=Math.tan(m/4),D=4/3*n*P,j=4/3*o*P,I=[t,s],T=[t+D*y,s-j*M],ht=[e+D*v,a-j*w],it=[e,a];if(T[0]=2*I[0]-T[0],T[1]=2*I[1]-T[1],c)return[T,ht,it].concat(f);{f=[T,ht,it].concat(f);const L=[];for(let x=0;x<f.length;x+=3){const A=G(f[x][0],f[x][1],l),z=G(f[x+1][0],f[x+1][1],l),W=G(f[x+2][0],f[x+2][1],l);L.push([A[0],A[1],z[0],z[1],W[0],W[1]])}return L}}var Wt={randOffset:function(t,s){return b(t,s)},randOffsetWithRange:function(t,s,e){return H(t,s,e)},ellipse:function(t,s,e,a,n){return st(t,s,n,wt(e,a,n)).opset},doubleLineOps:function(t,s,e,a,n){return _(t,s,e,a,n,!0)}};function vt(t,s,e,a,n){return{type:"path",ops:_(t,s,e,a,n)}}function Z(t,s,e){const a=(t||[]).length;if(a>2){const n=[];for(let o=0;o<a-1;o++)n.push(..._(t[o][0],t[o][1],t[o+1][0],t[o+1][1],e));return s&&n.push(..._(t[a-1][0],t[a-1][1],t[0][0],t[0][1],e)),{type:"path",ops:n}}return a===2?vt(t[0][0],t[0][1],t[1][0],t[1][1],e):{type:"path",ops:[]}}function Et(t,s,e,a,n){return(function(o,h){return Z(o,!0,h)})([[t,s],[t+e,s],[t+e,s+a],[t,s+a]],n)}function ut(t,s){if(t.length){const e=typeof t[0][0]=="number"?[t]:t,a=F(e[0],1*(1+.2*s.roughness),s),n=s.disableMultiStroke?[]:F(e[0],1.5*(1+.22*s.roughness),dt(s));for(let o=1;o<e.length;o++){const h=e[o];if(h.length){const r=F(h,1*(1+.2*s.roughness),s),i=s.disableMultiStroke?[]:F(h,1.5*(1+.22*s.roughness),dt(s));for(const c of r)c.op!=="move"&&a.push(c);for(const c of i)c.op!=="move"&&n.push(c)}}return{type:"path",ops:a.concat(n)}}return{type:"path",ops:[]}}function wt(t,s,e){const a=Math.sqrt(2*Math.PI*Math.sqrt((Math.pow(t/2,2)+Math.pow(s/2,2))/2)),n=Math.ceil(Math.max(e.curveStepCount,e.curveStepCount/Math.sqrt(200)*a)),o=2*Math.PI/n;let h=Math.abs(t/2),r=Math.abs(s/2);const i=1-e.curveFitting;return h+=b(h*i,e),r+=b(r*i,e),{increment:o,rx:h,ry:r}}function st(t,s,e,a){const[n,o]=gt(a.increment,t,s,a.rx,a.ry,1,a.increment*H(.1,H(.4,1,e),e),e);let h=N(n,null,e);if(!e.disableMultiStroke&&e.roughness!==0){const[r]=gt(a.increment,t,s,a.rx,a.ry,1.5,0,e),i=N(r,null,e);h=h.concat(i)}return{estimatedPoints:o,opset:{type:"path",ops:h}}}function pt(t,s,e,a,n,o,h,r,i){const c=t,l=s;let d=Math.abs(e/2),f=Math.abs(a/2);d+=b(.01*d,i),f+=b(.01*f,i);let u=n,p=o;for(;u<0;)u+=2*Math.PI,p+=2*Math.PI;p-u>2*Math.PI&&(u=0,p=2*Math.PI);const k=2*Math.PI/i.curveStepCount,g=Math.min(k/2,(p-u)/2),m=Mt(g,c,l,d,f,u,p,1,i);if(!i.disableMultiStroke){const M=Mt(g,c,l,d,f,u,p,1.5,i);m.push(...M)}return h&&(r?m.push(..._(c,l,c+d*Math.cos(u),l+f*Math.sin(u),i),..._(c,l,c+d*Math.cos(p),l+f*Math.sin(p),i)):m.push({op:"lineTo",data:[c,l]},{op:"lineTo",data:[c+d*Math.cos(u),l+f*Math.sin(u)]})),{type:"path",ops:m}}function ft(t,s){const e=yt(bt(rt(t))),a=[];let n=[0,0],o=[0,0];for(const{key:h,data:r}of e)switch(h){case"M":o=[r[0],r[1]],n=[r[0],r[1]];break;case"L":a.push(..._(o[0],o[1],r[0],r[1],s)),o=[r[0],r[1]];break;case"C":{const[i,c,l,d,f,u]=r;a.push(...Gt(i,c,l,d,f,u,o,s)),o=[f,u];break}case"Z":a.push(..._(o[0],o[1],n[0],n[1],s)),o=[n[0],n[1]]}return{type:"path",ops:a}}function tt(t,s){const e=[];for(const a of t)if(a.length){const n=s.maxRandomnessOffset||0,o=a.length;if(o>2){e.push({op:"move",data:[a[0][0]+b(n,s),a[0][1]+b(n,s)]});for(let h=1;h<o;h++)e.push({op:"lineTo",data:[a[h][0]+b(n,s),a[h][1]+b(n,s)]})}}return{type:"fillPath",ops:e}}function E(t,s){return(function(e,a){let n=e.fillStyle||"hachure";if(!S[n])switch(n){case"zigzag":S[n]||(S[n]=new Tt(a));break;case"cross-hatch":S[n]||(S[n]=new Dt(a));break;case"dots":S[n]||(S[n]=new At(a));break;case"dashed":S[n]||(S[n]=new _t(a));break;case"zigzag-line":S[n]||(S[n]=new It(a));break;default:n="hachure",S[n]||(S[n]=new ot(a))}return S[n]})(s,Wt).fillPolygons(t,s)}function dt(t){const s=Object.assign({},t);return s.randomizer=void 0,t.seed&&(s.seed=t.seed+1),s}function xt(t){return t.randomizer||(t.randomizer=new Ct(t.seed||0)),t.randomizer.next()}function H(t,s,e,a=1){return e.roughness*a*(xt(e)*(s-t)+t)}function b(t,s,e=1){return H(-t,t,s,e)}function _(t,s,e,a,n,o=!1){const h=o?n.disableMultiStrokeFill:n.disableMultiStroke,r=nt(t,s,e,a,n,!0,!1);if(h)return r;const i=nt(t,s,e,a,n,!0,!0);return r.concat(i)}function nt(t,s,e,a,n,o,h){const r=Math.pow(t-e,2)+Math.pow(s-a,2),i=Math.sqrt(r);let c=1;c=i<200?1:i>500?.4:-.0016668*i+1.233334;let l=n.maxRandomnessOffset||0;l*l*100>r&&(l=i/10);const d=l/2,f=.2+.2*xt(n);let u=n.bowing*n.maxRandomnessOffset*(a-s)/200,p=n.bowing*n.maxRandomnessOffset*(t-e)/200;u=b(u,n,c),p=b(p,n,c);const k=[],g=()=>b(d,n,c),m=()=>b(l,n,c),M=n.preserveVertices;return o&&(h?k.push({op:"move",data:[t+(M?0:g()),s+(M?0:g())]}):k.push({op:"move",data:[t+(M?0:b(l,n,c)),s+(M?0:b(l,n,c))]})),h?k.push({op:"bcurveTo",data:[u+t+(e-t)*f+g(),p+s+(a-s)*f+g(),u+t+2*(e-t)*f+g(),p+s+2*(a-s)*f+g(),e+(M?0:g()),a+(M?0:g())]}):k.push({op:"bcurveTo",data:[u+t+(e-t)*f+m(),p+s+(a-s)*f+m(),u+t+2*(e-t)*f+m(),p+s+2*(a-s)*f+m(),e+(M?0:m()),a+(M?0:m())]}),k}function F(t,s,e){if(!t.length)return[];const a=[];a.push([t[0][0]+b(s,e),t[0][1]+b(s,e)]),a.push([t[0][0]+b(s,e),t[0][1]+b(s,e)]);for(let n=1;n<t.length;n++)a.push([t[n][0]+b(s,e),t[n][1]+b(s,e)]),n===t.length-1&&a.push([t[n][0]+b(s,e),t[n][1]+b(s,e)]);return N(a,null,e)}function N(t,s,e){const a=t.length,n=[];if(a>3){const o=[],h=1-e.curveTightness;n.push({op:"move",data:[t[1][0],t[1][1]]});for(let r=1;r+2<a;r++){const i=t[r];o[0]=[i[0],i[1]],o[1]=[i[0]+(h*t[r+1][0]-h*t[r-1][0])/6,i[1]+(h*t[r+1][1]-h*t[r-1][1])/6],o[2]=[t[r+1][0]+(h*t[r][0]-h*t[r+2][0])/6,t[r+1][1]+(h*t[r][1]-h*t[r+2][1])/6],o[3]=[t[r+1][0],t[r+1][1]],n.push({op:"bcurveTo",data:[o[1][0],o[1][1],o[2][0],o[2][1],o[3][0],o[3][1]]})}if(s&&s.length===2){const r=e.maxRandomnessOffset;n.push({op:"lineTo",data:[s[0]+b(r,e),s[1]+b(r,e)]})}}else a===3?(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]]})):a===2&&n.push(...nt(t[0][0],t[0][1],t[1][0],t[1][1],e,!0,!0));return n}function gt(t,s,e,a,n,o,h,r){const i=[],c=[];if(r.roughness===0){t/=4,c.push([s+a*Math.cos(-t),e+n*Math.sin(-t)]);for(let l=0;l<=2*Math.PI;l+=t){const d=[s+a*Math.cos(l),e+n*Math.sin(l)];i.push(d),c.push(d)}c.push([s+a*Math.cos(0),e+n*Math.sin(0)]),c.push([s+a*Math.cos(t),e+n*Math.sin(t)])}else{const l=b(.5,r)-Math.PI/2;c.push([b(o,r)+s+.9*a*Math.cos(l-t),b(o,r)+e+.9*n*Math.sin(l-t)]);const d=2*Math.PI+l-.01;for(let f=l;f<d;f+=t){const u=[b(o,r)+s+a*Math.cos(f),b(o,r)+e+n*Math.sin(f)];i.push(u),c.push(u)}c.push([b(o,r)+s+a*Math.cos(l+2*Math.PI+.5*h),b(o,r)+e+n*Math.sin(l+2*Math.PI+.5*h)]),c.push([b(o,r)+s+.98*a*Math.cos(l+h),b(o,r)+e+.98*n*Math.sin(l+h)]),c.push([b(o,r)+s+.9*a*Math.cos(l+.5*h),b(o,r)+e+.9*n*Math.sin(l+.5*h)])}return[c,i]}function Mt(t,s,e,a,n,o,h,r,i){const c=o+b(.1,i),l=[];l.push([b(r,i)+s+.9*a*Math.cos(c-t),b(r,i)+e+.9*n*Math.sin(c-t)]);for(let d=c;d<=h;d+=t)l.push([b(r,i)+s+a*Math.cos(d),b(r,i)+e+n*Math.sin(d)]);return l.push([s+a*Math.cos(h),e+n*Math.sin(h)]),l.push([s+a*Math.cos(h),e+n*Math.sin(h)]),N(l,null,i)}function Gt(t,s,e,a,n,o,h,r){const i=[],c=[r.maxRandomnessOffset||1,(r.maxRandomnessOffset||1)+.3];let l=[0,0];const d=r.disableMultiStroke?1:2,f=r.preserveVertices;for(let u=0;u<d;u++)u===0?i.push({op:"move",data:[h[0],h[1]]}):i.push({op:"move",data:[h[0]+(f?0:b(c[0],r)),h[1]+(f?0:b(c[0],r))]}),l=f?[n,o]:[n+b(c[u],r),o+b(c[u],r)],i.push({op:"bcurveTo",data:[t+b(c[u],r),s+b(c[u],r),e+b(c[u],r),a+b(c[u],r),l[0],l[1]]});return i}function $(t){return[...t]}function kt(t,s=0){const e=t.length;if(e<3)throw new Error("A curve must have at least three points.");const a=[];if(e===3)a.push($(t[0]),$(t[1]),$(t[2]),$(t[2]));else{const n=[];n.push(t[0],t[0]);for(let r=1;r<t.length;r++)n.push(t[r]),r===t.length-1&&n.push(t[r]);const o=[],h=1-s;a.push($(n[0]));for(let r=1;r+2<n.length;r++){const i=n[r];o[0]=[i[0],i[1]],o[1]=[i[0]+(h*n[r+1][0]-h*n[r-1][0])/6,i[1]+(h*n[r+1][1]-h*n[r-1][1])/6],o[2]=[n[r+1][0]+(h*n[r][0]-h*n[r+2][0])/6,n[r+1][1]+(h*n[r][1]-h*n[r+2][1])/6],o[3]=[n[r+1][0],n[r+1][1]],a.push(o[1],o[2],o[3])}}return a}function Q(t,s){return Math.pow(t[0]-s[0],2)+Math.pow(t[1]-s[1],2)}function $t(t,s,e){const a=Q(s,e);if(a===0)return Q(t,s);let n=((t[0]-s[0])*(e[0]-s[0])+(t[1]-s[1])*(e[1]-s[1]))/a;return n=Math.max(0,Math.min(1,n)),Q(t,C(s,e,n))}function C(t,s,e){return[t[0]+(s[0]-t[0])*e,t[1]+(s[1]-t[1])*e]}function at(t,s,e,a){const n=a||[];if((function(r,i){const c=r[i+0],l=r[i+1],d=r[i+2],f=r[i+3];let u=3*l[0]-2*c[0]-f[0];u*=u;let p=3*l[1]-2*c[1]-f[1];p*=p;let k=3*d[0]-2*f[0]-c[0];k*=k;let g=3*d[1]-2*f[1]-c[1];return g*=g,u<k&&(u=k),p<g&&(p=g),u+p})(t,s)<e){const r=t[s+0];n.length?(o=n[n.length-1],h=r,Math.sqrt(Q(o,h))>1&&n.push(r)):n.push(r),n.push(t[s+3])}else{const i=t[s+0],c=t[s+1],l=t[s+2],d=t[s+3],f=C(i,c,.5),u=C(c,l,.5),p=C(l,d,.5),k=C(f,u,.5),g=C(u,p,.5),m=C(k,g,.5);at([i,f,k,m],0,e,n),at([m,g,p,d],0,e,n)}var o,h;return n}function Rt(t,s){return B(t,0,t.length,s)}function B(t,s,e,a,n){const o=n||[],h=t[s],r=t[e-1];let i=0,c=1;for(let l=s+1;l<e-1;++l){const d=$t(t[l],h,r);d>i&&(i=d,c=l)}return Math.sqrt(i)>a?(B(t,s,c+1,a,o),B(t,c,e,a,o)):(o.length||o.push(h),o.push(r)),o}function et(t,s=.15,e){const a=[],n=(t.length-1)/3;for(let o=0;o<n;o++)at(t,3*o,s,a);return e&&e>0?B(a,0,a.length,e):a}var O="none",J=class{constructor(t){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Math.floor(Math.random()*2**31)}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,s,e){return{shape:t,sets:s||[],options:e||this.defaultOptions}}line(t,s,e,a,n){const o=this._o(n);return this._d("line",[vt(t,s,e,a,o)],o)}rectangle(t,s,e,a,n){const o=this._o(n),h=[],r=Et(t,s,e,a,o);if(o.fill){const i=[[t,s],[t+e,s],[t+e,s+a],[t,s+a]];o.fillStyle==="solid"?h.push(tt([i],o)):h.push(E([i],o))}return o.stroke!==O&&h.push(r),this._d("rectangle",h,o)}ellipse(t,s,e,a,n){const o=this._o(n),h=[],r=wt(e,a,o),i=st(t,s,o,r);if(o.fill)if(o.fillStyle==="solid"){const c=st(t,s,o,r).opset;c.type="fillPath",h.push(c)}else h.push(E([i.estimatedPoints],o));return o.stroke!==O&&h.push(i.opset),this._d("ellipse",h,o)}circle(t,s,e,a){const n=this.ellipse(t,s,e,e,a);return n.shape="circle",n}linearPath(t,s){const e=this._o(s);return this._d("linearPath",[Z(t,!1,e)],e)}arc(t,s,e,a,n,o,h=!1,r){const i=this._o(r),c=[],l=pt(t,s,e,a,n,o,h,!0,i);if(h&&i.fill)if(i.fillStyle==="solid"){const d=Object.assign({},i);d.disableMultiStroke=!0;const f=pt(t,s,e,a,n,o,!0,!1,d);f.type="fillPath",c.push(f)}else c.push((function(d,f,u,p,k,g,m){const M=d,y=f;let w=Math.abs(u/2),v=Math.abs(p/2);w+=b(.01*w,m),v+=b(.01*v,m);let P=k,D=g;for(;P<0;)P+=2*Math.PI,D+=2*Math.PI;D-P>2*Math.PI&&(P=0,D=2*Math.PI);const j=(D-P)/m.curveStepCount,I=[];for(let T=P;T<=D;T+=j)I.push([M+w*Math.cos(T),y+v*Math.sin(T)]);return I.push([M+w*Math.cos(D),y+v*Math.sin(D)]),I.push([M,y]),E([I],m)})(t,s,e,a,n,o,i));return i.stroke!==O&&c.push(l),this._d("arc",c,i)}curve(t,s){const e=this._o(s),a=[],n=ut(t,e);if(e.fill&&e.fill!==O)if(e.fillStyle==="solid"){const o=ut(t,Object.assign(Object.assign({},e),{disableMultiStroke:!0,roughness:e.roughness?e.roughness+e.fillShapeRoughnessGain:0}));a.push({type:"fillPath",ops:this._mergedShape(o.ops)})}else{const o=[],h=t;if(h.length){const r=typeof h[0][0]=="number"?[h]:h;for(const i of r)i.length<3?o.push(...i):i.length===3?o.push(...et(kt([i[0],i[0],i[1],i[2]]),10,(1+e.roughness)/2)):o.push(...et(kt(i),10,(1+e.roughness)/2))}o.length&&a.push(E([o],e))}return e.stroke!==O&&a.push(n),this._d("curve",a,e)}polygon(t,s){const e=this._o(s),a=[],n=Z(t,!0,e);return e.fill&&(e.fillStyle==="solid"?a.push(tt([t],e)):a.push(E([t],e))),e.stroke!==O&&a.push(n),this._d("polygon",a,e)}path(t,s){const e=this._o(s),a=[];if(!t)return this._d("path",a,e);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");const n=e.fill&&e.fill!=="transparent"&&e.fill!==O,o=e.stroke!==O,h=!!(e.simplification&&e.simplification<1),r=(function(c,l,d){const f=yt(bt(rt(c))),u=[];let p=[],k=[0,0],g=[];const m=()=>{g.length>=4&&p.push(...et(g,l)),g=[]},M=()=>{m(),p.length&&(u.push(p),p=[])};for(const{key:w,data:v}of f)switch(w){case"M":M(),k=[v[0],v[1]],p.push(k);break;case"L":m(),p.push([v[0],v[1]]);break;case"C":if(!g.length){const P=p.length?p[p.length-1]:k;g.push([P[0],P[1]])}g.push([v[0],v[1]]),g.push([v[2],v[3]]),g.push([v[4],v[5]]);break;case"Z":m(),p.push([k[0],k[1]])}if(M(),!d)return u;const y=[];for(const w of u){const v=Rt(w,d);v.length&&y.push(v)}return y})(t,1,h?4-4*(e.simplification||1):(1+e.roughness)/2),i=ft(t,e);if(n)if(e.fillStyle==="solid")if(r.length===1){const c=ft(t,Object.assign(Object.assign({},e),{disableMultiStroke:!0,roughness:e.roughness?e.roughness+e.fillShapeRoughnessGain:0}));a.push({type:"fillPath",ops:this._mergedShape(c.ops)})}else a.push(tt(r,e));else a.push(E(r,e));return o&&(h?r.forEach((c=>{a.push(Z(c,!1,e))})):a.push(i)),this._d("path",a,e)}opsToPath(t,s){let e="";for(const a of t.ops){const n=typeof s=="number"&&s>=0?a.data.map((o=>+o.toFixed(s))):a.data;switch(a.op){case"move":e+=`M${n[0]} ${n[1]} `;break;case"bcurveTo":e+=`C${n[0]} ${n[1]}, ${n[2]} ${n[3]}, ${n[4]} ${n[5]} `;break;case"lineTo":e+=`L${n[0]} ${n[1]} `}}return e.trim()}toPaths(t){const s=t.sets||[],e=t.options||this.defaultOptions,a=[];for(const n of s){let o=null;switch(n.type){case"path":o={d:this.opsToPath(n),stroke:e.stroke,strokeWidth:e.strokeWidth,fill:O};break;case"fillPath":o={d:this.opsToPath(n),stroke:O,strokeWidth:0,fill:e.fill||O};break;case"fillSketch":o=this.fillSketch(n,e)}o&&a.push(o)}return a}fillSketch(t,s){let e=s.fillWeight;return e<0&&(e=s.strokeWidth/2),{d:this.opsToPath(t),stroke:s.fill||O,strokeWidth:e,fill:O}}_mergedShape(t){return t.filter(((s,e)=>e===0||s.op!=="move"))}},jt=class{constructor(t,s){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new J(s)}draw(t){const s=t.sets||[],e=t.options||this.getDefaultOptions(),a=this.ctx,n=t.options.fixedDecimalPlaceDigits;for(const o of s)switch(o.type){case"path":a.save(),a.strokeStyle=e.stroke==="none"?"transparent":e.stroke,a.lineWidth=e.strokeWidth,e.strokeLineDash&&a.setLineDash(e.strokeLineDash),e.strokeLineDashOffset&&(a.lineDashOffset=e.strokeLineDashOffset),this._drawToContext(a,o,n),a.restore();break;case"fillPath":{a.save(),a.fillStyle=e.fill||"";const h=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(a,o,n,h),a.restore();break}case"fillSketch":this.fillSketch(a,o,e)}}fillSketch(t,s,e){let a=e.fillWeight;a<0&&(a=e.strokeWidth/2),t.save(),e.fillLineDash&&t.setLineDash(e.fillLineDash),e.fillLineDashOffset&&(t.lineDashOffset=e.fillLineDashOffset),t.strokeStyle=e.fill||"",t.lineWidth=a,this._drawToContext(t,s,e.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,s,e,a="nonzero"){t.beginPath();for(const n of s.ops){const o=typeof e=="number"&&e>=0?n.data.map((h=>+h.toFixed(e))):n.data;switch(n.op){case"move":t.moveTo(o[0],o[1]);break;case"bcurveTo":t.bezierCurveTo(o[0],o[1],o[2],o[3],o[4],o[5]);break;case"lineTo":t.lineTo(o[0],o[1])}}s.type==="fillPath"?t.fill(a):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,s,e,a,n){const o=this.gen.line(t,s,e,a,n);return this.draw(o),o}rectangle(t,s,e,a,n){const o=this.gen.rectangle(t,s,e,a,n);return this.draw(o),o}ellipse(t,s,e,a,n){const o=this.gen.ellipse(t,s,e,a,n);return this.draw(o),o}circle(t,s,e,a){const n=this.gen.circle(t,s,e,a);return this.draw(n),n}linearPath(t,s){const e=this.gen.linearPath(t,s);return this.draw(e),e}polygon(t,s){const e=this.gen.polygon(t,s);return this.draw(e),e}arc(t,s,e,a,n,o,h=!1,r){const i=this.gen.arc(t,s,e,a,n,o,h,r);return this.draw(i),i}curve(t,s){const e=this.gen.curve(t,s);return this.draw(e),e}path(t,s){const e=this.gen.path(t,s);return this.draw(e),e}},V="http://www.w3.org/2000/svg",qt=class{constructor(t,s){this.svg=t,this.gen=new J(s)}draw(t){const s=t.sets||[],e=t.options||this.getDefaultOptions(),a=this.svg.ownerDocument||window.document,n=a.createElementNS(V,"g"),o=t.options.fixedDecimalPlaceDigits;for(const h of s){let r=null;switch(h.type){case"path":r=a.createElementNS(V,"path"),r.setAttribute("d",this.opsToPath(h,o)),r.setAttribute("stroke",e.stroke),r.setAttribute("stroke-width",e.strokeWidth+""),r.setAttribute("fill","none"),e.strokeLineDash&&r.setAttribute("stroke-dasharray",e.strokeLineDash.join(" ").trim()),e.strokeLineDashOffset&&r.setAttribute("stroke-dashoffset",`${e.strokeLineDashOffset}`);break;case"fillPath":r=a.createElementNS(V,"path"),r.setAttribute("d",this.opsToPath(h,o)),r.setAttribute("stroke","none"),r.setAttribute("stroke-width","0"),r.setAttribute("fill",e.fill||""),t.shape!=="curve"&&t.shape!=="polygon"||r.setAttribute("fill-rule","evenodd");break;case"fillSketch":r=this.fillSketch(a,h,e)}r&&n.appendChild(r)}return n}fillSketch(t,s,e){let a=e.fillWeight;a<0&&(a=e.strokeWidth/2);const n=t.createElementNS(V,"path");return n.setAttribute("d",this.opsToPath(s,e.fixedDecimalPlaceDigits)),n.setAttribute("stroke",e.fill||""),n.setAttribute("stroke-width",a+""),n.setAttribute("fill","none"),e.fillLineDash&&n.setAttribute("stroke-dasharray",e.fillLineDash.join(" ").trim()),e.fillLineDashOffset&&n.setAttribute("stroke-dashoffset",`${e.fillLineDashOffset}`),n}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,s){return this.gen.opsToPath(t,s)}line(t,s,e,a,n){const o=this.gen.line(t,s,e,a,n);return this.draw(o)}rectangle(t,s,e,a,n){const o=this.gen.rectangle(t,s,e,a,n);return this.draw(o)}ellipse(t,s,e,a,n){const o=this.gen.ellipse(t,s,e,a,n);return this.draw(o)}circle(t,s,e,a){const n=this.gen.circle(t,s,e,a);return this.draw(n)}linearPath(t,s){const e=this.gen.linearPath(t,s);return this.draw(e)}polygon(t,s){const e=this.gen.polygon(t,s);return this.draw(e)}arc(t,s,e,a,n,o,h=!1,r){const i=this.gen.arc(t,s,e,a,n,o,h,r);return this.draw(i)}curve(t,s){const e=this.gen.curve(t,s);return this.draw(e)}path(t,s){const e=this.gen.path(t,s);return this.draw(e)}},Ft={canvas:(t,s)=>new jt(t,s),svg:(t,s)=>new qt(t,s),generator:t=>new J(t),newSeed:()=>J.newSeed()};Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return Ft}});