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