Skip to content

Commit 43fdfd5

Browse files
committed
fix(image-editor): crop box reaches image edges; long URL no longer overflows header
- Measure the image via its layout box (offsetLeft/Top/Width/Height) instead of getBoundingClientRect()/scale. The stage's transform transition let a mid-flight measurement stick ~2% small, so the default crop box fell a few px short of the image edges; the layout box is transform-independent and always matches. - Address-bar pills no longer shrink (flex: 0 0 auto) and the URL pill flexes from basis 0, so a long filter-chain URL truncates instead of pushing the zoom and undo/redo controls out of the header.
1 parent df3b482 commit 43fdfd5

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

core-web/libs/image-editor/src/lib/components/dot-image-editor-address-bar/dot-image-editor-address-bar.component.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@
1616
display: flex;
1717
align-items: center;
1818
gap: 0.25rem;
19+
// Pills keep their natural (content) width and never shrink, so the tool and the
20+
// zoom/undo/redo controls always stay intact; only the URL pill flexes.
21+
flex: 0 0 auto;
1922
min-width: 0;
2023
padding: 0.125rem;
2124
border-radius: 1000px;
2225
background-color: var(--surface-200, #e5e7eb);
2326
}
2427

25-
// The URL pill grows to fill the row, pushing the tools pill hard to the left edge
26-
// and the zoom pill to the right edge; the URL truncates inside it.
28+
// The URL pill fills the free space between the tool and zoom pills. `flex-basis: 0`
29+
// (not `auto`) is key: the long, server-generated URL truncates inside the pill
30+
// instead of sizing it to the content and pushing the zoom/undo/redo controls out
31+
// of the header when more filters are appended.
2732
.address-bar__pill--url {
28-
flex: 1 1 auto;
33+
flex: 1 1 0;
2934
padding-right: 0.75rem;
3035
}
3136

core-web/libs/image-editor/src/lib/components/dot-image-editor-canvas/dot-image-editor-canvas.component.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -429,27 +429,27 @@ export class DotImageEditorCanvasComponent {
429429
* can position itself over the rendered pixels.
430430
*/
431431
#measureImageRect(): void {
432-
const stage = this.stage()?.nativeElement;
433432
const img = this.displayImg()?.nativeElement;
434433

435-
if (!stage || !img) {
434+
if (!img) {
436435
return;
437436
}
438437

439-
// The stage carries the zoom as a CSS `transform: scale(...)`, so
440-
// getBoundingClientRect returns painted (scaled) values. Divide back out so
441-
// the rect is in the stage's logical CSS px — the same space the crop overlay
442-
// (a child of the scaled stage) positions itself in. Without this the crop
443-
// box drifts at any zoom other than 100%.
444-
const scale = this.zoomLevel() / 100;
445-
const stageBox = stage.getBoundingClientRect();
446-
const imgBox = img.getBoundingClientRect();
447-
438+
// Measure the image's LAYOUT box (offset*) relative to the stage, not
439+
// `getBoundingClientRect()/scale`. The stage carries the zoom as a CSS
440+
// `transform: scale(...)` with a 150ms transition; a painted rect read
441+
// mid-transition and divided by the final scale yields a slightly-wrong size
442+
// that then sticks (ResizeObserver is layout-based, so it never fires again to
443+
// correct it) — which left the default crop box a few px short of the image
444+
// edges. `offset*` is the true pre-transform size in the stage's logical CSS
445+
// px — the exact space the crop overlay positions itself in — so the box
446+
// always matches the image at any zoom. (Its `offsetParent` is the
447+
// position:relative stage.)
448448
this.imageRect.set({
449-
x: (imgBox.left - stageBox.left) / scale,
450-
y: (imgBox.top - stageBox.top) / scale,
451-
width: imgBox.width / scale,
452-
height: imgBox.height / scale
449+
x: img.offsetLeft,
450+
y: img.offsetTop,
451+
width: img.offsetWidth,
452+
height: img.offsetHeight
453453
});
454454
}
455455

0 commit comments

Comments
 (0)