code-ranker-viewer 1.0.0-alpha.5

Code Ranker HTML viewer: self-contained interactive report with embedded snapshots.
Documentation
document.addEventListener('DOMContentLoaded', async () => {
  window.nodeSizeMode = null;
  window.drillGroup   = null;
  window.dig         = 0;   // relative LOD on the overview (see grouping.js)
  window.drillDig    = 0;
  window.cycleOnly   = false;   // cycle filter (show only nodes in cycles)

  // Read the snapshots embedded inline in the page (cs-baseline / cs-current script tags).
  window.BASELINE = readEmbeddedSnapshot('cs-baseline');
  window.CURRENT  = readEmbeddedSnapshot('cs-current');

  const EMPTY = { graphs: {} };
  window.DIFF   = computeDiff(window.BASELINE ?? window.CURRENT ?? EMPTY, window.CURRENT ?? window.BASELINE ?? EMPTY);
  window.CYCLES = computeCycles(window.BASELINE ?? window.CURRENT ?? EMPTY, window.CURRENT ?? window.BASELINE ?? EMPTY);
  window.META   = computeMeta(window.BASELINE, window.CURRENT);

  // Restore the active side from the URL (`side=baseline/current`); default to the
  // current (primary) snapshot. `baseline` is only honoured when a baseline exists.
  const urlSide = getNavParams().side;
  window.viewSide = (urlSide === 'baseline' && window.BASELINE) ? 'baseline'
                  : window.CURRENT ? 'current'
                  : 'baseline';
  // If the Prompt Generator was open (state in the URL), restore its selected
  // nodes before the tables render so those rows come up already selected.
  const epState = (typeof epReadUrl === 'function') ? epReadUrl() : null;
  if (epState?.sel?.length) {
    if (!window._ntSelected) window._ntSelected = {};
    window._ntSelected[epState.level] = new Set(epState.sel);
  }
  document.querySelectorAll('.view').forEach(sec => setupNodeTable(sec, sec.dataset.view));
  setupSnapPopup();
  setupModeToggle();
  setupFileControls();
  setupTooltip();
  buildSummary();
  updateFilesTab();
  updateHeader();

  document.getElementById('summary-header')?.addEventListener('click', () => {
    document.querySelector('.summary').classList.toggle('collapsed');
  });


  const active = document.querySelector('.view.active');
  const loading = active?.querySelector('.loading-indicator');
  if (loading) { loading.textContent = 'Loading Graphviz…'; loading.classList.add('on'); }

  window.gv = await window['@hpcc-js/wasm/graphviz'].Graphviz.load();

  renderView(active);


  // Restore state from URL, then set initial history entry
  const { level: urlLevel, node: urlNode, group: urlGroup, mode: urlMode, dig: urlDig } = getNavParams();
  if (urlLevel && urlLevel !== currentLevel()) switchToLevel(urlLevel);
  applyViewState({ level: urlLevel, group: urlGroup, mode: urlMode, dig: urlDig }, { rerender: !!(urlGroup || urlMode || urlDig) });
  if (urlNode) openModalForNode(urlNode, urlLevel ?? currentLevel());
  // Replace initial history state so popstate can restore it
  history.replaceState(
    { level: currentLevel(), node: urlNode ?? null, group: urlGroup ?? null, mode: urlMode ?? null, dig: window.dig || 0, side: window.viewSide },
    '', location.href
  );

  // Re-open the Prompt Generator if the URL says it was open.
  if (epState) {
    if (epState.level && epState.level !== currentLevel()) switchToLevel(epState.level);
    openExportPopup(epState.level, epState);
  }

  window.addEventListener('popstate', e => {
    const st   = e.state || getNavParams();
    const lvl  = st.level;
    const nid  = st.node;
    const side = st.side;
    if (window.CURRENT && (side === 'baseline' || side === 'current')) setViewSide(side);
    if (lvl && lvl !== currentLevel()) switchToLevel(lvl);
    applyViewState({ level: lvl ?? currentLevel(), group: st.group, mode: st.mode, dig: st.dig }, { rerender: true });
    if (nid) {
      openModalForNode(nid, lvl ?? currentLevel());
    } else {
      closeModalSilent();
    }
  });
});