/* Site DTF — PDF measurement and rasterisation, and the DPI of images inside one.
Extracted verbatim from the single inline script in web/index.html.
Loaded as classic scripts in the order listed there: they share one global
scope and run top to bottom, exactly as the original did. */
// ── PDF também é conferido: rasteriza a página e mede o DPI das imagens de dentro.
// Arte vetorial não tem resolução — nesses casos a nota é máxima, e isso é correto.
// Served from this origin, not a CDN: the Site keeps working when a third party
// does not, and the CSP can name only 'self' for scripts and workers. Provenance
// and hashes are recorded in web/vendor/README.md.
const PDFJS_URL='/vendor/pdf.min.js';
const PDFJS_WORKER=new URL('/vendor/pdf.worker.min.js', location.origin).href;
let pdfLibP=null, temWorker=null;
// Check whether this browser can create a same-origin Worker. The worker file
// is served alongside this script and does not need a blob URL.
function testaWorker(url){
try{ const w=new Worker(url); w.terminate(); return true; }catch(e){ return false; }
}
function carregarPdfJs(){
if(typeof window==='undefined') return Promise.resolve(null);
if(window.pdfjsLib) return Promise.resolve(window.pdfjsLib);
if(pdfLibP) return pdfLibP;
pdfLibP=new Promise(res=>{
const sc=document.createElement('script');
sc.src=PDFJS_URL;
sc.onload=()=>{
try{
temWorker=testaWorker(PDFJS_WORKER);
window.pdfjsLib.GlobalWorkerOptions.workerSrc=PDFJS_WORKER;
}catch(e){
temWorker=false;
try{ window.pdfjsLib.GlobalWorkerOptions.workerSrc=PDFJS_WORKER; }catch(e2){}
}
res(window.pdfjsLib||null);
};
sc.onerror=()=>res(null);
document.head.appendChild(sc);
});
return pdfLibP;
}
// DPI real de cada imagem embutida: acompanha a matriz de transformação e compara
// o tamanho em que a imagem foi colocada com quantos pixels ela tem.
function dpiDasImagens(page, ops){
const mul=(a,b)=>[a[0]*b[0]+a[2]*b[1], a[1]*b[0]+a[3]*b[1],
a[0]*b[2]+a[2]*b[3], a[1]*b[2]+a[3]*b[3],
a[0]*b[4]+a[2]*b[5]+a[4], a[1]*b[4]+a[3]*b[5]+a[5]];
const O=window.pdfjsLib.OPS;
let ctm=[1,0,0,1,0,0]; const pilha=[]; const dpis=[];
for(let i=0;it+x.area,0) || 1;
const abaixoPiso=lista.filter(x=>x.dpix.dpit+x.dpi*x.area,0)/total;
return {
pior: Math.round(Math.min(...lista.map(x=>x.dpi))),
ponderado: Math.round(pond),
fracBaixa: abaixoPiso.reduce((t,x)=>t+x.area,0)/total,
fracAviso: abaixoAviso.reduce((t,x)=>t+x.area,0)/total,
quantasBaixas: abaixoPiso.length,
quantasAviso: abaixoAviso.length,
total: lista.length
};
}
// Rasteriza a primeira página a 1 mm por pixel e devolve a tela para a análise
// The page drawn small for the preview and, with comMapa, again in strips at
// about 0,2 mm per pixel for the ink map the residue check measures.
const PDF_PX_POR_CM=50, PDF_MAPA_PX=30e6;
async function rasterizarPdf(file, larguraCm, alturaCm, comMapa){
const lib=await carregarPdfJs();
if(!lib) return {erro:'não foi possível carregar o leitor de PDF'};
// Decide after the worker check; the old timeout always used 30 seconds.
const espera=(temWorker===false ? 90000 : 30000)*(comMapa ? 2 : 1);
const folga=temWorker===false ? 2.2 : 1;
let loading=null, doc=null, rendering=null, expired=false, timer=null;
const trabalho=(async()=>{
try{
const buf=await file.arrayBuffer();
if(expired) return null;
loading=lib.getDocument({data:buf, disableFontFace:true,
isEvalSupported:false, useSystemFonts:false, verbosity:0});
doc=await loading.promise;
if(expired || doc.numPages!==1) return null;
const page=await doc.getPage(1);
if(expired) return null;
const vp1=page.getViewport({scale:1});
const passo=passoDe(larguraCm, alturaCm||larguraCm)*folga;
const alvo=Math.max(8,Math.round(larguraCm/passo));
const vp=page.getViewport({scale:alvo/vp1.width});
const cv=document.createElement('canvas');
cv.width=Math.max(8,Math.round(vp.width)); cv.height=Math.max(8,Math.round(vp.height));
const ctx=cv.getContext('2d',{willReadFrequently:true});
rendering=page.render({canvasContext:ctx, viewport:vp, background:'rgba(0,0,0,0)'});
await rendering.promise;
if(expired) return null;
const ops=await page.getOperatorList();
if(expired) return null;
let dpis=[];
try{ dpis=dpiDasImagens(page,ops); }catch(e){}
const r=resumoDpi(dpis);
let mapa=null;
if(comMapa){
const altura=alturaCm||larguraCm*vp1.height/vp1.width;
const pxPorCm=Math.min(PDF_PX_POR_CM, Math.sqrt(PDF_MAPA_PX/(larguraCm*altura)));
const vpM=page.getViewport({scale:pxPorCm*larguraCm/vp1.width});
const W=Math.max(1,Math.round(vpM.width)), H=Math.max(1,Math.round(vpM.height));
mapa=novoMapa(W,H,larguraCm);
const faixa=Math.max(1,Math.min(H,Math.floor(4e6/W)));
const cvM=document.createElement('canvas'); cvM.width=W; cvM.height=faixa;
const ctxM=cvM.getContext('2d',{willReadFrequently:true});
for(let topo=0;topo{});
else if(loading) loading.destroy().catch(()=>{});
}
})();
const tardio=new Promise(resolve=>{
timer=setTimeout(()=>{
expired=true;
try{ if(rendering) rendering.cancel(); }catch(e){}
if(loading) loading.destroy().catch(()=>{});
resolve({erro:'demorou demais neste navegador',semWorker:temWorker===false});
},espera);
});
const result=await Promise.race([trabalho,tardio]);
clearTimeout(timer);
return result||{erro:'não deu para conferir',semWorker:temWorker===false};
}
// Sheets of several GB are the normal order. The browser cannot decode an image
// that size (it would freeze or crash the tab), and it does not need to: the
// grade comes from the width in pixels, which PNG, JPEG and WebP store in their
// first bytes. Above GRANDE_BYTES only those bytes are read.
const GRANDE_BYTES=150*1048576;
async function dimensoesImagem(file){
const b=new Uint8Array(await file.slice(0,Math.min(file.size,4*1048576)).arrayBuffer());
const u16=(i,le)=>le? b[i]|(b[i+1]<<8) : (b[i]<<8)|b[i+1];
const u32=(i)=>((b[i]<<24)>>>0)+(b[i+1]<<16)+(b[i+2]<<8)+b[i+3];
if(b[0]===0x89 && b[1]===0x50 && b[2]===0x4E && b[3]===0x47) // PNG · IHDR
return {w:u32(16), h:u32(20)};
if(b[0]===0xFF && b[1]===0xD8){ // JPEG · SOFn
let i=2;
while(i+9=0xC0 && m<=0xCF && ![0xC4,0xC8,0xCC].includes(m)) return {w:u16(i+7), h:u16(i+5)};
i+=2+len;
}
return null;
}
const tag=String.fromCharCode(...b.slice(8,16));
if(String.fromCharCode(...b.slice(0,4))==='RIFF' && tag.startsWith('WEBP')){ // WebP
if(tag==='WEBPVP8X') return {w:1+(b[24]|(b[25]<<8)|(b[26]<<16)), h:1+(b[27]|(b[28]<<8)|(b[29]<<16))};
if(tag==='WEBPVP8L'){ const n=b[21]|(b[22]<<8)|(b[23]<<16)|(b[24]<<24); return {w:(n&0x3FFF)+1, h:((n>>14)&0x3FFF)+1}; }
if(tag==='WEBPVP8 ') return {w:u16(26,true)&0x3FFF, h:u16(28,true)&0x3FFF};
}
return null;
}
// A small copy of a large PNG, read as a stream: the file is inflated in
// pieces and only every n-th pixel of every n-th row is kept, so memory stays
// at a few MB whatever the file's size. It is the preview. Given the sheet's
// width in cm (mapaCm), every pixel also goes into the ink map the sheet check
// reads, and it returns {cv, mapa}. 8- and 16-bit greyscale, RGB, palette and
// alpha; interlaced files return null.
async function previaPngGrande(file, larguraAlvo, progresso, mapaCm){
const leitor=file.stream().getReader();
let pedacos=[], guardado=0, lidos=0, fim=false;
// A queue of the file's pieces: take() never copies more than it returns.
const enche=async n=>{
while(guardado=n;
};
const tira=n=>{
const out=new Uint8Array(n); let k=0;
while(k((b[0]<<24)>>>0)+(b[1]<<16)+(b[2]<<8)+b[3];
if(!await enche(8)) return null; tira(8);
// 1 · header chunks, up to the first image data
let w=0,h=0,prof=0,tipo=-1,paleta=null,trns=null, idat=0;
for(;;){
if(!await enche(8)) return null;
const cab=tira(8), len=u32(cab), nome=String.fromCharCode(...cab.subarray(4,8));
if(nome==='IDAT'){ idat=len; break; }
if(!await enche(len+4)) return null;
const d=tira(len); tira(4);
if(nome==='IHDR'){ w=u32(d); h=u32(d.subarray(4)); prof=d[8]; tipo=d[9];
if(d[12]!==0 || ![8,16].includes(prof) || !{0:1,2:1,3:1,4:1,6:1}[tipo]) return null; }
else if(nome==='PLTE') paleta=d;
else if(nome==='tRNS') trns=d;
else if(nome==='IEND') return null;
}
if(!(w>0 && h>0) || (tipo===3 && (!paleta || prof!==8))) return null;
// 2 · image data streamed into the inflater, a piece at a time
const inflador=new DecompressionStream('deflate'), escritor=inflador.writable.getWriter();
const alimenta=(async()=>{
let resta=idat;
for(;;){
while(resta>0){
if(!guardado && !await enche(1)) { await escritor.close(); return; }
const n=Math.min(resta,guardado); await escritor.write(tira(n)); resta-=n;
}
if(!await enche(12)) break;
tira(4); // CRC of the chunk just sent
const cab=tira(8), len=u32(cab), nome=String.fromCharCode(...cab.subarray(4,8));
if(nome==='IDAT'){ resta=len; continue; }
break; // anything after the image data
}
await escritor.close();
})();
alimenta.catch(()=>{});
// 3 · rows unfiltered one at a time; every passo-th pixel is kept
const canais={0:1,2:3,3:1,4:2,6:4}[tipo], b=prof/8, bpp=canais*b, linha=w*bpp;
const passo=Math.max(1,Math.ceil(w/larguraAlvo));
const cw=Math.ceil(w/passo), ch=Math.ceil(h/passo);
const cv=document.createElement('canvas'); cv.width=cw; cv.height=ch;
const ctx=cv.getContext('2d'), img=ctx.createImageData(cw,1), px=img.data;
// The ink map reads each pixel's alpha: from the row itself when the file has
// an alpha channel, else from the palette or the transparent colour.
const mapa=mapaCm ? novoMapa(w,h,mapaCm) : null;
const alfaLinha=mapa && ![4,6].includes(tipo) ? new Uint8Array(w).fill(255) : null;
const alfaDaLinha=()=>{
if(tipo===3){ for(let x=0;x{
const f=bruta[0], d=bruta.subarray(1);
if(f===0) atual.set(d);
else if(f===1){ for(let i=0;i>1);
for(let i=bpp;i>1); }
else { for(let i=0;ia?p-a:a-p, pb=p>up?p-up:up-p, pc=p>c?p-c:c-p;
atual[i]=d[i]+(pa<=pb&&pa<=pc?a:pb<=pc?up:c); } }
};
const leitorInflado=inflador.readable.getReader();
for(;;){
const {done,value}=await leitorInflado.read(); if(done) break;
let j=0;
while(j{});
leitor.cancel().catch(()=>{});
if(y{ file.slice(de,ate).arrayBuffer().then(buf=>t.onDataRange(de,new Uint8Array(buf))); };
return {range:t, rangeChunkSize:262144, disableAutoFetch:true, disableStream:true};
}
function medirFolha(file){
return new Promise(res=>{
const nome=(file.name||'').toLowerCase();
if(/\.png$/.test(nome)){
dimensoesImagem(file).then(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.'});
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});
carregarImagem(file).then(img=>res(img&&img.width?{...measure,fonte:'proporção da imagem'}:null));
}).catch(()=>res({rejected:true,reason:'Não foi possível ler o PNG. Exporte novamente.'}));
return;
}
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});
}).catch(()=>res(null));
return;
}
if(RENDERIZA.test(nome)){
carregarImagem(file).then(img=>{
if(!img || !img.width) return res(null);
const L=larguraFilme();
// 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});
});
return;
}
if(/\.pdf$/.test(nome)){
// PDF boxes can be inherited, compressed, rotated, and scaled by UserUnit.
// Searching raw bytes for /MediaBox can read the wrong object or miss it.
let doc=null;
carregarPdfJs().then(async lib=>{
if(!lib) throw new Error('Não foi possível carregar o leitor de PDF.');
doc=await lib.getDocument({...await fontePdf(lib,file),
disableFontFace:true, isEvalSupported:false, useSystemFonts:false,
verbosity:0}).promise;
if(doc.numPages!==1)
return {rejected:true, reason:'O PDF tem '+doc.numPages+
' páginas. Envie cada folha como um PDF de uma página para calcular o preço correto.'};
const page=await doc.getPage(1);
const view=page.view, unit=page.userUnit, vp=page.getViewport({scale:1});
if(!Array.isArray(view) || view.length!==4 ||
!Number.isFinite(unit) || unit<=0 ||
!Number.isFinite(vp.width) || !Number.isFinite(vp.height) ||
vp.width<=0 || vp.height<=0)
return {rejected:true, reason:'Não conseguimos determinar o tamanho desta página PDF. Exporte-a novamente.'};
const ptW=Math.abs(view[2]-view[0]), ptH=Math.abs(view[3]-view[1]);
if(!(ptW>0 && ptH>0) ||
(unit===1 && (ptW>PDF_MAX_PT || ptH>PDF_MAX_PT)))
return {rejected:true, reason:'A página passa do limite de 508 cm sem UserUnit. Divida a folha ou exporte em PNG.'};
// This pinned PDF.js build exposes the page's rotated view in points;
// userUnit is separate and must scale both physical dimensions.
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:'O tamanho desta página PDF não é suportado. Divida a folha em partes menores.'};
// Keep precise geometry for the fit and quote; the UI rounds only
// when displaying dimensions.
return {larg:+w.toFixed(3), alt:+h.toFixed(3),
fonte:'página do PDF'+(unit!==1 ? ' · UserUnit '+unit : '')};
}).then(res).catch(()=>res({rejected:true,
reason:'Não conseguimos ler este PDF. Exporte-o novamente como PDF de uma página ou PNG.'}))
.finally(()=>{ if(doc) doc.destroy().catch(()=>{}); });
return;
}
res(null);
});
}
function textoProgresso(x){
const tempo=x.analiseInicio?' · '+segundosDesde(x.analiseInicio)+' s':'';
if(x.med && x.med.grande) return 'o Prumo está gerando a prévia e conferindo a arte · '+faltaLeitura(x.leitura)+tempo;
return (x.pct<50?'lendo o arquivo…':x.pct<70?'medindo a folha…':'o Prumo está conferindo a arte…')+tempo;
}
// The file card's thumbnail (52 x 96 px, drawn at twice that for sharp screens).
// At 480 x 720 it is the picture the Kanban shows of the order (checkout.js).
function miniatura(fonte, maxW=104, maxH=192){
const w=fonte.naturalWidth||fonte.width, h=fonte.naturalHeight||fonte.height;
if(!(w>0 && h>0)) return null;
const s=Math.min(1,maxW/w,maxH/h), cv=document.createElement('canvas');
cv.width=Math.max(1,Math.round(w*s)); cv.height=Math.max(1,Math.round(h*s));
cv.getContext('2d').drawImage(fonte,0,0,cv.width,cv.height);
return cv.toDataURL('image/webp',0.8);
}
// The preview with a red circle around each residue dot and its size, so the
// customer finds what to erase: on the screen they are invisible.
async function previaMarcada(src, pontos){
const img=await new Promise(res=>{ const im=new Image(); im.onload=()=>res(im); im.onerror=()=>res(null); im.src=src; });
if(!img) return src;
const s=Math.min(1,1200/img.naturalWidth), cv=document.createElement('canvas');
cv.width=Math.max(1,Math.round(img.naturalWidth*s)); cv.height=Math.max(1,Math.round(img.naturalHeight*s));
const ctx=cv.getContext('2d');
ctx.drawImage(img,0,0,cv.width,cv.height);
const r=Math.max(9,cv.width*0.014);
ctx.lineWidth=Math.max(2,r/4); ctx.strokeStyle='#E0301E'; ctx.font='700 '+Math.round(r*1.1)+'px Inter, sans-serif';
for(const p of pontos){
const x=p.x*cv.width, y=p.y*cv.height;
ctx.beginPath(); ctx.arc(x,y,r,0,2*Math.PI); ctx.stroke();
const t=n1(p.mm)+' mm', tw=ctx.measureText(t).width, tx=Math.min(x+r+4,cv.width-tw-4);
ctx.fillStyle='rgba(255,255,255,.9)'; ctx.fillRect(tx-3,y-r*0.7,tw+6,r*1.4);
ctx.fillStyle='#E0301E'; ctx.fillText(t,tx,y+r*0.4);
}
return cv.toDataURL('image/webp',0.9);
}
// Moves one sheet's progress bar in place: repainting the whole list and the
// preview on every step made "Sua folha" flicker while a large file was read.
function pintaProgressoFolha(x){
const el=$('lista').querySelector('.rep[data-folha="'+folhas.indexOf(x)+'"]');
const barra=el && el.querySelector('.prog i'), texto=el && el.querySelector('.progT');
if(!barra){ pintaFolha(); return; }
barra.style.width=x.pct+'%'; if(texto) texto.textContent=textoProgresso(x);
}
// What the check found, as chips: ok (verde), av (atenção), er (resolva você),
// fix (arrumamos de graça), nt (a equipe confere). Details stay one click away.
function chipsDaFolha(a,aceito){
const chip=(k,t)=>'
'+t+'
';
const dpi = a.vetor ? chip('ok','Arte vetorial')
: chip(a.dpi>=DPI_AVISA?'ok':a.dpi>=DPI_RECUSA?'av':'er', a.dpi+' DPI');
if(a.grande) return dpi+chip('nt','Peças, resíduos e fundo: a equipe confere');
// Sem transparência a folha inteira é uma peça só: não há resíduo a contar.
if(a.fundoChapado) return dpi+chip('er','Fundo chapado');
return dpi+chip('ok','Fundo transparente')+
(a.residuos? chip(aceito?'av':'er',a.residuos+' resíduo'+(a.residuos>1?'s':'')+(aceito?' aceito'+(a.residuos>1?'s':''):''))
: chip('ok','Sem resíduos'))+
(a.encostadas? chip('fix',a.encostadas+' peças coladas · separamos grátis') : chip('ok','Peças separadas'));
}
// Resíduo e fundo chapado barram o pedido (Dropstar, 21/10/2026): o texto diz
// quantos pontos, onde estão e o que fazer, sem "arquivo com problema". O
// resíduo o cliente pode aceitar imprimir em ambos os caminhos.
function avisosDaFolha(a,nome,i,aceito,aceitavel=false){
if(a.grande) return '';
if(a.fundoChapado) return /\.jpe?g$/i.test(nome||'')
? '
JPG não tem fundo transparente. O que parece branco na tela sai branco '+
'no filme. Exporte a folha em PNG ou PDF, com fundo transparente, e envie de novo.
'
: '
O fundo da sua folha não é transparente. O que parece branco na tela sai '+
'branco no filme. Exporte a folha com fundo transparente, em PNG ou PDF, e envie de novo.
'+(varios?'Sobraram ':'Sobrou ')+n+(varios?' pontos':' ponto')+
' de recorte na sua folha. São restos da remoção de fundo: não aparecem na sua tela, mas a '+
'impressora enxerga e imprime. Apague '+(varios?'os pontos':'o ponto')+' na ferramenta que você '+
'usou e envie de novo. '+(varios?'Os círculos vermelhos na prévia mostram onde estão.':'O círculo vermelho na prévia mostra onde está.')+
(aceitavel?' Se '+(varios?'os pontos são':'o ponto é')+' da própria arte, marque abaixo.
'+aceite:'
');
}
// Ajuste Fino (front 1a) and Ajuste Fino Redesenho (front 1b): under a Prumo
// warning, the customer may hand this art to the designer. One service per
// art, chosen radio-like; the cart has the general switch for the basic one.
function temAvisoFolha(x){
const a=x.an;
if(!a || a.grande) return false;
return !!(a.fundoChapado || a.residuos || a.dpi0, redesenhado=TAXA_REDESENHO>0;
if(!basico && !redesenhado) return '';
let linha='';
if(basico){
const marcado=ajusteTudo || !!x.ajuste;
linha+='';
}
if(redesenhado){
const attrRedesenhado=folha?'data-redesenho':'data-redesenhoa';
linha+='';
}
return linha;
}
function detalhesDaFolha(a,i,aberto){
const linhas = a.grande
? ['Resolução '+a.dpi+' DPI, lida do arquivo',
'Arquivo grande: peças, resíduos e fundo são conferidos pela equipe']
: [a.artes+' peça'+(a.artes===1?'':'s')+' · '+a.aproveitamento+'% da folha com arte',
'Resolução '+a.dpi+' DPI · '+(a.fonteDpi==='imagens'? 'medida imagem por imagem dentro do PDF'
: a.fonteDpi==='vetor'? 'arte vetorial, sem imagem embutida' : 'lida do arquivo'),
'Conferido pelo Prumo numa grade de '+n1(a.grade)+' mm'];
return ''+
'Ver o que o Prumo conferiu'+
linhas.map(l=>''+l+'').join('')+'';
}
// What the empty strips cut from a sheet were (aplicaCorte, Marcus 18/11/2026):
// with one sheet the line says what is charged; with several the total is
// rounded once, so it says what this sheet counts.
function textoCorte(x, sozinha){
const {topo, fim}=x.corte;
const onde=topo&&fim ? 'do começo e do fim' : topo ? 'do começo' : 'do fim';
return 'Removemos '+Math.round(topo+fim)+' cm vazios '+onde+' do arquivo. '+
(sozinha ? 'Cobrado: '+fmtM(cobrar(x.m))+' m.' : 'Esta folha fica com '+fmtM(x.m)+' m.');
}
function pintaFolha(){
if(!MODOS[modo]) return; // read after the customer left the product page
invalidaItemAtual();
const L=larguraFilme();
pintaTipoEnvio(); // trava o seletor enquanto houver folha
$('zona').classList.toggle('compacta', folhas.length>0);
if(!folhas.length){ $('lista').innerHTML=''; agendaAvaliacao(); previaAoVivo(); agendaEnvios(); return; }
const tot=folhaTotalM();
$('lista').innerHTML = '
'+avisosDaFolha(a,x.f.name,i,residuoAceito(x),true)+
(temAvisoFolha(x)?ajusteLinha(i,'data-ajuste'):'')+
detalhesDaFolha(a,i,x.detAberto) : '')+
// Over 150 MB the browser cannot check a PDF: said before payment, as
// for a file opened by hand (Dropstar, 2026-10-23).
(x.pdfGrande? 'Conferência manual · sem conferência no site'+
'
Este PDF tem mais de 150 MB, e o site não confere arquivo desse tamanho: '+
'resíduo de recorte, fundo e resolução ficam para a equipe, que abre antes de imprimir, e o '+
'pedido pode voltar depois de pago. '+
'Exportando em PNG, ou num PDF menor, a conferência sai aqui, antes de pagar.
' : '')+
(suspeito? '
Este PDF passa do tamanho que o formato comporta. '+
'A especificação para em 508 cm e o seu tem '+n1(x.med.alt)+' cm. '+
'Ele abre certo só em quem o gerou — aqui vai precisar do Ajuste Fino. '+
'Manda em PNG ou TIFF, ou divide em partes de até 5 m, que sai na hora.
':'')+
(larga? '
Esta folha não roda neste filme. Ela tem '+n1(x.med.larg)+
' cm de largura e o filme aqui tem '+n1(L)+' cm. Não dá para reduzir: '+
'encolher a folha encolheria cada arte junto.'+
(x.med.larg<=57.5
? ' Ela cabe no DTF têxtil de 57 cm — troque de produto ali em cima.'
: ' Remonte a folha em '+n1(L)+' cm e suba de novo.')+'
Este arquivo não pode ser orçado. '+escapeHTML(x.measurementError)+'
';
}else{
// Só a abertura manual muda o metro (TAXA_MANUAL); a nota não mexe no preço.
const dif=(x.m>0)? TAXA_MANUAL*cobrar(x.m*(x.rep||1)) : 0;
medida='Conferência manual'+
'
O navegador não abre '+escapeHTML(extDe(x.f.name))+', então alguém da equipe '+
'confere antes de imprimir'+
(TAXA_MANUAL? ' e o metro sai a '+rs(precoMetro()+TAXA_MANUAL)+', com '+rs(TAXA_MANUAL)+
' pela abertura manual' : '')+'. '+
'Exportando em PNG ou PDF, a conferência sai aqui, antes de pagar'+
(TAXA_MANUAL? ', e o metro fica em '+rs(precoMetro())+''+
(dif>0.5? ' — '+rs(dif)+' a menos só nesta folha' : '') : '')+'.
';
manual='
'+
'm
';
}
const barra = x.pct!=null
? '
'+
''+textoProgresso(x)+''
: x.semAnalise
? '
Não conseguimos conferir esta folha. '+escapeHTML(x.semAnalise)+
'. A conferência será feita na sala. Para conferir a resolução aqui, exporte a mesma '+
'folha em PNG.
'
: '';
// A small thumbnail made once: the list is rebuilt on every change, and the
// full preview of a file up to 150 MB would be re-parsed each time.
const mini = x.miniSrc
? ''
: ''+escapeHTML(extDe(x.f.name))+'';
const copias = x.m>0 || manual ?
'
'+manual+
(x.m>0 ?
'
'+
''+
''+
'
'+
'
'+(x.rep>1? x.rep+' × '+fmtM(x.m)+' m = ' : '')+''+fmtM(sub)+' m
';
}).join('');
$('lista').querySelectorAll('[data-rmf]').forEach(b=>b.addEventListener('click',()=>{
folhas.splice(+b.dataset.rmf,1); pintaFolha();
}));
$('lista').querySelectorAll('[data-residuo]').forEach(el=>el.addEventListener('change',()=>{
folhas[+el.dataset.residuo].residuoAceito=el.checked; pintaFolha();
}));
$('lista').querySelectorAll('[data-ajuste]').forEach(el=>el.addEventListener('change',()=>{
if(ajusteTudo) materializaAjuste();
const x=folhas[+el.dataset.ajuste];
x.ajuste=el.checked;
if(el.checked) x.redesenho=false;
pintaFolha(); pintaPedido();
}));
$('lista').querySelectorAll('[data-redesenho]').forEach(el=>el.addEventListener('change',()=>{
if(ajusteTudo) materializaAjuste();
const x=folhas[+el.dataset.redesenho];
x.redesenho=el.checked;
if(el.checked) x.ajuste=false;
pintaFolha(); pintaPedido();
}));
$('lista').querySelectorAll('[data-det]').forEach(d=>d.addEventListener('toggle',()=>{
folhas[+d.dataset.det].detAberto=d.open;
}));
$('lista').querySelectorAll('[data-passo]').forEach(b=>b.addEventListener('click',()=>{
const el=$('repf'+b.dataset.i);
el.value=Math.max(1,Math.min(200,(+el.value||1)+(+b.dataset.passo)));
el.dispatchEvent(new Event('change'));
}));
$('lista').querySelectorAll('[data-repf]').forEach(el=>el.addEventListener('change',e=>{
folhas[+el.dataset.repf].rep=Math.max(1,Math.min(200,+e.target.value||1)); pintaFolha();
}));
$('lista').querySelectorAll('[data-comp]').forEach(el=>el.addEventListener('change',e=>{
folhas[+el.dataset.comp].m=Math.max(0,Math.min(60,+e.target.value||0)); pintaFolha();
}));
$('lista').querySelectorAll('[data-repf], [data-comp]').forEach(el=>
el.addEventListener('input',invalidaItemAtual));
agendaAvaliacao(); previaAoVivo(); agendaEnvios();
}
// sugestão de largura
const cabemNaLinha=w=>Math.max(1,Math.floor((larguraFilme()+GAP_CM)/(w+GAP_CM)));
const larguraPara=n=>(larguraFilme()-(n-1)*GAP_CM)/n;
// Só sugere se a folha realmente encolher. Caber mais um por fileira não adianta
// nada se a quantidade pedida continuar ocupando o mesmo número de fileiras.
function sugestao(a){
const w=a.cm, q=Math.max(1,a.q||1), prop=propDe(a);
const n=cabemNaLinha(w), alvo=Math.floor(larguraPara(n+1)*10)/10;
if(!(alvo>0) || alvo>=w) return null;
if((w-alvo)/w>0.12) return null; // não corta mais que 12% da peça
const fa=Math.ceil(q/n), fd=Math.ceil(q/(n+1));
if(fd>=fa) return null; // mesmo número de fileiras: não muda nada
const economiaCm=fa*w*prop - fd*alvo*prop;
if(economiaCm<0.5) return null; // menos de meio centímetro não é notícia
return {alvo, de:n, para:n+1, fileiras:fa-fd, cm:economiaCm};
}
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('[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 · '+faltaLeitura(a.leitura);
}
// O transfer têxtil é prensado com o filme virado para baixo: espelhado, sai
// invertido na peça. Só o UV espelha, até a Dropstar decidir (21/10/2026).
const espelhavel=()=>modo==='uv';
function pintaArtes(){
// A file still being read when the customer left the product page lands
// here with no product open: nothing to paint.
if(!MODOS[modo]) return;
if(!espelhavel()) artes.forEach(a=>{ a.esp=false; });
invalidaItemAtual();
$('zona').classList.toggle('compacta', artes.length>0);
// The same card as a finished sheet: thumbnail, size, a DPI chip, then the
// width (with the usual sizes), copies, rotation and mirroring.
const copiasTot=artes.reduce((t,a)=>t+(a.q||1),0);
$('lista').innerHTML=(artes.length? '
';
const sug=sugestao(a);
// One hint per artwork: resolution first, since it changes the price;
// otherwise a width that saves sheet.
const maxCm=Math.floor(a.px/DPI_AVISA*2.54*10)/10;
dica = dpi0 && maxCmPequena para '+n1(a.cm)+' cm. Em '+DPI_AVISA+' DPI ela sai com até '+
n1(maxCm)+' cm, ou envie um arquivo maior.'
: sug
? '
Com '+n1(sug.alvo)+' cm cabem '+sug.para+' por fileira e a folha encolhe '+
n1(sug.cm)+' cm.
'
: '';
}
// Item 4: the art's dots under 2 mm, with the same warning and acceptance as a sheet.
const an=analiseDaArte(a);
if(an && an.residuos) aviso+=avisosDaFolha({residuos:an.residuos},a.f.name,i,!!a.residuoAceito,true).replace('data-residuo=','data-residuoa=')
.replace('na sua folha','nesta arte');
if(a.semPrevia && !a.decodeError)
aviso+='
Sem prévia para '+escapeHTML(extDe(a.f.name))+' deste tamanho. '+
'A arte entra na folha pela medida, e a equipe confere antes de imprimir. Em PNG, a prévia aparece.