afterbefore 0.1.13 → 0.1.14

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.
package/dist/cli.js CHANGED
@@ -1657,34 +1657,37 @@ async function captureRoutes(tasks, beforeUrl, afterUrl, outputDir, options) {
1657
1657
 
1658
1658
  // src/stages/compare.ts
1659
1659
  import { join as join7, dirname as dirname2 } from "path";
1660
- import { readFileSync as readFileSync5, unlinkSync } from "fs";
1660
+ import { unlinkSync } from "fs";
1661
1661
  import { ODiffServer } from "odiff-bin";
1662
1662
  import sharp from "sharp";
1663
- function readPngSize(path) {
1664
- const buf = readFileSync5(path);
1665
- return { width: buf.readUInt32BE(16), height: buf.readUInt32BE(20) };
1663
+ async function trimImage(path) {
1664
+ const { data, info } = await sharp(path).trim({ threshold: 50 }).toBuffer({ resolveWithObject: true });
1665
+ return { data, width: info.width, height: info.height };
1666
1666
  }
1667
1667
  async function generateComposite(beforePath, afterPath, outputPath, bgColor) {
1668
- const beforeSize = readPngSize(beforePath);
1669
- const afterSize = readPngSize(afterPath);
1670
- const imgW = Math.max(beforeSize.width, afterSize.width);
1671
- const imgH = Math.max(beforeSize.height, afterSize.height);
1672
- const PADDING = 120;
1673
- const GAP = 80;
1668
+ const [beforeTrimmed, afterTrimmed] = await Promise.all([
1669
+ trimImage(beforePath),
1670
+ trimImage(afterPath)
1671
+ ]);
1672
+ const imgW = Math.max(beforeTrimmed.width, afterTrimmed.width);
1673
+ const imgH = Math.max(beforeTrimmed.height, afterTrimmed.height);
1674
+ const PADDING = 40;
1675
+ const GAP = 40;
1674
1676
  const LABEL_H = 70;
1675
1677
  const canvasW = Math.max(600, Math.min(2400, imgW * 2 + GAP + PADDING * 2));
1676
1678
  const canvasH = Math.max(300, Math.min(2400, imgH + LABEL_H + PADDING * 2));
1677
1679
  const maxImgH = canvasH - PADDING * 2 - LABEL_H;
1678
1680
  const colW = Math.floor((canvasW - PADDING * 2 - GAP) / 2);
1679
- const [beforeBuf, afterBuf] = await Promise.all([
1680
- sharp(beforePath).resize(colW, maxImgH, { fit: "inside" }).toBuffer({ resolveWithObject: true }),
1681
- sharp(afterPath).resize(colW, maxImgH, { fit: "inside" }).toBuffer({ resolveWithObject: true })
1682
- ]);
1681
+ const [beforeBuf, afterBuf] = await Promise.all(
1682
+ [beforeTrimmed, afterTrimmed].map(async (trimmed) => {
1683
+ return await sharp(trimmed.data).resize(colW, maxImgH, { fit: "inside" }).toBuffer({ resolveWithObject: true });
1684
+ })
1685
+ );
1683
1686
  const beforeLeft = PADDING + Math.floor((colW - beforeBuf.info.width) / 2);
1684
1687
  const beforeTop = PADDING + Math.floor((maxImgH - beforeBuf.info.height) / 2);
1685
1688
  const afterLeft = PADDING + colW + GAP + Math.floor((colW - afterBuf.info.width) / 2);
1686
1689
  const afterTop = PADDING + Math.floor((maxImgH - afterBuf.info.height) / 2);
1687
- const labelY = PADDING + maxImgH + 50;
1690
+ const labelY = PADDING + maxImgH + 20;
1688
1691
  const beforeLabelX = PADDING + Math.floor(colW / 2);
1689
1692
  const afterLabelX = PADDING + colW + GAP + Math.floor(colW / 2);
1690
1693
  const labelSvg = Buffer.from(
@@ -1939,7 +1942,7 @@ async function runPipeline(options) {
1939
1942
  const outputDir = resolve4(cwd, output, sessionName);
1940
1943
  const startTime = Date.now();
1941
1944
  try {
1942
- const version = true ? "0.1.13" : "dev";
1945
+ const version = true ? "0.1.14" : "dev";
1943
1946
  console.log(`
1944
1947
  afterbefore v${version} \xB7 Comparing against ${base}
1945
1948
  `);
@@ -2084,7 +2087,7 @@ afterbefore v${version} \xB7 Comparing against ${base}
2084
2087
  var program = new Command();
2085
2088
  program.name("afterbefore").description(
2086
2089
  "Automatic before/after screenshot capture for PRs. Git diff is the config."
2087
- ).version("0.1.13").option("--base <ref>", "Base branch or ref to compare against", "main").option("--output <dir>", "Output directory for screenshots", ".afterbefore").option("--post", "Post results as a PR comment via gh CLI", false).option(
2090
+ ).version("0.1.14").option("--base <ref>", "Base branch or ref to compare against", "main").option("--output <dir>", "Output directory for screenshots", ".afterbefore").option("--post", "Post results as a PR comment via gh CLI", false).option(
2088
2091
  "--threshold <percent>",
2089
2092
  "Diff threshold percentage (changes below this are ignored)",
2090
2093
  "0.1"