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