canicode 0.8.6 → 0.8.8

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/index.js CHANGED
@@ -28,7 +28,7 @@ __export(visual_compare_exports, {
28
28
  });
29
29
  async function fetchFigmaScreenshot(fileKey, nodeId, token, outputPath) {
30
30
  const res = await fetch(
31
- `https://api.figma.com/v1/images/${fileKey}?ids=${nodeId}&format=png&scale=2`,
31
+ `https://api.figma.com/v1/images/${fileKey}?ids=${nodeId}&format=png&scale=1`,
32
32
  { headers: { "X-Figma-Token": token } }
33
33
  );
34
34
  if (!res.ok) throw new Error(`Figma Images API: ${res.status} ${res.statusText}`);
@@ -50,7 +50,12 @@ async function renderCodeScreenshot(codePath, outputPath, viewport) {
50
50
  timeout: 3e4
51
51
  });
52
52
  await page.waitForTimeout(1e3);
53
- await page.screenshot({ path: outputPath, fullPage: true });
53
+ const root = page.locator("body > *:first-child");
54
+ if (await root.count() > 0) {
55
+ await root.screenshot({ path: outputPath });
56
+ } else {
57
+ await page.screenshot({ path: outputPath });
58
+ }
54
59
  await browser.close();
55
60
  }
56
61
  function resizePng(png, targetWidth, targetHeight) {
@@ -72,12 +77,26 @@ function resizePng(png, targetWidth, targetHeight) {
72
77
  function compareScreenshots(path1, path2, diffOutputPath) {
73
78
  const raw1 = PNG.sync.read(readFileSync(path1));
74
79
  const raw2 = PNG.sync.read(readFileSync(path2));
75
- const width = Math.max(raw1.width, raw2.width);
76
- const height = Math.max(raw1.height, raw2.height);
77
- const img1 = raw1.width !== width || raw1.height !== height ? resizePng(raw1, width, height) : raw1;
78
- const img2 = raw2.width !== width || raw2.height !== height ? resizePng(raw2, width, height) : raw2;
80
+ if (raw1.width !== raw2.width || raw1.height !== raw2.height) {
81
+ const width2 = Math.max(raw1.width, raw2.width);
82
+ const height2 = Math.max(raw1.height, raw2.height);
83
+ const img1 = resizePng(raw1, width2, height2);
84
+ const img2 = resizePng(raw2, width2, height2);
85
+ const diff2 = new PNG({ width: width2, height: height2 });
86
+ pixelmatch(img1.data, img2.data, diff2.data, width2, height2, { threshold: 0.1 });
87
+ mkdirSync(dirname(diffOutputPath), { recursive: true });
88
+ writeFileSync(diffOutputPath, PNG.sync.write(diff2));
89
+ return {
90
+ similarity: 0,
91
+ diffPixels: width2 * height2,
92
+ totalPixels: width2 * height2,
93
+ width: width2,
94
+ height: height2
95
+ };
96
+ }
97
+ const { width, height } = raw1;
79
98
  const diff = new PNG({ width, height });
80
- const diffPixels = pixelmatch(img1.data, img2.data, diff.data, width, height, {
99
+ const diffPixels = pixelmatch(raw1.data, raw2.data, diff.data, width, height, {
81
100
  threshold: 0.1
82
101
  });
83
102
  mkdirSync(dirname(diffOutputPath), { recursive: true });
@@ -1105,7 +1124,7 @@ async function loadFromApi(fileKey, nodeId, token) {
1105
1124
  }
1106
1125
 
1107
1126
  // package.json
1108
- var version = "0.8.6";
1127
+ var version = "0.8.8";
1109
1128
  var AnalysisNodeTypeSchema = z.enum([
1110
1129
  "DOCUMENT",
1111
1130
  "CANVAS",