fastdraw 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ import{C as Te,D as We,E as Be,S as re,T as ae,_ as De,a as qe,b as se,c as Je,d as he,f as St,g as Qt,h as Ke,i as Ye,l as pe,m as Xe,n as ti,o as ei,p as de,r as fe,s as ii,t as ni,u as li,v as $e,w as oi,x as Vt,y as xe}from"../embed.js";var ce=(t,e)=>Number.isNaN(t)?+!Number.isNaN(e):Number.isNaN(e)||t<e?-1:+(t>e),Et=(t,e)=>!t.images.has(e)&&!!re[e]&&t.icons.get(e)===re[e];function ri(t){return t>0?Object.entries(Be).reduce((e,i)=>Math.abs(i[1]-t)<Math.abs(e[1]-t)?i:e)[0]:"regular"}function ai(t,e,i="regular"){return e==="solid"?{tint:[],front:ae.fill[t]??[]}:{tint:oi[t]??[],front:ae[i][t]??[]}}function ue(t,e,i){let n=0,l=1,s=e.x-t.x,h=e.y-t.y,r=[[-s,t.x-i.x],[s,i.x+i.w-t.x],[-h,t.y-i.y],[h,i.y+i.h-t.y]];for(let[o,a]of r){if(o===0){if(a<=0)return!1;continue}let p=a/o;if(o<0){if(p>l)return!1;p>n&&(n=p)}else{if(p<n)return!1;p<l&&(l=p)}}return l-n>1e-6}var Tt=(t,e)=>({x:t.x-e,y:t.y-e,w:t.w+2*e,h:t.h+2*e}),si=(t,e)=>e.x>t.x&&e.x<t.x+t.w&&e.y>t.y&&e.y<t.y+t.h;function hi(t,e){for(let i=0;i<t.length-1;i++)for(let n of e)if(ue(t[i],t[i+1],Tt(n,-1)))return!0;return!1}function pi(t){let e=[];for(let i of t){let n=e[e.length-2],l=e[e.length-1];l&&l.x===i.x&&l.y===i.y||(n&&l&&(n.x===l.x&&l.x===i.x||n.y===l.y&&l.y===i.y)?e[e.length-1]=i:e.push(i))}return e}var di=12,Zt=20,ye=30,fi=160,ge=[di,24,36];function $i(t,e,i,n,l,s=[]){let h=e?{x:t.x+e.x*Zt,y:t.y+e.y*Zt}:t,r=n?{x:i.x+n.x*Zt,y:i.y+n.y*Zt}:i,o=Z=>[...new Set(Z.map(T=>Math.round(T)))].sort(ce),a=o([h.x,r.x,...l.flatMap(Z=>ge.flatMap(T=>[Z.x-T,Z.x+Z.w+T]))]),p=o([h.y,r.y,...l.flatMap(Z=>ge.flatMap(T=>[Z.y-T,Z.y+Z.h+T]))]),d=a.length,x=p.length;if(d*x>6e4)return null;let u=(Z,T)=>s.some(([f,L])=>Z.y===T.y&&f.y===L.y&&Z.y===f.y&&Math.min(Math.max(Z.x,T.x),Math.max(f.x,L.x))-Math.max(Math.min(Z.x,T.x),Math.min(f.x,L.x))>0||Z.x===T.x&&f.x===L.x&&Z.x===f.x&&Math.min(Math.max(Z.y,T.y),Math.max(f.y,L.y))-Math.max(Math.min(Z.y,T.y),Math.min(f.y,L.y))>0),c=a.indexOf(Math.round(h.x))+p.indexOf(Math.round(h.y))*d,w=a.indexOf(Math.round(r.x))+p.indexOf(Math.round(r.y))*d,v=Z=>({x:a[Z%d],y:p[Math.floor(Z/d)]}),y=l.map(Z=>Tt(Z,11)),m=l.map(Z=>Tt(Z,2)),U=Z=>Z===c||Z===w||!y.some(T=>si(T,v(Z))),A=(Z,T)=>{let f=v(Z),L=v(T);return!m.some(W=>ue(f,L,W))},Q=d*x*2,G=new Float64Array(Q).fill(1/0),V=new Int32Array(Q).fill(-1),_=[],B=Z=>{_.push(Z);let T=_.length-1;for(;T>0;){let f=T-1>>1;if(G[_[f]]<=G[_[T]])break;[_[f],_[T]]=[_[T],_[f]],T=f}},C=()=>{let Z=_[0],T=_.pop();if(_.length){_[0]=T;for(let f=0;;){let L=2*f+1,W=L+1,P=f;if(L<_.length&&G[_[L]]<G[_[P]]&&(P=L),W<_.length&&G[_[W]]<G[_[P]]&&(P=W),P===f)break;[_[P],_[f]]=[_[f],_[P]],f=P}}return Z},J=e?[+(e.x===0)]:[0,1];for(let Z of J)G[c*2+Z]=0,B(c*2+Z);let at=n?+(n.x===0):-1,dt=-1;for(;_.length;){let Z=C(),T=Z>>1,f=Z&1;if(T===w){dt=Z;break}let L=T%d,W=Math.floor(T/d),P=[];L>0&&P.push([T-1,0]),L<d-1&&P.push([T+1,0]),W>0&&P.push([T-d,1]),W<x-1&&P.push([T+d,1]);for(let[lt,z]of P){if(!U(lt)||!A(T,lt))continue;let O=v(T),R=v(lt),g=G[Z]+Math.abs(O.x-R.x)+Math.abs(O.y-R.y)+(z===f?0:ye)+(s.length&&u(O,R)?fi:0);lt===w&&at>=0&&z!==at&&(g+=ye);let S=lt*2+z;g<G[S]&&(G[S]=g,V[S]=Z,B(S))}}if(dt<0)return null;let ht=[];for(let Z=dt;Z>=0;Z=V[Z])ht.push(v(Z>>1));return ht.reverse(),pi([t,...ht,i])}var xi=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\xB7\u2013\u2014\u2026\u2192\u2190\u2191\u2193\u2022\xD7\u2019\u2018\u201C\u201D",At={geist:{400:[25,21,35,48,63,80,62,18,27,27,43,56,20,42,20,48,66,38,62,61,62,63,59,52,60,59,30,30,54,54,54,56,91,67,68,70,69,60,59,70,71,27,60,64,58,88,74,74,65,73,67,64,55,69,67,95,61,58,54,35,46,35,43,56,25,55,60,55,60,56,40,59,58,24,26,59,27,88,58,57,60,60,38,52,39,57,54,82,59,54,54,39,26,39,52,20,59,91,57,80,80,71,71,31,50,20,20,37,37],500:[24,23,36,52,64,81,65,19,29,29,43,56,21,42,21,49,67,41,63,63,63,64,60,53,62,61,30,30,55,54,55,57,93,69,69,71,70,61,60,71,72,28,61,66,58,89,75,75,66,75,68,65,57,69,69,97,63,59,56,36,47,36,44,56,26,56,61,56,61,58,41,61,59,26,28,61,28,89,59,59,61,61,39,54,41,59,56,83,61,55,55,40,27,40,52,21,59,91,61,80,80,71,71,33,52,22,22,40,40],600:[24,24,38,55,66,82,68,20,31,31,42,57,23,42,23,51,68,43,64,64,64,66,62,54,64,62,31,31,55,55,55,58,94,71,70,72,71,62,60,73,72,29,62,67,59,90,75,76,66,76,69,67,58,70,71,99,66,61,58,38,49,38,45,56,27,58,62,58,62,59,43,62,60,27,31,63,30,89,60,60,62,62,41,55,43,60,58,84,63,57,57,40,28,40,52,23,59,91,65,80,80,71,71,35,53,23,23,43,43],700:[23,26,39,59,67,83,71,20,32,32,42,57,24,42,24,52,69,45,65,65,66,67,63,54,66,63,31,31,55,55,55,59,96,73,70,73,72,62,60,74,72,30,63,69,59,92,75,78,67,77,70,68,60,70,73,101,69,63,59,39,50,39,46,56,28,59,63,60,63,61,45,63,61,28,33,65,31,90,61,62,63,63,43,57,45,61,61,85,65,59,58,41,29,41,52,24,60,91,70,79,79,71,71,36,54,25,25,46,46]},"libre franklin":{400:[21,24,41,60,61,92,78,24,29,29,38,56,21,38,21,34,69,47,60,64,65,65,66,60,67,66,21,23,54,56,54,52,83,73,70,71,72,63,60,74,74,29,42,70,60,91,76,76,69,77,70,64,65,71,71,105,69,68,63,29,34,29,48,52,28,55,60,54,60,58,38,60,58,24,24,56,24,91,58,60,60,60,38,51,39,58,55,80,54,53,48,31,26,31,57,20,56,88,75,-1,-1,-1,-1,31,54,22,22,40,40],500:[21,25,43,60,62,93,80,24,29,29,41,56,23,38,22,35,69,48,61,65,66,66,67,61,67,67,22,24,55,56,55,53,83,74,71,71,73,64,61,74,74,30,43,71,61,92,76,77,70,77,70,65,66,71,72,106,70,69,65,30,35,30,48,53,29,55,60,55,60,58,39,61,59,25,25,58,25,91,59,60,60,60,40,52,40,58,56,80,56,54,49,32,26,32,58,22,57,89,79,-1,-1,-1,-1,32,55,23,23,42,42],600:[21,26,45,60,64,94,82,25,30,30,44,57,24,38,24,36,70,49,63,66,68,67,68,61,68,68,24,25,57,57,57,53,83,76,72,72,74,65,62,75,75,31,44,73,62,93,76,77,71,77,71,67,67,72,72,107,72,72,66,31,36,31,48,54,30,56,61,55,61,58,39,62,59,26,26,59,26,91,59,60,61,61,41,52,42,59,56,81,57,55,51,35,26,35,60,23,57,90,84,-1,-1,-1,-1,33,56,23,23,44,45],700:[21,26,47,60,66,94,84,25,31,31,47,58,25,38,25,37,71,51,64,67,69,68,69,62,68,68,25,26,58,58,58,54,83,77,72,73,75,65,63,75,75,32,45,74,63,95,76,77,72,78,72,68,68,72,73,108,73,74,68,32,37,32,48,54,31,56,61,55,61,59,40,63,60,27,27,60,27,92,60,60,61,61,43,53,43,59,57,82,59,57,52,37,25,37,61,25,58,91,89,-1,-1,-1,-1,34,58,24,24,47,47]},newsreader:{400:[23,27,35,57,57,78,72,20,28,28,44,51,24,35,23,40,57,57,57,57,57,57,57,57,57,57,25,27,51,51,51,44,89,71,64,71,76,64,59,75,80,34,45,73,60,98,77,78,61,78,65,55,67,77,69,97,72,68,63,33,40,33,51,41,50,46,55,44,56,46,35,50,56,28,25,54,27,83,57,53,56,54,39,38,34,54,53,74,51,52,43,32,25,32,51,25,52,69,64,-1,-1,-1,-1,41,51,24,24,41,41],500:[22,28,37,59,59,81,73,20,29,29,43,51,25,36,24,40,59,59,59,59,59,59,59,59,59,59,26,27,51,51,51,46,89,73,67,71,77,65,61,76,82,35,46,75,62,100,78,78,63,78,67,57,68,78,71,100,74,70,64,33,40,33,51,41,50,47,56,45,57,47,36,51,57,29,26,56,28,85,59,53,57,56,41,40,36,55,54,76,52,54,44,32,25,32,51,25,52,68,67,-1,-1,-1,-1,42,51,24,24,43,43],600:[22,28,39,61,61,84,74,21,30,30,43,51,25,36,25,41,61,61,61,61,61,61,61,61,61,61,27,28,51,51,51,48,90,76,69,72,79,67,62,77,84,37,48,77,64,102,78,79,65,79,70,59,70,78,73,103,76,72,65,33,41,33,51,41,50,49,57,46,58,48,38,52,59,30,28,58,29,87,60,54,58,57,43,41,38,57,55,78,53,55,46,32,25,32,51,26,51,67,70,-1,-1,-1,-1,42,51,25,25,45,45]},"instrument serif":{400:[17,24,37,64,42,59,58,23,34,34,44,53,22,43,21,26,46,25,40,37,39,38,40,36,43,40,21,22,53,53,53,32,66,46,48,48,53,45,41,52,55,25,25,50,41,67,54,54,47,54,51,41,46,54,46,65,55,48,43,33,26,33,43,38,35,40,44,34,46,36,29,40,47,22,22,45,22,70,47,41,44,44,32,31,26,45,39,60,39,40,35,32,25,32,53,11,51,72,53,-1,-1,-1,-1,30,53,17,17,32,32]},"sketch hand":{400:[50,30,33,80,80,94,72,27,42,34,52,63,26,41,27,50,69,27,71,68,64,62,64,54,77,61,24,26,61,62,49,47,81,66,73,64,78,67,57,79,55,55,63,61,60,77,64,73,66,71,68,61,80,71,52,75,60,52,80,49,50,50,54,83,44,67,51,50,57,55,49,50,49,22,33,49,26,63,47,55,49,55,43,54,56,57,52,61,56,47,57,57,17,50,84,31,69,91,68,87,92,-1,-1,32,45,41,49,49,51]}},me=["bars","line","area","dots"],we=["paper","dots","dotgap","grid","gridgap","lines","linegap","cross","crossgap","iso","isogap","bars","bargap","diag","diaggap","graph","graphgap","hex","hexgap"],Wt=["none","arrow","open","triangle","diamond","diamond-solid","dot","circle","stop","one","only-one","many","one-many","zero-one","zero-many"],Bt={top:{x:0,y:-1},bottom:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}},ft=(t,e)=>t===void 0||t===""||isNaN(+t)?e:+t;function ut(t,e,i,n,l){let s=i==="mono"?.6:i==="serif"?.46:n>=600?.58:.56;return t.length*e*(s+l)}function ci(t,e,i,n,l,s){let h=(t.fonts.get(n)??n).toLowerCase(),r=[...e],o=0,a=Object.hasOwn(At,h);if(h.includes("mono")||n==="mono"&&!a)o=r.length*.6;else{let p=a?At[h]:At[n==="serif"?"newsreader":"geist"],d=p[Object.keys(p).map(Number).sort((u,c)=>Math.abs(u-l)-Math.abs(c-l)||c-u)[0]]??At.geist[400],x=d[xi.indexOf("o")];for(let u of r){let c=d[" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\xB7\u2013\u2014\u2026\u2192\u2190\u2191\u2193\u2022\xD7\u2019\u2018\u201C\u201D".indexOf(u)]??-1;o+=(c>=0?c:u.codePointAt(0)>=4352?100:x)/100}}return o*i+Math.max(0,r.length-1)*s*i}var mt=t=>t.x+t.w/2,bt=t=>t.y+t.h/2,zt=(t,e,i)=>t>=e&&t<=i;function ke(t,e){return zt(mt(t),e.x,e.x+e.w)||zt(mt(e),t.x,t.x+t.w)?bt(t)<=bt(e)?["bottom","top"]:["top","bottom"]:zt(bt(t),e.y,e.y+e.h)||zt(bt(e),t.y,t.y+t.h)?mt(t)<=mt(e)?["right","left"]:["left","right"]:[mt(e)>mt(t)?"right":"left",bt(t)<bt(e)?"top":"bottom"]}function Ft(t,e,i,n){let l=e==="top"||e==="bottom",s=i!==void 0&&i<=1?i:n,h=i!==void 0&&i>1?i:l?t.x+s*t.w:t.y+s*t.h;h=Math.round(Math.min(Math.max(h,l?t.x:t.y),l?t.x+t.w:t.y+t.h));let r=0,o=l?Math.abs(h-mt(t))/(t.w/2||1):Math.abs(h-bt(t))/(t.h/2||1),a=l?t.h/2:t.w/2;return t.shape==="diamond"?r=a*o:t.shape==="ellipse"&&(r=a*(1-Math.sqrt(Math.max(0,1-o*o)))),r=Math.round(r),e==="top"?{x:h,y:t.y+r}:e==="bottom"?{x:h,y:t.y+t.h-r}:e==="left"?{x:t.x+r,y:h}:{x:t.x+t.w-r,y:h}}function _t(t,e,i){return i?{x:e.x,y:t.y}:{x:t.x,y:e.y}}function ui(t,e){let i=t.a.pt,n=t.b.pt,l=t.a.dir,s=t.b.dir;if(!t.ortho)return[i,...e,n];if(e.length===0){let o=i.x===n.x||i.y===n.y;if(l&&s){let c=l.x!==0;if(c!==(s.x!==0))return[i,_t(i,n,c),n];if(l.x===s.x&&l.y===s.y){t.ushape=!0;let v=ft(t.p.loop,36);if(c){let m=l.x>0?Math.max(i.x,n.x)+v:Math.min(i.x,n.x)-v;return[i,{x:m,y:i.y},{x:m,y:n.y},n]}let y=l.y>0?Math.max(i.y,n.y)+v:Math.min(i.y,n.y)-v;return[i,{x:i.x,y},{x:n.x,y},n]}if(c?i.y===n.y:i.x===n.x)return[i,n];if(c){let v=Math.round((i.x+n.x)/2);return[i,{x:v,y:i.y},{x:v,y:n.y},n]}let w=Math.round((i.y+n.y)/2);return[i,{x:i.x,y:w},{x:n.x,y:w},n]}if(o)return[i,n];let a=n.x-i.x,p=n.y-i.y,d=Math.abs(a)>=Math.abs(p),x=()=>{if(d){let w=Math.round((i.x+n.x)/2);return[i,{x:w,y:i.y},{x:w,y:n.y},n]}let c=Math.round((i.y+n.y)/2);return[i,{x:i.x,y:c},{x:n.x,y:c},n]},u=(c,w)=>d?c.x*a*w>0:c.y*p*w>0;return l?u(l,1)?x():[i,_t(i,n,l.x!==0),n]:s?u(s,-1)?x():[i,_t(i,n,s.x===0),n]:x()}let h=[i,...e,n],r=[i];for(let o=0;o<h.length-1;o++){let a=h[o],p=h[o+1];if(a.x!==p.x&&a.y!==p.y){let d;if(o===h.length-2&&s)d=s.x===0;else if(o===0&&l)d=l.x!==0;else{let x=r[r.length-2];d=!x||x.y!==a.y}r.push(_t(a,p,d))}r.push(p)}return r}function yi(t,e,i,n,l,s){let h=[],r=i.x-t.x,o=i.y-t.y,a=Math.hypot(r,o)||1;if(l.length){let d=[t,...l,i],x=(c,w)=>{let v=Math.hypot(c,w)||1;return{x:c/v,y:w/v}},u=d.map((c,w)=>w===0?e??x(d[1].x-c.x,d[1].y-c.y):w===d.length-1?n?{x:-n.x,y:-n.y}:x(c.x-d[w-1].x,c.y-d[w-1].y):x(d[w+1].x-d[w-1].x,d[w+1].y-d[w-1].y));for(let c=0;c<d.length-1;c++){let w=d[c],v=d[c+1],y=Math.hypot(v.x-w.x,v.y-w.y)/3;h.push([w,{x:w.x+u[c].x*y,y:w.y+u[c].y*y},{x:v.x-u[c+1].x*y,y:v.y-u[c+1].y*y},v])}}else if(isNaN(s)){let d=Math.min(Math.max(a*.4,24),160),x=Math.abs(r)>=Math.abs(o),u=e??(x?{x:Math.sign(r)||1,y:0}:{x:0,y:Math.sign(o)||1}),c=n??(x?{x:-(Math.sign(r)||1),y:0}:{x:0,y:-(Math.sign(o)||1)});h.push([t,{x:t.x+u.x*d,y:t.y+u.y*d},{x:i.x+c.x*d,y:i.y+c.y*d},i])}else{let d=o/a*s*1.3333333333333333,x=-r/a*s*(4/3);h.push([t,{x:t.x+r/3+d,y:t.y+o/3+x},{x:t.x+2*r/3+d,y:t.y+2*o/3+x},i])}let p=[t];for(let[d,x,u,c]of h)for(let w=1;w<=24;w++){let v=w/24,y=1-v,m=U=>y*y*y*d[U]+3*y*y*v*x[U]+3*y*v*v*u[U]+v*v*v*c[U];p.push(w===24?c:{x:Math.round(m("x")*10)/10,y:Math.round(m("y")*10)/10})}return p}function gi(t,e){let i=t.pts[0],n=t.pts[t.pts.length-1];if(e>1){if(i.x===n.x)return{x:i.x,y:e};if(i.y===n.y)return{x:e,y:i.y}}let l=Math.min(Math.max(e,0),1);return{x:Math.round(i.x+(n.x-i.x)*l),y:Math.round(i.y+(n.y-i.y)*l)}}function mi(t,e=[]){if(!t.text)return;let i=ft(t.p["label.size"],8),n=ft(t.p["label.spacing"],.08),l=t.p["label.font"]??"mono",s=t.p["label.caps"]==="0"?t.text:t.text.toUpperCase(),h=Math.ceil((ut(s,i,l,400,n)+12)/4)*4,r=i+4;if(t.p.lpos){let[y,m]=t.p.lpos.split(",").map(Number);return{text:s,cx:y,baseline:m,x:y-h/2,y:m-r+2,w:h,h:r,size:i,spacing:n,font:l}}let o=0;if(t.curve)o=Math.floor((t.pts.length-1)/2);else if(t.ushape&&t.pts.length===4)o=1;else{let y=-1;for(let m=0;m<t.pts.length-1;m++){let U=Math.abs(t.pts[m+1].x-t.pts[m].x)+Math.abs(t.pts[m+1].y-t.pts[m].y);U>y&&(y=U,o=m)}}let a=t.pts[o],p=t.pts[o+1],d=(a.x+p.x)/2,x=(a.y+p.y)/2,u=y=>{if(t.curve){let U=t.pts[o],A=t.pts[Math.min(o+1,t.pts.length-1)],Q=t.pts[Math.max(o-1,0)],G=A.x-Q.x,V=A.y-Q.y,_=Math.hypot(G,V)||1,B=V/_,C=-G/_;(C>0||C===0&&B<0)&&(B=-B,C=-C),(y==="below"||y==="left")&&(B=-B,C=-C);let J=6+(Math.abs(B)*h+Math.abs(C)*r)/2,at=Math.round(U.x+B*J),dt=Math.round(U.y+C*J);return{text:s,cx:at,baseline:dt+r/2-3,x:at-h/2,y:dt-r/2,w:h,h:r,size:i,spacing:n,font:l}}if(a.x===p.x&&a.y!==p.y){let U=y==="left"?a.x-8-h:a.x+8;return{text:s,cx:U+h/2,baseline:Math.round(x)+3,x:U,y:Math.round(x)-r+5,w:h,h:r,size:i,spacing:n,font:l}}let m=y==="below"?Math.round(x)+18:Math.round(x)-10;return{text:s,cx:Math.round(d),baseline:m,x:Math.round(d)-h/2,y:m-r+2,w:h,h:r,size:i,spacing:n,font:l}},c=y=>e.some(m=>y.x<m.x+m.w&&y.x+y.w>m.x&&y.y<m.y+m.h&&y.y+y.h>m.y),w=u(t.p.lside);if(t.p.lside||!c(w))return w;let v=u(a.x===p.x&&a.y!==p.y?"left":"below");return c(v)?w:v}function wi(t,e,i,n,l){let s=t.p,h=ft(s["cell.size"],10),r=s["cell.font"]??"mono",o=ft(s["row.h"],24),a=ft(s["cell.pad"],12),p=ft(s["cell.gap"],16),d=ft(s["title.size"],12),x=t.text?t.text.split(`
2
+ `):[],u=t.text?ft(s["head.h"],32)+(x.length-1)*Math.ceil(d*1.25/4)*4:0,c=Math.max(0,...e.map(C=>C.cells.length)),w=[],v=C=>c>1&&C.cells.length===1&&C.kind!=="head";for(let C=0;C<c;C++)w.push(Math.max(0,...e.filter(J=>!v(J)).map(J=>J.cells[C]===void 0?0:ut(J.cells[C],h,r,J.kind==="head"?600:400,0))));if(s.align==="center"&&c>1){let C=Math.max(...w.slice(1));for(let J=1;J<c;J++)w[J]=C}let y=Math.max(0,...e.filter(v).map(C=>ut(C.cells[0],h,r,400,0)+a*2)),m=c?a*2+w.reduce((C,J)=>C+J,0)+p*(c-1):0,U=Math.max(y,m),A=t.text?Math.max(...x.map(C=>ut(C,d,s["title.font"]??"sans",ft(s["title.weight"],600),ft(s["title.spacing"],0))))+a*2:0,Q=Math.ceil(Math.max(i,U,A,48)/4)*4;i&&Math.max(U,A)>i+4&&l(`${t.id} was given a width of ${i} but its content needs ${Q}, so it is drawn ${Q} wide; shorten the cells or give it room`),c&&(w[0]+=Q-m);let G=[],V=a;for(let C of w)G.push({x:V,w:C}),V+=C+p;let _=t.y+u,B=new Set;for(let C of e)C.y=_,C.h=C.kind==="rule"?0:ft(C.p.h,o),_+=C.h,C.id&&(B.has(C.id)&&n(`the row id "${C.id}" is used twice in ${t.id}`),B.add(C.id));t.w=Q,t.h=Math.max(_-t.y,o),t.rows=e,t.cols=G,t.headH=u}function Me(t){let e={raw:t,pt:{x:0,y:0},dir:null},i=/^(\+\d+(?:\.\d+)?),([+-]?\d+(?:\.\d+)?)$/.exec(t)??/^(-\d+(?:\.\d+)?),(\+\d+(?:\.\d+)?)$/.exec(t);if(i)return{...e,kind:"rel",rel:{x:+i[1],y:+i[2]}};if(i=/^(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)$/.exec(t),i)return{...e,kind:"point",pt:{x:+i[1],y:+i[2]}};if(i=/^([A-Za-z_][\w-]*)(?:\.([A-Za-z_][\w-]*))?(?:\.(left|right))?(?:@(-?[\d.]+))?$/.exec(t),i){let n=i[2]!==void 0&&i[2]in Bt;return n&&i[3]?null:{...e,kind:"shape",id:i[1],row:n?void 0:i[2],side:n?i[2]:i[3],v:i[4]===void 0?void 0:+i[4]}}return null}function be(t){return Vt(t).find(e=>e.toks[0]?.t==="word"&&e.toks[0].v==="look")?.toks[1]?.v}function ve(t,e){let i=`look ${/^[a-z][a-z0-9-]*$/.test(e)?e:JSON.stringify(e)}`,n=t.split(/\r?\n/),l=Vt(t).filter(s=>s.toks[0]?.t==="word"&&s.toks[0].v==="look");return l.length?(l.forEach((s,h)=>{for(let r=s.line;r<=s.end;r++)n[r-1]=r===s.line&&h===0?i:""}),n.join(`
3
+ `)):t.replace(/\s*$/,"")+`
4
+ `+i+`
5
+ `}function ki(t,e,i=""){let n=[],l=(f,L)=>n.push({line:f,level:"error",msg:L}),s=(f,L)=>n.push({line:f,level:"warn",msg:L}),h=Vt(t),r=h.find(f=>f.toks[0]?.v==="look"&&f.toks[0].t==="word"),o=he(r?.toks[1]?.v??""),a=o??e??(r?Xe():de()),p=a.canvas;if(r){let f=r.toks[1]?.v;if(!f)l(r.line,`look needs a name or a path, e.g. look sketch or look "./team.look" (named looks: ${pe.join(", ")})`);else if(!o&&!e)l(r.line,De(f)?`the look at ${f} could not be fetched`:xe(f)?`the ${f} look no longer ships with FastDraw; it is in ${li} on GitHub: look "${xe(f)}"`:/[\\/]|\.look$/i.test(f)?`look file not found: ${f}`:`no look named ${f}; named looks: ${pe.join(", ")}, or give a path to a .look file`);else for(let L of a.issues)n.push({...L,line:r.line,msg:`${L.msg} (in look, line ${L.line})`})}let d=[],x=[],u=[],c=new Map,w,v=!1,y=[],m=[],U=()=>[...a.styles.values()];for(let f of h){let L=f.toks,W=L[0];if(W.t==="word"&&W.v==="look")continue;if(W.t==="word"&&W.v==="canvas"){w=f.line;let b={};for(let j of L.slice(1))/^\d+x\d+$/.test(j.v??"")?v=!0:j.t==="prop"&&we.includes(j.k)?b[j.k]=j.v:l(f.line,`canvas only takes ${we.map(D=>D+"=").join(", ")}; remove ${j.t==="prop"?j.k+"=":j.v}`);Object.keys(b).length&&(a={...a,canvas:{...a.canvas,...b}});continue}let P=0,lt;W.t==="word"&&W.v.endsWith(":")&&W.v.length>1&&(lt=W.v.slice(0,-1),P=1);let z=L.findIndex(b=>b.t==="word"&&(b.v==="->"||b.v==="--"||b.v==="<->")),O=(b,j)=>{let D=lt??`_${j}${f.line}`;return c.has(D)&&l(f.line,`the id "${D}" is already used; ids must be unique`),c.set(D,b),D};if(z>=0){let b=L[z-1],j=L[z+1];if(!b||z-1<P||!j){l(f.line,"a connector needs something on both sides, e.g. a -> b");continue}let D=Me(b.v),st=Me(j.v);if(!D||!st){l(f.line,`cannot read the connector end "${D?j.v:b.v}"; use an id, id.side, id.side@pos, id@pos or x,y`);continue}let $t=L[z].v,it={},tt;for(let nt of L.slice(z+2))nt.t==="str"?tt??=nt.v:nt.t==="prop"?it[nt.k]=nt.v:l(f.line,`unexpected word "${nt.v}" after the connector; properties look like key=value`);let et=it.style??($t==="--"?D.row||st.row?"relation":"line":"arrow"),pt=a.styles.get(et);if(!pt||pt.kind!=="line"){l(f.line,`"${et}" is not a line style in the look; line styles: ${U().filter(nt=>nt.kind==="line").map(nt=>nt.name).join(", ")}`);continue}let xt={...pt.props,...it};xt.route&&!["ortho","straight","curve"].includes(xt.route)&&l(f.line,`route=${xt.route} is not a route; use ortho, straight or curve`);let Nt=pt.props.head&&pt.props.head!=="none"?pt.props.head:"arrow",Pt=pt.props.head==="none"&&et!=="line",ot=it.head??($t==="--"||Pt?"none":Nt),gt=it.tail??($t==="<->"?ot:$t==="--"?"none":pt.props.tail??"none");for(let nt of[ot,gt])Wt.includes(nt)||l(f.line,`"${nt}" is not an end marker; use one of: ${Wt.join(", ")}`);let yt=nt=>Wt.includes(nt)?nt:"arrow";u.push({id:O("conn","c"),line:f.line,style:et,p:xt,a:D,b:st,pts:[],head:ot!=="none",tail:gt!=="none",headM:yt(ot),tailM:yt(gt),ortho:(xt.route??"ortho")==="ortho",curve:xt.route==="curve",ushape:!1,text:tt});continue}let R=L[P++];if(!R||R.t!=="word"){l(f.line,'expected: id: style "text" at x,y');continue}let g=a.styles.get(R.v);if(!g||g.kind==="line"){l(f.line,`unknown style "${R.v}"; available: ${U().filter(b=>b.kind!=="line").map(b=>b.name).join(", ")}`);continue}let S,k,H,F={},I=[];for(;P<L.length;P++){let b=L[P];if(b.t==="word"&&(b.v==="|"||b.v==="|=")){I.push({kind:b.v==="|"?"row":"head",cells:[],vals:[],p:{},y:0,h:0});continue}let j=I[I.length-1];if(j)b.t==="str"?j.cells.push(b.v):b.t==="prop"?j.p[b.k]=b.v:b.v==="---"&&!j.cells.length&&!j.id?j.kind="rule":!j.id&&!j.cells.length&&/^[A-Za-z_][\w-]*$/.test(b.v)&&!(b.v in Bt)?j.id=b.v:/^([+-]?\d*\.?\d+(,[+-]?\d*\.?\d+){0,2}|_)$/.test(b.v)?j.vals.push(b.v):l(f.line,`unexpected word "${b.v}" in a table row; a row is: | id "cell" "cell" (the id is optional, and cannot be top, bottom, left or right)`);else if(b.t==="str")S??=b.v;else if(b.t==="prop")F[b.k]=b.v;else if(b.v==="at"){let D=/^(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)$/.exec(L[++P]?.v??"");D?k={x:+D[1],y:+D[2]}:l(f.line,'after "at" write the position as x,y with no space, e.g. at 40,240')}else if(/^\d+(\.\d+)?x\d+(\.\d+)?$/.test(b.v)){let[D,st]=b.v.split("x").map(Number);H={w:D,h:st}}else l(f.line,`unexpected word "${b.v}"; properties look like key=value and text goes in "quotes"`)}let K=g.props,X=g.name;if(F.style){let b=a.styles.get(F.style);!b||b.kind!==g.kind?l(f.line,`style=${F.style} is not a ${g.kind} style in the look`):(K={...K,...b.props},X=b.name)}let N={...K,...F};if(g.kind==="text"){if(!k){l(f.line,"text needs a position: at x,y");continue}let b=ft(N.size,12),j=(S??"").split(`
6
+ `),D=N.caps==="1"?(S??"").toUpperCase():S??"",st=Math.max(...j.map(Nt=>ut(Nt,b,N.font??"sans",ft(N.weight,400),ft(N.spacing,0)))),$t=N.anchor??"start",it=$t==="middle"?k.x-st/2:$t==="end"?k.x-st:k.x,tt=b*1.3*j.length,et=ft(N.rotate,0);N.rotate!==void 0&&![0,90,-90].includes(et)&&l(f.line,`rotate=${N.rotate}: text can be turned by 90 (reading down) or -90 (reading up)`);let pt=it-k.x,xt=et===-90?{x:k.x-b,y:k.y-pt-st,w:tt,h:st}:et===90?{x:k.x-tt+b,y:k.y+pt,w:tt,h:st}:{x:it,y:k.y-b,w:st,h:tt};x.push({id:O("text","t"),line:f.line,style:X,p:N,text:D,ax:k.x,ay:k.y,...xt});continue}if(!H&&N.size){let b=/^(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)$/.exec(N.size);b&&(H={w:+b[1],h:+b[2]})}let ct=H;H??={w:120,h:48};let Y={id:O("shape","s"),line:f.line,style:X,p:N,shape:N.shape??"rect",text:S,back:N.layer==="back",x:k?.x??0,y:k?.y??0,w:H.w,h:H.h},Mt=fe(a,N.icon);if(Mt)s(f.line,`icon ${N.icon} is one of the look's icon files (${ti(a,N.icon)}), which could not be loaded here, so the built-in icon ${Mt} is drawn in its place`);else if(N.icon&&N.icon!=="none"&&!a.icons.has(N.icon)&&!a.images.has(N.icon)){let b=[...a.images.keys(),...a.icons.keys()],j=a.hideBuiltIns?[...new Set(b.filter(tt=>!Et(a,tt)))]:[],D=j.length?j:b,st=D.filter(tt=>Te(tt,N.icon)||tt.length>2&&N.icon.includes(tt)),$t=[...new Set([...st,...D])].slice(0,40),it=a.iconDirs.length&&!a.images.size?` (the look's icon folder ${a.iconDirs.join(", ")} could not be read here)`:"";l(f.line,`there is no icon called "${N.icon}"${it}; the look has: ${$t.join(", ")}${D.length>$t.length?`, and ${D.length-$t.length} more (run "fastdraw icons" to see them all)`:""}`)}N["icon.width"]!==void 0&&!(Number(N["icon.width"])>0&&Number(N["icon.width"])<=8)&&l(f.line,`icon.width=${N["icon.width"]}: the icon's line thickness in pixels, a number from 0.5 to 8 (e.g. icon.width=2)`),N["icon.style"]!==void 0&&!["outline","solid","duotone"].includes(N["icon.style"])?l(f.line,`icon.style=${N["icon.style"]}: an icon is drawn as an outline (the default), filled in one colour (icon.style=solid), or as an outline over a light tint (icon.style=duotone)`):(N["icon.style"]==="solid"||N["icon.style"]==="duotone")&&N.icon&&N.icon!=="none"&&(a.icons.has(N.icon)||a.images.has(N.icon))&&!Et(a,N.icon)&&s(f.line,`icon ${N.icon} is the look's own, with no ${N["icon.style"]} version (only the built-in icons have one), so it is drawn as it is; drop icon.style=${N["icon.style"]}`),N["icon.pos"]&&!["left","top","corner"].includes(N["icon.pos"])&&l(f.line,`icon.pos=${N["icon.pos"]}: an icon sits left of the text, on top of it, or in the top-left corner as a tab (icon.pos=left, icon.pos=top or icon.pos=corner)`);for(let b of["color","weight","font","italic"])F[b]!==void 0&&s(f.line,`${b}= does nothing on a shape; its text is set with title.${b}= (and sub.${b}= for the second line)`);if(Y.shape==="polygon"){let b=(N.points??"").split(";").filter(Boolean).map(j=>{let[D,st]=j.split(",").map(Number);return{x:D,y:st}});if(b.length<2||b.some(j=>isNaN(j.x)||isNaN(j.y)))l(f.line,'a polygon needs its corners: points=x,y;x,y;x,y measured from its "at" position, e.g. points=60,0;120,100;0,100');else{let j=Math.max(...b.map(it=>it.x)),D=Math.max(...b.map(it=>it.y));b.some(it=>it.x<0||it.y<0)&&l(f.line,'polygon points cannot be negative; they are measured from the "at" position, which is the top-left of the shape'),ct||(Y.w=j,Y.h=D);let st=j?Y.w/j:1,$t=D?Y.h/D:1;Y.poly=b.map(it=>({x:Math.round((Y.x+it.x*st)*100)/100,y:Math.round((Y.y+it.y*$t)*100)/100}))}}if(Y.shape==="arc")for(let b of["from","to","inner"])N[b]!==void 0&&isNaN(+N[b])&&l(f.line,`${b}=${N[b]} must be a number (from= and to= are degrees clockwise from the top; inner= is 0 to 1)`);if(Y.shape==="table")wi(Y,I,ct?.w??0,b=>l(f.line,b),b=>s(f.line,b));else if(Y.shape==="chart"){Y.rows=I,ct||l(f.line,"a chart needs a size for its plot area: at x,y WxH");for(let j of["step","xstep"])N[j]!==void 0&&!(Number(N[j])>0)&&l(f.line,`${j}=${N[j]} must be a number above 0`);for(let j of["x","y"]){let D=/^(-?[\d.]+)\.\.(-?[\d.]+)$/.exec(N[j]??"");D&&!(+D[2]>+D[1])&&l(f.line,`${j}=${N[j]} must run upwards, e.g. ${j}=0..100`)}let b=N.x&&!/^-?[\d.]+\.\.-?[\d.]+$/.test(N.x)?N.x.split(",").length:0;for(let j of I)!j.id||!me.includes(j.id)?l(f.line,`a chart row starts with the kind of series: ${me.join(", ")}; e.g. | bars "Revenue" 42 61 75`):j.vals.length?b&&j.vals.length!==b&&!j.vals[0].includes(",")&&s(f.line,`the ${j.id} series ${j.cells[0]?`"${j.cells[0]}" `:""}has ${j.vals.length} values but x= names ${b} categories`):l(f.line,`the ${j.id} series ${j.cells[0]?`"${j.cells[0]}" `:""}has no numbers; write them after the name: | ${j.id} "Name" 42 61 75`)}else I.length&&l(f.line,`rows (the parts starting with "|") only work on a table style; "${X}" is not one`);if(Y.shape==="legend"){let b=tt=>/^(swatch|dot|line)\.(.+)$/.exec(tt),j=Object.entries(F).filter(([tt])=>tt!=="style"&&(a.styles.has(tt)||b(tt))),D=ft(N["item.size"],8.5),st=N["item.font"]??"sans",$t=(N.title??"none")!=="none",it=tt=>{let et=j.map(([ot,gt])=>{let yt=b(ot);if(yt){let vt=yt[2];return yt[1]==="line"?{style:ot,kind:"line",label:gt,x:0,baseline:0,sample:28,props:{stroke:vt,sw:"1.6",head:"none"}}:{style:ot,kind:"shape",label:gt,x:0,baseline:0,sample:14,props:yt[1]==="dot"?{shape:"dot",fill:vt,stroke:"none"}:{shape:"rect",fill:vt,stroke:"none",radius:"2"}}}let nt=a.styles.get(ot),Ot=nt.kind==="line"?28:nt.kind==="text"?16:nt.props.shape==="diamond"?22:14;return{style:ot,kind:nt.kind,label:gt,x:0,baseline:0,sample:Ot}}),pt=et.map(ot=>ot.sample+6+ut(ot.label,D,st,400,0)),xt=[[]],Nt=0;pt.forEach((ot,gt)=>{let yt=xt[xt.length-1];yt.length&&Nt+20+ot>tt?(xt.push([gt]),Nt=ot):(Nt+=(yt.length?20:0)+ot,yt.push(gt))});let Pt=Y.y+($t?40:20);xt.forEach((ot,gt)=>{let yt=ot.reduce((vt,Ve)=>vt+pt[Ve],0),nt=xt.length===1&&ot.length>1?Math.min(64,Math.max(20,(tt-yt)/(ot.length-1))):24,Ot=Y.x;for(let vt of ot)et[vt].x=Math.round(Ot),et[vt].baseline=Pt+gt*20,Ot+=pt[vt]+nt}),Y.w=tt,Y.h=($t?40:20)+(xt.length-1)*20+12,Y.legend=et};ct?it(Y.w):y.push(()=>{let tt=[...d.filter(et=>et.shape!=="legend").map(et=>et.x+et.w),...x.map(et=>et.x+et.w),...u.flatMap(et=>[et.a,et.b].filter(pt=>pt.kind==="point").map(pt=>pt.pt.x))];it(tt.length?Math.max(200,Math.round((Math.max(...tt)-Y.x)/4)*4):920)}),j.length||s(f.line,'this legend has no entries; add style="what it means" for each style, e.g. focal="The main service"')}k||m.push(Y),d.push(Y)}for(let f of y)f();if(m.length){let f=d.filter(P=>!m.includes(P)),L=40,W=f.length?Math.max(...f.map(P=>P.y+P.h))+40:40;for(let P of m)P.x=L,P.y=W,L+=P.w+40,s(P.line,`${P.id} has no position ("at x,y"); it was dropped in a row at ${P.x},${P.y}`)}let A=new Map;for(let f of d)A.set(f.id,f);for(let f of x)A.set(f.id,{x:f.x-4,y:f.y-2,w:f.w+8,h:f.h+4});let Q=new Map(u.map(f=>[f.id,f])),G=new Map(d.filter(f=>f.rows).map(f=>[f.id,f.rows])),V=f=>{let L=A.get(f.id),W=f.row?G.get(f.id)?.find(P=>P.id===f.row):void 0;return W?{x:L.x,y:W.y,w:L.w,h:W.h}:L},_=f=>`${f.id}${f.row?"."+f.row:""}|${f.side}`,B=new Set,C=new Set;for(let f of u)for(let L of[f.a,f.b])if(L.kind==="shape")if(A.has(L.id)){if(L.row&&!G.get(L.id)?.some(W=>W.id===L.row)){let W=(G.get(L.id)??[]).filter(P=>P.id).map(P=>P.id);l(f.line,`${L.raw}: "${L.id}" has no row called "${L.row}"${W.length?`; its rows: ${W.join(", ")}`:" (only a table has rows; a side is top, bottom, left or right)"}`),C.add(f)}}else Q.has(L.id)?(L.kind="conn",L.side&&(l(f.line,`${L.raw}: "${L.id}" is a line, so it has no sides; use ${L.id}@position`),C.add(f)),L.v===void 0&&(L.v=.5)):(l(f.line,`connector refers to "${L.id}", which does not exist`),C.add(f));for(let f of u)f.a.kind==="rel"&&f.b.kind==="rel"&&(l(f.line,"only one end of a connector can be relative (+dx,+dy)"),C.add(f));let J=[],at=f=>{let L=z=>z.kind==="shape"?V(z):z.kind==="point"?{x:z.pt.x,y:z.pt.y,w:0,h:0}:z.kind==="conn"?(z.pt=gi(Q.get(z.id),z.v),{x:z.pt.x,y:z.pt.y,w:0,h:0}):null;for(let z of f){let O=L(z.a),R=L(z.b),g=k=>Math.abs(k.y)>=Math.abs(k.x)?k.y>=0?"bottom":"top":k.x>=0?"right":"left",S=(k,H,F)=>(H?mt(H)>=mt(k):F.x>=0)?"right":"left";if(z.a.kind==="shape"&&!z.a.side&&(z.a.side=z.a.row?S(O,R,z.b.rel??{x:0,y:0}):R?ke(O,R)[0]:g(z.b.rel),z.a.fanned=!0),z.b.kind==="shape"&&!z.b.side){let k=z.a.rel?{x:-z.a.rel.x,y:-z.a.rel.y}:{x:0,y:0};z.b.side=z.b.row?S(R,O,k):O?ke(O,R)[1]:g(k),z.b.fanned=!0}}let W=new Map;for(let z of f)for(let[O,R]of[[z.a,z.b],[z.b,z.a]]){if(O.kind!=="shape"||O.v!==void 0)continue;let g=_(O);W.has(g)||W.set(g,[]),W.get(g).push({c:z,e:O,o:R})}let P=new Map,lt=new Set;for(let[z,O]of W){let R=z.endsWith("top")||z.endsWith("bottom"),g=S=>{let k=L(S);return k?R?mt(k):bt(k):0};O.length===1?(P.set(O[0].e,.5),lt.add(O[0].e)):O.map((S,k)=>({m:S,idx:k,r:g(S.o)})).sort((S,k)=>ce(S.r,k.r)||S.idx-k.idx).forEach((S,k)=>P.set(S.m.e,(k+1)/(O.length+1)))}for(let z of f){for(let k of[z.a,z.b])if(k.kind==="shape"){let H=V(k);if(k.pt=Ft(H,k.side,k.v,P.get(k)??.5),k.dir=Bt[k.side],k.v!==void 0&&k.v>1){let F=k.side==="top"||k.side==="bottom",I=F?H.x:H.y,K=F?H.x+H.w:H.y+H.h;(k.v<I||k.v>K)&&s(z.line,`${k.raw}: ${k.v} is outside the ${k.side} side of ${k.id}, which runs from ${I} to ${K}; the end was moved to the nearest point`)}}let O=z.a,R=z.b,g=O.dir&&R.dir&&O.dir.x===-R.dir.x&&O.dir.y===-R.dir.y;if(O.kind==="shape"&&R.kind==="shape"&&g){let k=V(O),H=V(R),F=O.side==="top"||O.side==="bottom",I=F?Math.max(k.x,H.x):Math.max(k.y,H.y),K=F?Math.min(k.x+k.w,H.x+H.w):Math.min(k.y+k.h,H.y+H.h);if(K>I){let X;if(lt.has(O)&&lt.has(R)){let N=F?mt(k):bt(k),ct=F?mt(H):bt(H),Y=(F?k.w<=H.w:k.h<=H.h)?N:ct,Mt=Y===N?ct:N;X=zt(Y,I,K)?Y:zt(Mt,I,K)?Mt:(I+K)/2}else if(!lt.has(O)&&!lt.has(R)&&O.v===void 0&&R.v===void 0){let N=W.get(_(O)),ct=W.get(_(R));N.length===ct.length&&N.every(Y=>ct.some(Mt=>Mt.c===Y.c))&&(X=I+(K-I)*P.get(O))}else lt.has(O)&&R.v!==void 0?X=F?R.pt.x:R.pt.y:lt.has(R)&&O.v!==void 0&&(X=F?O.pt.x:O.pt.y);X!==void 0&&zt(X,I,K)&&(O.pt=Ft(k,O.side,Math.max(X,1.0001),.5),R.pt=Ft(H,R.side,Math.max(X,1.0001),.5))}}for(let[k,H]of[[O,R],[R,O]]){if(k.kind!=="shape"||!lt.has(k)||H.kind!=="point"&&H.kind!=="conn")continue;let F=V(k),I=k.side==="top"||k.side==="bottom",K=I?H.pt.x:H.pt.y;zt(K,(I?F.x:F.y)+2,(I?F.x+F.w:F.y+F.h)-2)&&(k.pt=Ft(F,k.side,Math.max(K,1.0001),.5))}O.kind==="rel"&&(O.pt={x:R.pt.x+O.rel.x,y:R.pt.y+O.rel.y}),R.kind==="rel"&&(R.pt={x:O.pt.x+R.rel.x,y:O.pt.y+R.rel.y});let S=[];if(z.p.via&&(S=z.p.via.split(";").map(k=>{let[H,F]=k.split(",").map(Number);return{x:H,y:F}}),S.some(k=>isNaN(k.x)||isNaN(k.y))&&(l(z.line,"via must look like via=x,y or via=x,y;x,y"),S=[])),O.pt.x===R.pt.x&&O.pt.y===R.pt.y&&s(z.line,`${z.a.raw} and ${z.b.raw} meet at the same point (${O.pt.x},${O.pt.y}), so this line has no length and is not drawn; attach it to other sides`),z.pts=z.curve?yi(O.pt,O.dir,R.pt,R.dir,S,ft(z.p.bend,NaN)):ui(z,S),z.ortho&&!S.length&&!z.ushape){let k=(F,I)=>I.x>F.x+1&&I.x<F.x+F.w-1&&I.y>F.y+1&&I.y<F.y+F.h-1,H=d.filter(F=>!F.back&&F.shape!=="legend"&&!(F.poly&&F.p.open==="1")&&Math.min(F.w,F.h)>12&&!k(F,O.pt)&&!k(F,R.pt));for(let F of d){let I=F.id!==z.a.id&&F.id!==z.b.id?ze(F):null;I&&H.push({x:I.x-4,y:I.y-2,w:I.w+8,h:I.h+4})}if(hi(z.pts,H)){let F=$i(O.pt,O.dir,R.pt,R.dir,H,J);F&&(z.pts=F)}}if(z.ortho)for(let k=0;k<z.pts.length-1;k++)J.push([z.pts[k],z.pts[k+1]]);z.label=mi(z,d.filter(k=>!k.back&&k.shape!=="legend")),B.add(z)}},dt=u.filter(f=>!C.has(f)),ht=f=>f.a.kind==="conn"||f.b.kind==="conn";at(dt.filter(f=>!ht(f)));let Z=dt.filter(ht);for(let f of Z)for(let L of[f.a,f.b])L.kind==="conn"&&!B.has(Q.get(L.id))&&(l(f.line,`"${L.id}" is itself attached to a line; attach to a line that starts at a shape or a point`),C.add(f));at(Z.filter(f=>!C.has(f)));let T=u.filter(f=>B.has(f));return{file:i,...Mi([...d,...d.map(ze).filter(f=>!!f)],x,T),look:a,canvasLine:w,canvasSize:v,baseCanvas:p,shapes:d,texts:x,conns:T,issues:n}}function ze(t){if(t.shape!=="icon"||!t.text&&!t.p.sub)return null;let e=t.p,i=+(e["title.size"]??11)||11,n=+(e["sub.size"]??9)||9,l=t.text?t.text.split(`
7
+ `):[],s=e.sub?e.sub.split(`
8
+ `):[],h=Math.max(0,...l.map(o=>ut(o,i,e["title.font"]??"sans",+(e["title.weight"]??600)||600,0)),...s.map(o=>ut(o,n,e["sub.font"]??"mono",400,0))),r=l.length*Math.round(i*1.17)+(s.length?2+s.length*Math.round(n*1.3):0);return{x:t.x+t.w/2-h/2,y:t.y+t.h+6,w:h,h:r}}function Mi(t,e,i){let n=[...t,...e,...i.flatMap(p=>[...p.pts.map(d=>({x:d.x,y:d.y,w:0,h:0})),...p.label?[p.label]:[]])];if(!n.length)return{x:0,y:0,w:400,h:240};let l=Math.min(...n.map(p=>p.x)),s=Math.min(...n.map(p=>p.y)),h=Math.max(...n.map(p=>p.x+p.w)),r=Math.max(...n.map(p=>p.y+p.h)),o=Math.floor((l-40)/4)*4,a=Math.floor((s-40)/4)*4;return{x:o,y:a,w:Math.ceil((h+40)/4)*4-o,h:Math.ceil((r+40)/4)*4-a}}var Ne=["accent","link","ink/0.55","soft","accent/0.5","link/0.5"];function bi(t,e=6){if(!(t>0))return 1;let i=t/e,n=10**Math.floor(Math.log10(i));for(let l of[1,2,2.5,5,10])if(l*n>=i)return l*n;return 10*n}var Le=(t,e)=>{let i=Number(t);return t!==void 0&&Number.isFinite(i)&&i>0&&e/i<=200?i:bi(e)};function Se(t,e,i){let n=Math.ceil(t/i-1e-9),l=Math.floor(e/i+1e-9),s=[];if(!Number.isFinite(n)||!Number.isFinite(l))return s;for(let h=n;h<=l&&s.length<=200;h++)s.push(h*i);return s}var Dt=t=>String(Math.round(t*1e3)/1e3),je=t=>{let e=/^(-?[\d.]+)\.\.(-?[\d.]+)$/.exec(t??"");return e&&Math.abs(+e[1])<1e15&&Math.abs(+e[2])<1e15&&+e[2]>+e[1]?[+e[1],+e[2]]:null};function vi(t,e){let i=e.p,n=(e.rows??[]).filter(g=>g.id&&g.vals.length),l=[],{x:s,y:h,w:r,h:o}=e,a=g=>g==="_"?[]:g.split(",").map(Number),p=je(i.x),d=!p&&i.x?i.x.split(",").map(g=>g.trim()):[],x=p?0:Math.max(d.length,...n.map(g=>g.vals.length),1),u=g=>Number.isFinite(g),c=n.flatMap(g=>g.vals.flatMap(S=>g.id==="bars"||g.id==="dots"&&!p?a(S):a(S).slice(-1))),w=i.stack==="1";if(w)for(let g=0;g<x;g++)c.push(n.filter(S=>S.id==="bars").reduce((S,k)=>S+(+k.vals[g]||0),0));for(let g=c.length-1;g>=0;g--)(!u(c[g])||Math.abs(c[g])>=1e15)&&c.splice(g,1);let v=je(i.y),y=v?v[0]:Math.min(0,...c),m=v?v[1]:Math.max(0,...c);m>y||(m=y+1);let U=Le(i.step,m-y);v||(y=Math.floor(y/U)*U,m=Math.ceil(m/U)*U,m===y&&(m=y+U));let A=g=>$(h+o-(g-y)/(m-y)*o),Q=x?r/x:0,G=g=>$(s+Q*(g+.5)),V=g=>p?$(s+(g-p[0])/(p[1]-p[0])*r):0,_=A(Math.min(Math.max(0,y),m)),B=rt(t,i,"tick.",{font:"mono",size:9,weight:400,color:"muted"}),C=E(t,i.stroke??"ink/0.5"),J=E(t,i["grid.color"]??"ink/0.08"),at=M(i.sw,1),dt=i.unit??"",ht=i.prefix??"";i.fill&&i.fill!=="none"&&l.push(`<rect x="${s}" y="${h}" width="${r}" height="${o}" fill="${E(t,i.fill)}"/>`);for(let g of Se(y,m,U)){let S=A(g);i.grid!=="0"&&i.grid!=="x"&&Math.abs(S-(h+o))>.5&&l.push(`<line x1="${s}" y1="${S}" x2="${s+r}" y2="${S}" stroke="${J}" stroke-width="1"/>`),i.yaxis!=="0"&&l.push(`<text x="${s-8}" y="${$(S+B.size*.35)}" text-anchor="end" ${B.a}>${q(ht+Dt(g)+dt)}</text>`)}if(p){let g=Le(i.xstep,p[1]-p[0]);for(let S of Se(p[0],p[1],g))(i.grid==="both"||i.grid==="x")&&S>p[0]&&l.push(`<line x1="${V(S)}" y1="${h}" x2="${V(S)}" y2="${h+o}" stroke="${J}" stroke-width="1"/>`),l.push(`<text x="${V(S)}" y="${h+o+8+B.size}" text-anchor="middle" ${B.a}>${q(Dt(S)+(i.xunit??""))}</text>`)}else d.forEach((g,S)=>{i.grid==="x"&&S>0&&l.push(`<line x1="${$(s+Q*S)}" y1="${h}" x2="${$(s+Q*S)}" y2="${h+o}" stroke="${J}" stroke-width="1"/>`),l.push(`<text x="${G(S)}" y="${h+o+8+B.size}" text-anchor="middle" ${B.a}>${q(g)}</text>`)});let Z=rt(t,i,"value.",{font:"mono",size:9,weight:400,color:"ink"}),T=i.labels==="1",f=(g,S,k,H=!1)=>T&&l.push(`<text x="${g}" y="${$(S)}" text-anchor="middle" ${Z.a}>${q((H?"+":"")+ht+Dt(k)+dt)}</text>`),L=n.filter(g=>g.id==="bars"),W=(g,S)=>g.p[S]??g.p.fill??g.p.stroke??Ne[n.indexOf(g)%Ne.length],P=Q*M(i["bar.width"],.64),lt=w||!L.length?P:P/L.length,z=[];L.forEach((g,S)=>{let k=M(i["bar.radius"],2),H=g.p.stroke&&g.p.fill?` stroke="${E(t,g.p.stroke)}" stroke-width="${M(g.p.sw,1)}"`:"";g.vals.forEach((F,I)=>{let K=a(F);if(!K.length)return;let X=K.length===2?K[0]:0,N=K.length===2?K[1]:K[0];w&&K.length===1&&(X=z[I]??0,N=X+K[0],z[I]=N);let ct=Math.min(A(X),A(N)),Y=Math.abs(A(X)-A(N)),Mt=$(G(I)-P/2+(w?0:S*lt)+ +(lt>6)),b=$(lt-(lt>6?2:0));l.push(`<rect x="${Mt}" y="${ct}" width="${b}" height="${$(Math.max(Y,.5))}"${k&&Y>k*2&&!w?` rx="${k}"`:""} fill="${E(t,g.p[`fill.${I+1}`]??W(g,"fill"))}"${H}/>`),f($(Mt+b/2),N>=X?ct-4:ct+Y+Z.size+2,K.length===2?N-X:K[0],K.length===2&&X!==0&&N>X)})});for(let g of n){if(g.id==="bars")continue;let S=E(t,W(g,"stroke")),k=M(g.p.sw,2),H=g.vals.map((I,K)=>({raw:I,i:K})).filter(I=>I.raw!=="_").map(({raw:I,i:K})=>{let X=a(I);return X.length>=2&&p?{x:V(X[0]),y:A(X[1]),v:X[1],r:X[2]??0,i:K}:{x:G(K),y:A(X[0]),v:X[0],r:X[1]??0,i:K}});if(!H.length)continue;let F=H.map(I=>`${I.x},${I.y}`).join(" ");if(g.id==="area"&&l.push(`<polygon points="${H[0].x},${_} ${F} ${H[H.length-1].x},${_}" fill="${E(t,g.p.fill??W(g,"stroke")+(/\/[\d.]+$/.test(W(g,"stroke"))?"":"/0.1"))}"/>`),g.id!=="dots"&&l.push(`<polyline points="${F}" fill="none" stroke="${S}" stroke-width="${k}" stroke-linejoin="round" stroke-linecap="round"${g.p.dash?` stroke-dasharray="${q(g.p.dash)}"`:""}/>`),g.id==="dots"||g.p.dots==="1")for(let I of H)l.push(`<circle cx="${I.x}" cy="${I.y}" r="${g.id==="dots"?M(g.p.r,I.r||4):3}" fill="${g.id==="dots"?E(t,g.p[`fill.${I.i+1}`]??g.p.fill??W(g,"stroke")):E(t,t.canvas.paper??"paper")}" stroke="${g.id==="dots"&&!(g.p.fill&&g.p.stroke)?"none":S}" stroke-width="${g.id==="dots"?M(g.p.sw,1.2):k}"${g.id==="dots"&&g.p.opacity?` fill-opacity="${M(g.p.opacity,1)}"`:""}/>`);for(let I of H)f(I.x,I.y-8,I.v)}l.push(`<path d="M ${s},${h} L ${s},${h+o} L ${s+r},${h+o}" fill="none" stroke="${C}" stroke-width="${at}"/>`),y<0&&m>0&&i.zero!=="0"&&l.push(`<line x1="${s}" y1="${_}" x2="${s+r}" y2="${_}" stroke="${C}" stroke-width="${at}"/>`);let O=rt(t,i,"axis.",{font:"sans",size:10,weight:400,color:"muted"});i.xtitle&&l.push(`<text x="${s+r/2}" y="${h+o+36}" text-anchor="middle" ${O.a}>${q(i.xtitle)}</text>`),i.ytitle&&l.push(`<text x="${s}" y="${h-12}" ${O.a}>${q(i.ytitle)}</text>`);let R=n.filter(g=>g.cells[0]);if(R.length>1&&i.key!=="0"){let g=s+r;for(let S of[...R].reverse()){let k=ut(S.cells[0],O.size,O.font,400,0);g-=k,l.push(`<text x="${$(g)}" y="${h-12}" ${O.a}>${q(S.cells[0])}</text>`),g-=14,l.push(`<rect x="${$(g)}" y="${h-20}" width="10" height="10" rx="2" fill="${E(t,W(S,S.id==="bars"?"fill":"stroke"))}"/>`),g-=16}}if(e.text){let g=rt(t,i,"title.",{font:"sans",size:12,weight:600,color:"ink"});l.push(`<text x="${s}" y="${h-(i.ytitle||R.length>1&&i.key!=="0"?32:12)}" ${g.a}>${q(e.text)}</text>`)}return l.join(`
9
+ `)}function zi(t,e){let i=2166136261^e;for(let n=0;n<t.length;n++)i=Math.imul(i^t.charCodeAt(n),16777619);return()=>{i=i+1831565813|0;let n=Math.imul(i^i>>>15,1|i);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function Ni(t){return/^[MLCQZ0-9eE\s,.+-]*$/.test(t)}function It(t,e,i){let n=zi(t,i),l=c=>(n()-.5)*2*c,s=(c,w)=>({x:c.x+l(w),y:c.y+l(w)}),h=[],r={x:0,y:0},o=r,a=r,p=c=>{let w=c.x-r.x,v=c.y-r.y,y=Math.hypot(w,v);if(y<.5)return;let m=l(Math.min(y*.02,3.2)*e),U=-v/y,A=w/y,Q=Math.min(1.8,.35+y*.012)*e,G=s(c,Q),V={x:a.x+w/3+U*m,y:a.y+v/3+A*m},_={x:a.x+w*2/3+U*m,y:a.y+v*2/3+A*m};h.push(`C ${$(V.x)},${$(V.y)} ${$(_.x)},${$(_.y)} ${$(G.x)},${$(G.y)}`),r=c,a=G},d=t.match(/[MLCQZ]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi)??[],x=0,u=()=>({x:+d[x++],y:+d[x++]});for(;x<d.length;){let c=d[x++];if(c==="M")r=o=u(),a=s(r,.6*e),h.push(`M ${$(a.x)},${$(a.y)}`);else if(c==="L")for(;x<d.length&&!/[A-Z]/i.test(d[x]);)p(u());else if(c==="C")for(;x<d.length&&!/[A-Z]/i.test(d[x]);){let w=s(u(),.9*e),v=s(u(),.9*e);r=u(),a=s(r,.6*e),h.push(`C ${$(w.x)},${$(w.y)} ${$(v.x)},${$(v.y)} ${$(a.x)},${$(a.y)}`)}else if(c==="Q")for(;x<d.length&&!/[A-Z]/i.test(d[x]);){let w=s(u(),.6*e);r=u(),a=s(r,.5*e),h.push(`Q ${$(w.x)},${$(w.y)} ${$(a.x)},${$(a.y)}`)}else c==="Z"?p(o):x++}return h.join(" ")}function jt(t,e,i,n=""){let l=/fill="([^"]*)"/.exec(e)?.[1]??"none",s=e.replace(/fill="[^"]*"/,'fill="none"'),h=!/stroke="none"/.test(e)&&/stroke="/.test(e),r=/stroke-dasharray/.test(e),o=[];if(l!=="none"&&o.push(`<path d="${It(t,i*.5,0)}" fill="${l}" stroke="none"/>`),n&&o.push(n.replace("{d}",It(t,i*.5,0))),h){let a=' stroke-linecap="round" stroke-linejoin="round"';o.push(`<path d="${It(t,i,1)}" ${s}${a}/>`),r||o.push(`<path d="${It(t,i,2)}" ${s.replace(/stroke-width="([\d.]+)"/,(p,d)=>`stroke-width="${$(d*.85)}"`)}${a}/>`)}return o.join(`
10
+ `)}function Ue(t,e,i,n,l){return l?`M ${t+l},${e} L ${t+i-l},${e} Q ${t+i},${e} ${t+i},${e+l} L ${t+i},${e+n-l} Q ${t+i},${e+n} ${t+i-l},${e+n} L ${t+l},${e+n} Q ${t},${e+n} ${t},${e+n-l} L ${t},${e+l} Q ${t},${e} ${t+l},${e} Z`:`M ${t},${e} L ${t+i},${e} L ${t+i},${e+n} L ${t},${e+n} Z`}function Li(t,e,i,n){let l=t+i/2,s=e+n/2,h=i/2,r=n/2,o=.5523;return`M ${$(l+h)},${$(s)} C ${$(l+h)},${$(s+r*o)} ${$(l+h*o)},${$(s+r)} ${$(l)},${$(s+r)} C ${$(l-h*o)},${$(s+r)} ${$(l-h)},${$(s+r*o)} ${$(l-h)},${$(s)} C ${$(l-h)},${$(s-r*o)} ${$(l-h*o)},${$(s-r)} ${$(l)},${$(s-r)} C ${$(l+h*o)},${$(s-r)} ${$(l+h)},${$(s-r*o)} ${$(l+h)},${$(s+r*.08)}`}var wt={amt:0,defs:new Map},Ut=t=>t.sketch==="0"?0:wt.amt;function qt(t,e,i,n){let l=`${t}|${e}|${i}|${n}`,s=wt.defs.get(l);return s||(s=`fd-${t}-${wt.defs.size}`,wt.defs.set(l,s)),`url(#${s})`}function Si(t,e){return!e.hatch||e.hatch==="none"?null:qt("hatch",E(t,e.hatch),M(e["hatch.gap"],6),M(e["hatch.sw"],1))}function ji(t,e){return!e.halftone||e.halftone==="none"?null:qt("dots",E(t,e.halftone),Math.max(2,M(e["halftone.gap"],6)),M(e["halftone.r"],1.05))}function Ui(){return[...wt.defs].map(([t,e])=>{let[i,n,l,s]=t.split("|");return i==="dots"?`<pattern id="${e}" width="${l}" height="${l}" patternUnits="userSpaceOnUse"><circle cx="${l/4}" cy="${l/4}" r="${s}" fill="${n}"/><circle cx="${l*3/4}" cy="${l*3/4}" r="${s}" fill="${n}"/></pattern>`:`<pattern id="${e}" width="${l}" height="${l}" patternUnits="userSpaceOnUse" patternTransform="rotate(-41)"><line x1="0" y1="0" x2="0" y2="${l}" stroke="${n}" stroke-width="${s}" stroke-linecap="round"/></pattern>`}).join("")}var Ci=' style="mix-blend-mode:multiply"',Rt=t=>t.blend==="multiply"?Ci:"",Jt=(t,e,i)=>({...t,x:t.x+e,y:t.y+i,poly:t.poly?.map(n=>({x:n.x+e,y:n.y+i}))}),Kt=t=>t.shape!=="polygon"&&t.shape!=="arc",Lt=6;function Ce(t,e){let i=e.p,n=[];if(i.shadow&&i.shadow!=="none"&&Kt(e)){let s=M(i["shadow.size"],12),h=M(i["shadow.dx"],0),r=M(i["shadow.dy"],4),o=E(t,i.shadow);for(let a=Lt;a>=1;a--){let p=$(s*a/Lt),d={...e,x:e.x-p+h,y:e.y-p+r,w:e.w+p*2,h:e.h+p*2,p:{...i,radius:String(M(i.radius,0)+p)}};n.push(kt(d,`fill="${o}" fill-opacity="${$(1/Lt)}" stroke="none"`))}}if(i.shade&&i.shade!=="none"){let s=M(i["shade.size"],5);n.push(kt(Jt(e,s,s),`fill="${qt("hatch",E(t,i.shade),M(i["shade.gap"],2.6),M(i["shade.sw"],.6))}" stroke="none"`))}let l=M(i.depth,0);if(l>0){let s=Jt(e,0,l),h=E(t,t.canvas.paper??"paper"),r=`fill="${E(t,i["depth.fill"]??"ink/0.2")}" stroke="${E(t,i["depth.stroke"]??i.stroke)}"`;i.stroke&&i.stroke!=="none"&&(r+=` stroke-width="${M(i.sw,1)}"`),n.push(kt(s,`fill="${h}"`),kt(s,r))}return n}function Oe(t,e){let i=e.p,n=[];if(i.inner&&i.inner!=="none"&&Kt(e)){let h=M(i["inner.gap"],3.5);if(e.w>h*2+4&&e.h>h*2+4){let r={...e,x:e.x+h,y:e.y+h,w:e.w-h*2,h:e.h-h*2,p:{...i,radius:String(Math.max(0,M(i.radius,0)-h))}};n.push(kt(r,`fill="none" stroke="${E(t,i.inner)}" stroke-width="${M(i["inner.sw"],.6)}"`))}}let l=te(e),s=[[i.side,M(i["side.w"],4)],[l?.block?i["icon.block"]:void 0,l?.block??0]];for(let[h,r]of s)h&&h!=="none"&&r>0&&e.shape==="rect"&&n.push(`<path d="${Oi(e,r)}" fill="${E(t,h)}"/>`);if(i.corners&&i.corners!=="none"&&(e.shape==="rect"||e.shape==="table")){let h=E(t,i["corners.color"]??i.stroke??"ink"),r=M(i["corners.size"],i.corners==="plus"?7:5)/2;for(let[o,a]of[[e.x,e.y],[e.x+e.w,e.y],[e.x,e.y+e.h],[e.x+e.w,e.y+e.h]])n.push(i.corners==="plus"?`<path d="M ${o-r},${a} H ${o+r} M ${o},${a-r} V ${a+r}" stroke="${h}" stroke-width="1.2" fill="none"/>`:`<rect x="${o-r}" y="${a-r}" width="${r*2}" height="${r*2}" fill="${h}"/>`)}return n}function Oi(t,e){let i=Math.min(M(t.p.radius,0),e,t.h/2),n=t.x,l=t.y,s=t.y+t.h;return i>0?`M ${$(n+i)},${l} H ${$(n+e)} V ${s} H ${$(n+i)} Q ${n},${s} ${n},${$(s-i)} V ${$(l+i)} Q ${n},${l} ${$(n+i)},${l} Z`:`M ${n},${l} H ${$(n+e)} V ${s} H ${n} Z`}var q=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),M=(t,e)=>t===void 0||t===""||isNaN(+t)?e:+t,$=t=>Math.round(t*100)/100,E=(t,e,i)=>q(St(t,e,i)),Ee=(t,e)=>q(Ke(t,e));function rt(t,e,i,n){let l=a=>e[i+a],s=M(l("size"),n.size),h=M(l("spacing"),0),r=`font-family="${Ee(t,l("font")??n.font)}" font-size="${s}" fill="${E(t,l("color")??n.color)}"`,o=M(l("weight"),n.weight);return o!==400&&(r+=` font-weight="${o}"`),l("italic")==="1"&&(r+=' font-style="italic"'),h&&(r+=` letter-spacing="${$(h*s)}"`),{a:r,size:s,spacing:h,font:l("font")??n.font,weight:o}}function Yt(t,e){let i=`fill="${E(t,e.fill)}" stroke="${E(t,e.stroke)}"`;return e.stroke&&e.stroke!=="none"&&(i+=` stroke-width="${M(e.sw,1)}"`),e.dash&&e.dash!=="none"&&(i+=` stroke-dasharray="${q(e.dash)}"`),e.cap==="round"&&(i+=' stroke-linecap="round"'),i}function Ei(t){let{x:e,y:i,w:n,h:l}=t;return t.shape==="ellipse"?Li(e,i,n,l):t.shape==="diamond"?`M ${e+n/2},${i} L ${e+n},${i+l/2} L ${e+n/2},${i+l} L ${e},${i+l/2} Z`:t.shape==="polygon"?t.poly?Ai(t):null:t.shape==="path"?t.p.path?Zi(t):null:t.shape==="arc"?null:Ue(e,i,n,l,Math.min(M(t.p.radius,0),n/2,l/2))}function Zi(t){let e=!0;return t.p.path.replace(/-?\d*\.?\d+/g,i=>{let n=e?t.x+ +i*t.w:t.y+ +i*t.h;return e=!e,String($(n))})}function Ai(t){let e=t.poly,i=t.p.open==="1";if(t.p.smooth==="1"&&e.length>2){let n=s=>i?e[Math.min(Math.max(s,0),e.length-1)]:e[(s+e.length)%e.length],l=`M ${e[0].x},${e[0].y}`;for(let s=0;s<(i?e.length-1:e.length);s++){let h=n(s-1),r=n(s),o=n(s+1),a=n(s+2);l+=` C ${$(r.x+(o.x-h.x)/6)},${$(r.y+(o.y-h.y)/6)} ${$(o.x-(a.x-r.x)/6)},${$(o.y-(a.y-r.y)/6)} ${o.x},${o.y}`}return l+(i?"":" Z")}return`M ${e.map(n=>`${n.x},${n.y}`).join(" L ")}${i?"":" Z"}`}function Xt(t,e,i){let n=Ut(t.p);if(n){let l=Ei(t);if(l&&Ni(l))return jt(l,t.shape==="polygon"&&t.p.open==="1"?e.replace(/fill="[^"]*"/,'fill="none"'):e,n,i?`<path d="{d}" fill="${i}" stroke="none"/>`:"")}return i?[kt(t,e.replace(/stroke="[^"]*"/,'stroke="none"')),kt(t,`fill="${i}" stroke="none"`),kt(t,e.replace(/fill="[^"]*"/,'fill="none"'))].join(`
11
+ `):kt(t,e)}function kt(t,e){let{x:i,y:n,w:l,h:s}=t;if(t.shape==="ellipse")return`<ellipse cx="${i+l/2}" cy="${n+s/2}" rx="${l/2}" ry="${s/2}" ${e}/>`;if(t.shape==="diamond")return`<polygon points="${i+l/2},${n} ${i+l},${n+s/2} ${i+l/2},${n+s} ${i},${n+s/2}" ${e}/>`;if(t.shape==="path"&&t.p.path){let r=!0;return`<path d="${q(t.p.path.replace(/-?\d*\.?\d+/g,o=>{let a=r?i+ +o*l:n+ +o*s;return r=!r,String($(a))}))}" ${e}/>`}if(t.shape==="polygon"&&t.poly){let r=t.poly,o=t.p.open==="1",a=o?e.replace(/fill="[^"]*"/,'fill="none"'):e;if(t.p.smooth==="1"&&r.length>2){let p=x=>o?r[Math.min(Math.max(x,0),r.length-1)]:r[(x+r.length)%r.length],d=`M ${r[0].x},${r[0].y}`;for(let x=0;x<(o?r.length-1:r.length);x++){let u=p(x-1),c=p(x),w=p(x+1),v=p(x+2);d+=` C ${$(c.x+(w.x-u.x)/6)},${$(c.y+(w.y-u.y)/6)} ${$(w.x-(v.x-c.x)/6)},${$(w.y-(v.y-c.y)/6)} ${w.x},${w.y}`}return`<path d="${d}${o?"":" Z"}" stroke-linejoin="round" ${a}/>`}return`<${o?"polyline":"polygon"} points="${r.map(p=>`${p.x},${p.y}`).join(" ")}" stroke-linejoin="round" ${a}/>`}if(t.shape==="arc"){let r=M(t.p.from,0),o=M(t.p.to,360),a=Math.min(Math.max(M(t.p.inner,0),0),.98),p=t.p.open==="1",d=i+l/2,x=n+s/2,u=(y,m)=>`${$(d+l/2*m*Math.sin(y*Math.PI/180))},${$(x-s/2*m*Math.cos(y*Math.PI/180))}`,c=(y,m,U)=>{let A=(m+U)/2,Q=+(U>m),G=`${$(l/2*y)} ${$(s/2*y)}`;return`A ${G} 0 0 ${Q} ${u(A,y)} A ${G} 0 0 ${Q} ${u(U,y)}`},w=Math.abs(o-r)>=360,v=`M ${u(r,1)} ${c(1,r,o)}`;return p?`<path d="${v}" ${e.replace(/fill="[^"]*"/,'fill="none"')} stroke-linecap="round"/>`:(v+=a>0?w?` Z M ${u(o,a)} ${c(a,o,r)} Z`:` L ${u(o,a)} ${c(a,o,r)} Z`:w?" Z":` L ${$(d)},${$(x)} Z`,`<path d="${v}" fill-rule="evenodd" stroke-linejoin="round" ${e}/>`)}let h=Math.min(M(t.p.radius,0),l/2,s/2);return`<rect x="${i}" y="${n}" width="${l}" height="${s}"${h?` rx="${h}"`:""} ${e}/>`}function Fi(t,e){let i=e.p,n=[];if(n.push(`<line x1="${e.x}" y1="${e.y}" x2="${e.x+e.w}" y2="${e.y}" stroke="${E(t,i.rule??"ink/0.12")}" stroke-width="0.8"/>`),(i.title??"none")!=="none"){let s=rt(t,i,"title.",{font:"mono",size:8,weight:400,color:"muted"});n.push(`<text x="${e.x}" y="${e.y+16}" ${s.a}>${q(i["title.caps"]==="0"?i.title:i.title.toUpperCase())}</text>`)}let l=rt(t,i,"item.",{font:"sans",size:8.5,weight:400,color:"muted"});for(let s of e.legend??[]){let h=s.props??t.styles.get(s.style)?.props??{},r=s.baseline;if(s.kind==="line"){let o=Math.min(M(h.sw,1.2),1.6),a=E(t,h.stroke??"muted"),p=h.head==="none"||h.route==="straight"?"none":h.head??"arrow",d=p!=="none",x=ie(p,{x:s.x+28,y:r-3},{x:s.x,y:r-3},o,a,E(t,t.canvas.paper??"paper")),u=h.dash&&h.dash!=="none"?` stroke-dasharray="${q(h.dash)}"`:"";n.push(wt.amt?jt(`M ${s.x},${r-3} L ${$(s.x+28-x.trim)},${r-3}`,`fill="none" stroke="${a}" stroke-width="${o}"${u}`,wt.amt*.6):`<line x1="${s.x}" y1="${r-3}" x2="${$(s.x+28-x.trim)}" y2="${r-3}" stroke="${a}" stroke-width="${o}"${u}/>`),d&&n.push(x.svg)}else if(s.kind==="text"){let o=rt(t,{...h,size:String(Math.min(M(h.size,12),11))},"",{font:"sans",size:11,weight:400,color:"ink"});n.push(`<text x="${s.x}" y="${r}" ${o.a}>Aa</text>`)}else{let o=Yt(t,{...h,sw:String(Math.min(M(h.sw,1),1.2))}),a=/^(\d+(?:\.\d+)?)x/.exec(h.size??"");h.shape==="dot"?n.push(`<circle cx="${s.x+7}" cy="${r-3}" r="4.5" ${o}/>`):h.shape==="diamond"?n.push(`<polygon points="${s.x+11},${r-9} ${s.x+22},${r-3} ${s.x+11},${r+3} ${s.x},${r-3}" ${o}/>`):a&&+a[1]<=12?n.push(`<rect x="${s.x+5}" y="${r-11}" width="4" height="14" ${o}/>`):n.push(`<rect x="${s.x}" y="${r-8}" width="14" height="10" rx="${M(h.radius,0)>=12?5:2}" ${o}/>`)}n.push(`<text x="${s.x+s.sample+6}" y="${r}" ${l.a}>${q(s.label)}</text>`)}return n.join(`
12
+ `)}function _i(t,e){let i=e.p,n=[],l=e.rows??[],s=e.cols??[],h=e.headH??0,r=E(t,t.canvas.paper??"paper"),o=E(t,i.stroke),a=M(i.sw,1),p=Math.min(M(i.radius,0),e.w/2,e.h/2),d=e.x+e.w;if(n.push(...Ce(t,e)),n.push(`<rect x="${e.x}" y="${e.y}" width="${e.w}" height="${e.h}"${p?` rx="${p}"`:""} fill="${r}"/>`),n.push(`<rect x="${e.x}" y="${e.y}" width="${e.w}" height="${e.h}"${p?` rx="${p}"`:""} fill="${E(t,i.fill)}"/>`),h){let m=e.y+h;n.push(`<path d="M ${e.x},${m} L ${e.x},${e.y+p} Q ${e.x},${e.y} ${e.x+p},${e.y} L ${d-p},${e.y} Q ${d},${e.y} ${d},${e.y+p} L ${d},${m} Z" fill="${E(t,i["head.fill"]??"ink/0.06",i.fill)}"/>`);let U=rt(t,i,"title.",{font:"sans",size:12,weight:600,color:"ink"}),A=(i["title.caps"]==="1"?e.text.toUpperCase():e.text).split(`
13
+ `),Q=Math.round(U.size*1.25),G=i["title.align"]==="left";A.forEach((V,_)=>n.push(`<text x="${G?e.x+M(i["cell.pad"],12):e.x+e.w/2}" y="${$(m-h/2+U.size*.36+(_-(A.length-1)/2)*Q)}" text-anchor="${G?"start":"middle"}" ${U.a}>${q(V)}</text>`)),l.length&&n.push(`<line x1="${e.x}" y1="${m}" x2="${d}" y2="${m}" stroke="${o}" stroke-width="${a}"/>`)}let x=rt(t,i,"cell.",{font:"mono",size:10,weight:400,color:"ink"}),u=rt(t,{...i,"cell.color":i["detail.color"]??"muted"},"cell.",{font:"mono",size:10,weight:400,color:"muted"}),c=rt(t,{...i,"cell.weight":"600"},"cell.",{font:"mono",size:10,weight:600,color:"ink"}),w=i.align==="center",v=E(t,i.rule??"ink/0.1");if(l.forEach((m,U)=>{if(m.kind==="rule"){n.push(`<line x1="${e.x}" y1="${m.y}" x2="${d}" y2="${m.y}" stroke="${o}" stroke-width="${a}"/>`);return}let A=m.p.fill??(m.kind==="head"?i["head.fill"]??"ink/0.06":void 0);A&&A!=="none"&&n.push(`<rect x="${e.x+a/2}" y="${m.y}" width="${e.w-a}" height="${m.h-(U===l.length-1?a/2:0)}" fill="${E(t,A,i.fill)}"/>`);let Q=l[U-1];Q&&Q.kind!=="rule"&&i.rules!=="0"&&n.push(`<line x1="${e.x}" y1="${m.y}" x2="${d}" y2="${m.y}" stroke="${v}" stroke-width="0.8"/>`),m.cells.forEach((G,V)=>{let _=s[V];if(!_)return;let B=m.p[`fill.${V+1}`],C=m.p[`color.${V+1}`],J=M(i["cell.gap"],16);if(B&&B!=="none"){let Z=V===0?e.x+a/2:e.x+_.x-J/2,T=V===s.length-1?d-a/2:e.x+s[V+1].x-J/2;n.push(`<rect x="${$(Z)}" y="${m.y}" width="${$(T-Z)}" height="${m.h}" fill="${E(t,B,i.fill)}"/>`)}if(G==="")return;let at=m.kind==="head"?c:V===0?x:u,dt=C?{...at,a:at.a.replace(/fill="[^"]*"/,()=>`fill="${E(t,C)}"`)}:at,ht=w&&V>0;n.push(`<text x="${$(e.x+_.x+(ht?_.w/2:0))}" y="${$(m.y+m.h/2+dt.size*.36)}"${ht?' text-anchor="middle"':""} ${dt.a}>${q(G)}</text>`)})}),i.grid==="1"&&l.length)for(let m of s.slice(1)){let U=$(e.x+m.x-M(i["cell.gap"],16)/2);n.push(`<line x1="${U}" y1="${e.y+h}" x2="${U}" y2="${e.y+e.h}" stroke="${v}" stroke-width="0.8"/>`)}let y=`fill="none" stroke="${o}"`;return i.stroke&&i.stroke!=="none"&&(y+=` stroke-width="${a}"`),i.dash&&i.dash!=="none"&&(y+=` stroke-dasharray="${q(i.dash)}"`),n.push(Ut(i)?jt(Ue(e.x,e.y,e.w,e.h,p),y,Ut(i)):`<rect x="${e.x}" y="${e.y}" width="${e.w}" height="${e.h}"${p?` rx="${p}"`:""} ${y}/>`),n.push(...Oe(t,e)),n.join(`
14
+ `)}function te(t){let e=t.p;if(!e.icon||e.icon==="none")return null;if(e["icon.pos"]==="corner")return{x:t.x,y:t.y,size:M(e["icon.size"],24),dx:0,dy:0};let i=!!(t.text||e.sub)&&e["title.pos"]!=="top",n=M(e["icon.size"],i?20:Math.max(8,Math.min(t.w,t.h,96)-(t.style==="icon"?0:16)));if(!i)return{x:t.x+(t.w-n)/2,y:t.y+(t.h-n)/2,size:n,dx:0,dy:0};if(e["icon.block"]&&e["icon.block"]!=="none"&&(e["icon.pos"]??"left")==="left"&&t.shape==="rect"){let h=M(e["icon.block.w"],t.h);return{x:t.x+(h-n)/2,y:t.y+(t.h-n)/2,size:n,dx:h/2,dy:0,block:h}}if(e["icon.pos"]==="top"){let h=Ze(e)?M(e["icon.bg.size"],n+24):n;return{x:t.x+(t.w-n)/2,y:0,size:n,dx:0,dy:(h+6)/2,room:h}}if(e["title.align"]==="left"||e["title.align"]==="right")return{x:t.x+12,y:t.y+(t.h-n)/2,size:n,dx:(n+8)/2,dy:0};let l=[...(t.text?t.text.split(`
15
+ `):[]).map(h=>ut(e["title.caps"]==="1"?h.toUpperCase():h,M(e["title.size"],12),e["title.font"]??"sans",M(e["title.weight"],600),M(e["title.spacing"],0))),...(e.sub?e.sub.split(`
16
+ `):[]).map(h=>ut(h,M(e["sub.size"],9),e["sub.font"]??"mono",400,0))],s=Math.max(0,...l);return{x:Math.max(t.x+8,t.x+(t.w-(n+8+s))/2),y:t.y+(t.h-n)/2,size:n,dx:(n+8)/2,dy:0}}var Ze=t=>!!t["icon.bg"]&&t["icon.bg"]!=="none";function ee(t,e,i,n,l){if(!Ze(e))return Ae(t,e,i,n,l);let s=M(e["icon.bg.size"],l+24),h=i+l/2,r=n+l/2,o=(p,d,x,u)=>e["icon.bg.shape"]==="circle"?`<circle cx="${$(h+d)}" cy="${$(r+x)}" r="${$(s/2+p)}" ${u}/>`:`<rect x="${$(h-s/2-p+d)}" y="${$(r-s/2-p+x)}" width="${$(s+p*2)}" height="${$(s+p*2)}" ${u}/>`,a="";if(e["icon.bg.shadow"]&&e["icon.bg.shadow"]!=="none"){let p=M(e["icon.bg.shadow.size"],8),d=M(e["icon.bg.shadow.dx"],0),x=M(e["icon.bg.shadow.dy"],3),u=E(t,e["icon.bg.shadow"]);for(let c=Lt;c>=1;c--)a+=o($(p*c/Lt),d,x,`fill="${u}" fill-opacity="${$(1/Lt)}"`)}return a+o(0,0,0,`fill="${E(t,e["icon.bg"])}"`)+Ae(t,e,i,n,l)}function Ae(t,e,i,n,l){let s=fe(t,e.icon)??e.icon,h=t.images.get(s);if(h)return Ye(h)?`<image x="${$(i)}" y="${$(n)}" width="${$(l)}" height="${$(l)}" href="${q(h)}"/>`:"";let r=E(t,e["icon.color"]??e["title.color"]??"ink"),o=e["icon.fill"]&&e["icon.fill"]!=="none"?E(t,e["icon.fill"]):null,a=M(e["icon.width"],0);if(Et(t,s)){let c=["solid","duotone"].includes(e["icon.style"])?e["icon.style"]:"outline",{tint:w,front:v}=ai(s,c,ri(a>0?a*256/l:void 0)),y=c==="duotone"?o??r:c==="outline"?o:null,m=y?w.map(U=>`<path d="${q(U)}" fill="${y}"${o?"":' fill-opacity="0.2"'}/>`).join(""):"";return`<g transform="translate(${$(i)} ${$(n)}) scale(${+(l/256).toFixed(5)})">${m}<g fill="${r}">${v.map(U=>`<path d="${q(U)}"/>`).join("")}</g></g>`}let p=$(l/24),d=o??"none",x=a>0?Math.min(a,8)/p:Math.max(1.5,1.2/p),u=(t.icons.get(s)??[]).map(c=>`<path d="${q(c)}"/>`).join("");return`<g transform="translate(${$(i)} ${$(n)}) scale(${p})" fill="${d}" stroke="${r}" stroke-width="${$(x)}" stroke-linecap="round" stroke-linejoin="round">${u}</g>`}function Ii(t,e){let i=e.p,n=Math.min(e.w,e.h),l=[],s={...i,"icon.fill":i.fill??i["icon.fill"]??"none","icon.color":i.stroke??i["icon.color"]??"ink","icon.width":i.sw??i["icon.width"]??""};i.icon&&i.icon!=="none"&&l.push(ee(t,s,e.x+(e.w-n)/2,e.y+(e.h-n)/2,n));let h=e.x+e.w/2,r=e.y+e.h+6;if(e.text){let o=rt(t,i,"title.",{font:"sans",size:11,weight:600,color:"ink"}),a=Math.round(o.size*1.17);(i["title.caps"]==="1"?e.text.toUpperCase():e.text).split(`
17
+ `).forEach(p=>{l.push(`<text x="${h}" y="${$(r+o.size*.86)}" text-anchor="middle" ${o.a}>${q(p)}</text>`),r+=a})}if(i.sub){let o=rt(t,i,"sub.",{font:"mono",size:9,weight:400,color:"muted"}),a=Math.round(o.size*1.3);r+=2,i.sub.split(`
18
+ `).forEach(p=>{l.push(`<text x="${h}" y="${$(r+o.size*.86)}" text-anchor="middle" ${o.a}>${q(p)}</text>`),r+=a})}return l.join(`
19
+ `)}function Fe(t,e){if(e.shape==="legend")return Fi(t,e);if(e.shape==="table")return _i(t,e);if(e.shape==="chart")return vi(t,e);if(e.shape==="icon")return Ii(t,e);let i=e.p,n=[],l=E(t,t.canvas.paper??"paper");n.push(...Ce(t,e)),!e.back&&i.mask!=="0"&&i.fill&&i.fill!=="none"&&n.push(Xt(e,`fill="${l}"`));let s=Si(t,i)??ji(t,i)??void 0,h=/^(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)$/.exec(i.offset??""),r=Rt(i);if(h||r){let A=h?Jt(e,+h[1],+h[2]):e;i.fill&&i.fill!=="none"&&n.push(kt(A,`fill="${E(t,i.fill)}" stroke="none"${r}`)),s&&n.push(kt(A,`fill="${s}" stroke="none"${r}`)),n.push(Xt(e,Yt(t,{...i,fill:"none"})))}else n.push(Xt(e,Yt(t,i),s));n.push(...Oe(t,e));let o=e.x+e.w/2,a=e.y+e.h/2;if(e.shape==="polygon"&&e.poly&&e.p.open!=="1"){let A=0,Q=0,G=0;e.poly.forEach((V,_)=>{let B=e.poly[(_+1)%e.poly.length],C=V.x*B.y-B.x*V.y;A+=C,Q+=(V.x+B.x)*C,G+=(V.y+B.y)*C}),Math.abs(A)>1&&(o=$(Q/(3*A)),a=$(G/(3*A)))}if(e.shape==="arc"&&Math.abs(M(i.to,360)-M(i.from,0))<360){let A=(M(i.from,0)+M(i.to,360))/2*(Math.PI/180),Q=M(i.inner,0),G=Q>0?(1+Q)/2:.62;o=$(o+e.w/2*G*Math.sin(A)),a=$(a-e.h/2*G*Math.cos(A))}if(i.ghost){let A=rt(t,i,"ghost.",{font:"mono",size:32,weight:600,color:"ink/0.06"});n.push(`<text x="${e.x+e.w-8}" y="${e.y+e.h-4}" text-anchor="end" ${A.a}>${q(i.ghost)}</text>`)}let p=rt(t,i,"title.",{font:"sans",size:12,weight:600,color:"ink"}),d=i.tag?Hi(e,t,Ri(e,p.size),p.size,a+(te(e)?.dy??0)):null,x=!!e.text&&i["title.pos"]==="top",u=i["title.dy"]!==void 0||i["title.fill"]!==void 0?Math.max(12,Math.ceil(p.size+4)):12,c=M(i["title.dy"],0)+4;d&&x&&(d={...d,x:12,y:c+Math.round((u-d.h)/2)});let w=x&&i["icon.pos"]==="corner"&&i.icon&&i.icon!=="none"?M(i["icon.size"],24)-4:0,v=(d&&x?Ht(t,i)+4:0)+w;if(d){let A=rt(t,i,"tag.",{font:"mono",size:7,weight:400,color:"muted"}),Q=Ht(t,i);n.push(`<rect x="${e.x+d.x}" y="${e.y+d.y}" width="${Q}" height="${d.h}" rx="2" fill="none" stroke="${E(t,i["tag.border"]??"muted/0.4")}" stroke-width="0.8"/>`),n.push(`<text x="${e.x+d.x+Q/2}" y="${$(e.y+d.y+d.h/2+A.size*.36)}" text-anchor="middle" ${A.a}>${q(i.tag)}</text>`)}let y=te(e);y&&(o+=y.dx,a+=y.dy);let m=M(i["icon.dx"],0),U=M(i["icon.dy"],0);if(y&&!(y.dy>0)&&n.push(ee(t,i,y.x+m,y.y+U,y.size)),e.text&&i["title.pos"]==="top"){let A=i["title.caps"]==="1"?e.text.toUpperCase():e.text,Q=Math.ceil(ci(t,A,p.size,p.font,p.weight,p.spacing)+12),G=i["title.align"],V=G==="left"?e.x+12+v+Q/2:G==="right"?e.x+e.w-12-Q/2:o,_=i["title.dy"]!==void 0||i["title.fill"]!==void 0,B=e.y+M(i["title.dy"],0),C=_?Math.max(12,Math.ceil(p.size+4)):12;if(i["title.fill"]!=="none"){let J=at=>`<rect x="${$(V-Q/2)}" y="${B+4}" width="${Q}" height="${C}" rx="2" fill="${at}"/>`;n.push(J(E(t,i["title.fill"]??t.canvas.paper??"paper"))),i["title.fill"]===void 0&&B+4>=e.y+M(i.sw,1)/2&&!i.offset&&!Rt(i)&&i.fill&&i.fill!=="none"&&n.push(J(E(t,i.fill)))}n.push(`<text x="${V}" y="${_?$(B+4+C/2+p.size*.36):e.y+13}" text-anchor="middle" ${p.a}>${q(A)}</text>`)}else if(e.text||i.sub){let A=e.text?(i["title.caps"]==="1"?e.text.toUpperCase():e.text).split(`
20
+ `):[],Q=Math.round(p.size*1.17),G=rt(t,i,"sub.",{font:"mono",size:9,weight:400,color:"muted"}),V=i.sub?i.sub.split(`
21
+ `):[],_=Math.round(G.size*1.3),B=A.length*Q+(V.length?G.size+7+(V.length-1)*_:0),C=d?d.top:a-B/2;if(y&&y.dy>0){let ht=y.room??y.size;n.push(ee(t,i,y.x+m,C-ht-6+(ht-y.size)/2+U,y.size))}let J=i["title.align"],at=J==="left"?y?.block?e.x+y.block+12:e.x+12+(y&&y.dx?y.size+8:0):J==="right"?e.x+e.w-12:o,dt=J==="left"?"start":J==="right"?"end":"middle";A.forEach((ht,Z)=>n.push(`<text x="${at}" y="${$(C+p.size*.86+Z*Q)}" text-anchor="${dt}" ${p.a}>${q(ht)}</text>`)),V.forEach((ht,Z)=>n.push(`<text x="${at}" y="${$(C+A.length*Q+G.size+3+Z*_)}" text-anchor="${dt}" ${G.a}>${q(ht)}</text>`))}return n.join(`
22
+ `)}function _e(t,e,i,n){let l=t.map(r=>({...r})),s=(r,o,a)=>{let p=l[o].x-l[r].x,d=l[o].y-l[r].y,x=Math.hypot(p,d);x>a+1&&(l[r].x+=p/x*a,l[r].y+=d/x*a)};i&&s(l.length-1,l.length-2,i),n&&s(0,1,n);let h=`M ${$(l[0].x)},${$(l[0].y)}`;for(let r=1;r<l.length;r++){let o=l[r],a=l[r-1],p=l[r+1];if(!p||!e){h+=` L ${$(o.x)},${$(o.y)}`;continue}let d=Math.hypot(o.x-a.x,o.y-a.y),x=Math.hypot(p.x-o.x,p.y-o.y),u=Math.min(e,d/2,x/2),c={x:o.x-(o.x-a.x)/d*u,y:o.y-(o.y-a.y)/d*u},w={x:o.x+(p.x-o.x)/x*u,y:o.y+(p.y-o.y)/x*u};h+=` L ${$(c.x)},${$(c.y)} Q ${o.x},${o.y} ${$(w.x)},${$(w.y)}`}return h}function Ri(t,e){let i=t.p,n=M(i["sub.size"],9),l=i.sub?i.sub.split(`
23
+ `).length:0;return(t.text?t.text.split(`
24
+ `).length:0)*Math.round(e*1.17)+(l?n+7+(l-1)*Math.round(n*1.3):0)}function Hi(t,e,i,n,l){let s=t.p,h=s.sketch==="0"?0:Math.max(0,Math.min(M(e.canvas.sketch,0),4)),r=8+(h?2:0),o=Math.max(12,Math.ceil(M(s["tag.size"],7)+4)),a=n*.14,p=Ti(t,r,Ht(e,s),o,6,3+h),d=(c,w)=>{let v=t.y+c+o+3-a,y=t.y+t.h-w-i;return{y:c,top:Math.min(Math.max(l-i/2+8,v),Math.max(y,l-i/2)),fits:v<=y+.5}},x=d(Math.max(8,p),4),u=x.fits?x:d(Math.max(6,p),2);if(!x.fits&&!u.fits){let c=Math.max(8,p),w=Math.min(l-i/2+8,Math.max(t.y+t.h-4-i,l-i/2));if(Gi(t,e,r+Ht(e,s),t.y+c-2,t.y+c+o+2,w))return{x:r,h:o,y:c,top:w,fits:!0}}return{x:r,h:o,...u.fits?u:x}}function Gi(t,e,i,n,l,s){let h=t.p;if(h["title.align"]||h.icon)return!1;let r=rt(e,h,"title.",{font:"sans",size:12,weight:600,color:"ink"}),o=rt(e,h,"sub.",{font:"mono",size:9,weight:400,color:"muted"}),a=t.text?(h["title.caps"]==="1"?t.text.toUpperCase():t.text).split(`
25
+ `):[],p=Math.round(r.size*1.17),d=Math.round(o.size*1.3),x=h.sub?h.sub.split(`
26
+ `):[];return[...a.map((u,c)=>({w:ut(u,r.size,r.font,r.weight,r.spacing),a:s+c*p+r.size*.14,b:s+c*p+r.size*1.05})),...x.map((u,c)=>{let w=s+a.length*p+o.size+3+c*d;return{w:ut(u,o.size,o.font,400,o.spacing),a:w-o.size*.75,b:w+o.size*.2}})].every(u=>u.b<n||u.a>l||t.w/2-u.w/2>=i+2)}function Ht(t,e){let i=rt(t,e,"tag.",{font:"mono",size:7,weight:400,color:"muted"});return Math.ceil((ut(e.tag??"",i.size,i.font,400,i.spacing)+12)/4)*4}var Pi=2e4;function Qi(t,e){let{w:i,h:n}=t,l=[],s=(h,r)=>{if(Math.max(h.x,r.x)<e.x0||Math.min(h.x,r.x)>e.x1||Math.max(h.y,r.y)<e.y0||Math.min(h.y,r.y)>e.y1)return;let o=Math.min(Pi,Math.max(1,Math.ceil(Math.hypot(r.x-h.x,r.y-h.y)/2)));for(let a=0;a<=o;a++){let p={x:h.x+(r.x-h.x)*a/o,y:h.y+(r.y-h.y)*a/o};p.x>=e.x0&&p.x<=e.x1&&p.y>=e.y0&&p.y<=e.y1&&l.push(p)}};if(t.shape==="ellipse"){for(let h=0;h<180;h++){let r=h/180*2*Math.PI;l.push({x:i/2+i/2*Math.cos(r),y:n/2+n/2*Math.sin(r)})}return l}if(t.shape==="diamond"){let h=[{x:i/2,y:0},{x:i,y:n/2},{x:i/2,y:n},{x:0,y:n/2}];return h.forEach((r,o)=>s(r,h[(o+1)%4])),l}if(t.shape==="polygon"&&t.poly){let h=t.poly.map(r=>({x:r.x-t.x,y:r.y-t.y}));return h.forEach((r,o)=>s(r,h[(o+1)%h.length])),l}if(t.shape==="path"&&t.p.path){let h=t.p.path.match(/[MLCZ]|-?\d*\.?\d+/gi)??[],r="M",o={x:0,y:0},a=o,p=0,d=()=>({x:+h[p++]*i,y:+h[p++]*n});for(;p<h.length;)if(/[a-z]/i.test(h[p]))r=h[p++].toUpperCase(),r==="Z"&&(s(o,a),o=a);else if(r==="M")o=a=d(),r="L";else if(r==="L"){let x=d();s(o,x),o=x}else if(r==="C"){let x=d(),u=d(),c=d(),w=o;for(let v=1;v<=24;v++){let y=v/24,m=1-y,U={x:m*m*m*o.x+3*m*m*y*x.x+3*m*y*y*u.x+y*y*y*c.x,y:m*m*m*o.y+3*m*m*y*x.y+3*m*y*y*u.y+y*y*y*c.y};s(w,U),w=U}o=c}else p++;return l}return null}var Vi=400;function Ti(t,e,i,n,l,s){let h=Math.min(t.h/2,l+Vi),r=Qi(t,{x0:e-s,x1:e+i+s,y0:l-s,y1:h+n+s});if(!r)return 0;for(let o=l;o<h;o++)if(!r.some(a=>a.x>e-s&&a.x<e+i+s&&a.y>o-s&&a.y<o+n+s))return o;return 0}function ie(t,e,i,n,l,s,h=1,r=l){let o=e.x-i.x,a=e.y-i.y,p=Math.hypot(o,a)||1,d=o/p,x=a/p,u=(U,A)=>`${$(e.x-d*U-x*A)},${$(e.y-x*U+d*A)}`,c=`fill="none" stroke="${l}" stroke-width="${n}" stroke-linecap="round" stroke-linejoin="round"`,w=`fill="${s}" stroke="${l}" stroke-width="${n}" stroke-linejoin="round"`,v=U=>`<path d="M ${u(U,6)} L ${u(U,-6)}" ${c}/>`,y=(U,A,Q)=>`<circle cx="${$(e.x-d*U)}" cy="${$(e.y-x*U)}" r="${A}" ${Q}/>`,m=`<path d="M ${u(0,6)} L ${u(12,0)} L ${u(0,-6)}" ${c}/>`;if(wt.amt&&(t==="arrow"||t==="open"))return{svg:jt(`M ${u(13,6)} L ${u(0,0)} L ${u(13,-6)}`,`fill="none" stroke="${l}" stroke-width="${n}"`,wt.amt*.6),trim:0};switch(t){case"none":return{svg:"",trim:0};case"open":return{svg:`<path d="M ${u(10*h,5*h)} L ${u(0,0)} L ${u(10*h,-5*h)}" ${c}/>`,trim:0};case"triangle":return{svg:`<polygon points="${u(0,0)} ${u(11*h,6*h)} ${u(11*h,-6*h)}" ${w}/>`,trim:11*h};case"stop":{let U=Math.max(4,n/2+3);return{svg:`<circle cx="${$(e.x)}" cy="${$(e.y)}" r="${U}" fill="${s}" stroke="${r}" stroke-width="${Math.max(2,$(n*.45))}"/>`,trim:0}}case"diamond":return{svg:`<polygon points="${u(0,0)} ${u(8,4.5)} ${u(16,0)} ${u(8,-4.5)}" ${w}/>`,trim:16};case"diamond-solid":return{svg:`<polygon points="${u(0,0)} ${u(8,4.5)} ${u(16,0)} ${u(8,-4.5)}" fill="${l}" stroke="${l}" stroke-width="${n}" stroke-linejoin="round"/>`,trim:16};case"dot":return{svg:y(3.5,3.5,`fill="${l}"`),trim:3.5};case"circle":return{svg:y(4,4,w),trim:8};case"one":return{svg:v(8),trim:0};case"only-one":return{svg:v(7)+v(12),trim:0};case"many":return{svg:m,trim:0};case"one-many":return{svg:m+v(16),trim:0};case"zero-one":return{svg:v(8)+y(16,4,w),trim:0};case"zero-many":return{svg:m+y(17,4,w),trim:0};default:return{svg:`<polygon points="${u(0,0)} ${u(10*h,4*h)} ${u(10*h,-4*h)}" fill="${l}"/>`,trim:7*h}}}function Ie(t,e){let i=e;for(let n=t.length-1;n>0;n--){let l=t[n],s=t[n-1],h=Math.hypot(l.x-s.x,l.y-s.y);if(h>=i)return{x:l.x+(s.x-l.x)/h*i,y:l.y+(s.y-l.y)/h*i};i-=h}return t[0]}function Re(t,e){if(!e)return t;let i=e;for(let n=t.length-1;n>0;n--){let l=t[n],s=t[n-1],h=Math.hypot(l.x-s.x,l.y-s.y);if(h>i)return[...t.slice(0,n),{x:l.x+(s.x-l.x)/h*i,y:l.y+(s.y-l.y)/h*i}];i-=h}return t.slice(0,2)}function He(t,e){if(e.pts.length<2)return"";let i=e.p,n=M(i.sw,1.2),l=E(t,i.stroke??"muted"),s=e.pts.length,h=E(t,t.canvas.paper??"paper"),r=e.curve?Ie(e.pts,10):e.pts[s-2],o=e.curve?Ie([...e.pts].reverse(),10):e.pts[1],a=Math.max(.5,Math.min(M(i["head.size"],1),4)),p=E(t,i["stop.color"]??i.stroke??"muted"),d=ie(e.headM,e.pts[s-1],r,n,l,h,a,p),x=ie(e.tailM,e.pts[0],o,n,l,h,a,p),u=e.curve?_e(Re([...Re(e.pts,d.trim)].reverse(),x.trim).reverse(),0,0,0):_e(e.pts,e.ortho?M(i.radius,8):0,d.trim,x.trim),c=i.cap==="round"?' stroke-linecap="round" stroke-linejoin="round"':"",w=`fill="none" stroke="${l}" stroke-width="${n}"${i.dash&&i.dash!=="none"?` stroke-dasharray="${q(i.dash)}"`:""}${c}${Rt(i)}`,v=Ut(i)?jt(u,w,Ut(i)):`<path d="${u}" ${w}/>`;return i.casing&&i.casing!=="none"&&(v=`<path d="${u}" fill="none" stroke="${E(t,i.casing)}" stroke-width="${$(n+2*M(i["casing.width"],2.5))}"${c}/>
27
+ `+v),i.double&&i.double!=="none"&&(v+=`
28
+ <path d="${u}" fill="none" stroke="${E(t,i.double)}" stroke-width="${M(i["double.sw"],$(n*.42))}"${c}/>`),d.svg&&(v+=`
29
+ `+d.svg),x.svg&&(v+=`
30
+ `+x.svg),v}function Ge(t,e){let i=e.label,n=E(t,t.canvas.paper??"paper"),l=e.p,s=E(t,l["label.color"]??l.stroke??"muted"),h=l["label.fill"]&&l["label.fill"]!=="none"||l["label.border"]&&l["label.border"]!=="none",r=h?M(l["label.pad"],3):0,o=M(l["label.radius"],2),a=l["label.border"]&&l["label.border"]!=="none"?` stroke="${E(t,l["label.border"])}" stroke-width="${M(l["label.sw"],1)}"`:"",p=M(l["label.weight"],400);return`<rect x="${$(i.x-r)}" y="${$(i.y-r/2)}" width="${i.w+r*2}" height="${i.h+r}" rx="${Math.min(o,(i.h+r)/2)}" fill="${h&&l["label.fill"]&&l["label.fill"]!=="none"?E(t,l["label.fill"]):n}"${a}/>
31
+ <text x="${$(i.cx)}" y="${$(i.baseline)}" text-anchor="middle" font-family="${Ee(t,i.font)}" font-size="${i.size}" fill="${s}"${p===400?"":` font-weight="${p}"`}${l["label.italic"]==="1"?' font-style="italic"':""}${i.spacing?` letter-spacing="${$(i.spacing*i.size)}"`:""}>${q(i.text)}</text>`}function Wi(t,e){let i=rt(t,e.p,"",{font:"sans",size:12,weight:400,color:"ink"}),n=e.p.anchor&&e.p.anchor!=="start"?` text-anchor="${q(e.p.anchor)}"`:"",l=M(e.p.rotate,0),s=e.text.split(`
32
+ `),h=Rt(e.p),r=s.map((o,a)=>`<text x="${e.ax}" y="${$(e.ay+a*i.size*1.3)}"${n} ${i.a}${h}>${q(o)}</text>`).join(`
33
+ `);if(e.p.echo&&e.p.echo!=="none"){let o=M(e.p["echo.dx"],3),a=M(e.p["echo.dy"],3),p=i.a.replace(/fill="[^"]*"/,()=>`fill="${E(t,e.p.echo)}"`);r=s.map((d,x)=>`<text x="${e.ax+o}" y="${$(e.ay+a+x*i.size*1.3)}"${n} ${p}>${q(d)}</text>`).join(`
34
+ `)+`
35
+ `+r}return l===90||l===-90?`<g transform="rotate(${l} ${e.ax} ${e.ay})">${r}</g>`:r}function Ct(t,e,i){let n=St(t,e),l=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);if(l){let r=l[1].length===3?l[1].replace(/./g,o=>o+o):l[1];return[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)]}if(l=/^rgba?\(([\d.]+),\s*([\d.]+),\s*([\d.]+)(?:,\s*([\d.]+))?\)$/.exec(n),!l)return null;let s=l[4]===void 0?1:+l[4],h=i??[255,255,255];return[0,1,2].map(r=>+l[r+1]*s+h[r]*(1-s))}function Gt(t,e){let i=s=>{let[h,r,o]=s.map(a=>(a/=255,a<=.03928?a/12.92:((a+.055)/1.055)**2.4));return .2126*h+.7152*r+.0722*o},n=i(t),l=i(e);return(Math.max(n,l)+.05)/(Math.min(n,l)+.05)}var Bi=1.8;function Di(t){let e=t.look,i=Ct(e,e.canvas.paper??"paper")??[255,255,255],n=a=>!a.rows&&a.shape!=="legend"&&a.shape!=="chart"&&a.shape!=="icon"&&!!a.p.fill&&a.p.fill!=="none",l=(a,p,d)=>{for(let x=d-1;x>=0;x--){let u=t.shapes[x];if(n(u)&&a>=u.x&&a<=u.x+u.w&&p>=u.y&&p<=u.y+u.h)return u}},s=(a,p)=>{if(!a||a.back||a.p.fill!==e.styles.get(a.style)?.props.fill)return;let d=Ct(e,a.p.fill,i),x=d&&Ct(e,p,d);if(!d||!x)return;let u=a.p["title.color"],c=u?Ct(e,u,d):null,w=!!c&&Gt(i,c)<2,v=Gt(d,x);if(!(v>=(w?4.5:Bi)))return[St(e,p)===St(e,"ink")?void 0:a.p["sub.color"],u,"paper","ink","#ffffff"].find(y=>{let m=y?Ct(e,y,d):null;return m&&Gt(d,m)>=3&&Gt(d,m)>v})},h=!1,r=t.texts.map(a=>{if(/\/0?\.[0-3]\d*$/.test(a.p.color??""))return a;let p=s(l(a.x+a.w/2,a.y+a.h/2,t.shapes.length),a.p.color??"ink");return p?(h=!0,{...a,p:{...a.p,color:p}}):a}),o=t.shapes.map((a,p)=>{if(a.back||!a.text||a.rows||!Kt(a)||a.shape==="icon"||a.shape==="legend"||a.shape==="chart"||a.p.fill&&a.p.fill!=="none"||a.p["title.pos"]==="top")return a;let d=s(l(a.x+a.w/2,a.y+a.h/2,p),a.p["title.color"]??"ink");return d?(h=!0,{...a,p:{...a.p,"title.color":d,...a.p.stroke&&a.p.stroke!=="none"?{stroke:/\/[0-9.]+$/.test(d)?d:d+"/0.6"}:{}}}):a});return h?{...t,texts:r,shapes:o}:t}function qi(t,e){if(t.curve||t.pts.length<2)return t;let i=t.pts.map(l=>({...l})),n=!1;for(let[l,s]of[[0,1],[i.length-1,i.length-2]]){let h=i[l],r=i[s];if(!(Math.abs(h.x-r.x)>.5||r.y<h.y))for(let o of e){let a=M(o.p.depth,0);if(a>0&&!o.back&&Math.abs(h.y-(o.y+o.h))<1&&h.x>o.x&&h.x<o.x+o.w&&r.y-h.y>a+6){h.y+=a,n=!0;break}}}return n?{...t,pts:i}:t}var Ji="font-variant-ligatures:none;text-rendering:geometricPrecision";function Ki(t,e=!0){t=Di(t);let i=t.look,n=i.canvas,l=[];if(wt={amt:Math.max(0,Math.min(M(n.sketch,0),4)),defs:new Map},e&&l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="${E(i,n.paper??"paper")}"/>`),e&&n.dots&&n.dots!=="none"){let o=M(n.dotgap,22);l.push(`<defs><pattern id="fd-dots" width="${o}" height="${o}" patternUnits="userSpaceOnUse"><circle cx="1" cy="1" r="0.9" fill="${E(i,n.dots)}"/></pattern></defs>`),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="url(#fd-dots)"/>`)}if(e&&n.grid&&n.grid!=="none"){let o=Math.max(4,M(n.gridgap,24));l.push(`<defs><pattern id="fd-grid" width="${o}" height="${o}" patternUnits="userSpaceOnUse"><path d="M ${o},0 H 0 V ${o}" fill="none" stroke="${E(i,n.grid)}" stroke-width="1"/></pattern></defs>`),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="url(#fd-grid)"/>`)}if(e&&n.lines&&n.lines!=="none"){let o=Math.max(4,M(n.linegap,24));l.push(`<defs><pattern id="fd-lines" width="${o}" height="${o}" patternUnits="userSpaceOnUse"><rect y="${o-1}" width="${o}" height="1" fill="${E(i,n.lines)}"/></pattern></defs>`),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="url(#fd-lines)"/>`)}if(e&&n.cross&&n.cross!=="none"){let o=Math.max(8,M(n.crossgap,24)),a=o/2;l.push(`<defs><pattern id="fd-cross" x="${-a}" y="${-a}" width="${o}" height="${o}" patternUnits="userSpaceOnUse"><path d="M ${a-3},${a} H ${a+3} M ${a},${a-3} V ${a+3}" fill="none" stroke="${E(i,n.cross)}" stroke-width="1"/></pattern></defs>`),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="url(#fd-cross)"/>`)}if(e&&n.iso&&n.iso!=="none"){let o=Math.max(4,M(n.isogap,24)),a=Math.round(o*Math.sqrt(3)*100)/100;l.push(`<defs><pattern id="fd-iso" width="${o}" height="${a}" patternUnits="userSpaceOnUse"><circle cx="${o/4}" cy="${a/4}" r="0.9" fill="${E(i,n.iso)}"/><circle cx="${o*3/4}" cy="${a*3/4}" r="0.9" fill="${E(i,n.iso)}"/></pattern></defs>`),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="url(#fd-iso)"/>`)}if(e&&n.diag&&n.diag!=="none"){let o=Math.max(4,M(n.diaggap,12));l.push(`<defs><pattern id="fd-diag" width="${o}" height="${o}" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="1" height="${o}" fill="${E(i,n.diag)}"/></pattern></defs>`),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="url(#fd-diag)"/>`)}if(e&&n.graph&&n.graph!=="none"){let o=Math.max(4,M(n.graphgap,10)),a=o*5,p=E(i,n.graph),d=[1,2,3,4].map(x=>`M ${x*o},0 V ${a} M 0,${x*o} H ${a}`).join(" ");l.push(`<defs><pattern id="fd-graph" width="${a}" height="${a}" patternUnits="userSpaceOnUse"><path d="${d}" fill="none" stroke="${p}" stroke-width="0.5" stroke-opacity="0.6"/><path d="M 0,0.5 H ${a} M 0.5,0 V ${a}" fill="none" stroke="${p}" stroke-width="1"/></pattern></defs>`),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="url(#fd-graph)"/>`)}if(e&&n.hex&&n.hex!=="none"){let o=Math.max(4,M(n.hexgap,14)),a=Math.round(o*Math.sqrt(3)*100)/100,p=a/2,d=`M ${p},0 V ${o/2} L ${a},${o} V ${o*2} L ${p},${o*2.5} V ${o*3} M ${p},${o*2.5} L 0,${o*2} V ${o} L ${p},${o/2}`;l.push(`<defs><pattern id="fd-hex" width="${a}" height="${o*3}" patternUnits="userSpaceOnUse"><path d="${d}" fill="none" stroke="${E(i,n.hex)}" stroke-width="1"/></pattern></defs>`),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="url(#fd-hex)"/>`)}if(e&&n.bars&&n.bars!=="none"){let o=Math.max(8,M(n.bargap,32));l.push(`<defs><pattern id="fd-bars" width="${o*2}" height="${o*2}" patternUnits="userSpaceOnUse"><rect width="${o*2}" height="${o}" fill="${E(i,n.bars)}"/></pattern></defs>`),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="url(#fd-bars)"/>`)}if(e&&n.feed&&n.feed!=="none"){let o=E(i,n.feed),a=E(i,n.paper??"paper"),p=(d,x)=>`<pattern id="${d}" x="${x}" y="0" width="26" height="24" patternUnits="userSpaceOnUse"><circle cx="13" cy="12" r="4.2" fill="${a}" stroke="${o}" stroke-width="1"/></pattern>`;l.push(`<defs>${p("fd-feed-l",t.x)}${p("fd-feed-r",t.x+t.w-26)}</defs>`),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="26" height="${t.h}" fill="url(#fd-feed-l)"/><rect class="fd-page" x="${t.x+t.w-26}" y="${t.y}" width="26" height="${t.h}" fill="url(#fd-feed-r)"/>`),l.push(`<path class="fd-page" d="M ${t.x+26},${t.y} v ${t.h} M ${t.x+t.w-26},${t.y} v ${t.h}" stroke="${o}" stroke-width="1" stroke-dasharray="2 3" fill="none"/>`)}for(let o of t.shapes)o.back&&l.push(Fe(i,o));let s=t.shapes.some(o=>M(o.p.depth,0)>0)?t.conns.map(o=>qi(o,t.shapes)):t.conns,h=s.filter(o=>o.p.layer!=="front"),r=s.filter(o=>o.p.layer==="front");for(let o of h)l.push(He(i,o));for(let o of h)o.label&&l.push(Ge(i,o));for(let o of t.shapes)o.back||l.push(Fe(i,o));for(let o of r)l.push(He(i,o));for(let o of r)o.label&&l.push(Ge(i,o));for(let o of t.texts)l.push(Wi(i,o));return e&&M(n.grain,0)>0&&(l.push('<defs><filter id="fd-grain" x="0" y="0" width="100%" height="100%"><feTurbulence type="fractalNoise" baseFrequency="1.1" numOctaves="2" seed="4"/><feColorMatrix values="0 0 0 0 .25 0 0 0 0 .22 0 0 0 0 .2 0 0 0 .5 -.2"/></filter></defs>'),l.push(`<rect class="fd-page" x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" filter="url(#fd-grain)" opacity="${Math.min(1,M(n.grain,0))}" pointer-events="none"/>`)),wt.defs.size&&l.splice(1,0,`<defs>${Ui()}</defs>`),Yi([`<g style="${Ji}">`,...l,"</g>"].join(`
36
+ `))}var Yi=t=>t.replace(/<text\b([^>]*)>([^<]*)<\/text>/g,(e,i,n)=>/^ | $| {2}/.test(n)&&!/[\n\t]/.test(n)&&!/xml:space|style=/.test(i)?`<text xml:space="preserve" style="white-space:pre"${i}>${n}</text>`:e);function Xi(t,e,i={}){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${t.x} ${t.y} ${t.w} ${t.h}" width="${t.w}" height="${t.h}">
37
+ `+(e?`<style>${e.replace(/&/g,"&amp;").replace(/</g,"&lt;")}</style>
38
+ `:"")+Ki(t,i.background??!0)+`
39
+ </svg>`}var ne=[["Geist","400","normal","Geist-Regular.ttf"],["Geist","500","normal","Geist-Medium.ttf"],["Geist","600","normal","Geist-SemiBold.ttf"],["Geist","700","normal","Geist-Bold.ttf"],["Geist Mono","400","normal","GeistMono-Regular.ttf"],["Geist Mono","500","normal","GeistMono-Medium.ttf"],["Newsreader","400","normal","Newsreader-Regular.ttf"],["Newsreader","500","normal","Newsreader-Medium.ttf"],["Newsreader","600","normal","Newsreader-SemiBold.ttf"],["Newsreader","400","italic","Newsreader-Italic.ttf"],["Libre Franklin","400","normal","LibreFranklin-Regular.ttf"],["Libre Franklin","500","normal","LibreFranklin-Medium.ttf"],["Libre Franklin","600","normal","LibreFranklin-SemiBold.ttf"],["Libre Franklin","700","normal","LibreFranklin-Bold.ttf"],["Instrument Serif","400","normal","InstrumentSerif-Regular.ttf"],["Instrument Serif","400","italic","InstrumentSerif-Italic.ttf"],["Sketch Hand","400","normal","SketchHand-Regular.ttf"]];ne.map(t=>t[3]);function tn(t,e){let i=new Set;for(let[,n]of t.matchAll(/font-family="([^"]*)"/g)){let l=n.split(",").map(s=>s.trim().replace(/^'|'$/g,"")).find(e);l&&i.add(l)}return i}var en=t=>t.iconUrls.size>0||t.iconDirs.some($e);function nn(t,e){let i=[],n=t.iconUrls.get(e);n&&i.push(n);for(let l of t.iconDirs)$e(l)&&i.push(l.includes("{name}")?l.replaceAll("{name}",e):`${l.replace(/\/+$/,"")}/${e}.svg`);return i}function ln(t){let e=t.toLowerCase().replace(/^\[|\]$/g,"").replace(/\.+$/,"");if(e==="localhost"||e.endsWith(".localhost")||e.endsWith(".local")||e.endsWith(".internal")||!e.includes(".")&&!e.includes(":"))return!0;let i=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(e);if(i){let[n,l]=[Number(i[1]),Number(i[2])];return n===0||n===10||n===127||n===169&&l===254||n===172&&l>=16&&l<=31||n===192&&l===168||n===100&&l>=64&&l<=127||n>=224}return e.includes(":")&&(e==="::"||e==="::1"||/^f[cd]/.test(e)||/^fe[89ab]/.test(e)||e.startsWith("::ffff:")||/^::[0-9a-f.:]*$/.test(e)||e.startsWith("64:ff9b:"))}function Pe(t){try{let e=new URL(t);return e.protocol==="https:"&&!ln(e.hostname)}catch{return!1}}var on=async(t,e)=>{if(!Pe(t))throw Error("not a public https address");let i=new URL(t),n=await fetch(i,{credentials:"omit",referrerPolicy:"no-referrer",redirect:"error",signal:AbortSignal.timeout(15e3)});if(n.status===404||n.status===410)return null;if(!n.ok)throw Error(`${n.status} ${n.statusText}`.trim());if(Number(n.headers.get("content-length"))>e)throw Error("file too large");let l=[],s=0,h=n.body.getReader();for(;;){let{done:a,value:p}=await h.read();if(a)break;if(s+=p.length,s>e)throw await h.cancel(),Error("file too large");l.push(p)}let r=new Uint8Array(s),o=0;for(let a of l)r.set(a,o),o+=a.length;return r},Qe=new WeakMap;function rn(t,e,i){let n=Qe.get(t);n||Qe.set(t,n=new Map);let l=n.get(e);return l||(l=t(e,i),n.set(e,l),l.catch(()=>n.delete(e))),l}var an=t=>{try{return new URL(t).host}catch{return"an address in the look"}};async function sn(t,e,i=on){let n=[...new Set(e)].filter(h=>/^[a-z0-9-]{1,80}$/.test(h)&&!t.images.has(h)&&!(t.icons.has(h)&&!Et(t,h))),l={},s=new Set;return await Promise.all(n.slice(0,300).map(async h=>{for(let r of nn(t,h))try{let o=await rn(i,r,ni),a=o&&qe(o);if(a){l[h]=a;return}}catch{s.add(an(r));return}})),{uris:l,done:s.size===0,unreachable:[...s]}}var hn=[400,500,600,700];function pn(t){let e=[];for(let[i,n]of t.fontUrls){if(!/^[\w .-]{1,64}$/.test(i))continue;let l=(h,r)=>n.replaceAll("{weight}",String(h)).replaceAll("{style}",r),s=(h,r)=>{let o=l(h||400,r);Pe(o)&&e.push({family:i,weight:h,style:r,url:o})};if(!n.includes("{weight}"))s(0,"normal");else{for(let h of hn)s(h,"normal");n.includes("{style}")&&s(400,"italic")}}return e}function dn(t){let e=new Set([400]);for(let[,i]of t.matchAll(/font-weight="(\d+)"/g))e.add(Number(i));return e}async function le(t){let e=await fetch(t);if(!e.ok)throw Error(`${t}: ${e.status} ${e.statusText}`);let i=await e.text();if(/^\s*</.test(i))throw Error(`${t}: not a FastDraw file (it starts with "<")`);return i}async function fn(t){let e=await le(t),i=be(e);if(!i||Qt(i))return{url:t,text:e,look:null};let n=new URL(i,t).href;return{url:t,text:e,look:{url:n,path:i,text:await le(n)}}}async function $n(t,e,i){let n=t.text,l=t.look?.text??null;if(e){let p=be(n),d=p?Qt(p)?he(p):l===null?null:se(l):de(),x=We(p,d);if(x&&Qt(x))n=ve(n,x),l=null;else if(x)try{l=await le(new URL(x,t.look?.url??t.url).href),n=ve(n,x)}catch(u){console.warn("fastdraw-diagram: the dark look could not be read, so the diagram keeps its own",u)}}let s=l===null?null:se(l),h=()=>ki(n,s),r=h();if(!ii()&&r.issues.some(p=>p.msg.startsWith("there is no icon called"))&&(await Je(),r=h()),s&&en(s)){let p=await sn(s,r.shapes.map(d=>d.p.icon).filter(Boolean));for(let d of p.unreachable)console.warn(`fastdraw-diagram: ${d} could not be reached for the look's icons, so the closest built-in ones are drawn`);s=ei(s,[],p.uris,p.done),r=h()}let o=r.issues.filter(p=>p.level==="error");if(o.length)throw Error(`${t.url} has errors:
40
+ ${o.map(p=>` line ${p.line}: ${p.msg}`).join(`
41
+ `)}`);let a=Xi(r);return await xn(a,i,r.look),{svg:a,paper:St(r.look,r.look.canvas.paper??"paper"),x:r.x,y:r.y,w:r.w,h:r.h}}var oe=new Map;async function xn(t,e,i){let n=pn(i),l=dn(t),s=/font-style="italic"/.test(t),h=tn(t,o=>ne.some(a=>a[0]===o)||n.some(a=>a.family===o)),r=[...ne.filter(o=>h.has(o[0])).map(o=>[o[0],o[1],o[2],new URL(o[3],e).href]),...n.filter(o=>h.has(o.family)&&(!o.weight||l.has(o.weight))&&(o.style==="normal"||s)).map(o=>[o.family,o.weight?String(o.weight):"100 900",o.style,o.url])];await Promise.all(r.map(o=>{let a=o[3];if(!oe.has(a)){let p=new FontFace(o[0],`url(${JSON.stringify(a)})`,{weight:o[1],style:o[2]});document.fonts.add(p),oe.set(a,p.load().catch(d=>console.warn(`fastdraw-diagram: font ${a} did not load`,d)))}return oe.get(a)}))}export{$n as draw,fn as fetchSource};