Files
pymc_console-dist/frontend/dist/assets/PathMapMapLibre-CKO2fNHB.js
T
GitHub Actions Bot 824b85edee Sync build v0.9.192
Automated sync from private repository.
Commit: a7ee3749c3d0cdb16ec9916a90d6e0c32f343ab3
2026-01-27 07:29:45 +00:00

2 lines
9.3 KiB
JavaScript

import{r as e,j as t,bx as o,by as r,bz as n,bA as i,bB as a,aC as s,m as l,a8 as d}from"./vendor-react-LAbPDfrQ.js";import"./maplibre-gl-Bk5DsYkB.js";import{c}from"./recharts-D38YBQhj.js";import{u,B as p}from"./BasemapLayer-D6Rvk89s.js";import{h as m,s as h,p as g}from"./useThemeColors-BZADUK_r.js";import{E as x,B as f}from"./index-DSST4Vwq.js";import"./vendor-core-WoOfkQwm.js";import"./deckgl-DTsmDcfs.js";const b={version:8,sources:{},layers:[],glyphs:"https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf"},y={nodeColor:"#4338CA",localColor:"#4F46E5",hubColor:"#6366F1",edgeColor:"#3B3F4A",ambiguousColor:"#F9D26F",highlightColor:"#B49DFF",sourceColor:"#39D98A",destinationColor:"#B49DFF"};function C(e,t){if(!e)return t;if(e.startsWith("#"))return e;const o=g(e);return o?`#${o.r.toString(16).padStart(2,"0")}${o.g.toString(16).padStart(2,"0")}${o.b.toString(16).padStart(2,"0")}`:t}function v(){if("undefined"==typeof document)return y;const e=document.documentElement,t=getComputedStyle(e);return{nodeColor:C(t.getPropertyValue("--map-node-stroke").trim(),y.nodeColor),localColor:C(t.getPropertyValue("--map-local-color").trim(),y.localColor),hubColor:C(t.getPropertyValue("--map-hub-color").trim(),y.hubColor),edgeColor:C(t.getPropertyValue("--map-edge-rest").trim(),y.edgeColor),ambiguousColor:C(t.getPropertyValue("--accent-secondary").trim(),y.ambiguousColor),highlightColor:C(t.getPropertyValue("--accent-primary").trim(),y.highlightColor),sourceColor:C(t.getPropertyValue("--accent-success").trim(),y.sourceColor),destinationColor:C(t.getPropertyValue("--accent-primary").trim(),y.destinationColor)}}function j({prefix:o,isLocal:r,isSource:n,isDestination:i,isLastHop:a,isHighlighted:u,isAnimating:p,candidate:m,onHover:h,onLeave:g,onClick:x}){const b=s(),[y,C]=e.useState(!1);e.useEffect(()=>{p&&b.start({boxShadow:["0 0 0 0px rgba(113, 156, 223, 0)","0 0 0 2px rgba(113, 156, 223, 0.5)","0 0 0 2px rgba(113, 156, 223, 0.5)","0 0 0 0px rgba(113, 156, 223, 0)"],transition:{duration:.5,times:[0,.2,.7,1],ease:"easeInOut"}})},[p,b]);const v=e.useCallback(()=>{C(!0),h()},[h]),j=e.useCallback(()=>{C(!1),g()},[g]);return t.jsx(l.div,{className:c("flex items-center cursor-pointer","transition-all duration-150",u&&"ring-2 ring-accent-primary/50 rounded"),animate:b,initial:{boxShadow:"0 0 0 0px rgba(113, 156, 223, 0)"},onMouseEnter:v,onMouseLeave:j,onClick:x,style:{pointerEvents:"auto"},children:t.jsxs(f,{color:r?"amber":n?"green":a?"amber":i?"purple":"blue",filled:!0,className:"font-mono text-[10px] shadow-lg border border-current/30",children:[r&&t.jsx(d,{className:"w-2.5 h-2.5 mr-1"}),o,y&&m.name&&t.jsx("span",{className:"ml-1 opacity-75",children:m.name})]})})}function k({hopNumber:e,isLastHop:o,snr:r}){return t.jsxs("div",{className:"flex flex-col items-center gap-0.5 pointer-events-none",children:[t.jsx(f,{color:o?"amber":"blue",filled:!0,compact:!0,className:"!rounded-full !px-1.5 !py-0.5 !text-[10px] font-bold tabular-nums shadow-md",children:e}),void 0!==r&&t.jsx(f,{color:"zinc",compact:!0,className:"!text-[9px] font-mono tabular-nums shadow-sm",children:r.toFixed(1)})]})}function S({resolvedPath:s,localNode:l,hubNodes:d=[],hoveredHopIndex:g,onHoverHop:f,traceSnr:y}){const C=void 0!==y&&y.length>0,S=e.useRef(null),N=u(),F=e.useMemo(()=>new Set(d),[d]),[L,w]=e.useState(null),P=x(),[D,E]=e.useState(!1),[H,$]=e.useState(0);e.useEffect(()=>{var e;const t=null==(e=S.current)?void 0:e.getMap();if(!t)return;const o=t.getCanvas();if(!o)return;const r=e=>{e.preventDefault()},n=()=>{$(e=>e+1)};return o.addEventListener("webglcontextlost",r),o.addEventListener("webglcontextrestored",n),()=>{o.removeEventListener("webglcontextlost",r),o.removeEventListener("webglcontextrestored",n)}},[H]);const{positions:M,markers:B,pathLineGeoJSON:V,edges:A}=e.useMemo(()=>{const e=[],t=[],o=[],r=[];let n=0;s.hops.forEach((i,a)=>{const s=i.candidates.filter(e=>{return t=e.latitude,o=e.longitude,0!==t||0!==o;var t,o});if(0===s.length)return;const l=[...s].sort((e,t)=>t.probability-e.probability)[0],d=[l.longitude,l.latitude];if(o.push(d),o.length>=2){const e=o[o.length-2],t=o.length-2,n=null==y?void 0:y[t],i=d[0]-e[0],a=d[1]-e[1],s=Math.atan2(i,a)*(180/Math.PI);r.push({from:e,to:d,snrFwd:n,midpoint:[(e[0]+d[0])/2,(e[1]+d[1])/2],bearing:s})}const c=!0===i.isSource,u=!0===i.isDestination;s.forEach((o,r)=>{const l=[o.latitude,o.longitude];e.push(l);const d=0===r;t.push({position:l,prefix:i.prefix,confidence:i.confidence,candidateCount:s.length,hopIndex:a,candidate:o,isHub:F.has(o.hash),isPrimary:d,isSource:c,isDestination:u,validIndex:n})}),n++});const i={type:"FeatureCollection",features:o.length>=2?[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:o}}]:[]};return{positions:e,markers:t,pathLineGeoJSON:i,edges:r}},[s,F,y]),I=e.useMemo(()=>{const e=B.filter(e=>e.isPrimary&&(e.confidence>=.5||e.isSource||e.isDestination));if(0===e.length)return null;let t=1/0,o=-1/0,r=1/0,n=-1/0;for(const i of e){const[e,a]=i.position;e<t&&(t=e),e>o&&(o=e),a<r&&(r=a),a>n&&(n=a)}return[[r,t],[n,o]]},[B]),O=e.useMemo(()=>{if(0===M.length)return l?[l.longitude,l.latitude]:[0,0];let e=0,t=0;for(const[o,r]of M)e+=o,t+=r;return[t/M.length,e/M.length]},[M,l]),z=e.useCallback(()=>{var e;const t=null==(e=S.current)?void 0:e.getMap();t&&I?(t.fitBounds(I,{padding:{top:50,bottom:50,left:50,right:50},maxZoom:15,duration:0}),setTimeout(()=>{E(!0)},50)):E(!0)},[I]),T=e.useMemo(()=>I?`${I[0][0].toFixed(5)},${I[0][1].toFixed(5)},${I[1][0].toFixed(5)},${I[1][1].toFixed(5)}`:"",[I]);e.useEffect(()=>{var e;if(!D)return;const t=null==(e=S.current)?void 0:e.getMap();t&&I&&t.fitBounds(I,{padding:{top:50,bottom:50,left:50,right:50},maxZoom:15,duration:300})},[T,D,I]);const G=P&&D,J=e.useCallback(e=>{w({longitude:e.position[1],latitude:e.position[0],marker:e})},[]);return 0===M.length?t.jsx("div",{className:"h-full flex items-center justify-center text-text-muted text-sm bg-bg-elevated",children:"No mappable path data"}):t.jsxs("div",{className:"h-full w-full relative",children:[t.jsx("div",{className:c("absolute inset-0 bg-bg-elevated flex items-center justify-center","transition-opacity duration-200 ease-out pointer-events-none",G?"opacity-0":"opacity-100"),children:t.jsx("div",{className:"w-5 h-5 border-2 border-text-muted/30 border-t-text-muted rounded-full animate-spin"})}),t.jsx("div",{className:"h-full w-full transition-opacity duration-300 ease-out",style:{opacity:G?1:0},children:t.jsxs(o,{ref:S,initialViewState:{longitude:O[0],latitude:O[1],zoom:10},onLoad:z,style:{height:"100%",width:"100%"},mapStyle:b,attributionControl:!1,children:[t.jsx(p,{mode:N}),C?A.map((e,o)=>{const i=void 0!==e.snrFwd?m()[h(e.snrFwd)]||"#6b7280":"#71717a",a={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e.from,e.to]}}]};return t.jsx(r,{id:`edge-${o}`,type:"geojson",data:a,children:t.jsx(n,{id:`edge-line-${o}`,type:"line",paint:{"line-color":i,"line-width":4,"line-opacity":1},layout:{"line-cap":"round","line-join":"round"}})},`edge-${o}`)}):V.features.length>0&&t.jsx(r,{id:"path-line-source",type:"geojson",data:V,children:t.jsx(n,{id:"path-line",type:"line",paint:{"line-color":v().edgeColor,"line-width":3,"line-opacity":1},layout:{"line-cap":"round","line-join":"round"}})}),A.map((e,o)=>t.jsx(i,{longitude:e.midpoint[0],latitude:e.midpoint[1],anchor:"center",children:t.jsx(k,{hopNumber:o+1,isLastHop:o===A.length-1,snr:C?e.snrFwd:void 0})},`hop-${o}`)),(()=>{const e=B.filter(e=>e.isPrimary),o=e.length>1?e.length-2:-1;return e.map((e,r)=>{const n=g===e.hopIndex,a=r===o&&!e.candidate.isLocal&&!e.isDestination;return t.jsx(i,{longitude:e.position[1],latitude:e.position[0],anchor:"center",children:t.jsx(j,{prefix:e.prefix,isLocal:e.candidate.isLocal||!1,isSource:e.isSource,isDestination:e.isDestination,isLastHop:a,isHighlighted:n,isAnimating:!1,candidate:e.candidate,onHover:()=>null==f?void 0:f(e.hopIndex),onLeave:()=>null==f?void 0:f(null),onClick:()=>J(e)})},`${e.hopIndex}-${e.candidate.hash}`)})})(),L&&t.jsx(a,{longitude:L.longitude,latitude:L.latitude,anchor:"bottom",offset:[0,-12],closeOnClick:!1,onClose:()=>w(null),className:"maplibre-popup",children:t.jsxs("div",{className:"text-xs",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"font-semibold",children:L.marker.candidate.name}),(()=>{const e=v();return t.jsxs(t.Fragment,{children:[L.marker.isSource&&t.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:e.sourceColor,color:"#000"},children:"SRC"}),L.marker.isDestination&&t.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:e.destinationColor,color:"#000"},children:"DST"}),L.marker.isHub&&t.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:e.hubColor,color:"#000"},children:"HUB"}),L.marker.candidate.isLocal&&t.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:e.localColor,color:"#fff"},children:"LOCAL"})]})})()]}),t.jsxs("div",{className:"text-text-muted font-mono text-[10px]",children:[L.marker.prefix," • ",L.marker.candidate.hash.slice(0,10),"..."]}),!L.marker.isPrimary&&L.marker.candidateCount>1&&t.jsxs("div",{style:{color:v().ambiguousColor},children:["Alternative (",(100*L.marker.candidate.probability).toFixed(0),"%)"]}),L.marker.isPrimary&&L.marker.candidateCount>1&&t.jsxs("div",{className:"text-text-muted",children:[L.marker.candidateCount," candidates"]})]})})]},H)})]})}export{S as default};