@hugobatist/smartcode 0.1.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.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +292 -0
  3. package/dist/cli.js +4324 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/index.d.ts +374 -0
  6. package/dist/index.js +1167 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/static/annotations-panel.js +133 -0
  9. package/dist/static/annotations-svg.js +108 -0
  10. package/dist/static/annotations.css +367 -0
  11. package/dist/static/annotations.js +367 -0
  12. package/dist/static/app-init.js +497 -0
  13. package/dist/static/breakpoints.css +69 -0
  14. package/dist/static/breakpoints.js +197 -0
  15. package/dist/static/clipboard.js +94 -0
  16. package/dist/static/collapse-ui.js +325 -0
  17. package/dist/static/command-history.js +89 -0
  18. package/dist/static/context-menu.js +334 -0
  19. package/dist/static/custom-renderer.js +201 -0
  20. package/dist/static/dagre-layout.js +291 -0
  21. package/dist/static/diagram-dom.js +241 -0
  22. package/dist/static/diagram-editor.js +368 -0
  23. package/dist/static/editor-panel.js +107 -0
  24. package/dist/static/editor-popovers.js +187 -0
  25. package/dist/static/event-bus.js +57 -0
  26. package/dist/static/export.js +181 -0
  27. package/dist/static/file-tree.js +470 -0
  28. package/dist/static/ghost-paths.js +397 -0
  29. package/dist/static/heatmap.css +116 -0
  30. package/dist/static/heatmap.js +308 -0
  31. package/dist/static/icons.js +66 -0
  32. package/dist/static/inline-edit.js +294 -0
  33. package/dist/static/interaction-state.js +155 -0
  34. package/dist/static/interaction-tracker.js +93 -0
  35. package/dist/static/live.html +239 -0
  36. package/dist/static/main-layout.css +220 -0
  37. package/dist/static/main.css +334 -0
  38. package/dist/static/mcp-sessions.js +202 -0
  39. package/dist/static/modal.css +109 -0
  40. package/dist/static/modal.js +171 -0
  41. package/dist/static/node-drag.js +293 -0
  42. package/dist/static/pan-zoom.js +199 -0
  43. package/dist/static/renderer.js +280 -0
  44. package/dist/static/search.css +103 -0
  45. package/dist/static/search.js +304 -0
  46. package/dist/static/selection.js +353 -0
  47. package/dist/static/session-player.css +137 -0
  48. package/dist/static/session-player.js +411 -0
  49. package/dist/static/sidebar.css +248 -0
  50. package/dist/static/svg-renderer.js +313 -0
  51. package/dist/static/svg-shapes.js +218 -0
  52. package/dist/static/tokens.css +76 -0
  53. package/dist/static/vendor/dagre-bundle.js +43 -0
  54. package/dist/static/vendor/dagre.min.js +3 -0
  55. package/dist/static/vendor/graphlib.min.js +2 -0
  56. package/dist/static/viewport-transform.js +107 -0
  57. package/dist/static/workspace-switcher.js +202 -0
  58. package/dist/static/ws-client.js +71 -0
  59. package/dist/static/ws-handler.js +125 -0
  60. package/package.json +74 -0
