UNPKG

mermaid

Version:

Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.

2 lines (1 loc) • 5.63 kB
import{c as R,g as O}from"./chunk-MTL3NAOM.mjs";import{a as m}from"./chunk-V3YWWTDH.mjs";var I=1e-5,J=2,N=.6;function F(t){return t===!1?!1:t==="gap"?"gap":"arc"}m(F,"normalizeLineHops");var $=1e-6;function w(t){let n=[];for(let s=0;s<t.length-1;s++)n.push({a:t[s],b:t[s+1]});return n}m(w,"buildSegmentList");function T(t,n,s,c){let i=n.x-t.x,r=n.y-t.y,u=c.x-s.x,f=c.y-s.y,l=i*f-r*u;if(l===0)return null;let o=s.x-t.x,e=s.y-t.y,a=(o*f-e*u)/l,d=(o*r-e*i)/l;return a<=$||a>=1-$||d<=$||d>=1-$?null:{point:{x:t.x+a*i,y:t.y+a*r},tA:a,tB:d}}m(T,"segmentIntersection");function B(t){return Math.abs(t.b.x-t.a.x)>=Math.abs(t.b.y-t.a.y)}m(B,"isHorizontalSeg");function G(t,n,s){if(t.curve!=="rounded")return!1;let c=t.points,i=c[n],r=c[n+1];if(!i||!r)return!1;let u=Math.hypot(r.x-i.x,r.y-i.y),f=s*u,l=O(t.cornerRadius),o=n>0?C(c[n-1],i,r,l):null;if(o&&f<o.cutLen)return!0;let e=n+2<c.length?C(i,r,c[n+2],l):null;return e!==null&&u-f<e.cutLen}m(G,"crossingSitsInRoundedCorner");function k(t){let n=[];for(let s=0;s<t.length;s++){let c=t[s],i=w(c.points);for(let r=s+1;r<t.length;r++){let u=t[r],f=w(u.points);for(let[l,o]of i.entries())for(let[e,a]of f.entries()){let d=T(o.a,o.b,a.a,a.b);if(!d||G(c,l,d.tA)||G(u,e,d.tB))continue;let g=B(o),S=B(a);(g!==S?g:!1)?n.push({jumpEdgeId:c.id,otherEdgeId:u.id,segIndex:l,t:d.tA,point:d.point}):n.push({jumpEdgeId:u.id,otherEdgeId:c.id,segIndex:e,t:d.tB,point:d.point})}}}return n}m(k,"findEdgeIntersections");function E(t){let n=Math.round(t*1e3)/1e3;return Number.isInteger(n)?`${n}`:`${n}`}m(E,"fmt");function A(t){return`${E(t.x)},${E(t.y)}`}m(A,"pointToString");function D(t){let n=t.b.x-t.a.x,s=t.b.y-t.a.y;return Math.abs(n)>=Math.abs(s)?n>=0?1:0:s>=0?1:0}m(D,"getArcSweepFlag");function X(t,n){if(t.length<2)return t.map(r=>({...r}));let s=t.map(r=>({...r})),c=n.arrowTypeStart&&R[n.arrowTypeStart];if(c){let r=t[0],u=t[1],f=Math.atan2(u.y-r.y,u.x-r.x);s[0].x=r.x+c*Math.cos(f),s[0].y=r.y+c*Math.sin(f)}let i=n.arrowTypeEnd&&R[n.arrowTypeEnd];if(i){let r=t.length,u=t[r-2],f=t[r-1],l=Math.atan2(f.y-u.y,f.x-u.x);s[r-1].x=f.x-i*Math.cos(l),s[r-1].y=f.y-i*Math.sin(l)}return s}m(X,"applyMarkerOffsets");function Y(t,n,s,c,i){let r=t.point.x,u=t.point.y,f={x:r-n*t.r,y:u-s*t.r},l={x:r+n*t.r,y:u+s*t.r},o=[`L${A(f)}`];return i==="arc"?o.push(`A${E(t.r)},${E(t.r)} 0 0 ${c} ${A(l)}`):o.push(`M${A(l)}`),o}m(Y,"emitJump");function C(t,n,s,c){let i=n.x-t.x,r=n.y-t.y,u=s.x-n.x,f=s.y-n.y,l=Math.hypot(i,r),o=Math.hypot(u,f);if(l<I||o<I)return null;let e=i/l,a=r/l,d=u/o,g=f/o,S=e*d+a*g,M=Math.max(-1,Math.min(1,S)),x=Math.acos(M);if(x<I||Math.abs(Math.PI-x)<I)return null;let y=Math.min(c/Math.sin(x/2),l/2,o/2);return{startX:n.x-e*y,startY:n.y-a*y,endX:n.x+d*y,endY:n.y+g*y,ctrlX:n.x,ctrlY:n.y,cutLen:y}}m(C,"computeRoundedCorner");function _(t,n,s){let c=t.points;if(c.length<2)return"";let i=X(c,t),r=t.curve==="rounded",u=O(t.cornerRadius),f=w(i),l=new Map;for(let e of n){let a=f[e.segIndex];if(!a)continue;let d=Math.hypot(a.b.x-a.a.x,a.b.y-a.a.y),g=l.get(e.segIndex)??[];g.push({t:e.t,point:e.point,d:e.t*d,r:s.jumpRadius}),l.set(e.segIndex,g)}let o=[`M${A(i[0])}`];for(let e=0;e<f.length;e++){let a=f[e],d=Math.hypot(a.b.x-a.a.x,a.b.y-a.a.y),g=d===0?0:(a.b.x-a.a.x)/d,S=d===0?0:(a.b.y-a.a.y)/d,M=D(a),x=0;if(r&&e>0){let p=C(i[e-1],i[e],i[e+1]??i[e],u);p&&(x=p.cutLen)}let y=d,h=null;r&&e<f.length-1&&(h=C(i[e],i[e+1],i[e+2]??i[e+1],u),h&&(y=d-h.cutLen));let L=s.jumpRadius*N,b=[...l.get(e)??[]].sort((p,P)=>p.t-P.t).filter(p=>{let P=Math.min(p.d-x,y-p.d)-J;return p.r=Math.min(p.r,P),p.r>=L});for(let p=0;p<b.length-1;p++){let P=b[p+1].d-b[p].d;if(b[p].r+b[p+1].r>P){let j=P/2;b[p].r=Math.min(b[p].r,j),b[p+1].r=Math.min(b[p+1].r,j)}}for(let p of b)p.r<L||o.push(...Y(p,g,S,M,s.jumpStyle));r&&h?(o.push(`L${E(h.startX)},${E(h.startY)}`),o.push(`Q${E(h.ctrlX)},${E(h.ctrlY)} ${E(h.endX)},${E(h.endY)}`)):o.push(`L${A(a.b)}`)}return o.join(" ")}m(_,"rewriteEdgePath");function H(t){return/^[\d\s+,.LMelm-]*$/.test(t)}m(H,"isStraightPath");function v(t){return t?t==="linear"||t==="rounded"||t==="step"||t==="stepBefore"||t==="stepAfter":!0}m(v,"curveSupportsLineHops");function U(t){if(!t)return null;try{let n=typeof atob=="function"?atob(t):Buffer.from(t,"base64").toString(),s=JSON.parse(n);if(!Array.isArray(s))return null;let c=[];for(let i of s)i&&typeof i.x=="number"&&typeof i.y=="number"&&c.push({x:i.x,y:i.y});return c.length>=2?c:null}catch{return null}}m(U,"decodeDataPoints");function q(t,n,s){if(!s.enabled)return;let c=t.node();if(!c)return;let i=new Map;for(let o of n)i.set(o.id,o);let r=new Map;for(let o of c.querySelectorAll("path[data-id]")){let e=o.getAttribute("data-id");e!==null&&!r.has(e)&&r.set(e,o)}let u=[];for(let o of n){let e=r.get(o.id);if(!e)continue;let d=U(e.getAttribute("data-points"))??o.points;u.push({...o,points:d})}let f=k(u);if(f.length===0)return;let l=new Map;for(let o of f){let e=l.get(o.jumpEdgeId)??[];e.push(o),l.set(o.jumpEdgeId,e)}for(let o of u){let e=l.get(o.id);if(!e||e.length===0)continue;let d=i.get(o.id)?.curve;if(d!==void 0&&!v(d))continue;let g=r.get(o.id);if(!g)continue;if(d===void 0){let L=g.getAttribute("d")??"";if(!H(L))continue}let S=g.getAttribute("style")??"",M=/stroke-dasharray\s*:\s*0\s+([\d.]+)\s+[\d.]+\s+([\d.]+)/.exec(S),x=M?Number.parseFloat(M[1]):null,y=M?Number.parseFloat(M[2]):null,h=_(o,e,s);if(g.setAttribute("d",h),x!==null&&y!==null&&typeof g.getTotalLength=="function"){let L=g.getTotalLength(),b=Math.max(0,L-x-y),p=`0 ${x} ${b} ${y}`,P=S.replace(/stroke-dasharray\s*:[^;]*;?/g,`stroke-dasharray: ${p};`).replace(/;\s*;+/g,";");g.setAttribute("style",P)}}}m(q,"applyLineJumpsToSvg");export{F as a,q as b};