afterbefore 0.1.13 → 0.1.15

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/index.js CHANGED
@@ -115,16 +115,15 @@ var Logger = class {
115
115
  this.log("info", `Pipeline ${finished ? "completed" : "stopped"}`);
116
116
  if (this.spinner) {
117
117
  if (finished) {
118
- this.spinner.stop();
119
118
  const bar = "\u2588".repeat(BAR_WIDTH);
120
- console.log(`${chalk.green("\u2714")} ${bar}`);
119
+ this.spinner.succeed(` ${bar}`);
121
120
  } else {
122
121
  this.spinner.stop();
123
122
  }
124
123
  this.spinner = null;
125
124
  } else if (finished) {
126
125
  const bar = "\u2588".repeat(BAR_WIDTH);
127
- console.log(`${chalk.green("\u2714")} ${bar}`);
126
+ console.error(`${chalk.green("\u2714")} ${bar}`);
128
127
  }
129
128
  this.pipelineTotal = 0;
130
129
  this.lastStep = 0;
@@ -1644,34 +1643,37 @@ async function captureRoutes(tasks, beforeUrl, afterUrl, outputDir, options) {
1644
1643
 
1645
1644
  // src/stages/compare.ts
1646
1645
  import { join as join7, dirname as dirname2 } from "path";
1647
- import { readFileSync as readFileSync5, unlinkSync } from "fs";
1646
+ import { unlinkSync } from "fs";
1648
1647
  import { ODiffServer } from "odiff-bin";
1649
1648
  import sharp from "sharp";
1650
- function readPngSize(path) {
1651
- const buf = readFileSync5(path);
1652
- return { width: buf.readUInt32BE(16), height: buf.readUInt32BE(20) };
1649
+ async function trimImage(path) {
1650
+ const { data, info } = await sharp(path).trim({ threshold: 50 }).toBuffer({ resolveWithObject: true });
1651
+ return { data, width: info.width, height: info.height };
1653
1652
  }
1654
1653
  async function generateComposite(beforePath, afterPath, outputPath, bgColor) {
1655
- const beforeSize = readPngSize(beforePath);
1656
- const afterSize = readPngSize(afterPath);
1657
- const imgW = Math.max(beforeSize.width, afterSize.width);
1658
- const imgH = Math.max(beforeSize.height, afterSize.height);
1659
- const PADDING = 120;
1660
- const GAP = 80;
1654
+ const [beforeTrimmed, afterTrimmed] = await Promise.all([
1655
+ trimImage(beforePath),
1656
+ trimImage(afterPath)
1657
+ ]);
1658
+ const imgW = Math.max(beforeTrimmed.width, afterTrimmed.width);
1659
+ const imgH = Math.max(beforeTrimmed.height, afterTrimmed.height);
1660
+ const PADDING = 40;
1661
+ const GAP = 40;
1661
1662
  const LABEL_H = 70;
1662
1663
  const canvasW = Math.max(600, Math.min(2400, imgW * 2 + GAP + PADDING * 2));
1663
1664
  const canvasH = Math.max(300, Math.min(2400, imgH + LABEL_H + PADDING * 2));
1664
1665
  const maxImgH = canvasH - PADDING * 2 - LABEL_H;
1665
1666
  const colW = Math.floor((canvasW - PADDING * 2 - GAP) / 2);
1666
- const [beforeBuf, afterBuf] = await Promise.all([
1667
- sharp(beforePath).resize(colW, maxImgH, { fit: "inside" }).toBuffer({ resolveWithObject: true }),
1668
- sharp(afterPath).resize(colW, maxImgH, { fit: "inside" }).toBuffer({ resolveWithObject: true })
1669
- ]);
1667
+ const [beforeBuf, afterBuf] = await Promise.all(
1668
+ [beforeTrimmed, afterTrimmed].map(async (trimmed) => {
1669
+ return await sharp(trimmed.data).resize(colW, maxImgH, { fit: "inside" }).toBuffer({ resolveWithObject: true });
1670
+ })
1671
+ );
1670
1672
  const beforeLeft = PADDING + Math.floor((colW - beforeBuf.info.width) / 2);
1671
1673
  const beforeTop = PADDING + Math.floor((maxImgH - beforeBuf.info.height) / 2);
1672
1674
  const afterLeft = PADDING + colW + GAP + Math.floor((colW - afterBuf.info.width) / 2);
1673
1675
  const afterTop = PADDING + Math.floor((maxImgH - afterBuf.info.height) / 2);
1674
- const labelY = PADDING + maxImgH + 50;
1676
+ const labelY = PADDING + maxImgH + 20;
1675
1677
  const beforeLabelX = PADDING + Math.floor(colW / 2);
1676
1678
  const afterLabelX = PADDING + colW + GAP + Math.floor(colW / 2);
1677
1679
  const labelSvg = Buffer.from(
@@ -1926,7 +1928,7 @@ async function runPipeline(options) {
1926
1928
  const outputDir = resolve4(cwd, output, sessionName);
1927
1929
  const startTime = Date.now();
1928
1930
  try {
1929
- const version = true ? "0.1.13" : "dev";
1931
+ const version = true ? "0.1.15" : "dev";
1930
1932
  console.log(`
1931
1933
  afterbefore v${version} \xB7 Comparing against ${base}
1932
1934
  `);