@@ -0,0 +1,3 @@
1
+ var dagre=(()=>{var g=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(t,r)=>(typeof require!="undefined"?require:t)[r]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var p=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Y=p((ai,A)=>{var L=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,r=t._prev;if(r!==t)return D(r),r}enqueue(t){let r=this._sentinel;t._prev&&t._next&&D(t),t._next=r._next,r._next._prev=t,r._next=t,t._prev=r}toString(){let t=[],r=this._sentinel,n=r._prev;for(;n!==r;)t.push(JSON.stringify(n,Ot)),n=n._prev;return"["+t.join(", ")+"]"}};function D(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Ot(e,t){if(e!=="_next"&&e!=="_prev")return t}A.exports=L});var z=p((li,W)=>{var It=g("@dagrejs/graphlib").Graph,qt=Y();W.exports=Rt;var Lt=()=>1;function Rt(e,t){if(e.nodeCount()<=1)return[];let r=Mt(e,t||Lt);return Ct(r.graph,r.buckets,r.zeroIdx).flatMap(i=>e.outEdges(i.v,i.w))}function Ct(e,t,r){let n=[],i=t[t.length-1],a=t[0],o;for(;e.nodeCount();){for(;o=a.dequeue();)R(e,t,r,o);for(;o=i.dequeue();)R(e,t,r,o);if(e.nodeCount()){for(let l=t.length-2;l>0;--l)if(o=t[l].dequeue(),o){n=n.concat(R(e,t,r,o,!0));break}}}return n}function R(e,t,r,n,i){let a=i?[]:void 0;return e.inEdges(n.v).forEach(o=>{let l=e.edge(o),s=e.node(o.v);i&&a.push({v:o.v,w:o.w}),s.out-=l,C(t,r,s)}),e.outEdges(n.v).forEach(o=>{let l=e.edge(o),s=o.w,d=e.node(s);d.in-=l,C(t,r,d)}),e.removeNode(n.v),a}function Mt(e,t){let r=new It,n=0,i=0;e.nodes().forEach(l=>{r.setNode(l,{v:l,in:0,out:0})}),e.edges().forEach(l=>{let s=r.edge(l.v,l.w)||0,d=t(l),u=s+d;r.setEdge(l.v,l.w,u),i=Math.max(i,r.node(l.v).out+=d),n=Math.max(n,r.node(l.w).in+=d)});let a=Tt(i+n+3).map(()=>new qt),o=n+1;return r.nodes().forEach(l=>{C(a,o,r.node(l))}),{graph:r,buckets:a,zeroIdx:o}}function C(e,t,r){r.out?r.in?e[r.out-r.in+t].enqueue(r):e[e.length-1].enqueue(r):e[0].enqueue(r)}function Tt(e){let t=[];for(let r=0;r<e;r++)t.push(r);return t}});var m=p((si,Z)=>{"use strict";var X=g("@dagrejs/graphlib").Graph;Z.exports={addBorderNode:Dt,addDummyNode:H,applyWithChunking:N,asNonCompoundGraph:_t,buildLayerMatrix:Vt,intersectRect:Gt,mapValues:Ut,maxRank:J,normalizeRanks:Ft,notime:zt,partition:Yt,pick:Ht,predecessorWeights:Pt,range:Q,removeEmptyRanks:Bt,simplify:jt,successorWeights:St,time:Wt,uniqueId:K,zipObject:M};function H(e,t,r,n){for(var i=n;e.hasNode(i);)i=K(n);return r.dummy=t,e.setNode(i,r),i}function jt(e){let t=new X().setGraph(e.graph());return e.nodes().forEach(r=>t.setNode(r,e.node(r))),e.edges().forEach(r=>{let n=t.edge(r.v,r.w)||{weight:0,minlen:1},i=e.edge(r);t.setEdge(r.v,r.w,{weight:n.weight+i.weight,minlen:Math.max(n.minlen,i.minlen)})}),t}function _t(e){let t=new X({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(r=>{e.children(r).length||t.setNode(r,e.node(r))}),e.edges().forEach(r=>{t.setEdge(r,e.edge(r))}),t}function St(e){let t=e.nodes().map(r=>{let n={};return e.outEdges(r).forEach(i=>{n[i.w]=(n[i.w]||0)+e.edge(i).weight}),n});return M(e.nodes(),t)}function Pt(e){let t=e.nodes().map(r=>{let n={};return e.inEdges(r).forEach(i=>{n[i.v]=(n[i.v]||0)+e.edge(i).weight}),n});return M(e.nodes(),t)}function Gt(e,t){let r=e.x,n=e.y,i=t.x-r,a=t.y-n,o=e.width/2,l=e.height/2;if(!i&&!a)throw new Error("Not possible to find intersection inside of the rectangle");let s,d;return Math.abs(a)*o>Math.abs(i)*l?(a<0&&(l=-l),s=l*i/a,d=l):(i<0&&(o=-o),s=o,d=o*a/i),{x:r+s,y:n+d}}function Vt(e){let t=Q(J(e)+1).map(()=>[]);return e.nodes().forEach(r=>{let n=e.node(r),i=n.rank;i!==void 0&&(t[i][n.order]=r)}),t}function Ft(e){let t=e.nodes().map(n=>{let i=e.node(n).rank;return i===void 0?Number.MAX_VALUE:i}),r=N(Math.min,t);e.nodes().forEach(n=>{let i=e.node(n);Object.hasOwn(i,"rank")&&(i.rank-=r)})}function Bt(e){let t=e.nodes().map(o=>e.node(o).rank).filter(o=>o!==void 0),r=N(Math.min,t),n=[];e.nodes().forEach(o=>{let l=e.node(o).rank-r;n[l]||(n[l]=[]),n[l].push(o)});let i=0,a=e.graph().nodeRankFactor;Array.from(n).forEach((o,l)=>{o===void 0&&l%a!==0?--i:o!==void 0&&i&&o.forEach(s=>e.node(s).rank+=i)})}function Dt(e,t,r,n){let i={width:0,height:0};return arguments.length>=4&&(i.rank=r,i.order=n),H(e,"border",i,t)}function At(e,t=U){let r=[];for(let n=0;n<e.length;n+=t){let i=e.slice(n,n+t);r.push(i)}return r}var U=65535;function N(e,t){if(t.length>U){let r=At(t);return e.apply(null,r.map(n=>e.apply(null,n)))}else return e.apply(null,t)}function J(e){let r=e.nodes().map(n=>{let i=e.node(n).rank;return i===void 0?Number.MIN_VALUE:i});return N(Math.max,r)}function Yt(e,t){let r={lhs:[],rhs:[]};return e.forEach(n=>{t(n)?r.lhs.push(n):r.rhs.push(n)}),r}function Wt(e,t){let r=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-r)+"ms")}}function zt(e,t){return t()}var Xt=0;function K(e){var t=++Xt;return e+(""+t)}function Q(e,t,r=1){t==null&&(t=e,e=0);let n=a=>a<t;r<0&&(n=a=>t<a);let i=[];for(let a=e;n(a);a+=r)i.push(a);return i}function Ht(e,t){let r={};for(let n of t)e[n]!==void 0&&(r[n]=e[n]);return r}function Ut(e,t){let r=t;return typeof t=="string"&&(r=n=>n[t]),Object.entries(e).reduce((n,[i,a])=>(n[i]=r(a,i),n),{})}function M(e,t){return e.reduce((r,n,i)=>(r[n]=t[i],r),{})}});var ee=p((di,$)=>{"use strict";var Jt=z(),Kt=m().uniqueId;$.exports={run:Qt,undo:$t};function Qt(e){(e.graph().acyclicer==="greedy"?Jt(e,r(e)):Zt(e)).forEach(n=>{let i=e.edge(n);e.removeEdge(n),i.forwardName=n.name,i.reversed=!0,e.setEdge(n.w,n.v,i,Kt("rev"))});function r(n){return i=>n.edge(i).weight}}function Zt(e){let t=[],r={},n={};function i(a){Object.hasOwn(n,a)||(n[a]=!0,r[a]=!0,e.outEdges(a).forEach(o=>{Object.hasOwn(r,o.w)?t.push(o):i(o.w)}),delete r[a])}return e.nodes().forEach(i),t}function $t(e){e.edges().forEach(t=>{let r=e.edge(t);if(r.reversed){e.removeEdge(t);let n=r.forwardName;delete r.reversed,delete r.forwardName,e.setEdge(t.w,t.v,r,n)}})}});var re=p((ui,te)=>{"use strict";var er=m();te.exports={run:tr,undo:nr};function tr(e){e.graph().dummyChains=[],e.edges().forEach(t=>rr(e,t))}function rr(e,t){let r=t.v,n=e.node(r).rank,i=t.w,a=e.node(i).rank,o=t.name,l=e.edge(t),s=l.labelRank;if(a===n+1)return;e.removeEdge(t);let d,u,h;for(h=0,++n;n<a;++h,++n)l.points=[],u={width:0,height:0,edgeLabel:l,edgeObj:t,rank:n},d=er.addDummyNode(e,"edge",u,"_d"),n===s&&(u.width=l.width,u.height=l.height,u.dummy="edge-label",u.labelpos=l.labelpos),e.setEdge(r,d,{weight:l.weight},o),h===0&&e.graph().dummyChains.push(d),r=d;e.setEdge(r,i,{weight:l.weight},o)}function nr(e){e.graph().dummyChains.forEach(t=>{let r=e.node(t),n=r.edgeLabel,i;for(e.setEdge(r.edgeObj,n);r.dummy;)i=e.successors(t)[0],e.removeNode(t),n.points.push({x:r.x,y:r.y}),r.dummy==="edge-label"&&(n.x=r.x,n.y=r.y,n.width=r.width,n.height=r.height),t=i,r=e.node(t)})}});var v=p((hi,ne)=>{"use strict";var{applyWithChunking:ir}=m();ne.exports={longestPath:or,slack:ar};function or(e){var t={};function r(n){var i=e.node(n);if(Object.hasOwn(t,n))return i.rank;t[n]=!0;let a=e.outEdges(n).map(l=>l==null?Number.POSITIVE_INFINITY:r(l.w)-e.edge(l).minlen);var o=ir(Math.min,a);return o===Number.POSITIVE_INFINITY&&(o=0),i.rank=o}e.sources().forEach(r)}function ar(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}});var T=p((fi,ie)=>{"use strict";var lr=g("@dagrejs/graphlib").Graph,O=v().slack;ie.exports=sr;function sr(e){var t=new lr({directed:!1}),r=e.nodes()[0],n=e.nodeCount();t.setNode(r,{});for(var i,a;dr(t,e)<n;)i=ur(t,e),a=t.hasNode(i.v)?O(e,i):-O(e,i),hr(t,e,a);return t}function dr(e,t){function r(n){t.nodeEdges(n).forEach(i=>{var a=i.v,o=n===a?i.w:a;!e.hasNode(o)&&!O(t,i)&&(e.setNode(o,{}),e.setEdge(n,o,{}),r(o))})}return e.nodes().forEach(r),e.nodeCount()}function ur(e,t){return t.edges().reduce((n,i)=>{let a=Number.POSITIVE_INFINITY;return e.hasNode(i.v)!==e.hasNode(i.w)&&(a=O(t,i)),a<n[0]?[a,i]:n},[Number.POSITIVE_INFINITY,null])[1]}function hr(e,t,r){e.nodes().forEach(n=>t.node(n).rank+=r)}});var ce=p((ci,fe)=>{"use strict";var fr=T(),oe=v().slack,cr=v().longestPath,pr=g("@dagrejs/graphlib").alg.preorder,mr=g("@dagrejs/graphlib").alg.postorder,br=m().simplify;fe.exports=y;y.initLowLimValues=_;y.initCutValues=j;y.calcCutValue=le;y.leaveEdge=de;y.enterEdge=ue;y.exchangeEdges=he;function y(e){e=br(e),cr(e);var t=fr(e);_(t),j(t,e);for(var r,n;r=de(t);)n=ue(t,e,r),he(t,e,r,n)}function j(e,t){var r=mr(e,e.nodes());r=r.slice(0,r.length-1),r.forEach(n=>wr(e,t,n))}function wr(e,t,r){var n=e.node(r),i=n.parent;e.edge(r,i).cutvalue=le(e,t,r)}function le(e,t,r){var n=e.node(r),i=n.parent,a=!0,o=t.edge(r,i),l=0;return o||(a=!1,o=t.edge(i,r)),l=o.weight,t.nodeEdges(r).forEach(s=>{var d=s.v===r,u=d?s.w:s.v;if(u!==i){var h=d===a,f=t.edge(s).weight;if(l+=h?f:-f,gr(e,r,u)){var c=e.edge(r,u).cutvalue;l+=h?-c:c}}}),l}function _(e,t){arguments.length<2&&(t=e.nodes()[0]),se(e,{},1,t)}function se(e,t,r,n,i){var a=r,o=e.node(n);return t[n]=!0,e.neighbors(n).forEach(l=>{Object.hasOwn(t,l)||(r=se(e,t,r,l,n))}),o.low=a,o.lim=r++,i?o.parent=i:delete o.parent,r}function de(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ue(e,t,r){var n=r.v,i=r.w;t.hasEdge(n,i)||(n=r.w,i=r.v);var a=e.node(n),o=e.node(i),l=a,s=!1;a.lim>o.lim&&(l=o,s=!0);var d=t.edges().filter(u=>s===ae(e,e.node(u.v),l)&&s!==ae(e,e.node(u.w),l));return d.reduce((u,h)=>oe(t,h)<oe(t,u)?h:u)}function he(e,t,r,n){var i=r.v,a=r.w;e.removeEdge(i,a),e.setEdge(n.v,n.w,{}),_(e),j(e,t),Er(e,t)}function Er(e,t){var r=e.nodes().find(i=>!t.node(i).parent),n=pr(e,r);n=n.slice(1),n.forEach(i=>{var a=e.node(i).parent,o=t.edge(i,a),l=!1;o||(o=t.edge(a,i),l=!0),t.node(i).rank=t.node(a).rank+(l?o.minlen:-o.minlen)})}function gr(e,t,r){return e.hasEdge(t,r)}function ae(e,t,r){return r.low<=t.lim&&t.lim<=r.lim}});var we=p((pi,be)=>{"use strict";var kr=v(),me=kr.longestPath,xr=T(),yr=ce();be.exports=vr;function vr(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":pe(e);break;case"tight-tree":Or(e);break;case"longest-path":Nr(e);break;case"none":break;default:pe(e)}}var Nr=me;function Or(e){me(e),xr(e)}function pe(e){yr(e)}});var ge=p((mi,Ee)=>{Ee.exports=Ir;function Ir(e){let t=Lr(e);e.graph().dummyChains.forEach(r=>{let n=e.node(r),i=n.edgeObj,a=qr(e,t,i.v,i.w),o=a.path,l=a.lca,s=0,d=o[s],u=!0;for(;r!==i.w;){if(n=e.node(r),u){for(;(d=o[s])!==l&&e.node(d).maxRank<n.rank;)s++;d===l&&(u=!1)}if(!u){for(;s<o.length-1&&e.node(d=o[s+1]).minRank<=n.rank;)s++;d=o[s]}e.setParent(r,d),r=e.successors(r)[0]}})}function qr(e,t,r,n){let i=[],a=[],o=Math.min(t[r].low,t[n].low),l=Math.max(t[r].lim,t[n].lim),s,d;s=r;do s=e.parent(s),i.push(s);while(s&&(t[s].low>o||l>t[s].lim));for(d=s,s=n;(s=e.parent(s))!==d;)a.push(s);return{path:i.concat(a.reverse()),lca:d}}function Lr(e){let t={},r=0;function n(i){let a=r;e.children(i).forEach(n),t[i]={low:a,lim:r++}}return e.children().forEach(n),t}});var ye=p((bi,xe)=>{var I=m();xe.exports={run:Rr,cleanup:Tr};function Rr(e){let t=I.addDummyNode(e,"root",{},"_root"),r=Cr(e),n=Object.values(r),i=I.applyWithChunking(Math.max,n)-1,a=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(l=>e.edge(l).minlen*=a);let o=Mr(e)+1;e.children().forEach(l=>ke(e,t,a,o,i,r,l)),e.graph().nodeRankFactor=a}function ke(e,t,r,n,i,a,o){let l=e.children(o);if(!l.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:r});return}let s=I.addBorderNode(e,"_bt"),d=I.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(s,o),u.borderTop=s,e.setParent(d,o),u.borderBottom=d,l.forEach(h=>{ke(e,t,r,n,i,a,h);let f=e.node(h),c=f.borderTop?f.borderTop:h,b=f.borderBottom?f.borderBottom:h,w=f.borderTop?n:2*n,x=c!==b?1:i-a[o]+1;e.setEdge(s,c,{weight:w,minlen:x,nestingEdge:!0}),e.setEdge(b,d,{weight:w,minlen:x,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,s,{weight:0,minlen:i+a[o]})}function Cr(e){var t={};function r(n,i){var a=e.children(n);a&&a.length&&a.forEach(o=>r(o,i+1)),t[n]=i}return e.children().forEach(n=>r(n,1)),t}function Mr(e){return e.edges().reduce((t,r)=>t+e.edge(r).weight,0)}function Tr(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(r=>{var n=e.edge(r);n.nestingEdge&&e.removeEdge(r)})}});var Oe=p((wi,Ne)=>{var jr=m();Ne.exports=_r;function _r(e){function t(r){let n=e.children(r),i=e.node(r);if(n.length&&n.forEach(t),Object.hasOwn(i,"minRank")){i.borderLeft=[],i.borderRight=[];for(let a=i.minRank,o=i.maxRank+1;a<o;++a)ve(e,"borderLeft","_bl",r,i,a),ve(e,"borderRight","_br",r,i,a)}}e.children().forEach(t)}function ve(e,t,r,n,i,a){let o={width:0,height:0,rank:a,borderType:t},l=i[t][a-1],s=jr.addDummyNode(e,"border",o,r);i[t][a]=s,e.setParent(s,n),l&&e.setEdge(l,s,{weight:1})}});var Re=p((Ei,Le)=>{"use strict";Le.exports={adjust:Sr,undo:Pr};function Sr(e){let t=e.graph().rankdir.toLowerCase();(t==="lr"||t==="rl")&&qe(e)}function Pr(e){let t=e.graph().rankdir.toLowerCase();(t==="bt"||t==="rl")&&Gr(e),(t==="lr"||t==="rl")&&(Vr(e),qe(e))}function qe(e){e.nodes().forEach(t=>Ie(e.node(t))),e.edges().forEach(t=>Ie(e.edge(t)))}function Ie(e){let t=e.width;e.width=e.height,e.height=t}function Gr(e){e.nodes().forEach(t=>S(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);r.points.forEach(S),Object.hasOwn(r,"y")&&S(r)})}function S(e){e.y=-e.y}function Vr(e){e.nodes().forEach(t=>P(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);r.points.forEach(P),Object.hasOwn(r,"x")&&P(r)})}function P(e){let t=e.x;e.x=e.y,e.y=t}});var Te=p((gi,Me)=>{"use strict";var Ce=m();Me.exports=Fr;function Fr(e){let t={},r=e.nodes().filter(s=>!e.children(s).length),n=r.map(s=>e.node(s).rank),i=Ce.applyWithChunking(Math.max,n),a=Ce.range(i+1).map(()=>[]);function o(s){if(t[s])return;t[s]=!0;let d=e.node(s);a[d.rank].push(s),e.successors(s).forEach(o)}return r.sort((s,d)=>e.node(s).rank-e.node(d).rank).forEach(o),a}});var _e=p((ki,je)=>{"use strict";var Br=m().zipObject;je.exports=Dr;function Dr(e,t){let r=0;for(let n=1;n<t.length;++n)r+=Ar(e,t[n-1],t[n]);return r}function Ar(e,t,r){let n=Br(r,r.map((d,u)=>u)),i=t.flatMap(d=>e.outEdges(d).map(u=>({pos:n[u.w],weight:e.edge(u).weight})).sort((u,h)=>u.pos-h.pos)),a=1;for(;a<r.length;)a<<=1;let o=2*a-1;a-=1;let l=new Array(o).fill(0),s=0;return i.forEach(d=>{let u=d.pos+a;l[u]+=d.weight;let h=0;for(;u>0;)u%2&&(h+=l[u+1]),u=u-1>>1,l[u]+=d.weight;s+=d.weight*h}),s}});var Pe=p((xi,Se)=>{Se.exports=Yr;function Yr(e,t=[]){return t.map(r=>{let n=e.inEdges(r);if(n.length){let i=n.reduce((a,o)=>{let l=e.edge(o),s=e.node(o.v);return{sum:a.sum+l.weight*s.order,weight:a.weight+l.weight}},{sum:0,weight:0});return{v:r,barycenter:i.sum/i.weight,weight:i.weight}}else return{v:r}})}});var Ve=p((yi,Ge)=>{"use strict";var Wr=m();Ge.exports=zr;function zr(e,t){let r={};e.forEach((i,a)=>{let o=r[i.v]={indegree:0,in:[],out:[],vs:[i.v],i:a};i.barycenter!==void 0&&(o.barycenter=i.barycenter,o.weight=i.weight)}),t.edges().forEach(i=>{let a=r[i.v],o=r[i.w];a!==void 0&&o!==void 0&&(o.indegree++,a.out.push(r[i.w]))});let n=Object.values(r).filter(i=>!i.indegree);return Xr(n)}function Xr(e){let t=[];function r(i){return a=>{a.merged||(a.barycenter===void 0||i.barycenter===void 0||a.barycenter>=i.barycenter)&&Hr(i,a)}}function n(i){return a=>{a.in.push(i),--a.indegree===0&&e.push(a)}}for(;e.length;){let i=e.pop();t.push(i),i.in.reverse().forEach(r(i)),i.out.forEach(n(i))}return t.filter(i=>!i.merged).map(i=>Wr.pick(i,["vs","i","barycenter","weight"]))}function Hr(e,t){let r=0,n=0;e.weight&&(r+=e.barycenter*e.weight,n+=e.weight),t.weight&&(r+=t.barycenter*t.weight,n+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=r/n,e.weight=n,e.i=Math.min(t.i,e.i),t.merged=!0}});var De=p((vi,Be)=>{var Ur=m();Be.exports=Jr;function Jr(e,t){let r=Ur.partition(e,u=>Object.hasOwn(u,"barycenter")),n=r.lhs,i=r.rhs.sort((u,h)=>h.i-u.i),a=[],o=0,l=0,s=0;n.sort(Kr(!!t)),s=Fe(a,i,s),n.forEach(u=>{s+=u.vs.length,a.push(u.vs),o+=u.barycenter*u.weight,l+=u.weight,s=Fe(a,i,s)});let d={vs:a.flat(!0)};return l&&(d.barycenter=o/l,d.weight=l),d}function Fe(e,t,r){let n;for(;t.length&&(n=t[t.length-1]).i<=r;)t.pop(),e.push(n.vs),r++;return r}function Kr(e){return(t,r)=>t.barycenter<r.barycenter?-1:t.barycenter>r.barycenter?1:e?r.i-t.i:t.i-r.i}});var We=p((Ni,Ye)=>{var Qr=Pe(),Zr=Ve(),$r=De();Ye.exports=Ae;function Ae(e,t,r,n){let i=e.children(t),a=e.node(t),o=a?a.borderLeft:void 0,l=a?a.borderRight:void 0,s={};o&&(i=i.filter(f=>f!==o&&f!==l));let d=Qr(e,i);d.forEach(f=>{if(e.children(f.v).length){let c=Ae(e,f.v,r,n);s[f.v]=c,Object.hasOwn(c,"barycenter")&&tn(f,c)}});let u=Zr(d,r);en(u,s);let h=$r(u,n);if(o&&(h.vs=[o,h.vs,l].flat(!0),e.predecessors(o).length)){let f=e.node(e.predecessors(o)[0]),c=e.node(e.predecessors(l)[0]);Object.hasOwn(h,"barycenter")||(h.barycenter=0,h.weight=0),h.barycenter=(h.barycenter*h.weight+f.order+c.order)/(h.weight+2),h.weight+=2}return h}function en(e,t){e.forEach(r=>{r.vs=r.vs.flatMap(n=>t[n]?t[n].vs:n)})}function tn(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}});var Xe=p((Oi,ze)=>{var rn=g("@dagrejs/graphlib").Graph,nn=m();ze.exports=on;function on(e,t,r,n){n||(n=e.nodes());let i=an(e),a=new rn({compound:!0}).setGraph({root:i}).setDefaultNodeLabel(o=>e.node(o));return n.forEach(o=>{let l=e.node(o),s=e.parent(o);(l.rank===t||l.minRank<=t&&t<=l.maxRank)&&(a.setNode(o),a.setParent(o,s||i),e[r](o).forEach(d=>{let u=d.v===o?d.w:d.v,h=a.edge(u,o),f=h!==void 0?h.weight:0;a.setEdge(u,o,{weight:e.edge(d).weight+f})}),Object.hasOwn(l,"minRank")&&a.setNode(o,{borderLeft:l.borderLeft[t],borderRight:l.borderRight[t]}))}),a}function an(e){for(var t;e.hasNode(t=nn.uniqueId("_root")););return t}});var Ue=p((Ii,He)=>{He.exports=ln;function ln(e,t,r){let n={},i;r.forEach(a=>{let o=e.parent(a),l,s;for(;o;){if(l=e.parent(o),l?(s=n[l],n[l]=o):(s=i,i=o),s&&s!==o){t.setEdge(s,o);return}o=l}})}});var $e=p((qi,Ze)=>{"use strict";var sn=Te(),dn=_e(),un=We(),hn=Xe(),fn=Ue(),cn=g("@dagrejs/graphlib").Graph,q=m();Ze.exports=Qe;function Qe(e,t={}){if(typeof t.customOrder=="function"){t.customOrder(e,Qe);return}let r=q.maxRank(e),n=Je(e,q.range(1,r+1),"inEdges"),i=Je(e,q.range(r-1,-1,-1),"outEdges"),a=sn(e);if(Ke(e,a),t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,l,s=t.constraints||[];for(let d=0,u=0;u<4;++d,++u){pn(d%2?n:i,d%4>=2,s),a=q.buildLayerMatrix(e);let h=dn(e,a);h<o?(u=0,l=Object.assign({},a),o=h):h===o&&(l=structuredClone(a))}Ke(e,l)}function Je(e,t,r){let n=new Map,i=(a,o)=>{n.has(a)||n.set(a,[]),n.get(a).push(o)};for(let a of e.nodes()){let o=e.node(a);if(typeof o.rank=="number"&&i(o.rank,a),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let l=o.minRank;l<=o.maxRank;l++)l!==o.rank&&i(l,a)}return t.map(function(a){return hn(e,a,r,n.get(a)||[])})}function pn(e,t,r){let n=new cn;e.forEach(function(i){r.forEach(l=>n.setEdge(l.left,l.right));let a=i.graph().root,o=un(i,a,n,t);o.vs.forEach((l,s)=>i.node(l).order=s),fn(i,n,o.vs)})}function Ke(e,t){Object.values(t).forEach(r=>r.forEach((n,i)=>e.node(n).order=i))}});var dt=p((Li,st)=>{"use strict";var mn=g("@dagrejs/graphlib").Graph,k=m();st.exports={positionX:En,findType1Conflicts:et,findType2Conflicts:tt,addConflict:G,hasConflict:rt,verticalAlignment:nt,horizontalCompaction:it,alignCoordinates:at,findSmallestWidthAlignment:ot,balance:lt};function et(e,t){let r={};function n(i,a){let o=0,l=0,s=i.length,d=a[a.length-1];return a.forEach((u,h)=>{let f=bn(e,u),c=f?e.node(f).order:s;(f||u===d)&&(a.slice(l,h+1).forEach(b=>{e.predecessors(b).forEach(w=>{let x=e.node(w),B=x.order;(B<o||c<B)&&!(x.dummy&&e.node(b).dummy)&&G(r,w,b)})}),l=h+1,o=c)}),a}return t.length&&t.reduce(n),r}function tt(e,t){let r={};function n(a,o,l,s,d){let u;k.range(o,l).forEach(h=>{u=a[h],e.node(u).dummy&&e.predecessors(u).forEach(f=>{let c=e.node(f);c.dummy&&(c.order<s||c.order>d)&&G(r,f,u)})})}function i(a,o){let l=-1,s,d=0;return o.forEach((u,h)=>{if(e.node(u).dummy==="border"){let f=e.predecessors(u);f.length&&(s=e.node(f[0]).order,n(o,d,h,l,s),d=h,l=s)}n(o,d,o.length,s,a.length)}),o}return t.length&&t.reduce(i),r}function bn(e,t){if(e.node(t).dummy)return e.predecessors(t).find(r=>e.node(r).dummy)}function G(e,t,r){if(t>r){let i=t;t=r,r=i}let n=e[t];n||(e[t]=n={}),n[r]=!0}function rt(e,t,r){if(t>r){let n=t;t=r,r=n}return!!e[t]&&Object.hasOwn(e[t],r)}function nt(e,t,r,n){let i={},a={},o={};return t.forEach(l=>{l.forEach((s,d)=>{i[s]=s,a[s]=s,o[s]=d})}),t.forEach(l=>{let s=-1;l.forEach(d=>{let u=n(d);if(u.length){u=u.sort((f,c)=>o[f]-o[c]);let h=(u.length-1)/2;for(let f=Math.floor(h),c=Math.ceil(h);f<=c;++f){let b=u[f];a[d]===d&&s<o[b]&&!rt(r,d,b)&&(a[b]=d,a[d]=i[d]=i[b],s=o[b])}}})}),{root:i,align:a}}function it(e,t,r,n,i){let a={},o=wn(e,t,r,i),l=i?"borderLeft":"borderRight";function s(h,f){let c=o.nodes().slice(),b={},w=c.pop();for(;w;){if(b[w])h(w);else{b[w]=!0,c.push(w);for(let x of f(w))c.push(x)}w=c.pop()}}function d(h){a[h]=o.inEdges(h).reduce((f,c)=>Math.max(f,a[c.v]+o.edge(c)),0)}function u(h){let f=o.outEdges(h).reduce((b,w)=>Math.min(b,a[w.w]-o.edge(w)),Number.POSITIVE_INFINITY),c=e.node(h);f!==Number.POSITIVE_INFINITY&&c.borderType!==l&&(a[h]=Math.max(a[h],f))}return s(d,o.predecessors.bind(o)),s(u,o.successors.bind(o)),Object.keys(n).forEach(h=>a[h]=a[r[h]]),a}function wn(e,t,r,n){let i=new mn,a=e.graph(),o=gn(a.nodesep,a.edgesep,n);return t.forEach(l=>{let s;l.forEach(d=>{let u=r[d];if(i.setNode(u),s){var h=r[s],f=i.edge(h,u);i.setEdge(h,u,Math.max(o(e,d,s),f||0))}s=d})}),i}function ot(e,t){return Object.values(t).reduce((r,n)=>{let i=Number.NEGATIVE_INFINITY,a=Number.POSITIVE_INFINITY;Object.entries(n).forEach(([l,s])=>{let d=kn(e,l)/2;i=Math.max(s+d,i),a=Math.min(s-d,a)});let o=i-a;return o<r[0]&&(r=[o,n]),r},[Number.POSITIVE_INFINITY,null])[1]}function at(e,t){let r=Object.values(t),n=k.applyWithChunking(Math.min,r),i=k.applyWithChunking(Math.max,r);["u","d"].forEach(a=>{["l","r"].forEach(o=>{let l=a+o,s=e[l];if(s===t)return;let d=Object.values(s),u=n-k.applyWithChunking(Math.min,d);o!=="l"&&(u=i-k.applyWithChunking(Math.max,d)),u&&(e[l]=k.mapValues(s,h=>h+u))})})}function lt(e,t){return k.mapValues(e.ul,(r,n)=>{if(t)return e[t.toLowerCase()][n];{let i=Object.values(e).map(a=>a[n]).sort((a,o)=>a-o);return(i[1]+i[2])/2}})}function En(e){let t=k.buildLayerMatrix(e),r=Object.assign(et(e,t),tt(e,t)),n={},i;["u","d"].forEach(o=>{i=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(l=>{l==="r"&&(i=i.map(h=>Object.values(h).reverse()));let s=(o==="u"?e.predecessors:e.successors).bind(e),d=nt(e,i,r,s),u=it(e,i,d.root,d.align,l==="r");l==="r"&&(u=k.mapValues(u,h=>-h)),n[o+l]=u})});let a=ot(e,n);return at(n,a),lt(n,e.graph().align)}function gn(e,t,r){return(n,i,a)=>{let o=n.node(i),l=n.node(a),s=0,d;if(s+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":d=-o.width/2;break;case"r":d=o.width/2;break}if(d&&(s+=r?d:-d),d=0,s+=(o.dummy?t:e)/2,s+=(l.dummy?t:e)/2,s+=l.width/2,Object.hasOwn(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":d=l.width/2;break;case"r":d=-l.width/2;break}return d&&(s+=r?d:-d),d=0,s}}function kn(e,t){return e.node(t).width}});var ft=p((Ri,ht)=>{"use strict";var ut=m(),xn=dt().positionX;ht.exports=yn;function yn(e){e=ut.asNonCompoundGraph(e),vn(e),Object.entries(xn(e)).forEach(([t,r])=>e.node(t).x=r)}function vn(e){let t=ut.buildLayerMatrix(e),r=e.graph().ranksep,n=e.graph().rankalign,i=0;t.forEach(a=>{let o=a.reduce((l,s)=>{let d=e.node(s).height;return l>d?l:d},0);a.forEach(l=>{let s=e.node(l);n==="top"?s.y=i+s.height/2:n==="bottom"?s.y=i+o-s.height/2:s.y=i+o/2}),i+=o+r})}});var gt=p((Ci,Et)=>{"use strict";var ct=ee(),pt=re(),Nn=we(),On=m().normalizeRanks,In=ge(),qn=m().removeEmptyRanks,mt=ye(),Ln=Oe(),bt=Re(),Rn=$e(),Cn=ft(),E=m(),Mn=g("@dagrejs/graphlib").Graph;Et.exports=Tn;function Tn(e,t={}){let r=t.debugTiming?E.time:E.notime;return r("layout",()=>{let n=r(" buildLayoutGraph",()=>An(e));return r(" runLayout",()=>jn(n,r,t)),r(" updateInputGraph",()=>_n(e,n)),n})}function jn(e,t,r){t(" makeSpaceForEdgeLabels",()=>Yn(e)),t(" removeSelfEdges",()=>Zn(e)),t(" acyclic",()=>ct.run(e)),t(" nestingGraph.run",()=>mt.run(e)),t(" rank",()=>Nn(E.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Wn(e)),t(" removeEmptyRanks",()=>qn(e)),t(" nestingGraph.cleanup",()=>mt.cleanup(e)),t(" normalizeRanks",()=>On(e)),t(" assignRankMinMax",()=>zn(e)),t(" removeEdgeLabelProxies",()=>Xn(e)),t(" normalize.run",()=>pt.run(e)),t(" parentDummyChains",()=>In(e)),t(" addBorderSegments",()=>Ln(e)),t(" order",()=>Rn(e,r)),t(" insertSelfEdges",()=>$n(e)),t(" adjustCoordinateSystem",()=>bt.adjust(e)),t(" position",()=>Cn(e)),t(" positionSelfEdges",()=>ei(e)),t(" removeBorderNodes",()=>Qn(e)),t(" normalize.undo",()=>pt.undo(e)),t(" fixupEdgeLabelCoords",()=>Jn(e)),t(" undoCoordinateSystem",()=>bt.undo(e)),t(" translateGraph",()=>Hn(e)),t(" assignNodeIntersects",()=>Un(e)),t(" reversePoints",()=>Kn(e)),t(" acyclic.undo",()=>ct.undo(e))}function _n(e,t){e.nodes().forEach(r=>{let n=e.node(r),i=t.node(r);n&&(n.x=i.x,n.y=i.y,n.order=i.order,n.rank=i.rank,t.children(r).length&&(n.width=i.width,n.height=i.height))}),e.edges().forEach(r=>{let n=e.edge(r),i=t.edge(r);n.points=i.points,Object.hasOwn(i,"x")&&(n.x=i.x,n.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var Sn=["nodesep","edgesep","ranksep","marginx","marginy"],Pn={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},Gn=["acyclicer","ranker","rankdir","align","rankalign"],Vn=["width","height","rank"],wt={width:0,height:0},Fn=["minlen","weight","width","height","labeloffset"],Bn={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Dn=["labelpos"];function An(e){let t=new Mn({multigraph:!0,compound:!0}),r=F(e.graph());return t.setGraph(Object.assign({},Pn,V(r,Sn),E.pick(r,Gn))),e.nodes().forEach(n=>{let i=F(e.node(n)),a=V(i,Vn);Object.keys(wt).forEach(o=>{a[o]===void 0&&(a[o]=wt[o])}),t.setNode(n,a),t.setParent(n,e.parent(n))}),e.edges().forEach(n=>{let i=F(e.edge(n));t.setEdge(n,Object.assign({},Bn,V(i,Fn),E.pick(i,Dn)))}),t}function Yn(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(r=>{let n=e.edge(r);n.minlen*=2,n.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?n.width+=n.labeloffset:n.height+=n.labeloffset)})}function Wn(e){e.edges().forEach(t=>{let r=e.edge(t);if(r.width&&r.height){let n=e.node(t.v),a={rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t};E.addDummyNode(e,"edge-proxy",a,"_ep")}})}function zn(e){let t=0;e.nodes().forEach(r=>{let n=e.node(r);n.borderTop&&(n.minRank=e.node(n.borderTop).rank,n.maxRank=e.node(n.borderBottom).rank,t=Math.max(t,n.maxRank))}),e.graph().maxRank=t}function Xn(e){e.nodes().forEach(t=>{let r=e.node(t);r.dummy==="edge-proxy"&&(e.edge(r.e).labelRank=r.rank,e.removeNode(t))})}function Hn(e){let t=Number.POSITIVE_INFINITY,r=0,n=Number.POSITIVE_INFINITY,i=0,a=e.graph(),o=a.marginx||0,l=a.marginy||0;function s(d){let u=d.x,h=d.y,f=d.width,c=d.height;t=Math.min(t,u-f/2),r=Math.max(r,u+f/2),n=Math.min(n,h-c/2),i=Math.max(i,h+c/2)}e.nodes().forEach(d=>s(e.node(d))),e.edges().forEach(d=>{let u=e.edge(d);Object.hasOwn(u,"x")&&s(u)}),t-=o,n-=l,e.nodes().forEach(d=>{let u=e.node(d);u.x-=t,u.y-=n}),e.edges().forEach(d=>{let u=e.edge(d);u.points.forEach(h=>{h.x-=t,h.y-=n}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=n)}),a.width=r-t+o,a.height=i-n+l}function Un(e){e.edges().forEach(t=>{let r=e.edge(t),n=e.node(t.v),i=e.node(t.w),a,o;r.points?(a=r.points[0],o=r.points[r.points.length-1]):(r.points=[],a=i,o=n),r.points.unshift(E.intersectRect(n,a)),r.points.push(E.intersectRect(i,o))})}function Jn(e){e.edges().forEach(t=>{let r=e.edge(t);if(Object.hasOwn(r,"x"))switch((r.labelpos==="l"||r.labelpos==="r")&&(r.width-=r.labeloffset),r.labelpos){case"l":r.x-=r.width/2+r.labeloffset;break;case"r":r.x+=r.width/2+r.labeloffset;break}})}function Kn(e){e.edges().forEach(t=>{let r=e.edge(t);r.reversed&&r.points.reverse()})}function Qn(e){e.nodes().forEach(t=>{if(e.children(t).length){let r=e.node(t),n=e.node(r.borderTop),i=e.node(r.borderBottom),a=e.node(r.borderLeft[r.borderLeft.length-1]),o=e.node(r.borderRight[r.borderRight.length-1]);r.width=Math.abs(o.x-a.x),r.height=Math.abs(i.y-n.y),r.x=a.x+r.width/2,r.y=n.y+r.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function Zn(e){e.edges().forEach(t=>{if(t.v===t.w){var r=e.node(t.v);r.selfEdges||(r.selfEdges=[]),r.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function $n(e){var t=E.buildLayerMatrix(e);t.forEach(r=>{var n=0;r.forEach((i,a)=>{var o=e.node(i);o.order=a+n,(o.selfEdges||[]).forEach(l=>{E.addDummyNode(e,"selfedge",{width:l.label.width,height:l.label.height,rank:o.rank,order:a+ ++n,e:l.e,label:l.label},"_se")}),delete o.selfEdges})})}function ei(e){e.nodes().forEach(t=>{var r=e.node(t);if(r.dummy==="selfedge"){var n=e.node(r.e.v),i=n.x+n.width/2,a=n.y,o=r.x-i,l=n.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:i+2*o/3,y:a-l},{x:i+5*o/6,y:a-l},{x:i+o,y:a},{x:i+5*o/6,y:a+l},{x:i+2*o/3,y:a+l}],r.label.x=r.x,r.label.y=r.y}})}function V(e,t){return E.mapValues(E.pick(e,t),Number)}function F(e){var t={};return e&&Object.entries(e).forEach(([r,n])=>{typeof r=="string"&&(r=r.toLowerCase()),t[r]=n}),t}});var xt=p((Mi,kt)=>{var ti=m(),ri=g("@dagrejs/graphlib").Graph;kt.exports={debugOrdering:ni};function ni(e){let t=ti.buildLayerMatrix(e),r=new ri({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(n=>{r.setNode(n,{label:n}),r.setParent(n,"layer"+e.node(n).rank)}),e.edges().forEach(n=>r.setEdge(n.v,n.w,{},n.name)),t.forEach((n,i)=>{let a="layer"+i;r.setNode(a,{rank:"same"}),n.reduce((o,l)=>(r.setEdge(o,l,{style:"invis"}),l))}),r}});var vt=p((Ti,yt)=>{yt.exports="2.0.4"});var ii=p((ji,Nt)=>{Nt.exports={graphlib:g("@dagrejs/graphlib"),layout:gt(),debug:xt(),util:{time:m().time,notime:m().notime},version:vt()}});return ii();})();
2
+ /*! For license information please see dagre.min.js.LEGAL.txt */
3
+ //# sourceMappingURL=dagre.min.js.map
@@ -0,0 +1,2 @@
1
+ var graphlib=(()=>{var ye=Object.defineProperty;var Ne=(s,e,r)=>e in s?ye(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var d=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var c=(s,e,r)=>Ne(s,typeof e!="symbol"?e+"":e,r);var w=d((cr,T)=>{"use strict";var je="\0",v="\0",D="",O=class{constructor(e){c(this,"_isDirected",!0);c(this,"_isMultigraph",!1);c(this,"_isCompound",!1);c(this,"_label");c(this,"_defaultNodeLabelFn",()=>{});c(this,"_defaultEdgeLabelFn",()=>{});c(this,"_nodes",{});c(this,"_in",{});c(this,"_preds",{});c(this,"_out",{});c(this,"_sucs",{});c(this,"_edgeObjs",{});c(this,"_edgeLabels",{});c(this,"_nodeCount",0);c(this,"_edgeCount",0);c(this,"_parent");c(this,"_children");e&&(this._isDirected=Object.hasOwn(e,"directed")?e.directed:!0,this._isMultigraph=Object.hasOwn(e,"multigraph")?e.multigraph:!1,this._isCompound=Object.hasOwn(e,"compound")?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[v]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn=e,typeof e!="function"&&(this._defaultNodeLabelFn=()=>e),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var e=this;return this.nodes().filter(r=>Object.keys(e._in[r]).length===0)}sinks(){var e=this;return this.nodes().filter(r=>Object.keys(e._out[r]).length===0)}setNodes(e,r){var t=arguments,i=this;return e.forEach(function(n){t.length>1?i.setNode(n,r):i.setNode(n)}),this}setNode(e,r){return Object.hasOwn(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=r),this):(this._nodes[e]=arguments.length>1?r:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=v,this._children[e]={},this._children[v][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return Object.hasOwn(this._nodes,e)}removeNode(e){var r=this;if(Object.hasOwn(this._nodes,e)){var t=i=>r.removeEdge(r._edgeObjs[i]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(function(i){r.setParent(i)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,r){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(r===void 0)r=v;else{r+="";for(var t=r;t!==void 0;t=this.parent(t))if(t===e)throw new Error("Setting "+r+" as parent of "+e+" would create a cycle");this.setNode(r)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=r,this._children[r][e]=!0,this}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}parent(e){if(this._isCompound){var r=this._parent[e];if(r!==v)return r}}children(e=v){if(this._isCompound){var r=this._children[e];if(r)return Object.keys(r)}else{if(e===v)return this.nodes();if(this.hasNode(e))return[]}}predecessors(e){var r=this._preds[e];if(r)return Object.keys(r)}successors(e){var r=this._sucs[e];if(r)return Object.keys(r)}neighbors(e){var r=this.predecessors(e);if(r){let i=new Set(r);for(var t of this.successors(e))i.add(t);return Array.from(i.values())}}isLeaf(e){var r;return this.isDirected()?r=this.successors(e):r=this.neighbors(e),r.length===0}filterNodes(e){var r=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});r.setGraph(this.graph());var t=this;Object.entries(this._nodes).forEach(function([a,o]){e(a)&&r.setNode(a,o)}),Object.values(this._edgeObjs).forEach(function(a){r.hasNode(a.v)&&r.hasNode(a.w)&&r.setEdge(a,t.edge(a))});var i={};function n(a){var o=t.parent(a);return o===void 0||r.hasNode(o)?(i[a]=o,o):o in i?i[o]:n(o)}return this._isCompound&&r.nodes().forEach(a=>r.setParent(a,n(a))),r}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn=e,typeof e!="function"&&(this._defaultEdgeLabelFn=()=>e),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,r){var t=this,i=arguments;return e.reduce(function(n,a){return i.length>1?t.setEdge(n,a,r):t.setEdge(n,a),a}),this}setEdge(){var e,r,t,i,n=!1,a=arguments[0];typeof a=="object"&&a!==null&&"v"in a?(e=a.v,r=a.w,t=a.name,arguments.length===2&&(i=arguments[1],n=!0)):(e=a,r=arguments[1],t=arguments[3],arguments.length>2&&(i=arguments[2],n=!0)),e=""+e,r=""+r,t!==void 0&&(t=""+t);var o=E(this._isDirected,e,r,t);if(Object.hasOwn(this._edgeLabels,o))return n&&(this._edgeLabels[o]=i),this;if(t!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(r),this._edgeLabels[o]=n?i:this._defaultEdgeLabelFn(e,r,t);var h=Ie(this._isDirected,e,r,t);return e=h.v,r=h.w,Object.freeze(h),this._edgeObjs[o]=h,L(this._preds[r],e),L(this._sucs[e],r),this._in[r][o]=h,this._out[e][o]=h,this._edgeCount++,this}edge(e,r,t){var i=arguments.length===1?m(this._isDirected,arguments[0]):E(this._isDirected,e,r,t);return this._edgeLabels[i]}edgeAsObj(){let e=this.edge(...arguments);return typeof e!="object"?{label:e}:e}hasEdge(e,r,t){var i=arguments.length===1?m(this._isDirected,arguments[0]):E(this._isDirected,e,r,t);return Object.hasOwn(this._edgeLabels,i)}removeEdge(e,r,t){var i=arguments.length===1?m(this._isDirected,arguments[0]):E(this._isDirected,e,r,t),n=this._edgeObjs[i];return n&&(e=n.v,r=n.w,delete this._edgeLabels[i],delete this._edgeObjs[i],F(this._preds[r],e),F(this._sucs[e],r),delete this._in[r][i],delete this._out[e][i],this._edgeCount--),this}inEdges(e,r){return this.isDirected()?this.filterEdges(this._in[e],e,r):this.nodeEdges(e,r)}outEdges(e,r){return this.isDirected()?this.filterEdges(this._out[e],e,r):this.nodeEdges(e,r)}nodeEdges(e,r){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,r)}filterEdges(e,r,t){if(e){var i=Object.values(e);return t?i.filter(function(n){return n.v===r&&n.w===t||n.v===t&&n.w===r}):i}}};function L(s,e){s[e]?s[e]++:s[e]=1}function F(s,e){--s[e]||delete s[e]}function E(s,e,r,t){var i=""+e,n=""+r;if(!s&&i>n){var a=i;i=n,n=a}return i+D+n+D+(t===void 0?je:t)}function Ie(s,e,r,t){var i=""+e,n=""+r;if(!s&&i>n){var a=i;i=n,n=a}var o={v:i,w:n};return t&&(o.name=t),o}function m(s,e){return E(s,e.v,e.w,e.name)}T.exports=O});var P=d((_r,A)=>{A.exports="3.0.4"});var S=d((pr,M)=>{M.exports={Graph:w(),version:P()}});var V=d((vr,G)=>{var ke=w();G.exports={write:xe,read:De};function xe(s){var e={options:{directed:s.isDirected(),multigraph:s.isMultigraph(),compound:s.isCompound()},nodes:Ce(s),edges:qe(s)};return s.graph()!==void 0&&(e.value=structuredClone(s.graph())),e}function Ce(s){return s.nodes().map(function(e){var r=s.node(e),t=s.parent(e),i={v:e};return r!==void 0&&(i.value=r),t!==void 0&&(i.parent=t),i})}function qe(s){return s.edges().map(function(e){var r=s.edge(e),t={v:e.v,w:e.w};return e.name!==void 0&&(t.name=e.name),r!==void 0&&(t.value=r),t})}function De(s){var e=new ke(s.options).setGraph(s.value);return s.nodes.forEach(function(r){e.setNode(r.v,r.value),r.parent&&e.setParent(r.v,r.parent)}),s.edges.forEach(function(r){e.setEdge({v:r.v,w:r.w,name:r.name},r.value)}),e}});var y=d((Er,U)=>{U.exports=Fe;var Le=()=>1;function Fe(s,e,r,t){return Te(s,String(e),r||Le,t||function(i){return s.outEdges(i)})}function Te(s,e,r,t){var i={},n=!0,a=0,o=s.nodes(),h=function(l){var _=r(l);i[l.v].distance+_<i[l.w].distance&&(i[l.w]={distance:i[l.v].distance+_,predecessor:l.v},n=!0)},u=function(){o.forEach(function(l){t(l).forEach(function(_){var q=_.v===l?_.v:_.w,Oe=q===_.v?_.w:_.v;h({v:q,w:Oe})})})};o.forEach(function(l){var _=l===e?0:Number.POSITIVE_INFINITY;i[l]={distance:_}});for(var f=o.length,p=1;p<f&&(n=!1,a++,u(),!!n);p++);if(a===f-1&&(n=!1,u(),n))throw new Error("The graph contains a negative weight cycle");return i}});var Y=d((gr,W)=>{W.exports=Ae;function Ae(s){var e={},r=[],t;function i(n){Object.hasOwn(e,n)||(e[n]=!0,t.push(n),s.successors(n).forEach(i),s.predecessors(n).forEach(i))}return s.nodes().forEach(function(n){t=[],i(n),t.length&&r.push(t)}),r}});var j=d((wr,z)=>{var N=class{constructor(){c(this,"_arr",[]);c(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(e){return e.key})}has(e){return Object.hasOwn(this._keyIndices,e)}priority(e){var r=this._keyIndices[e];if(r!==void 0)return this._arr[r].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(e,r){var t=this._keyIndices;if(e=String(e),!Object.hasOwn(t,e)){var i=this._arr,n=i.length;return t[e]=n,i.push({key:e,priority:r}),this._decrease(n),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,r){var t=this._keyIndices[e];if(r>this._arr[t].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[t].priority+" New: "+r);this._arr[t].priority=r,this._decrease(t)}_heapify(e){var r=this._arr,t=2*e,i=t+1,n=e;t<r.length&&(n=r[t].priority<r[n].priority?t:n,i<r.length&&(n=r[i].priority<r[n].priority?i:n),n!==e&&(this._swap(e,n),this._heapify(n)))}_decrease(e){for(var r=this._arr,t=r[e].priority,i;e!==0&&(i=e>>1,!(r[i].priority<t));)this._swap(e,i),e=i}_swap(e,r){var t=this._arr,i=this._keyIndices,n=t[e],a=t[r];t[e]=a,t[r]=n,i[a.key]=e,i[n.key]=r}};z.exports=N});var b=d((mr,H)=>{var Pe=j();H.exports=Se;var Me=()=>1;function Se(s,e,r,t){var i=function(n){return s.outEdges(n)};return Ge(s,String(e),r||Me,t||i)}function Ge(s,e,r,t){var i={},n=new Pe,a,o,h=function(u){var f=u.v!==a?u.v:u.w,p=i[f],l=r(u),_=o.distance+l;if(l<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+u+" Weight: "+l);_<p.distance&&(p.distance=_,p.predecessor=a,n.decrease(f,_))};for(s.nodes().forEach(function(u){var f=u===e?0:Number.POSITIVE_INFINITY;i[u]={distance:f},n.add(u,f)});n.size()>0&&(a=n.removeMin(),o=i[a],o.distance!==Number.POSITIVE_INFINITY);)t(a).forEach(h);return i}});var R=d((Or,K)=>{var Ve=b();K.exports=Ue;function Ue(s,e,r){return s.nodes().reduce(function(t,i){return t[i]=Ve(s,i,e,r),t},{})}});var Q=d((yr,B)=>{B.exports=We;function We(s,e,r){if(s[e].predecessor!==void 0)throw new Error("Invalid source vertex");if(s[r].predecessor===void 0&&r!==e)throw new Error("Invalid destination vertex");return{weight:s[r].distance,path:Ye(s,e,r)}}function Ye(s,e,r){for(var t=[],i=r;i!==e;)t.push(i),i=s[i].predecessor;return t.push(e),t.reverse()}});var I=d((Nr,J)=>{J.exports=ze;function ze(s){var e=0,r=[],t={},i=[];function n(a){var o=t[a]={onStack:!0,lowlink:e,index:e++};if(r.push(a),s.successors(a).forEach(function(f){Object.hasOwn(t,f)?t[f].onStack&&(o.lowlink=Math.min(o.lowlink,t[f].index)):(n(f),o.lowlink=Math.min(o.lowlink,t[f].lowlink))}),o.lowlink===o.index){var h=[],u;do u=r.pop(),t[u].onStack=!1,h.push(u);while(a!==u);i.push(h)}}return s.nodes().forEach(function(a){Object.hasOwn(t,a)||n(a)}),i}});var Z=d((jr,X)=>{var He=I();X.exports=Ke;function Ke(s){return He(s).filter(function(e){return e.length>1||e.length===1&&s.hasEdge(e[0],e[0])})}});var ee=d((Ir,$)=>{$.exports=Be;var Re=()=>1;function Be(s,e,r){return Qe(s,e||Re,r||function(t){return s.outEdges(t)})}function Qe(s,e,r){var t={},i=s.nodes();return i.forEach(function(n){t[n]={},t[n][n]={distance:0},i.forEach(function(a){n!==a&&(t[n][a]={distance:Number.POSITIVE_INFINITY})}),r(n).forEach(function(a){var o=a.v===n?a.w:a.v,h=e(a);t[n][o]={distance:h,predecessor:n}})}),i.forEach(function(n){var a=t[n];i.forEach(function(o){var h=t[o];i.forEach(function(u){var f=h[n],p=a[u],l=h[u],_=f.distance+p.distance;_<l.distance&&(l.distance=_,l.predecessor=p.predecessor)})})}),t}});var k=d((kr,te)=>{function re(s){var e={},r={},t=[];function i(n){if(Object.hasOwn(r,n))throw new g;Object.hasOwn(e,n)||(r[n]=!0,e[n]=!0,s.predecessors(n).forEach(i),delete r[n],t.push(n))}if(s.sinks().forEach(i),Object.keys(e).length!==s.nodeCount())throw new g;return t}var g=class extends Error{constructor(){super(...arguments)}};te.exports=re;re.CycleException=g});var ne=d((xr,se)=>{var ie=k();se.exports=Je;function Je(s){try{ie(s)}catch(e){if(e instanceof ie.CycleException)return!1;throw e}return!0}});var x=d((Cr,oe)=>{oe.exports=Xe;function Xe(s,e,r,t,i){Array.isArray(e)||(e=[e]);var n=(s.isDirected()?s.successors:s.neighbors).bind(s),a={};return e.forEach(function(o){if(!s.hasNode(o))throw new Error("Graph does not have node: "+o);i=ae(s,o,r==="post",a,n,t,i)}),i}function ae(s,e,r,t,i,n,a){return Object.hasOwn(t,e)||(t[e]=!0,r||(a=n(a,e)),i(e).forEach(function(o){a=ae(s,o,r,t,i,n,a)}),r&&(a=n(a,e))),a}});var C=d((qr,ue)=>{var Ze=x();ue.exports=$e;function $e(s,e,r){return Ze(s,e,r,function(t,i){return t.push(i),t},[])}});var de=d((Dr,he)=>{var er=C();he.exports=rr;function rr(s,e){return er(s,e,"post")}});var ce=d((Lr,fe)=>{var tr=C();fe.exports=ir;function ir(s,e){return tr(s,e,"pre")}});var _e=d((Fr,le)=>{var sr=w(),nr=j();le.exports=ar;function ar(s,e){var r=new sr,t={},i=new nr,n;function a(h){var u=h.v===n?h.w:h.v,f=i.priority(u);if(f!==void 0){var p=e(h);p<f&&(t[u]=n,i.decrease(u,p))}}if(s.nodeCount()===0)return r;s.nodes().forEach(function(h){i.add(h,Number.POSITIVE_INFINITY),r.setNode(h)}),i.decrease(s.nodes()[0],0);for(var o=!1;i.size()>0;){if(n=i.removeMin(),Object.hasOwn(t,n))r.setEdge(n,t[n]);else{if(o)throw new Error("Input graph is not connected: "+s);o=!0}s.nodeEdges(n).forEach(a)}return r}});var Ee=d((Tr,ve)=>{var pe=b(),or=y();ve.exports=ur;function ur(s,e,r,t){return hr(s,e,r,t||function(i){return s.outEdges(i)})}function hr(s,e,r,t){if(r===void 0)return pe(s,e,r,t);for(var i=!1,n=s.nodes(),a=0;a<n.length;a++){for(var o=t(n[a]),h=0;h<o.length;h++){var u=o[h],f=u.v===n[a]?u.v:u.w,p=f===u.v?u.w:u.v;r({v:f,w:p})<0&&(i=!0)}if(i)return or(s,e,r,t)}return pe(s,e,r,t)}});var we=d((Ar,ge)=>{ge.exports={bellmanFord:y(),components:Y(),dijkstra:b(),dijkstraAll:R(),extractPath:Q(),findCycles:Z(),floydWarshall:ee(),isAcyclic:ne(),postorder:de(),preorder:ce(),prim:_e(),shortestPaths:Ee(),reduce:x(),tarjan:I(),topsort:k()}});var dr=d((Pr,me)=>{var be=S();me.exports={Graph:be.Graph,json:V(),alg:we(),version:be.version}});return dr();})();
2
+ //# sourceMappingURL=graphlib.min.js.map
@@ -0,0 +1,107 @@
1
+ /**
2
+ * SmartCode ViewportTransform -- screen/graph coordinate conversion and zoom.
3
+ * Standalone class for managing a 2D viewport with pan and zoom.
4
+ *
5
+ * Dependencies: none
6
+ * Dependents: canvas-renderer.js (Plan 02)
7
+ *
8
+ * Usage:
9
+ * var vt = new ViewportTransform();
10
+ * vt.zoomToFit(graphW, graphH, containerW, containerH);
11
+ * var graphPt = vt.screenToGraph(mouseX, mouseY);
12
+ * var screenPt = vt.graphToScreen(nodeX, nodeY);
13
+ * vt.applyToElement(svgGroup);
14
+ */
15
+ (function() {
16
+ 'use strict';
17
+
18
+ /**
19
+ * ViewportTransform -- manages a 2D affine transform (translate + uniform scale).
20
+ * @constructor
21
+ */
22
+ function ViewportTransform() {
23
+ this.x = 0;
24
+ this.y = 0;
25
+ this.zoom = 1;
26
+ }
27
+
28
+ /**
29
+ * Convert screen (pixel) coordinates to graph coordinates.
30
+ * @param {number} screenX - Screen X position.
31
+ * @param {number} screenY - Screen Y position.
32
+ * @returns {{ x: number, y: number }}
33
+ */
34
+ ViewportTransform.prototype.screenToGraph = function(screenX, screenY) {
35
+ return {
36
+ x: (screenX - this.x) / this.zoom,
37
+ y: (screenY - this.y) / this.zoom,
38
+ };
39
+ };
40
+
41
+ /**
42
+ * Convert graph coordinates to screen (pixel) coordinates.
43
+ * @param {number} graphX - Graph X position.
44
+ * @param {number} graphY - Graph Y position.
45
+ * @returns {{ x: number, y: number }}
46
+ */
47
+ ViewportTransform.prototype.graphToScreen = function(graphX, graphY) {
48
+ return {
49
+ x: graphX * this.zoom + this.x,
50
+ y: graphY * this.zoom + this.y,
51
+ };
52
+ };
53
+
54
+ /**
55
+ * Adjust the viewport to fit the entire graph within a container.
56
+ * Applies padding and caps maximum zoom at 2.5x.
57
+ * @param {number} graphW - Total graph width.
58
+ * @param {number} graphH - Total graph height.
59
+ * @param {number} containerW - Container width in pixels.
60
+ * @param {number} containerH - Container height in pixels.
61
+ */
62
+ ViewportTransform.prototype.zoomToFit = function(graphW, graphH, containerW, containerH) {
63
+ if (graphW <= 0 || graphH <= 0 || containerW <= 0 || containerH <= 0) {
64
+ return;
65
+ }
66
+
67
+ var padFraction = 0.92;
68
+ var scaleX = (containerW * padFraction) / graphW;
69
+ var scaleY = (containerH * padFraction) / graphH;
70
+ this.zoom = Math.min(scaleX, scaleY, 2.5);
71
+
72
+ this.x = (containerW - graphW * this.zoom) / 2;
73
+ this.y = (containerH - graphH * this.zoom) / 2;
74
+ };
75
+
76
+ /**
77
+ * Apply the current transform to a DOM element via CSS transform.
78
+ * @param {HTMLElement|SVGElement} el - The element to transform.
79
+ */
80
+ ViewportTransform.prototype.applyToElement = function(el) {
81
+ el.style.transform = 'translate(' + this.x + 'px, ' + this.y + 'px) scale(' + this.zoom + ')';
82
+ };
83
+
84
+ /**
85
+ * Set the transform values directly.
86
+ * @param {number} x - Horizontal translation.
87
+ * @param {number} y - Vertical translation.
88
+ * @param {number} zoom - Zoom/scale factor.
89
+ */
90
+ ViewportTransform.prototype.setTransform = function(x, y, zoom) {
91
+ this.x = x;
92
+ this.y = y;
93
+ this.zoom = zoom;
94
+ };
95
+
96
+ /**
97
+ * Get the current transform values.
98
+ * @returns {{ x: number, y: number, zoom: number }}
99
+ */
100
+ ViewportTransform.prototype.getTransform = function() {
101
+ return { x: this.x, y: this.y, zoom: this.zoom };
102
+ };
103
+
104
+ // ── Public API ──
105
+ window.ViewportTransform = ViewportTransform;
106
+
107
+ })();
@@ -0,0 +1,202 @@
1
+ /**
2
+ * SmartCode Workspace Switcher -- dropdown to switch between multiple
3
+ * SmartCode server instances running on different ports.
4
+ *
5
+ * Reads the workspace registry via GET /api/workspaces and renders
6
+ * a dropdown in the topbar. When the user switches workspace, sets
7
+ * window.SmartCodeBaseUrl and triggers WS reconnect + file tree reload.
8
+ *
9
+ * Dependencies: ws-client.js (createReconnectingWebSocket), file-tree.js
10
+ * Loaded before app-init.js.
11
+ */
12
+ (function() {
13
+ 'use strict';
14
+
15
+ var POLL_INTERVAL = 10000; // 10s
16
+ var LS_KEY = 'smartcode-workspace-selection';
17
+
18
+ // ── State ──
19
+ var workspaces = [];
20
+ var currentWorkspace = null; // { name, dir, port, pid }
21
+ var pollTimer = null;
22
+
23
+ // ── Global base URL: empty string = current server (relative URLs) ──
24
+ window.SmartCodeBaseUrl = '';
25
+
26
+ // ── Helpers ──
27
+
28
+ function getLocalPort() {
29
+ return parseInt(location.port, 10) || (location.protocol === 'https:' ? 443 : 80);
30
+ }
31
+
32
+ function loadSelection() {
33
+ try {
34
+ var stored = localStorage.getItem(LS_KEY);
35
+ if (stored) return JSON.parse(stored);
36
+ } catch (e) {}
37
+ return null;
38
+ }
39
+
40
+ function saveSelection(ws) {
41
+ try {
42
+ localStorage.setItem(LS_KEY, JSON.stringify({ port: ws.port, dir: ws.dir }));
43
+ } catch (e) {}
44
+ }
45
+
46
+ // ── Fetch workspace list ──
47
+
48
+ function fetchWorkspaces() {
49
+ // Always fetch from the server we're connected to (current origin)
50
+ fetch('/api/workspaces')
51
+ .then(function(resp) { return resp.ok ? resp.json() : []; })
52
+ .then(function(data) {
53
+ if (!Array.isArray(data)) return;
54
+ workspaces = data;
55
+ reconcileSelection();
56
+ renderDropdown();
57
+ })
58
+ .catch(function() {
59
+ // Server might be down; keep last known list
60
+ });
61
+ }
62
+
63
+ function reconcileSelection() {
64
+ var localPort = getLocalPort();
65
+
66
+ // If no current workspace, default to the server we're connected to.
67
+ // Don't auto-restore a different port from localStorage — the user
68
+ // navigated to this port intentionally; cross-port restore causes
69
+ // 404s because the file tree shows local files but requests go elsewhere.
70
+ if (!currentWorkspace) {
71
+ var local = workspaces.find(function(w) { return w.port === localPort; });
72
+ if (local) {
73
+ currentWorkspace = local;
74
+ saveSelection(local);
75
+ return;
76
+ }
77
+ }
78
+
79
+ // Default: select the workspace running on this server's port
80
+ if (!currentWorkspace) {
81
+ currentWorkspace = workspaces.find(function(w) { return w.port === localPort; }) || workspaces[0] || null;
82
+ }
83
+
84
+ // Validate current selection still exists
85
+ if (currentWorkspace) {
86
+ var still = workspaces.find(function(w) { return w.port === currentWorkspace.port; });
87
+ if (!still) {
88
+ // Workspace disappeared; fall back to local
89
+ currentWorkspace = workspaces.find(function(w) { return w.port === localPort; }) || workspaces[0] || null;
90
+ if (currentWorkspace) applyBaseUrl(currentWorkspace);
91
+ }
92
+ }
93
+ }
94
+
95
+ // ── Apply base URL and trigger reconnection ──
96
+
97
+ function applyBaseUrl(ws) {
98
+ var localPort = getLocalPort();
99
+ if (ws.port === localPort) {
100
+ window.SmartCodeBaseUrl = '';
101
+ } else {
102
+ window.SmartCodeBaseUrl = 'http://localhost:' + ws.port;
103
+ }
104
+ }
105
+
106
+ function switchWorkspace(ws) {
107
+ if (currentWorkspace && currentWorkspace.port === ws.port) return;
108
+ currentWorkspace = ws;
109
+ saveSelection(ws);
110
+ applyBaseUrl(ws);
111
+
112
+ // Reconnect WebSocket to the new server
113
+ if (window.SmartCodeWsReconnect) {
114
+ window.SmartCodeWsReconnect(window.SmartCodeBaseUrl);
115
+ }
116
+
117
+ // Reload file tree from new server
118
+ if (window.SmartCodeFileTree) {
119
+ SmartCodeFileTree.refreshFileList();
120
+ }
121
+
122
+ renderDropdown();
123
+
124
+ if (window.toast) toast('Workspace: ' + ws.name);
125
+ }
126
+
127
+ // ── Dropdown UI ──
128
+
129
+ function renderDropdown() {
130
+ var container = document.getElementById('workspaceSwitcher');
131
+ if (!container) return;
132
+
133
+ // No workspaces at all — hide
134
+ if (workspaces.length === 0) {
135
+ container.textContent = '';
136
+ return;
137
+ }
138
+
139
+ container.textContent = '';
140
+ var select = document.createElement('select');
141
+ select.className = 'workspace-select';
142
+ select.title = 'Switch workspace';
143
+
144
+ for (var i = 0; i < workspaces.length; i++) {
145
+ var ws = workspaces[i];
146
+ var opt = document.createElement('option');
147
+ opt.value = String(ws.port);
148
+ opt.textContent = ws.name;
149
+ if (currentWorkspace && ws.port === currentWorkspace.port) {
150
+ opt.selected = true;
151
+ }
152
+ select.appendChild(opt);
153
+ }
154
+
155
+ select.addEventListener('change', function() {
156
+ var port = parseInt(select.value, 10);
157
+ var ws = workspaces.find(function(w) { return w.port === port; });
158
+ if (ws) switchWorkspace(ws);
159
+ });
160
+
161
+ container.appendChild(select);
162
+ }
163
+
164
+ // ── Init ──
165
+
166
+ function init() {
167
+ fetchWorkspaces();
168
+ pollTimer = setInterval(fetchWorkspaces, POLL_INTERVAL);
169
+
170
+ // Pause polling when tab is hidden, resume when visible
171
+ document.addEventListener('visibilitychange', function() {
172
+ if (document.hidden) {
173
+ if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
174
+ } else {
175
+ if (!pollTimer) {
176
+ fetchWorkspaces();
177
+ pollTimer = setInterval(fetchWorkspaces, POLL_INTERVAL);
178
+ }
179
+ }
180
+ });
181
+ }
182
+
183
+ function destroy() {
184
+ if (pollTimer) clearInterval(pollTimer);
185
+ }
186
+
187
+ // Start on DOM ready
188
+ if (document.readyState === 'loading') {
189
+ document.addEventListener('DOMContentLoaded', init);
190
+ } else {
191
+ init();
192
+ }
193
+
194
+ // ── Public API ──
195
+ window.SmartCodeWorkspaceSwitcher = {
196
+ init: init,
197
+ destroy: destroy,
198
+ getWorkspaces: function() { return workspaces; },
199
+ getCurrent: function() { return currentWorkspace; },
200
+ switchTo: switchWorkspace,
201
+ };
202
+ })();
@@ -0,0 +1,71 @@
1
+ // ws-client.js -- Reconnecting WebSocket client with exponential backoff + jitter
2
+ // Browser-native WebSocket API only -- no npm dependencies
3
+ //
4
+ // URL should be /ws for default project or /ws/project-name for named projects.
5
+ // For multi-project: change the URL to include the project namespace, e.g.,
6
+ // createReconnectingWebSocket('ws://localhost:3333/ws/my-project', ...)
7
+
8
+ /**
9
+ * Creates a WebSocket connection that automatically reconnects with exponential backoff.
10
+ *
11
+ * @param {string} url - WebSocket URL (e.g., 'ws://localhost:3333/ws' or 'ws://localhost:3333/ws/project-name')
12
+ * @param {function} onMessage - Called with parsed JSON message on each incoming message
13
+ * @param {function} onStatusChange - Called with status string: 'connected' | 'disconnected' | 'reconnecting'
14
+ * @returns {{ close: function }} - Object with close() method to teardown the connection
15
+ */
16
+ function createReconnectingWebSocket(url, onMessage, onStatusChange) {
17
+ var ws = null;
18
+ var attempt = 0;
19
+ var timer = null;
20
+ var BASE_DELAY = 500; // 500ms initial delay
21
+ var MAX_DELAY = 16000; // 16s cap
22
+ var MAX_ATTEMPTS = Infinity;
23
+
24
+ function connect() {
25
+ // Guard: don't create a new connection if one is already open or connecting
26
+ if (ws && ws.readyState < 2) return;
27
+
28
+ ws = new WebSocket(url);
29
+
30
+ ws.onopen = function () {
31
+ attempt = 0;
32
+ onStatusChange('connected');
33
+ };
34
+
35
+ ws.onmessage = function (event) {
36
+ try {
37
+ var msg = JSON.parse(event.data);
38
+ onMessage(msg);
39
+ } catch (e) {
40
+ console.error('WS parse error:', e);
41
+ }
42
+ };
43
+
44
+ ws.onclose = function () {
45
+ onStatusChange('disconnected');
46
+ scheduleReconnect();
47
+ };
48
+
49
+ ws.onerror = function () {
50
+ // No-op: onclose fires after onerror
51
+ };
52
+ }
53
+
54
+ function scheduleReconnect() {
55
+ var delay = Math.min(BASE_DELAY * Math.pow(2, attempt), MAX_DELAY);
56
+ var jitter = delay * (0.5 + Math.random() * 0.5); // 50-100% of delay
57
+ attempt++;
58
+ onStatusChange('reconnecting');
59
+ timer = setTimeout(connect, jitter);
60
+ }
61
+
62
+ function close() {
63
+ clearTimeout(timer);
64
+ if (ws) ws.close();
65
+ }
66
+
67
+ // Connect immediately
68
+ connect();
69
+
70
+ return { close: close };
71
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * SmartCode WebSocket Handler -- Processes incoming WebSocket messages.
3
+ * Extracted from app-init.js. Exposed as window.SmartCodeWsHandler.
4
+ * Dependencies: file-tree.js, editor-panel.js, annotations.js,
5
+ * custom-renderer.js, breakpoints.js, ghost-paths.js,
6
+ * heatmap.js, session-player.js
7
+ */
8
+ (function() {
9
+ 'use strict';
10
+
11
+ /**
12
+ * Handle incoming WebSocket messages.
13
+ * @param {object} msg - Parsed WebSocket message
14
+ * @param {object} ctx - Context object with:
15
+ * - getRendererType: function returning current renderer type
16
+ * - setRendererType: function(type) to update renderer type
17
+ * - selectRendererType: function(diagramType) to auto-select renderer
18
+ * - updateRendererIndicator: function to update UI indicator
19
+ * - renderWithType: async function(text) to render diagram
20
+ */
21
+ function handleMessage(msg, ctx) {
22
+ switch (msg.type) {
23
+ case 'graph:update':
24
+ if (msg.file === SmartCodeFileTree.getCurrentFile()) {
25
+ ctx.setRendererType(ctx.selectRendererType(msg.graph.diagramType));
26
+ if (ctx.getRendererType() === 'custom') {
27
+ SmartCodeCustomRenderer.render(msg.graph).catch(function(e) {
28
+ console.warn('Custom renderer failed on graph:update, keeping current render:', e.message);
29
+ });
30
+ }
31
+ ctx.updateRendererIndicator();
32
+ }
33
+ break;
34
+ case 'file:changed':
35
+ if (!SmartCodeEditorPanel.isAutoSync()) return;
36
+ if (msg.file === SmartCodeFileTree.getCurrentFile()) {
37
+ var wsText = msg.content;
38
+ if (wsText !== SmartCodeFileTree.getLastContent()) {
39
+ var finalText = wsText;
40
+ if (window.SmartCodeAnnotations && SmartCodeAnnotations.getState().flags.size > 0) {
41
+ finalText = SmartCodeAnnotations.mergeIncomingContent(wsText);
42
+ } else if (window.SmartCodeAnnotations) {
43
+ var incoming = SmartCodeAnnotations.parseAnnotations(wsText);
44
+ SmartCodeAnnotations.getState().flags = incoming.flags;
45
+ SmartCodeAnnotations.getState().statuses = incoming.statuses;
46
+ SmartCodeAnnotations.getState().breakpoints = incoming.breakpoints;
47
+ SmartCodeAnnotations.getState().risks = incoming.risks;
48
+ SmartCodeAnnotations.getState().ghosts = incoming.ghosts || [];
49
+ if (window.SmartCodeBreakpoints) SmartCodeBreakpoints.updateBreakpoints(incoming.breakpoints);
50
+ if (window.SmartCodeHeatmap) SmartCodeHeatmap.updateRisks(incoming.risks);
51
+ if (window.SmartCodeGhostPaths) SmartCodeGhostPaths.updateGhostPaths(msg.file, incoming.ghosts || []);
52
+ SmartCodeAnnotations.renderPanel();
53
+ SmartCodeAnnotations.updateBadge();
54
+ }
55
+ SmartCodeFileTree.setLastContent(finalText);
56
+ document.getElementById('editor').value = finalText;
57
+ if (ctx.getRendererType() !== 'custom') {
58
+ ctx.renderWithType(finalText);
59
+ }
60
+ }
61
+ }
62
+ break;
63
+ case 'breakpoint:hit':
64
+ if (window.SmartCodeBreakpoints) SmartCodeBreakpoints.showNotification(msg.nodeId);
65
+ break;
66
+ case 'breakpoint:continue':
67
+ if (window.SmartCodeBreakpoints) SmartCodeBreakpoints.hideNotification();
68
+ break;
69
+ case 'ghost:update':
70
+ if (window.SmartCodeGhostPaths) SmartCodeGhostPaths.updateGhostPaths(msg.file, msg.ghostPaths);
71
+ break;
72
+ case 'heatmap:update':
73
+ if (window.SmartCodeHeatmap) {
74
+ // Check if this is a full refresh or incremental delta
75
+ // Small deltas (1-3 keys) from record_step or click tracking: merge
76
+ // Full refreshes (many keys) from file switch: replace
77
+ var dataKeys = msg.data ? Object.keys(msg.data) : [];
78
+ if (dataKeys.length <= 3) {
79
+ SmartCodeHeatmap.mergeVisitCounts(msg.data);
80
+ } else {
81
+ SmartCodeHeatmap.updateVisitCounts(msg.data);
82
+ }
83
+ }
84
+ break;
85
+ case 'session:event':
86
+ if (window.SmartCodeSessionPlayer) SmartCodeSessionPlayer.handleSessionEvent(msg.sessionId, msg.event);
87
+ break;
88
+ case 'mcp-session:updated':
89
+ if (window.SmartCodeMcpSessions) SmartCodeMcpSessions.refresh();
90
+ break;
91
+ case 'file:added':
92
+ case 'file:removed':
93
+ case 'tree:updated':
94
+ SmartCodeFileTree.refreshFileList();
95
+ break;
96
+ }
97
+ }
98
+
99
+ function handleStatus(status) {
100
+ var dot = document.getElementById('statusDot');
101
+ var statusText = document.getElementById('statusText');
102
+ switch (status) {
103
+ case 'connected':
104
+ dot.className = 'status-dot';
105
+ statusText.textContent = 'Local Server';
106
+ statusText.title = 'Connected to SmartCode server via WebSocket.';
107
+ break;
108
+ case 'disconnected':
109
+ dot.className = 'status-dot paused';
110
+ statusText.textContent = 'Disconnected';
111
+ statusText.title = 'No connection to SmartCode server. Run: smartcode serve';
112
+ break;
113
+ case 'reconnecting':
114
+ dot.className = 'status-dot paused';
115
+ statusText.textContent = 'Reconnecting...';
116
+ statusText.title = 'Attempting to reconnect to SmartCode server...';
117
+ break;
118
+ }
119
+ }
120
+
121
+ window.SmartCodeWsHandler = {
122
+ handleMessage: handleMessage,
123
+ handleStatus: handleStatus,
124
+ };
125
+ })();