682 lines
18 KiB
HTML
682 lines
18 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Fichero Printer</title>
|
|
<style>
|
|
:root {
|
|
--bg-primary: #0a0a0a;
|
|
--bg-secondary: #111827;
|
|
--text-primary: #e5e7eb;
|
|
--text-secondary: #9ca3af;
|
|
--accent: #3b82f6;
|
|
--accent-green: #10b981;
|
|
--accent-orange: #f59e0b;
|
|
--border: #374151;
|
|
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
|
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
|
--transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
--radius-sm: 0.25rem;
|
|
--radius-md: 0.375rem;
|
|
--radius-lg: 0.5rem;
|
|
}
|
|
|
|
/* Light theme variables */
|
|
[data-theme="light"] {
|
|
--bg-primary: #ffffff;
|
|
--bg-secondary: #f9fafb;
|
|
--text-primary: #111827;
|
|
--text-secondary: #6b7280;
|
|
--accent: #3b82f6;
|
|
--border: #e5e7eb;
|
|
}
|
|
|
|
/* System dark mode support */
|
|
@media (prefers-color-scheme: dark) {
|
|
:root:not([data-theme]) {
|
|
--bg-primary: #0a0a0a;
|
|
--bg-secondary: #111827;
|
|
--text-primary: #e5e7eb;
|
|
--text-secondary: #9ca3af;
|
|
--border: #374151;
|
|
}
|
|
}
|
|
|
|
* {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
body {
|
|
margin: 0;
|
|
font-family: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
|
|
color: var(--text-primary);
|
|
background-color: var(--bg-primary);
|
|
min-height: 100vh;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
/* Responsive container */
|
|
.container {
|
|
width: 100%;
|
|
margin: 0 auto;
|
|
padding: 0 1.5rem;
|
|
}
|
|
|
|
/* Responsive breakpoints */
|
|
@media (min-width: 768px) {
|
|
.container {
|
|
padding: 0 2rem;
|
|
}
|
|
}
|
|
|
|
@media (min-width: 1024px) {
|
|
.container {
|
|
padding: 0 4rem;
|
|
}
|
|
}
|
|
|
|
@media (min-width: 1440px) {
|
|
.container {
|
|
max-width: 1440px;
|
|
padding: 0 5rem;
|
|
}
|
|
}
|
|
|
|
main {
|
|
width: 100%;
|
|
margin: 0 auto;
|
|
padding: 2rem 0 3rem;
|
|
}
|
|
|
|
.hero {
|
|
margin-bottom: 2rem;
|
|
padding: 2rem;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius-lg);
|
|
background-color: var(--bg-secondary);
|
|
box-shadow: var(--shadow-md);
|
|
position: relative;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.hero::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
height: 3px;
|
|
background: linear-gradient(90deg, var(--accent), var(--accent-green));
|
|
}
|
|
|
|
h1 {
|
|
font-size: 2rem;
|
|
font-weight: 700;
|
|
margin-bottom: 0.5rem;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
h2 {
|
|
font-size: 1.5rem;
|
|
font-weight: 600;
|
|
margin-bottom: 1rem;
|
|
color: var(--text-primary);
|
|
border-bottom: 2px solid var(--border);
|
|
padding-bottom: 0.5rem;
|
|
}
|
|
|
|
h3 {
|
|
font-size: 1.25rem;
|
|
font-weight: 600;
|
|
margin-bottom: 1rem;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.muted {
|
|
color: var(--text-secondary);
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.grid {
|
|
display: grid;
|
|
gap: 1.5rem;
|
|
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.card {
|
|
padding: 1.5rem;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius-md);
|
|
background-color: var(--bg-secondary);
|
|
box-shadow: var(--shadow-sm);
|
|
transition: var(--transition);
|
|
}
|
|
|
|
.card:hover {
|
|
box-shadow: var(--shadow-md);
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.card h3 {
|
|
margin-bottom: 1rem;
|
|
padding-bottom: 0.5rem;
|
|
border-bottom: 1px solid var(--border);
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
margin: 0.75rem 0 0.5rem;
|
|
font-size: 0.9rem;
|
|
font-weight: 600;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
input, select, textarea {
|
|
width: 100%;
|
|
border-radius: var(--radius-sm);
|
|
border: 1px solid var(--border);
|
|
padding: 0.75rem 1rem;
|
|
font: inherit;
|
|
font-size: 0.95rem;
|
|
background-color: var(--bg-secondary);
|
|
color: var(--text-primary);
|
|
transition: var(--transition);
|
|
}
|
|
|
|
input:focus, select:focus, textarea:focus {
|
|
outline: none;
|
|
border-color: var(--accent);
|
|
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
|
|
}
|
|
|
|
textarea {
|
|
min-height: 120px;
|
|
resize: vertical;
|
|
font-family: inherit;
|
|
}
|
|
|
|
.row {
|
|
display: grid;
|
|
gap: 1rem;
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
margin-top: 0.5rem;
|
|
}
|
|
|
|
.inline {
|
|
display: flex;
|
|
gap: 0.75rem;
|
|
align-items: center;
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.inline input[type="checkbox"] {
|
|
width: auto;
|
|
transform: scale(1.2);
|
|
}
|
|
|
|
button {
|
|
cursor: pointer;
|
|
font-weight: 600;
|
|
color: white;
|
|
background-color: var(--accent);
|
|
border: none;
|
|
border-radius: var(--radius-sm);
|
|
padding: 0.75rem 1.5rem;
|
|
font-size: 0.95rem;
|
|
transition: var(--transition);
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
button:hover {
|
|
background-color: #2563eb;
|
|
transform: translateY(-1px);
|
|
}
|
|
|
|
button:active {
|
|
transform: translateY(0);
|
|
}
|
|
|
|
button.alt {
|
|
background-color: var(--accent-green);
|
|
}
|
|
|
|
button.alt:hover {
|
|
background-color: #059669;
|
|
}
|
|
|
|
button.secondary {
|
|
background-color: var(--border);
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
button.secondary:hover {
|
|
background-color: #4b5563;
|
|
}
|
|
|
|
pre {
|
|
overflow: auto;
|
|
margin: 1rem 0;
|
|
padding: 1rem;
|
|
border-radius: var(--radius-md);
|
|
background-color: #1f2937;
|
|
color: var(--text-primary);
|
|
min-height: 160px;
|
|
font-size: 0.9rem;
|
|
position: relative;
|
|
}
|
|
|
|
pre::before {
|
|
content: '$';
|
|
position: absolute;
|
|
left: 1rem;
|
|
top: 1rem;
|
|
color: var(--text-secondary);
|
|
font-weight: bold;
|
|
}
|
|
|
|
.actions {
|
|
display: flex;
|
|
gap: 0.75rem;
|
|
flex-wrap: wrap;
|
|
margin-top: 1.5rem;
|
|
}
|
|
|
|
.actions button {
|
|
flex: 1;
|
|
min-width: 160px;
|
|
}
|
|
|
|
/* Touch-friendly button sizes for mobile */
|
|
@media (max-width: 768px) {
|
|
button {
|
|
min-height: 44px;
|
|
padding: 0.75rem 1.5rem;
|
|
}
|
|
|
|
.actions button {
|
|
min-height: 48px;
|
|
}
|
|
}
|
|
|
|
/* Responsive adjustments */
|
|
@media (max-width: 768px) {
|
|
main {
|
|
padding: 1.5rem 0 2.5rem;
|
|
}
|
|
|
|
.hero {
|
|
padding: 1.5rem;
|
|
}
|
|
|
|
h1 {
|
|
font-size: 1.75rem;
|
|
}
|
|
|
|
.grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.row {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.actions button {
|
|
width: 100%;
|
|
}
|
|
}
|
|
|
|
@media (max-width: 480px) {
|
|
h1 {
|
|
font-size: 1.5rem;
|
|
}
|
|
|
|
h2 {
|
|
font-size: 1.25rem;
|
|
}
|
|
|
|
button {
|
|
padding: 0.6rem 1rem;
|
|
font-size: 0.9rem;
|
|
}
|
|
}
|
|
|
|
/* Loading spinner - updated for dark theme */
|
|
.loading {
|
|
display: inline-block;
|
|
width: 20px;
|
|
height: 20px;
|
|
border: 3px solid rgba(255, 255, 255, 0.3);
|
|
border-radius: 50%;
|
|
border-top-color: var(--accent);
|
|
animation: spin 1s ease-in-out infinite;
|
|
}
|
|
|
|
/* Animation for loading spinner */
|
|
@keyframes spin {
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
|
|
/* Theme toggle button */
|
|
.theme-toggle {
|
|
position: fixed;
|
|
bottom: 2rem;
|
|
right: 2rem;
|
|
width: 50px;
|
|
height: 50px;
|
|
border-radius: 50%;
|
|
background-color: var(--bg-secondary);
|
|
border: 1px solid var(--border);
|
|
color: var(--text-primary);
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
box-shadow: var(--shadow-md);
|
|
z-index: 1000;
|
|
transition: var(--transition);
|
|
}
|
|
|
|
.theme-toggle:hover {
|
|
background-color: var(--border);
|
|
transform: scale(1.1);
|
|
}
|
|
|
|
@keyframes spin {
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
|
|
/* Status indicators */
|
|
.status {
|
|
display: inline-block;
|
|
padding: 0.25rem 0.5rem;
|
|
border-radius: 12px;
|
|
font-size: 0.8rem;
|
|
font-weight: 600;
|
|
margin-left: 0.5rem;
|
|
}
|
|
|
|
.status.success {
|
|
background: rgba(46, 139, 87, 0.2);
|
|
color: var(--success);
|
|
}
|
|
|
|
.status.error {
|
|
background: rgba(205, 133, 63, 0.2);
|
|
color: var(--warning);
|
|
}
|
|
|
|
/* Tabs */
|
|
.tabs {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
margin-bottom: 1.5rem;
|
|
border-bottom: 1px solid var(--line);
|
|
}
|
|
|
|
.tab {
|
|
padding: 0.75rem 1rem;
|
|
cursor: pointer;
|
|
border: none;
|
|
background: transparent;
|
|
color: var(--muted);
|
|
font-weight: 500;
|
|
border-bottom: 2px solid transparent;
|
|
transition: var(--transition);
|
|
}
|
|
|
|
.tab.active {
|
|
color: var(--ink);
|
|
border-bottom-color: var(--accent);
|
|
}
|
|
|
|
.tab-content {
|
|
display: none;
|
|
}
|
|
|
|
.tab-content.active {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<div class="container">
|
|
<section class="hero">
|
|
<h1>Fichero Printer</h1>
|
|
<p class="muted">Home Assistant print console for status, text labels, and image uploads.</p>
|
|
<p class="muted">API docs remain available at <a href="docs">/docs</a>.</p>
|
|
</section>
|
|
|
|
<section class="grid">
|
|
<div class="card">
|
|
<h2>Connection</h2>
|
|
<label for="address">Printer address</label>
|
|
<input id="address" value="{default_address}" placeholder="C9:48:8A:69:D5:C0">
|
|
|
|
<div class="row">
|
|
<div>
|
|
<label for="transport">Transport</label>
|
|
<select id="transport" title="BLE is recommended for most users. Classic Bluetooth requires pairing and specific permissions.">
|
|
<option value="ble"{ble_selected}>BLE (Recommended)</option>
|
|
<option value="classic"{classic_selected}>Classic Bluetooth</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label for="channel">RFCOMM channel</label>
|
|
<input id="channel" type="number" min="1" max="30" value="{default_channel}">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="actions">
|
|
<button type="button" class="alt" onclick="runPost('pair')" title="Only needed for Classic Bluetooth. BLE does not require pairing.">Pair Device</button>
|
|
<button type="button" class="alt" onclick="runPost('unpair')" title="Only needed for Classic Bluetooth. BLE does not require pairing.">Unpair Device</button>
|
|
<button type="button" class="alt" onclick="runGet('status')">Get Status</button>
|
|
<button type="button" class="alt" onclick="runGet('info')">Get Info</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2>Output</h2>
|
|
<pre id="output">Ready.</pre>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2>Print Text</h2>
|
|
<label for="text">Text</label>
|
|
<textarea id="text" placeholder="Hello from Home Assistant"></textarea>
|
|
<div class="row">
|
|
<div>
|
|
<label for="text_density">Density</label>
|
|
<select id="text_density">
|
|
<option value="0">0</option>
|
|
<option value="1">1</option>
|
|
<option value="2" selected>2</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label for="text_copies">Copies</label>
|
|
<input id="text_copies" type="number" min="1" max="99" value="1">
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div>
|
|
<label for="text_font_size">Font size</label>
|
|
<input id="text_font_size" type="number" min="6" max="200" value="30">
|
|
</div>
|
|
<div>
|
|
<label for="text_label_length">Label length (mm)</label>
|
|
<input id="text_label_length" type="number" min="5" max="500" value="30">
|
|
</div>
|
|
</div>
|
|
<label for="text_paper">Paper</label>
|
|
<select id="text_paper">
|
|
<option value="gap" selected>gap</option>
|
|
<option value="black">black</option>
|
|
<option value="continuous">continuous</option>
|
|
</select>
|
|
<div class="actions">
|
|
<button type="button" onclick="printText()">Print Text</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2>Print Image</h2>
|
|
<label for="image_file">Image file</label>
|
|
<input id="image_file" type="file" accept="image/*">
|
|
<div class="row">
|
|
<div>
|
|
<label for="image_density">Density</label>
|
|
<select id="image_density">
|
|
<option value="0">0</option>
|
|
<option value="1">1</option>
|
|
<option value="2" selected>2</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label for="image_copies">Copies</label>
|
|
<input id="image_copies" type="number" min="1" max="99" value="1">
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div>
|
|
<label for="image_label_length">Label length (mm)</label>
|
|
<input id="image_label_length" type="number" min="5" max="500" value="30">
|
|
</div>
|
|
<div class="inline">
|
|
<input id="image_dither" type="checkbox" checked>
|
|
<label for="image_dither">Enable dithering</label>
|
|
</div>
|
|
</div>
|
|
<label for="image_paper">Paper</label>
|
|
<select id="image_paper">
|
|
<option value="gap" selected>gap</option>
|
|
<option value="black">black</option>
|
|
<option value="continuous">continuous</option>
|
|
</select>
|
|
<div class="actions">
|
|
<button type="button" onclick="printImage()">Print Image</button>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div> <!-- Close container -->
|
|
</main>
|
|
|
|
<!-- Theme Toggle Button -->
|
|
<button id="theme-toggle" class="theme-toggle" onclick="toggleTheme()" aria-label="Toggle theme">
|
|
🌙
|
|
</button>
|
|
|
|
<script>
|
|
function commonParams() {
|
|
const address = document.getElementById("address").value.trim();
|
|
const classic = document.getElementById("transport").value === "classic";
|
|
const channel = document.getElementById("channel").value;
|
|
const params = new URLSearchParams();
|
|
if (address) params.set("address", address);
|
|
params.set("classic", String(classic));
|
|
params.set("channel", channel);
|
|
return params;
|
|
}
|
|
|
|
async function showResponse(response) {
|
|
const output = document.getElementById("output");
|
|
let data;
|
|
try {
|
|
data = await response.json();
|
|
} catch {
|
|
data = { detail: await response.text() };
|
|
}
|
|
output.textContent = JSON.stringify({ status: response.status, ok: response.ok, data }, null, 2);
|
|
}
|
|
|
|
async function runGet(path) {
|
|
const response = await fetch(`${path}?${commonParams().toString()}`);
|
|
await showResponse(response);
|
|
}
|
|
|
|
async function runPost(path) {
|
|
const form = new FormData();
|
|
const params = commonParams();
|
|
for (const [key, value] of params.entries()) {
|
|
form.set(key, value);
|
|
}
|
|
const response = await fetch(path, { method: "POST", body: form });
|
|
await showResponse(response);
|
|
}
|
|
|
|
async function printText() {
|
|
const form = new FormData();
|
|
form.set("text", document.getElementById("text").value);
|
|
form.set("density", document.getElementById("text_density").value);
|
|
form.set("copies", document.getElementById("text_copies").value);
|
|
form.set("font_size", document.getElementById("text_font_size").value);
|
|
form.set("label_length", document.getElementById("text_label_length").value);
|
|
form.set("paper", document.getElementById("text_paper").value);
|
|
form.set("address", document.getElementById("address").value.trim());
|
|
form.set("classic", String(document.getElementById("transport").value === "classic"));
|
|
form.set("channel", document.getElementById("channel").value);
|
|
const response = await fetch("print/text", { method: "POST", body: form });
|
|
await showResponse(response);
|
|
}
|
|
|
|
async function printImage() {
|
|
const fileInput = document.getElementById("image_file");
|
|
if (!fileInput.files.length) {
|
|
document.getElementById("output").textContent = "Select an image file first.";
|
|
return;
|
|
}
|
|
const form = new FormData();
|
|
form.set("file", fileInput.files[0]);
|
|
form.set("density", document.getElementById("image_density").value);
|
|
form.set("copies", document.getElementById("image_copies").value);
|
|
form.set("label_length", document.getElementById("image_label_length").value);
|
|
form.set("paper", document.getElementById("image_paper").value);
|
|
form.set("dither", String(document.getElementById("image_dither").checked));
|
|
form.set("address", document.getElementById("address").value.trim());
|
|
form.set("classic", String(document.getElementById("transport").value === "classic"));
|
|
form.set("channel", document.getElementById("channel").value);
|
|
const response = await fetch("print/image", { method: "POST", body: form });
|
|
await showResponse(response);
|
|
}
|
|
/* Theme toggle functionality */
|
|
function toggleTheme() {
|
|
const html = document.documentElement;
|
|
const currentTheme = html.getAttribute('data-theme');
|
|
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
|
|
html.setAttribute('data-theme', newTheme);
|
|
localStorage.setItem('theme', newTheme);
|
|
updateThemeIcon(newTheme);
|
|
}
|
|
|
|
function updateThemeIcon(theme) {
|
|
const toggleButton = document.getElementById('theme-toggle');
|
|
if (toggleButton) {
|
|
toggleButton.textContent = theme === 'light' ? '🌙' : '☀️';
|
|
}
|
|
}
|
|
|
|
// Initialize theme
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const savedTheme = localStorage.getItem('theme');
|
|
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
const initialTheme = savedTheme || (systemPrefersDark ? 'dark' : 'light');
|
|
document.documentElement.setAttribute('data-theme', initialTheme);
|
|
updateThemeIcon(initialTheme);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |