2026-04-09 22:28:24 +02:00
|
|
|
|
import { Handler } from '/csspageweaver/lib/paged.esm.js';
|
|
|
|
|
|
|
|
|
|
|
|
export default class thesis extends Handler {
|
|
|
|
|
|
constructor(chunker, polisher, caller) {
|
|
|
|
|
|
super(chunker, polisher, caller);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-09 22:35:44 +02:00
|
|
|
|
|
2026-04-10 11:24:39 +02:00
|
|
|
|
// Créer un wrapper pour récupérer tous les éléments qui suivent le ol (hors titres et .container-following-note)
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
beforeParsed(content){
|
|
|
|
|
|
const nums = content.querySelectorAll('ol[type="1"]');
|
|
|
|
|
|
|
|
|
|
|
|
nums.forEach((num) => {
|
|
|
|
|
|
const wrapper = document.createElement('div');
|
|
|
|
|
|
wrapper.classList.add('wrapper-ol');
|
|
|
|
|
|
wrapper.id = 'wrapper-' + (num.getAttribute('start') || '1');
|
|
|
|
|
|
|
|
|
|
|
|
// Collecter les frères/sœurs suivants jusqu'à la prochaine limite
|
|
|
|
|
|
const siblings = [];
|
2026-04-09 22:28:24 +02:00
|
|
|
|
let sibling = num.nextElementSibling;
|
|
|
|
|
|
while (sibling) {
|
|
|
|
|
|
if (sibling.matches('ol[type="1"], h1, h2, h3, h4, h5, h6, .container-following-note')) break;
|
2026-04-10 11:24:39 +02:00
|
|
|
|
siblings.push(sibling);
|
|
|
|
|
|
sibling = sibling.nextElementSibling;
|
|
|
|
|
|
}
|
2026-04-09 22:35:44 +02:00
|
|
|
|
|
2026-04-10 11:24:39 +02:00
|
|
|
|
// Insérer le wrapper à la place du ol
|
|
|
|
|
|
num.before(wrapper);
|
|
|
|
|
|
wrapper.appendChild(num);
|
|
|
|
|
|
siblings.forEach(s => wrapper.appendChild(s));
|
|
|
|
|
|
});
|
2026-04-10 11:46:11 +02:00
|
|
|
|
|
|
|
|
|
|
// Si le dernier enfant d'un wrapper est un p et que le suivant est aussi un wrapper → .wrapper-indent
|
|
|
|
|
|
const wrappers = content.querySelectorAll('.wrapper-ol');
|
|
|
|
|
|
wrappers.forEach((wrapper) => {
|
|
|
|
|
|
const last = wrapper.lastElementChild;
|
|
|
|
|
|
const next = wrapper.nextElementSibling;
|
|
|
|
|
|
if (last && last.nodeName === 'P' && next && next.classList.contains('wrapper-ol')) {
|
|
|
|
|
|
const firstP = next.querySelector('p');
|
|
|
|
|
|
if (!firstP || !firstP.classList.contains('p-these')) {
|
|
|
|
|
|
next.classList.add('wrapper-indent');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-04-10 11:24:39 +02:00
|
|
|
|
}
|
2026-04-09 22:35:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
2026-04-10 11:24:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
afterPageLayout(pageElement, page, breakToken){
|
|
|
|
|
|
|
|
|
|
|
|
const wrappers = pageElement.querySelectorAll('.wrapper-ol');
|
|
|
|
|
|
const minSize = 37; // taille minimal du wrapper pour qu’il y ait clone (2 lignes)
|
|
|
|
|
|
|
|
|
|
|
|
// Fais un clone du ol pour de la page précédente
|
|
|
|
|
|
// -----------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
if (wrappers.length > 0) {
|
|
|
|
|
|
const first = wrappers[0];
|
|
|
|
|
|
if (first.hasAttribute('data-split-from')) {
|
|
|
|
|
|
let idWrapper = first.getAttribute('data-id');
|
|
|
|
|
|
let numPage = pageElement.getAttribute('data-page-number');
|
|
|
|
|
|
let numPrev = parseInt(numPage) - 1;
|
|
|
|
|
|
let prevPage = document.querySelector('#page-' + numPrev);
|
|
|
|
|
|
let olPara = prevPage.querySelector('#' + idWrapper + ' ol[type="1"]');
|
|
|
|
|
|
|
|
|
|
|
|
if (olPara && first.offsetHeight >= minSize) {
|
|
|
|
|
|
const start = olPara.getAttribute('start') || '1';
|
|
|
|
|
|
const olClonePage = document.createElement('ol');
|
|
|
|
|
|
olClonePage.setAttribute('start', start);
|
|
|
|
|
|
olClonePage.setAttribute('type', '1');
|
|
|
|
|
|
olClonePage.classList.add('ol-clone-page');
|
|
|
|
|
|
olClonePage.style.height = first.offsetHeight + 'px';
|
|
|
|
|
|
const li = document.createElement('li');
|
|
|
|
|
|
li.setAttribute('data-item-num', start);
|
|
|
|
|
|
olClonePage.appendChild(li);
|
|
|
|
|
|
first.prepend(olClonePage);
|
|
|
|
|
|
}
|
2026-04-09 22:28:24 +02:00
|
|
|
|
}
|
2026-04-10 11:24:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-09 22:35:44 +02:00
|
|
|
|
|
2026-04-10 11:24:39 +02:00
|
|
|
|
// Fais un clone du ol pour la colonne suivante (dans la même page)
|
|
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
|
|
wrappers.forEach((wrapper) => {
|
|
|
|
|
|
const ol = wrapper.querySelector('ol[type="1"]');
|
|
|
|
|
|
if (!ol) return;
|
|
|
|
|
|
|
|
|
|
|
|
const rects = wrapper.getClientRects();
|
|
|
|
|
|
if (rects.length === 1) {
|
|
|
|
|
|
ol.style.height = rects[0].height + 'px';
|
|
|
|
|
|
} else if (rects.length === 2) {
|
|
|
|
|
|
ol.style.height = rects[0].height + 'px';
|
|
|
|
|
|
if (rects[1].height >= minSize) {
|
|
|
|
|
|
const olClone = ol.cloneNode(true);
|
|
|
|
|
|
olClone.classList.add('ol-clone');
|
|
|
|
|
|
olClone.style.height = rects[1].height + 'px';
|
|
|
|
|
|
olClone.removeAttribute('id');
|
|
|
|
|
|
ol.after(olClone);
|
|
|
|
|
|
}
|
2026-04-09 22:28:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-04-10 11:24:39 +02:00
|
|
|
|
|
2026-04-09 22:28:24 +02:00
|
|
|
|
|
2026-04-10 11:24:39 +02:00
|
|
|
|
}
|
2026-04-09 22:28:24 +02:00
|
|
|
|
|
2026-04-10 11:24:39 +02:00
|
|
|
|
}
|