Files
ploxion-veille/app.blade.php

328 lines
33 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{-- PL0XI0N veille 🛰 — LE GOD'S EYE du xerboxion (spec docs/plans/veille-gods-eye-v1.md §3, port de gods-eye-view
en bions + ploxions, RS-7 12.09). Ce ploxion n'a AUCUN état-vérité : tout vit dans le bion jOSVeille. (registre
d'entités, sources, refcount, réalisateur) et les sources pures dans jOSVeilleSources. ; il HÉBERGE sa vue —
jOSGlobe.create (3D Cesium) si WebGL, conteneur ≥ 480 px, pas ctx.panneau et pas .onion, sinon jOSCarte.create
(2D Leaflet, repli automatique) — et l'attache par jOSVeille.attach(engine, handle, {hosted:true}) : la vue
devient pilote (sa bbox nourrit les sources mode 'view'), focus/track/scènes la font voler.
HUD (data-hud-fab="veille", jamais retiré) : bandeau situation = jOSVeille.summary().text (déterministe, sans
LLM) · chips par source avec statut (off/sleep/loading/live/stale/down/key-required/unavailable) + compteur, tap
= jOSVeille.enable(id, !on, {origin:'user'}) · roster = jOSVeille.near(centre, 250 km) · fiche au pick
(jOSVeille.on('pick') → jOSVeille.fiche(e), actions = boutons → jOSXui.act → bus ploxion.veille.cmd, jamais un
callback) · recherche jOSVeille.find → focus · réalisateur ▶/⏸/■/● sur jOSVeille.director.list() (les 5
recettes de /px/veille-scenes.json poussées par director.builtin) · styles CSS none/crt/nvg/flir · bouton
2D/3D · bouton « sortir » TOUJOURS visible · crédits jOSVeille.credits(). describe() = XUI global du bion
(+ moteur), shareParams() = ?src=&lat&lng&alt&scene=&style=&moteur=. Mobile-first, boutons ≥ 44 px, caps D9.
Tout est OFF par défaut : sans couche allumée, rien ne fetch, rien ne se dessine. Sans jOSVeille : message.
Les sources fetchent par jOSApi.get (/px/api, même-origine) : la mention charge _api_bions sur /px/veille (détection non transitive). --}}
<style>
.ve{position:relative;height:100%;min-height:0;background:var(--xr-bg,#05060c);color:var(--xr-text,#e7f0ff);font-family:var(--xr-font-ui,ui-sans-serif,system-ui);overflow:hidden}
.ve *{box-sizing:border-box}
.ve__view{position:absolute;inset:0;z-index:1}
.ve__view .leaflet-container{width:100%;height:100%;background:#05060c}
.ve__view .cesium-viewer-bottom{display:none}
/* styles de vue (CSS seulement, gratuit sur iPhone ; jamais de post-process Cesium) : filter sur la vue + scanlines/vignette */
.ve.st-crt .ve__view>*{filter:contrast(1.15) saturate(.75) sepia(.25) hue-rotate(50deg) brightness(1.05)}
.ve.st-nvg .ve__view>*{filter:grayscale(1) sepia(1) hue-rotate(60deg) saturate(3.5) brightness(.95) contrast(1.25)}
.ve.st-flir .ve__view>*{filter:grayscale(1) invert(1) contrast(1.5) brightness(.9)}
.ve.st-crt .ve__view::after,.ve.st-nvg .ve__view::after,.ve.st-flir .ve__view::after{content:"";position:absolute;inset:0;pointer-events:none;z-index:2;background:radial-gradient(ellipse at center,transparent 55%,rgba(0,0,0,.65) 100%)}
.ve.st-crt .ve__view::before,.ve.st-nvg .ve__view::before{content:"";position:absolute;inset:0;pointer-events:none;z-index:2;background:repeating-linear-gradient(0deg,rgba(0,0,0,.22) 0 1px,transparent 1px 3px)}
.ve.st-crt{--ve-acc:#ffb347}.ve.st-nvg{--ve-acc:#7dff7a}.ve.st-flir{--ve-acc:#ffffff}
.ve__hud{position:absolute;inset:0;z-index:3;pointer-events:none;display:flex;flex-direction:column;justify-content:space-between;padding:8px 8px calc(8px + env(safe-area-inset-bottom));gap:6px}
.ve__hud>*{pointer-events:auto}
.ve__top{display:flex;gap:6px;align-items:flex-start;flex-wrap:wrap}
.ve__sit{flex:1 1 200px;min-width:0;background:rgba(8,17,27,.78);border:1px solid var(--ve-acc,var(--xr-accent,#3fe0d0));border-radius:12px;padding:8px 10px;backdrop-filter:blur(6px);font-size:.8rem;line-height:1.35}
.ve__sit b{color:var(--ve-acc,var(--xr-accent,#3fe0d0));font-size:.68rem;letter-spacing:.08em;text-transform:uppercase;display:block;margin-bottom:2px}
.ve__sit .say{color:#ffd75f;font-size:.74rem;margin-top:3px} .ve__sit .say:empty{display:none}
.ve__btn{display:inline-flex;align-items:center;justify-content:center;gap:5px;min-height:44px;min-width:44px;padding:8px 12px;border-radius:12px;background:rgba(8,17,27,.78);border:1px solid rgba(63,224,208,.45);color:var(--xr-text,#e7f0ff);font:600 .8rem/1 var(--xr-font-ui,ui-sans-serif,system-ui);cursor:pointer;backdrop-filter:blur(6px);white-space:nowrap}
.ve__btn.on{background:var(--ve-acc,var(--xr-accent,#3fe0d0));color:#06121a;border-color:transparent}
.ve__btn.exit{border-color:#ff8a5f;color:#ffb59a} .ve__btn.rec.on{background:#ff5f5f;color:#fff}
.ve__row{display:flex;gap:6px;flex-wrap:wrap}
.ve__bottom{display:flex;flex-direction:column;gap:6px;max-width:100%}
.ve__chips{display:flex;gap:6px;overflow-x:auto;scrollbar-width:none;padding:2px 0;-webkit-overflow-scrolling:touch}
.ve__chips::-webkit-scrollbar{display:none}
.ve__chip{flex:0 0 auto;display:inline-flex;align-items:center;gap:6px;min-height:44px;padding:6px 12px;border-radius:999px;background:rgba(8,17,27,.78);border:1px solid rgba(63,224,208,.35);color:var(--xr-text,#e7f0ff);font:.8rem/1 var(--xr-font-ui,ui-sans-serif,system-ui);cursor:pointer;backdrop-filter:blur(6px)}
.ve__chip.on{background:rgba(63,224,208,.18);border-color:var(--ve-acc,var(--xr-accent,#3fe0d0));font-weight:700}
.ve__chip .dot{width:9px;height:9px;border-radius:50%;background:#6f7f8f;flex:0 0 auto}
.ve__chip .dot.live{background:#3fe07f}.ve__chip .dot.loading{background:#5fd0ff;animation:vepulse 1s infinite}.ve__chip .dot.stale{background:#ffd75f}.ve__chip .dot.sleep{background:#9fb0c0}.ve__chip .dot.down,.ve__chip .dot.key-required,.ve__chip .dot.unavailable{background:#ff5f5f}
.ve__chip small{opacity:.7;font-variant-numeric:tabular-nums}
@keyframes vepulse{50%{opacity:.3}}
.ve__search{display:flex;gap:6px;align-items:center}
.ve__search input{flex:1;min-width:0;min-height:44px;padding:8px 12px;border-radius:12px;border:1px solid rgba(63,224,208,.45);background:rgba(8,17,27,.85);color:var(--xr-text,#e7f0ff);font:.85rem var(--xr-font-ui,ui-sans-serif,system-ui);outline:none}
.ve__panel{position:absolute;right:8px;bottom:calc(120px + env(safe-area-inset-bottom));z-index:4;width:min(92vw,340px);max-height:min(56%,420px);overflow:auto;background:rgba(8,17,27,.94);border:1px solid var(--ve-acc,var(--xr-accent,#3fe0d0));border-radius:14px;padding:10px 12px;font-size:.8rem;line-height:1.4;backdrop-filter:blur(8px)}
.ve__panel h4{margin:0 0 6px;font-size:.68rem;letter-spacing:.08em;text-transform:uppercase;color:var(--ve-acc,var(--xr-accent,#3fe0d0));display:flex;align-items:center;gap:6px}
.ve__panel h4 .x{margin-left:auto;min-width:44px;min-height:44px;border:0;background:transparent;color:inherit;font-size:1.1rem;cursor:pointer}
.ve__item{display:flex;gap:8px;align-items:center;width:100%;min-height:44px;padding:6px 8px;border:0;border-bottom:1px solid rgba(150,170,255,.08);background:transparent;color:inherit;font:inherit;text-align:left;cursor:pointer}
.ve__item .l{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} .ve__item .m{opacity:.6;font-size:.72rem;font-variant-numeric:tabular-nums;white-space:nowrap}
.ve__item.sev2 .l{color:#ffd75f}.ve__item.sev3 .l{color:#ff8a8a}
.ve__fiche dl{margin:6px 0 0;display:grid;grid-template-columns:auto 1fr;gap:2px 8px} .ve__fiche dt{color:#8aa0c0} .ve__fiche dd{margin:0;overflow:hidden;text-overflow:ellipsis}
.ve__fiche .sub{opacity:.75;font-size:.74rem} .ve__fiche .acts{display:flex;gap:6px;flex-wrap:wrap;margin-top:8px}
.ve__msg{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;text-align:center;padding:24px;color:#8aa0c0;z-index:2;background:var(--xr-bg,#05060c);font-size:.9rem;line-height:1.5}
.ve__credits{font-size:.74rem;opacity:.85} .ve__credits div{padding:4px 0;border-bottom:1px solid rgba(150,170,255,.08)}
.ve--compact .ve__sit{font-size:.74rem} .ve--compact .ve__panel{bottom:calc(64px + env(safe-area-inset-bottom))}
@media (max-width:480px){.ve__top .ve__btn span.t{display:none}}
</style>
<script>
(function () {
'use strict';
var ID = 'veille';
if (!window.jOSApps) window.jOSApps = {};
if (window.jOSApps[ID]) return;
var STYLES = ['none', 'crt', 'nvg', 'flir'], STYLE_ICON = { none: '◯', crt: '📺', nvg: '🟢', flir: '🌡' };
var HOME = { lat: 46.8, lng: 8.2, alt: 2.2e6 };
var LIVE = null; // état monté (pour describe/shareParams) — jamais une entité
function esc(s) { return window.jOSb.esc(s); }
function V() { return window.jOSVeille || null; }
function VS() { return window.jOSVeilleSources || null; }
function onion() { try { return /\.onion$/.test(location.hostname || ''); } catch (e) { return false; } }
function coarse() { try { return !!(window.matchMedia && matchMedia('(pointer:coarse)').matches); } catch (e) { return false; } }
function webgl() { try { var c = document.createElement('canvas'); return !!(c.getContext('webgl2') || c.getContext('webgl')); } catch (e) { return false; } }
function fmtN(n) { return String(Math.round(+n || 0)).replace(/\B(?=(\d{3})+(?!\d))/g, ' '); }
function fmtAlt(m) { m = +m || 0; return m > 5000 ? Math.round(m / 1000) + ' km' : Math.round(m) + ' m'; }
// act : TOUTE action passe par le bus (jOSXui.act → jOSPorts.emit → topic ploxion.<id>.<port>) ; sans bus, le
// même contrat via jOSVeille.cmd (le port d'entrée ploxion.veille.cmd) — jamais un callback UI
function act(port, payload) {
var a = { port: port, payload: payload || {} }, ok = false;
try { if (window.jOSXui && jOSXui.act) ok = !!jOSXui.act({ act: a }); } catch (e) { ok = false; }
if (!ok) { try { var m = /^ploxion\.([^.]+)\.(.+)$/.exec(port); if (m && window.jOSPorts && jOSPorts.emit) { jOSPorts.emit(m[1], m[2], a.payload); ok = true; } } catch (e2) {} }
if (!ok && port === 'ploxion.veille.cmd' && V()) { try { V().cmd(a.payload); } catch (e3) {} }
return ok;
}
function cmd(payload) { return act('ploxion.veille.cmd', payload); }
function busOn(topic, cb) { try { if (window.jOSPorts && jOSPorts.on) { var off = jOSPorts.on(topic, cb); return typeof off === 'function' ? off : function () {}; } } catch (e) {} return function () {}; }
function mount(container, ctx) {
ctx = ctx || {};
container.classList.add('ve'); if (ctx.panneau) container.classList.add('ve--compact');
container.innerHTML = '<div class="ve__view" data-view></div><div class="ve__hud" data-hud-fab="veille" data-hud></div>';
var viewEl = container.querySelector('[data-view]'), hud = container.querySelector('[data-hud]');
var veille = V(), dead = false, engine = null, api = null, vue = null, offs = [], timers = [], ficheActs = [], panel = null, sayText = '', lastSit = '';
if (!veille) {
container.insertAdjacentHTML('beforeend', '<div class="ve__msg">🛰 Veille — bion <b style="color:#3fe0d0;margin:0 6px">jOSVeille</b> absent sur cette surface : le god\'s eye n\'est pas chargé ici.</div>');
return { unmount: function () { container.classList.remove('ve'); container.innerHTML = ''; } };
}
// ---- paramètres (ctx.params ou ?src=&lat&lng&alt&scene=&style=&moteur= sur /px/veille) ----
var params = Object.assign({}, ctx.params || {});
try { if (/^\/px\/veille\b/.test(location.pathname || '')) { var q = new URLSearchParams(location.search); ['src', 'lat', 'lng', 'alt', 'scene', 'style', 'moteur', 'test'].forEach(function (k) { if (q.get(k) != null && params[k] == null) params[k] = q.get(k); }); } } catch (e) {}
var pref = {}; try { pref = veille.pref() || {}; } catch (e) { pref = {}; }
var style = STYLES.indexOf(params.style) >= 0 ? params.style : (STYLES.indexOf(pref.style) >= 0 ? pref.style : 'none');
var start = { lat: +params.lat, lng: +params.lng, alt: +params.alt };
if (!isFinite(start.lat) || !isFinite(start.lng)) start = { lat: HOME.lat, lng: HOME.lng, alt: HOME.alt }; else if (!isFinite(start.alt)) start.alt = 8e5;
// ---- choix du moteur : 3D si WebGL + large + pas panneau + pas onion (D9 : jamais de globe en cadran) ----
function width() { return container.clientWidth || container.offsetWidth || window.innerWidth || 0; }
function canGlobe() { return !!window.jOSGlobe && !ctx.panneau && !onion() && width() >= 480 && webgl(); }
function wantEngine() { var w = params.moteur || pref.engine || 'globe'; return (w === 'carte' || !canGlobe()) ? 'carte' : 'globe'; }
// ---- chrome ----
function chrome() {
var st = dirStatus(), playing = st.state === 'play', paused = st.state === 'pause';
hud.innerHTML = '<div class="ve__top">'
+ '<div class="ve__sit"><b>situation · ' + esc(engine === 'globe' ? '3D' : '2D') + (LIVE && LIVE.place ? ' · ' + esc(LIVE.place) : '') + '</b><span data-sit>' + esc(lastSit || '…') + '</span><div class="say" data-say>' + esc(sayText) + '</div></div>'
+ '<div class="ve__row">'
+ '<button class="ve__btn exit" data-exit title="sortir">✕ <span class="t">sortir</span></button>'
+ '<button class="ve__btn" data-engine title="' + (engine === 'globe' ? 'passer en 2D' : 'passer en 3D') + '">' + (engine === 'globe' ? '2D' : '3D') + '</button>'
+ '<button class="ve__btn' + (style !== 'none' ? ' on' : '') + '" data-style title="style de vue : ' + esc(style) + '">' + STYLE_ICON[style] + '</button>'
+ '<button class="ve__btn" data-panel="roster" title="roster 250 km">📡</button>'
+ '<button class="ve__btn" data-panel="credits" title="crédits">ⓘ</button>'
+ '</div></div>'
+ '<div class="ve__bottom">'
+ '<div class="ve__row">'
+ (playing ? '<button class="ve__btn on" data-dir="pause">⏸ ' + esc(st.id || '') + ' ' + (st.step + 1) + '/' + st.n + '</button><button class="ve__btn exit" data-dir="stop">■ sortir de la scène</button>'
: paused ? '<button class="ve__btn" data-dir="resume">▶ reprendre</button><button class="ve__btn exit" data-dir="stop">■</button>'
: '<button class="ve__btn" data-panel="scenes" title="scènes">▶ <span class="t">scènes</span></button>')
+ '<button class="ve__btn rec' + (isRec() ? ' on' : '') + '" data-rec title="' + (isRec() ? 'marquer une étape (long : terminer)' : 'enregistrer une scène') + '">●' + (isRec() ? ' ' + recSteps() : '') + '</button>'
+ (isRec() ? '<button class="ve__btn" data-rec-stop title="terminer l\'enregistrement">■ garder</button>' : '')
+ '<button class="ve__btn" data-home title="chez moi">🏠</button>'
+ '</div>'
+ '<div class="ve__search"><input data-q placeholder="callsign, ISS, M>5, mil, lat,lng" inputmode="search" autocomplete="off"></div>'
+ '<div class="ve__chips" data-chips></div></div>';
chips();
}
function sources() { var out = []; try { out = veille.sources().map(function (s) { return s.id; }); } catch (e) {} if (!out.length) { try { out = (VS() && VS().ids) ? VS().ids.slice() : []; } catch (e2) {} } return out; }
function isOn(id) { try { var st = veille.status(id); if (st && st.views > 0) return true; } catch (e) {} try { return veille.enabled().indexOf(id) >= 0; } catch (e2) { return false; } }
function defOf(id) { try { var s = veille.get(id); if (s && s.def) return s.def; } catch (e) {} try { return (VS() && VS().spec(id)) || {}; } catch (e2) { return {}; } }
function chips() {
var el = hud.querySelector('[data-chips]'); if (!el) return;
el.innerHTML = sources().map(function (id) {
var d = defOf(id) || {}, st = null; try { st = veille.status(id); } catch (e) {} st = st || { status: 'off', n: 0 };
var on = isOn(id), s = st.status || 'off';
return '<button class="ve__chip' + (on ? ' on' : '') + '" data-src="' + esc(id) + '" title="' + esc((d.name || id) + ' · ' + s + (st.err ? ' · ' + st.err : '')) + '"><span class="dot ' + esc(s) + '"></span>' + esc(d.icon || '•') + ' ' + esc(d.name || id) + ' <small>' + (on ? fmtN(st.n) : (s === 'off' ? 'off' : s)) + '</small></button>';
}).join('') || '<span style="opacity:.6;font-size:.75rem">aucune source (jOSVeilleSources absent)</span>';
}
// ---- situation déterministe (jOSVeille.summary, ≤ 1/15 s sur le bus, ici rafraîchie toutes les 5 s) ----
function situation() {
var s = null; try { s = veille.summary(); } catch (e) { s = null; } if (!s) return;
lastSit = s.text || ''; if (LIVE) LIVE.place = s.place || null;
var el = hud.querySelector('[data-sit]'); if (el) el.textContent = lastSit;
chips();
}
// ---- réalisateur ----
function dirStatus() { try { return veille.director.status() || { state: 'stop', step: 0, n: 0 }; } catch (e) { return { state: 'stop', step: 0, n: 0 }; } }
function isRec() { try { return !!veille.director.record(); } catch (e) { return false; } }
function recSteps() { try { var r = veille.director.record(); return r && r.steps ? r.steps.length : 0; } catch (e) { return 0; } }
function loadScenes() {
try { if (veille.director.builtin().length) return; } catch (e) {}
fetch('/px/veille-scenes.json', { credentials: 'same-origin' }).then(function (r) { return r.ok ? r.json() : null; }).then(function (j) {
if (dead || !j) return; var list = Array.isArray(j) ? j : (j.items || []);
try { veille.director.builtin(list); } catch (e) {}
if (params.scene) { cmd({ cmd: 'scene', id: params.scene }); params.scene = null; }
}).catch(function () {});
}
// ---- panneaux (roster / fiche / scènes / recherche / crédits) — un seul à la fois ----
function closePanel() { if (panel) { try { panel.remove(); } catch (e) {} } panel = null; ficheActs = []; }
function openPanel(kind, html) {
closePanel(); panel = document.createElement('div'); panel.className = 've__panel' + (kind === 'fiche' ? ' ve__fiche' : ''); panel.setAttribute('data-kind', kind);
panel.innerHTML = html + ''; container.appendChild(panel);
}
function head(t) { return '<h4>' + t + '<button class="x" data-x title="fermer">✕</button></h4>'; }
function center() { try { var v = vue && vue.viewport ? vue.viewport() : (veille.pilot() ? veille.pilot().viewport() : null); return v && v.center ? v.center : start; } catch (e) { return start; } }
function item(e, meta) { return '<button class="ve__item sev' + (e.severity || 0) + '" data-id="' + esc(e.id) + '"><span>' + esc(e.icon || '•') + '</span><span class="l">' + esc(e.label || e.id) + '</span><span class="m">' + esc(meta || '') + '</span></button>'; }
function roster() {
var c = center(), rows = []; try { rows = veille.near(c, 250).slice(0, 14); } catch (e) { rows = []; }
openPanel('roster', head('📡 roster · 250 km · ' + rows.length) + (rows.length ? rows.map(function (r) { return item(r.e, r.km.toFixed(0) + ' km · ' + r.bearing + '°'); }).join('') : '<div style="opacity:.6">rien à 250 km — allume une source, ou rapproche-toi</div>'));
}
function fiche(e) {
var f = null; try { f = veille.fiche(e); } catch (er) { f = null; } if (!f) return;
var acts = (f.actions || []).filter(function (a) { return a && a.act && typeof a.act.port === 'string'; }).slice(0, 6);
openPanel('fiche', head(esc(f.title || e.label || e.id)) + '<div class="sub">' + esc(f.sub || '') + '</div><dl>' + (f.rows || []).slice(0, 14).map(function (r) { return '<dt>' + esc(r && r[0]) + '</dt><dd>' + esc(r && r[1]) + '</dd>'; }).join('') + '</dl>'
+ (acts.length ? '<div class="acts">' + acts.map(function (a, i) { return '<button class="ve__btn" data-act="' + i + '">' + esc(a.label || 'action') + '</button>'; }).join('') + '</div>' : ''));
ficheActs = acts; // après openPanel (closePanel remet ficheActs à zéro)
}
function scenes() {
var list = []; try { list = veille.director.list(); } catch (e) { list = []; }
openPanel('scenes', head('🎬 scènes · ' + list.length) + (list.length ? list.map(function (s) { return '<button class="ve__item" data-scene="' + esc(s.id) + '"><span>' + esc(s.icon || '🎬') + '</span><span class="l">' + esc(s.name || s.id) + '</span><span class="m">' + (s.steps ? s.steps.length + ' pas · ' : '') + (s.durationSec ? Math.round(s.durationSec) + ' s' : '') + '</span></button>'; }).join('') : '<div style="opacity:.6">chargement des recettes…</div>')
+ '<div class="ve__row" style="margin-top:8px">' + [0.5, 1, 2].map(function (r) { return '<button class="ve__btn' + (dirRate() === r ? ' on' : '') + '" data-rate="' + r + '">' + r + '×</button>'; }).join('') + '</div>');
}
var rate = 1; function dirRate() { return rate; }
function search(q) {
q = String(q || '').trim(); if (!q) return;
var m = /^(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)$/.exec(q);
if (m) { cmd({ cmd: 'fly', lat: +m[1], lng: +m[2], alt: 2e5 }); return; }
var rs = []; try { rs = veille.find(q, 8); } catch (e) { rs = []; }
if (rs.length === 1) { cmd({ cmd: 'focus', id: rs[0].e.id }); fiche(rs[0].e); return; }
openPanel('find', head('🔎 ' + esc(q) + ' · ' + rs.length) + (rs.length ? rs.map(function (r) { return item(r.e, r.e.src); }).join('') : '<div style="opacity:.6">rien dans le registre — allume la source qui va bien (les sources éteintes n\'ont pas d\'entités)</div>'));
}
function credits() {
var cs = []; try { cs = veille.credits(); } catch (e) {} if (!cs.length) { try { cs = VS().credits(); } catch (e2) { cs = []; } }
openPanel('credits', head('ⓘ crédits') + '<div class="ve__credits">' + cs.map(function (c) { var d = defOf(c.src) || {}; return '<div><b>' + esc(d.icon || '•') + ' ' + esc(d.name || c.src) + '</b> — ' + esc(c.credit || '') + (c.licence ? ' · ' + esc(c.licence) : '') + '</div>'; }).join('')
+ '<div>fonds : Sentinel-2 cloudless by EOX (CC BY 4.0) · © OpenStreetMap contributors · Esri</div><div>moteurs : CesiumJS (Apache-2.0), Leaflet (BSD-2) · SGP4 satellite.js (MIT)</div><div style="opacity:.7">Données retardées, incomplètes, modélisées ou fausses — jamais pour la navigation, l\'urgence ou la recherche d\'une personne.</div></div>');
}
// ---- style + moteur ----
function applyStyle(id) { style = STYLES.indexOf(id) >= 0 ? id : 'none'; STYLES.forEach(function (s) { container.classList.remove('st-' + s); }); if (style !== 'none') container.classList.add('st-' + style); if (LIVE) LIVE.style = style; var b = hud.querySelector('[data-style]'); if (b) { b.textContent = STYLE_ICON[style]; b.classList.toggle('on', style !== 'none'); } }
// Teardown d'une vue : DÉTRUIRE le moteur d'abord (ses hooks onToggle(false) tombent sur la vue encore attachée →
// refcount à zéro, poll stoppé, aucune vue fantôme), PUIS détacher. Le bion retire de l'état préféré une source
// quand plus aucune vue ne l'affiche : on garde la liste et on la rend (origine 'boot') après le remontage —
// basculer 2D/3D ou fermer le god's eye n'oublie pas ce que l'utilisateur avait allumé.
var keep = [];
function unmountView() {
try { veille.enabled().forEach(function (id) { if (keep.indexOf(id) < 0) keep.push(id); }); } catch (e) {} // union : un double teardown n'efface pas la liste
try { api && api.destroy && api.destroy(); } catch (e) {} api = null;
try { vue && vue.detach && vue.detach(); } catch (e) {} vue = null;
viewEl.innerHTML = ''; var m = container.querySelector('.ve__msg'); if (m) m.remove();
}
function restoreKeep() { var k = keep; keep = []; k.forEach(function (id) { try { veille.enable(id, true, { origin: 'boot' }); } catch (e) {} }); }
function mountView(which) {
engine = which; if (LIVE) LIVE.engine = engine;
var msg = document.createElement('div'); msg.className = 've__msg'; msg.textContent = which === 'globe' ? '🛰 chargement du globe (Cesium, 6 Mo, une fois)…' : '🛰 chargement de la carte…'; container.appendChild(msg);
function ready(handle, eng) {
if (dead) { try { handle.destroy(); } catch (e) {} return; }
api = handle; engine = eng; if (LIVE) LIVE.engine = eng; msg.remove();
try { vue = veille.attach(eng, handle, { hosted: true }) || null; } catch (e) { vue = null; } // la vue devient pilote ; émet ploxion.veille.ready {engine}
restoreKeep(); // les couches gardées d'une vue précédente se rallument ici
try { if (eng === 'globe') handle.fly(start.lat, start.lng, start.alt, { duration: 0 }); else handle.setView(start.lat, start.lng, veille.zoomEq(start.alt)); } catch (e) {}
chrome(); situation();
}
if (which === 'globe') {
window.jOSGlobe.create(viewEl, { eco: coarse() }).then(function (a) { ready(a, 'globe'); })
.catch(function (e) { if (dead) return; msg.textContent = '🛰 globe indisponible (' + ((e && e.message) || 'WebGL') + ') → carte 2D'; viewEl.innerHTML = ''; setTimeout(function () { if (!dead) { msg.remove(); mountView('carte'); } }, 600); });
} else if (window.jOSCarte && jOSCarte.create) {
window.jOSCarte.create(viewEl, { center: [start.lat, start.lng], zoom: veille.zoomEq(start.alt) }).then(function (h) { ready(h, 'carte'); })
.catch(function (e) { if (dead) return; msg.innerHTML = '🛰 carte indisponible : ' + esc(e && e.message); });
} else { msg.textContent = '🛰 aucun moteur de vue (jOSGlobe / jOSCarte absents)'; chrome(); }
}
function switchEngine() {
var next = engine === 'globe' ? 'carte' : 'globe';
if (next === 'globe' && !canGlobe()) { try { window.jOSb && jOSb.toast && jOSb.toast('3D indisponible ici (WebGL, largeur ou onion)'); } catch (e) {} return; }
try { var lk = LIVE && LIVE.look ? LIVE.look() : null; if (lk && isFinite(+lk.lat) && isFinite(+lk.lng)) start = { lat: +lk.lat, lng: +lk.lng, alt: isFinite(+lk.alt) ? +lk.alt : start.alt }; } catch (e) {} // on reprend au même endroit
closePanel(); unmountView(); pref.engine = next; mountView(next); // engine posé AVANT le cmd : l'écho ploxion.veille.engine du bus est alors un no-op
cmd({ cmd: 'engine', id: next });
}
function exit() {
if (dirStatus().state !== 'stop') { cmd({ cmd: 'stop' }); }
try { if (typeof ctx.close === 'function') { ctx.close(); return; } } catch (e) {}
try { if (window.jOSWindows && jOSWindows.close) { jOSWindows.close(ID); return; } } catch (e2) {}
try { if (window.jOS && jOS.closeWin) { jOS.closeWin(ID); return; } } catch (e3) {}
try { if (history.length > 1) history.back(); else location.href = '/'; } catch (e4) {}
}
// ---- événements ----
function onClick(ev) {
var b = ev.target.closest ? ev.target.closest('button') : null; if (!b) return;
var src = b.getAttribute('data-src'), id = b.getAttribute('data-id'), sc = b.getAttribute('data-scene'), dir = b.getAttribute('data-dir'), pk = b.getAttribute('data-panel'), rt = b.getAttribute('data-rate');
if (src) { try { veille.enable(src, !isOn(src), { origin: 'user' }); } catch (e) {} chips(); return; } // le chip = l'état préféré ; les hooks des moteurs font partir/arrêter le poll
if (id) { cmd({ cmd: 'focus', id: id }); var e2 = null; try { e2 = veille.entity(id); } catch (er) {} if (e2) fiche(e2); return; }
if (sc) { rate = rate || 1; cmd({ cmd: 'scene', id: sc, rate: rate }); closePanel(); chrome(); return; }
if (rt) { rate = +rt || 1; scenes(); return; }
if (dir) { cmd({ cmd: dir }); chrome(); return; }
if (b.hasAttribute('data-act')) { var a = ficheActs[+b.getAttribute('data-act')]; if (a) { try { if (window.jOSXui && jOSXui.act) jOSXui.act(a); else act(a.act.port, a.act.payload); } catch (er2) {} } return; }
if (b.hasAttribute('data-x')) { closePanel(); return; }
if (pk) { if (panel && panel.getAttribute('data-kind') === pk) { closePanel(); return; } if (pk === 'roster') roster(); else if (pk === 'scenes') scenes(); else if (pk === 'credits') credits(); return; }
if (b.hasAttribute('data-exit')) { exit(); return; }
if (b.hasAttribute('data-engine')) { switchEngine(); return; }
if (b.hasAttribute('data-style')) { var nx = STYLES[(STYLES.indexOf(style) + 1) % STYLES.length]; applyStyle(nx); cmd({ cmd: 'style', id: nx }); return; }
if (b.hasAttribute('data-home')) { cmd({ cmd: 'fly', home: true, alt: 2e5 }); return; }
if (b.hasAttribute('data-rec')) { cmd({ cmd: 'record', phase: isRec() ? 'mark' : 'start' }); chrome(); return; }
if (b.hasAttribute('data-rec-stop')) { cmd({ cmd: 'record', phase: 'stop' }); chrome(); try { window.jOSb && jOSb.toast && jOSb.toast('scène gardée'); } catch (e5) {} return; }
}
function onKey(ev) { if (ev.key !== 'Enter' || !ev.target.matches || !ev.target.matches('[data-q]')) return; search(ev.target.value); }
container.addEventListener('click', onClick); container.addEventListener('keydown', onKey);
// abonnements bion (pick → fiche ; update/status/view → chips + situation, coalescés) et bus (style/engine/say/scene)
var sitT = null; function sitSoon() { if (sitT) return; sitT = setTimeout(function () { sitT = null; if (!dead) situation(); }, 1200); }
offs.push(veille.on('pick', function (p) { if (p && p.e) fiche(p.e); }));
offs.push(veille.on('update', sitSoon), veille.on('status', sitSoon), veille.on('view', sitSoon));
offs.push(veille.on('scene', function () { if (!dead) chrome(); }));
offs.push(busOn('ploxion.veille.style', function (p) { if (p && p.id) applyStyle(p.id); }));
offs.push(busOn('ploxion.veille.engine', function (p) { if (p && p.id && p.id !== engine && !dead) { pref.engine = p.id; if (p.id === 'carte' || canGlobe()) { closePanel(); unmountView(); mountView(p.id); } } }));
offs.push(busOn('ploxion.veille.say', function (p) { sayText = (p && p.text) ? String(p.text).slice(0, 200) : ''; var el = hud.querySelector('[data-say]'); if (el) el.textContent = sayText; }));
offs.push(busOn('ploxion.veille.find', function (p) { if (!p || !Array.isArray(p.items) || panel) return; openPanel('find', head('🔎 ' + esc(p.q || '') + ' · ' + p.items.length) + p.items.map(function (r) { return '<button class="ve__item" data-id="' + esc(r.id) + '"><span>•</span><span class="l">' + esc(r.label || r.id) + '</span></button>'; }).join('')); }));
timers.push(setInterval(function () { if (!dead && document.visibilityState !== 'hidden') situation(); }, 5000));
LIVE = { engine: null, style: style, place: null, start: start, look: function () { try { if (engine === 'globe' && api && api.look) return api.look(); if (vue && vue.viewport) { var v = vue.viewport(); return { lat: v.center.lat, lng: v.center.lng, alt: v.altM }; } } catch (e) {} return null; } };
applyStyle(style); mountView(wantEngine()); chrome(); loadScenes();
// partage : ?src=a,b → allume (origine 'share') ; snapshot hors-ligne restauré en 'stale' pour les sources connues
if (params.src) { String(params.src).split(',').forEach(function (id) { id = id.trim(); if (id) { try { veille.enable(id, true, { origin: 'share' }); } catch (e) {} } }); }
try { sources().forEach(function (id) { veille.restore(id); }); } catch (e) {}
if (params.style) cmd({ cmd: 'style', id: style });
try { if (window.jOSGame && jOSGame.bion) jOSGame.bion('veille'); } catch (e) {}
return { unmount: function () {
dead = true; offs.forEach(function (f) { try { f(); } catch (e) {} }); timers.forEach(function (t) { try { clearInterval(t); } catch (e) {} }); if (sitT) { try { clearTimeout(sitT); } catch (e) {} }
try { if (dirStatus().state !== 'stop') veille.director.stop(); } catch (e) {}
try { cmd({ cmd: 'snapshot' }); } catch (e) {} // hors-ligne : ≤ 200 Ko par source (veille:snap:<src>)
container.removeEventListener('click', onClick); container.removeEventListener('keydown', onKey);
closePanel(); unmountView(); restoreKeep(); LIVE = null; // l'état préféré survit à la fermeture (aucune vue → rien ne s'allume)
container.classList.remove('ve', 've--compact'); STYLES.forEach(function (s) { container.classList.remove('st-' + s); }); container.innerHTML = '';
} };
}
// ---- describe() : XUI global du bion (situation, contacts, sources, alertes, scène suivante, chez moi) + moteur — pur, ne lève jamais ----
function describe() {
var x = null; try { if (V() && V().describe) x = V().describe(); } catch (e) { x = null; }
if (!x) return { v: 1, id: ID, title: 'Veille', icon: '🛰', items: [{ p: 1, kind: 'text', label: 'veille — bion jOSVeille absent' }] };
try { x.items.push({ p: 2, kind: 'stat', label: 'moteur', value: LIVE ? (LIVE.engine === 'globe' ? '3D' : '2D') + (LIVE.style !== 'none' ? ' · ' + LIVE.style : '') : 'non monté' }); } catch (e) {}
return x;
}
// ---- shareParams (convention jOSSharePloxion) : ?src=&lat&lng&alt&scene=&style=&moteur= — l'état courant, rien de plus ----
function shareParams() {
try {
var o = {}, v = V(); if (!v) return null;
var en = v.enabled(); if (en.length) o.src = en.join(',');
var lk = LIVE && LIVE.look ? LIVE.look() : null; if (lk && isFinite(lk.lat)) { o.lat = (+lk.lat).toFixed(4); o.lng = (+lk.lng).toFixed(4); if (lk.alt != null) o.alt = Math.round(lk.alt); }
var d = v.director.status(); if (d && d.id && d.state !== 'stop') o.scene = d.id;
if (LIVE && LIVE.style && LIVE.style !== 'none') o.style = LIVE.style;
if (LIVE && LIVE.engine) o.moteur = LIVE.engine;
return Object.keys(o).length ? o : null;
} catch (e) { return null; }
}
window.jOSApps[ID] = { manifest: { id: ID, name: 'Veille', icon: '🛰' }, mount: mount, describe: describe, shareParams: shareParams };
})();
</script>