From: Thomas Walker Lynch Date: Sun, 28 Jun 2026 16:52:04 +0000 (+0000) Subject: elements self queue on load, still no pagination X-Git-Url: https://git.reasoningtechnology.com/RT-Manuscript_locator.js?a=commitdiff_plain;h=721a9fd64ec6818816f8b6ede8cf2a4bc4bbc553;p=RT-Style elements self queue on load, still no pagination --- diff --git a/developer/authored/Manuscript.copy/Core/RT-Style_make.js b/developer/authored/Manuscript.copy/Core/RT-Style_make.js index f5faef9..4784075 100644 --- a/developer/authored/Manuscript.copy/Core/RT-Style_make.js +++ b/developer/authored/Manuscript.copy/Core/RT-Style_make.js @@ -1,11 +1,8 @@ // Core/loader.js window.RT = window.RT || {}; -window.RT.Element = []; window.RT.Module = window.RT.Module || new Set(); - - // 2. Establish the Debug System window.RT.Debug = { active_tokens: new Set([ diff --git a/developer/authored/Manuscript.copy/Core/stage_manager.js b/developer/authored/Manuscript.copy/Core/stage_manager.js index 2f980d7..de03a79 100644 --- a/developer/authored/Manuscript.copy/Core/stage_manager.js +++ b/developer/authored/Manuscript.copy/Core/stage_manager.js @@ -1,11 +1,10 @@ -// Core/document_loaded.js +// Core/stage_manager.js -window.RT = window.RT || {}; -window.RT.Element = window.RT.Element || []; -window.RT.Module = window.RT.Module || new Set(); +RT = RT || {}; +RT.Element = RT.Element || new Set(); (function(){ - const debug = window.RT.Debug || { log: function(){} }; + const debug = RT.Debug || { log: function(){} }; let target_y = 0; let is_reload = false; @@ -91,7 +90,7 @@ window.RT.Module = window.RT.Module || new Set(); function execute_pagination_and_scroll(){ debug.log('scroll' ,`Pagination layout starting.`); - if(window.RT.paginate_by_element) window.RT.paginate_by_element(); + if(RT.paginate_by_element) RT.paginate_by_element(); let final_target = target_y; let use_hash = false; @@ -108,11 +107,17 @@ window.RT.Module = window.RT.Module || new Set(); function process_elements_and_layout() { debug.log('lifecycle', 'Processing registered elements.'); - if (window.RT.Element && Array.isArray(window.RT.Element)) { - while (window.RT.Element.length > 0) { - const element_fn = window.RT.Element.shift(); + if (RT.Element instanceof Set && RT.Element.size > 0) { + for (const element_fn of RT.Element) { if (typeof element_fn === 'function') { element_fn(); + } else { + // Fallback warning if your debug utility is not available + if (RT.Debug?.warn) { + RT.Debug.warn('layout', 'Invalid element in RT.Element Set: ' + element_fn); + } else { + console.warn('Invalid element in RT.Element Set:', element_fn); + } } } } @@ -124,6 +129,7 @@ window.RT.Module = window.RT.Module || new Set(); } } + // Initial Execution lock_layout(); configure_history(); @@ -132,7 +138,7 @@ window.RT.Module = window.RT.Module || new Set(); document.addEventListener('DOMContentLoaded', process_elements_and_layout); - // Structural Safety Net: restore visibility on load if layout engine hangs + // Safety Net: restore visibility on load if layout engine hangs window.addEventListener("load", unlock_layout); })(); diff --git a/developer/authored/Manuscript.copy/Document/manual.html b/developer/authored/Manuscript.copy/Document/manual.html index c81adc2..6611972 100644 --- a/developer/authored/Manuscript.copy/Document/manual.html +++ b/developer/authored/Manuscript.copy/Document/manual.html @@ -5,7 +5,7 @@ RT Style System: Reference Manual diff --git a/developer/authored/Manuscript.copy/Element/TOC.js b/developer/authored/Manuscript.copy/Element/TOC.js index 1aa0eef..494b90a 100644 --- a/developer/authored/Manuscript.copy/Element/TOC.js +++ b/developer/authored/Manuscript.copy/Element/TOC.js @@ -18,145 +18,156 @@ Next heading 2 3 */ -window.RT = window.RT || {}; - -window.RT.TOC = function(){ - const debug = window.RT.Debug || { log: function(){} }; - const TOC_seq = document.querySelectorAll('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; - - if (attr_val) { - const rangeMatch = attr_val.match(/^(\d)-(\d)$/); - if (rangeMatch) { - const a = parseInt(rangeMatch[1]); - const b = parseInt(rangeMatch[2]); - 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}`); +(function() { + + if (!window.RT) { + console.error("RT not defined - was RT-Style_make run?"); + return; + } + if (!window.RT.Element) { + console.error("RT.Element not defined - was the state_manager run?"); + return; + } + + RT.Element.add( function() { + const debug = window.RT.Debug || { log: function(){} }; + const TOC_seq = document.querySelectorAll('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; + + if (attr_val) { + const rangeMatch = attr_val.match(/^(\d)-(\d)$/); + if (rangeMatch) { + const a = parseInt(rangeMatch[1]); + const b = parseInt(rangeMatch[2]); + 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 { - if (debug.log) debug.log('TOC', `Invalid level "${attr_val}" → implicit mode`); + 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; - while (prev) { - const match = prev.tagName.match(/^H([1-6])$/); - if (match) { - context_level = parseInt(match[1]); - break; + + // 2. Implicit mode (no attribute or invalid) + if (start_level === undefined || end_level === undefined) { + let context_level = 0; + let prev = container.previousElementSibling; + while (prev) { + const match = prev.tagName.match(/^H([1-6])$/); + if (match) { + context_level = parseInt(match[1]); + break; + } + prev = prev.previousElementSibling; } - prev = prev.previousElementSibling; + 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}`); } - 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) { - const match = next_el.tagName.match(/^H([1-6])$/); - 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}`; + + // 3. Collect all matching headings until a higher-level heading stops us + const headings = []; + let next_el = container.nextElementSibling; + while (next_el) { + const match = next_el.tagName.match(/^H([1-6])$/); + 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}`; + } + headings.push({ el: next_el, level: found_level }); } - headings.push({ el: next_el, level: found_level }); } - } - 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 - - // Top-level list - const topList = document.createElement('ul'); - topList.style.listStyle = 'none'; - topList.style.paddingLeft = '0'; - container.appendChild(topList); - - // Stack of