Fit exported diagram HTML to its content without extra scroll
This commit is contained in:
@@ -214,7 +214,8 @@ func diagramHTML(_ diagram: DiagramLayout) -> String {
|
||||
if(opening){bar.append(el("span","grow",""));bar.append(el("button","on","Open "+D.levels[picked].title+" ›",()=>go(picked,null)))}
|
||||
}
|
||||
let s=1,tx=0,ty=0;
|
||||
const apply=()=>world.setAttribute("transform",`translate(${tx} ${ty}) scale(${s})`);
|
||||
const bound=(t,view,size)=>size<=view?(view-size)/2:Math.min(0,Math.max(view-size,t));
|
||||
const apply=()=>{const r=svg.getBoundingClientRect();tx=bound(tx,r.width,L.width*s);ty=bound(ty,r.height,L.height*s);world.setAttribute("transform",`translate(${tx} ${ty}) scale(${s})`)};
|
||||
function fit(){const r=svg.getBoundingClientRect();s=Math.min(2,r.width/L.width,r.height/L.height);tx=(r.width-L.width*s)/2;ty=(r.height-L.height*s)/2;apply()}
|
||||
function zoom(f,cx,cy){const n=Math.min(6,Math.max(.25,s*f));tx=cx-(cx-tx)*n/s;ty=cy-(cy-ty)*n/s;s=n;apply()}
|
||||
const local=e=>{const r=svg.getBoundingClientRect();return[e.clientX-r.left,e.clientY-r.top]};
|
||||
|
||||
Reference in New Issue
Block a user