2024-09-17 12:23:11 +08:00
|
|
|
import{_ as o,j as T,l as L,d as N,T as A,al as ct,am as U,U as lt,i as J}from"./index-DG3lcEeB.js";function X(l,t){t&&l.attr("style",t)}o(X,"applyStyle");function Z(l){const t=T(document.createElementNS("http://www.w3.org/2000/svg","foreignObject")),c=t.append("xhtml:div"),e=l.label,s=l.isNode?"nodeLabel":"edgeLabel",r=c.append("span");return r.html(e),X(r,l.labelStyle),r.attr("class",s),X(c,l.labelStyle),c.style("display","inline-block"),c.style("white-space","nowrap"),c.attr("xmlns","http://www.w3.org/1999/xhtml"),t.node()}o(Z,"addHtmlLabel");var nt=o((l,t,c,e)=>{let s=l||"";if(typeof s=="object"&&(s=s[0]),A(N().flowchart.htmlLabels)){s=s.replace(/\\n|\n/g,"<br />"),L.debug("vertexText"+s);const r={isNode:e,label:ct(U(s)),labelStyle:t.replace("fill:","color:")};return Z(r)}else{const r=document.createElementNS("http://www.w3.org/2000/svg","text");r.setAttribute("style",t.replace("color:","fill:"));let a=[];typeof s=="string"?a=s.split(/\\n|\n|<br\s*\/?>/gi):Array.isArray(s)?a=s:a=[];for(const i of a){const n=document.createElementNS("http://www.w3.org/2000/svg","tspan");n.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:space","preserve"),n.setAttribute("dy","1em"),n.setAttribute("x","0"),c?n.setAttribute("class","title-row"):n.setAttribute("class","row"),n.textContent=i.trim(),r.appendChild(n)}return r}},"createLabel"),R=nt,_=o(async(l,t,c,e)=>{const s=N();let r;const a=t.useHtmlLabels||A(s.flowchart.htmlLabels);c?r=c:r="node default";const i=l.insert("g").attr("class",r).attr("id",t.domId||t.id),n=i.insert("g").attr("class","label").attr("style",t.labelStyle);let y;t.labelText===void 0?y="":y=typeof t.labelText=="string"?t.labelText:t.labelText[0];const h=n.node();let x;t.labelType==="markdown"?x=lt(n,J(U(y),s),{useHtmlLabels:a,width:t.width||s.flowchart.wrappingWidth,classes:"markdown-node-label"},s):x=h.appendChild(R(J(U(y),s),t.labelStyle,!1,e));let f=x.getBBox();const g=t.padding/2;if(A(s.flowchart.htmlLabels)){const d=x.children[0],m=T(x),p=d.getElementsByTagName("img");if(p){const C=y.replace(/<img[^>]*>/g,"").trim()==="";await Promise.all([...p].map(S=>new Promise(D=>{function B(){if(S.style.display="flex",S.style.flexDirection="column",C){const j=s.fontSize?s.fontSize:window.getComputedStyle(document.body).fontSize,F=parseInt(j,10)*5+"px";S.style.minWidth=F,S.style.maxWidth=F}else S.style.width="100%";D(S)}o(B,"setupImage"),setTimeout(()=>{S.complete&&B()}),S.addEventListener("error",B),S.addEventListener("load",B)})))}f=d.getBoundingClientRect(),m.attr("width",f.width),m.attr("height",f.height)}return a?n.attr("transform","translate("+-f.width/2+", "+-f.height/2+")"):n.attr("transform","translate(0, "+-f.height/2+")"),t.centerLabel&&n.attr("transform","translate("+-f.width/2+", "+-f.height/2+")"),n.insert("rect",":first-child"),{shapeSvg:i,bbox:f,halfPadding:g,label:n}},"labelHelper"),w=o((l,t)=>{const c=t.node().getBBox();l.width=c.width,l.height=c.height},"updateNodeBounds");function E(l,t,c,e){return l.insert("polygon",":first-child").attr("points",e.map(function(s){return s.x+","+s.y}).join(" ")).attr("class","label-container").attr("transform","translate("+-t/2+","+c/2+")")}o(E,"insertPolygonShape");var ht=o(l=>{const t=new Set;for(const c of l)switch(c){case"x":t.add("right"),t.add("left");break;case"y":t.add("up"),t.add("down");break;default:t.add(c);break}return t},"expandAndDeduplicateDirections"),ot=o((l,t,c)=>{const e=ht(l),s=2,r=t.height+2*c.padding,a=r/s,i=t.width+2*a+c.padding,n=c.padding/2;return e.has("right")&&e.has("left")&&e.has("up")&&e.has("down")?[{x:0,y:0},{x:a,y:0},{x:i/2,y:2*n},{x:i-a,y:0},{x:i,y:0},{x:i,y:-r/3},{x:i+2*n,y:-r/2},{x:i,y:-2*r/3},{x:i,y:-r},{x:i-a,y:-r},{x:i/2,y:-r-2*n},{x:a,y:-r},{x:0,y:-r},{x:0,y:-2*r/3},{x:-2*n,y:-r/2},{x:0,y:-r/3}]:e.has("right")&&e.has("left")&&e.has("up")?[{x:a,y:0},{x:i-a,y:0},{x:i,y:-r/2},{x:i-a,y:-r},{x:a,y:-r},{x:0,y:-r/2}]:e.has("right")&&e.has("left")&&e.has("down")?[{x:0,y:0},{x:a,y:-r},{x:i-a,y:-r},{x:i,y:0}]:e.has("right")&&e.has("up")&&e.has("down")?[{x:0,y:0},{x:i,y:-a},{x:i,y:-r+a},{x:0,y:-r}]:e.has("left")&&e.has("up")&&e.
|