fix: hide platform actions from long image exports
Memind CI / Test, build, and release guards (push) Successful in 1m26s
Memind CI / Test, build, and release guards (push) Successful in 1m26s
This commit is contained in:
@@ -9,12 +9,25 @@ const DEFAULT_VIEWPORT_HEIGHT = 720;
|
||||
const MAX_LONG_IMAGE_HEIGHT = 20000;
|
||||
export const LONG_IMAGE_EXPORT_STYLE = `
|
||||
[data-mindspace-public-share],
|
||||
[data-mindspace-public-share-dialog],
|
||||
[data-mindspace-public-share-dialog-panel],
|
||||
.publication-share-fab,
|
||||
.publication-share-sheet {
|
||||
display: none !important;
|
||||
visibility: hidden !important;
|
||||
opacity: 0 !important;
|
||||
pointer-events: none !important;
|
||||
}
|
||||
`;
|
||||
|
||||
export const LONG_IMAGE_EXPORT_SELECTORS = Object.freeze([
|
||||
'[data-mindspace-public-share]',
|
||||
'[data-mindspace-public-share-dialog]',
|
||||
'[data-mindspace-public-share-dialog-panel]',
|
||||
'.publication-share-fab',
|
||||
'.publication-share-sheet',
|
||||
]);
|
||||
|
||||
export function isLongImageDownloadRequest(query) {
|
||||
const value = String(query?.download ?? query?.export ?? '').trim().toLowerCase();
|
||||
return value === 'long-image' || value === 'long_image' || value === 'png';
|
||||
@@ -53,6 +66,23 @@ async function launchChromium(chromium) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function hideLongImageExportChrome(page) {
|
||||
await page.addStyleTag?.({
|
||||
content: LONG_IMAGE_EXPORT_STYLE,
|
||||
}).catch(() => null);
|
||||
await page.evaluate?.((selectors) => {
|
||||
for (const selector of selectors) {
|
||||
for (const element of document.querySelectorAll(selector)) {
|
||||
element.setAttribute('data-memind-long-image-hidden', '1');
|
||||
element.style.setProperty('display', 'none', 'important');
|
||||
element.style.setProperty('visibility', 'hidden', 'important');
|
||||
element.style.setProperty('opacity', '0', 'important');
|
||||
element.style.setProperty('pointer-events', 'none', 'important');
|
||||
}
|
||||
}
|
||||
}, LONG_IMAGE_EXPORT_SELECTORS).catch(() => null);
|
||||
}
|
||||
|
||||
export async function renderLongImage({
|
||||
htmlPath = null,
|
||||
url = null,
|
||||
@@ -84,6 +114,7 @@ export async function renderLongImage({
|
||||
width: clampDimension(size.width, DEFAULT_VIEWPORT_WIDTH, 2400),
|
||||
height: Math.min(clampDimension(size.height, DEFAULT_VIEWPORT_HEIGHT, MAX_LONG_IMAGE_HEIGHT), 2400),
|
||||
});
|
||||
await hideLongImageExportChrome(page);
|
||||
await fsPromises.mkdir(path.dirname(destination), { recursive: true });
|
||||
await page.screenshot({
|
||||
path: destination,
|
||||
|
||||
Reference in New Issue
Block a user