From: Thomas Walker Lynch Date: Thu, 6 Aug 2026 07:33:30 +0000 (+0000) Subject: before grid split X-Git-Url: https://git.reasoningtechnology.com/?a=commitdiff_plain;h=b84adbd7ff4f994acd3330bf0fcf64c81de85bab;p=RT-Style before grid split --- diff --git a/developer/authored/Manuscript.copy/Layout/paginate.js b/developer/authored/Manuscript.copy/Layout/paginate.js index 8d75373..03cdc31 100644 --- a/developer/authored/Manuscript.copy/Layout/paginate.js +++ b/developer/authored/Manuscript.copy/Layout/paginate.js @@ -18,6 +18,7 @@ let measure_container = null; + // 1. DOM Measurement Utilities function get_el_height(el){ const was_in_DOM = el.parentNode !== null; if(!was_in_DOM) document.body.appendChild(el); @@ -62,16 +63,17 @@ return h; } + // Splitting Logic function is_splittable(el){ if(!el || el.nodeType !== Node.ELEMENT_NODE) return null; const component_id = el.getAttribute('data-rt-component'); if(component_id && window.RT.Component && window.RT.Component[component_id] && window.RT.Component[component_id].split){ - return (remaining ,force) => window.RT.Component[component_id].split(el ,remaining ,measure_fragment ,force); + return (remaining) => window.RT.Component[component_id].split(el ,remaining ,measure_fragment); } if(el.hasAttribute('splitable') && window.RT.Splitter && window.RT.Splitter[(el.tagName || '').toLowerCase()]){ - return (remaining ,force) => window.RT.Splitter[(el.tagName || '').toLowerCase()](el ,remaining ,measure_fragment ,is_splittable ,force); + return (remaining) => window.RT.Splitter[(el.tagName || '').toLowerCase()](el ,remaining ,measure_fragment ,is_splittable); } const tag = (el.tagName || '').toUpperCase(); @@ -108,7 +110,7 @@ } function make_list_splitter(el ,info){ - return (remaining ,force) => { + return (remaining) => { const children = Array.from(el.children).filter(c => (c.tagName || '').toUpperCase() === 'LI'); const start = info.offset; @@ -129,18 +131,7 @@ } } - if(best_count === 0){ - if(force && children.length > 0){ - best_count = 1; - best_height = measure_fragment(children[0].cloneNode(true)); - }else{ - return { first: null ,rest: el ,firstHeight: 0 }; - } - } - - if(best_count === children.length){ - return { first: el ,rest: null ,firstHeight: best_height }; - } + if(best_count === 0) return { first: null ,rest: el ,firstHeight: 0 }; const first = el.cloneNode(false); for(let i = 0; i < best_count; i++){ @@ -181,7 +172,7 @@ return shell; }; - return (remaining ,force) => { + return (remaining) => { const tbody = el.querySelector('tbody'); const rows = tbody ? Array.from(tbody.rows) : Array.from(el.rows); const start = info.offset; @@ -203,18 +194,7 @@ } } - if(best_count === 0){ - if(force && rows.length > 0){ - best_count = 1; - best_height = measure_fragment(rows[0].cloneNode(true)); - }else{ - return { first: null ,rest: el ,firstHeight: 0 }; - } - } - - if(best_count === rows.length){ - return { first: el ,rest: null ,firstHeight: best_height }; - } + if(best_count === 0) return { first: null ,rest: el ,firstHeight: 0 }; const first = create_shell(); const first_body = first.querySelector('tbody'); @@ -243,9 +223,10 @@ }; } + // RT ELEMENT SPLITTERS window.RT.Splitter = window.RT.Splitter || {}; - window.RT.Splitter['rt·counter·step'] = function(el ,remaining ,measure_fn ,is_splittable_fn ,force){ + window.RT.Splitter['rt·counter·step'] = function(el ,remaining ,measure_fn ,is_splittable_fn){ const children = Array.from(el.childNodes); let best_count = 0; let best_height = 0; @@ -273,7 +254,7 @@ temp_container.removeChild(temp_container.lastChild); const child_splitter = child.nodeType === Node.ELEMENT_NODE ? is_splittable_fn(child) : null; if(child_splitter){ - const child_split = child_splitter(remaining - best_height ,false); + const child_split = child_splitter(remaining - best_height); if(child_split && child_split.first){ split_child_result = child_split; best_height += child_split.firstHeight; @@ -284,17 +265,8 @@ } } - if(best_count === children.length && !split_child_result && !forced_break){ - return { first: el ,rest: null ,firstHeight: best_height }; - } - if(best_count === 0 && !split_child_result && !forced_break){ - if(force && children.length > 0){ - best_count = 1; - best_height = measure_fn(children[0].cloneNode(true)); - }else{ - return { first: null ,rest: el ,firstHeight: 0 }; - } + return { first: null ,rest: el ,firstHeight: 0 }; } const first = el.cloneNode(false); @@ -335,6 +307,7 @@ return { first: first ,rest: rest ,firstHeight: best_height }; }; + // PAGINATE 0: CHUNKING & INJECTING STRUCTURE function paginate_0(){ if(debug.log) debug.log('paginate_0' ,'Running initial document chunking'); @@ -389,13 +362,7 @@ if(splitter){ const remaining = page_height_limit - current_h; - let split_res = splitter(remaining ,false); - - if(!split_res.first && current_h === 0){ - split_res = splitter(remaining ,true); - } - - const { first ,rest ,firstHeight } = split_res; + const { first ,rest ,firstHeight } = splitter(remaining); if(first){ current_batch_seq.push(first); @@ -419,24 +386,42 @@ continue; } }else{ - let backtrack_seq = []; - let backtrack_h = 0; - - while(current_batch_seq.length > 0){ - const last = current_batch_seq[current_batch_seq.length - 1]; - if(!last.tagName || !/^H[1-6]$/i.test(last.tagName)) break; - const popped = current_batch_seq.pop(); - backtrack_seq.unshift(popped); - backtrack_h += get_el_height(popped); - } - - if(current_h - backtrack_h > 0){ - page_seq.push(current_batch_seq); - current_batch_seq = backtrack_seq; - current_h = backtrack_h; + if(current_h === 0){ + const frame = document.createElement('RT·scroll-frame'); + frame.style.display = 'block'; + frame.style.overflowY = 'auto'; + frame.style.maxHeight = page_height_limit + 'px'; + frame.appendChild(el); + current_batch_seq.push(frame); + i++; }else{ - current_batch_seq.push(...backtrack_seq); - current_h += backtrack_h; + let backtrack_seq = []; + let backtrack_h = 0; + + while(current_batch_seq.length > 0){ + const last = current_batch_seq[current_batch_seq.length - 1]; + if(!last.tagName || !/^H[1-6]$/i.test(last.tagName)) break; + const popped = current_batch_seq.pop(); + backtrack_seq.unshift(popped); + backtrack_h += get_el_height(popped); + } + + if(current_h - backtrack_h > 0){ + page_seq.push(current_batch_seq); + current_batch_seq = backtrack_seq; + current_h = backtrack_h; + }else{ + current_batch_seq.push(...backtrack_seq); + current_h += backtrack_h; + + const frame = document.createElement('RT·scroll-frame'); + frame.style.display = 'block'; + frame.style.overflowY = 'auto'; + frame.style.maxHeight = page_height_limit + 'px'; + frame.appendChild(el); + current_batch_seq.push(frame); + i++; + } } } continue;