Miss die Navigationsbreite ohne Kopie im DOM.
CI Feature / test (push) Successful in 38s
Deploy Test / test (push) Successful in 31s
Deploy Test / deploy (push) Successful in 40s

Die Messkopie verdoppelte Navigationselemente samt Zustandsklassen und
störte Prüfungen, die die Navigation über Klassen finden. Gemessen wird
jetzt an der echten Navigation: Zustandsklassen werden innerhalb eines
Aufrufs entfernt und wiederhergestellt, ohne Zeichnen dazwischen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-18 07:10:02 +01:00
1 parent 8390dcdb41
commit 7c1caec546
1 file changed
+33 -42
+33 -42
View File
@@ -1,7 +1,7 @@
/**
* Website-Kopfzeile: Menümodus, mobile Navigation, Untermenüs und kompakter Zustand beim Scrollen.
*
* Breitenstufen der Kopfzeile (Messung an einer unsichtbaren Kopie, unabhängig vom aktuellen Modus):
* Breitenstufen der Kopfzeile (Messung der Desktop-Darstellung an der echten Navigation, unabhängig vom aktuellen Modus):
* 1. Navigation und Kontozugang mit Beschriftung passen in eine Zeile.
* 2. Sonst: Kontozugang nur als Symbol (is-account-compact).
* 3. Sonst und immer unter 75 rem: Menümodus (is-menu-mode).
@@ -95,57 +95,48 @@ function setupMode(header, closeMenu) {
const brand = inner?.querySelector('.brand');
const actions = inner?.querySelector('.site-header-actions');
const account = actions?.querySelector('.site-account-link');
const menuButton = actions?.querySelector('[data-site-menu-button]');
if (!inner || !list || !brand || !actions || !account) {
return;
}
// Unsichtbare Kopie von Navigation und Kontozugang in Desktop-Darstellung: liefert die benötigten Breiten in jedem Modus.
const probe = document.createElement('div');
probe.className = 'site-nav-probe';
probe.setAttribute('aria-hidden', 'true');
probe.style.cssText = 'position:absolute;visibility:hidden;pointer-events:none;left:-10000px;top:0;height:auto;padding:0;width:max-content;';
const nav = document.createElement('nav');
nav.className = 'site-nav';
nav.appendChild(list.cloneNode(true));
const accountProbe = account.cloneNode(true);
probe.append(nav, accountProbe);
// Die Kopie ist reine Messfläche: nicht bedienbar, nicht vorgelesen, ohne Kennungen, Ziele und Skript-Merkmale.
probe.inert = true;
probe.querySelectorAll('*').forEach((node) => {
[...node.attributes]
.filter((attribute) => attribute.name === 'id' || attribute.name === 'href' || attribute.name.startsWith('aria-') || attribute.name.startsWith('data-'))
.forEach((attribute) => node.removeAttribute(attribute.name));
});
document.body.appendChild(probe);
const width = (element) => element.getBoundingClientRect().width;
const realNav = header.querySelector('.site-nav');
let lastNavMargin = 32;
/*
* Misst die Desktop-Darstellung an der echten Navigation: Zustandsklassen werden innerhalb desselben
* Aufrufs entfernt, gemessen und wiederhergestellt. Dazwischen wird nicht gezeichnet; es entsteht keine Kopie.
*/
const measureDesktop = () => {
const menuMode = header.classList.contains('is-menu-mode');
const accountCompact = header.classList.contains('is-account-compact');
header.classList.remove('is-menu-mode', 'is-account-compact');
const gap = parseFloat(getComputedStyle(inner).columnGap) || 0;
const result = {
room: inner.clientWidth - width(brand) - 2 * gap - (parseFloat(getComputedStyle(realNav).marginLeft) || 0) - (width(actions) - width(account)),
needed: list.scrollWidth,
accountFull: width(account),
};
header.classList.toggle('is-menu-mode', menuMode);
header.classList.toggle('is-account-compact', accountCompact);
return result;
};
const update = () => {
const gap = parseFloat(getComputedStyle(inner).columnGap) || 0;
const actionsGap = parseFloat(getComputedStyle(actions).columnGap) || 0;
// Abstand zwischen Wortmarke und Navigation in Desktop-Darstellung; im Menümodus der zuletzt gemessene Wert.
if (!isMenuMode(header)) {
lastNavMargin = parseFloat(getComputedStyle(realNav).marginLeft) || 0;
}
const navMargin = BASELINE.matches ? 0 : lastNavMargin;
let fixedActions = width(actions) - width(account);
if (menuButton && menuButton.offsetParent !== null) {
fixedActions -= width(menuButton) + actionsGap;
}
// Die Wortmarke ist im Ausgangszustand skaliert; gemessen wird die tatsächlich belegte Breite.
const room = inner.clientWidth - width(brand) - 2 * gap - navMargin - fixedActions;
const needed = nav.scrollWidth;
const accountIcon = parseFloat(getComputedStyle(account).minWidth) || 44;
let state = 'menu';
if (!BASELINE.matches && needed + width(accountProbe) <= room) {
state = 'full';
} else if (!BASELINE.matches && needed + accountIcon <= room) {
state = 'icon';
if (!BASELINE.matches) {
const { room, needed, accountFull } = measureDesktop();
const accountIcon = parseFloat(getComputedStyle(account).minWidth) || 44;
if (needed + accountFull <= room) {
state = 'full';
} else if (needed + accountIcon <= room) {
state = 'icon';
}
}
header.classList.toggle('is-account-compact', state !== 'full');