synchro du labo (0bf0da65) : app.blade.php, README.md

This commit is contained in:
cloudion
2026-11-03 22:39:03 +00:00
commit 197b5a7d1b
2 changed files with 167 additions and 0 deletions

146
app.blade.php Normal file
View File

@@ -0,0 +1,146 @@
{{-- PL0XION circuit ▣ — un circuit de logisim devenu BION (RS-7 30.10 : « des input et output de logisim utilisables comme bions pour en
faire un xer »). Pas d'éditeur : les ENTRÉES du circuit en broches à cliquer (ou un nombre pour un bus), ses SORTIES en voyants, comme
Logisim ; à poser dans un xer comme n'importe quel ploxion.
· la source : un bloc de ma bibliothèque (?b=nom), un circuit public (?c=slug, sans compte), ou le circuit ouvert dans logisim ;
le choix reste attaché à l'instance (ctx.k) dans ce navigateur.
· le bus jOSPorts : chaque sortie part en `ploxion.circuit.sortie` {circuit, broche, v, de} et `ploxion.circuit.<broche>` (un nombre) ;
une sortie d'un AUTRE circuit (ou de logisim) qui porte le nom d'une de mes entrées la pilote — les broches de même nom sont
reliées d'un ploxion à l'autre, comme des tunnels ; `ploxion.circuit.entree` {broche, v[, circuit]} pilote une entrée à la main.
Le moteur : jOSCircuit.instance (partials/_circuit_bion). Rien ne tourne en fond (l'horloge : ⏵ à la main). --}}
@include('partials._circuit_bion')
<style>
.cbn{position:absolute;inset:0;display:flex;flex-direction:column;background:#fff;color:#111;font:13px/1.35 var(--xr-font-ui,ui-sans-serif,system-ui);overflow:auto}
.cbn header{display:flex;align-items:center;gap:6px;padding:7px 10px;border-bottom:1px solid #ddd;background:#f4f4f4}
.cbn header b{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.cbn button{font:inherit;border:1px solid #999;background:#fff;border-radius:5px;padding:3px 8px;cursor:pointer;color:#111}
.cbn button:hover{border-color:#333}
.cbn__c{display:grid;grid-template-columns:1fr 1fr;gap:4px 18px;padding:10px 12px}
.cbn__col h4{margin:0 0 6px;font-size:.66rem;letter-spacing:.08em;text-transform:uppercase;color:#666;font-weight:600}
.cbn__b{display:flex;align-items:center;gap:8px;padding:3px 0}
.cbn__b span{font-family:ui-monospace,monospace;font-size:.82rem;overflow:hidden;text-overflow:ellipsis}
.cbn__in{width:24px;height:24px;border:2px solid #000;background:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;flex:0 0 auto;padding:0}
.cbn__in i,.cbn__out i{width:15px;height:15px;border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;font:700 11px ui-monospace,monospace;font-style:normal}
.cbn__out{width:24px;height:24px;border:2px solid #000;border-radius:50%;display:flex;align-items:center;justify-content:center;flex:0 0 auto}
.cbn__n{width:64px;border:2px solid #000;padding:2px 4px;font:12px ui-monospace,monospace}
.cbn__v{font:12px ui-monospace,monospace;border:2px solid #000;border-radius:8px;padding:1px 6px;min-width:40px;text-align:center}
.cbn__note{padding:6px 12px;color:#666;font-size:.74rem}
.cbn__liste{padding:6px 10px}
.cbn__it{display:flex;gap:8px;align-items:center;padding:6px 8px;border:1px solid #ddd;border-radius:6px;margin:4px 0;cursor:pointer}
.cbn__it:hover{border-color:#333}.cbn__it small{color:#777;margin-left:auto}
</style>
<script>
(function () {
'use strict';
var ID = 'circuit', C = window.jOSCircuit;
function esc(s) { return String(s === undefined || s === null ? '' : s).replace(/[&<>"']/g, function (c) { return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]; }); }
function ls(k, v) { try { if (v === undefined) return localStorage.getItem(k); if (v === null) localStorage.removeItem(k); else localStorage.setItem(k, v); } catch (e) { return null; } }
function qs(k) { try { return new URLSearchParams(location.search).get(k); } catch (e) { return null; } }
var V1 = '#00d200', V0 = '#006400', VX = '#2828ff';
var dernier = null;
function describe() {
var d = dernier;
if (!d) return { v: 1, id: ID, title: 'Circuit', icon: '▣', items: [{ p: 1, kind: 'text', label: 'circuit', value: '—' }] };
var r = d.inst.sorties_v(), items = Object.keys(r).slice(0, 6).map(function (k, i) { return { p: i + 1, kind: 'stat', label: k, value: r[k] === null ? 'x' : String(r[k]) }; });
return { v: 1, id: ID, title: d.nom, icon: '▣', items: items };
}
function mount(container, ctx) {
ctx = ctx || {};
var cle = 'xb:circuit:' + String(ctx.k || ctx.id || 'defaut').slice(0, 60), moi = 'c' + Math.random().toString(36).slice(2, 8);
var R = document.createElement('div'); R.className = 'cbn'; container.appendChild(R);
var st = { inst: null, nom: '', source: null, offs: [], projet: null };
function P() { return window.jOSPorts; }
function poserInst(projet, nom, source) {
st.offs.forEach(function (f) { try { f(); } catch (e) {} }); st.offs = [];
var inst = C.instance(projet, nom);
if (!inst) { R.innerHTML = '<div class="cbn__note">✗ circuit « ' + esc(nom) + ' » introuvable</div>'; return; }
st.inst = inst; st.nom = nom; st.source = source; st.projet = projet; dernier = st;
ls(cle, JSON.stringify(source));
st.offs.push(inst.on(function (ch) {
var p = P(); if (p) Object.keys(ch).forEach(function (b) { p.emit(ID, 'sortie', { circuit: nom, broche: b, v: ch[b], de: moi }); p.emit(ID, b, ch[b]); });
rendre();
}));
// les broches de même nom : la sortie d'un autre circuit (ou de l'éditeur logisim) pilote mon entrée
var p = P();
if (p) {
var entre = function (d) {
if (!d || d.de === moi || typeof d.broche !== 'string') return;
if (d.circuit && d.cible && d.cible !== nom) return;
if (inst.entrees.some(function (e) { return e.nom === d.broche; }) && d.v !== null && d.v !== undefined) { inst.poser(d.broche, d.v); rendre(); }
};
st.offs.push(p.on('ploxion.circuit.sortie', entre), p.on('ploxion.logisim.sortie', entre));
st.offs.push(p.on('ploxion.circuit.entree', function (d) { if (d && (!d.circuit || d.circuit === nom)) entre({ broche: d.broche, v: d.v, de: 'main' }); }));
}
rendre();
// annoncer mes sorties au départ (un circuit posé après les autres se synchronise)
if (p) { var r = inst.sorties_v(); Object.keys(r).forEach(function (b) { p.emit(ID, 'sortie', { circuit: nom, broche: b, v: r[b], de: moi }); }); }
}
function voyant(v, w) {
if (w > 1) return '<span class="cbn__v" style="color:' + (v === null ? VX : '#000') + '">' + (v === null ? 'x' : esc(v.toString(2).padStart(w, '0'))) + '</span>';
return '<span class="cbn__out"><i style="background:' + (v === 1 ? V1 : v === 0 ? V0 : VX) + '">' + (v === null ? 'x' : v) + '</i></span>';
}
function rendre() {
var i = st.inst; if (!i) return;
var ve = i.entrees_v(), vs = i.sorties_v();
R.innerHTML = '<header><b>▣ ' + esc(st.nom) + '</b>' + (i.sequentiel ? '<button data-tic title="un demi-tic d\'horloge">⏵|</button>' : '') + '<button data-choisir title="un autre circuit">⇄</button><button data-logisim title="ouvrir dans logisim">⊼</button></header>' +
'<div class="cbn__c"><div class="cbn__col"><h4>entrées</h4>' + (i.entrees.length ? i.entrees.map(function (e) {
var v = ve[e.nom];
return '<div class="cbn__b">' + (e.w === 1 ? '<button class="cbn__in" data-bascule="' + esc(e.nom) + '" title="basculer"><i style="background:' + (v === 1 ? V1 : V0) + '">' + (v === 1 ? 1 : 0) + '</i></button>' : '<input class="cbn__n" data-nombre="' + esc(e.nom) + '" value="' + (v === null ? 0 : v) + '" inputmode="numeric" title="' + e.w + ' bits">') + '<span>' + esc(e.nom) + (e.w > 1 ? '[' + e.w + ']' : '') + '</span></div>';
}).join('') : '<div class="cbn__note">aucune</div>') + '</div>' +
'<div class="cbn__col"><h4>sorties</h4>' + (i.sorties.length ? i.sorties.map(function (s) { return '<div class="cbn__b">' + voyant(vs[s.nom], s.w) + '<span>' + esc(s.nom) + '</span></div>'; }).join('') : '<div class="cbn__note">aucune</div>') + '</div></div>' +
'<div class="cbn__note">bus : <code>ploxion.circuit.sortie</code> · une sortie d\'un autre circuit qui porte le nom d\'une de ces entrées la pilote</div>';
}
function choisir() {
R.innerHTML = '<header><b>▣ quel circuit ?</b></header><div class="cbn__liste" data-l><div class="cbn__note">…</div></div>';
var L = R.querySelector('[data-l]'), h = '';
var auto = null; try { auto = JSON.parse(ls('xb:logisim:auto') || 'null'); } catch (e) {}
if (auto && auto.circuits) Object.keys(auto.circuits).forEach(function (n) { h += '<div class="cbn__it" data-src=\'' + esc(JSON.stringify({ t: 'logisim', n: n })) + '\'>⊼ ' + esc(n) + '<small>ouvert dans logisim</small></div>'; });
L.innerHTML = h || '<div class="cbn__note">…</div>';
var B = window.jOSBoxion;
var p1 = B && B.get ? Promise.resolve(B.get('logisim', 'biblio')).catch(function () { return null; }) : Promise.resolve(null);
var p2 = fetch('/px/logisim/publics.json', { headers: { Accept: 'application/json' } }).then(function (r) { return r.json(); }).catch(function () { return null; });
Promise.all([p1, p2]).then(function (r) {
var bib = r[0], pub = r[1];
if (bib && bib.blocs) Object.keys(bib.blocs).forEach(function (n) { h += '<div class="cbn__it" data-src=\'' + esc(JSON.stringify({ t: 'biblio', n: n })) + '\'>⧉ ' + esc(n) + '<small>ma bibliothèque</small></div>'; });
((pub && pub.circuits) || []).slice(0, 60).forEach(function (c) { h += '<div class="cbn__it" data-src=\'' + esc(JSON.stringify({ t: 'public', s: c.slug })) + '\'>◎ ' + esc(c.nom) + '<small>public · ' + esc(c.auteur) + '</small></div>'; });
L.innerHTML = h || '<div class="cbn__note">aucun circuit : fais-en un dans ⊼ logisim (« ↑ ce bloc » ou ◎ public)</div>';
});
}
function charger(src) {
if (!src) return choisir();
if (src.t === 'logisim') { var a = null; try { a = JSON.parse(ls('xb:logisim:auto') || 'null'); } catch (e) {} if (a && a.circuits && a.circuits[src.n]) return poserInst(a, src.n, src); return choisir(); }
if (src.t === 'biblio') {
var B = window.jOSBoxion; if (!B || !B.get) return choisir();
return Promise.resolve(B.get('logisim', 'biblio')).then(function (bib) { var e = bib && bib.blocs && bib.blocs[src.n]; if (!e) return choisir(); poserInst({ v: 1, nom: src.n, main: e.racine || src.n, circuits: e.circuits }, e.racine || src.n, src); }).catch(choisir);
}
if (src.t === 'public') {
return fetch('/px/logisim/c/' + encodeURIComponent(src.s)).then(function (r) { if (!r.ok) throw 0; return r.text(); }).then(function (t) {
var res = C.depuisCirc(t, src.s); if (res.erreur) throw 0; poserInst(res.projet, res.projet.main, src);
}).catch(choisir);
}
choisir();
}
R.addEventListener('click', function (ev) {
var a;
if ((a = ev.target.closest('[data-bascule]'))) { var n = a.getAttribute('data-bascule'), v = st.inst.entrees_v()[n]; st.inst.poser(n, v === 1 ? 0 : 1); rendre(); return; }
if (ev.target.closest('[data-tic]')) { st.inst.tic(); rendre(); return; }
if (ev.target.closest('[data-choisir]')) { choisir(); return; }
if (ev.target.closest('[data-logisim]')) { var u = st.source && st.source.t === 'public' ? '/px/logisim?c=' + encodeURIComponent(st.source.s) : '/px/logisim'; try { if (window.jOS && window.jOS.openPloxion && !(st.source && st.source.t === 'public')) { window.jOS.openPloxion('logisim'); return; } } catch (e) {} location.href = u; return; }
if ((a = ev.target.closest('[data-src]'))) { try { charger(JSON.parse(a.getAttribute('data-src'))); } catch (e) {} }
});
R.addEventListener('change', function (ev) { var a = ev.target.closest('[data-nombre]'); if (a) { st.inst.poser(a.getAttribute('data-nombre'), parseInt(a.value, a.value.indexOf('0x') === 0 ? 16 : 10) || 0); rendre(); } });
var depart = ctx.c || qs('c') ? { t: 'public', s: ctx.c || qs('c') } : ctx.b || qs('b') ? { t: 'biblio', n: ctx.b || qs('b') } : null;
if (!depart) { try { depart = JSON.parse(ls(cle) || 'null'); } catch (e) {} }
charger(depart);
return { unmount: function () { st.offs.forEach(function (f) { try { f(); } catch (e) {} }); if (dernier === st) dernier = null; container.innerHTML = ''; } };
}
window.jOSApps = window.jOSApps || {};
window.jOSApps[ID] = { manifest: { id: ID, name: 'Circuit', icon: '▣' }, mount: mount, describe: describe };
})();
</script>