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 3m52s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m14s
- "The designer approves every file" (Dropstar's rule D-16): the Operador leaves "produce", so it no longer approves final files, picks the contraction, treats the art or marks the contact wait. It pulls and prints. The order panel says the Designer approves and shows the contraction read-only; the profiles table follows. - The stroke measure drops ink components under 30 px (at 300 DPI) before the distance, as Dropstar's method says (2026-10-30). Each strip keeps at least 30 rows of context, so a speck is always seen whole and a component cut by the strip is a stroke. One real order sheet went from C1 (2 px, specks) to C2 (5 px); Dropstar's four test sheets still give 2, 5, 20 and 4 px. The artwork browser test checks widths 2, 5 and 6, and a C3 sheet with 300 specks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
283 lines
13 KiB
JavaScript
283 lines
13 KiB
JavaScript
/* Site DTF — Reading a finished sheet from its alpha channel: pieces, gaps, waste.
|
|
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. */
|
|
// ── Análise real da folha: lê o canal alfa, separa cada ilha de arte e mede.
|
|
// A grade de 1 mm agrupa a tinta; a medida de cada ilha sai dos pixels.
|
|
const MM=0.1; // grade fina: 1 mm
|
|
const CELULAS_MAX=1200000; // teto de custo da análise
|
|
// Folha grande vira grade mais grossa. Sem isso, 57 x 480 cm dá 2,7 milhões de
|
|
// células e o navegador congela antes de terminar.
|
|
function passoDe(larguraCm, alturaCm){
|
|
const fino=(larguraCm/MM)*(alturaCm/MM);
|
|
return fino<=CELULAS_MAX ? MM : MM*Math.sqrt(fino/CELULAS_MAX);
|
|
}
|
|
|
|
// Dilata a máscara em r células · usada para agrupar por distância real, não por caixa
|
|
function inchar(bits,cw,ch,r){
|
|
const a=new Uint8Array(cw*ch), b=new Uint8Array(cw*ch);
|
|
for(let y=0;y<ch;y++){ const o=y*cw;
|
|
for(let x=0;x<cw;x++){ if(!bits[o+x]) continue;
|
|
const x0=Math.max(0,x-r), x1=Math.min(cw-1,x+r);
|
|
for(let k=x0;k<=x1;k++) a[o+k]=1; } }
|
|
for(let x=0;x<cw;x++)
|
|
for(let y=0;y<ch;y++){ if(!a[y*cw+x]) continue;
|
|
const y0=Math.max(0,y-r), y1=Math.min(ch-1,y+r);
|
|
for(let k=y0;k<=y1;k++) b[k*cw+x]=1; }
|
|
return b;
|
|
}
|
|
// Componentes conexos de 8 vizinhos · devolve o mapa de rótulos e quantos grupos
|
|
function grupos(bits,cw,ch){
|
|
const marca=new Int32Array(cw*ch).fill(-1), fila=new Int32Array(cw*ch);
|
|
let n=0;
|
|
for(let p0=0;p0<bits.length;p0++){
|
|
if(!bits[p0]||marca[p0]>=0) continue;
|
|
const id=n++; let ini=0,fim=0; fila[fim++]=p0; marca[p0]=id;
|
|
while(ini<fim){
|
|
const p=fila[ini++], x=p%cw, y=(p/cw)|0;
|
|
for(let dy=-1;dy<=1;dy++) for(let dx=-1;dx<=1;dx++){
|
|
const nx=x+dx, ny=y+dy;
|
|
if(nx<0||ny<0||nx>=cw||ny>=ch) continue;
|
|
const q=ny*cw+nx;
|
|
if(bits[q]&&marca[q]<0){ marca[q]=id; fila[fim++]=q; }
|
|
}
|
|
}
|
|
}
|
|
return {marca,n};
|
|
}
|
|
|
|
// ── Mapa de tinta: cada pixel da folha lido, nenhum pulado.
|
|
// Regra da Dropstar (21/10/2026): resíduo é uma ilha de tinta menor que 2 mm
|
|
// nos dois lados, e um ponto só já barra o pedido. Reduzir a imagem antes de
|
|
// olhar perde ponto pequeno, e medir pela grade erra até uma célula: o mesmo
|
|
// ponto de 1,5 mm saía resíduo ou arte conforme caía na grade. Aqui a grade só
|
|
// agrupa; cada célula guarda onde a tinta começa e termina, em pixels, e cada
|
|
// ilha é medida por esses extremos, em milímetros reais.
|
|
const ALFA_TINTA=10; // acima disto o pixel leva tinta (e branco de base)
|
|
function novoMapa(wPx,hPx,larguraCm){
|
|
const pxPorCm=wPx/larguraCm, passo=passoDe(larguraCm,hPx/pxPorCm), pxCel=passo*pxPorCm;
|
|
const cw=Math.max(1,Math.ceil(wPx/pxCel)), ch=Math.max(1,Math.ceil(hPx/pxCel)), n=cw*ch;
|
|
const colDe=new Uint32Array(wPx);
|
|
for(let x=0;x<wPx;x++) colDe[x]=Math.min(cw-1,Math.floor(x/pxCel));
|
|
return {wPx,hPx,larguraCm,pxPorCm,passo,pxCel,cw,ch,colDe,bits:new Uint8Array(n),
|
|
x0:new Uint32Array(n),x1:new Uint32Array(n),y0:new Uint32Array(n),y1:new Uint32Array(n),tinta:0,
|
|
traco:novoTraco(wPx,wPx/(larguraCm/2.54))};
|
|
}
|
|
// ── Traço mais fino (Dropstar, 30/10/2026): a contração do Flexi vem dele.
|
|
// Tinta é alfa acima de 40; a distância de cada pixel de tinta ao fundo sai de
|
|
// um chanfro 10/14, e no eixo do traço a largura é o dobro da distância (menos
|
|
// um quando a largura é ímpar). O mais fino da folha é o 1º percentil dessas
|
|
// larguras, em pixels a 300 DPI: até 4 é C1, de 5 a 19 é C2, 20 ou mais é C3.
|
|
// A folha passa em faixas, linha a linha: cada faixa guarda 20 linhas antes e
|
|
// depois, o alcance da distância, e nada maior que uma faixa fica na memória.
|
|
const ALFA_TRACO=40, TRACO_D=20, TRACO_FAIXA=256, TRACO_CISCO=30;
|
|
// O contexto de cada faixa: as linhas acima e abaixo que ela lê sem medir. Um
|
|
// cisco (menos de 30 px de tinta a 300 DPI) tem menos linhas que isso, então
|
|
// a faixa sempre o vê inteiro; o que encosta na borda cortada é traço.
|
|
function novoTraco(wPx,dpi){
|
|
const cisco=Math.ceil(TRACO_CISCO*(dpi/300)**2), ctx=Math.min(120,Math.max(TRACO_D,cisco));
|
|
const linhas=TRACO_FAIXA+2*ctx;
|
|
return {w:wPx,dpi,linhas,ctx,cisco,tinta:new Uint8Array(wPx*linhas),dist:new Uint16Array(wPx*linhas),
|
|
rot:new Int32Array(wPx*linhas),pai:new Int32Array((wPx*linhas>>1)+2),area:new Int32Array((wPx*linhas>>1)+2),
|
|
n:0,inicio:0,hist:new Float64Array(2*TRACO_D+2),total:0,tintaPx:0,largosPx:0};
|
|
}
|
|
// Como a sala mede (Dropstar, 30/10/2026): componentes de tinta com menos de
|
|
// 30 px não são traço e saem antes da distância. Vizinhos nas oito direções.
|
|
function tiraCiscos(t,topo,fim){
|
|
const {w,n,tinta,rot,pai,area,cisco}=t;
|
|
let prox=1;
|
|
const raiz=a=>{while(pai[a]!==a){pai[a]=pai[pai[a]];a=pai[a];}return a;};
|
|
const une=(a,b)=>{a=raiz(a);b=raiz(b);if(a===b)return a;if(a<b){pai[b]=a;return a;}pai[a]=b;return b;};
|
|
// O pixel de cima já encosta nos outros três vizinhos lidos; sem ele, o da
|
|
// esquerda encosta no de cima à esquerda. Só sobra unir o de cima à direita.
|
|
for(let y=0;y<n;y++){ const o=y*w;
|
|
for(let x=0;x<w;x++){ const p=o+x;
|
|
if(!tinta[p]){ rot[p]=0; continue; }
|
|
const a=p-w, cima=y>0&&tinta[a], dir=y>0&&x<w-1&&tinta[a+1];
|
|
let r=0;
|
|
if(cima) r=rot[a];
|
|
else{
|
|
if(x>0&&tinta[p-1]) r=rot[p-1];
|
|
else if(y>0&&x>0&&tinta[a-1]) r=rot[a-1];
|
|
if(dir) r=r?une(r,rot[a+1]):rot[a+1];
|
|
}
|
|
if(!r){ r=prox++; pai[r]=r; area[r]=0; }
|
|
rot[p]=r; } }
|
|
if(prox===1) return;
|
|
// Cada rótulo aponta para um menor: em ordem, um passo só leva à raiz.
|
|
for(let r=1;r<prox;r++) pai[r]=pai[pai[r]];
|
|
for(let p=0;p<w*n;p++) if(rot[p]) area[pai[rot[p]]]++;
|
|
// Encostar numa borda que não é a da folha: o componente continua fora da faixa.
|
|
if(!topo) for(let x=0;x<w;x++) if(rot[x]) area[pai[rot[x]]]=cisco;
|
|
if(!fim) for(let x=0,o=(n-1)*w;x<w;x++) if(rot[o+x]) area[pai[rot[o+x]]]=cisco;
|
|
let ciscos=0;
|
|
for(let r=1;r<prox;r++) if(pai[r]===r&&area[r]<cisco) ciscos++;
|
|
if(!ciscos) return;
|
|
for(let p=0;p<w*n;p++) if(rot[p]&&area[pai[rot[p]]]<cisco) tinta[p]=0;
|
|
}
|
|
function tracoLinha(t,alfa,inicio,de){
|
|
const o=t.n*t.w, ink=t.tinta;
|
|
for(let x=0,i=inicio;x<t.w;x++,i+=de) ink[o+x]=alfa[i]>ALFA_TRACO?1:0;
|
|
t.n++;
|
|
if(t.n===t.linhas) tracoFaixa(t,false);
|
|
}
|
|
// A distância na faixa, e as larguras das linhas que ela já mede inteiras.
|
|
function tracoFaixa(t,fim){
|
|
const {w,n,tinta,dist,ctx}=t, CAP=TRACO_D*10+10, topo=t.inicio===0;
|
|
if(!n) return;
|
|
tiraCiscos(t,topo,fim);
|
|
for(let p=0;p<w*n;p++) dist[p]=tinta[p]?CAP:0;
|
|
// ida: de cima para baixo; fora da folha é fundo
|
|
for(let y=0;y<n;y++){ const o=y*w, a=o-w;
|
|
for(let x=0;x<w;x++){ const p=o+x; if(!dist[p]) continue;
|
|
let d=dist[p];
|
|
const l=x>0?dist[p-1]:0; if(l+10<d) d=l+10;
|
|
if(y>0){ const u=dist[a+x]; if(u+10<d) d=u+10;
|
|
const ul=x>0?dist[a+x-1]:0; if(ul+14<d) d=ul+14;
|
|
const ur=x<w-1?dist[a+x+1]:0; if(ur+14<d) d=ur+14; }
|
|
else if(topo) d=10;
|
|
dist[p]=d; } }
|
|
// volta: de baixo para cima
|
|
for(let y=n-1;y>=0;y--){ const o=y*w, b=o+w;
|
|
for(let x=w-1;x>=0;x--){ const p=o+x; if(!dist[p]) continue;
|
|
let d=dist[p];
|
|
const r=x<w-1?dist[p+1]:0; if(r+10<d) d=r+10;
|
|
if(y<n-1){ const dn=dist[b+x]; if(dn+10<d) d=dn+10;
|
|
const dl=x>0?dist[b+x-1]:0; if(dl+14<d) d=dl+14;
|
|
const dr=x<w-1?dist[b+x+1]:0; if(dr+14<d) d=dr+14; }
|
|
else if(fim) d=Math.min(d,10);
|
|
dist[p]=d; } }
|
|
// As linhas medidas por inteiro: longe das bordas da faixa, salvo as da folha.
|
|
const de=topo?0:ctx, ate=fim?n:n-ctx;
|
|
const escala=300/t.dpi, hist=t.hist, max=hist.length-1;
|
|
const at=(x,y)=>(x<0||x>=w||y<0||y>=n)?0:dist[y*w+x];
|
|
// Item 16: tinta em áreas de 20 px ou mais (a 300 DPI) é a que fica a 10 px
|
|
// ou mais do fundo; a conta é da tinta das linhas medidas.
|
|
const largo=100/escala;
|
|
for(let y=de;y<ate;y++){ const o=y*w; for(let x=0;x<w;x++){ const d=dist[o+x]; if(!d) continue; t.tintaPx++; if(d>=largo) t.largosPx++; } }
|
|
for(let y=de;y<ate;y++) for(let x=0;x<w;x++){
|
|
const d=dist[y*w+x]; if(!d||d>=CAP) continue;
|
|
// No eixo do traço a distância não é menor que a de nenhum vizinho; perto
|
|
// de um canto sempre há um vizinho mais fundo, e o canto não conta.
|
|
let iguais=0, eixo=true;
|
|
for(let dy=-1;dy<=1&&eixo;dy++) for(let dx=-1;dx<=1;dx++){
|
|
if(!dx&&!dy) continue;
|
|
const v=at(x+dx,y+dy);
|
|
if(v>d){ eixo=false; break; }
|
|
if(v===d) iguais++;
|
|
}
|
|
if(!eixo) continue;
|
|
// Largura par: o eixo tem dois pixels, e os iguais passam de dois.
|
|
const larg=iguais>=4?2*d/10:2*d/10-1;
|
|
const i=Math.max(1,Math.min(max,Math.round(larg*escala)));
|
|
hist[i]++;t.total++;
|
|
}
|
|
// As últimas linhas ficam como contexto da próxima faixa.
|
|
if(!fim){
|
|
const fica=2*ctx;
|
|
tinta.copyWithin(0,(n-fica)*w,n*w);
|
|
t.inicio+=n-fica; t.n=fica;
|
|
}
|
|
}
|
|
// O 1º percentil das larguras, em pixels a 300 DPI, e a classe de contração.
|
|
// Uma vez só: depois a faixa não existe mais, e a resposta fica guardada,
|
|
// também quando é null (uma folha sem tinta).
|
|
function tracoFim(t){
|
|
if(t.lido!==undefined) return t.lido;
|
|
tracoFaixa(t,true);
|
|
t.tinta=t.dist=t.rot=t.pai=t.area=null; // a faixa não serve mais
|
|
if(!t.total) return t.lido=null;
|
|
let soma=0, px=1;
|
|
for(let i=1;i<t.hist.length;i++){ soma+=t.hist[i]; if(soma>=t.total*0.01){ px=i; break; } }
|
|
// largos: a parte da tinta em áreas chapadas, de 20 px ou mais (item 16)
|
|
return t.lido={px, classe:px<=4?'C1':px<=19?'C2':'C3', largos:t.tintaPx?t.largosPx/t.tintaPx:0};
|
|
}
|
|
// A linha y da folha: o alfa de cada pixel em alfa[inicio + x*de].
|
|
function mapaLinha(m,y,alfa,inicio,de){
|
|
if(m.traco) tracoLinha(m.traco,alfa,inicio,de);
|
|
const base=Math.min(m.ch-1,Math.floor(y/m.pxCel))*m.cw;
|
|
const {bits,x0,x1,y0,y1,colDe}=m;
|
|
let tinta=0;
|
|
for(let x=0,i=inicio;x<m.wPx;x++,i+=de){
|
|
if(alfa[i]<=ALFA_TINTA) continue;
|
|
tinta++;
|
|
const c=base+colDe[x];
|
|
if(!bits[c]){ bits[c]=1; x0[c]=x1[c]=x; y0[c]=y1[c]=y; }
|
|
else{ if(x<x0[c]) x0[c]=x; else if(x>x1[c]) x1[c]=x; y1[c]=y; }
|
|
}
|
|
m.tinta+=tinta;
|
|
}
|
|
// Uma imagem que o navegador abre, lida em faixas no tamanho real (1:1).
|
|
// Melhor um ImageBitmap: decodificado uma vez, não a cada faixa.
|
|
async function mapaDaImagem(img,larguraCm,progresso){
|
|
const w=img.naturalWidth||img.width, h=img.naturalHeight||img.height;
|
|
const m=novoMapa(w,h,larguraCm);
|
|
const faixa=Math.max(1,Math.min(h,Math.floor(4e6/w)));
|
|
const cv=document.createElement('canvas'); cv.width=w; cv.height=faixa;
|
|
const ctx=cv.getContext('2d',{willReadFrequently:true});
|
|
ctx.imageSmoothingEnabled=false;
|
|
for(let topo=0;topo<h;topo+=faixa){
|
|
const n=Math.min(faixa,h-topo);
|
|
ctx.clearRect(0,0,w,faixa);
|
|
ctx.drawImage(img,0,topo,w,n,0,0,w,n);
|
|
const d=ctx.getImageData(0,0,w,n).data;
|
|
for(let r=0;r<n;r++) mapaLinha(m,topo+r,d,r*w*4+3,4);
|
|
if(progresso) progresso((topo+n)/h);
|
|
await new Promise(r=>setTimeout(r)); // a página não congela
|
|
}
|
|
return m;
|
|
}
|
|
|
|
// ── O que a folha permite medir, e só isso.
|
|
// Peça = tinta a menos de 2 mm entre si · letras de uma palavra ficam juntas.
|
|
// Encostadas = peças que só se unem quando a folga chega a 6 mm.
|
|
const R_PECA=1, R_PERTO=2; // peça: 2 mm · aviso de encostadas: 4 mm
|
|
const RESIDUO_MM=2;
|
|
function analisarMapa(m){
|
|
const {cw,ch,bits}=m;
|
|
const gp=grupos(inchar(bits,cw,ch,R_PECA), cw, ch);
|
|
const caixas=[];
|
|
for(let p=0;p<bits.length;p++){
|
|
if(!bits[p]) continue;
|
|
const id=gp.marca[p]; if(id<0) continue;
|
|
const c=caixas[id] || (caixas[id]={x0:m.x0[p],x1:m.x1[p],y0:m.y0[p],y1:m.y1[p],id});
|
|
if(m.x0[p]<c.x0)c.x0=m.x0[p]; if(m.x1[p]>c.x1)c.x1=m.x1[p];
|
|
if(m.y0[p]<c.y0)c.y0=m.y0[p]; if(m.y1[p]>c.y1)c.y1=m.y1[p];
|
|
}
|
|
const mm=px=>px/m.pxPorCm*10;
|
|
const ilhas=caixas.filter(Boolean).map(c=>({...c, wMm:mm(c.x1-c.x0+1), hMm:mm(c.y1-c.y0+1)}));
|
|
const residuos=ilhas.filter(c=>c.wMm<RESIDUO_MM && c.hMm<RESIDUO_MM);
|
|
const deResiduo=new Set(residuos.map(c=>c.id));
|
|
|
|
// encostadas: peças diferentes que se unem quando a folga chega a 6 mm
|
|
const gper=grupos(inchar(bits,cw,ch,R_PERTO), cw, ch);
|
|
const porPerto=new Map();
|
|
for(let p=0;p<bits.length;p++){
|
|
if(!bits[p]) continue;
|
|
const a=gp.marca[p], b=gper.marca[p];
|
|
if(a<0||b<0||deResiduo.has(a)) continue;
|
|
if(!porPerto.has(b)) porPerto.set(b,new Set());
|
|
porPerto.get(b).add(a);
|
|
}
|
|
let encostadas=0;
|
|
porPerto.forEach(set=>{ if(set.size>1) encostadas+=set.size; });
|
|
|
|
const total=m.wPx*m.hPx;
|
|
return {
|
|
dpi: Math.round(m.wPx/(m.larguraCm/2.54)),
|
|
artes: ilhas.length-residuos.length,
|
|
residuos: residuos.length,
|
|
// Onde está cada ponto, em fração da folha: os círculos da prévia.
|
|
pontos: residuos.map(c=>({x:(c.x0+c.x1+1)/2/m.wPx, y:(c.y0+c.y1+1)/2/m.hPx,
|
|
mm:+Math.max(c.wMm,c.hMm).toFixed(1)})),
|
|
encostadas,
|
|
// Sem transparência: o que parece branco na tela sai branco no filme.
|
|
fundoChapado: (total-m.tinta)/total < 0.015,
|
|
aproveitamento: Math.max(1,Math.min(100,Math.round(m.tinta/total*100))),
|
|
alturaCm: m.hPx/m.pxPorCm,
|
|
grade: +(m.passo*10).toFixed(1), // mm por célula que agrupa
|
|
traco: m.traco ? tracoFim(m.traco) : null
|
|
};
|
|
}
|
|
|