fix header logo optimize
This commit is contained in:
parent
f11313909d
commit
03d7307adf
110
dist/remote/AppHeader.js
vendored
110
dist/remote/AppHeader.js
vendored
File diff suppressed because one or more lines are too long
@ -62,6 +62,12 @@ const STYLES = `
|
||||
flex-shrink:0;
|
||||
object-fit:contain;
|
||||
}
|
||||
/* Only opt-in optimized logos use a square, padded image box. */
|
||||
.logo.logo--optimized{
|
||||
aspect-ratio:1 / 1;
|
||||
max-height:none;
|
||||
padding:8px;
|
||||
}
|
||||
.brand{
|
||||
display:flex;
|
||||
min-width:0;
|
||||
@ -243,27 +249,16 @@ class AppHeaderElement extends HTMLElement {
|
||||
const update = () => {
|
||||
if (!active || failed || !logo.isConnected) return;
|
||||
const rect = logo.getBoundingClientRect();
|
||||
const width = Math.max(0, Math.round(rect.width));
|
||||
if (!width) return;
|
||||
|
||||
// Before an image has loaded, the browser cannot know its aspect ratio.
|
||||
// Start from the available bounds (square logo is the common case); after
|
||||
// load and on resizing, measure the *actual rendered element* again.
|
||||
let height;
|
||||
if (logo.naturalWidth && logo.naturalHeight) {
|
||||
height = Math.max(0, Math.round(rect.height));
|
||||
} else {
|
||||
const maxHeight = Number.parseFloat(getComputedStyle(logo).maxHeight);
|
||||
height = Number.isFinite(maxHeight)
|
||||
? Math.min(width, Math.round(maxHeight))
|
||||
: width;
|
||||
}
|
||||
if (!height) return;
|
||||
const boxSize = Math.max(0, Math.round(rect.width));
|
||||
if (!boxSize) return;
|
||||
|
||||
// The optimized image sits in a square box with 8px of padding
|
||||
// on every side; resize the remote asset to the usable inner square.
|
||||
const imageSize = Math.max(1, boxSize - 16);
|
||||
const url = processImage(absoluteSource, {
|
||||
w: width,
|
||||
h: height,
|
||||
q: 70,
|
||||
w: imageSize,
|
||||
h: imageSize,
|
||||
q: 100,
|
||||
webp: true,
|
||||
});
|
||||
if (url === lastRequestedUrl) return;
|
||||
@ -336,6 +331,7 @@ class AppHeaderElement extends HTMLElement {
|
||||
|
||||
if (logoSrc) {
|
||||
const logo = createElement("img", "logo");
|
||||
if (logoOptimize === true) logo.classList.add("logo--optimized");
|
||||
logo.alt = logoAlt || "logo";
|
||||
logo.loading = logoOptimize ? "eager" : "lazy";
|
||||
brandSection.appendChild(logo);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user