feat: a ready sheet prints at its real size, centred on the film, with the customer's confirmation (Marcus, 2026-12-02)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m55s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m43s

Replaces 7111995 (only 57,0 cm entered; a whole order of 56,5-56,9 cm
sheets was refused, DTF-WEB-2C). Marcus's rules, for Arquivo por metro,
Premium (57 cm) and UV (27 cm):
1. A known width up to the film (PNG recording 200 DPI or more, or a PDF
   page) enters at its real size, centred, billed by its real height.
2. Narrower: his warning before the cart, confirmation required
   (Imprimir no tamanho real / Enviar outro arquivo); recorded in the
   Prumo report ("cliente confirmou folha de 35,8 cm no tamanho real") and
   shown in the cart and payment summaries.
3. Wider than the film: refused with his message.
4. Unknown width: taken as the film's, DPI from the pixels; 200 or more
   with a confirmation, under 200 refused with the artes avulsas hint.
Within 0,1 cm of the film counts as the film. The server checks it all
again at checkout (sheet_width_issue, centred placement, size_confirmed).

Also ops.stretched_sheets: the ready-sheet orders since 16/10 laid out
wider than their real width (number, real width, factor), for Marcus.
Contract: output/revisao/contrato-folha-real.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-12-02 09:51:38 -03:00
parent 7af6c9797d
commit 41126a42fd
22 changed files with 634 additions and 153 deletions

View File

