diff --git a/bzGraflow.js b/bzGraflow.js index 53ff9e9..f3a6c50 100644 --- a/bzGraflow.js +++ b/bzGraflow.js @@ -1196,6 +1196,11 @@ class BZgraflow extends Buildoz{ autofit(percent=100){ if(!this.parentElement) return + + const prevTransformOrigin = this.style.transformOrigin + this.style.transform = 'none' + this.style.transformOrigin = 'top left' + // Measure real content by unioning viewport-space bounding boxes. // This is robust with overflow:auto and absolute-positioned layers. let left = Infinity @@ -1224,7 +1229,11 @@ class BZgraflow extends Buildoz{ const sx = parentBB.width / contentW const sy = parentBB.height / contentH const scale = Math.min(sx, sy)*(percent/100) // uniform scale to fit inside parent - this.style.transform = `scale(${scale})` + const tx = Number.isFinite(left) ? (-left + gapx) : gapx + const ty = Number.isFinite(top) ? (-top + gapy) : gapy + this.style.transformOrigin = prevTransformOrigin || 'top left' + // First normalize content origin to (0,0), then scale to fit. + this.style.transform = `scale(${scale}) translate(${tx}px, ${ty}px)` } } Buildoz.define('graflow', BZgraflow)