import { Elena, html, unsafeHTML } from '@elenajs/core'; import type { TocEntry } from '../extract-headings.js'; /** * * Renders the table of contents as anchor links. * Light DOM — no shadow root traversal needed for scroll targets. * */ export class StarlightToc extends Elena(HTMLElement) { static tagName = 'starlight-toc'; static props = ['entries']; entries: TocEntry[] = []; handleClick(e: MouseEvent, slug: string) { e.preventDefault(); // Light DOM — headings are directly queryable in the document const sel = `#${CSS.escape(slug)}`; const target = document.querySelector(sel); if (target) target.scrollIntoView({ behavior: 'smooth' }); history.pushState(null, '', `#${slug}`); } render() { if (!this.entries || this.entries.length === 0) return html``; const items = this.entries.map(entry => `
  • ${entry.text}
  • ` ).join(''); return html` `; } } StarlightToc.define(); export default StarlightToc;