UNPKG

code-server

Version:

Run VS Code on a remote server.

2 lines (1 loc) • 11.4 kB
var Z=Object.defineProperty,g=(t,i)=>Z(t,"name",{value:i,configurable:!0}),D=class{static{g(this,"Tree")}constructor(t,i,s,o){this.w=t,this.h=i,this.y=s,this.c=o,this.cs=o.length,this.x=0,this.prelim=0,this.mod=0,this.shift=0,this.change=0,this.tl=null,this.tr=null,this.el=null,this.er=null,this.msel=0,this.mser=0}};function C(t){t.cs===0?(t.el=t,t.er=t,t.msel=t.mser=0):(t.el=t.c[0].el,t.msel=t.c[0].msel,t.er=t.c[t.cs-1].er,t.mser=t.c[t.cs-1].mser)}g(C,"setExtremes");function B(t){return t.y+t.h}g(B,"bottom");var P=class{static{g(this,"IYL")}constructor(t,i,s){this.lowY=t,this.index=i,this.next=s}};function I(t,i,s){for(;s!==null&&t>=s.lowY;)s=s.next;return new P(t,i,s)}g(I,"updateIYL");function $(t,i,s,o){if(s!==i-1){let n=i-s;t.c[s+1].shift+=o/n,t.c[i].shift-=o/n,t.c[i].change-=o-o/n}}g($,"distributeExtra");function q(t,i,s,o){t.c[i].mod+=o,t.c[i].msel+=o,t.c[i].mser+=o,$(t,i,s,o)}g(q,"moveSubtree");function H(t){return t.cs===0?t.tl:t.c[0]}g(H,"nextLeftContour");function O(t){return t.cs===0?t.tr:t.c[t.cs-1]}g(O,"nextRightContour");function k(t,i,s,o){let n=t.c[0].el;n.tl=s;let e=o-s.mod-t.c[0].msel;n.mod+=e,n.prelim-=e,t.c[0].el=t.c[i].el,t.c[0].msel=t.c[i].msel}g(k,"setLeftThread");function F(t,i,s,o){let n=t.c[i].er;n.tr=s;let e=o-s.mod-t.c[i].mser;n.mod+=e,n.prelim-=e,t.c[i].er=t.c[i-1].er,t.c[i].mser=t.c[i-1].mser}g(F,"setRightThread");function j(t,i,s){let o=t.c[i-1],n=o.mod,e=t.c[i],h=e.mod;for(;o!==null&&e!==null;){B(o)>s.lowY&&(s=s.next);let r=n+o.prelim+o.w-(h+e.prelim);r>0&&(h+=r,q(t,i,s.index,r));let d=B(o),m=B(e);d<=m&&(o=O(o),o!==null&&(n+=o.mod)),d>=m&&(e=H(e),e!==null&&(h+=e.mod))}o===null&&e!==null?k(t,i,e,h):o!==null&&e===null&&F(t,i,o,n)}g(j,"seperate");function z(t){t.prelim=(t.c[0].prelim+t.c[0].mod+t.c[t.cs-1].mod+t.c[t.cs-1].prelim+t.c[t.cs-1].w)/2-t.w/2}g(z,"positionRoot");function Y(t){if(t.cs===0){C(t);return}Y(t.c[0]);let i=I(B(t.c[0].el),0,null);for(let s=1;s<t.cs;s++){Y(t.c[s]);let o=B(t.c[s].er);j(t,s,i),i=I(o,s,i)}z(t),C(t)}g(Y,"firstWalk");function G(t){let i=0,s=0;for(let o=0;o<t.cs;o++)i+=t.c[o].shift,s+=i+t.c[o].change,t.c[o].mod+=s}g(G,"addChildSpacing");function W(t,i){i+=t.mod,t.x=t.prelim+i,G(t);for(let s=0;s<t.cs;s++)W(t.c[s],i)}g(W,"secondWalk");function Q(t){Y(t),W(t,0)}g(Q,"layout");var tt=class{static{g(this,"BoundingBox")}constructor(t,i){this.gap=t,this.bottomPadding=i}addBoundingBox(t,i){return{width:t+this.gap,height:i+this.bottomPadding}}removeBoundingBox(t,i){return{x:t+this.gap/2,y:i}}},it=class{static{g(this,"Layout")}constructor(t){this.bb=t}layout(t){let i=this.convert(t);Q(i);let{boundingBox:s,result:o}=this.assignLayout(i,t);return{result:o,boundingBox:s}}convert(t,i=0){if(t===null)return null;let{width:s,height:o}=this.bb.addBoundingBox(t.width,t.height),n=[];if(t.children&&t.children.length)for(let e=0;e<t.children.length;e++)n[e]=this.convert(t.children[e],i+o);return new D(s,o,i,n)}assignCoordinates(t,i){let{x:s,y:o}=this.bb.removeBoundingBox(t.x,t.y);i.x=s,i.y=o;for(let n=0;n<t.c.length;n++)this.assignCoordinates(t.c[n],i.children[n])}getSize(t,i=null){let{x:s,y:o,width:n,height:e}=t;if(i===null&&(i={left:s,right:s+n,top:o,bottom:o+e}),i.left=Math.min(i.left,s),i.right=Math.max(i.right,s+n),i.top=Math.min(i.top,o),i.bottom=Math.max(i.bottom,o+e),t.children)for(let h of t.children)this.getSize(h,i);return i}assignLayout(t,i,s=null){let{x:o,y:n}=this.bb.removeBoundingBox(t.x,t.y);i.x=o,i.y=n;let{width:e,height:h}=i;s===null&&(s={left:o,right:o+e,top:n,bottom:n+h}),s.left=Math.min(s.left,o),s.right=Math.max(s.right,o+e),s.top=Math.min(s.top,n),s.bottom=Math.max(s.bottom,n+h);for(let r=0;r<t.c.length;r++)this.assignLayout(t.c[r],i.children[r],s);return{result:i,boundingBox:s}}};function J(t){let i=50;return new Promise((s,o)=>{try{if(!t.nodes||!Array.isArray(t.nodes)||t.nodes.length===0)throw new Error("No nodes found in layout data");(!t.edges||!Array.isArray(t.edges))&&(t.edges=[]);let{leftTree:n,rightTree:e,rootNode:h}=K(t),r=20,d=40;i=30;let m=new tt(r,d),f=new it(m),y=null,u=null;n&&(y=f.layout(n).result),e&&(u=f.layout(e).result);let p=U(h,y,u),x=V(t.edges,p,i);s({nodes:p,edges:x})}catch(n){o(n)}})}g(J,"executeTidyTreeLayout");function K(t){let{nodes:i,edges:s}=t,o=new Map;i.forEach(x=>o.set(x.id,x));let n=new Map,e=new Map;s.forEach(x=>{let c=x.start,T=x.end;c&&T&&(n.has(c)||n.set(c,[]),n.get(c).push(T),e.set(T,c))});let h=i.find(x=>!e.has(x.id));if(!h&&i.length===0)throw new Error("No nodes available to create tree");let r=h??i[0],d={id:r.id,width:r.width??100,height:r.height??50,_originalNode:r},m=n.get(r.id)??[],f=[],y=[];m.forEach((x,c)=>{c%2===0?f.push(x):y.push(x)});let u=f.length>0?_(f,n,o):null,p=y.length>0?_(y,n,o):null;return{leftTree:u,rightTree:p,rootNode:d}}g(K,"convertToDualTreeFormat");function _(t,i,s){return{id:`virtual-root-${Math.random()}`,width:1,height:1,children:t.map(n=>s.get(n)).filter(n=>n!==void 0).map(n=>X(n,i,s))}}g(_,"buildSubTree");function X(t,i,s){let n=(i.get(t.id)??[]).map(e=>s.get(e)).filter(e=>e!==void 0).map(e=>X(e,i,s));return{id:t.id,width:t.height??50,height:t.width??100,children:n.length>0?n:void 0,_originalNode:t}}g(X,"convertNodeToTidyTreeTransposed");function U(t,i,s){let o=[],h=t.width/2+30,r=[],d=[];i?.children&&A(i.children,r,0-h,0),s?.children&&S(s.children,d,0+h,0);let m=0,f=0;if(r.length>0){let T=[...new Set(r.map(w=>w.x))].sort((w,l)=>l-w)[0],v=r.filter(w=>w.x===T);if(v.length>0){let w=Math.min(...v.map(a=>a.y-(a.height??50)/2)),l=Math.max(...v.map(a=>a.y+(a.height??50)/2));m=(w+l)/2}}if(d.length>0){let T=[...new Set(d.map(w=>w.x))].sort((w,l)=>w-l)[0],v=d.filter(w=>w.x===T);if(v.length>0){let w=Math.min(...v.map(a=>a.y-(a.height??50)/2)),l=Math.max(...v.map(a=>a.y+(a.height??50)/2));f=(w+l)/2}}let y=-m,u=-f;o.push({id:String(t.id),x:0,y:20,section:"root",width:t._originalNode?.width??t.width,height:t._originalNode?.height??t.height,originalNode:t._originalNode});let p=r.map(c=>({id:c.id,x:c.x-(c.width??0)/2,y:c.y+y+(c.height??0)/2,section:"left",width:c.width,height:c.height,originalNode:c.originalNode})),x=d.map(c=>({id:c.id,x:c.x+(c.width??0)/2,y:c.y+u+(c.height??0)/2,section:"right",width:c.width,height:c.height,originalNode:c.originalNode}));return o.push(...p),o.push(...x),o}g(U,"combineAndPositionTrees");function A(t,i,s,o){t.forEach(n=>{let e=n.y??0,h=n.x??0,r=n._originalNode?.width??100,d=n._originalNode?.height??50,m=o+h;i.push({id:String(n.id),x:s-e,y:m,width:r,height:d,originalNode:n._originalNode}),n.children&&A(n.children,i,s,o)})}g(A,"positionLeftTreeBidirectional");function S(t,i,s,o){t.forEach(n=>{let e=n.y??0,h=n.x??0,r=n._originalNode?.width??100,d=n._originalNode?.height??50,m=o+h;i.push({id:String(n.id),x:s+e,y:m,width:r,height:d,originalNode:n._originalNode}),n.children&&S(n.children,i,s,o)})}g(S,"positionRightTreeBidirectional");function E(t,i,s){let o=Math.min(t.width,t.height)/2,n=s.x-i.x,e=s.y-i.y,h=Math.sqrt(n*n+e*e);if(h===0)return i;let r=n/h,d=e/h;return{x:t.x-r*o,y:t.y-d*o}}g(E,"computeCircleEdgeIntersection");function R(t,i,s){let o=t.x,n=t.y;if(!t.width||!t.height)return{x:i.x,y:i.y};let e=Math.abs(o-s.x),h=t?.width/2,r=s.x<i.x?h-e:h+e,d=t.height/2,m=Math.abs(i.y-s.y),f=Math.abs(i.x-s.x);if(Math.abs(n-i.y)*h>Math.abs(o-i.x)*d){let y=s.y<i.y?i.y-d-n:n-d-i.y;r=f*y/m;let u={x:s.x<i.x?s.x+r:s.x-f+r,y:s.y<i.y?s.y+m-y:s.y-m+y};return r===0&&(u.x=i.x,u.y=i.y),f===0&&(u.x=i.x),m===0&&(u.y=i.y),u}else{s.x<i.x?r=i.x-h-o:r=o-h-i.x;let y=m*r/f,u=s.x<i.x?s.x+f-r:s.x-f+r,p=s.y<i.y?s.y+y:s.y-y;return r===0&&(u=i.x,p=i.y),f===0&&(u=i.x),m===0&&(p=i.y),{x:u,y:p}}}g(R,"intersection");function V(t,i,s){let o=new Map;return i.forEach(n=>{o.set(n.id,n)}),t.map(n=>{let e=o.get(n.start??""),h=o.get(n.end??"");if(!e||!h)return{id:n.id,source:n.start??"",target:n.end??"",startX:0,startY:0,midX:0,midY:0,endX:0,endY:0,points:[{x:0,y:0}],sourceSection:void 0,targetSection:void 0,sourceWidth:void 0,sourceHeight:void 0,targetWidth:void 0,targetHeight:void 0};let r={x:e.x,y:e.y},d={x:h.x,y:h.y},m=["circle","cloud","bang"].includes(e.originalNode?.shape??""),f=["circle","cloud","bang"].includes(h.originalNode?.shape??""),y=m?E({x:e.x,y:e.y,width:e.width??100,height:e.height??100},d,r):R(e,r,d),u=f?E({x:h.x,y:h.y,width:h.width??100,height:h.height??100},r,d):R(h,d,r),p=(y.x+u.x)/2,x=(y.y+u.y)/2,c=[y];e.section==="left"?c.push({x:e.x-(e.width??0)/2-s,y:e.y}):e.section==="right"?c.push({x:e.x+(e.width??0)/2+s,y:e.y}):e.section==="root"&&(h.section==="right"?c.push({x:e.x+(e.width??0)/2+s,y:e.y}):h.section==="left"&&c.push({x:e.x-(e.width??0)/2-s,y:e.y})),h.section==="left"?c.push({x:h.x+(h.width??0)/2+s,y:h.y}):h.section==="right"?c.push({x:h.x-(h.width??0)/2-s,y:h.y}):h.section==="root"&&(e.section==="right"?c.push({x:h.x+(h.width??0)/2+s,y:h.y}):e.section==="left"&&c.push({x:h.x-(h.width??0)/2-s,y:h.y})),c.push(u);let T=c.length>1?c[1]:d;y=m?E({x:e.x,y:e.y,width:e.width??100,height:e.height??100},T,r):R(e,T,r),c[0]=y;let v=c.length>1?c[c.length-2]:r;return u=f?E({x:h.x,y:h.y,width:h.width??100,height:h.height??100},v,d):R(h,v,d),c[c.length-1]=u,{id:n.id,source:n.start??"",target:n.end??"",startX:y.x,startY:y.y,midX:p,midY:x,endX:u.x,endY:u.y,points:c,sourceSection:e?.section,targetSection:h?.section,sourceWidth:e?.width,sourceHeight:e?.height,targetWidth:h?.width,targetHeight:h?.height}})}g(V,"calculateEdgePositions");function st(t){if(!t)throw new Error("Layout data is required");if(!t.config)throw new Error("Configuration is required in layout data");if(!Array.isArray(t.nodes))throw new Error("Nodes array is required in layout data");if(!Array.isArray(t.edges))throw new Error("Edges array is required in layout data");return!0}g(st,"validateLayoutData");var nt=g(async(t,i,{insertCluster:s,insertEdge:o,insertEdgeLabel:n,insertMarkers:e,insertNode:h,log:r,positionEdgeLabel:d},{algorithm:m})=>{let f={},y={},u=i.select("g");e(u,t.markers,t.type,t.diagramId);let p=u.insert("g").attr("class","subgraphs"),x=u.insert("g").attr("class","edgePaths"),c=u.insert("g").attr("class","edgeLabels"),T=u.insert("g").attr("class","nodes");r.debug("Inserting nodes into DOM for dimension calculation"),await Promise.all(t.nodes.map(async l=>{if(l.isGroup){let a={...l,id:l.id,width:l.width,height:l.height};y[l.id]=a,f[l.id]=a,await s(p,l)}else{let a={...l,id:l.id,width:l.width,height:l.height};f[l.id]=a;let b=await h(T,l,{config:t.config,dir:t.direction||"TB"}),N=b.node().getBBox();a.width=N.width,a.height=N.height,a.domId=b,r.debug(`Node ${l.id} dimensions: ${N.width}x${N.height}`)}})),r.debug("Running bidirectional tidy-tree layout algorithm");let v={...t,nodes:t.nodes.map(l=>{let a=f[l.id];return{...l,width:a.width??l.width??100,height:a.height??l.height??50}})},w=await J(v);r.debug("Positioning nodes based on bidirectional layout results"),w.nodes.forEach(l=>{let a=f[l.id];a?.domId&&(a.domId.attr("transform",`translate(${l.x}, ${l.y})`),a.x=l.x,a.y=l.y,r.debug(`Positioned node ${a.id} at (${l.x}, ${l.y})`))}),r.debug("Inserting and positioning edges"),await Promise.all(t.edges.map(async l=>{await n(c,l);let a=f[l.start??""],b=f[l.end??""];if(a&&b){let N=w.edges.find(M=>M.id===l.id);if(N){r.debug("APA01 positionedEdge",N);let M={...l,points:N.points},L=o(x,M,y,t.type,a,b,t.diagramId);d(M,L)}else{let M={...l,points:[{x:a.x??0,y:a.y??0},{x:b.x??0,y:b.y??0}]},L=o(x,M,y,t.type,a,b,t.diagramId);d(M,L)}}})),r.debug("Bidirectional tidy-tree rendering completed")},"render");export{g as a,nt as b};