@agent-scope/cli 1.0.1 → 1.0.2

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
@@ -643,13 +643,19 @@ function buildRenderer(filePath, componentName, viewportWidth, viewportHeight) {
643
643
  `Component "${componentName}" rendered with zero bounding box \u2014 it may be invisible or not mounted`
644
644
  );
645
645
  }
646
+ const PAD = 24;
647
+ const MIN_W = 320;
648
+ const MIN_H = 200;
649
+ const clipX = Math.max(0, boundingBox.x - PAD);
650
+ const clipY = Math.max(0, boundingBox.y - PAD);
651
+ const rawW = boundingBox.width + PAD * 2;
652
+ const rawH = boundingBox.height + PAD * 2;
653
+ const clipW = Math.max(rawW, MIN_W);
654
+ const clipH = Math.max(rawH, MIN_H);
655
+ const safeW = Math.min(clipW, viewportWidth - clipX);
656
+ const safeH = Math.min(clipH, viewportHeight - clipY);
646
657
  const screenshot = await page.screenshot({
647
- clip: {
648
- x: boundingBox.x,
649
- y: boundingBox.y,
650
- width: boundingBox.width,
651
- height: boundingBox.height
652
- },
658
+ clip: { x: clipX, y: clipY, width: safeW, height: safeH },
653
659
  type: "png"
654
660
  });
655
661
  const computedStyles = {};
@@ -676,8 +682,8 @@ function buildRenderer(filePath, componentName, viewportWidth, viewportHeight) {
676
682
  computedStyles["[data-reactscope-root] > *"] = styles;
677
683
  return {
678
684
  screenshot,
679
- width: Math.round(boundingBox.width),
680
- height: Math.round(boundingBox.height),
685
+ width: Math.round(safeW),
686
+ height: Math.round(safeH),
681
687
  renderTimeMs,
682
688
  computedStyles
683
689
  };