diff --git a/web/index.html b/web/index.html
index 2dbfd7c..f55a6f2 100644
--- a/web/index.html
+++ b/web/index.html
@@ -1204,6 +1204,7 @@ h2 em{font-style:normal;color:var(--laranja)}
+
diff --git a/web/kanban-montador.js b/web/kanban-montador.js
index d8996cc..ab9ff13 100644
--- a/web/kanban-montador.js
+++ b/web/kanban-montador.js
@@ -1,12 +1,14 @@
/* Kanban DTF: "Montar folha" (Fase 2, front 7). The stamps are the PNG files
in Estampas/ inside the folder chosen in Integrações; the sizes are the
- table Gestão edits. Slice 1: the list and the estimate; Montar is slice 2.
- Uses the globals of kanban.js, loaded first. */
+ table Gestão edits. The packing is the Site's own engine (web/packing.js).
+ Montar, which creates the card, is slice 2b. Uses the globals of kanban.js
+ and packing.js, loaded first. */
const MONTAR_CODE=/^[A-Za-z0-9_-]{1,40}$/;
// The Site's ruler (web/site-config.js): the same numbers, copied there too.
const MONTAR_DPI_REFUSE=96, MONTAR_DPI_WARN=200;
const MONTAR_FILM_CM=57, MONTAR_GAP_CM=0.5;
-const MONTAR={sizes:[],lines:[],seq:0,preview:null,timer:null,dirty:false,token:0};
+const MONTAR={sizes:[],lines:[],seq:0,preview:null,timer:null,dirty:false,token:0,
+ layout:null,layoutTimer:null,layoutToken:0,layoutPending:false};
const montarFolderReady=()=>!!FOLDER.handle&&!!FOLDER.granted;
const montarDpi=found=>found.width/(found.widthCm/2.54);
@@ -104,9 +106,85 @@ function montarEstimate(){
return (MONTAR_GAP_CM+total)/100;
}
function montarPaintTotals(){
- $('montar-total').textContent='Estimativa: '+metres(montarEstimate());
+ const done=MONTAR.layout&&!MONTAR.layoutPending;
+ $('montar-total').textContent=done
+ ? 'Montagem: '+metres(MONTAR.layout.altura/100)
+ : 'Estimativa: '+metres(montarEstimate())+(MONTAR.layoutPending?' · montando…':'');
$('montar-count').textContent=MONTAR.lines.length?plural(MONTAR.lines.length,'estampa','estampas'):'';
$('montar-clear').disabled=!MONTAR.lines.length;
+ $('montar-warning').hidden=!(MONTAR.lines.length>20||MONTAR.lines.some(line=>line.qty>200));
+}
+// The line's image, loaded once and kept for the packing and the preview.
+function montarStampImage(url){
+ const img=new Image();
+ const loading=new Promise(ok=>{img.onload=()=>ok(img);img.onerror=()=>ok(null);});
+ img.src=url;
+ return {img,loading};
+}
+// Every list change shows the estimate at once and schedules the real packing,
+// 300 ms later; a run that finishes after a newer change is thrown away.
+function montarChanged(){
+ MONTAR.layoutToken+=1;
+ MONTAR.layout=null;
+ MONTAR.layoutPending=true;
+ montarPaintLines();
+ if(!MONTAR.lines.length)montarDrawPreview(null);
+ clearTimeout(MONTAR.layoutTimer);
+ MONTAR.layoutTimer=setTimeout(()=>montarLayout(MONTAR.layoutToken).catch(e=>say(e.message,true)),300);
+}
+async function montarLayout(token){
+ if(token!==MONTAR.layoutToken)return;
+ const lines=[...MONTAR.lines];
+ if(!lines.length){MONTAR.layout=null;MONTAR.layoutPending=false;montarPaintTotals();montarDrawPreview(null);return;}
+ const images=await Promise.all(lines.map(line=>line.loading));
+ if(token!==MONTAR.layoutToken)return;
+ if(images.some(image=>!image)){
+ MONTAR.layoutPending=false;montarPaintTotals();
+ say('A estampa não pôde ser lida.',true);return;
+ }
+ const cargas=lines.flatMap((line,sourceIndex)=>Array.from({length:line.qty},(_,copyIndex)=>({
+ a:{sourceIndex,giro:0,esp:false},img:line.img,copyIndex,w:line.widthCm,h:line.heightCm,travado:false})));
+ let enc;
+ try{enc=encaixar(cargas,MONTAR_FILM_CM);}
+ catch(e){
+ if(token!==MONTAR.layoutToken)return;
+ MONTAR.layoutPending=false;montarPaintTotals();say(e.message,true);return;
+ }
+ if(token!==MONTAR.layoutToken)return;
+ MONTAR.layout={token,altura:enc.altura,pos:enc.pos};
+ MONTAR.layoutPending=false;
+ montarPaintTotals();
+ montarDrawPreview(MONTAR.layout);
+}
+// The sheet's preview: 57 cm across the panel, white film and the outline.
+function montarDrawPreview(layout){
+ const box=$('montar-layout'),canvas=$('montar-canvas');
+ if(!layout){box.hidden=true;return;}
+ box.hidden=false;
+ const width=box.clientWidth-24; // the box's padding
+ if(width<60)return;
+ const px=width/MONTAR_FILM_CM;
+ const height=Math.max(20,layout.altura*px);
+ const dpr=Math.min(2,window.devicePixelRatio||1);
+ canvas.width=Math.round(width*dpr);canvas.height=Math.round(height*dpr);
+ canvas.style.width=width+'px';canvas.style.height=height+'px';
+ const ctx=canvas.getContext('2d');
+ ctx.setTransform(dpr,0,0,dpr,0,0);
+ ctx.fillStyle='#fff';ctx.fillRect(0,0,width,height);
+ ctx.strokeStyle='#B4BAC5';ctx.lineWidth=1;
+ ctx.strokeRect(.5,.5,width-1,height-1);
+ for(const p of layout.pos){
+ const c=p.ref;
+ const giro=(p.rot===90?90:0)+(c.a&&c.a.giro?90:0);
+ ctx.save();
+ ctx.translate((p.x+p.w/2)*px,(p.y+p.h/2)*px);
+ ctx.rotate(giro*Math.PI/180);
+ if(c.a&&c.a.esp)ctx.scale(-1,1);
+ const dw=((giro%180===90)?p.h:p.w)*px, dh=((giro%180===90)?p.w:p.h)*px;
+ if(c.img)ctx.drawImage(c.img,-dw/2,-dh/2,dw,dh);
+ else{ctx.fillStyle='#E7E7E3';ctx.fillRect(-dw/2,-dh/2,dw,dh);}
+ ctx.restore();
+ }
}
function montarLine(line){
const row=node('div',undefined,'montar-line');
@@ -118,7 +196,7 @@ function montarLine(line){
qty.onchange=()=>{
const value=Math.round(Number(qty.value));
if(!Number.isInteger(value)||value<1||value>9999){qty.value=String(line.qty);return;}
- line.qty=value;qty.value=String(value);montarPaintTotals();
+ line.qty=value;qty.value=String(value);montarChanged();
};
const dpi=node('span',undefined,'montar-dpi');
if(line.dpiother!==line);
- montarPaintLines();
+ montarChanged();
}
function montarClear(){
for(const line of MONTAR.lines)URL.revokeObjectURL(line.url);
MONTAR.lines=[];
- montarPaintLines();
+ montarChanged();
}
async function montarAdd(){
@@ -159,10 +237,11 @@ async function montarAdd(){
const dpi=montarDpi(found);
if(dpiline.code===code&&line.letter===size.letter);
- if(existing){existing.qty=Math.min(9999,existing.qty+qty);montarPaintLines();return;}
+ if(existing){existing.qty=Math.min(9999,existing.qty+qty);montarChanged();return;}
+ const url=URL.createObjectURL(found.file),picture=montarStampImage(url);
MONTAR.lines.push({id:++MONTAR.seq,code,letter:size.letter,widthCm:found.widthCm,qty,
- heightCm:montarHeight(found),dpi,url:URL.createObjectURL(found.file),file:found.file});
- montarPaintLines();
+ heightCm:montarHeight(found),dpi,url,img:picture.img,loading:picture.loading,file:found.file});
+ montarChanged();
}
function montarPaintSelect(){
@@ -226,8 +305,21 @@ async function loadMontador(){
else montarPaintHint();
}
montarPaintLines();
+ if(MONTAR.layout)montarDrawPreview(MONTAR.layout);
}
+// 2b splits an order that passes these limits into more than one sheet; from
+// now on it only warns, it does not block.
+const montarWarning=node('p','O pedido será dividido em mais de uma folha.','montar-warn');
+montarWarning.id='montar-warning';montarWarning.hidden=true;
+$('montar-sheet').insertBefore(montarWarning,$('montar-lines'));
+
+let montarResize=null;
+addEventListener('resize',()=>{
+ clearTimeout(montarResize);
+ montarResize=setTimeout(()=>{if(MONTAR.layout)montarDrawPreview(MONTAR.layout);},200);
+});
+
$('montar-code').addEventListener('input',montarQueuePreview);
$('montar-size').addEventListener('change',()=>montarPreview().catch(e=>say(e.message,true)));
$('montar-qty').addEventListener('keydown',event=>{
diff --git a/web/kanban.css b/web/kanban.css
index 36f73d5..6793fa3 100644
--- a/web/kanban.css
+++ b/web/kanban.css
@@ -1255,6 +1255,9 @@ dialog.viewer::backdrop{background:var(--scrim)}
#tab-montar .montar-height{font-size:13px;color:var(--tx2);text-align:right;white-space:nowrap}
#tab-montar #montar-lines .emptystate{padding:28px 18px}
#tab-montar .montar-actions{display:flex;justify-content:flex-end;gap:10px;padding:12px 18px;border-top:1px solid var(--ln)}
+#tab-montar .montar-warn{margin:0;padding:10px 18px;border-bottom:1px solid var(--ln);font-size:13px;font-weight:600;color:var(--warn)}
+#tab-montar .montar-layout{height:340px;overflow:auto;scrollbar-gutter:stable;border-top:1px solid var(--ln);background:var(--sf2);padding:12px}
+#tab-montar .montar-layout canvas{display:block;margin:0 auto;background:#fff;box-shadow:0 0 0 1px var(--ln2)}
#tab-montar .montar-sizes{display:flex;flex-direction:column;padding:8px 0}
#tab-montar .montar-size-head,#tab-montar .montar-size-row{display:grid;grid-template-columns:90px 160px 36px;gap:12px;align-items:center;padding:6px 18px}
#tab-montar .montar-size-head{font-size:12.5px;color:var(--tx3)}
@@ -1273,5 +1276,7 @@ dialog.viewer::backdrop{background:var(--scrim)}
#tab-montar .montar-line>.btn{grid-area:remove}
#tab-montar .montar-actions{flex-wrap:wrap;padding:12px 14px}
#tab-montar .montar-actions .btn{flex:1}
+ #tab-montar .montar-warn{padding:10px 14px}
+ #tab-montar .montar-layout{height:260px;padding:8px}
#tab-montar .montar-size-head,#tab-montar .montar-size-row{grid-template-columns:70px minmax(0,1fr) 36px;padding:6px 14px}
}
diff --git a/web/kanban.html b/web/kanban.html
index d2818a0..e87755d 100644
--- a/web/kanban.html
+++ b/web/kanban.html
@@ -131,6 +131,7 @@
Folha
+
@@ -231,4 +232,4 @@
-