ploxion-wayback/app.blade.php

379 lines
32 KiB
PHP
Raw Permalink 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.

{{-- PL0XION wayback 🕰 — LA WAYBACK MACHINE DU XERBOXION (RS-7 22.09 : « se balader entre les versions comme sur la
Wayback Machine » ; « la Wayback des ploxions fait partie intégrante du système » ; 10.09 : « tout est un repo, on ne
peut pas voir l'histoire d'un ploxion »). Entrée = UN ploxion (recherche dans /px/wayback/index.json, ou ctx.ploxion /
?ploxion= / dernier choisi). TIMELINE façon Wayback Machine : une barre horizontale par mois, ticks (git = trait,
instantané manuel = point), compteur « N versions », liste antichrono (date, genre, auteur, message, taille), sélection →
APERÇU en iframe (/px/wayback/{id}/{v} : la version passée rendue dans son cadre, lecture seule) + « Ouvrir en grand »,
« Code » (GET …/{v}/source), « Comparer avec l'actuel » (diff ligne à ligne LCS en JS, ±3 lignes de contexte), ⏮ ⏭,
et « 📸 Instantané maintenant » (admin : POST /px/wayback/{id}/snapshot {note, ns[]} → code + config + KV du boxion +
index des fichiers). Serveur : WaybackController · hôte : bin/wayback-export.mjs + fleet/wayback-refresh.sh (git →
volume). Bions : jOSb (esc/toast/postJSON), jOSPorts (ploxion.wayback.cmd : snapshot / ouvrir). describe() = XUI p1-p3.
Mobile-first : timeline scrollable, liste puis aperçu empilés ; 2 colonnes ≥ 900 px. Ne touche à AUCUN autre ploxion. --}}
<style>
.wb{display:flex;flex-direction:column;height:100%;background:var(--xr-bg,#070a0d);color:var(--xr-fg,#dfe8ee);font-family:var(--xr-font-ui,system-ui);font-size:.87rem}
.wb__h{flex:0 0 auto;padding:12px 14px 10px;border-bottom:1px solid var(--xr-line,#16232c);display:flex;flex-direction:column;gap:8px}
.wb__ht{display:flex;align-items:baseline;gap:8px;font-weight:800;color:#f2c766;flex-wrap:wrap}
.wb__ht small{color:var(--xr-muted,#5a7784);font-weight:400;font-size:.7rem}
.wb__pick{position:relative}
.wb__in{width:100%;box-sizing:border-box;font:inherit;font-size:16px;padding:10px 12px;min-height:44px;border-radius:11px;border:1px solid var(--xr-line,#1d3540);background:var(--xr-card,#0c1218);color:var(--xr-fg,#dfe8ee);outline:none}
.wb__in:focus{border-color:#a8842a}
.wb__sug{position:absolute;left:0;right:0;top:calc(100% + 4px);z-index:5;max-height:240px;overflow:auto;border:1px solid var(--xr-line,#1d3540);border-radius:11px;background:#0c1218;box-shadow:0 12px 30px rgba(0,0,0,.5)}
.wb__sug button{display:flex;width:100%;gap:8px;align-items:center;cursor:pointer;font:inherit;text-align:left;padding:10px 12px;min-height:40px;border:0;border-bottom:1px solid #121c24;background:transparent;color:var(--xr-fg,#dfe8ee)}
.wb__sug button:last-child{border-bottom:0}
.wb__sug button small{margin-left:auto;color:var(--xr-muted,#5a7784);font-size:.7rem;white-space:nowrap}
.wb__body{flex:1;min-height:0;overflow:auto;padding:12px 14px;display:flex;flex-direction:column;gap:12px;-webkit-overflow-scrolling:touch}
.wb__empty{color:var(--xr-muted,#5a7784);font-size:.8rem;padding:10px 0}
.wb__hint{margin:0;font-size:.78rem;line-height:1.55;color:#9fb6be}
.wb__chips{display:flex;gap:6px;flex-wrap:wrap}
.wb__chip{cursor:pointer;font:inherit;font-size:.76rem;font-weight:700;padding:7px 12px;min-height:36px;border-radius:999px;border:1px solid var(--xr-line,#1d3540);background:var(--xr-card,#0c1218);color:#c9d4da;display:inline-flex;align-items:center;gap:6px}
.wb__chip small{color:var(--xr-muted,#5a7784);font-weight:400}
.wb__chip.on{border-color:#a8842a;background:rgba(242,199,102,.14);color:#f2d38a}
.wb__top{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.wb__title{flex:1;min-width:160px;font-weight:800;font-size:1rem}
.wb__title small{display:block;color:var(--xr-muted,#5a7784);font-weight:400;font-size:.72rem;margin-top:2px}
.wb__btns{display:flex;gap:6px;flex-wrap:wrap}
.wb__btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;cursor:pointer;font:inherit;font-weight:800;font-size:.82rem;padding:9px 13px;min-height:40px;border-radius:10px;border:1px solid #7a5a16;background:linear-gradient(180deg,#f2c766,#c99a2e);color:#1a1204;text-decoration:none;box-sizing:border-box;white-space:nowrap}
.wb__btn.ghost{background:transparent;color:#f2d38a}
.wb__btn.on{background:rgba(242,199,102,.22);color:#ffe29a;border-color:#a8842a}
.wb__btn:disabled{opacity:.4;cursor:default}
.wb__btn:active{transform:scale(.98)}
.wb__snap{border:1px solid #7a5a16;border-radius:14px;background:rgba(242,199,102,.06);padding:12px 14px;display:flex;flex-direction:column;gap:10px}
.wb__lbl{font-size:.68rem;color:var(--xr-muted,#5a7784);text-transform:uppercase;letter-spacing:.06em}
.wb__row{display:flex;gap:6px;flex-wrap:wrap;align-items:center}
.wb__row .wb__in{flex:1;min-width:140px;width:auto}
.wb__tl{position:relative;overflow-x:auto;overflow-y:hidden;border:1px solid var(--xr-line,#16232c);border-radius:12px;background:var(--xr-card,#0c1218);scrollbar-width:thin;-webkit-overflow-scrolling:touch}
.wb__tlin{position:relative;height:68px;min-width:100%}
.wb__mo{position:absolute;top:0;bottom:0;border-left:1px solid #17232c;box-sizing:border-box}
.wb__mo span{position:absolute;left:4px;bottom:3px;font-size:.6rem;color:#4f6572;white-space:nowrap}
.wb__tk{position:absolute;bottom:20px;padding:0;margin:0;border:0;cursor:pointer;background:#6b8797;transform:translateX(-50%)}
.wb__tk--git{width:3px;height:30px;border-radius:2px}
.wb__tk--manuel{width:11px;height:11px;border-radius:50%;bottom:30px;background:#f2c766;box-shadow:0 0 0 2px rgba(242,199,102,.25)}
.wb__tk:hover{background:#9fb6be}
.wb__tk.on{background:#ffe29a;height:40px;box-shadow:0 0 10px rgba(242,199,102,.6)}
.wb__tk--manuel.on{height:13px;width:13px}
.wb__tk::after{content:'';position:absolute;left:-8px;right:-8px;top:-8px;bottom:-8px} /* zone tactile */
.wb__count{font-size:.74rem;color:var(--xr-muted,#5a7784)}
.wb__count b{color:#f2d38a}
.wb__cols{display:flex;flex-direction:column;gap:12px;min-height:0}
.wb__list{display:flex;flex-direction:column;gap:6px;max-height:38vh;overflow:auto;-webkit-overflow-scrolling:touch}
.wb__it{display:flex;flex-direction:column;gap:3px;cursor:pointer;font:inherit;text-align:left;padding:9px 12px;border-radius:11px;border:1px solid var(--xr-line,#16232c);background:var(--xr-card,#0c1218);color:var(--xr-fg,#dfe8ee)}
.wb__it.on{border-color:#a8842a;background:rgba(242,199,102,.1)}
.wb__it1{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.wb__it1 b{font-size:.84rem}
.wb__badge{font-size:.6rem;font-weight:800;letter-spacing:.06em;text-transform:uppercase;padding:2px 7px;border-radius:20px;border:1px solid #26355c;background:#15233f;color:#7cc4ff}
.wb__badge.manuel{border-color:#7a5a16;background:#241a08;color:#f2c766}
.wb__it1 small{margin-left:auto;color:var(--xr-muted,#5a7784);font-size:.68rem;white-space:nowrap}
.wb__it2{font-size:.74rem;color:#9fb6be;line-height:1.4;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
.wb__it2 em{font-style:normal;color:#c9d4da}
.wb__prev{display:flex;flex-direction:column;gap:8px;border:1px solid var(--xr-line,#16232c);border-radius:14px;background:var(--xr-card,#0c1218);padding:10px;min-height:0}
.wb__pbar{display:flex;gap:6px;flex-wrap:wrap;align-items:center}
.wb__pbar .wb__btn{padding:7px 10px;min-height:36px;font-size:.76rem}
.wb__pt{flex:1;min-width:120px;font-size:.76rem;color:#c9d4da}
.wb__pt b{color:#ffe29a}
.wb__pbody{min-height:0}
.wb__if{display:block;width:100%;height:60vh;border:1px solid #1d2a34;border-radius:10px;background:#05080c}
.wb__pre{margin:0;padding:10px;max-height:60vh;overflow:auto;border:1px solid #1d2a34;border-radius:10px;background:#05080c;color:#9fb6be;font:.72rem/1.45 var(--xr-font-mono,ui-monospace,SFMono-Regular,Menlo,monospace);white-space:pre-wrap;word-break:break-word}
.wb__dl{display:block;padding:0 6px;border-radius:3px}
.wb__dl--add{background:rgba(63,224,140,.14);color:#9ff0c0}
.wb__dl--del{background:rgba(255,110,110,.14);color:#ffb3a8;text-decoration:line-through;text-decoration-color:rgba(255,110,110,.35)}
.wb__dl--skip{color:#4f6572;text-align:center;padding:4px 0;font-style:italic}
.wb__dsum{font-size:.74rem;color:#9fb6be;margin-bottom:6px}
.wb__same{padding:20px;text-align:center;color:#9ff0c0;font-size:.85rem}
@media (min-width:900px){
.wb__cols{flex-direction:row;align-items:stretch;flex:1;min-height:0}
.wb__list{flex:0 0 320px;max-height:none;overflow:auto}
.wb__prev{flex:1;min-width:0}
.wb__if,.wb__pre{height:calc(100vh - 330px);max-height:none;min-height:360px}
.wb__pre{height:auto;max-height:calc(100vh - 330px)}
}
</style>
<script>
(function () {
'use strict';
var ID = 'wayback', KEY = 'xb:wayback:last';
var esc = function (s) { return (window.jOSb && window.jOSb.esc) ? window.jOSb.esc(s) : String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]; }); };
function toast(m) { try { if (window.jOSb && window.jOSb.toast) return window.jOSb.toast(m); } catch (e) {} try { console.log('[wayback] ' + m); } catch (e2) {} }
var IDX = null, CUR = null; // IDX = /px/wayback/index.json ; CUR = { id, data } (pour describe() hors montage)
function qs(k) { try { return new URLSearchParams(location.search).get(k); } catch (e) { return null; } }
function getJSON(url) { return fetch(url, { credentials: 'same-origin', headers: { Accept: 'application/json' } }).then(function (r) { if (!r.ok) throw new Error(r.status + ' ' + url); return r.json(); }); }
function getText(url) { return fetch(url, { credentials: 'same-origin' }).then(function (r) { if (!r.ok) throw new Error(r.status + ' ' + url); return r.text(); }); }
function postJSON(url, body) {
if (window.jOSb && window.jOSb.postJSON) return window.jOSb.postJSON(url, body);
var m = document.querySelector('meta[name=csrf-token]');
return fetch(url, { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRF-TOKEN': m ? m.getAttribute('content') : '' }, body: JSON.stringify(body || {}) })
.then(function (r) { if (!r.ok) throw new Error(r.status + ' ' + url); return r.json(); });
}
function isAdmin() {
if (IDX && IDX.admin === true) return true;
if (CUR && CUR.data && CUR.data.admin === true) return true;
try { var m = document.querySelector('meta[name="user-admin"]'); if (m && m.getAttribute('content') === '1') return true; } catch (e) {}
return false;
}
function pad(n) { return (n < 10 ? '0' : '') + n; }
function dt(iso) { var d = new Date(iso); if (isNaN(d)) return iso || '?'; return pad(d.getDate()) + '.' + pad(d.getMonth() + 1) + '.' + d.getFullYear() + ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes()); }
function ko(n) { n = +n || 0; return n < 1024 ? n + ' o' : (n / 1024).toFixed(1) + ' Ko'; }
function abrev(id) { return String(id).split('-').map(function (p) { return /^\d+$/.test(p) ? p : p.charAt(0); }).join(''); }
function idPropre(s) { s = String(s || '').trim().toLowerCase(); return /^[a-z0-9][a-z0-9-]{0,63}$/.test(s) ? s : ''; }
function ploxions() { return (IDX && Array.isArray(IDX.ploxions)) ? IDX.ploxions : []; }
// ---- diff ligne à ligne (préfixe/suffixe communs + LCS sur le milieu ; au-delà de 4 M cellules : blocs entiers) ----
function diffLines(a, b) {
var A = String(a).split('\n'), B = String(b).split('\n'), out = [], p = 0, s = 0, i, j;
while (p < A.length && p < B.length && A[p] === B[p]) p++;
while (s < A.length - p && s < B.length - p && A[A.length - 1 - s] === B[B.length - 1 - s]) s++;
for (i = 0; i < p; i++) out.push([' ', A[i]]);
var Am = A.slice(p, A.length - s), Bm = B.slice(p, B.length - s), n = Am.length, m = Bm.length;
if (n && m && n * m <= 4000000) {
var W = m + 1, dp = new Uint16Array((n + 1) * W);
for (i = n - 1; i >= 0; i--) for (j = m - 1; j >= 0; j--) dp[i * W + j] = Am[i] === Bm[j] ? dp[(i + 1) * W + j + 1] + 1 : Math.max(dp[(i + 1) * W + j], dp[i * W + j + 1]);
i = 0; j = 0;
while (i < n && j < m) {
if (Am[i] === Bm[j]) { out.push([' ', Am[i]]); i++; j++; }
else if (dp[(i + 1) * W + j] >= dp[i * W + j + 1]) { out.push(['-', Am[i]]); i++; }
else { out.push(['+', Bm[j]]); j++; }
}
while (i < n) out.push(['-', Am[i++]]);
while (j < m) out.push(['+', Bm[j++]]);
} else {
for (i = 0; i < n; i++) out.push(['-', Am[i]]);
for (j = 0; j < m; j++) out.push(['+', Bm[j]]);
}
for (i = A.length - s; i < A.length; i++) out.push([' ', A[i]]);
return out;
}
function renderDiff(lines) {
var n = lines.length, CTX = 3, show = new Array(n), any = false, i, k;
for (i = 0; i < n; i++) if (lines[i][0] !== ' ') { any = true; for (k = Math.max(0, i - CTX); k <= Math.min(n - 1, i + CTX); k++) show[k] = true; }
if (!any) return '<div class="wb__same">✓ identique à l\'actuel</div>';
var html = '', hidden = 0, add = 0, del = 0;
for (i = 0; i < n; i++) {
if (!show[i]) { hidden++; continue; }
if (hidden) { html += '<span class="wb__dl wb__dl--skip">⋯ ' + hidden + ' lignes identiques</span>'; hidden = 0; }
var t = lines[i][0]; if (t === '+') add++; if (t === '-') del++;
html += '<span class="wb__dl' + (t === '+' ? ' wb__dl--add' : t === '-' ? ' wb__dl--del' : '') + '">' + esc(t + ' ' + lines[i][1]) + '</span>';
}
if (hidden) html += '<span class="wb__dl wb__dl--skip">⋯ ' + hidden + ' lignes identiques</span>';
return '<div class="wb__dsum">−' + del + ' / +' + add + ' lignes (cette version → l\'actuel)</div><pre class="wb__pre">' + html + '</pre>';
}
// ---- la timeline : une colonne par mois, ticks positionnés au jour près ----
function monthKey(d) { return d.getFullYear() * 12 + d.getMonth(); }
function renderTimeline(el, versions, selV) {
var dates = versions.map(function (v) { return new Date(v.quand); }).filter(function (d) { return !isNaN(d); });
if (!dates.length) { el.innerHTML = '<div class="wb__empty" style="padding:10px 12px">aucune version datée</div>'; return; }
var MW = 64, keys = dates.map(monthKey), min = Math.min.apply(null, keys), max = Math.max.apply(null, keys), months = max - min + 1;
var html = '<div class="wb__tlin" style="width:' + (months * MW) + 'px">';
for (var k = 0; k < months; k++) { var mk = min + k, y = Math.floor(mk / 12), mo = mk % 12; html += '<div class="wb__mo" style="left:' + (k * MW) + 'px;width:' + MW + 'px"><span>' + pad(mo + 1) + '.' + String(y).slice(2) + '</span></div>'; }
versions.forEach(function (v) {
var d = new Date(v.quand); if (isNaN(d)) return;
var days = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
var x = (monthKey(d) - min) * MW + ((d.getDate() - 1 + d.getHours() / 24) / days) * MW;
html += '<button type="button" class="wb__tk wb__tk--' + (v.genre === 'manuel' ? 'manuel' : 'git') + (v.v === selV ? ' on' : '') + '" style="left:' + x.toFixed(1) + 'px" data-v="' + esc(v.v) + '" title="' + esc(dt(v.quand) + ' · ' + v.genre + (v.message ? ' · ' + v.message : '')) + '" aria-label="' + esc(dt(v.quand)) + '"></button>';
});
el.innerHTML = html + '</div>';
}
function describe() {
var d = CUR && CUR.data, vs = (d && Array.isArray(d.versions)) ? d.versions : [], last = vs[0], items = [];
if (d) {
items.push({ p: 1, kind: 'stat', label: 'versions · ' + CUR.id, value: vs.length });
items.push({ p: 2, kind: 'text', label: 'dernière version', value: last ? (dt(last.quand) + ' · ' + last.genre + (last.message ? ' · ' + last.message : '')) : '—' });
items.push({ p: 3, kind: 'action', label: '📸 instantané', act: { port: 'ploxion.wayback.cmd', payload: { cmd: 'snapshot', ploxion: CUR.id } } });
} else {
items.push({ p: 1, kind: 'stat', label: 'ploxions suivis', value: IDX ? (IDX.count || ploxions().length) : 0 });
items.push({ p: 2, kind: 'text', label: 'wayback', value: 'choisis un ploxion' });
}
return { v: 1, id: ID, title: 'Wayback', icon: '🕰', items: items };
}
function mount(container, ctx) {
ctx = ctx || {};
var params = ctx.params || {};
var want = idPropre(ctx.ploxion || params.ploxion || qs('ploxion') || '');
if (!want) { try { want = idPropre(localStorage.getItem(KEY) || ''); } catch (e0) {} }
var alive = true, offPort = null, pid = null, data = null, sel = null, mode = 'apercu', snapOpen = false, srcCache = {}, nsSel = {};
container.innerHTML = '<div class="wb">'
+ '<div class="wb__h"><div class="wb__ht">🕰 Wayback <small>l\'histoire de chaque ploxion — comme sur la Wayback Machine</small></div>'
+ '<div class="wb__pick"><input class="wb__in" type="search" placeholder="un ploxion… (pourriture-4)" autocomplete="off" spellcheck="false" data-in><div class="wb__sug" data-sug hidden></div></div></div>'
+ '<div class="wb__body" data-body><div class="wb__empty">chargement…</div></div></div>';
var root = container.querySelector('.wb'), body = root.querySelector('[data-body]'), input = root.querySelector('[data-in]'), sug = root.querySelector('[data-sug]');
// ---- recherche d'un ploxion ----
function suggest() {
var q = input.value.trim().toLowerCase(), list = ploxions();
if (!q) { sug.hidden = true; return; }
var hits = list.filter(function (p) { return p.id.indexOf(q) >= 0; }).slice(0, 12);
if (!hits.length) { sug.innerHTML = '<button type="button" disabled>aucun ploxion « ' + esc(q) + ' »</button>'; sug.hidden = false; return; }
sug.innerHTML = hits.map(function (p) { return '<button type="button" data-pick="' + esc(p.id) + '">' + esc(p.icon || '▫') + ' ' + esc(p.id) + '<small>' + (p.total || 0) + ' v · ' + esc((p.derniere || '').slice(0, 10)) + '</small></button>'; }).join('');
sug.hidden = false;
}
input.addEventListener('input', suggest);
input.addEventListener('focus', suggest);
input.addEventListener('keydown', function (e) { if (e.key === 'Enter') { var v = idPropre(input.value); if (v) { sug.hidden = true; ouvrir(v); } } if (e.key === 'Escape') sug.hidden = true; });
sug.addEventListener('click', function (e) { var b = e.target.closest('[data-pick]'); if (!b) return; sug.hidden = true; input.value = b.getAttribute('data-pick'); ouvrir(b.getAttribute('data-pick')); });
document.addEventListener('click', function onDoc(e) { if (!alive) { document.removeEventListener('click', onDoc); return; } if (!root.contains(e.target) || !e.target.closest('.wb__pick')) sug.hidden = true; });
// ---- l'accueil : tous les ploxions suivis, les plus récemment changés d'abord ----
function renderAccueil() {
var list = ploxions().slice().sort(function (a, b) { return (b.derniere || '').localeCompare(a.derniere || ''); });
var tot = list.reduce(function (s, p) { return s + (p.total || 0); }, 0);
body.innerHTML = '<p class="wb__hint">Chaque ploxion est un repo : voici son histoire. <b>' + list.length + '</b> ploxions suivis · <b>' + tot + '</b> versions (git = trait, 📸 instantané manuel = point). Choisis un ploxion :</p>'
+ (list.length ? '<div class="wb__chips">' + list.map(function (p) { return '<button type="button" class="wb__chip" data-pick="' + esc(p.id) + '">' + esc(p.icon || '▫') + ' ' + esc(p.id) + ' <small>' + (p.total || 0) + '</small></button>'; }).join('') + '</div>'
: '<div class="wb__empty">aucune version exportée pour l\'instant — l\'hôte remplit storage/app/wayback (fleet/wayback-refresh.sh), ou tu n\'es pas connecté.</div>');
}
body.addEventListener('click', function (e) {
var b = e.target.closest('[data-pick]'); if (b) { input.value = b.getAttribute('data-pick'); ouvrir(b.getAttribute('data-pick')); return; }
var tk = e.target.closest('[data-v]'); if (tk) { select(tk.getAttribute('data-v')); return; }
var a = e.target.closest('[data-act]'); if (a) { action(a.getAttribute('data-act'), a); }
});
// ---- un ploxion : timeline + liste + aperçu ----
function ouvrir(id) {
id = idPropre(id); if (!id) return;
pid = id; sel = null; mode = 'apercu'; snapOpen = false; srcCache = {};
try { localStorage.setItem(KEY, id); } catch (e) {}
body.innerHTML = '<div class="wb__empty">chargement de l\'histoire de « ' + esc(id) + ' »…</div>';
getJSON('/px/wayback/' + encodeURIComponent(id) + '/index.json').then(function (d) {
if (!alive || pid !== id) return;
data = (d && Array.isArray(d.versions)) ? d : { ploxion: id, versions: [], ns: [id, abrev(id)], actuel: { existe: false } };
data.versions = data.versions.filter(function (v) { return v && v.v; });
CUR = { id: id, data: data };
nsSel = {}; (data.ns || [id, abrev(id)]).forEach(function (n) { nsSel[n] = true; });
renderPloxion();
if (data.versions.length) select(data.versions[0].v, true);
}).catch(function (e) {
if (!alive || pid !== id) return;
body.innerHTML = '<div class="wb__empty">impossible de lire l\'histoire de « ' + esc(id) + ' » (' + esc(e && e.message) + ') — connecté ?</div>';
});
}
function versions() { return (data && data.versions) || []; }
function selIndex() { var vs = versions(); for (var i = 0; i < vs.length; i++) if (vs[i].v === sel) return i; return -1; }
function renderPloxion() {
var vs = versions(), git = vs.filter(function (v) { return v.genre === 'git'; }).length, man = vs.length - git;
body.innerHTML = '<div class="wb__top"><div class="wb__title">' + esc(data.icon || '🕰') + ' ' + esc(pid)
+ '<small class="wb__count"><b>' + vs.length + '</b> version' + (vs.length > 1 ? 's' : '') + ' · ' + git + ' git · ' + man + ' instantané' + (man > 1 ? 's' : '') + (data.commit_labo ? ' · labo ' + esc(data.commit_labo) : '') + '</small></div>'
+ '<div class="wb__btns">' + (isAdmin() ? '<button type="button" class="wb__btn" data-act="snap-toggle">📸 Instantané maintenant</button>' : '')
+ '<a class="wb__btn ghost" href="/px/' + esc(pid) + '" target="_blank" rel="noopener">↗ actuel</a></div></div>'
+ '<div class="wb__snap" data-snap hidden></div>'
+ '<div class="wb__tl" data-tl></div>'
+ '<div class="wb__cols"><div class="wb__list" data-list></div><div class="wb__prev" data-prev></div></div>';
renderTimeline(body.querySelector('[data-tl]'), vs.slice().reverse(), sel);
renderList();
renderPrev();
var tl = body.querySelector('[data-tl]'); try { tl.scrollLeft = tl.scrollWidth; } catch (e) {}
}
function renderList() {
var el = body.querySelector('[data-list]'); if (!el) return;
var vs = versions();
if (!vs.length) { el.innerHTML = '<div class="wb__empty">aucune version : l\'export git de l\'hôte n\'est pas encore passé (fleet/wayback-refresh.sh)' + (isAdmin() ? ', mais tu peux prendre un 📸 instantané dès maintenant' : '') + '.</div>'; return; }
el.innerHTML = vs.map(function (v) {
return '<button type="button" class="wb__it' + (v.v === sel ? ' on' : '') + '" data-v="' + esc(v.v) + '">'
+ '<span class="wb__it1"><b>' + esc(dt(v.quand)) + '</b><span class="wb__badge ' + esc(v.genre) + '">' + esc(v.genre) + '</span><small>' + esc(v.v) + ' · ' + ko(v.taille) + '</small></span>'
+ '<span class="wb__it2">' + (v.auteur ? '<em>' + esc(v.auteur) + '</em> · ' : '') + esc(v.message || (v.genre === 'manuel' ? 'instantané manuel' : '—'))
+ (v.genre === 'manuel' ? ' · ' + (v.kv || 0) + ' KV · ' + (v.fichiers || 0) + ' fichiers' : '') + '</span></button>';
}).join('');
}
function select(v, keepMode) {
sel = v; if (!keepMode) mode = 'apercu';
var list = body.querySelector('[data-list]');
if (list) { Array.prototype.forEach.call(list.querySelectorAll('.wb__it'), function (b) { b.classList.toggle('on', b.getAttribute('data-v') === v); }); }
var tl = body.querySelector('[data-tl]');
if (tl) { Array.prototype.forEach.call(tl.querySelectorAll('.wb__tk'), function (b) { b.classList.toggle('on', b.getAttribute('data-v') === v); var onb = b.classList.contains('on'); if (onb) { try { var x = b.offsetLeft - tl.clientWidth / 2; if (x > tl.scrollLeft + tl.clientWidth - 40 || x + tl.clientWidth < tl.scrollLeft) tl.scrollLeft = Math.max(0, x); } catch (e) {} } }); }
renderPrev();
}
function urlV(v) { return '/px/wayback/' + encodeURIComponent(pid) + '/' + encodeURIComponent(v); }
function renderPrev() {
var el = body.querySelector('[data-prev]'); if (!el) return;
var vs = versions(), i = selIndex(), v = i >= 0 ? vs[i] : null;
if (!v) { el.innerHTML = '<div class="wb__empty">sélectionne une version (liste ou timeline) pour la voir telle qu\'elle était.</div>'; return; }
el.innerHTML = '<div class="wb__pbar">'
+ '<button type="button" class="wb__btn ghost" data-act="prec" title="version précédente (plus ancienne)"' + (i >= vs.length - 1 ? ' disabled' : '') + '>⏮</button>'
+ '<button type="button" class="wb__btn ghost" data-act="suiv" title="version suivante (plus récente)"' + (i <= 0 ? ' disabled' : '') + '>⏭</button>'
+ '<span class="wb__pt"><b>' + esc(dt(v.quand)) + '</b> · ' + esc(v.genre) + ' · ' + esc(v.v) + '</span>'
+ '<button type="button" class="wb__btn ghost' + (mode === 'apercu' ? ' on' : '') + '" data-act="mode-apercu">👁 Aperçu</button>'
+ '<button type="button" class="wb__btn ghost' + (mode === 'code' ? ' on' : '') + '" data-act="mode-code">Code</button>'
+ '<button type="button" class="wb__btn ghost' + (mode === 'diff' ? ' on' : '') + '" data-act="mode-diff">Comparer avec l\'actuel</button>'
+ '<button type="button" class="wb__btn" data-act="grand">↗ Ouvrir en grand</button>'
+ '</div><div class="wb__pbody" data-pbody></div>';
var pb = el.querySelector('[data-pbody]');
if (mode === 'apercu') {
pb.innerHTML = '<iframe class="wb__if" src="' + esc(urlV(v.v)) + '" title="' + esc(pid + ' @ ' + v.v) + '" loading="lazy" sandbox="allow-scripts allow-same-origin allow-forms allow-popups"></iframe>';
} else if (mode === 'code') {
pb.innerHTML = '<pre class="wb__pre">chargement de la source…</pre>';
source(v.v).then(function (s) { if (alive && sel === v.v && mode === 'code') pb.innerHTML = '<pre class="wb__pre">' + esc(s) + '</pre>'; })
.catch(function (e) { if (alive) pb.innerHTML = '<div class="wb__empty">source indisponible (' + esc(e && e.message) + ')</div>'; });
} else {
pb.innerHTML = '<pre class="wb__pre">comparaison en cours…</pre>';
Promise.all([source(v.v), source('actuel')]).then(function (r) {
if (!alive || sel !== v.v || mode !== 'diff') return;
pb.innerHTML = renderDiff(diffLines(r[0], r[1]));
}).catch(function (e) { if (alive) pb.innerHTML = '<div class="wb__empty">comparaison impossible (' + esc(e && e.message) + ')</div>'; });
}
}
function source(v) { if (srcCache[v] !== undefined) return Promise.resolve(srcCache[v]); return getText(urlV(v) + '/source').then(function (s) { srcCache[v] = s; return s; }); }
// ---- 📸 instantané (admin) ----
function renderSnap() {
var el = body.querySelector('[data-snap]'); if (!el) return;
el.hidden = !snapOpen; if (!snapOpen) return;
var props = (data.ns && data.ns.length ? data.ns : [pid, abrev(pid)]).slice();
Object.keys(nsSel).forEach(function (n) { if (props.indexOf(n) < 0) props.push(n); });
el.innerHTML = '<div class="wb__lbl">📸 instantané manuel de « ' + esc(pid) + ' » — code + config + KV du boxion + index des fichiers</div>'
+ '<div class="wb__row"><input class="wb__in" type="text" maxlength="400" placeholder="note (ex. état avant le chantier…)" data-note></div>'
+ '<div class="wb__lbl">namespaces KV à emporter</div><div class="wb__chips" data-ns>'
+ props.map(function (n) { return '<button type="button" class="wb__chip' + (nsSel[n] ? ' on' : '') + '" data-ns-toggle="' + esc(n) + '">' + esc(n) + '</button>'; }).join('')
+ '<button type="button" class="wb__chip" data-act="ns-add">+ ns</button></div>'
+ '<div class="wb__row"><button type="button" class="wb__btn" data-act="snap-go">📸 Prendre l\'instantané</button><button type="button" class="wb__btn ghost" data-act="snap-toggle">annuler</button></div>';
el.querySelector('[data-ns]').addEventListener('click', function (e) { var b = e.target.closest('[data-ns-toggle]'); if (!b) return; var n = b.getAttribute('data-ns-toggle'); nsSel[n] = !nsSel[n]; b.classList.toggle('on', !!nsSel[n]); });
}
function snapshot(note) {
if (!pid) return Promise.resolve(null);
var ns = Object.keys(nsSel).filter(function (n) { return nsSel[n]; });
toast('📸 instantané de ' + pid + '…');
return postJSON('/px/wayback/' + encodeURIComponent(pid) + '/snapshot', { note: note || '', ns: ns }).then(function (r) {
if (!alive) return r;
if (!r || !r.ok || !r.version) { toast('instantané refusé'); return r; }
toast('📸 instantané pris : ' + dt(r.version.quand));
snapOpen = false;
data.versions.unshift(r.version); CUR = { id: pid, data: data };
renderPloxion(); select(r.version.v);
try { if (window.jOSPorts && window.jOSPorts.emit) window.jOSPorts.emit('ploxion.wayback.snapshot', { ploxion: pid, version: r.version }); } catch (e) {}
return r;
}).catch(function (e) { toast('instantané impossible (' + (e && e.message) + ') — admin ?'); return null; });
}
function action(a, btn) {
var vs = versions(), i = selIndex();
if (a === 'prec') { if (i >= 0 && i < vs.length - 1) select(vs[i + 1].v, true); }
else if (a === 'suiv') { if (i > 0) select(vs[i - 1].v, true); }
else if (a === 'mode-apercu' || a === 'mode-code' || a === 'mode-diff') { mode = a.slice(5); renderPrev(); }
else if (a === 'grand') { if (sel) { try { window.open(urlV(sel), '_blank', 'noopener'); } catch (e) { location.href = urlV(sel); } } }
else if (a === 'snap-toggle') { snapOpen = !snapOpen; renderSnap(); if (snapOpen) { try { body.querySelector('[data-note]').focus(); } catch (e) {} } }
else if (a === 'ns-add') { var n = String(window.prompt('namespace KV à emporter (ex. p4)') || '').trim().toLowerCase(); if (n && /^[a-z0-9][a-z0-9._-]{0,39}$/.test(n)) { nsSel[n] = true; renderSnap(); } }
else if (a === 'snap-go') { var ne = body.querySelector('[data-note]'); btn.disabled = true; snapshot(ne ? ne.value : '').then(function () { if (alive && btn) btn.disabled = false; }); }
}
// ---- le bus : XUI (describe → act) et les autres ploxions ----
if (window.jOSPorts && window.jOSPorts.on) offPort = window.jOSPorts.on('ploxion.wayback.cmd', function (p) {
if (container.isConnected === false) { alive = false; try { offPort && offPort(); } catch (e0) {} return; }
if (!alive) return;
p = p || {};
var target = idPropre(p.ploxion || pid || '');
if (p.cmd === 'snapshot') { if (target && target !== pid) { ouvrir(target); setTimeout(function () { if (alive && pid === target) snapshot(p.note || ''); }, 700); } else if (pid) snapshot(p.note || ''); }
else if (p.cmd === 'ouvrir' && target) { input.value = target; ouvrir(target); }
});
// ---- départ ----
getJSON('/px/wayback/index.json').then(function (d) { IDX = (d && typeof d === 'object') ? d : { ploxions: [] }; if (!Array.isArray(IDX.ploxions)) IDX.ploxions = []; })
.catch(function () { IDX = IDX || { ploxions: [] }; })
.then(function () { if (!alive) return; if (want) { input.value = want; ouvrir(want); } else renderAccueil(); });
return { unmount: function () { alive = false; try { if (offPort) offPort(); } catch (e) {} container.innerHTML = ''; } };
}
window.jOSApps = window.jOSApps || {};
window.jOSApps[ID] = { manifest: { id: ID, name: 'Wayback', icon: '🕰' }, mount: mount, describe: describe };
})();
</script>