src/options/log-section.ts

Total Symbols
2
Lines of Code
50
Avg Complexity
3.5
Symbol Types
1

File Relationships

graph LR initLogTab["initLogTab"] setupViewer["setupViewer"] initLogTab -->|calls| setupViewer click initLogTab "../symbols/f0e7324e99722ddb.html" click setupViewer "../symbols/b9fbe5505eaeb3e4.html"

Symbols by Kind

function 2

All Symbols

Name Kind Visibility Status Lines Signature
initLogTab function exported- 12-39 initLogTab(): : void
setupViewer function - 41-49 setupViewer(): : void

Full Source

/**
 * Options page — Log tab section.
 *
 * Renders a persistent log viewer using the shared log-viewer component.
 */

import type { LogViewer } from "@/lib/logger/log-viewer";
import { createLogViewer, getLogViewerStyles } from "@/lib/logger/log-viewer";

let viewer: LogViewer | null = null;

export function initLogTab(): void {
  // Inject log viewer styles once
  const style = document.createElement("style");
  style.textContent = getLogViewerStyles("options");
  document.head.appendChild(style);

  // Observe when the log tab becomes visible to init the viewer
  const tabContent = document.getElementById("tab-log");
  if (!tabContent) return;

  const observer = new MutationObserver(() => {
    if (tabContent.classList.contains("active")) {
      setupViewer();
      observer.disconnect();
    }
  });

  observer.observe(tabContent, {
    attributes: true,
    attributeFilter: ["class"],
  });

  // Also check if already active (e.g. deep link)
  if (tabContent.classList.contains("active")) {
    setupViewer();
    observer.disconnect();
  }
}

function setupViewer(): void {
  if (viewer) return;

  const container = document.getElementById("options-log-viewer");
  if (!container) return;

  viewer = createLogViewer({ container, variant: "options" });
  void viewer.refresh();
}