From: Thomas Walker Lynch Date: Mon, 3 Aug 2026 11:20:53 +0000 (+0000) Subject: working style structure refactor X-Git-Url: https://git.reasoningtechnology.com/%27%20%20%20window.RT.dirpr_library%20%20%20%27/RT-style.js?a=commitdiff_plain;h=71279b823c241afb1cebc24451b42bf00f668704;p=RT-Style working style structure refactor --- diff --git a/developer/authored/Manuscript.copy/Element/TOC.js b/developer/authored/Manuscript.copy/Element/TOC.js index 227a090..b91835a 100644 --- a/developer/authored/Manuscript.copy/Element/TOC.js +++ b/developer/authored/Manuscript.copy/Element/TOC.js @@ -20,23 +20,25 @@ Next heading 2 3 (function() { - if (!window.RT) { - console.error("RT not defined - was RT-Manuscript_make run?"); - return; - } - if (!window.RT.Element) { - console.error("RT.Element not defined - was the state_manager run?"); - return; - } + if (!window.RT) return; + + const apply_style = function(a, config) { + a.style.textDecoration = 'none'; + a.style.color = 'inherit'; + a.style.display = 'block'; + + a.onmouseover = () => a.style.color = config.brand_primary || '#000'; + a.onmouseout = () => a.style.color = 'inherit'; + }; RT.Element.add( function() { const debug = window.RT.Debug || { log: function(){} }; - const TOC_seq = document.querySelectorAll('rt·toc'); + const config = window.RT.layout_config || {}; + const TOC_seq = document.querySelectorAll('rt·toc, RT·TOC'); TOC_seq.forEach( (container ,TOC_index) => { container.style.display = 'block'; - // 1. Parse attribute: single number N or range A-B const attr_val = container.getAttribute('level'); let start_level, end_level; @@ -48,23 +50,16 @@ Next heading 2 3 if (a >= 1 && a <= 6 && b >= 1 && b <= 6 && a <= b) { start_level = a; end_level = b; - if (debug.log) debug.log('TOC', `TOC #${TOC_index} range: H${a}-H${b}`); - } else { - if (debug.log) debug.log('TOC', `Invalid range "${attr_val}" -> implicit mode`); - } + } } else { const single = parseInt(attr_val); if (!isNaN(single) && single >= 1 && single <= 6) { start_level = single; end_level = single; - if (debug.log) debug.log('TOC', `TOC #${TOC_index} single level: H${single}`); - } else { - if (debug.log) debug.log('TOC', `Invalid level "${attr_val}" -> implicit mode`); - } + } } } - // 2. Implicit mode (no attribute or invalid) if (start_level === undefined || end_level === undefined) { let context_level = 0; let prev = container.previousElementSibling; @@ -79,10 +74,8 @@ Next heading 2 3 const target_level = Math.min(context_level + 1, 6); start_level = target_level; end_level = target_level; - if (debug.log) debug.log('TOC', `TOC #${TOC_index} implicit target: H${target_level}`); } - // 3. Collect all matching headings until a higher-level heading stops us const headings = []; let next_el = container.nextElementSibling; while (next_el) { @@ -90,12 +83,9 @@ Next heading 2 3 if (match) { const found_level = parseInt(match[1]); - // Stop if we hit a heading that is a parent of the lowest level we collect if (found_level < start_level) break; - // Collect if within the requested range if (found_level >= start_level && found_level <= end_level) { - // Ensure it has an id if (!next_el.id) { next_el.id = `TOC-ref-${TOC_index}-${found_level}-${headings.length}`; } @@ -105,36 +95,29 @@ Next heading 2 3 next_el = next_el.nextElementSibling; } - // 4. Build the container (title + list) container.innerHTML = ''; const title = document.createElement('h1'); title.textContent = start_level === 1 ? 'Table of Contents' : 'Section Contents'; title.style.textAlign = 'center'; container.appendChild(title); - if (headings.length === 0) return; // nothing to show + if (headings.length === 0) return; - // Top-level list const topList = document.createElement('ul'); topList.style.listStyle = 'none'; topList.style.paddingLeft = '0'; topList.style.marginBottom = '0'; container.appendChild(topList); - // Stack of