WEFT_OS/examples/org.weft.demo.counter/ui/index.html

145 lines
3.4 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Counter</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: #0f0f0f;
color: #e8e8e8;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
.card {
background: #1a1a1a;
border: 1px solid #2a2a2a;
border-radius: 16px;
padding: 48px 64px;
display: flex;
flex-direction: column;
align-items: center;
gap: 32px;
min-width: 320px;
}
h1 {
font-size: 14px;
font-weight: 500;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #666;
}
#count {
font-size: 96px;
font-weight: 700;
font-variant-numeric: tabular-nums;
line-height: 1;
min-width: 3ch;
text-align: center;
transition: color 0.15s;
}
#count.negative { color: #e05252; }
#count.positive { color: #e8e8e8; }
.controls {
display: flex;
gap: 12px;
}
button {
width: 56px;
height: 56px;
border-radius: 12px;
border: 1px solid #333;
background: #222;
color: #e8e8e8;
font-size: 24px;
font-weight: 300;
cursor: pointer;
transition: background 0.1s, transform 0.08s;
display: flex;
align-items: center;
justify-content: center;
line-height: 1;
}
button:hover { background: #2e2e2e; }
button:active { transform: scale(0.94); }
#reset {
font-size: 13px;
font-weight: 500;
letter-spacing: 0.04em;
width: auto;
padding: 0 20px;
color: #888;
border-color: #2a2a2a;
}
#status {
font-size: 12px;
color: #444;
min-height: 16px;
}
</style>
</head>
<body>
<div class="card">
<h1>Counter</h1>
<div id="count" class="positive">0</div>
<div class="controls">
<button id="dec" aria-label="Decrement"></button>
<button id="reset">Reset</button>
<button id="inc" aria-label="Increment">+</button>
</div>
<div id="status">connecting…</div>
</div>
<script>
(function () {
var countEl = document.getElementById('count');
var statusEl = document.getElementById('status');
function applyCount(n) {
countEl.textContent = n;
countEl.className = n < 0 ? 'negative' : 'positive';
}
function send(action) {
if (window.weftIpc) {
window.weftIpc.send(action);
}
}
document.getElementById('inc').addEventListener('click', function () { send('increment'); });
document.getElementById('dec').addEventListener('click', function () { send('decrement'); });
document.getElementById('reset').addEventListener('click', function () { send('reset'); });
document.addEventListener('keydown', function (e) {
if (e.key === 'ArrowUp' || e.key === '+') send('increment');
if (e.key === 'ArrowDown' || e.key === '-') send('decrement');
if (e.key === 'r' || e.key === 'R') send('reset');
});
function setupIpc() {
if (!window.weftIpc) {
setTimeout(setupIpc, 50);
return;
}
statusEl.textContent = '';
send('get');
window.weftIpc.onmessage = function (raw) {
try {
var msg = typeof raw === 'string' ? JSON.parse(raw) : raw;
if (typeof msg.count === 'number') {
applyCount(msg.count);
}
} catch (_) {}
};
}
setupIpc();
})();
</script>
</body>
</html>