Spaces:
Running
Running
File size: 9,072 Bytes
0ca3ac8 f2c6292 0ca3ac8 f2c6292 0ca3ac8 63c364f f2c6292 63c364f c481e2a f2c6292 0ca3ac8 63c364f 0ca3ac8 f2c6292 0ca3ac8 f2c6292 0ca3ac8 f2c6292 63c364f 0ca3ac8 f2c6292 c481e2a 0ca3ac8 63c364f 0ca3ac8 f2c6292 c481e2a 63c364f 0ca3ac8 63c364f 0ca3ac8 63c364f 0ca3ac8 63c364f 0ca3ac8 63c364f 0ca3ac8 63c364f f2c6292 c481e2a 63c364f 0ca3ac8 f2c6292 0ca3ac8 f2c6292 0ca3ac8 f2c6292 0ca3ac8 f2c6292 0ca3ac8 f2c6292 0ca3ac8 f2c6292 c481e2a 0ca3ac8 f2c6292 0ca3ac8 f2c6292 63c364f 0ca3ac8 63c364f 0ca3ac8 63c364f 0ca3ac8 63c364f 0ca3ac8 f2c6292 c481e2a 0ca3ac8 f2c6292 0ca3ac8 f2c6292 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
class PDFComplianceAnalyzer {
constructor() {
this.fileInput = document.getElementById('file-upload');
this.loadingElement = document.getElementById('loading');
this.resultsContainer = document.getElementById('analysis-results');
this.reportContainer = document.getElementById('compliance-report');
this.reportContent = document.querySelector('.report-content');
this.progressContainer = document.getElementById('progress-container');
this.progressBar = document.getElementById('progress-bar');
this.toastElement = document.getElementById('toast');
this.initializeEventListeners();
this.initializeThemeToggle();
}
initializeEventListeners() {
this.fileInput.addEventListener('change', (e) => this.handleFileChange(e));
this.setupDragAndDrop();
// Keyboard navigation
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') this.closeToast();
});
}
initializeThemeToggle() {
const themeToggle = document.getElementById('theme-toggle');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
document.body.classList.toggle('dark-theme', prefersDark);
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('dark-theme');
this.showToast('Tema alterado');
});
}
setupDragAndDrop() {
const uploadArea = document.querySelector('.upload-area');
['dragenter', 'dragover'].forEach(eventName => {
uploadArea.addEventListener(eventName, (e) => {
e.preventDefault();
uploadArea.classList.add('drag-over');
});
});
['dragleave', 'drop'].forEach(eventName => {
uploadArea.addEventListener(eventName, (e) => {
e.preventDefault();
uploadArea.classList.remove('drag-over');
});
});
uploadArea.addEventListener('drop', (e) => {
const files = Array.from(e.dataTransfer.files);
if (files.length > 0) {
this.validateAndProcessFile(files[0]);
}
});
}
handleFileChange(e) {
const file = e.target.files[0];
if (file) {
this.validateAndProcessFile(file);
}
}
validateAndProcessFile(file) {
if (file.type !== 'application/pdf') {
this.showToast('Por favor, envie apenas arquivos PDF.', 'error');
return;
}
if (file.size > 10 * 1024 * 1024) {
this.showToast('O arquivo excede o limite de 10MB.', 'error');
return;
}
this.analyzePDF(file);
}
async analyzePDF(file) {
this.showLoading(true);
this.showSkeleton();
this.clearResults();
try {
await this.simulateFileUpload(file);
await this.validatePDF(file);
const report = await this.generateComplianceReport(file);
this.displayResults(report);
this.showToast('Análise concluída com sucesso!', 'success');
} catch (error) {
this.showError(error.message);
this.showToast(error.message, 'error');
} finally {
this.showLoading(false);
this.hideSkeleton();
}
}
simulateFileUpload(file) {
return new Promise((resolve) => {
this.progressContainer.classList.remove('hidden');
let progress = 0;
const interval = setInterval(() => {
progress += 10;
this.progressBar.style.width = `${progress}%`;
if (progress >= 100) {
clearInterval(interval);
setTimeout(() => {
this.progressContainer.classList.add('hidden');
resolve();
}, 200);
}
}, 100);
});
}
showSkeleton() {
const template = document.getElementById('skeleton-template');
const skeleton = template.content.cloneNode(true);
this.resultsContainer.appendChild(skeleton);
}
hideSkeleton() {
const skeleton = document.querySelector('.skeleton-loader');
if (skeleton) skeleton.remove();
}
showToast(message, type = 'info') {
this.toastElement.textContent = message;
this.toastElement.className = `toast toast-${type}`;
this.toastElement.classList.remove('hidden');
setTimeout(() => this.closeToast(), 3000);
}
closeToast() {
this.toastElement.classList.add('hidden');
}
async validatePDF(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => {
const content = new Uint8Array(e.target.result);
const header = content.slice(0, 4);
const isPDF = String.fromCharCode(...header) === '%PDF';
if (!isPDF) {
reject(new Error('O arquivo não é um PDF válido.'));
}
resolve(true);
};
reader.onerror = () => reject(new Error('Erro ao ler o arquivo.'));
reader.readAsArrayBuffer(file);
});
}
async generateComplianceReport(file) {
await new Promise(resolve => setTimeout(resolve, 1500));
return {
status: 'compliant',
confidence: 92.5,
details: {
format: 'Válido',
version: 'PDF 1.7',
pages: 1,
signature: 'Presente e válida',
metadata: 'Completo',
accessibility: 'Conforme'
},
checks: [
{ name: 'Estrutura do documento', status: 'pass', score: 100 },
{ name: 'Metadados', status: 'pass', score: 95 },
{ name: 'Assinatura digital', status: 'pass', score: 100 },
{ name: 'Acessibilidade', status: 'pass', score: 85 }
]
};
}
displayResults(report) {
this.reportContainer.classList.remove('hidden');
const statusClass = report.status === 'compliant' ? 'badge-success' : 'badge-error';
const statusText = report.status === 'compliant' ? 'Conforme' : 'Não conforme';
this.reportContent.innerHTML = `
<div class="report-header">
<span class="badge ${statusClass}">${statusText}</span>
<div class="confidence-meter">
<div class="progress">
<div class="progress-bar" style="width: ${report.confidence}%"></div>
</div>
<span>Confiança: ${report.confidence}%</span>
</div>
</div>
<div class="report-section">
<h3>Detalhes do Documento</h3>
<div class="table-container">
<table class="table">
${Object.entries(report.details).map(([key, value]) => `
<tr>
<th>${key}</th>
<td>${value}</td>
</tr>
`).join('')}
</table>
</div>
</div>
<div class="report-section">
<h3>Verificações de Conformidade</h3>
${report.checks.map(check => `
<div class="check-item">
<div class="check-header">
<span>${check.name}</span>
<span class="badge ${check.status === 'pass' ? 'badge-success' : 'badge-error'}">
${check.score}%
</span>
</div>
<div class="progress">
<div class="progress-bar" style="width: ${check.score}%"></div>
</div>
</div>
`).join('')}
</div>
`;
}
showError(message) {
this.resultsContainer.innerHTML = `
<div class="alert alert-error">
<p>${message}</p>
</div>
`;
}
showLoading(show) {
if (show) {
this.loadingElement.classList.remove('hidden');
} else {
this.loadingElement.classList.add('hidden');
}
}
clearResults() {
this.resultsContainer.innerHTML = '';
this.reportContainer.classList.add('hidden');
this.reportContent.innerHTML = '';
}
}
// Inicialização
document.addEventListener('DOMContentLoaded', () => {
new PDFComplianceAnalyzer();
}); |