mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-06-22 04:58:40 +00:00
Merge branch 'master' into Open-Sans---Installed-vs-Google-Fonts
This commit is contained in:
+56
-9
@@ -105,14 +105,35 @@ const splitTextStyleAndMetadata = (brew)=>{
|
||||
if(typeof brew.tags === 'string') brew.tags = brew.tags ? [brew.tags] : [];
|
||||
};
|
||||
|
||||
const printCurrentBrew = ()=>{
|
||||
const printCurrentBrew = async ()=>{
|
||||
if(window.typeof !== 'undefined') {
|
||||
window.frames['BrewRenderer'].contentWindow.print();
|
||||
//Force DOM reflow; Print dialog causes a repaint, and @media print CSS somehow makes out-of-view pages disappear
|
||||
const node = window.frames['BrewRenderer'].contentDocument.getElementsByClassName('brewRenderer').item(0);
|
||||
node.style.display='none';
|
||||
node.offsetHeight; // accessing this is enough to trigger a reflow
|
||||
node.style.display='';
|
||||
// fire a custom event for the print cycle
|
||||
document.dispatchEvent(new CustomEvent('print:startprep'));
|
||||
try {
|
||||
const iframeDoc = window.frames['BrewRenderer'].contentDocument;
|
||||
|
||||
// get all img elements with lazy loading (currently only elements generated through MarkedJS)
|
||||
const lazyImages = [...iframeDoc.querySelectorAll('img[loading="lazy"]')];
|
||||
lazyImages.forEach((img)=>{ img.loading = 'eager'; });
|
||||
|
||||
// waits for images to load before resolving promise and opening print dialog
|
||||
await Promise.all(
|
||||
lazyImages
|
||||
.filter((img)=>!img.complete)
|
||||
.map((img)=>new Promise((resolve)=>{ img.onload = resolve; img.onerror = resolve; }))
|
||||
);
|
||||
|
||||
window.frames['BrewRenderer'].contentWindow.print();
|
||||
|
||||
//Force DOM reflow; Print dialog causes a repaint, and @media print CSS somehow makes out-of-view pages disappear
|
||||
const node = iframeDoc.getElementsByClassName('brewRenderer').item(0);
|
||||
node.style.display='none';
|
||||
node.offsetHeight; // accessing this is enough to trigger a reflow
|
||||
node.style.display='';
|
||||
} finally {
|
||||
// when lazy load images have all been loaded, and the doc re-rendered for print preview, emit 'finished' event.
|
||||
document.dispatchEvent(new CustomEvent('print:finishedprep'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -160,9 +181,35 @@ const debugTextMismatch = (clientTextRaw, serverTextRaw, label)=>{
|
||||
// Char-level diff
|
||||
for (let i = 0; i < Math.min(clientText.length, serverText.length); i++) {
|
||||
if(clientText[i] !== serverText[i]) {
|
||||
const getMismatchContext = (text, index, name, size = 10)=>{
|
||||
const lower = Math.max(index - size, 0);
|
||||
const upper = Math.min(index + size, text.length);
|
||||
const slice = `${JSON.stringify(text.slice(lower, index)).slice(1, -1)}\u001B[31m${JSON.stringify(text[i]).slice(1, -1)}\u001B[0m${JSON.stringify(text.slice(index+1, upper)).slice(1, -1)}`;
|
||||
const lineNo = text.slice(0, index).split('\n').length;
|
||||
const code = `U+${text.charCodeAt(i).toString(16).toUpperCase()}`;
|
||||
|
||||
return {
|
||||
name,
|
||||
lineNo,
|
||||
code,
|
||||
lower,
|
||||
upper,
|
||||
slice
|
||||
};
|
||||
};
|
||||
|
||||
const boundSize = 10;
|
||||
|
||||
const clientContext = getMismatchContext(clientText, i, 'Client', boundSize);
|
||||
const serverContext = getMismatchContext(serverText, i, 'Server', boundSize);
|
||||
|
||||
const logContext = (context)=>{
|
||||
console.log(` ${context.name} - line ${context.lineNo} : (${context.code})\t${context.slice}`);
|
||||
};
|
||||
|
||||
console.log(`Char mismatch at index ${i}:`);
|
||||
console.log(` Client: '${clientText[i]}' (U+${clientText.charCodeAt(i).toString(16).toUpperCase()})`);
|
||||
console.log(` Server: '${serverText[i]}' (U+${serverText.charCodeAt(i).toString(16).toUpperCase()})`);
|
||||
logContext(clientContext);
|
||||
logContext(serverContext);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ renderer.image = function (token) {
|
||||
if(href === null)
|
||||
return text;
|
||||
|
||||
let out = `<img src="${href}" alt="${text}" style="--HB_src:url(${href});"`;
|
||||
let out = `<img loading="lazy" src="${href}" alt="${text}" style="--HB_src:url(${href});"`;
|
||||
if(title)
|
||||
out += ` title="${title}"`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user