212 lines
7.2 KiB
HTML
212 lines
7.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Visor Markdown - Versión Optimizada</title>
|
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
/* Optimizamos el fondo: degradado fijo en CSS en lugar de Canvas */
|
|
background: radial-gradient(circle at center, #0a0e27 0%, #050810 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
overflow-x: hidden;
|
|
color: #e2e8f0;
|
|
}
|
|
|
|
#stars-canvas {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
z-index: 0;
|
|
pointer-events: none;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1400px;
|
|
margin: 0 auto;
|
|
background: rgba(15, 23, 42, 0.9);
|
|
border-radius: 20px;
|
|
/* Reducimos el radio de las sombras para mejorar el rendimiento */
|
|
box-shadow: 0 0 30px rgba(59, 130, 246, 0.2);
|
|
overflow: hidden;
|
|
border: 1px solid rgba(59, 130, 246, 0.2);
|
|
position: relative;
|
|
z-index: 1;
|
|
}
|
|
|
|
/* Estilos de Header y Botones (Mantenemos tu estética) */
|
|
.header {
|
|
background: linear-gradient(135deg, #1e3a8a 0%, #7c3aed 50%, #db2777 100%);
|
|
padding: 40px 30px;
|
|
text-align: center;
|
|
}
|
|
|
|
.controls {
|
|
display: flex;
|
|
gap: 12px;
|
|
padding: 20px;
|
|
background: rgba(15, 23, 42, 0.95);
|
|
border-bottom: 1px solid rgba(59, 130, 246, 0.2);
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.btn {
|
|
padding: 10px 20px;
|
|
border-radius: 8px;
|
|
border: none;
|
|
cursor: pointer;
|
|
font-weight: 600;
|
|
transition: transform 0.2s;
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary { background: #3b82f6; }
|
|
.btn-secondary { background: #6366f1; }
|
|
.btn-success { background: #10b981; }
|
|
.btn:hover { transform: translateY(-2px); }
|
|
|
|
.workspace {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
min-height: 600px;
|
|
}
|
|
|
|
.workspace.preview-only { grid-template-columns: 1fr; }
|
|
|
|
.editor-panel, .preview-panel { padding: 30px; overflow-y: auto; max-height: 750px; }
|
|
.editor-panel { border-right: 1px solid rgba(59, 130, 246, 0.2); }
|
|
|
|
textarea {
|
|
width: 100%;
|
|
min-height: 550px;
|
|
padding: 15px;
|
|
background: rgba(30, 41, 59, 0.5);
|
|
color: #fff;
|
|
border: 1px solid rgba(59, 130, 246, 0.3);
|
|
border-radius: 8px;
|
|
font-family: 'Courier New', monospace;
|
|
resize: none;
|
|
}
|
|
|
|
/* Markdown Preview Styles */
|
|
#content h1 { color: #60a5fa; border-bottom: 1px solid #3b82f6; padding-bottom: 10px; margin-bottom: 20px; }
|
|
#content code { background: #1e293b; color: #fbbf24; padding: 2px 6px; border-radius: 4px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="stars-canvas"></canvas>
|
|
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>🚀 Visor Markdown Pro</h1>
|
|
<p>Optimizado para alto rendimiento</p>
|
|
</div>
|
|
|
|
<div class="controls">
|
|
<input type="file" id="file-upload" hidden>
|
|
<button onclick="document.getElementById('file-upload').click()" class="btn btn-primary">📁 Cargar</button>
|
|
<button id="clear-btn" class="btn btn-secondary">🗑️ Limpiar</button>
|
|
<button id="download-btn" class="btn btn-success">💾 Descargar</button>
|
|
</div>
|
|
|
|
<div class="workspace" id="workspace">
|
|
<div class="editor-panel">
|
|
<textarea id="markdown-input" placeholder="# Empieza a escribir..."></textarea>
|
|
</div>
|
|
<div class="preview-panel">
|
|
<div id="content"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// --- OPTIMIZACIÓN DE CANVAS (Estrellas) ---
|
|
const canvas = document.getElementById('stars-canvas');
|
|
const ctx = canvas.getContext('2d');
|
|
const offscreenCanvas = document.createElement('canvas');
|
|
const offCtx = offscreenCanvas.getContext('2d');
|
|
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
|
|
// Pre-renderizamos una estrella una sola vez
|
|
offscreenCanvas.width = 10;
|
|
offscreenCanvas.height = 10;
|
|
const grad = offCtx.createRadialGradient(5, 5, 0, 5, 5, 5);
|
|
grad.addColorStop(0, 'rgba(139, 92, 246, 1)');
|
|
grad.addColorStop(1, 'rgba(139, 92, 246, 0)');
|
|
offCtx.fillStyle = grad;
|
|
offCtx.fillRect(0, 0, 10, 10);
|
|
|
|
let stars = [];
|
|
for (let i = 0; i < 150; i++) {
|
|
stars.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
s: Math.random() * 0.5 + 0.2,
|
|
vx: (Math.random() - 0.5) * 0.3,
|
|
vy: (Math.random() - 0.5) * 0.3
|
|
});
|
|
}
|
|
|
|
function animate() {
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
stars.forEach(s => {
|
|
s.x = (s.x + s.vx + canvas.width) % canvas.width;
|
|
s.y = (s.y + s.vy + canvas.height) % canvas.height;
|
|
// Usamos drawImage en lugar de crear gradientes cada vez
|
|
ctx.drawImage(offscreenCanvas, s.x, s.y, 10 * s.s, 10 * s.s);
|
|
});
|
|
requestAnimationFrame(animate);
|
|
}
|
|
animate();
|
|
|
|
// --- OPTIMIZACIÓN DE EDITOR (Debounce) ---
|
|
const input = document.getElementById('markdown-input');
|
|
const content = document.getElementById('content');
|
|
|
|
function debounce(func, wait) {
|
|
let timeout;
|
|
return (...args) => {
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(() => func.apply(this, args), wait);
|
|
};
|
|
}
|
|
|
|
const updatePreview = debounce(() => {
|
|
content.innerHTML = marked.parse(input.value || '*Vista previa vacía*');
|
|
}, 300); // 300ms de espera
|
|
|
|
input.addEventListener('input', updatePreview);
|
|
|
|
// Funciones básicas de botones
|
|
document.getElementById('clear-btn').onclick = () => {
|
|
if(confirm('¿Limpiar?')) { input.value = ''; updatePreview(); }
|
|
};
|
|
|
|
document.getElementById('download-btn').onclick = () => {
|
|
const blob = new Blob([input.value], {type: 'text/markdown'});
|
|
const a = document.createElement('a');
|
|
a.href = URL.createObjectURL(blob);
|
|
a.download = 'nota.md';
|
|
a.click();
|
|
};
|
|
|
|
// Cargar archivo
|
|
document.getElementById('file-upload').onchange = (e) => {
|
|
const reader = new FileReader();
|
|
reader.onload = (ev) => { input.value = ev.target.result; updatePreview(); };
|
|
reader.readAsText(e.target.files[0]);
|
|
};
|
|
|
|
// Carga inicial
|
|
updatePreview();
|
|
</script>
|
|
</body>
|
|
</html>
|