@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/cli.js CHANGED
@@ -669,13 +669,19 @@ function buildRenderer(filePath, componentName, viewportWidth, viewportHeight) {
669
669
  `Component "${componentName}" rendered with zero bounding box \u2014 it may be invisible or not mounted`
670
670
  );
671
671
  }
672
+ const PAD = 24;
673
+ const MIN_W = 320;
674
+ const MIN_H = 200;
675
+ const clipX = Math.max(0, boundingBox.x - PAD);
676
+ const clipY = Math.max(0, boundingBox.y - PAD);
677
+ const rawW = boundingBox.width + PAD * 2;
678
+ const rawH = boundingBox.height + PAD * 2;
679
+ const clipW = Math.max(rawW, MIN_W);
680
+ const clipH = Math.max(rawH, MIN_H);
681
+ const safeW = Math.min(clipW, viewportWidth - clipX);
682
+ const safeH = Math.min(clipH, viewportHeight - clipY);
672
683
  const screenshot = await page.screenshot({
673
- clip: {
674
- x: boundingBox.x,
675
- y: boundingBox.y,
676
- width: boundingBox.width,
677
- height: boundingBox.height
678
- },
684
+ clip: { x: clipX, y: clipY, width: safeW, height: safeH },
679
685
  type: "png"
680
686
  });
681
687
  const computedStyles = {};
@@ -702,8 +708,8 @@ function buildRenderer(filePath, componentName, viewportWidth, viewportHeight) {
702
708
  computedStyles["[data-reactscope-root] > *"] = styles;
703
709
  return {
704
710
  screenshot,
705
- width: Math.round(boundingBox.width),
706
- height: Math.round(boundingBox.height),
711
+ width: Math.round(safeW),
712
+ height: Math.round(safeH),
707
713
  renderTimeMs,
708
714
  computedStyles
709
715
  };