Skip to content

Commit 8e42ed4

Browse files
Copilotjogibear9988
andcommitted
Fix screenshot services using wrong viewport dimensions when designerWidth/Height != 100%
Both DisplayMediaPngWriterService and ElectronPngWriterService used canvas.offsetWidth/Height for tile viewport sizing but captured from outercanvas2. When designerWidth/Height > 100%, the canvas element is larger than the actual capture viewport, causing screenshots to contain only a fraction of the element. Fix by using outercanvas2.offsetWidth/Height which matches the actual visible capture area. Co-authored-by: jogibear9988 <364896+jogibear9988@users.noreply.github.com> Agent-Logs-Url: https://github.com/node-projects/web-component-designer/sessions/76a14e97-53dd-48d1-9442-f68292307d18
1 parent c3ae7a1 commit 8e42ed4

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

packages/web-component-designer/src/elements/services/pngCreatorService/DisplayMediaPngWriterService.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ export class DisplayMediaPngWriterService implements IPngCreatorService {
4545
const totalWidth = Math.ceil(maxX - minX);
4646
const totalHeight = Math.ceil(maxY - minY);
4747

48-
const viewportW = designerCanvas.canvas.offsetWidth;
49-
const viewportH = designerCanvas.canvas.offsetHeight;
48+
// Use the outer viewport element for screenshots so that the crop
49+
// coordinates are not affected by the canvasOffset CSS transform.
50+
// Its dimensions reflect the actual visible capture area, which may
51+
// differ from canvas.offsetWidth when designerWidth/Height != 100%.
52+
const viewportElement = (<DesignerCanvas>designerCanvas).outercanvas2;
53+
const viewportW = viewportElement.offsetWidth;
54+
const viewportH = viewportElement.offsetHeight;
5055

5156
// Inset by 1 CSS pixel on each edge to avoid border artifacts when stitching tiles
5257
const borderInset = 1;
@@ -68,10 +73,6 @@ export class DisplayMediaPngWriterService implements IPngCreatorService {
6873
finalCanvas.height = Math.ceil(totalHeight * dpr);
6974
const finalCtx = finalCanvas.getContext('2d');
7075

71-
// Use the outer viewport element for screenshots so that the crop
72-
// coordinates are not affected by the canvasOffset CSS transform
73-
const viewportElement = (<DesignerCanvas>designerCanvas).outercanvas2;
74-
7576
let sleepTime = 1000;
7677

7778
for (let iy = 0; iy < numTilesY; iy++) {

packages/web-component-designer/src/elements/services/pngCreatorService/ElectronPngWriterService.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ export class ElectronPngWriterService implements IPngCreatorService {
7575
const totalWidth = Math.ceil(maxX - minX);
7676
const totalHeight = Math.ceil(maxY - minY);
7777

78-
const viewportW = designerCanvas.canvas.offsetWidth;
79-
const viewportH = designerCanvas.canvas.offsetHeight;
78+
// Use the outer viewport element to determine the capture rectangle
79+
// so that coordinates are not affected by the canvasOffset CSS transform.
80+
// Its dimensions reflect the actual visible capture area, which may
81+
// differ from canvas.offsetWidth when designerWidth/Height != 100%.
82+
const viewportElement = (<DesignerCanvas>designerCanvas).outercanvas2;
83+
const viewportW = viewportElement.offsetWidth;
84+
const viewportH = viewportElement.offsetHeight;
8085

8186
// Inset by 1 CSS pixel on each edge to avoid border artifacts when stitching tiles
8287
const borderInset = 1;
@@ -98,10 +103,6 @@ export class ElectronPngWriterService implements IPngCreatorService {
98103
finalCanvas.height = Math.ceil(totalHeight * dpr);
99104
const finalCtx = finalCanvas.getContext('2d');
100105

101-
// Use the outer viewport element to determine the capture rectangle
102-
// so that coordinates are not affected by the canvasOffset CSS transform
103-
const viewportElement = (<DesignerCanvas>designerCanvas).outercanvas2;
104-
105106
for (let iy = 0; iy < numTilesY; iy++) {
106107
for (let ix = 0; ix < numTilesX; ix++) {
107108
const tileX = minX + ix * effectiveW;

0 commit comments

Comments
 (0)