diff --git a/web/site-packing.js b/web/site-packing.js index 2c0f7ed..05c6881 100644 --- a/web/site-packing.js +++ b/web/site-packing.js @@ -12,6 +12,18 @@ function carregarImagem(file){ fr.readAsDataURL(file); }); } +// The image each artwork was measured with, loaded once and reused on every +// repaint: the packing used to read and decode the whole file again each +// time. Kept outside the artwork, which is saved with the cart. +const imagensDasArtes=new WeakMap(); +function imagemDaArte(a){ + if(!a.src) return Promise.resolve(null); + const guardada=imagensDasArtes.get(a); + if(guardada && guardada.src===a.src) return guardada.img; + const img=new Promise(res=>{ const im=new Image(); im.onload=()=>res(im); im.onerror=()=>res(null); im.src=a.src; }); + imagensDasArtes.set(a,{src:a.src,img}); + return img; +} // A folha precisa parecer uma folha: borda, largura marcada e régua de metros. // Sem isso o cliente não tem noção de escala e acha que está mal encaixado. function molduraFolha(ctx,W,H,larguraCm,metrosReais){ @@ -199,12 +211,14 @@ function desenhaMontagem(area,lista,mts,W,fora,aoTerminar){ return; } - Promise.all(itens.map(a=>carregarImagem(a.f).then(img=>({a,img})))).then(imagens=>{ + Promise.all(itens.map(a=>imagemDaArte(a).then(img=>({a,img})))).then(imagens=>{ if(area.montagemVersao!==versao) return; const cargas=imagens.flatMap(c=>Array.from({length:c.a.q||1},(_,copyIndex)=>({...c,copyIndex}))); cargas.forEach(c=>{ c.w = c.a.cm; // o motor trabalha em centímetros - c.h = c.w * (c.img ? (c.a.giro? c.img.width/c.img.height : c.img.height/c.img.width) : 1); + // The file's own proportion: a large artwork is drawn from a smaller copy. + const prop = c.a.prop>0 ? c.a.prop : c.img ? c.img.height/c.img.width : 1; + c.h = c.w * (c.a.giro? 1/prop : prop); c.travado = !!c.a.giro; // giro do cliente manda no encaixe }); const enc=encaixar(cargas,filme); diff --git a/web/site-pdf.js b/web/site-pdf.js index 1cb060b..929ad87 100644 --- a/web/site-pdf.js +++ b/web/site-pdf.js @@ -492,11 +492,23 @@ function sugestao(a){ } const n1=v=>v.toFixed(1).replace('.',','); +// Moves one artwork's progress in place, without repainting the list. +function pintaProgressoArte(a){ + const el=$('lista').querySelector('.art[data-arte="'+artes.indexOf(a)+'"]'); + const barra=el && el.querySelector('.prog i'), texto=el && el.querySelector('.progT'); + if(!barra){ pintaArtes(); return; } + barra.style.width=a.lendo+'%'; if(texto) texto.textContent='arquivo grande · gerando a prévia… '+a.lendo+'%'; +} function pintaArtes(){ invalidaItemAtual(); $('lista').innerHTML=artes.map((a,i)=>{ let barra='', dica='', calc='informe a largura para ver a qualidade'; - if(a.decodeError){ + if(a.lendo!=null){ + barra='