Resize n/w: inkrementell delta i stedet for kumulativ
Forrige versjon sendte total offset fra startposisjon på hvert pointermove-event, som ble addert gjentatte ganger og akselererte panelet ut av bildet. Nå beregnes delta fra forrige frame. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b8be448908
commit
b37746207a
1 changed files with 11 additions and 3 deletions
|
|
@ -82,6 +82,8 @@
|
|||
let resizeStartY = 0;
|
||||
let resizeStartW = 0;
|
||||
let resizeStartH = 0;
|
||||
let resizeLastW = 0;
|
||||
let resizeLastH = 0;
|
||||
|
||||
// Track drag interaction
|
||||
let dragStartX = 0;
|
||||
|
|
@ -205,6 +207,9 @@
|
|||
resizeStartW = clampedWidth;
|
||||
resizeStartH = clampedHeight;
|
||||
|
||||
resizeLastW = clampedWidth;
|
||||
resizeLastH = clampedHeight;
|
||||
|
||||
// Capture on the document level for smooth resizing
|
||||
window.addEventListener('pointermove', handleResizeMove);
|
||||
window.addEventListener('pointerup', handleResizeEnd);
|
||||
|
|
@ -233,11 +238,14 @@
|
|||
const clampedW = Math.min(constraints.maxWidth, Math.max(constraints.minWidth, newW));
|
||||
const clampedH = Math.min(constraints.maxHeight, Math.max(constraints.minHeight, newH));
|
||||
|
||||
// Position delta for n/w dragging: move origin to keep the opposite edge fixed
|
||||
// Incremental position delta for n/w dragging
|
||||
let posDx = 0;
|
||||
let posDy = 0;
|
||||
if (resizeDir.includes('w')) posDx = resizeStartW - clampedW;
|
||||
if (resizeDir.includes('n')) posDy = resizeStartH - clampedH;
|
||||
if (resizeDir.includes('w')) posDx = resizeLastW - clampedW;
|
||||
if (resizeDir.includes('n')) posDy = resizeLastH - clampedH;
|
||||
|
||||
resizeLastW = clampedW;
|
||||
resizeLastH = clampedH;
|
||||
|
||||
onResize?.(clampedW, clampedH, posDx, posDy);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue