mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-surfaces.git
synced 2026-11-29 07:15:08 +00:00
597 lines
35 KiB
PHP
597 lines
35 KiB
PHP
{{-- ============================================================================================
|
||
PL0XI0N surfaces 🖥️ — LE DÉMONSTRATEUR XUI (directive RS-7 : « le xer doit être un TYPE d'UI
|
||
complètement différent, pas un thème »). Choisis n'importe quel ploxion → il est rendu
|
||
SIMULTANÉMENT sur 5 machines simulées, dessinées au canvas :
|
||
(a) OLED 128×64 1-bit (pixels durs ×3, police bitmap 5×7 dessinée à la main)
|
||
(b) montre ronde 240px (clip circulaire, UNE carte p1, aiguille décorative)
|
||
(c) e-ink 296×128 (papier, 4 gris, dithering Bayer 2×2 rect-based)
|
||
(d) terminal phosphore 40×12 caractères
|
||
(e) TV 10-pieds (grosses cartes, focus d-pad ← ↑ ↓ → + OK)
|
||
SOURCE : window.jOSXui.get(id) || jOSXui.fallback(id) si le bion existe, sinon
|
||
window.jOSApps[id].describe() (contrat XUI v0), sinon une DÉMO générée (badge DÉMO).
|
||
COUPE : jOSXui.render(xui, caps) si dispo, sinon tri par p + slice local — la montre ne
|
||
montre que p1, le desktop montre tout : la révélation progressive EST le renderer.
|
||
ACTIONS VIVANTES : taper une action sur une surface simulée émet le VRAI act sur le bus
|
||
jOSPorts (ex. stopper le rover xerbot depuis l'OLED) — jamais de callback : un ESP32
|
||
déclencherait exactement pareil. XUIC (version micro-écrans) affichée en pied.
|
||
100% client-side, zéro CDN, unmount propre. --}}
|
||
<style>
|
||
.px-surf{display:flex;flex-direction:column;height:100%;overflow:auto;background:var(--xr-bg,#0a0d16);color:var(--xr-fg,#e8ecf8);font-family:var(--xr-font-ui,ui-sans-serif,system-ui)}
|
||
.px-surf .hd{display:flex;align-items:center;gap:8px;padding:11px 13px;border-bottom:1px solid var(--xr-line,#1b2540);font-weight:700;flex-wrap:wrap}
|
||
.px-surf .hd select{background:var(--xr-card,#111a30);color:var(--xr-fg,#e8ecf8);border:1px solid var(--xr-line,#1b2540);border-radius:9px;padding:7px 10px;font-size:.9rem;max-width:52vw}
|
||
.px-surf .hd .badge{font-size:.62rem;font-weight:800;letter-spacing:.08em;padding:3px 8px;border-radius:99px;border:1px solid var(--xr-line,#1b2540)}
|
||
.px-surf .hd .badge.live{color:#4ade80;border-color:#4ade8055}
|
||
.px-surf .hd .badge.demo{color:var(--xr-muted,#7f93c8)}
|
||
.px-surf .bandeau{padding:9px 13px;font-size:.78rem;color:var(--xr-muted,#7f93c8);border-bottom:1px solid var(--xr-line,#1b2540);line-height:1.45}
|
||
.px-surf .bandeau b{color:var(--xr-accent,#3fe0d0)}
|
||
.px-surf .bus{padding:4px 13px;font-size:.68rem;font-family:ui-monospace,monospace;color:var(--xr-accent,#3fe0d0);min-height:1.3em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||
.px-surf .grid{flex:1;display:grid;grid-template-columns:1fr;gap:16px;padding:13px;align-content:start}
|
||
@media (min-width:920px){.px-surf .grid{grid-template-columns:repeat(2,1fr)}}
|
||
@media (min-width:1500px){.px-surf .grid{grid-template-columns:repeat(3,1fr)}}
|
||
.px-surf .dev{display:flex;flex-direction:column;gap:8px;min-width:0}
|
||
.px-surf .dev .cap{font-size:.7rem;color:var(--xr-muted,#7f93c8);display:flex;gap:6px;align-items:baseline}
|
||
.px-surf .dev .cap b{color:var(--xr-fg,#e8ecf8);font-size:.78rem}
|
||
.px-surf .dev .cap .p{margin-left:auto;color:var(--xr-accent,#3fe0d0);font-family:ui-monospace,monospace}
|
||
.px-surf canvas{display:block;max-width:100%;height:auto;cursor:pointer}
|
||
.px-surf .fr-oled{background:#101318;border:1px solid #262b33;border-radius:10px;padding:14px;box-shadow:inset 0 0 22px rgba(0,0,0,.8);align-self:start}
|
||
.px-surf .fr-oled canvas{image-rendering:pixelated}
|
||
.px-surf .fr-watch{align-self:center;background:radial-gradient(circle at 30% 25%,#2b313d,#0c0e13 70%);border-radius:50%;padding:12px;border:1px solid #333a46;box-shadow:0 6px 24px rgba(0,0,0,.5)}
|
||
.px-surf .fr-watch canvas{border-radius:50%;width:200px;height:200px}
|
||
.px-surf .fr-eink{background:#f2efe6;border:8px solid #d8d4c6;border-radius:6px;padding:8px;align-self:start}
|
||
.px-surf .fr-eink canvas{image-rendering:pixelated}
|
||
.px-surf .fr-term{background:#050b06;border:1px solid #14331a;border-radius:8px;padding:10px;box-shadow:inset 0 0 30px rgba(20,255,90,.06)}
|
||
.px-surf .fr-tv{background:#000;border:6px solid #14161c;border-radius:10px;padding:4px}
|
||
.px-surf .dpad{display:flex;gap:6px;justify-content:center;margin-top:4px}
|
||
.px-surf .dpad button{width:44px;height:38px;border:1px solid var(--xr-line,#1b2540);border-radius:9px;background:var(--xr-card,#111a30);color:var(--xr-fg,#e8ecf8);font-size:1rem;cursor:pointer}
|
||
.px-surf .dpad button:active{border-color:var(--xr-accent,#3fe0d0)}
|
||
.px-surf .xuic{padding:9px 13px;border-top:1px solid var(--xr-line,#1b2540);font-family:ui-monospace,monospace;font-size:.64rem;color:var(--xr-muted,#7f93c8);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;cursor:pointer}
|
||
.px-surf .xuic b{color:var(--xr-accent,#3fe0d0)}
|
||
</style>
|
||
<script>
|
||
(function () {
|
||
'use strict';
|
||
|
||
// ===== police bitmap 5×7 dessinée à la main (colonnes, bit 0 = ligne du haut) =============
|
||
// Le strict nécessaire pour un micro-écran : A-Z 0-9 + ponctuation. Un char inconnu = blanc.
|
||
var FONT = {
|
||
' ': [0,0,0,0,0], '!': [0,0,95,0,0], '%': [35,19,8,100,98], '(': [0,28,34,65,0], ')': [0,65,34,28,0],
|
||
'+': [8,8,62,8,8], ',': [0,80,48,0,0], '-': [8,8,8,8,8], '.': [0,96,96,0,0], '/': [32,16,8,4,2],
|
||
'0': [62,81,73,69,62], '1': [0,66,127,64,0], '2': [66,97,81,73,70], '3': [33,65,69,75,49],
|
||
'4': [24,20,18,127,16], '5': [39,69,69,69,57], '6': [60,74,73,73,48], '7': [1,113,9,5,3],
|
||
'8': [54,73,73,73,54], '9': [6,73,73,41,30], ':': [0,54,54,0,0], '<': [8,20,34,65,0],
|
||
'=': [20,20,20,20,20], '>': [0,65,34,20,8], '?': [2,1,81,9,6], '[': [0,127,65,65,0], ']': [0,65,65,127,0],
|
||
'A': [126,17,17,17,126], 'B': [127,73,73,73,54], 'C': [62,65,65,65,34], 'D': [127,65,65,34,28],
|
||
'E': [127,73,73,73,65], 'F': [127,9,9,9,1], 'G': [62,65,73,73,122], 'H': [127,8,8,8,127],
|
||
'I': [0,65,127,65,0], 'J': [32,64,65,63,1], 'K': [127,8,20,34,65], 'L': [127,64,64,64,64],
|
||
'M': [127,2,12,2,127], 'N': [127,4,8,16,127], 'O': [62,65,65,65,62], 'P': [127,9,9,9,6],
|
||
'Q': [62,65,81,33,94], 'R': [127,9,25,41,70], 'S': [70,73,73,73,49], 'T': [1,1,127,1,1],
|
||
'U': [63,64,64,64,63], 'V': [31,32,64,32,31], 'W': [63,64,56,64,63], 'X': [99,20,8,20,99],
|
||
'Y': [7,8,112,8,7], 'Z': [97,81,73,69,67], '°': [0,7,5,7,0]
|
||
};
|
||
|
||
// ===== capacités de chaque surface (la clé de voûte : mêmes données, coupes différentes) ===
|
||
var CAPS = {
|
||
oled: { maxP: 2, maxItems: 5, chars: 21 },
|
||
watch: { maxP: 1, maxItems: 1, chars: 12 },
|
||
eink: { maxP: 3, maxItems: 4, chars: 24 },
|
||
term: { maxP: 4, maxItems: 8, chars: 38 },
|
||
tv: { maxP: 5, maxItems: 12, chars: 30 }
|
||
};
|
||
|
||
// ===== helpers ============================================================================
|
||
function esc(s) { return window.jOSb.esc(s); }
|
||
function toast(m){ if (window.jOSb && window.jOSb.toast) window.jOSb.toast(m); }
|
||
function deacc(s){ try { return String(s == null ? '' : s).normalize('NFD').replace(/[\u0300-\u036f]/g, ''); } catch (e) { return String(s == null ? '' : s); } }
|
||
function trunc(s, n){ s = String(s == null ? '' : s); return s.length > n ? s.slice(0, Math.max(0, n - 1)) + '…' : s; }
|
||
function truncA(s, n){ s = deacc(s); return s.length > n ? s.slice(0, Math.max(0, n - 1)) + '.' : s; } // ascii (pas de …)
|
||
function valStr(it){ var v = it.value; if (v == null) return ''; return String(v) + (it.unit ? String(it.unit) : ''); }
|
||
function num(v, d){ var n = Number(v); return isFinite(n) ? n : d; }
|
||
|
||
// ===== l'action passe par le BUS, jamais par un callback (un ESP32 fait pareil) ============
|
||
function emitAct(act) {
|
||
if (!act || !act.port) return;
|
||
var topic = String(act.port).replace(/\//g, '.'); // style MQTT xerbot/<dev>/<port> accepté
|
||
var rest = topic.indexOf('ploxion.') === 0 ? topic.slice(8) : topic;
|
||
var i = rest.indexOf('.');
|
||
var id = i < 0 ? rest : rest.slice(0, i);
|
||
var port = i < 0 ? '' : rest.slice(i + 1);
|
||
if (window.jOSPorts && window.jOSPorts.emit) window.jOSPorts.emit(id, port, act.payload || {});
|
||
toast('⚡ ' + (topic.indexOf('ploxion.') === 0 ? topic : 'ploxion.' + topic));
|
||
}
|
||
|
||
// ===== source XUI : jOSXui → describe() → démo générée (badge honnête) =====================
|
||
function demoXui(m) {
|
||
var t = Date.now() / 1000;
|
||
var items = [
|
||
{ p: 1, kind: 'stat', label: 'etat', value: 'OK' },
|
||
{ p: 2, kind: 'gauge', label: 'charge', value: Math.round(55 + 35 * Math.sin(t / 9)), unit: '%', min: 0, max: 100 },
|
||
{ p: 3, kind: 'list', label: 'derniers', items: [ { label: 'tsoin', value: '12:04' }, { label: 'bus', value: 'ack' }, { label: 'sync', value: 'ok' } ] },
|
||
{ p: 4, kind: 'text', label: 'note', value: trunc(m.description || 'ploxion sans describe() — XUI de démo', 90) },
|
||
{ p: 5, kind: 'stat', label: 'id', value: m.id }
|
||
];
|
||
if (m.id === 'xerbot') {
|
||
// LA démo : stopper le vrai rover depuis l'OLED simulé (contrat xerbot v1 : <dev>.cmd)
|
||
items.splice(1, 0, { p: 1, kind: 'action', label: 'STOP', act: { port: 'ploxion.xerbot.xerbot.cmd', payload: { cmd: 'stop', src: 'surfaces' } } });
|
||
} else {
|
||
items.splice(2, 0, { p: 2, kind: 'action', label: 'ping', act: { port: 'ploxion.' + m.id + '.ping', payload: { src: 'surfaces' } } });
|
||
}
|
||
return { v: 1, id: m.id, title: m.name || m.id, icon: m.icon || '▣', items: items };
|
||
}
|
||
function xuiOf(m) {
|
||
var x = null, X = window.jOSXui;
|
||
if (X) { try { x = (X.get && X.get(m.id)) || (X.fallback && X.fallback(m.id)) || null; } catch (e) { x = null; } }
|
||
if (!x) {
|
||
var app = window.jOSApps && window.jOSApps[m.id];
|
||
if (app && typeof app.describe === 'function') { try { x = app.describe(); } catch (e) { x = null; } }
|
||
}
|
||
var live = !!(x && x.items && x.items.length);
|
||
if (!live) x = demoXui(m);
|
||
if (!x.items) x.items = [];
|
||
return { xui: x, live: live };
|
||
}
|
||
|
||
// ===== la COUPE par priorité : trier par p, couper où la surface s'arrête ==================
|
||
function cut(xui, caps) {
|
||
if (window.jOSXui && typeof window.jOSXui.render === 'function') {
|
||
try {
|
||
var r = window.jOSXui.render(xui, caps);
|
||
if (r && r.items) return r.items;
|
||
if (Array.isArray(r)) return r;
|
||
} catch (e) {}
|
||
}
|
||
var its = (xui.items || []).slice();
|
||
its.sort(function (a, b) { return num(a.p, 5) - num(b.p, 5); });
|
||
return its.filter(function (it) { return num(it.p, 5) <= caps.maxP; }).slice(0, caps.maxItems);
|
||
}
|
||
|
||
// ===== liste des ploxions (comme le lanceur : window.__PLOXIONS__, sinon jOSApps) ==========
|
||
function listPloxions() {
|
||
var out = [], seen = {};
|
||
(window.__PLOXIONS__ || []).forEach(function (p) { if (p && p.id && !seen[p.id]) { seen[p.id] = 1; out.push({ id: p.id, name: p.name || p.id, icon: p.icon || '▣', description: p.description || '' }); } });
|
||
Object.keys(window.jOSApps || {}).forEach(function (id) {
|
||
if (seen[id]) return; seen[id] = 1;
|
||
var mf = (window.jOSApps[id] && window.jOSApps[id].manifest) || {};
|
||
out.push({ id: id, name: mf.name || id, icon: mf.icon || '▣', description: '' });
|
||
});
|
||
if (!seen['xerbot']) out.unshift({ id: 'xerbot', name: 'Xerbot', icon: '🤖', description: 'le rover du terrain (contrat bus v1)' });
|
||
return out;
|
||
}
|
||
|
||
// ===== XUIC : la version compacte micro-écrans (arrays — parse trivial sur ESP32) ==========
|
||
function xuic(xui) {
|
||
return JSON.stringify([xui.id, xui.title, (xui.items || []).map(function (it) {
|
||
return [num(it.p, 5), it.kind || 'stat', String(it.label || ''), it.value == null ? '' : it.value, it.unit || ''];
|
||
})]);
|
||
}
|
||
|
||
// ============================================================================================
|
||
// (a) OLED 128×64 · 1-bit · framebuffer + blit pixels durs ×3
|
||
// ============================================================================================
|
||
var OW = 128, OH = 64, OS = 3;
|
||
function FB() { this.b = new Uint8Array(OW * OH); }
|
||
FB.prototype.px = function (x, y, c) { if (x >= 0 && x < OW && y >= 0 && y < OH) this.b[y * OW + x] = c ? 1 : 0; };
|
||
FB.prototype.fill = function (x, y, w, h, c) { for (var j = 0; j < h; j++) for (var i = 0; i < w; i++) this.px(x + i, y + j, c); };
|
||
FB.prototype.text = function (x, y, s, c) {
|
||
s = deacc(s).toUpperCase();
|
||
for (var k = 0; k < s.length; k++) {
|
||
var g = FONT[s[k]];
|
||
if (g) for (var col = 0; col < 5; col++) { var bits = g[col]; for (var row = 0; row < 7; row++) if ((bits >> row) & 1) this.px(x + col, y + row, c); }
|
||
x += 6;
|
||
if (x >= OW) break;
|
||
}
|
||
return x;
|
||
};
|
||
FB.prototype.blit = function (g2d) {
|
||
g2d.fillStyle = '#04070c'; g2d.fillRect(0, 0, OW * OS, OH * OS);
|
||
g2d.fillStyle = '#e8f4ff';
|
||
for (var y = 0; y < OH; y++) for (var x = 0; x < OW; x++)
|
||
if (this.b[y * OW + x]) g2d.fillRect(x * OS, y * OS, OS - 1, OS - 1); // -1 = pixels durs séparés
|
||
};
|
||
function drawOled(g2d, xui, items, hits) {
|
||
var fb = new FB();
|
||
fb.fill(0, 0, OW, 9, 1); // barre de titre inversée
|
||
fb.text(2, 1, truncA(xui.title, 20), 0);
|
||
var y = 12;
|
||
items.forEach(function (it) {
|
||
if (y > OH - 8) return;
|
||
if (it.kind === 'action') {
|
||
var lab = '[' + truncA(it.label, 12) + ']';
|
||
var w = lab.length * 6 + 3;
|
||
fb.fill(1, y - 1, w, 9, 1);
|
||
fb.text(3, y, lab, 0);
|
||
hits.push({ x: 0, y: (y - 1) * OS, w: (w + 2) * OS, h: 9 * OS, act: it.act });
|
||
y += 10;
|
||
} else if (it.kind === 'gauge') {
|
||
var v = num(it.value, 0), mn = num(it.min, 0), mx = num(it.max, 100);
|
||
var ratio = mx > mn ? Math.max(0, Math.min(1, (v - mn) / (mx - mn))) : 0;
|
||
fb.text(1, y, truncA(it.label, 7), 1);
|
||
var bx = 46, bw = OW - bx - 26;
|
||
fb.fill(bx, y + 1, bw, 5, 0); fb.px(bx, y + 1, 1); // cadre fin
|
||
for (var i = 0; i < bw; i++) { fb.px(bx + i, y + 1, 1); fb.px(bx + i, y + 5, 1); }
|
||
fb.fill(bx + 1, y + 2, Math.round((bw - 2) * ratio), 3, 1);
|
||
var vs = truncA(valStr(it), 4);
|
||
fb.text(OW - vs.length * 6 - 1, y, vs, 1);
|
||
y += 9;
|
||
} else if (it.kind === 'list') {
|
||
fb.text(1, y, truncA(it.label, 12) + ' (' + ((it.items || []).length) + ')', 1);
|
||
y += 9;
|
||
} else { // stat | text
|
||
fb.text(1, y, truncA(it.label, 10), 1);
|
||
var s = truncA(valStr(it), it.kind === 'text' ? 21 : 10);
|
||
if (it.kind === 'text') { y += 9; if (y <= OH - 8) { fb.text(1, y, s, 1); y += 9; } }
|
||
else { fb.text(OW - s.length * 6 - 1, y, s, 1); y += 9; }
|
||
}
|
||
});
|
||
fb.blit(g2d);
|
||
}
|
||
|
||
// ============================================================================================
|
||
// (b) montre ronde 240 — UNE carte p1, aiguille de molette décorative
|
||
// ============================================================================================
|
||
function drawWatch(g2d, xui, items, hits) {
|
||
var R = 120, cx = R, cy = R;
|
||
g2d.clearRect(0, 0, 240, 240);
|
||
g2d.save();
|
||
g2d.beginPath(); g2d.arc(cx, cy, R, 0, Math.PI * 2); g2d.clip();
|
||
g2d.fillStyle = '#05070d'; g2d.fillRect(0, 0, 240, 240);
|
||
// index des heures (décoratif)
|
||
g2d.strokeStyle = 'rgba(127,147,200,.35)'; g2d.lineWidth = 2;
|
||
for (var i = 0; i < 12; i++) {
|
||
var a = i * Math.PI / 6;
|
||
g2d.beginPath();
|
||
g2d.moveTo(cx + Math.cos(a) * (R - 4), cy + Math.sin(a) * (R - 4));
|
||
g2d.lineTo(cx + Math.cos(a) * (R - 10), cy + Math.sin(a) * (R - 10));
|
||
g2d.stroke();
|
||
}
|
||
var it = items[0];
|
||
g2d.textAlign = 'center';
|
||
g2d.fillStyle = '#7f93c8'; g2d.font = '600 13px system-ui,sans-serif';
|
||
g2d.fillText(trunc(xui.title, CAPS.watch.chars), cx, 46);
|
||
if (it) {
|
||
if (it.kind === 'gauge') {
|
||
var v = num(it.value, 0), mn = num(it.min, 0), mx = num(it.max, 100);
|
||
var ratio = mx > mn ? Math.max(0, Math.min(1, (v - mn) / (mx - mn))) : 0;
|
||
g2d.strokeStyle = 'rgba(63,224,208,.18)'; g2d.lineWidth = 9;
|
||
g2d.beginPath(); g2d.arc(cx, cy, 84, -Math.PI / 2, Math.PI * 1.5); g2d.stroke();
|
||
g2d.strokeStyle = '#3fe0d0';
|
||
g2d.beginPath(); g2d.arc(cx, cy, 84, -Math.PI / 2, -Math.PI / 2 + ratio * Math.PI * 2); g2d.stroke();
|
||
}
|
||
if (it.kind === 'action') {
|
||
g2d.fillStyle = '#3fe0d0';
|
||
g2d.beginPath(); g2d.arc(cx, cy + 8, 52, 0, Math.PI * 2); g2d.fill();
|
||
g2d.fillStyle = '#04252b'; g2d.font = '800 20px system-ui,sans-serif';
|
||
g2d.fillText(trunc(deacc(it.label).toUpperCase(), 8), cx, cy + 15);
|
||
hits.push({ x: cx - 52, y: cy - 44, w: 104, h: 104, act: it.act });
|
||
} else {
|
||
var main = it.kind === 'list' ? String((it.items || []).length) : String(it.value == null ? '—' : it.value);
|
||
g2d.fillStyle = '#e8ecf8'; g2d.font = '800 ' + (main.length > 6 ? 30 : 44) + 'px system-ui,sans-serif';
|
||
g2d.fillText(trunc(main, CAPS.watch.chars), cx, cy + 20);
|
||
if (it.unit) { g2d.fillStyle = '#3fe0d0'; g2d.font = '700 15px system-ui,sans-serif'; g2d.fillText(String(it.unit), cx, cy + 42); }
|
||
g2d.fillStyle = '#7f93c8'; g2d.font = '600 13px system-ui,sans-serif';
|
||
g2d.fillText(trunc(it.label, CAPS.watch.chars), cx, cy + 66);
|
||
}
|
||
} else {
|
||
g2d.fillStyle = '#7f93c8'; g2d.font = '600 14px system-ui,sans-serif';
|
||
g2d.fillText('rien en p1', cx, cy + 8);
|
||
}
|
||
// aiguille de molette décorative (tourne avec les secondes)
|
||
var sa = (Date.now() / 1000 % 60) / 60 * Math.PI * 2 - Math.PI / 2;
|
||
g2d.fillStyle = '#3fe0d0';
|
||
g2d.beginPath(); g2d.arc(cx + Math.cos(sa) * (R - 7), cy + Math.sin(sa) * (R - 7), 3.4, 0, Math.PI * 2); g2d.fill();
|
||
g2d.restore();
|
||
g2d.strokeStyle = 'rgba(63,224,208,.5)'; g2d.lineWidth = 2;
|
||
g2d.beginPath(); g2d.arc(cx, cy, R - 1, 0, Math.PI * 2); g2d.stroke();
|
||
}
|
||
|
||
// ============================================================================================
|
||
// (c) e-ink 296×128 — papier, 4 niveaux de gris, dithering Bayer 2×2 (rects, pas d'ImageData)
|
||
// ============================================================================================
|
||
var EW = 296, EH = 128, ES = 2;
|
||
var EGRAY = ['#eae6da', '#b8b4a8', '#6f6c63', '#26251f']; // 0 = papier … 3 = encre
|
||
function ePix(g2d, x, y, lvl) { g2d.fillStyle = EGRAY[lvl]; g2d.fillRect(x * ES, y * ES, ES, ES); }
|
||
function eFill(g2d, x, y, w, h, lvl) { g2d.fillStyle = EGRAY[lvl]; g2d.fillRect(x * ES, y * ES, w * ES, h * ES); }
|
||
function eDither(g2d, x, y, w, h, a, b) { // Bayer 2×2 : mélange deux gris voisins
|
||
for (var j = 0; j < h; j++) for (var i = 0; i < w; i++) ePix(g2d, x + i, y + j, ((i + j) % 2) ? a : b);
|
||
}
|
||
function eText(g2d, x, y, s, lvl) {
|
||
s = deacc(s).toUpperCase();
|
||
for (var k = 0; k < s.length; k++) {
|
||
var g = FONT[s[k]];
|
||
if (g) for (var col = 0; col < 5; col++) { var bits = g[col]; for (var row = 0; row < 7; row++) if ((bits >> row) & 1) ePix(g2d, x + col, y + row, lvl); }
|
||
x += 6;
|
||
if (x >= EW) break;
|
||
}
|
||
return x;
|
||
}
|
||
function drawEink(g2d, xui, items, hits) {
|
||
eFill(g2d, 0, 0, EW, EH, 0);
|
||
eDither(g2d, 0, 0, EW, 13, 0, 1); // bandeau tramé
|
||
eText(g2d, 3, 3, truncA(xui.title, 24), 3);
|
||
eFill(g2d, 0, 13, EW, 1, 2);
|
||
var y = 19;
|
||
items.forEach(function (it) {
|
||
if (y > EH - 10) return;
|
||
if (it.kind === 'action') {
|
||
var lab = truncA(it.label, 14);
|
||
var w = lab.length * 6 + 10;
|
||
eFill(g2d, 3, y - 2, w, 12, 3);
|
||
eText(g2d, 8, y + 1, lab, 0);
|
||
hits.push({ x: 3 * ES, y: (y - 2) * ES, w: w * ES, h: 12 * ES, act: it.act });
|
||
y += 16;
|
||
} else if (it.kind === 'gauge') {
|
||
var v = num(it.value, 0), mn = num(it.min, 0), mx = num(it.max, 100);
|
||
var ratio = mx > mn ? Math.max(0, Math.min(1, (v - mn) / (mx - mn))) : 0;
|
||
eText(g2d, 3, y, truncA(it.label, 10), 3);
|
||
var bx = 70, bw = EW - bx - 40;
|
||
eFill(g2d, bx, y, bw, 8, 1);
|
||
eDither(g2d, bx, y, Math.round(bw * ratio), 8, 2, 3); // remplissage tramé
|
||
var vs = truncA(valStr(it), 5);
|
||
eText(g2d, EW - vs.length * 6 - 3, y, vs, 3);
|
||
y += 14;
|
||
} else if (it.kind === 'list') {
|
||
eText(g2d, 3, y, truncA(it.label, 12) + ':', 3);
|
||
var lx = 3;
|
||
y += 10;
|
||
(it.items || []).slice(0, 3).forEach(function (li) {
|
||
if (lx > EW - 40) return;
|
||
lx = eText(g2d, lx, y, '·' + truncA(li.label, 8) + ' ', 2);
|
||
});
|
||
y += 14;
|
||
} else {
|
||
eText(g2d, 3, y, truncA(it.label, 12), 2);
|
||
var s2 = truncA(valStr(it), it.kind === 'text' ? 24 : 14);
|
||
if (it.kind === 'text') { y += 10; eText(g2d, 3, y, s2, 3); y += 14; }
|
||
else { eText(g2d, EW - s2.length * 6 - 3, y, s2, 3); y += 14; }
|
||
}
|
||
});
|
||
}
|
||
|
||
// ============================================================================================
|
||
// (d) terminal phosphore 40×12
|
||
// ============================================================================================
|
||
var TCOLS = 40, TROWS = 12, TCW = 12, TCH = 20;
|
||
function padTo(s, n) { s = String(s); while (s.length < n) s += ' '; return s.slice(0, n); }
|
||
function drawTerm(g2d, xui, items, hits, blink) {
|
||
var W = TCOLS * TCW, H = TROWS * TCH;
|
||
g2d.fillStyle = '#030904'; g2d.fillRect(0, 0, W, H);
|
||
var lines = [], acts = {}; // n° de ligne -> act
|
||
lines.push('== ' + trunc(deacc(xui.title), 32) + ' ' + new Array(Math.max(1, 36 - deacc(xui.title).length)).join('='));
|
||
items.forEach(function (it) {
|
||
if (lines.length >= TROWS - 1) return;
|
||
var lab = trunc(deacc(it.label || ''), 14);
|
||
if (it.kind === 'action') {
|
||
acts[lines.length] = it.act;
|
||
lines.push(' > [' + lab.toUpperCase() + ']');
|
||
} else if (it.kind === 'gauge') {
|
||
var v = num(it.value, 0), mn = num(it.min, 0), mx = num(it.max, 100);
|
||
var ratio = mx > mn ? Math.max(0, Math.min(1, (v - mn) / (mx - mn))) : 0;
|
||
var bw = 14, fill = Math.round(bw * ratio), bar = '';
|
||
for (var i = 0; i < bw; i++) bar += i < fill ? '#' : '-';
|
||
lines.push(' ' + padTo(lab, 14) + '[' + bar + '] ' + trunc(deacc(valStr(it)), 6));
|
||
} else if (it.kind === 'list') {
|
||
lines.push(' ' + padTo(lab, 14) + '(' + ((it.items || []).length) + ')');
|
||
(it.items || []).slice(0, 2).forEach(function (li) {
|
||
if (lines.length >= TROWS - 1) return;
|
||
if (li.act) acts[lines.length] = li.act;
|
||
lines.push(' · ' + padTo(trunc(deacc(li.label || ''), 16), 17) + trunc(deacc(li.value == null ? '' : String(li.value)), 12));
|
||
});
|
||
} else if (it.kind === 'text') {
|
||
lines.push(' ' + trunc(deacc(String(it.value == null ? '' : it.value)), 38));
|
||
} else {
|
||
var vs = trunc(deacc(valStr(it)), 18);
|
||
lines.push(' ' + padTo(lab, 14) + new Array(Math.max(1, 22 - vs.length)).join('.') + ' ' + vs);
|
||
}
|
||
});
|
||
lines.push('xer> ' + (blink ? '█' : ' '));
|
||
g2d.font = '16px ui-monospace,monospace';
|
||
g2d.textBaseline = 'top';
|
||
g2d.shadowColor = '#22ff77'; g2d.shadowBlur = 5;
|
||
for (var r = 0; r < Math.min(lines.length, TROWS); r++) {
|
||
var isAct = !!acts[r];
|
||
g2d.fillStyle = isAct ? '#8dffb8' : '#2fe36f';
|
||
g2d.fillText(lines[r].slice(0, TCOLS), 4, r * TCH + 2);
|
||
if (isAct) hits.push({ x: 0, y: r * TCH, w: W, h: TCH, act: acts[r] });
|
||
}
|
||
g2d.shadowBlur = 0;
|
||
g2d.fillStyle = 'rgba(0,0,0,.16)'; // scanlines
|
||
for (var sy = 0; sy < H; sy += 4) g2d.fillRect(0, sy, W, 2);
|
||
}
|
||
|
||
// ============================================================================================
|
||
// (e) TV 10-pieds 960×540 — grosses cartes, focus d-pad
|
||
// ============================================================================================
|
||
function rr(g2d, x, y, w, h, r) {
|
||
g2d.beginPath();
|
||
g2d.moveTo(x + r, y); g2d.arcTo(x + w, y, x + w, y + h, r); g2d.arcTo(x + w, y + h, x, y + h, r);
|
||
g2d.arcTo(x, y + h, x, y, r); g2d.arcTo(x, y, x + w, y, r); g2d.closePath();
|
||
}
|
||
function drawTv(g2d, xui, items, hits, focusIdx) {
|
||
var W = 960, H = 540;
|
||
var grad = g2d.createLinearGradient(0, 0, 0, H);
|
||
grad.addColorStop(0, '#0c1120'); grad.addColorStop(1, '#070a12');
|
||
g2d.fillStyle = grad; g2d.fillRect(0, 0, W, H);
|
||
g2d.textBaseline = 'alphabetic'; g2d.textAlign = 'left';
|
||
g2d.font = '46px system-ui,sans-serif'; g2d.fillText(xui.icon || '▣', 34, 66);
|
||
g2d.fillStyle = '#e8ecf8'; g2d.font = '800 34px system-ui,sans-serif';
|
||
g2d.fillText(trunc(xui.title, 30), 100, 62);
|
||
g2d.fillStyle = '#7f93c8'; g2d.font = '600 17px system-ui,sans-serif';
|
||
g2d.fillText('p1→p5 · tout est visible ici — le desktop est la surface la plus bavarde', 100, 90);
|
||
var cols = 3, gw = (W - 34 * 2 - 24 * (cols - 1)) / cols, gh = 118, x0 = 34, y0 = 118;
|
||
items.forEach(function (it, i) {
|
||
var cx2 = x0 + (i % cols) * (gw + 24), cy2 = y0 + Math.floor(i / cols) * (gh + 20);
|
||
if (cy2 + gh > H - 12) return;
|
||
var focused = i === focusIdx, isAct = it.kind === 'action';
|
||
g2d.fillStyle = isAct ? (focused ? '#134d48' : '#0e2e2c') : '#111a30';
|
||
rr(g2d, cx2, cy2, gw, gh, 16); g2d.fill();
|
||
g2d.lineWidth = focused ? 4 : 1;
|
||
g2d.strokeStyle = focused ? '#3fe0d0' : '#1b2540';
|
||
rr(g2d, cx2, cy2, gw, gh, 16); g2d.stroke();
|
||
g2d.fillStyle = '#7f93c8'; g2d.font = '700 15px system-ui,sans-serif';
|
||
g2d.fillText('P' + num(it.p, 5) + ' · ' + trunc(deacc(it.label || ''), 22).toUpperCase(), cx2 + 18, cy2 + 30);
|
||
if (it.kind === 'gauge') {
|
||
var v = num(it.value, 0), mn = num(it.min, 0), mx = num(it.max, 100);
|
||
var ratio = mx > mn ? Math.max(0, Math.min(1, (v - mn) / (mx - mn))) : 0;
|
||
g2d.fillStyle = '#1b2540'; rr(g2d, cx2 + 18, cy2 + 62, gw - 36, 16, 8); g2d.fill();
|
||
g2d.fillStyle = '#3fe0d0'; rr(g2d, cx2 + 18, cy2 + 62, Math.max(10, (gw - 36) * ratio), 16, 8); g2d.fill();
|
||
g2d.fillStyle = '#e8ecf8'; g2d.font = '800 22px system-ui,sans-serif';
|
||
g2d.fillText(valStr(it), cx2 + 18, cy2 + 104);
|
||
} else if (it.kind === 'action') {
|
||
g2d.fillStyle = '#3fe0d0'; g2d.font = '800 30px system-ui,sans-serif';
|
||
g2d.fillText('▶ ' + trunc(deacc(it.label || ''), 14).toUpperCase(), cx2 + 18, cy2 + 78);
|
||
hits.push({ x: cx2, y: cy2, w: gw, h: gh, act: it.act });
|
||
} else if (it.kind === 'list') {
|
||
g2d.fillStyle = '#e8ecf8'; g2d.font = '600 17px system-ui,sans-serif';
|
||
(it.items || []).slice(0, 3).forEach(function (li, j) {
|
||
g2d.fillText('· ' + trunc(li.label, 20) + (li.value != null ? ' ' + trunc(String(li.value), 10) : ''), cx2 + 18, cy2 + 58 + j * 24);
|
||
});
|
||
} else if (it.kind === 'text') {
|
||
g2d.fillStyle = '#c6d2f0'; g2d.font = '400 17px system-ui,sans-serif';
|
||
var words = String(it.value == null ? '' : it.value).split(' '), line = '', ly = cy2 + 60;
|
||
for (var w2 = 0; w2 < words.length && ly < cy2 + gh - 12; w2++) {
|
||
if ((line + words[w2]).length > 30) { g2d.fillText(line, cx2 + 18, ly); line = ''; ly += 24; }
|
||
line += words[w2] + ' ';
|
||
}
|
||
if (ly < cy2 + gh - 6) g2d.fillText(line, cx2 + 18, ly);
|
||
} else {
|
||
g2d.fillStyle = '#e8ecf8'; g2d.font = '800 40px system-ui,sans-serif';
|
||
g2d.fillText(trunc(valStr(it), 14), cx2 + 18, cy2 + 84);
|
||
}
|
||
});
|
||
}
|
||
|
||
// ============================================================================================
|
||
// MOUNT
|
||
// ============================================================================================
|
||
function mount(container, ctx) {
|
||
container.innerHTML =
|
||
'<div class="px-surf">' +
|
||
'<div class="hd">🖥️ Surfaces' +
|
||
'<select data-pick aria-label="choisir un ploxion"></select>' +
|
||
'<span class="badge" data-badge></span>' +
|
||
'</div>' +
|
||
'<div class="bandeau"><b>Le même ploxion, 5 machines — le xer est un renderer.</b> ' +
|
||
'Le ploxion décrit son contenu (XUI, priorités p1→p5) ; chaque surface coupe où elle s’arrête : ' +
|
||
'la montre ne montre que p1, la TV montre tout. Les actions passent par le bus jOSPorts — ' +
|
||
'un ESP32 déclencherait exactement pareil (tape STOP sur l’OLED).</div>' +
|
||
'<div class="bus" data-bus></div>' +
|
||
'<div class="grid">' +
|
||
'<div class="dev"><div class="cap"><b>OLED</b> 128×64 · 1-bit · police 5×7<span class="p">p≤2</span></div><div class="fr-oled"><canvas data-cv="oled" width="384" height="192"></canvas></div></div>' +
|
||
'<div class="dev"><div class="cap"><b>Montre</b> ronde 240 · une carte<span class="p">p≤1</span></div><div class="fr-watch"><canvas data-cv="watch" width="240" height="240"></canvas></div></div>' +
|
||
'<div class="dev"><div class="cap"><b>E-ink</b> 296×128 · 4 gris · tramé<span class="p">p≤3</span></div><div class="fr-eink"><canvas data-cv="eink" width="592" height="256"></canvas></div></div>' +
|
||
'<div class="dev"><div class="cap"><b>Terminal</b> 40×12 · phosphore<span class="p">p≤4</span></div><div class="fr-term"><canvas data-cv="term" width="480" height="240"></canvas></div></div>' +
|
||
'<div class="dev"><div class="cap"><b>TV</b> 10-pieds · d-pad<span class="p">p≤5</span></div><div class="fr-tv"><canvas data-cv="tv" width="960" height="540" tabindex="0"></canvas></div>' +
|
||
'<div class="dpad"><button data-dp="left">◀</button><button data-dp="up">▲</button><button data-dp="down">▼</button><button data-dp="right">▶</button><button data-dp="ok">OK</button></div></div>' +
|
||
'</div>' +
|
||
'<div class="xuic" data-xuic title="XUIC — la version compacte pour micro-écrans (MQTT/série) · clic = copier"></div>' +
|
||
'</div>';
|
||
|
||
var root = container.querySelector('.px-surf');
|
||
var pick = root.querySelector('[data-pick]');
|
||
var badge = root.querySelector('[data-badge]');
|
||
var busEl = root.querySelector('[data-bus]');
|
||
var xuicEl = root.querySelector('[data-xuic]');
|
||
var cvs = {}, g2ds = {}, hits = { oled: [], watch: [], eink: [], term: [], tv: [] };
|
||
root.querySelectorAll('[data-cv]').forEach(function (c) {
|
||
var k = c.getAttribute('data-cv');
|
||
cvs[k] = c;
|
||
g2ds[k] = c.getContext('2d');
|
||
});
|
||
|
||
var plx = listPloxions();
|
||
var state = { pid: 'xerbot', focusIdx: 0, blink: true, lastXuic: '' };
|
||
if (!plx.some(function (p) { return p.id === state.pid; })) state.pid = (plx[0] || { id: 'template' }).id;
|
||
pick.innerHTML = plx.map(function (p) {
|
||
return '<option value="' + esc(p.id) + '"' + (p.id === state.pid ? ' selected' : '') + '>' + esc((p.icon || '▣') + ' ' + p.name) + '</option>';
|
||
}).join('');
|
||
pick.onchange = function () { state.pid = pick.value; state.focusIdx = 0; draw(); };
|
||
|
||
function manifOf(pid) { for (var i = 0; i < plx.length; i++) if (plx[i].id === pid) return plx[i]; return { id: pid, name: pid, icon: '▣' }; }
|
||
|
||
function draw() {
|
||
var src = xuiOf(manifOf(state.pid));
|
||
badge.textContent = src.live ? 'LIVE · describe()' : 'DÉMO · XUI généré';
|
||
badge.className = 'badge ' + (src.live ? 'live' : 'demo');
|
||
Object.keys(hits).forEach(function (k) { hits[k].length = 0; });
|
||
var tvItems = cut(src.xui, CAPS.tv);
|
||
if (state.focusIdx >= tvItems.length) state.focusIdx = Math.max(0, tvItems.length - 1);
|
||
try { drawOled(g2ds.oled, src.xui, cut(src.xui, CAPS.oled), hits.oled); } catch (e) {}
|
||
try { drawWatch(g2ds.watch, src.xui, cut(src.xui, CAPS.watch), hits.watch); } catch (e) {}
|
||
try { drawEink(g2ds.eink, src.xui, cut(src.xui, CAPS.eink), hits.eink); } catch (e) {}
|
||
try { drawTerm(g2ds.term, src.xui, cut(src.xui, CAPS.term), hits.term, state.blink); } catch (e) {}
|
||
try { drawTv(g2ds.tv, src.xui, tvItems, hits.tv, state.focusIdx); } catch (e) {}
|
||
var c = xuic(src.xui);
|
||
state.lastXuic = c;
|
||
xuicEl.innerHTML = '<b>XUIC→micro-écran</b> ' + esc(trunc(c, 220));
|
||
return tvItems;
|
||
}
|
||
|
||
// ---- tap sur une surface = le VRAI act sur le bus (hit zones en coordonnées canvas) ----
|
||
function bindTap(key) {
|
||
cvs[key].addEventListener('click', function (e) {
|
||
var r = cvs[key].getBoundingClientRect();
|
||
if (!r.width || !r.height) return;
|
||
var x = (e.clientX - r.left) * (cvs[key].width / r.width);
|
||
var y = (e.clientY - r.top) * (cvs[key].height / r.height);
|
||
for (var i = 0; i < hits[key].length; i++) {
|
||
var h = hits[key][i];
|
||
if (x >= h.x && x <= h.x + h.w && y >= h.y && y <= h.y + h.h) { emitAct(h.act); return; }
|
||
}
|
||
});
|
||
}
|
||
Object.keys(cvs).forEach(bindTap);
|
||
|
||
// ---- d-pad TV (boutons + flèches clavier quand la TV a le focus) ----
|
||
function dpad(dir) {
|
||
var items = draw(); // resync avant de bouger
|
||
var n = items.length || 1, cols = 3;
|
||
if (dir === 'left') state.focusIdx = Math.max(0, state.focusIdx - 1);
|
||
if (dir === 'right') state.focusIdx = Math.min(n - 1, state.focusIdx + 1);
|
||
if (dir === 'up') state.focusIdx = Math.max(0, state.focusIdx - cols);
|
||
if (dir === 'down') state.focusIdx = Math.min(n - 1, state.focusIdx + cols);
|
||
if (dir === 'ok') { var it = items[state.focusIdx]; if (it && it.act) emitAct(it.act); else toast('cette carte n’a pas d’action'); }
|
||
draw();
|
||
}
|
||
root.querySelectorAll('[data-dp]').forEach(function (b) { b.onclick = function () { dpad(b.getAttribute('data-dp')); }; });
|
||
cvs.tv.addEventListener('keydown', function (e) {
|
||
var map = { ArrowLeft: 'left', ArrowRight: 'right', ArrowUp: 'up', ArrowDown: 'down', Enter: 'ok', ' ': 'ok' };
|
||
if (map[e.key]) { e.preventDefault(); dpad(map[e.key]); }
|
||
});
|
||
xuicEl.onclick = function () { if (window.jOSb && window.jOSb.copy) { window.jOSb.copy(state.lastXuic); toast('XUIC copié'); } };
|
||
|
||
// ---- le bus vit : montrer ce qui circule pour le ploxion choisi (acks du rover…) ----
|
||
var unsubBus = (window.jOSPorts && window.jOSPorts.on)
|
||
? window.jOSPorts.on('*', function (payload, topic) {
|
||
if (!topic || String(topic).indexOf('ploxion.' + state.pid) !== 0) return;
|
||
var s = (typeof payload === 'string') ? payload : (function () { try { return JSON.stringify(payload); } catch (e) { return String(payload); } })();
|
||
busEl.textContent = '◈ ' + topic + ' ' + trunc(s || '', 90);
|
||
})
|
||
: null;
|
||
|
||
draw();
|
||
var timer = setInterval(function () { state.blink = !state.blink; try { draw(); } catch (e) {} }, 1000);
|
||
|
||
return {
|
||
unmount: function () {
|
||
clearInterval(timer);
|
||
if (unsubBus) { try { unsubBus(); } catch (e) {} }
|
||
container.innerHTML = '';
|
||
}
|
||
};
|
||
}
|
||
|
||
window.jOSApps = window.jOSApps || {};
|
||
window.jOSApps['surfaces'] = {
|
||
manifest: { id: 'surfaces', name: 'Surfaces', icon: '🖥️' },
|
||
mount: mount,
|
||
// le démonstrateur se décrit lui-même (contrat XUI v0) — describe() PUR, état courant
|
||
describe: function () {
|
||
return { v: 1, id: 'surfaces', title: 'Surfaces', icon: '🖥️', items: [
|
||
{ p: 1, kind: 'stat', label: 'surfaces', value: 5 },
|
||
{ p: 2, kind: 'text', label: 'idee', value: 'le xer est un renderer : XUI decrit, la surface coupe par priorite' },
|
||
{ p: 3, kind: 'list', label: 'machines', items: [ { label: 'oled' }, { label: 'montre' }, { label: 'e-ink' }, { label: 'terminal' }, { label: 'tv' } ] }
|
||
] };
|
||
}
|
||
};
|
||
})();
|
||
</script>
|