feat: browser simulator served by the controller, desktop build, browser bridge
- led-simulator: the rig runs the C++ led-driver as WebAssembly (sim-driver/), one single-threaded worker per bar, no cross-origin isolation needed. Rooms (one JSON per room) with an on-page editor, and a pattern gallery. The Python server, Pyodide boot and ring buffer are removed. - sim-controller sim_rig.c: serves /sim/ from an embedded pack, the page's WebSocket and the rooms/flash API. The desktop build embeds it too. - bridge.c: a "browser" bridge kind that carries ESP-NOW frames to the page; devices announced through it are marked sim. - UI: Simulator in the Menu, split view with resize and pop-out, swipe between controller and rig on phones; SIM/REAL badges in Devices. - Fades: preset pushes and Wi-Fi driver bodies always carry fade and beat_time, so "off" no longer inherits an earlier fade. - Also the sequences-v2 work in progress: desktop port, bridge firmware, serial bridge, Wi-Fi drivers, sequence timeline, audio and API changes. - led-driver: ESP-NOW link, beat sync, control messages, sim hooks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
698c1463c0
commit
581b751904
506 files changed
+42336
-3599
No files matched your search
+756
-309
File diff suppressed because it is too large.
Load diff
@@ -1,84 +1,105 @@
|
||||
/* One simulated led-driver: Pyodide running led-driver/src/main.py.
|
||||
/* One simulated led-driver: the C++ firmware (led-driver/main) built to WebAssembly (sim-driver/ in led-controller).
|
||||
*
|
||||
* The page posts {t: 'boot', ...} once. The worker loads Pyodide, writes the
|
||||
* strip's flash (driver source, patterns, settings.json, presets.json) and the
|
||||
* stubs into the Pyodide filesystem, then runs web/driver_boot.py, which never
|
||||
* returns while the driver is powered. Power-off is Worker.terminate().
|
||||
* A module worker. The page posts {t: 'boot', mac, nvs, fps} once; the worker instantiates
|
||||
* wasm/led_driver.mjs and calls sim_boot. There are no threads (so no SharedArrayBuffer, and the page works
|
||||
* on any address): every TICK_MS the worker calls sim_tick, which runs what the board's two tasks run, a pass
|
||||
* of the ESP-NOW link and, every 10 ms, a pattern frame. Packets arrive as plain messages between ticks.
|
||||
* Power-off is Worker.terminate().
|
||||
*
|
||||
* Messages to the page:
|
||||
* Page -> worker:
|
||||
* {t:'boot', mac, nvs, fps} mac: 12 hex digits; nvs: the strip's flash (JSON text)
|
||||
* {t:'rx', data} Uint8Array src_mac(6) + ESP-NOW packet
|
||||
* Worker -> page:
|
||||
* {t:'state', state} loading | running
|
||||
* {t:'log', text} driver serial output (one line)
|
||||
* {t:'tx', data} Uint8Array dest_mac(6) + ESP-NOW packet
|
||||
* {t:'px', data} Uint8Array RGB frame
|
||||
* {t:'flash', path, data} settings.json / presets.json changed
|
||||
* {t:'exit', error, reset} main.py stopped (reset: machine.reset())
|
||||
* {t:'px', data} Uint8Array RGB frame, pixel 0 first
|
||||
* {t:'flash', data} the NVS store after a commit (JSON text)
|
||||
* {t:'exit', error, reset} the driver stopped (reset: esp_restart())
|
||||
*/
|
||||
/* global importScripts, loadPyodide, SimRing */
|
||||
importScripts('/web/ring.js');
|
||||
import LedDriver from './wasm/led_driver.mjs';
|
||||
|
||||
let ring = null;
|
||||
let sleepView = null;
|
||||
const FRAME_CAP = 512 * 3; // FX_LEDS_MAX
|
||||
const TICK_MS = 4;
|
||||
const RX_CAP = 6 + 250;
|
||||
|
||||
self.simRecv = () => (ring ? ring.pop() : undefined);
|
||||
self.simPending = () => (ring ? ring.count() : 0);
|
||||
self.simTx = (u8) => self.postMessage({ t: 'tx', data: u8 }, [u8.buffer]);
|
||||
self.simPixels = (u8) => self.postMessage({ t: 'px', data: u8 }, [u8.buffer]);
|
||||
self.simFlash = (path, text) =>
|
||||
self.postMessage({ t: 'flash', path: String(path), data: String(text) });
|
||||
self.simSleep = (ms) => {
|
||||
if (ms > 0 && sleepView) {
|
||||
// Nobody notifies this slot: it is a plain blocking sleep.
|
||||
Atomics.wait(sleepView, 0, 0, ms);
|
||||
}
|
||||
};
|
||||
let mod = null;
|
||||
let rxPtr = 0;
|
||||
|
||||
function log(text) {
|
||||
self.postMessage({ t: 'log', text: String(text) });
|
||||
}
|
||||
|
||||
function writeTree(FS, root, files) {
|
||||
for (const [rel, body] of Object.entries(files)) {
|
||||
const path = `${root}/${String(rel).replace(/^\/+/, '')}`;
|
||||
const dir = path.slice(0, path.lastIndexOf('/'));
|
||||
if (dir) {
|
||||
FS.mkdirTree(dir);
|
||||
}
|
||||
FS.writeFile(path, String(body));
|
||||
}
|
||||
function exit(error, reset = false) {
|
||||
self.postMessage({ t: 'exit', error: String(error), reset });
|
||||
}
|
||||
|
||||
self.onmessage = async (event) => {
|
||||
const m = event.data || {};
|
||||
if (m.t !== 'boot') {
|
||||
return;
|
||||
}
|
||||
ring = new SimRing(m.ringSab);
|
||||
sleepView = new Int32Array(m.sleepSab);
|
||||
function startPixels(fps) {
|
||||
const ptr = mod._malloc(FRAME_CAP);
|
||||
let last = null;
|
||||
setInterval(() => {
|
||||
const n = mod._sim_frame(ptr, FRAME_CAP);
|
||||
const frame = mod.HEAPU8.slice(ptr, ptr + n * 3);
|
||||
if (last && last.length === frame.length && frame.every((v, i) => v === last[i])) {
|
||||
return; // unchanged: nothing to redraw
|
||||
}
|
||||
last = frame;
|
||||
const out = frame.slice();
|
||||
self.postMessage({ t: 'px', data: out }, [out.buffer]);
|
||||
}, 1000 / Math.max(1, Math.min(60, Number(fps) || 30)));
|
||||
}
|
||||
|
||||
async function boot(m) {
|
||||
self.postMessage({ t: 'state', state: 'loading' });
|
||||
try {
|
||||
importScripts(`${m.pyodideUrl}pyodide.js`);
|
||||
const py = await loadPyodide({
|
||||
indexURL: m.pyodideUrl,
|
||||
stdout: log,
|
||||
stderr: log,
|
||||
mod = await LedDriver({
|
||||
print: log,
|
||||
printErr: log,
|
||||
simTx: (u8) => self.postMessage({ t: 'tx', data: u8 }, [u8.buffer]),
|
||||
simFlash: (json) => self.postMessage({ t: 'flash', data: json }),
|
||||
simRestart: () => exit('esp_restart()', true),
|
||||
onAbort: (what) => exit(`abort: ${what}`),
|
||||
});
|
||||
const FS = py.FS;
|
||||
writeTree(FS, '/flash', m.files.driver);
|
||||
writeTree(FS, '/flash', m.flash);
|
||||
writeTree(FS, '/stubs', m.files.stubs);
|
||||
FS.writeFile('/boot.py', m.bootPy);
|
||||
py.globals.set('__sim_env', py.toPy(m.env));
|
||||
py.runPython('import os\nos.environ.update({str(k): str(v) for k, v in __sim_env.items()})\ndel __sim_env');
|
||||
self.postMessage({ t: 'state', state: 'running' });
|
||||
// Blocks until main.py exits (it normally never does).
|
||||
py.runPython('import runpy\nrunpy.run_path("/boot.py", run_name="__boot__")');
|
||||
self.postMessage({ t: 'exit', error: 'main.py returned', reset: false });
|
||||
} catch (err) {
|
||||
const msg = String((err && err.message) || err);
|
||||
const reset = /SystemExit:\s*75\b/.test(msg);
|
||||
if (!reset) {
|
||||
log(msg);
|
||||
log(String((err && err.stack) || err));
|
||||
exit(`load failed: ${err}`);
|
||||
return;
|
||||
}
|
||||
const mac = mod.stringToNewUTF8(String(m.mac));
|
||||
const nvs = mod.stringToNewUTF8(String(m.nvs || '{}'));
|
||||
let rc;
|
||||
try {
|
||||
rc = mod._sim_boot(mac, nvs);
|
||||
} catch (err) {
|
||||
log(String((err && err.stack) || err));
|
||||
exit(String(err));
|
||||
return;
|
||||
} finally {
|
||||
mod._free(mac);
|
||||
mod._free(nvs);
|
||||
}
|
||||
if (rc !== 0) {
|
||||
exit(`sim_boot returned ${rc}`);
|
||||
return;
|
||||
}
|
||||
rxPtr = mod._malloc(RX_CAP);
|
||||
setInterval(() => {
|
||||
try {
|
||||
mod._sim_tick();
|
||||
} catch (err) {
|
||||
exit(String((err && err.message) || err));
|
||||
}
|
||||
self.postMessage({ t: 'exit', error: reset ? 'machine.reset()' : msg, reset });
|
||||
}, TICK_MS);
|
||||
startPixels(m.fps);
|
||||
self.postMessage({ t: 'state', state: 'running' });
|
||||
}
|
||||
|
||||
self.onmessage = (event) => {
|
||||
const m = event.data || {};
|
||||
if (m.t === 'boot' && !mod) {
|
||||
boot(m);
|
||||
} else if (m.t === 'rx' && rxPtr && m.data && m.data.length <= RX_CAP) {
|
||||
mod.HEAPU8.set(m.data, rxPtr);
|
||||
mod._sim_rx(rxPtr, m.data.length);
|
||||
}
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
"""Boot one simulated led-driver inside Pyodide (run by web/driver-worker.js).
|
||||
|
||||
The worker has already written the strip's flash into ``LED_SIM_FLASH``
|
||||
(``led-driver/src`` including ``patterns/``, plus this strip's
|
||||
``settings.json`` and ``presets.json``) and the stubs into ``LED_SIM_STUBS``.
|
||||
This then runs the real ``main.py`` as ``__main__``, as the board does at
|
||||
power-on: settings, presets, startup preset, ESP-NOW hello, main loop.
|
||||
"""
|
||||
|
||||
import gc
|
||||
import os
|
||||
import runpy
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
def boot():
|
||||
flash = os.environ.get("LED_SIM_FLASH", "/flash")
|
||||
stubs = os.environ.get("LED_SIM_STUBS", "/stubs")
|
||||
|
||||
# Stubs replace the hardware modules; the flash root plays the device's
|
||||
# "/" (cwd), where main.py, settings.json, presets.json and patterns/ live.
|
||||
for p in (flash, stubs):
|
||||
while p in sys.path:
|
||||
sys.path.remove(p)
|
||||
sys.path[:0] = [stubs, flash]
|
||||
os.chdir(flash)
|
||||
|
||||
import _simlink
|
||||
|
||||
# No threads and no event loop turns while main.py runs: sleeps block on
|
||||
# Atomics.wait, and the ping-reply "thread" runs from the main loop.
|
||||
time.sleep = _simlink.real_sleep
|
||||
import _thread
|
||||
|
||||
_thread.start_new_thread = _simlink.start_new_thread
|
||||
|
||||
if not hasattr(gc, "mem_free"):
|
||||
gc.mem_free = lambda: 256 * 1024
|
||||
gc.mem_alloc = lambda: 64 * 1024
|
||||
|
||||
import settings as led_settings
|
||||
|
||||
led_settings.Settings.SETTINGS_FILE = flash.rstrip("/") + "/settings.json"
|
||||
|
||||
runpy.run_path(flash.rstrip("/") + "/main.py", run_name="__main__")
|
||||
|
||||
|
||||
boot()
|
||||
@@ -0,0 +1,37 @@
|
||||
.gallery-intro { margin: 0; padding: 10px 16px 0; color: var(--muted); max-width: 900px; }
|
||||
.gallery {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
|
||||
gap: 12px;
|
||||
padding: 12px 16px 24px;
|
||||
}
|
||||
.card {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
padding: 10px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||||
.card-name { font-weight: 600; font-family: ui-monospace, Menlo, Consolas, monospace; }
|
||||
.card-head .btns { display: flex; gap: 4px; }
|
||||
.card-head button { padding: 2px 8px; }
|
||||
.card canvas { width: 100%; height: 22px; display: block; background: #0b0c0f; border-radius: 4px; }
|
||||
.card form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px 8px; }
|
||||
.card form[hidden] { display: none; }
|
||||
.card form label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 11px; }
|
||||
.card form label.wide { grid-column: span 2; }
|
||||
.card form label.full { grid-column: 1 / -1; }
|
||||
.card form label.check { flex-direction: row; align-items: center; gap: 5px; }
|
||||
.card form input { width: 100%; padding: 3px 5px; }
|
||||
.card form input[type=checkbox] { width: auto; }
|
||||
.colours { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
|
||||
.colours input[type=color] { width: 30px; height: 24px; padding: 0; border-radius: 4px; }
|
||||
.colours button { padding: 1px 7px; }
|
||||
@media (max-width: 420px) {
|
||||
.gallery { grid-template-columns: 1fr; padding: 12px 16px; }
|
||||
.card form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="theme-color" content="#0e0f12">
|
||||
<title>Pattern Gallery</title>
|
||||
<link rel="icon" href="data:,">
|
||||
<link rel="stylesheet" href="/sim/styles.css">
|
||||
<link rel="stylesheet" href="/sim/gallery.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
<div class="brand">
|
||||
<span class="brand-mark" aria-hidden="true"></span>
|
||||
<span class="brand-name">Pattern gallery</span>
|
||||
</div>
|
||||
<div class="chips"><span class="chip" id="g-count">loading…</span></div>
|
||||
<div class="actions">
|
||||
<label class="field-inline">LEDs <input id="g-leds" type="number" min="1" max="512" step="1" value="119"></label>
|
||||
<label class="field-inline">Speed
|
||||
<select id="g-speed">
|
||||
<option value="0.25">¼×</option><option value="0.5">½×</option><option value="1" selected>1×</option>
|
||||
<option value="2">2×</option><option value="4">4×</option>
|
||||
</select>
|
||||
</label>
|
||||
<button type="button" id="g-pause" class="secondary">Pause</button>
|
||||
<button type="button" id="g-restart" class="secondary">Restart all</button>
|
||||
<a class="button secondary" href="/sim/">Rig</a>
|
||||
</div>
|
||||
</header>
|
||||
<div id="banner" class="banner" hidden></div>
|
||||
<p class="gallery-intro">
|
||||
Every pattern of the C++ led-driver, built to WebAssembly and stepped every 10 ms as on the strip. Fields are the
|
||||
preset's (the names the controller sends). Leave the colour list empty for the pattern's own colours.
|
||||
</p>
|
||||
<main class="gallery" id="gallery"></main>
|
||||
<script type="module" src="/sim/gallery.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,303 @@
|
||||
/* Pattern gallery: every led-driver pattern side by side, from the C++ engine built to WebAssembly
|
||||
* (wasm/led_fx.mjs: led-driver/main/patterns.cpp and the effects, no threads).
|
||||
*
|
||||
* One module instance per pattern, so each has its own engine state; the wasm is compiled once and shared.
|
||||
* Each instance has its own clock and runs patterns_frame() every 10 ms of it (FRAME_MS on the board).
|
||||
*/
|
||||
import LedFx from './wasm/led_fx.mjs';
|
||||
|
||||
const FRAME_MS = 10;
|
||||
const MAX_STEPS = 25; // per animation frame, after the tab was in the background
|
||||
const LED_CAP = 512;
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
const state = { leds: 119, speed: 1, paused: false, cards: [] };
|
||||
|
||||
function banner(text) {
|
||||
const el = $('banner');
|
||||
el.textContent = text;
|
||||
el.hidden = !text;
|
||||
}
|
||||
|
||||
function hex(c) {
|
||||
return `#${c.map((v) => Number(v).toString(16).padStart(2, '0')).join('')}`;
|
||||
}
|
||||
|
||||
function rgb(h) {
|
||||
const v = parseInt(h.slice(1), 16);
|
||||
return [(v >> 16) & 255, (v >> 8) & 255, v & 255];
|
||||
}
|
||||
|
||||
async function instantiate(wasmModule) {
|
||||
return LedFx({
|
||||
print: () => {},
|
||||
printErr: (t) => console.warn('[fx]', t),
|
||||
instantiateWasm(imports, receive) {
|
||||
WebAssembly.instantiate(wasmModule, imports).then((inst) => receive(inst, wasmModule));
|
||||
return {};
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function presetJson(card) {
|
||||
return JSON.stringify(card.preset);
|
||||
}
|
||||
|
||||
function apply(card, restart) {
|
||||
const p = card.mod.stringToNewUTF8(presetJson(card));
|
||||
const ok = card.mod._fx_select_json(p, restart ? 1 : 0);
|
||||
card.mod._free(p);
|
||||
if (restart) {
|
||||
card.clock = 0;
|
||||
card.next = 0;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
function numField(card, key, label, opts = {}) {
|
||||
const l = document.createElement('label');
|
||||
if (opts.cls) l.className = opts.cls;
|
||||
l.textContent = label;
|
||||
const i = document.createElement('input');
|
||||
i.type = 'number';
|
||||
i.step = opts.step ?? 1;
|
||||
if (opts.min !== undefined) i.min = opts.min;
|
||||
if (opts.max !== undefined) i.max = opts.max;
|
||||
i.value = card.preset[key] ?? 0;
|
||||
i.onchange = () => {
|
||||
const v = Number(i.value);
|
||||
if (Number.isFinite(v)) {
|
||||
card.preset[key] = Math.round(v);
|
||||
apply(card, opts.restart);
|
||||
}
|
||||
};
|
||||
l.append(i);
|
||||
return l;
|
||||
}
|
||||
|
||||
function checkField(card, key, label, restart) {
|
||||
const l = document.createElement('label');
|
||||
l.className = 'check';
|
||||
const i = document.createElement('input');
|
||||
i.type = 'checkbox';
|
||||
i.checked = Boolean(card.preset[key]);
|
||||
i.onchange = () => {
|
||||
card.preset[key] = i.checked;
|
||||
apply(card, restart);
|
||||
};
|
||||
l.append(i, label);
|
||||
return l;
|
||||
}
|
||||
|
||||
function colourList(card) {
|
||||
const l = document.createElement('label');
|
||||
l.className = 'full';
|
||||
l.textContent = 'Colours';
|
||||
const box = document.createElement('div');
|
||||
box.className = 'colours';
|
||||
const render = () => {
|
||||
const items = card.preset.colors.map((c, k) => {
|
||||
const i = document.createElement('input');
|
||||
i.type = 'color';
|
||||
i.value = hex(c);
|
||||
i.title = 'Click to change; right-click to remove';
|
||||
i.oninput = () => {
|
||||
card.preset.colors[k] = rgb(i.value);
|
||||
apply(card, false);
|
||||
};
|
||||
i.oncontextmenu = (ev) => {
|
||||
ev.preventDefault();
|
||||
card.preset.colors.splice(k, 1);
|
||||
apply(card, false);
|
||||
render();
|
||||
};
|
||||
return i;
|
||||
});
|
||||
const add = document.createElement('button');
|
||||
add.type = 'button';
|
||||
add.className = 'secondary';
|
||||
add.textContent = '+';
|
||||
add.title = 'Add a colour';
|
||||
add.disabled = card.preset.colors.length >= 8;
|
||||
add.onclick = () => {
|
||||
const last = card.preset.colors[card.preset.colors.length - 1];
|
||||
card.preset.colors.push(last ? [last[2], last[0], last[1]] : [255, 0, 0]);
|
||||
apply(card, false);
|
||||
render();
|
||||
};
|
||||
const clear = document.createElement('button');
|
||||
clear.type = 'button';
|
||||
clear.className = 'link';
|
||||
clear.textContent = card.preset.colors.length ? 'use defaults' : 'pattern defaults';
|
||||
clear.disabled = !card.preset.colors.length;
|
||||
clear.onclick = () => {
|
||||
card.preset.colors = [];
|
||||
apply(card, false);
|
||||
render();
|
||||
};
|
||||
box.replaceChildren(...items, add, clear);
|
||||
};
|
||||
render();
|
||||
l.append(box);
|
||||
return l;
|
||||
}
|
||||
|
||||
function bgField(card) {
|
||||
const l = document.createElement('label');
|
||||
l.textContent = 'Background';
|
||||
const i = document.createElement('input');
|
||||
i.type = 'color';
|
||||
i.value = hex(card.preset.background || [0, 0, 0]);
|
||||
i.oninput = () => {
|
||||
card.preset.background = rgb(i.value);
|
||||
apply(card, false);
|
||||
};
|
||||
l.append(i);
|
||||
return l;
|
||||
}
|
||||
|
||||
function buildCard(mod, index) {
|
||||
mod._fx_init(state.leds);
|
||||
const name = mod.UTF8ToString(mod._fx_name(index));
|
||||
const ptr = mod._fx_defaults_json(index);
|
||||
const preset = JSON.parse(mod.UTF8ToString(ptr));
|
||||
mod._free(ptr);
|
||||
preset.n5 = preset.n5 ?? 0;
|
||||
|
||||
const el = document.createElement('section');
|
||||
el.className = 'card';
|
||||
el.innerHTML =
|
||||
'<div class="card-head"><span class="card-name"></span><span class="btns">' +
|
||||
'<button type="button" class="secondary" data-a="restart" title="Restart the pattern">↺</button>' +
|
||||
'<button type="button" class="secondary" data-a="edit" aria-expanded="false">Edit</button></span></div>' +
|
||||
'<canvas></canvas>';
|
||||
el.querySelector('.card-name').textContent = name;
|
||||
const card = {
|
||||
mod,
|
||||
index,
|
||||
name,
|
||||
preset,
|
||||
el,
|
||||
canvas: el.querySelector('canvas'),
|
||||
clock: 0,
|
||||
next: 0,
|
||||
framePtr: mod._malloc(LED_CAP * 3),
|
||||
last: null,
|
||||
};
|
||||
const form = document.createElement('form');
|
||||
form.hidden = true;
|
||||
form.onsubmit = (ev) => ev.preventDefault();
|
||||
form.append(
|
||||
colourList(card),
|
||||
bgField(card),
|
||||
numField(card, 'delay', 'Delay d (ms)', { min: 10, max: 10000 }),
|
||||
numField(card, 'brightness', 'Bright b', { min: 0, max: 255 }),
|
||||
numField(card, 'mode', 'Style n6', { min: 0 }),
|
||||
numField(card, 'n1', 'n1'),
|
||||
numField(card, 'n2', 'n2'),
|
||||
numField(card, 'n3', 'n3'),
|
||||
numField(card, 'n4', 'n4'),
|
||||
numField(card, 'n5', 'n5'),
|
||||
checkField(card, 'reverse', 'reverse', false),
|
||||
checkField(card, 'auto', 'auto a', true),
|
||||
checkField(card, 'beat_time', 'beat time', false),
|
||||
);
|
||||
el.append(form);
|
||||
el.querySelector('[data-a=edit]').onclick = (ev) => {
|
||||
form.hidden = !form.hidden;
|
||||
ev.currentTarget.setAttribute('aria-expanded', String(!form.hidden));
|
||||
ev.currentTarget.textContent = form.hidden ? 'Edit' : 'Close';
|
||||
};
|
||||
el.querySelector('[data-a=restart]').onclick = () => apply(card, true);
|
||||
apply(card, true);
|
||||
return card;
|
||||
}
|
||||
|
||||
function draw(card) {
|
||||
const mod = card.mod;
|
||||
const n = mod._sim_frame(card.framePtr, LED_CAP * 3);
|
||||
const px = mod.HEAPU8.subarray(card.framePtr, card.framePtr + n * 3);
|
||||
const c = card.canvas;
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
const w = Math.max(1, Math.round(c.clientWidth * dpr));
|
||||
const h = Math.max(1, Math.round(c.clientHeight * dpr));
|
||||
if (c.width !== w || c.height !== h) {
|
||||
c.width = w;
|
||||
c.height = h;
|
||||
}
|
||||
const ctx = c.getContext('2d');
|
||||
ctx.fillStyle = '#0b0c0f';
|
||||
ctx.fillRect(0, 0, w, h);
|
||||
if (!n) return;
|
||||
const pitch = w / n;
|
||||
const gap = pitch >= 3 ? 1 : 0;
|
||||
for (let i = 0; i < n; i += 1) {
|
||||
const r = px[i * 3];
|
||||
const g = px[i * 3 + 1];
|
||||
const b = px[i * 3 + 2];
|
||||
ctx.fillStyle = r | g | b ? `rgb(${r},${g},${b})` : '#1d1f24';
|
||||
ctx.fillRect(Math.floor(i * pitch), 2 * dpr, Math.max(1, Math.ceil(pitch) - gap), h - 4 * dpr);
|
||||
}
|
||||
}
|
||||
|
||||
let lastT = 0;
|
||||
function tick(t) {
|
||||
const dt = lastT ? Math.min(250, t - lastT) : 0;
|
||||
lastT = t;
|
||||
if (!state.paused) {
|
||||
for (const card of state.cards) {
|
||||
card.clock += dt * state.speed;
|
||||
let steps = 0;
|
||||
while (card.next <= card.clock && steps < MAX_STEPS) {
|
||||
card.mod._fx_step(card.next);
|
||||
card.next += FRAME_MS;
|
||||
steps += 1;
|
||||
}
|
||||
if (card.next <= card.clock) {
|
||||
card.next = Math.ceil(card.clock / FRAME_MS) * FRAME_MS; // fell behind: skip ahead
|
||||
}
|
||||
draw(card);
|
||||
}
|
||||
}
|
||||
requestAnimationFrame(tick);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
let wasmModule;
|
||||
try {
|
||||
wasmModule = await WebAssembly.compileStreaming(fetch('/sim/wasm/led_fx.wasm'));
|
||||
} catch (err) {
|
||||
banner(`Could not load the pattern engine (web/wasm/led_fx.wasm): ${err}. Build it with make sim-wasm, then rebuild the controller.`);
|
||||
return;
|
||||
}
|
||||
const first = await instantiate(wasmModule);
|
||||
const count = first._fx_count();
|
||||
$('g-count').textContent = `${count} patterns`;
|
||||
const grid = $('gallery');
|
||||
for (let i = 0; i < count; i += 1) {
|
||||
const mod = i === 0 ? first : await instantiate(wasmModule);
|
||||
const card = buildCard(mod, i);
|
||||
state.cards.push(card);
|
||||
grid.append(card.el);
|
||||
}
|
||||
$('g-leds').onchange = () => {
|
||||
const n = Math.max(1, Math.min(LED_CAP, Math.round(Number($('g-leds').value)) || 119));
|
||||
$('g-leds').value = n;
|
||||
state.leds = n;
|
||||
for (const card of state.cards) {
|
||||
card.mod._fx_init(n);
|
||||
apply(card, true);
|
||||
}
|
||||
};
|
||||
$('g-speed').onchange = () => {
|
||||
state.speed = Number($('g-speed').value) || 1;
|
||||
};
|
||||
$('g-pause').onclick = () => {
|
||||
state.paused = !state.paused;
|
||||
$('g-pause').textContent = state.paused ? 'Play' : 'Pause';
|
||||
};
|
||||
$('g-restart').onclick = () => state.cards.forEach((c) => apply(c, true));
|
||||
requestAnimationFrame(tick);
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -6,7 +6,7 @@
|
||||
<meta name="theme-color" content="#0e0f12">
|
||||
<title>LED Rig Simulator</title>
|
||||
<link rel="icon" href="data:,">
|
||||
<link rel="stylesheet" href="/web/styles.css">
|
||||
<link rel="stylesheet" href="/sim/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
@@ -15,11 +15,25 @@
|
||||
<span class="brand-name">led-simulator</span>
|
||||
</div>
|
||||
<div class="chips">
|
||||
<span class="chip" id="bridge-chip" title="Simulated Wi-Fi bridge">bridge</span>
|
||||
<span class="chip" id="bridge-chip" title="The rig's bridge: frames from the controller come in as from this MAC">bridge</span>
|
||||
<span class="chip" id="controller-chip">controller: –</span>
|
||||
<button type="button" id="add-bridge" class="secondary" hidden
|
||||
title="The controller sends its ESP-NOW frames only to the bridges in its settings">Add the browser bridge</button>
|
||||
<span class="chip" id="strips-chip">strips: –</span>
|
||||
</div>
|
||||
<div class="room-bar">
|
||||
<label class="field-inline">Room <select id="room-select" aria-label="Room"></select></label>
|
||||
<button type="button" id="edit-toggle" class="secondary">Edit room</button>
|
||||
<span id="edit-tools" class="edit-tools" hidden>
|
||||
<button type="button" id="room-settings" class="secondary">Size & strip types…</button>
|
||||
<button type="button" id="room-new" class="secondary">New room…</button>
|
||||
<button type="button" id="room-delete" class="secondary">Delete room</button>
|
||||
<span class="muted" id="save-state"></span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<a class="button secondary not-embedded" href="/">Controller</a>
|
||||
<a class="button secondary" href="/sim/gallery" target="_blank" rel="noopener">Pattern gallery</a>
|
||||
<button type="button" id="power-on-all">Power on all</button>
|
||||
<button type="button" id="power-cycle-all">Power cycle all</button>
|
||||
<button type="button" id="power-off-all" class="secondary">Power off all</button>
|
||||
@@ -30,6 +44,9 @@
|
||||
</header>
|
||||
|
||||
<div id="banner" class="banner" hidden></div>
|
||||
<div class="edit-hint" id="edit-hint">
|
||||
Click the floor to add a strip · drag a strip to move it (Alt: no snap) · drag its end circle to turn it (Shift: no snap) · Delete removes the selected strip
|
||||
</div>
|
||||
|
||||
<main class="stage">
|
||||
<div class="rig" id="rig">
|
||||
@@ -37,6 +54,11 @@
|
||||
</div>
|
||||
|
||||
<aside class="drawer" id="drawer" hidden aria-label="Strip details">
|
||||
<p class="drawer-empty" id="d-empty" hidden>
|
||||
Select a strip to edit it, or click the floor to add one. Changes are saved to
|
||||
<code>rooms/<room>.json</code> as you make them.
|
||||
</p>
|
||||
<div class="drawer-body" id="d-body">
|
||||
<div class="drawer-head">
|
||||
<div>
|
||||
<div class="drawer-title" id="d-name">sim-01</div>
|
||||
@@ -49,6 +71,16 @@
|
||||
<dt>Position</dt><dd id="d-pos">–</dd>
|
||||
<dt>Packets</dt><dd id="d-packets">–</dd>
|
||||
</dl>
|
||||
<p class="note" id="d-note" hidden></p>
|
||||
<form class="edit-form" id="d-edit" hidden onsubmit="return false">
|
||||
<label>Label <input id="e-label" maxlength="47"></label>
|
||||
<label>Strip type <select id="e-def"></select></label>
|
||||
<label>LEDs <input id="e-leds" type="number" min="1" max="512" step="1" title="Empty: the strip type's count"></label>
|
||||
<label>Pixel 0 x (m) <input id="e-x" type="number" step="0.05"></label>
|
||||
<label>Pixel 0 y (m) <input id="e-y" type="number" step="0.05"></label>
|
||||
<label>Heading (°) <input id="e-dir" type="number" step="15" title="Degrees clockwise from up: 90 runs right, -90 runs left"></label>
|
||||
<button type="button" id="d-delete" class="danger">Remove strip</button>
|
||||
</form>
|
||||
<div class="drawer-actions">
|
||||
<button type="button" id="d-on">Power on</button>
|
||||
<button type="button" id="d-reset">Reset</button>
|
||||
@@ -59,13 +91,51 @@
|
||||
<button type="button" class="link" id="d-clear">clear</button>
|
||||
</div>
|
||||
<pre class="log" id="d-log"></pre>
|
||||
</div>
|
||||
</aside>
|
||||
</main>
|
||||
|
||||
<footer class="hint" id="hint">Loading…</footer>
|
||||
|
||||
<script src="/web/ring.js"></script>
|
||||
<script src="/web/layout.js"></script>
|
||||
<script src="/web/app.js"></script>
|
||||
<dialog id="room-dialog" aria-labelledby="r-title">
|
||||
<h2 id="r-title">Room size and strip types</h2>
|
||||
<div class="dialog-row">
|
||||
<label>Width (m) <input id="r-width" type="number" min="0.5" max="200" step="0.1"></label>
|
||||
<label>Depth (m) <input id="r-depth" type="number" min="0.5" max="200" step="0.1"></label>
|
||||
</div>
|
||||
<table class="defs">
|
||||
<thead><tr><th>Type</th><th>LEDs</th><th>LEDs per metre</th><th></th><th></th></tr></thead>
|
||||
<tbody id="r-defs"></tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td><input id="r-def-name" placeholder="name, e.g. bar-60"></td>
|
||||
<td><input id="r-def-leds" type="number" min="1" max="512" step="1" value="60"></td>
|
||||
<td><input id="r-def-perm" type="number" min="1" max="1000" step="1" value="60"></td>
|
||||
<td colspan="2"><button type="button" id="r-add-def" class="secondary">Add type</button></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<div class="dialog-actions"><button type="button" id="r-close">Done</button></div>
|
||||
</dialog>
|
||||
|
||||
<dialog id="new-dialog" aria-labelledby="n-title">
|
||||
<form id="new-form">
|
||||
<h2 id="n-title">New room</h2>
|
||||
<label>Name <input id="n-name" required pattern="[A-Za-z0-9_\-]{1,40}" title="Letters, digits, - or _"></label>
|
||||
<div class="dialog-row">
|
||||
<label>Width (m) <input id="n-width" type="number" min="0.5" max="200" step="0.1" required></label>
|
||||
<label>Depth (m) <input id="n-depth" type="number" min="0.5" max="200" step="0.1" required></label>
|
||||
</div>
|
||||
<label class="check"><input type="checkbox" id="n-copy"> Copy the strips of the current room</label>
|
||||
<p class="error" id="n-error"></p>
|
||||
<div class="dialog-actions">
|
||||
<button type="button" id="n-cancel" class="secondary">Cancel</button>
|
||||
<button type="submit">Create and edit</button>
|
||||
</div>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<script src="/sim/layout.js"></script>
|
||||
<script src="/sim/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+62
-84
@@ -1,103 +1,81 @@
|
||||
/* Rig geometry for the canvas: strips along their rows, pixel 0 at the
|
||||
* strip's start end (next to the centre line for start: "center").
|
||||
* Strip placement (row, col, reversed) comes from the server (layout.py).
|
||||
/* Room geometry for the canvas: metres <-> canvas pixels, and where each strip's LEDs are.
|
||||
*
|
||||
* A room (rooms/<name>.json, see rooms.py) spans x -width/2..width/2 and y 0..depth, metres,
|
||||
* y up on screen. A fixture's x, y is pixel 0; the strip runs along `direction` (degrees clockwise
|
||||
* from +y) for leds x pitch_m metres. roomStrips() mirrors rooms.room_strips() on the server.
|
||||
*/
|
||||
(function (g) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @param {object} layout {rows, columns, leds_per_strip}
|
||||
* @param {Array} strips [{row, col, leds, reversed}]
|
||||
* @returns {object} {ledPitch, ledW, ledH, strips:[{x0, y, w, labelX, labelY, labelAlign}], centreLines}
|
||||
*/
|
||||
function computeGeometry(layout, strips, width, height, opts = {}) {
|
||||
const margin = opts.margin ?? 16;
|
||||
const colGap = opts.colGap ?? 32;
|
||||
const labelH = opts.labelH ?? 16;
|
||||
const rows = layout.rows;
|
||||
const cols = layout.columns;
|
||||
const n = layout.leds_per_strip;
|
||||
const usableW = Math.max(cols * n, width - 2 * margin - (cols - 1) * colGap);
|
||||
const colW = usableW / cols;
|
||||
const pitch = colW / n;
|
||||
const rowH = Math.max(labelH + 6, (height - 2 * margin) / rows);
|
||||
const ledH = Math.max(6, Math.min(rowH - labelH - 10, 18));
|
||||
const gap = pitch >= 3 ? 1 : 0;
|
||||
const ledW = Math.max(1, pitch - gap);
|
||||
function fixtureLeds(room, f) {
|
||||
return Number(f.leds) || room.definitions[f.def].leds;
|
||||
}
|
||||
|
||||
const out = strips.map((s) => {
|
||||
const x0 = margin + s.col * (colW + colGap);
|
||||
const yTop = margin + s.row * rowH;
|
||||
// strip sits just under its label; leftover row space goes below it
|
||||
const y = yTop + labelH + 4;
|
||||
function fixtureEnd(room, f) {
|
||||
const len = fixtureLeds(room, f) * room.definitions[f.def].pitch_m;
|
||||
const a = (f.direction * Math.PI) / 180;
|
||||
return [f.x + len * Math.sin(a), f.y + len * Math.cos(a)];
|
||||
}
|
||||
|
||||
/** One entry per fixture, in file order. */
|
||||
function roomStrips(room) {
|
||||
return Object.entries(room.fixtures).map(([id, f], i) => {
|
||||
const [x1, y1] = fixtureEnd(room, f);
|
||||
return {
|
||||
x0,
|
||||
y,
|
||||
w: colW,
|
||||
h: ledH,
|
||||
top: yTop,
|
||||
rowH,
|
||||
reversed: Boolean(s.reversed),
|
||||
labelX: s.reversed ? x0 + colW : x0,
|
||||
labelY: yTop + labelH / 2 + 2,
|
||||
labelAlign: s.reversed ? 'right' : 'left',
|
||||
index: i,
|
||||
n: i + 1,
|
||||
id,
|
||||
label: f.label,
|
||||
mac: f.mac,
|
||||
leds: fixtureLeds(room, f),
|
||||
x: f.x,
|
||||
y: f.y,
|
||||
x1,
|
||||
y1,
|
||||
direction: f.direction,
|
||||
};
|
||||
});
|
||||
const centreLines = [];
|
||||
for (let c = 1; c < cols; c += 1) {
|
||||
centreLines.push(margin + c * (colW + colGap) - colGap / 2);
|
||||
}
|
||||
return { ledPitch: pitch, ledW, ledH, strips: out, centreLines };
|
||||
}
|
||||
|
||||
/**
|
||||
* Geometry from each strip's rig place [x0, y0, x1, y1] (y up, centre 0, as the controller sends it),
|
||||
* fitted to the canvas with one scale. Used once every strip has a place.
|
||||
* @returns {object} {placed: true, ledH, strips: [{ax, ay, bx, by, ang, len, pitch, labelX, labelY}], centre}
|
||||
* Fit the room to a width x height canvas with one scale.
|
||||
* @returns {object} {scale, sx(x), sy(y), mx(px), my(py)} metres -> px and back
|
||||
*/
|
||||
function computePlaced(strips, width, height, opts = {}) {
|
||||
const margin = opts.margin ?? 28;
|
||||
const ledH = opts.ledH ?? 12;
|
||||
let lo = [Infinity, Infinity];
|
||||
let hi = [-Infinity, -Infinity];
|
||||
for (const s of strips) {
|
||||
const p = s.place;
|
||||
for (let k = 0; k < 4; k += 2) {
|
||||
lo = [Math.min(lo[0], p[k]), Math.min(lo[1], p[k + 1])];
|
||||
hi = [Math.max(hi[0], p[k]), Math.max(hi[1], p[k + 1])];
|
||||
}
|
||||
}
|
||||
const spanX = Math.max(hi[0] - lo[0], 1e-3);
|
||||
const spanY = Math.max(hi[1] - lo[1], 1e-3);
|
||||
const scale = Math.min((width - 2 * margin) / spanX, (height - 2 * margin) / spanY);
|
||||
const ox = width / 2 - ((lo[0] + hi[0]) / 2) * scale;
|
||||
const oy = height / 2 + ((lo[1] + hi[1]) / 2) * scale;
|
||||
const tx = (x) => ox + x * scale;
|
||||
const ty = (y) => oy - y * scale;
|
||||
const out = strips.map((s) => {
|
||||
const [x0, y0, x1, y1] = s.place;
|
||||
const ax = tx(x0);
|
||||
const ay = ty(y0);
|
||||
const bx = tx(x1);
|
||||
const by = ty(y1);
|
||||
function fit(room, width, height, margin = 28) {
|
||||
const scale = Math.max(
|
||||
1e-3,
|
||||
Math.min((width - 2 * margin) / room.width, (height - 2 * margin) / room.depth),
|
||||
);
|
||||
const ox = width / 2;
|
||||
const oy = height / 2 + (room.depth / 2) * scale;
|
||||
return {
|
||||
scale,
|
||||
sx: (x) => ox + x * scale,
|
||||
sy: (y) => oy - y * scale,
|
||||
mx: (px) => (px - ox) / scale,
|
||||
my: (py) => (oy - py) / scale,
|
||||
};
|
||||
}
|
||||
|
||||
/** Canvas geometry of each strip: pixel 0 at (ax, ay), the end at (bx, by). */
|
||||
function stripGeometry(view, strips) {
|
||||
return strips.map((s) => {
|
||||
const ax = view.sx(s.x);
|
||||
const ay = view.sy(s.y);
|
||||
const bx = view.sx(s.x1);
|
||||
const by = view.sy(s.y1);
|
||||
const len = Math.hypot(bx - ax, by - ay);
|
||||
const n = s.leds;
|
||||
return {
|
||||
ax, ay, bx, by, len,
|
||||
ang: Math.atan2(by - ay, bx - ax),
|
||||
pitch: len / n,
|
||||
labelX: (ax + bx) / 2,
|
||||
labelY: (ay + by) / 2 - ledH / 2 - 9,
|
||||
};
|
||||
return { ax, ay, bx, by, len, ang: Math.atan2(by - ay, bx - ax), pitch: len / s.leds };
|
||||
});
|
||||
return { placed: true, ledH, strips: out, centre: { x: tx(0), y: ty(0) } };
|
||||
}
|
||||
|
||||
/** x of pixel i of a strip (pixel 0 at the start end). */
|
||||
function pixelX(geo, sg, i, leds) {
|
||||
const pos = sg.reversed ? leds - 1 - i : i;
|
||||
return sg.x0 + pos * geo.ledPitch;
|
||||
/** Distance from point (x, y) to the segment of a strip, canvas px. */
|
||||
function distToStrip(sg, x, y) {
|
||||
const dx = sg.bx - sg.ax;
|
||||
const dy = sg.by - sg.ay;
|
||||
const t = Math.max(0, Math.min(1, ((x - sg.ax) * dx + (y - sg.ay) * dy) / (dx * dx + dy * dy || 1)));
|
||||
return Math.hypot(x - (sg.ax + t * dx), y - (sg.ay + t * dy));
|
||||
}
|
||||
|
||||
g.RigLayout = { computeGeometry, computePlaced, pixelX };
|
||||
g.RigLayout = { roomStrips, fit, stripGeometry, distToStrip, fixtureLeds };
|
||||
})(typeof self !== 'undefined' ? self : globalThis);
|
||||
@@ -1,93 +0,0 @@
|
||||
/* SharedArrayBuffer message ring: the page pushes received ESP-NOW frames,
|
||||
* the driver worker pops them while main.py runs (it never yields to the JS
|
||||
* event loop, so postMessage cannot reach it).
|
||||
*
|
||||
* Layout: Int32[4] header {head, tail, dropped, count} then `capacity` bytes.
|
||||
* Each message is a little-endian u16 length followed by the bytes.
|
||||
* One producer (page) and one consumer (worker).
|
||||
*
|
||||
* Loaded as a classic script by both the page and the worker.
|
||||
*/
|
||||
(function (g) {
|
||||
'use strict';
|
||||
const HEADER = 16;
|
||||
const HEAD = 0;
|
||||
const TAIL = 1;
|
||||
const DROPPED = 2;
|
||||
const COUNT = 3;
|
||||
|
||||
class SimRing {
|
||||
constructor(sab) {
|
||||
this.sab = sab;
|
||||
this.idx = new Int32Array(sab, 0, 4);
|
||||
this.cap = sab.byteLength - HEADER;
|
||||
this.data = new Uint8Array(sab, HEADER, this.cap);
|
||||
}
|
||||
|
||||
static create(capacity = 65536) {
|
||||
return new SimRing(new SharedArrayBuffer(HEADER + capacity));
|
||||
}
|
||||
|
||||
used() {
|
||||
const h = Atomics.load(this.idx, HEAD);
|
||||
const t = Atomics.load(this.idx, TAIL);
|
||||
return (h - t + this.cap) % this.cap;
|
||||
}
|
||||
|
||||
count() {
|
||||
return Atomics.load(this.idx, COUNT);
|
||||
}
|
||||
|
||||
dropped() {
|
||||
return Atomics.load(this.idx, DROPPED);
|
||||
}
|
||||
|
||||
/** Producer: false (and counted as dropped) when the ring is full. */
|
||||
push(bytes) {
|
||||
const n = bytes.length;
|
||||
if (n > 0xffff || n + 2 >= this.cap - this.used()) {
|
||||
Atomics.add(this.idx, DROPPED, 1);
|
||||
return false;
|
||||
}
|
||||
const cap = this.cap;
|
||||
const data = this.data;
|
||||
let h = Atomics.load(this.idx, HEAD);
|
||||
data[h] = n & 0xff;
|
||||
h = (h + 1) % cap;
|
||||
data[h] = n >> 8;
|
||||
h = (h + 1) % cap;
|
||||
for (let i = 0; i < n; i += 1) {
|
||||
data[h] = bytes[i];
|
||||
h = (h + 1) % cap;
|
||||
}
|
||||
Atomics.store(this.idx, HEAD, h);
|
||||
Atomics.add(this.idx, COUNT, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Consumer: next message as a Uint8Array, or undefined when empty. */
|
||||
pop() {
|
||||
let t = Atomics.load(this.idx, TAIL);
|
||||
if (t === Atomics.load(this.idx, HEAD)) {
|
||||
return undefined;
|
||||
}
|
||||
const cap = this.cap;
|
||||
const data = this.data;
|
||||
const lo = data[t];
|
||||
t = (t + 1) % cap;
|
||||
const hi = data[t];
|
||||
t = (t + 1) % cap;
|
||||
const n = lo | (hi << 8);
|
||||
const out = new Uint8Array(n);
|
||||
for (let i = 0; i < n; i += 1) {
|
||||
out[i] = data[t];
|
||||
t = (t + 1) % cap;
|
||||
}
|
||||
Atomics.store(this.idx, TAIL, t);
|
||||
Atomics.sub(this.idx, COUNT, 1);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
g.SimRing = SimRing;
|
||||
})(typeof self !== 'undefined' ? self : globalThis);
|
||||
@@ -167,3 +167,87 @@ button.link {
|
||||
.drawer { width: auto; border-left: none; border-top: 1px solid var(--line); max-height: 50vh; }
|
||||
.actions { margin-left: 0; }
|
||||
}
|
||||
|
||||
/* ---- rooms and the editor ---- */
|
||||
.room-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
||||
.edit-tools { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
||||
.edit-tools[hidden] { display: none; }
|
||||
.field-inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
|
||||
.muted { color: var(--muted); }
|
||||
select, input {
|
||||
font: inherit;
|
||||
color: var(--text);
|
||||
background: var(--panel-2);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
padding: 4px 7px;
|
||||
min-width: 0;
|
||||
}
|
||||
input:focus, select:focus { outline: 2px solid #34465f; outline-offset: 0; }
|
||||
a.button {
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
color: var(--text);
|
||||
border: 1px solid var(--line);
|
||||
background: var(--panel-2);
|
||||
border-radius: 6px;
|
||||
padding: 5px 11px;
|
||||
}
|
||||
a.button:hover { background: #232730; }
|
||||
button.danger { background: #3a1d22; border-color: #5c2a31; color: #ffd6d6; }
|
||||
button.danger:hover:not(:disabled) { background: #4a242b; }
|
||||
|
||||
.edit-hint {
|
||||
display: none;
|
||||
padding: 6px 16px;
|
||||
background: #1d2a3a;
|
||||
color: #d6e8ff;
|
||||
border-bottom: 1px solid #2a405c;
|
||||
}
|
||||
body.editing .edit-hint { display: block; }
|
||||
|
||||
.note { margin: 0; color: var(--warn); }
|
||||
.edit-form {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 8px 10px;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
background: var(--panel-2);
|
||||
}
|
||||
.edit-form[hidden] { display: none; }
|
||||
.edit-form label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); }
|
||||
.edit-form label:first-child, .edit-form label:nth-child(2) { grid-column: 1 / -1; }
|
||||
.edit-form button { grid-column: 1 / -1; justify-self: start; }
|
||||
|
||||
dialog {
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
padding: 16px 18px;
|
||||
width: min(560px, calc(100vw - 32px));
|
||||
}
|
||||
dialog::backdrop { background: rgba(0, 0, 0, .55); }
|
||||
dialog h2 { margin: 0 0 12px; font-size: 15px; }
|
||||
dialog form, dialog { display: flex; flex-direction: column; gap: 10px; }
|
||||
dialog:not([open]) { display: none; }
|
||||
dialog label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); }
|
||||
dialog label.check { flex-direction: row; align-items: center; gap: 6px; }
|
||||
.dialog-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.dialog-actions { display: flex; justify-content: flex-end; gap: 6px; }
|
||||
.error { color: var(--bad); margin: 0; min-height: 1em; }
|
||||
table.defs { width: 100%; border-collapse: collapse; }
|
||||
table.defs th { text-align: left; color: var(--muted); font-weight: normal; padding: 4px; }
|
||||
table.defs td { padding: 4px; }
|
||||
table.defs input { width: 100%; }
|
||||
|
||||
.drawer-body { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; }
|
||||
.drawer-body[hidden] { display: none; }
|
||||
.drawer-empty { margin: 0; color: var(--muted); }
|
||||
.drawer-empty[hidden] { display: none; }
|
||||
.drawer-empty code { color: var(--text); }
|
||||
|
||||
/* In the controller's split view (an iframe beside it) */
|
||||
body.embedded .not-embedded { display: none; }
|
||||
Reference in new issue
Block a user