finite: conduite task

This commit is contained in:
2026-05-01 12:42:37 +07:00
parent 04c7310749
commit d287badbee
14 changed files with 2417 additions and 630 deletions
+22 -1
View File
@@ -11,7 +11,8 @@ const PROJECT_ROOT = resolve(__dirname, '../..');
const OUTPUT_DIR = resolve(PROJECT_ROOT, 'output/pdf');
const MIME_TYPES = {
'.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript',
'.html': 'text/html', '.css': 'text/css',
'.js': 'application/javascript', '.mjs': 'application/javascript',
'.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
'.webp': 'image/webp', '.svg': 'image/svg+xml', '.json': 'application/json',
};
@@ -53,6 +54,26 @@ async function generatePdf(htmlPath) {
await page.goto(`http://127.0.0.1:${port}/${relPath}`, { waitUntil: 'networkidle0', timeout: 30000 });
// Theme custom elements load via dynamic import inside the per-theme loader.
// networkidle0 doesn't wait for the post-import upgrade + shadow-DOM image fetch,
// so we explicitly wait for any used custom elements to be defined and their
// shadow-DOM images to finish loading.
const hasCustomTags = await page.evaluate(() =>
[...document.querySelectorAll('*')].some(el => el.tagName.includes('-'))
);
if (hasCustomTags) {
await page.waitForFunction(() => {
const customs = [...document.querySelectorAll('*')].filter(el => el.tagName.includes('-'));
return customs.every(el => {
const root = el.shadowRoot;
if (!root) return false;
const imgs = root.querySelectorAll('img');
if (imgs.length === 0) return false;
return [...imgs].every(img => img.complete && img.naturalWidth > 0);
});
}, { timeout: 15000, polling: 100 });
}
await page.pdf({
path: pdfPath,
format: 'A4',