@@ -192,16 +192,24 @@
const amount=document.createElement('b'); amount.textContent=value;
row.append(name,amount); return row;
};
const umaCasa = value => Number(value).toFixed(1).replace('.',',');
// The sheets of a split (item 17) are one line, as in the cart.
const linhas=[];
const linhas=[], estreitas=[];
for (const item of approved.items) {
const grupo=item.split && linhas.find(l=>l.split?.group===item.split.group);
if (grupo) { grupo.billed_metres=String(Number(grupo.billed_metres)+Number(item.billed_metres)); grupo.total_cents+=item.total_cents; grupo.folhas++; }
else linhas.push({...item,folhas:1});
const film=item.production?.film_width_cm;
if (film!=null) for (const source of item.production.sources || []) {
if (source.kind==='sheet' && Number(source.width_cm) < Number(film)-0.1)
estreitas.push('Folha de '+umaCasa(source.width_cm)+' cm no tamanho real, '+
'centralizada no filme de '+String(Number(film)).replace('.',',')+' cm');
}
}
const rows = linhas.map(item => linha(
(MODOS[item.mode]?.tit || item.mode)+(item.folhas>1?' · '+item.folhas+' folhas':'')+' · '+
fmtM(Number(item.billed_metres))+' m', rs(item.total_cents/100)));
rows.push(...estreitas.map(texto => linha(texto,'')));
const pickup = approved.freight.service === 'pickup';
const prazo = approved.freight.days ? ' · até '+approved.freight.days+' dias úteis' : '';
rows.push(linha(pickup ? 'Retirada em Franca' : (approved.freight.description || 'Frete')+prazo,

View File

@@ -972,13 +972,20 @@ h2 em{font-style:normal;color:var(--laranja)}
</div>
</dialog>
<dialog class="ampliaDlg mistaDlg" id="larguraDlg" aria-labelledby="larguraTit">
<div class="ampliaCab"><b id="larguraTit">A folha precisa ter 57 cm de largura</b></div>
<div class="ampliaCab"><b id="larguraTit">A folha não cabe no filme de 57 cm</b></div>
<div class="mistaCorpo">
<ul id="larguraLista"></ul>
<p>Ajuste a largura da folha no seu programa para 57 cm e envie de novo.</p>
<p id="larguraTxt">Reduza no seu programa ou envie as artes separadas.</p>
<div class="mistaBot"><button type="button" class="ec-go" id="larguraOk">Entendi</button></div>
</div>
</dialog>
<dialog class="ampliaDlg mistaDlg" id="tamanhoDlg" aria-labelledby="tamanhoTit">
<div class="ampliaCab"><b id="tamanhoTit">Tamanho da folha</b></div>
<div class="mistaCorpo">
<p id="tamanhoTxt"></p>
<div class="mistaBot"><button type="button" class="ec-go" id="tamanhoOk">Confirmar</button><button type="button" id="tamanhoOutro">Enviar outro arquivo</button></div>
</div>
</dialog>
<dialog class="ampliaDlg" id="ampliaDlg" aria-labelledby="ampliaTit">
<div class="ampliaCab"><b id="ampliaTit">Sua folha</b>
<button type="button" id="ampliaFecha" aria-label="Fechar"><svg class="ic" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button></div>

View File

@@ -213,6 +213,17 @@ function itemParaSalvar(it){
}
return copia;
}
// A folha que entra no tamanho real, centralizada no filme: o resumo diz isso
// uma vez por folha estreita confirmada.
function folhasEstreitas(it){
const p=it.production;
if(!p || p.film_width_cm==null) return [];
const filme=Number(p.film_width_cm);
return (p.sources||[]).filter(s=>s.kind==='sheet' &&
Number(s.width_cm)<filme-0.1).map(s=>
'Folha de '+n1(Number(s.width_cm))+' cm no tamanho real, centralizada no filme de '+
String(filme).replace('.',',')+' cm');
}
// O carrinho junta itens de produtos diferentes e cobra uma vez só.
function pintaPedido(){
const aPagar = itensAPagar();
@@ -242,6 +253,7 @@ function pintaPedido(){
'<span class="miniItem">'+(it.mini ? '<img src="'+escapeHTML(it.mini)+'" alt="">' : '<i>'+escapeHTML(it.ext||'')+'</i>')+
(it.arquivos>1 ? '<em>+'+(it.arquivos-1)+'</em>' : '')+'</span>'+
'<div class="nm2"><b>'+escapeHTML(it.tit)+'</b><span>'+escapeHTML(it.desc)+'</span>'+
folhasEstreitas(it).map(l=>'<span>'+l+'</span>').join('')+
(semMargem(it)?'<span class="avisoF">O espaço entre as cópias passou a ser de 8 mm. Remova este item e adicione a folha de novo.</span>':'')+'</div>'+
'<div class="vl2">'+rs(it.total)+'</div>'+
(window.dtfContaAberta?'<button type="button" class="salvaBt" data-salvai="'+i+'"'+
@@ -353,7 +365,7 @@ function carrinho(){
const sources=(ehFolha()?folhas:artes).map(x=>ehFolha()
? {kind:'sheet',width_cm:x.med?.larg||larguraFilme(),length_cm:+(x.m*100).toFixed(4),
copies:x.rep||1,rotation_degrees:0,mirrored:false,
measurement:x.med?'file':'customer',
measurement:x.med?'file':'customer',size_confirmed:!!x.confirmado,
// The empty strips cut from the top and the bottom (aplicaCorte).
...(x.corte?{trim_top_cm:x.corte.topo,trim_bottom_cm:x.corte.fim}:{})}
: fonteDaArte(x));
@@ -365,7 +377,8 @@ function carrinho(){
for(let copy_index=0;copy_index<source.copies;copy_index++){
// MARGEM_FOLHA_CM entre uma cópia e a próxima, nunca depois da última.
if(placements.length)y+=MARGEM_FOLHA_CM;
placements.push({source_index,copy_index,x_cm:0,y_cm:+y.toFixed(4),
placements.push({source_index,copy_index,
x_cm:+((larguraFilme()-source.width_cm)/2).toFixed(4),y_cm:+y.toFixed(4),
width_cm:source.width_cm,length_cm:source.length_cm,
rotation_degrees:0,mirrored:false});
y+=source.length_cm;

View File

@@ -114,14 +114,14 @@ const ACEITA={
};
const MEDE=/[.](png|jpe?g|webp|gif|bmp|pdf)$/i;
const DPI_RECUSA=96, DPI_AVISA=200; // régua aprovada pela Dropstar · 05/11/2026
// A folha pronta dos produtos têxteis de 57 cm tem de ter 57 cm de largura
// quando a largura real é conhecida: abre um aviso e não entra (Marcus,
// 01/12). Conhecida é um PNG que grava DPI_TAMANHO_REAL ou mais (o limite do
// A1, rodada 5) ou a página de um PDF; o resto segue a regra da versão 0
// (esticada até o filme). output/revisao/contrato-largura-folha.md.
const LARGURA_EXATA={file:57, premium:57};
// Folha pronta no tamanho real, centralizada no filme (Marcus, 02/12):
// output/revisao/contrato-folha-real.md. A largura é conhecida num PNG que
// grava DPI_TAMANHO_REAL ou mais (o limite do A1) e na página de um PDF; senão
// vale a do filme e o DPI sai dos pixels, com DPI_MINIMO_FOLHA de piso.
// Dentro de LARGURA_TOLERANCIA_CM da largura do filme conta como o filme.
const LARGURA_TOLERANCIA_CM=0.1;
const DPI_TAMANHO_REAL=200;
const DPI_MINIMO_FOLHA=200;
// A especificação do PDF limita a página a 14.400 unidades — 200 pol, 508 cm.
// Passar disso só é válido com UserUnit (PDF 1.6+), que a maioria dos programas
// não escreve: o arquivo sai fora do padrão e só o gerador lê direito.

View File

@@ -11,6 +11,11 @@
// straight to the cart.
$('qOk').addEventListener('click',()=>{
if($('qOk').disabled) return;
// A folha que pede confirmação de tamanho (Marcus, 02/12) só entra confirmada.
if(ehFolha() && folhas.some(x=>x.med?.confirmar && !x.confirmado)){
qm('Confirme o tamanho da folha antes de adicionar.','var(--vermelho)');
proximaTamanho(); return;
}
if(!$('prev').classList.contains('on')){ adicionaAoCarrinho(); return; }
const ok=$('ciente').classList.contains('on');
qm(ok? '<b>Ressalva aceita.</b> Confira a folha montada abaixo.'

View File

@@ -95,9 +95,9 @@ function recusaFolha(x, md){
folhas=folhas.filter(y=>y!==x);
pintaFolha();
avisoTipo('<b>'+escapeHTML(arquivo.name)+' não é uma folha montada.</b> '+
'Nos '+n1(larguraFilme())+' cm do filme ela teria só '+md.dpiFolha+
' DPI, abaixo do mínimo de '+DPI_RECUSA+'. '+
'Se for uma arte para montarmos, use <b>'+MODOS[destino].tit+'</b>, '+
'Nos '+larguraFilme()+' cm do filme ela teria só '+md.dpiFolha+
' DPI, abaixo do mínimo de '+DPI_MINIMO_FOLHA+'. '+
'Se a sua folha não tem '+larguraFilme()+' cm, suba as artes como <b>'+MODOS[destino].tit+'</b>, '+
'a '+rs(PRECO[destino])+' o metro. '+
'<button type="button" id="usarAvulsa">Enviar como '+MODOS[destino].tit.toLowerCase()+'</button>');
const botao=$('usarAvulsa');

View File

@@ -360,17 +360,22 @@ function medirFolha(file){
if(/\.png$/.test(nome)){
dimensoesImagem(file).then(async d=>{
if(!d || !(d.w>0) || !(d.h>0)) return res({rejected:true,reason:'Não foi possível ler as dimensões do PNG. Exporte novamente.'});
// Folha têxtil de 57 cm: se o PNG diz o DPI real, a largura tem de ser 57.
const exata=LARGURA_EXATA[modo];
if(exata!=null){
const dpi=await dpiSalvoPng(file);
if(dpi>=DPI_TAMANHO_REAL){
const cm=d.w/dpi*2.54;
if(Math.abs(cm-exata)>LARGURA_TOLERANCIA_CM) return res({larguraErrada:{cm, dpi}});
}
const L=larguraFilme(), tol=LARGURA_TOLERANCIA_CM, dpi=await dpiSalvoPng(file);
let measure;
if(dpi>=DPI_TAMANHO_REAL){
// A largura real vem do pHYs; até 0,1 cm além do filme conta como o filme.
const cm=d.w/dpi*2.54;
if(cm>L+tol) return res({largaDemais:{cm}});
// Até 0,1 cm além do filme é o filme: a folha nunca passa da largura dele.
measure={larg:Math.min(cm,L), alt:+(d.h/dpi*2.54).toFixed(1), fonte:'dimensões do arquivo',
dpiFolha:dpi, px:d.w};
if(cm<L-tol) measure.confirmar='estreita';
}else{
// Sem DPI confiável a folha vale o filme inteiro; o DPI sai dos pixels.
measure={larg:L, alt:+(d.h/d.w*L).toFixed(1), fonte:'dimensões do arquivo',
dpiFolha:Math.round(d.w/(L/2.54)), px:d.w, larguraDesconhecida:true};
if(measure.dpiFolha>=DPI_MINIMO_FOLHA) measure.confirmar='desconhecida';
}
const L=larguraFilme(), measure={larg:L,alt:+(d.h/d.w*L).toFixed(1),
fonte:'dimensões do arquivo',dpiFolha:Math.round(d.w/(L/2.54)),px:d.w};
if(d.h>32767 || file.size>GRANDE_BYTES) return res({...measure,grande:true,tall:d.h>32767});
// A PNG the phone cannot open whole (out of memory, a 57 MB sheet on
// 26/11) is read in bands like a large one, never sent to the manual
@@ -382,21 +387,25 @@ function medirFolha(file){
if(RENDERIZA.test(nome) && file.size>GRANDE_BYTES){
dimensoesImagem(file).then(d=>{
if(!d || !(d.w>0) || !(d.h>0)) return res(null);
const L=larguraFilme();
res({larg:L, alt:+(d.h/d.w*L).toFixed(1), fonte:'dimensões do arquivo',
dpiFolha:Math.round(d.w/(L/2.54)), px:d.w, grande:true});
const L=larguraFilme(), dpiFolha=Math.round(d.w/(L/2.54));
const measure={larg:L, alt:+(d.h/d.w*L).toFixed(1), fonte:'dimensões do arquivo',
dpiFolha, px:d.w, grande:true, larguraDesconhecida:true};
if(dpiFolha>=DPI_MINIMO_FOLHA) measure.confirmar='desconhecida';
res(measure);
}).catch(()=>res(null));
return;
}
if(RENDERIZA.test(nome)){
carregarImagem(file).then(img=>{
if(!img || !img.width) return res(null);
const L=larguraFilme();
const L=larguraFilme(), dpiFolha=Math.round(img.width/(L/2.54));
// Uma imagem só é folha montada se tiver pixel para ocupar a largura do
// filme. Sem esta conferência, qualquer arte pequena vira "folha" e leva
// o preço por metro sem nunca ter sido montada.
res({larg:L, alt:+(img.height/img.width*L).toFixed(1), fonte:'proporção da imagem',
dpiFolha:Math.round(img.width/(L/2.54)), px:img.width});
const measure={larg:L, alt:+(img.height/img.width*L).toFixed(1), fonte:'proporção da imagem',
dpiFolha, px:img.width, larguraDesconhecida:true};
if(dpiFolha>=DPI_MINIMO_FOLHA) measure.confirmar='desconhecida';
res(measure);
});
return;
}
@@ -428,14 +437,14 @@ function medirFolha(file){
const w=vp.width*unit*PT_CM, h=vp.height*unit*PT_CM;
if(!Number.isFinite(w) || !Number.isFinite(h) || w<=0 || h<=0 || h>6000)
return {rejected:true, reason:'Esta página é grande demais. Divida a folha em partes menores.'};
// A página do PDF já diz a largura real: fora de 57 cm, recusa.
const exata=LARGURA_EXATA[modo];
if(exata!=null && Math.abs(w-exata)>LARGURA_TOLERANCIA_CM)
return {larguraErrada:{cm:w, dpi:null}};
// Keep precise geometry for the fit and quote; the UI rounds only
// when displaying dimensions.
return {larg:+w.toFixed(3), alt:+h.toFixed(3),
// A página do PDF já diz a largura real: mais larga que o filme, não entra;
// mais estreita, entra no tamanho real e pede confirmação.
const L=larguraFilme(), tol=LARGURA_TOLERANCIA_CM;
if(w>L+tol) return {largaDemais:{cm:w}};
const medida={larg:+Math.min(w,L).toFixed(3), alt:+h.toFixed(3),
fonte:'página do PDF'+(unit!==1 ? ' · UserUnit '+unit : '')};
if(w<L-tol) medida.confirmar='estreita';
return medida;
}).then(res).catch(()=>res({rejected:true,
reason:'Não conseguimos ler este PDF. Exporte de novo como PDF de uma página ou PNG.'}))
.finally(()=>{ if(doc) doc.destroy().catch(()=>{}); });

View File

@@ -32,7 +32,7 @@ const TEXTO_MISTA={
// avulsa: imprimir assim mesmo (C1), ou trocar o arquivo por dois.
function perguntaMista(){
const dlg=$('mistaDlg');
if(!dlg || dlg.open || $('larguraDlg')?.open) return;
if(!dlg || dlg.open || $('larguraDlg')?.open || $('tamanhoDlg')?.open) return;
const lista=ehFolha()?folhas:artes;
const x=lista.find(y=>!y.mistaVista && mista(tracoDoArquivo(y)));
if(!x) return;

View File

@@ -48,19 +48,65 @@ function recusa(lista){
: '<b>'+exts+' não entra aqui.</b> Artes avulsas só aceitam PNG com '+
'fundo transparente. Para CDR, AI ou PSD, exporte em PNG ou use <b>Arquivo por metro</b>.';
}
// Folha de 57 cm com largura real conhecida e diferente: sai da lista e o
// diálogo junta os arquivos, um por linha, até o cliente fechar.
function recusaLargura(nome, {cm, dpi}){
// Folha mais larga que o filme: sai da lista e o diálogo junta os arquivos,
// um por linha, até o cliente fechar.
function recusaLargura(nome, {cm}){
const dlg=$('larguraDlg'); if(!dlg) return;
const lista=$('larguraLista');
const li=document.createElement('li');
li.textContent=nome+': '+n1(cm)+' cm'+(dpi==null?'':' ('+dpi+' DPI)');
li.textContent=nome+': tem '+n1(cm)+' cm e não cabe em '+larguraFilme()+' cm.';
lista.appendChild(li);
$('larguraTit').textContent='A folha não cabe no filme de '+larguraFilme()+' cm';
const texto=$('larguraTxt');
if(texto) texto.textContent='Reduza no seu programa ou envie as artes separadas.';
const ok=$('larguraOk');
ok.onclick=()=>dlg.close();
dlg.onclose=()=>{ lista.textContent=''; const z=$('zona'); if(z) z.focus(); agendaAvaliacao(); };
if(!dlg.open){ dlg.showModal(); ok.focus(); }
}
// Uma folha por vez, na ordem em que chegaram. Uma folha que já saiu da lista
// (troca de modo, remoção) é pulada; confirmar segue para a próxima.
let filaTamanho=[], tamanhoAtual=null;
function proximaTamanho(){
const dlg=$('tamanhoDlg'); if(!dlg || dlg.open) return;
while(filaTamanho.length && (!folhas.includes(filaTamanho[0]) || !filaTamanho[0].med?.confirmar))
filaTamanho.shift();
const x=filaTamanho.shift();
if(!x || !MODOS[modo] || !ehFolha()){ tamanhoAtual=null; return; }
tamanhoAtual=x;
const md=x.med;
$('tamanhoTit').textContent=x.f.name;
if(md.confirmar==='estreita'){
$('tamanhoTxt').textContent='Sua folha tem '+n1(md.larg)+' cm de largura. '+
'Vamos imprimir no tamanho real, centralizada no filme de '+larguraFilme()+
' cm, e cobrar pela altura: '+fmtM(md.alt/100)+' m. Se quiser aproveitar a largura toda, '+
'remonte a folha com '+larguraFilme()+' cm no seu programa ou envie as artes separadas ('+
rs(PRECO[PAR[modo]]||PRECO[modo])+'/m) que nós encaixamos.';
$('tamanhoOk').textContent='Imprimir no tamanho real';
}else{
$('tamanhoTxt').textContent='Sua folha vai sair com '+larguraFilme()+' cm de largura e '+
n1(md.alt)+' cm de altura ('+md.dpiFolha+' DPI). Confirma?';
$('tamanhoOk').textContent='Confirmar';
}
$('tamanhoOk').className='ec-go';
dlg.showModal();
$('tamanhoOk').focus();
}
function resolveTamanho(acao){
const dlg=$('tamanhoDlg'), x=tamanhoAtual;
if(x && folhas.includes(x)){
if(acao==='confirmar') x.confirmado=true;
else folhas=folhas.filter(y=>y!==x);
pintaFolha();
}
tamanhoAtual=null;
if(dlg && dlg.open) dlg.close();
if(acao==='outro') $('inp').click();
setTimeout(proximaTamanho,0);
}
$('tamanhoDlg')?.addEventListener('cancel',e=>{ e.preventDefault(); resolveTamanho('cancelar'); });
$('tamanhoOk')?.addEventListener('click',()=>resolveTamanho('confirmar'));
$('tamanhoOutro')?.addEventListener('click',()=>resolveTamanho('outro'));
const Z=$('zona'), I=$('inp');
Z.addEventListener('click',()=>I.click());
Z.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){I.click();e.preventDefault();}});
@@ -221,16 +267,23 @@ async function sel(fs){
if(md && md.rejected){
x.measurementError=md.reason; x.pct=null; pintaFolha(); return;
}
if(md && md.larguraErrada){
if(md && md.largaDemais){
if(folhas.includes(x)){
folhas=folhas.filter(y=>y!==x);
pintaFolha();
recusaLargura(x.f.name, md.larguraErrada);
recusaLargura(x.f.name, md.largaDemais);
}
return;
}
if(md && md.dpiFolha!=null && md.dpiFolha<DPI_RECUSA) return recusaFolha(x, md);
x.med=md; if(md) x.m=md.alt/100; x.pct=55; pintaFolha();
if(md && md.larguraDesconhecida && md.dpiFolha<DPI_MINIMO_FOLHA)
return recusaFolha(x, md);
x.med=md; if(md) x.m=md.alt/100; x.pct=55;
if(md && md.confirmar){
x.confirmado=false;
if(!filaTamanho.includes(x)) filaTamanho.push(x);
}
pintaFolha();
if(md && md.confirmar) proximaTamanho();
if(md && md.grande){
// Graded at once from its size in pixels. A PNG is then read as a
// stream into a small copy: the preview, and the sheet check.