@decocms/parity 0.33.36 → 0.33.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +28 -8
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -62955,23 +62955,43 @@ async function captureSectionScreenshot(page, selector, outPath, preCapturedFull
62955
62955
  await loc.scrollIntoViewIfNeeded({ timeout: 3000 }).catch(() => {
62956
62956
  return;
62957
62957
  });
62958
- const fullPng = preCapturedFullPng ?? await page.screenshot({
62959
- fullPage: true,
62960
- animations: "disabled",
62961
- timeout: 15000
62962
- });
62963
62958
  const box = await loc.boundingBox({ timeout: 3000 });
62964
62959
  if (!box || box.width <= 0 || box.height <= 0) {
62965
62960
  return `seletor '${selector}' não tem boundingBox visível`;
62966
62961
  }
62967
- const dpr = await page.evaluate(() => window.devicePixelRatio).catch(() => 1);
62968
- const cropped = cropPngBuffer(fullPng, box, dpr);
62969
- await writeFile(outPath, cropped);
62962
+ const detached = await isDetachedFromScroll(loc);
62963
+ if (preCapturedFullPng && !detached) {
62964
+ const dpr = await page.evaluate(() => window.devicePixelRatio).catch(() => 1);
62965
+ await writeFile(outPath, cropPngBuffer(preCapturedFullPng, box, dpr));
62966
+ return null;
62967
+ }
62968
+ if (detached)
62969
+ await settleAtTop(page);
62970
+ await loc.screenshot({ path: outPath, animations: "disabled", timeout: 15000 });
62970
62971
  return null;
62971
62972
  } catch (err) {
62972
62973
  return `falha no screenshot: ${err.message}`;
62973
62974
  }
62974
62975
  }
62976
+ async function settleAtTop(page, attempts = 4) {
62977
+ for (let i = 0;i < attempts; i++) {
62978
+ await page.evaluate(() => window.scrollTo(0, 0)).catch(() => {
62979
+ return;
62980
+ });
62981
+ await page.waitForTimeout(200);
62982
+ const y = await page.evaluate(() => window.scrollY).catch(() => 0);
62983
+ if (y === 0) {
62984
+ await page.waitForTimeout(250);
62985
+ return;
62986
+ }
62987
+ }
62988
+ }
62989
+ async function isDetachedFromScroll(loc) {
62990
+ return loc.evaluate((el) => {
62991
+ const p = getComputedStyle(el).position;
62992
+ return p === "fixed" || p === "sticky";
62993
+ }).catch(() => true);
62994
+ }
62975
62995
 
62976
62996
  // src/extract/extract-component.ts
62977
62997
  var LINK_CAP = 30;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.33.36",
3
+ "version": "0.33.37",
4
4
  "description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with an LLM-ranked HTML report.",
5
5
  "type": "module",
6
6
  "license": "MIT",