Files
ploxion-portion/app.blade.php

507 lines
48 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 portion — le PORTION = des CARRÉS dans des CARRÉS (RS-7, cahier rs-flay
p.22/29/32/33 : « découvre tous les modes du portion, comme tu découvres tous
les modes du wormion »). Pendant carré du `zoom` (wormion=ronds). Zoom infini à
la molette + 4 MODES : concentrique · spirale · cube (carré dans carré) ·
hypercube (carré³). Des koins (triangles) aux coins, façon cahier. 100% canvas.
window.jOSApps['portion']. mount(c, ctx) -> { unmount }.
LOT BUREAU v2 (25.09.2026, docs/dev/33-bureau-v2-et-zones.md) : le portion devient le NAVIGATEUR des structures — « ranger,
structurer, stocker, indexer » (papiers 26/27 : portion = discret, gravité, on CRÉE, on RECHERCHE). Avec un scope :
bureau le bureau (ses dossiers, ses zones) bureau:<id> un dossier-portion, une zone ▢, un trou noir ●
fichiers:<chemin> un vrai dossier de jOSFiles (l'index, lu niveau par niveau, à la demande)
deux vues : ▦ la grille (on glisse dedans / dehors, sous-portions, renommer, couleur, chercher) et ▢ les carrés imbriqués (on les
traverse en zoomant ; deux niveaux montés, jamais plus). Le scope vient de ctx.scope (restauré par le WM) ou de jOSEntrees.demande
(le bureau qui l'ouvre) ; il est gardé dans l'onglet. Sans scope : les 4 modes d'avant, à l'identique (+ un bouton « ▢ structure »).
Kill-switch : localStorage xb:portion.nav = off (ou xb:bureau-v2 = off, tout le bureau v2) → seulement les modes d'avant. 0 rAF permanent : transform + transitions CSS. --}}
<style>
.pt { position:relative; height:100%; background:var(--xr-bg,#05060c); overflow:hidden; cursor:zoom-in; font-family:ui-sans-serif,system-ui,sans-serif; }
.pt canvas { display:block; width:100%; height:100%; touch-action:none; }
.pt__bar { position:absolute; left:10px; top:9px; display:flex; gap:5px; flex-wrap:wrap; }
.pt__m { cursor:pointer; font-size:.66rem; padding:3px 9px; border-radius:7px; border:1px solid rgba(120,170,255,.35);
background:rgba(12,18,34,.7); color:rgba(180,205,255,.9); font-family:inherit; }
.pt__m.on { background:rgba(60,90,180,.55); color:#fff; border-color:rgba(150,185,255,.8); }
.pt__hud { position:absolute; right:10px; top:9px; font-size:.7rem; color:rgba(170,200,255,.85); font-family:ui-monospace,monospace; background:rgba(8,12,22,.6); padding:3px 8px; border-radius:7px; pointer-events:none; }
.pt__hint { position:absolute; right:10px; bottom:9px; font-size:.62rem; color:rgba(160,180,220,.6); background:rgba(8,12,22,.6); padding:3px 8px; border-radius:7px; pointer-events:none; }
/* ── le navigateur (bureau v2) : le langage de dix-mille-ans — le vide, un trait, le présent en ambre ── */
.pn { position:absolute; inset:0; display:flex; flex-direction:column; background:#010306; color:rgba(225,247,255,.92); font:400 .8rem/1.35 system-ui,-apple-system,"Segoe UI",sans-serif; overflow:hidden; }
.pn *, .pn *::before { box-sizing:border-box; }
.pn__attente { margin:auto; font:italic .9rem Georgia,serif; color:rgba(193,227,240,.5); }
.pn__h { flex:0 0 auto; display:flex; flex-wrap:wrap; align-items:center; gap:8px 12px; padding:9px 12px 8px; border-bottom:1px solid rgba(158,223,245,.12); }
.pn__fil { display:flex; align-items:center; flex-wrap:wrap; gap:2px 6px; min-width:0; flex:1 1 220px; font:600 .56rem/1.4 system-ui,sans-serif; letter-spacing:.2em; text-transform:uppercase; color:rgba(193,227,240,.45); }
.pn__fil button { border:0; background:none; color:rgba(193,227,240,.62); font:inherit; letter-spacing:inherit; text-transform:inherit; cursor:pointer; padding:2px 0; }
.pn__fil button:hover, .pn__fil button:focus-visible { color:#ffc46b; outline:none; }
.pn__fil i { font-style:normal; opacity:.5; }
.pn__fil b { font:italic 500 .92rem/1.2 Georgia,"Times New Roman",serif; letter-spacing:0; text-transform:none; color:rgba(225,247,255,.95); cursor:text; }
.pn__fil input { font:italic 500 .9rem Georgia,serif; color:#fff; background:#010306; border:1px solid #ffc46b; border-radius:2px; padding:1px 5px; width:14em; outline:none; }
.pn__outils { display:flex; flex-wrap:wrap; align-items:center; gap:6px; }
.pn__outils button, .pn__vues button { border:1px solid rgba(158,223,245,.26); background:none; color:rgba(193,227,240,.8); border-radius:2px; font:600 .54rem/1 system-ui,sans-serif; letter-spacing:.18em; text-transform:uppercase; padding:6px 8px; cursor:pointer; white-space:nowrap; }
.pn__outils button:hover, .pn__outils button:focus-visible, .pn__vues button:hover { border-color:#ffc46b; color:#ffc46b; outline:none; }
.pn__vues { display:inline-flex; gap:0; }
.pn__vues button + button { border-left:0; }
.pn__vues button[aria-pressed="true"] { background:rgba(158,223,245,.1); color:#fff; box-shadow:inset 0 -1px 0 #ffc46b; }
.pn__q { width:13em; max-width:40vw; background:rgba(158,223,245,.05); border:1px solid rgba(158,223,245,.22); border-radius:2px; color:#e1f7ff; font:400 .72rem system-ui,sans-serif; padding:5px 8px; outline:none; }
.pn__q:focus { border-color:#ffc46b; }
.pn__coul { display:inline-flex; gap:3px; }
.pn__coul button { width:13px; height:13px; padding:0; border:1px solid rgba(255,255,255,.25); border-radius:1px; cursor:pointer; }
.pn__coul button[aria-pressed="true"] { outline:1px solid #ffc46b; outline-offset:1px; }
.pn__corps { position:relative; flex:1 1 auto; min-height:0; overflow:auto; outline:none; }
.pn__corps.bv2-cible { box-shadow:inset 0 0 0 1px #ffc46b; background:rgba(255,196,107,.04); }
.pn__grille { display:grid; grid-template-columns:repeat(auto-fill,minmax(88px,1fr)); gap:6px; padding:12px; align-content:start; min-height:100%; }
.pn__grille .bv2-i { position:relative; left:auto; top:auto; width:auto; touch-action:pan-y; } /* (relecture) au doigt, la grille défile : un geste vertical sur une tuile est un défilement ; de côté, un glisser */
.pn__grille .bv2-i .bv2-n { max-width:100%; }
.pn__chemin { display:block; font:500 .5rem/1.2 ui-monospace,Menlo,monospace; color:rgba(193,227,240,.4); text-align:center; margin-top:-2px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:100%; }
.pn__vide { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:10px; pointer-events:none; color:rgba(193,227,240,.45); font:italic .86rem Georgia,serif; text-align:center; padding:20px; }
.pn__vide svg { width:64px; height:64px; fill:none; stroke:rgba(158,223,245,.35); stroke-width:1; }
.pn__pied { flex:0 0 auto; display:flex; flex-wrap:wrap; gap:4px 14px; align-items:baseline; padding:6px 12px 7px; border-top:1px solid rgba(158,223,245,.1); font:500 .6rem/1.3 ui-monospace,Menlo,monospace; color:rgba(193,227,240,.55); }
.pn__pied b { font:600 .5rem/1 system-ui,sans-serif; letter-spacing:.24em; text-transform:uppercase; color:rgba(193,227,240,.4); margin-right:4px; }
.pn__pied .present { color:#ffc46b; }
/* le trou noir : ce qu'il a avalé, récupérable */
.pn__av { display:flex; flex-direction:column; align-items:center; gap:4px; padding:8px 4px 6px; border:1px solid rgba(255,196,107,.14); border-radius:3px; background:rgba(255,196,107,.03); text-align:center; }
.pn__av .g { width:40px; height:40px; display:flex; align-items:center; justify-content:center; color:rgba(255,196,107,.8); font-size:28px; opacity:.85; }
.pn__av .g svg { width:34px; height:34px; fill:none; stroke:currentColor; stroke-width:1.1; }
.pn__av .g img { max-width:42px; max-height:42px; border-radius:2px; filter:saturate(.6); }
.pn__av .n { font:500 .66rem/1.2 system-ui,sans-serif; max-width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.pn__av .t { font:500 .52rem ui-monospace,Menlo,monospace; color:rgba(193,227,240,.45); }
.pn__av .a { display:flex; gap:4px; }
.pn__av .a button { border:1px solid rgba(158,223,245,.25); background:none; color:rgba(193,227,240,.85); border-radius:2px; font:600 .5rem/1 system-ui,sans-serif; letter-spacing:.14em; text-transform:uppercase; padding:4px 6px; cursor:pointer; }
.pn__av .a button:hover { border-color:#ffc46b; color:#ffc46b; }
/* les carrés imbriqués : une scène carrée, transformée (transform seulement), deux niveaux montés */
.pc { position:absolute; inset:0; overflow:hidden; touch-action:none; cursor:zoom-in; }
.pc__scene { position:absolute; transform-origin:0 0; will-change:transform; }
.pc__cadre { position:absolute; inset:0; border:1px solid rgba(158,223,245,.35); pointer-events:none; }
.pc__c { position:absolute; padding:3px; outline:none; }
.pc__in { position:absolute; inset:3px; border:1px solid rgba(158,223,245,.3); overflow:hidden; background:rgba(158,223,245,.025); transition:border-color .12s, background-color .12s; }
.pc__c:hover .pc__in, .pc__c:focus-visible .pc__in, .pc__c.bv2-sel .pc__in { border-color:#ffc46b; background:rgba(255,196,107,.05); }
.pc__c.bv2-cible .pc__in { border-color:#ffc46b; background:rgba(255,196,107,.1); }
.pc__c.bv2-src { opacity:.3; }
.pc__nom { position:absolute; left:5px; top:4px; right:5px; font:600 .5rem/1.2 system-ui,sans-serif; letter-spacing:.16em; text-transform:uppercase; color:rgba(193,227,240,.7); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; pointer-events:none; }
.pc__val { position:absolute; left:5px; bottom:3px; font:500 .5rem ui-monospace,Menlo,monospace; color:rgba(193,227,240,.45); pointer-events:none; }
.pc__mini { position:absolute; border:1px solid rgba(158,223,245,.22); pointer-events:none; }
.pc__mini.portion { border-color:rgba(255,196,107,.45); background:rgba(255,196,107,.06); }
.pc__mini.image { background:rgba(111,159,216,.18); } .pc__mini.video { background:rgba(167,139,250,.2); } .pc__mini.son { background:rgba(110,231,183,.16); }
.pc__mini.texte, .pc__mini.pdf { background:rgba(225,247,255,.08); } .pc__mini.px { background:rgba(158,223,245,.12); transform:rotate(45deg) scale(.7); }
.pc__nid { position:absolute; inset:22%; border:1px solid rgba(255,196,107,.28); pointer-events:none; }
.pc__nid::before { content:""; position:absolute; inset:24%; border:1px solid rgba(255,196,107,.2); }
.pc__g { position:absolute; left:50%; top:52%; transform:translate(-50%,-50%); width:44%; max-width:64px; aspect-ratio:1; display:flex; align-items:center; justify-content:center; color:rgba(158,223,245,.8); font-size:1.4rem; pointer-events:none; }
.pc__g svg { width:100%; height:100%; fill:none; stroke:currentColor; stroke-width:1.1; }
.pc__g svg .plein { fill:currentColor; }
.pc__img { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; opacity:.8; pointer-events:none; }
.pc__plus { position:absolute; right:6px; bottom:4px; font:500 .5rem ui-monospace,monospace; color:rgba(193,227,240,.5); }
@media (prefers-reduced-motion:reduce) { .pc__scene { transition:none !important; } }
</style>
<script>
(function () {
// ═══════════════ les modes d'avant (visualiseur, zoom infini) — inchangés ; + « ▢ structure » quand le bureau v2 est là ═══════════════
function motifs(container, ctx, api) {
var MODES = [['concentrique','□'], ['spirale','◳'], ['cube','▣'], ['hypercube','⧉']];
container.innerHTML = '<div class="pt"><canvas></canvas>'
+ '<div class="pt__bar">' + MODES.map(function (m, i) { return '<button class="pt__m' + (i === 0 ? ' on' : '') + '" data-m="' + m[0] + '">' + m[1] + ' ' + m[0] + '</button>'; }).join('')
+ (api && api.structure ? '<button class="pt__m" data-structure title="la vraie structure : ton bureau, tes dossiers, en carrés imbriqués">▢ structure</button>' : '') + '</div>'
+ '<div class="pt__hud">▣ portion · <b data-z>×1.0</b></div>'
+ '<div class="pt__hint">molette / pinch = zoom infini · double-clic = recentrer</div></div>';
var root = container.querySelector('.pt'), cv = container.querySelector('canvas'), cx = cv.getContext('2d');
var hud = container.querySelector('[data-z]');
var RATIO = 1.7, LOGR = Math.log(RATIO), zoom = 0, raf = 0, mode = 'concentrique';
function size() { var r = root.getBoundingClientRect(), dpr = Math.min(2, devicePixelRatio || 1);
cv.width = Math.max(1, r.width * dpr); cv.height = Math.max(1, r.height * dpr); cx.setTransform(dpr, 0, 0, dpr, 0, 0); }
function sq(x, y, h, rot, stroke, lw) { // un carré centré, optionnellement tourné
cx.save(); cx.translate(x, y); if (rot) cx.rotate(rot);
cx.beginPath(); cx.rect(-h, -h, 2 * h, 2 * h); cx.strokeStyle = stroke; cx.lineWidth = lw; cx.stroke(); cx.restore();
}
function koinsAt(x, y, h, col) { // 4 triangles (koins) dans les coins
var c = [[-1,-1],[1,-1],[1,1],[-1,1]], t = h * 0.34;
cx.fillStyle = col;
for (var i = 0; i < 4; i++) {
var cxx = x + c[i][0] * h, cyy = y + c[i][1] * h;
cx.beginPath(); cx.moveTo(cxx, cyy);
cx.lineTo(cxx - c[i][0] * t, cyy); cx.lineTo(cxx, cyy - c[i][1] * t); cx.closePath(); cx.fill();
}
}
function cube(x, y, h, d, stroke, lw) { // carré dans carré (oblique) = un cube
cx.strokeStyle = stroke; cx.lineWidth = lw;
cx.strokeRect(x - h, y - h, 2 * h, 2 * h);
cx.strokeRect(x - h + d, y - h - d, 2 * h, 2 * h);
cx.beginPath();
var f = [[-h,-h],[h,-h],[h,h],[-h,h]];
for (var i = 0; i < 4; i++) { cx.moveTo(x + f[i][0], y + f[i][1]); cx.lineTo(x + f[i][0] + d, y + f[i][1] - d); }
cx.stroke();
}
function draw() {
var r = root.getBoundingClientRect(), w = r.width, h = r.height, X = w / 2, Y = h / 2;
cx.clearRect(0, 0, w, h);
var maxR = Math.hypot(w, h), phase = zoom / LOGR;
for (var k = -2; k < 40; k++) {
var s = 7 * Math.pow(RATIO, k + (phase % 1));
if (s < 2) continue; if (s > maxR) break;
var depth = k + phase, hue = 210 + 35 * Math.sin(depth * 0.5);
var op = 0.18 + 0.5 * (1 - Math.min(1, s / maxR));
var col = 'hsla(' + hue + ',70%,66%,' + op + ')', lw = Math.max(0.6, s * 0.011);
if (mode === 'concentrique') { sq(X, Y, s, 0, col, lw); if (s > 22) koinsAt(X, Y, s, 'hsla(' + (hue + 60) + ',75%,70%,' + (op * 0.8) + ')'); }
else if (mode === 'spirale') { sq(X, Y, s, depth * 0.20, col, lw); }
else if (mode === 'cube') { cube(X, Y, s, s * 0.32, col, lw); }
else { cube(X, Y, s, s * 0.32, col, lw); sq(X, Y, s * 0.5, 0, 'hsla(' + (hue + 40) + ',75%,72%,' + op + ')', lw); }
}
hud.textContent = '×' + Math.exp(zoom).toFixed(2);
}
function schedule() { if (!raf) raf = requestAnimationFrame(function () { raf = 0; draw(); }); }
cv.addEventListener('wheel', function (e) { e.preventDefault(); zoom += (e.deltaY < 0 ? 1 : -1) * 0.12; schedule(); }, { passive: false });
var pinch = null;
cv.addEventListener('touchmove', function (e) {
if (e.touches.length === 2) { e.preventDefault();
var d = Math.hypot(e.touches[0].clientX - e.touches[1].clientX, e.touches[0].clientY - e.touches[1].clientY);
if (pinch != null) { zoom += Math.log(d / pinch); schedule(); } pinch = d;
}
}, { passive: false });
cv.addEventListener('touchend', function () { pinch = null; });
root.addEventListener('dblclick', function () { zoom = 0; schedule(); });
container.querySelector('.pt__bar').addEventListener('click', function (e) {
if (e.target.closest('[data-structure]')) { api.structure('bureau'); return; }
var b = e.target.closest('[data-m]'); if (!b) return;
mode = b.getAttribute('data-m');
container.querySelectorAll('.pt__m').forEach(function (x) { x.classList.toggle('on', x === b); });
schedule();
});
var ro = new ResizeObserver(function () { size(); draw(); }); ro.observe(root);
size(); draw();
return { unmount: function () { try { ro.disconnect(); } catch (e) {} if (raf) cancelAnimationFrame(raf); container.innerHTML = ''; } };
}
// ═══════════════ le navigateur des structures (bureau v2) ═══════════════
var RE_ID = /^[a-z0-9][a-z0-9_-]{0,47}$/i;
function parse(s) {
s = String(s || 'bureau');
if (s === 'bureau') return { k: 'bureau', id: null };
var m = /^bureau:([a-z0-9][a-z0-9_-]{0,47})$/i.exec(s); if (m) return { k: 'bureau', id: m[1] };
m = /^fichiers:(.{1,600})$/.exec(s); if (m) return { k: 'fichiers', chemin: m[1] };
return { k: 'bureau', id: null };
}
function scopeDe(o) { return o.k === 'fichiers' ? 'fichiers:' + o.chemin : (o.id ? 'bureau:' + o.id : 'bureau'); }
function norm(s) { s = String(s || '').toLowerCase(); try { s = s.normalize('NFD').replace(/[̀-ͯ]/g, ''); } catch (e) {} return s; }
var COULEURS = ['', '#ffc46b', '#a78bfa', '#6ee7b7', '#f472b6', '#7aa0ff', '#f87171'];
var LISTES_FS = {}; // chemin → entrées (cache de la session : l'index se lit niveau par niveau, à la demande)
function navigateur(container, ctx, scope, api) {
var W = window, D = document, E = W.jOSEntrees, alive = true, S = parse(scope), vue = null, q = '', rt = null, desabo = [], Z = { s: 1, tx: 0, ty: 0 }, entre = null;
container.innerHTML = '<div class="pn" data-bv2-nav><div class="pn__attente">▢ la portion se déplie…</div></div>'; // data-bv2-nav (25.09) : toute la fenêtre reçoit un dépôt (le bureau cherche sa cible dedans)
var root = container.firstChild;
var esc = function (s) { return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]; }); };
function clamp(v, a, b) { return Math.max(a, Math.min(b, v)); }
function reduit() { try { var h = D.documentElement; return h.getAttribute('data-puissance') === 'faible' || h.classList.contains('xb-no-anim') || !!(W.matchMedia && W.matchMedia('(prefers-reduced-motion: reduce)').matches); } catch (e) { return false; } }
function persister() {
var sc = scopeDe(S), nom = titre();
try { if (ctx && ctx.tab) { ctx.tab.scope = sc; ctx.tab.title = 'Portion · ' + nom; } } catch (e) {}
try { if (ctx && ctx.win && ctx.win.tabs && ctx.win.tabs.length === 1) { ctx.win.title = '▣ Portion · ' + nom; var n = W.jOS && W.jOS._wm && W.jOS._wm.node(ctx.win.id), t = n && n.querySelector('.jos-win__title'); if (t) t.textContent = ctx.win.title; } } catch (e2) {}
try { if (W.jOS && W.jOS._wm && W.jOS._wm.save) W.jOS._wm.save(); } catch (e3) {}
}
function titre() { if (S.k === 'fichiers') return S.chemin.split('/').filter(Boolean).pop() || S.chemin; var it = S.id && E.item ? E.item(S.id) : null; return it ? E.nomDe(it) : 'bureau'; }
function aller(o, anim) { S = o; q = ''; if (o.k === 'fichiers') { vue = 'carres'; delete LISTES_FS[o.chemin]; } else if (vue === 'carres' && !anim) vue = null; persister(); entre = anim || null; Z = { s: 1, tx: 0, ty: 0 }; rendre(); }
var inst = { vivant: function () { return alive; }, winId: function () { return ctx && ctx.win && ctx.win.id; }, naviguer: function (sc) { aller(parse(sc)); } };
function planifier() { if (rt) return; rt = setTimeout(function () { rt = null; rendre(); }, 40); }
// ── ce que montre la portion ──
function courant() { return S.k === 'bureau' && S.id ? E.item(S.id) : null; }
function liste() {
var p = courant();
if (S.k === 'bureau' && !S.id) return E.enfants(null);
if (!p) return [];
return E.enfants(p.id);
}
function cherche(q0) {
var qq = norm(q0), base = S.id ? E.descendants(S.id) : Object.keys(E.etat().items).map(function (k) { return E.etat().items[k]; });
return base.filter(function (c) { return norm(E.nomDe(c)).indexOf(qq) >= 0 || (c.chemin && norm(c.chemin).indexOf(qq) >= 0); }).slice(0, 200);
}
// ── l'en-tête : le fil, les outils ──
function entete() {
var p = courant(), h = '<div class="pn__h"><nav class="pn__fil" aria-label="où je suis">';
h += '<button type="button" data-aller="bureau" title="le bureau">▭ bureau</button>';
if (S.k === 'bureau' && S.id) {
var ch = E.chemin(S.id);
ch.forEach(function (c, i) { h += '<i>›</i>' + (i === ch.length - 1 ? '<b data-renommer title="renommer (clic)">' + esc(E.nomDe(c)) + '</b>' : '<button type="button" data-aller="bureau:' + esc(c.id) + '">' + esc(E.nomDe(c)) + '</button>'); });
} else if (S.k === 'fichiers') {
var m = /^([a-z]+:)?(.*)$/.exec(S.chemin), pre = m[1] || '', segs = (m[2] || '').split('/').filter(Boolean), acc = '';
h += '<i>›</i><button type="button" data-aller="fichiers:' + esc(pre + '/') + '">⌗ ' + esc(pre ? pre.replace(':', '') : 'mes fichiers') + '</button>';
segs.forEach(function (s, i) { acc += '/' + s; h += '<i>›</i>' + (i === segs.length - 1 ? '<b>' + esc(s) + '</b>' : '<button type="button" data-aller="fichiers:' + esc(pre + acc) + '">' + esc(s) + '</button>'); });
}
h += '</nav><div class="pn__outils">';
var trou = p && p.t === 'trou';
if (!trou) h += '<input class="pn__q" type="search" data-q placeholder="chercher ici…" aria-label="chercher dans la portion (et ses sous-portions)" value="' + esc(q) + '">';
if (!trou) h += '<span class="pn__vues" role="group" aria-label="vue"><button type="button" data-vue="grille" aria-pressed="' + (vue === 'grille') + '" ' + (S.k === 'fichiers' ? 'disabled' : '') + '>▦ grille</button><button type="button" data-vue="carres" aria-pressed="' + (vue === 'carres') + '">▢ carrés</button></span>';
if (S.k === 'bureau' && !trou && !(p && p.t !== 'portion')) h += '<button type="button" data-a="sous" title="une portion dans la portion">+ sous-portion</button>';
// (25.09, docs/dev/33 § Créer des fichiers) « + nouveau » : un document, un texte, une note… né ICI (la portion, ou le vrai dossier de l'index)
if (((S.k === 'bureau' && !trou && !(p && p.t !== 'portion')) || S.k === 'fichiers') && typeof E.menuNouveau === 'function' && !E.coupe('fichiers.nouveau') && !E.coupe('bureau.fichiers')) h += '<button type="button" data-a="nouveau" title="créer un fichier ici (document, texte, note, tableur…)" aria-haspopup="menu">+ nouveau</button>';
if (S.k === 'bureau' && !trou && !(p && p.t !== 'portion') && !E.coupe('bureau.fichiers')) h += '<button type="button" data-a="importer" title="des fichiers de ton appareil, rangés ici">⇪ importer</button>';
if (trou && p.avales.length) h += '<button type="button" data-a="recracher-tout">↺ tout recracher</button>';
if (S.k === 'bureau' && !S.id) { var cb = E.cibleFichiers(); if (cb.ou !== 'idb') h += '<button type="button" data-aller="fichiers:' + esc(cb.base) + '" title="le dossier réel où vont les fichiers du bureau">⌗ index</button>'; }
if (p && p.t === 'portion') h += '<span class="pn__coul" role="group" aria-label="couleur">' + COULEURS.map(function (c) { return '<button type="button" data-couleur="' + (c || 'glace') + '" aria-pressed="' + ((p.couleur || '') === c) + '" title="' + (c || 'glace') + '" style="background:' + (c || '#9edff5') + '"></button>'; }).join('') + '</span>';
if (api && api.motifs) h += '<button type="button" data-a="motifs" title="les motifs du portion (les modes d\'avant)">◳ motifs</button>';
return h + '</div></div>';
}
// ── le corps : grille, carrés, trou noir, index ──
function tuile(c, chemin) { return E.iconeHTML(c, { grille: true, apres: chemin ? '<span class="pn__chemin">' + esc(chemin) + '</span>' : '' }); }
function grille(l, avecChemin) {
if (!l.length) return '';
return '<div class="pn__grille">' + l.map(function (c) { return tuile(c, avecChemin && c.parent ? E.cheminTexte(c.parent) : ''); }).join('') + '</div>';
}
function vide(msg) { return '<div class="pn__vide">' + (E.glyphes && E.glyphes.portion || '') + '<span>' + esc(msg) + '</span></div>'; }
function trouHTML(tr) {
if (!tr.avales.length) return vide('le trou noir est vide · glisse ce que tu veux oublier dedans');
return '<div class="pn__grille">' + tr.avales.map(function (a, i) {
var it = a.item, g = it.t === 'fichier' ? (E.vignetteSync(it.id) ? '<img src="' + E.vignetteSync(it.id) + '" alt="" draggable="false">' : (E.glyphes[it.type] || E.glyphes.autre)) : (E.glyphes[it.t] || E.glyphes.px);
return '<div class="pn__av" data-bv2-avale="' + i + '" title="' + esc(E.nomDe(it)) + '"><span class="g">' + g + '</span><span class="n">' + esc(E.nomDe(it)) + '</span>'
+ '<span class="t">' + esc(E.ilya(a.quand)) + (a.enfants && a.enfants.length ? ' · +' + a.enfants.length : '') + (a.chaoxion ? ' · chaoxion' : '') + '</span>'
+ '<span class="a"><button type="button" data-recracher="' + i + '" title="le remettre là où il était">↺ recracher</button><button type="button" data-oublier="' + i + '" title="l\'oublier (le fichier reste dans tes fichiers)">✕</button></span></div>';
}).join('') + '</div>';
}
function contenuCarre(c) {
var h = '<span class="pc__nom">' + esc(E.nomDe(c)) + '</span>';
if (c.t === 'portion') {
var ks = E.enfants(c.id), m = Math.min(ks.length, 16), k = Math.max(1, Math.ceil(Math.sqrt(m)));
h += '<span class="pc__nid"></span>';
ks.slice(0, 16).forEach(function (g, i) { var col = i % k, row = Math.floor(i / k), w = 64 / k; h += '<span class="pc__mini ' + (g.t === 'fichier' ? g.type : g.t) + '" style="left:' + (18 + col * w + 1).toFixed(2) + '%;top:' + (20 + row * w + 1).toFixed(2) + '%;width:' + (w - 2).toFixed(2) + '%;height:' + (w - 2).toFixed(2) + '%"></span>'; });
var p = E.poids(c.id);
h += '<span class="pc__val">' + p.n + ' · ' + esc(E.taille(p.octets)) + '</span>';
if (ks.length > 16) h += '<span class="pc__plus">+' + (ks.length - 16) + '</span>';
} else if (c.t === 'fichier') {
var v = E.vignetteSync(c.id);
h = (v ? '<img class="pc__img" src="' + v + '" alt="" draggable="false">' : '<span class="pc__g">' + (E.glyphes[c.type] || E.glyphes.autre) + '</span>') + h + '<span class="pc__val">' + esc(E.taille(c.taille)) + '</span>';
if (!v) E.demanderVignette(c.id);
} else if (c.t === 'px') {
var ic = ''; try { var mm = (W.__PLOXIONS__ || []).filter(function (x) { return x.id === c.px; })[0]; ic = mm && mm.icon ? esc(mm.icon) : E.glyphes.px; } catch (e) { ic = E.glyphes.px; }
h += '<span class="pc__g">' + ic + '</span>';
} else {
h += '<span class="pc__g">' + (E.glyphes[c.t] || '') + '</span><span class="pc__val">' + esc(c.t === 'wormion' ? c.vus.length + ' vus' : c.avales.length + ' avalés') + '</span>';
}
return h;
}
function scene(l, fs) {
var n = Math.min(l.length, 81), k = Math.max(1, Math.ceil(Math.sqrt(n))), w = 100 / k, h = '';
l.slice(0, 81).forEach(function (c, i) {
var col = i % k, row = Math.floor(i / k), st = 'left:' + (col * w).toFixed(3) + '%;top:' + (row * w).toFixed(3) + '%;width:' + w.toFixed(3) + '%;height:' + w.toFixed(3) + '%';
if (fs) h += '<div class="pc__c pc__c--' + (c.type === 'dir' ? 'portion' : 'fichier') + '" data-fs="' + esc(c.path) + '" data-fs-type="' + (c.type === 'dir' ? 'dir' : 'file') + '" tabindex="0" style="' + st + '" title="' + esc(c.name) + '"><div class="pc__in">' + contenuFs(c) + '</div></div>';
else h += '<div class="pc__c pc__c--' + c.t + '" data-bv2-item="' + esc(c.id) + '" data-bv2-t="' + c.t + '" tabindex="0" role="button" aria-label="' + esc(E.nomDe(c) + ' — ' + E.genreDe(c)) + '" style="' + st + '"><div class="pc__in">' + contenuCarre(c) + '</div></div>';
});
if (l.length > 81) h += '<span class="pc__plus" style="right:4px;bottom:-14px">+' + (l.length - 81) + ' plus loin</span>';
return '<div class="pc" data-carres><div class="pc__scene"><div class="pc__cadre"></div>' + h + '</div></div>';
}
function contenuFs(e) {
var h = '<span class="pc__nom">' + esc(e.name) + '</span>';
if (e.type === 'dir') {
var sous = LISTES_FS[e.path];
h += '<span class="pc__nid"></span>';
if (sous) { var m = Math.min(sous.length, 16), k = Math.max(1, Math.ceil(Math.sqrt(m))); sous.slice(0, 16).forEach(function (g, i) { var col = i % k, row = Math.floor(i / k), w = 64 / k; h += '<span class="pc__mini ' + (g.type === 'dir' ? 'portion' : E.typeDe(g.name, g.mime)) + '" style="left:' + (18 + col * w + 1).toFixed(2) + '%;top:' + (20 + row * w + 1).toFixed(2) + '%;width:' + (w - 2).toFixed(2) + '%;height:' + (w - 2).toFixed(2) + '%"></span>'; }); h += '<span class="pc__val">' + sous.length + '</span>'; }
} else h += '<span class="pc__g">' + (E.glyphes[E.typeDe(e.name, e.mime)] || E.glyphes.autre) + '</span><span class="pc__val">' + esc(E.taille(e.size)) + '</span>';
return h;
}
function pied(l) {
var h = '<div class="pn__pied">', p = courant();
var prof = S.k === 'bureau' ? (S.id ? E.chemin(S.id).length : 0) : S.chemin.split('/').filter(Boolean).length;
h += '<span><b>z</b>' + prof + '</span>';
if (vue === 'carres') h += '<span><b>×</b><span data-echelle>' + Z.s.toFixed(2) + '</span></span>';
if (S.k === 'bureau') {
var tout = S.id ? E.descendants(S.id) : Object.keys(E.etat().items).map(function (k) { return E.etat().items[k]; }), oct = 0, par = {};
tout.forEach(function (c) { if (c.t === 'fichier') { oct += c.taille || 0; par[c.type] = (par[c.type] || 0) + 1; } else par[c.t] = (par[c.t] || 0) + 1; });
if (p && p.t === 'trou') h += '<span><b>avalés</b>' + p.avales.length + '</span><span><b>vers</b>' + esc(p.action === 'chaoxion' ? 'le chaoxion' : 'la corbeille') + '</span>';
else {
h += '<span><b>ici</b>' + l.length + '</span><span><b>en tout</b>' + tout.length + ' · ' + esc(E.exact(oct)) + '</span>';
// (relecture adverse 25.09) « doc » : le genre des documents des ploxions (.wdoc .note .xlc .deck, .docx .xlsx…) — avant, ils n'étaient comptés nulle part
['portion', 'image', 'video', 'son', 'texte', 'doc', 'pdf', '3d', 'autre', 'px'].forEach(function (t) { if (par[t]) h += '<span><b>' + ({ portion: 'portions', image: 'images', video: 'vidéos', son: 'sons', texte: 'textes', doc: 'documents', pdf: 'pdf', '3d': '3d', autre: 'autres', px: 'ploxions' }[t]) + '</b>' + par[t] + '</span>'; });
}
if (p && p.t === 'portion' && p.zone) h += '<span><b>action</b>' + (p.ranger === 'type' ? 'range par genre' : 'garde tel quel') + '</span>';
} else h += '<span><b>index</b>' + esc(S.chemin) + '</span><span><b>ici</b>' + ((LISTES_FS[S.chemin] || []).length) + '</span>';
h += '<span class="present"><b>maintenant</b>' + esc(E.quand(Date.now()).split(' · ')[1] || '') + '</span>';
return h + '</div>';
}
function rendre() {
if (!alive || !E.__impl) return;
if (root.querySelector('.bv2-ren') && D.activeElement && D.activeElement.classList && D.activeElement.classList.contains('bv2-ren')) return; // un nom en cours d'écriture : on attend
var p = courant();
if (S.k === 'bureau' && S.id && !p) { S = { k: 'bureau', id: null }; persister(); }
p = courant();
if (p && p.t === 'wormion') { root.innerHTML = entete() + '<div class="pn__corps" data-bv2-wormion="' + esc(p.id) + '">' + vide('c\'est un wormion : il s\'ouvre dans le ploxion wormion') + '</div>'; brancher(); return; }
if (!vue) vue = (S.k === 'fichiers') ? 'carres' : 'grille';
var l = S.k === 'bureau' ? liste() : (LISTES_FS[S.chemin] || []), corps = '', attr = '';
if (S.k === 'bureau') attr = ' data-bv2-portion="' + esc(p ? p.id : 'racine') + '" tabindex="0" aria-label="' + esc('le contenu de ' + titre()) + '"';
else if (S.k === 'fichiers') attr = ' data-bv2-fs="' + esc(S.chemin) + '"'; // (25.09, le dépôt fluide) un vrai dossier : les fichiers lâchés y sont écrits
if (p && p.t === 'trou') corps = trouHTML(p);
else if (q) { var r = cherche(q); corps = r.length ? grille(r, true) : vide('rien ne s\'appelle « ' + q + ' » ici'); }
else if (S.k === 'fichiers') { corps = LISTES_FS[S.chemin] ? (l.length ? scene(l, true) : vide('dossier vide')) : '<div class="pn__vide"><span>⌗ lecture de l\'index…</span></div>'; if (!LISTES_FS[S.chemin]) lireFs(S.chemin); }
else if (vue === 'carres') corps = l.length ? scene(l, false) : vide('portion vide · glisse des fichiers ou des icônes ici');
else corps = l.length ? grille(l, false) : vide(S.id ? 'portion vide · glisse des fichiers ou des icônes ici' : 'le bureau est vide');
// garder la place (le défilement) et le focus d'une tuile à travers le redessin
var c0 = root.querySelector('.pn__corps'), haut = c0 ? c0.scrollTop : 0, a = D.activeElement, fid = (a && root.contains(a) && a.getAttribute) ? a.getAttribute('data-bv2-item') : null;
root.innerHTML = entete() + '<div class="pn__corps"' + attr + '>' + corps + '</div>' + pied(l);
var c1 = root.querySelector('.pn__corps'); if (c1 && haut) c1.scrollTop = haut;
if (fid) { var f = root.querySelector('[data-bv2-item="' + fid.replace(/["\\]/g, '') + '"]'); if (f) try { f.focus({ preventScroll: true }); } catch (e) {} }
brancher();
if (vue === 'carres' && !q && !(p && p.t === 'trou')) cadrer();
}
function lireFs(ch) {
var F = W.jOSFiles; if (!F || !F.list) { LISTES_FS[ch] = []; planifier(); return; }
Promise.resolve(F.list(ch)).then(function (d) {
var es = ((d && d.entries) || []).filter(function (e) { return e && e.name && e.name.charAt(0) !== '.'; }).sort(function (a, b) { return (a.type === b.type ? 0 : a.type === 'dir' ? -1 : 1) || String(a.name).localeCompare(String(b.name), 'fr'); });
LISTES_FS[ch] = es.slice(0, 400); if (!alive) return; planifier();
// un niveau de plus, pour les carrés imbriqués des 12 premiers dossiers (jamais plus loin)
es.filter(function (e) { return e.type === 'dir' && !LISTES_FS[e.path]; }).slice(0, 12).forEach(function (e) { Promise.resolve(F.list(e.path)).then(function (d2) { LISTES_FS[e.path] = ((d2 && d2.entries) || []).slice(0, 64); if (alive && S.chemin === ch) planifier(); }).catch(function () { LISTES_FS[e.path] = []; }); });
}).catch(function () { LISTES_FS[ch] = []; planifier(); });
}
// ── les carrés : cadrer la scène (un carré au centre), zoomer (transform), traverser ──
function stage() { return root.querySelector('.pc'); }
function cadrer() {
var st = stage(); if (!st) return;
var sc = st.querySelector('.pc__scene'), r = st.getBoundingClientRect(), cote = Math.max(40, Math.min(r.width, r.height) - 36);
sc.style.width = cote + 'px'; sc.style.height = cote + 'px'; sc.style.left = ((r.width - cote) / 2) + 'px'; sc.style.top = ((r.height - cote) / 2) + 'px';
if (entre && !reduit()) {
// la continuité de la traversée : on arrive de plus loin (on entre) ou de plus près (on sort), puis la scène se pose
var s0 = entre === 'dedans' ? 0.62 : 1.45;
sc.style.transition = 'none'; sc.style.transform = 'translate(' + (cote * (1 - s0) / 2) + 'px,' + (cote * (1 - s0) / 2) + 'px) scale(' + s0 + ')'; sc.style.opacity = entre === 'dedans' ? '.4' : '.5';
void sc.offsetWidth;
sc.style.transition = 'transform .28s cubic-bezier(.2,.9,.1,1), opacity .2s'; sc.style.transform = 'none'; sc.style.opacity = '1';
}
entre = null; Z = { s: 1, tx: 0, ty: 0 };
}
function appliquer(anim) {
var sc = stage() && stage().querySelector('.pc__scene'); if (!sc) return;
sc.style.transition = anim && !reduit() ? 'transform .28s cubic-bezier(.2,.9,.1,1)' : 'none';
sc.style.transform = 'translate(' + Z.tx.toFixed(1) + 'px,' + Z.ty.toFixed(1) + 'px) scale(' + Z.s.toFixed(4) + ')';
var e = root.querySelector('[data-echelle]'); if (e) e.textContent = Z.s.toFixed(2);
}
function parentDe() { if (S.k === 'fichiers') { var m = /^([a-z]+:)?(.*)$/.exec(S.chemin), segs = (m[2] || '').split('/').filter(Boolean); if (!segs.length) return null; segs.pop(); return { k: 'fichiers', chemin: (m[1] || '') + '/' + segs.join('/') }; } var p = courant(); if (!p) return null; return p.parent ? { k: 'bureau', id: p.parent } : { k: 'bureau', id: null }; }
function entrerDans(el) {
if (!el) return;
if (el.hasAttribute('data-fs')) { if (el.getAttribute('data-fs-type') === 'dir') aller({ k: 'fichiers', chemin: el.getAttribute('data-fs') }, 'dedans'); return; }
var id = el.getAttribute('data-bv2-item'), it = E.item(id); if (!it) return;
if (it.t === 'portion' || it.t === 'trou') aller({ k: 'bureau', id: id }, 'dedans');
else if (it.t === 'wormion') E.ouvrir(id);
}
function plonger(el) { // un clic sur un carré-portion : la scène zoome jusqu'à lui (transform), puis on y entre
var st = stage(); if (!st || !el) return;
if (reduit()) { entrerDans(el); return; }
var r = st.getBoundingClientRect(), c = el.getBoundingClientRect(), sc = st.querySelector('.pc__scene');
if (!c.width || !c.height) { entrerDans(el); return; }
var f = Math.min(r.width / c.width, r.height / c.height) * 0.92;
// le centre du carré (repère de la scène, avant zoom) vient au centre de la vue ; l'échelle le fait remplir la vue
var ox = sc.offsetLeft, oy = sc.offsetTop, cx = c.left + c.width / 2 - r.left, cy = c.top + c.height / 2 - r.top;
var px = (cx - ox - Z.tx) / Z.s, py = (cy - oy - Z.ty) / Z.s;
Z.s = Z.s * f; Z.tx = r.width / 2 - ox - Z.s * px; Z.ty = r.height / 2 - oy - Z.s * py;
appliquer(true);
setTimeout(function () { if (alive) entrerDans(el); }, 290);
}
function molette(e) {
var st = stage(); if (!st) return;
e.preventDefault();
var r = st.getBoundingClientRect(), sc = st.querySelector('.pc__scene'), mx = e.clientX - r.left - sc.offsetLeft, my = e.clientY - r.top - sc.offsetTop;
var ns = clamp(Z.s * Math.exp(-(e.deltaY || 0) * 0.0016), 0.5, 14), wx = (mx - Z.tx) / Z.s, wy = (my - Z.ty) / Z.s;
Z.s = ns; Z.tx = mx - wx * ns; Z.ty = my - wy * ns; appliquer(false);
if (e.deltaY < 0) { // on s'approche : le carré-portion sous le pointeur remplit la vue → on y est
var el = D.elementFromPoint(e.clientX, e.clientY), c = el && el.closest && el.closest('.pc__c--portion,.pc__c--trou');
if (c && root.contains(c)) { var cr = c.getBoundingClientRect(); if (cr.width >= r.width * 0.72 || cr.height >= r.height * 0.72) entrerDans(c); }
} else if (Z.s <= 0.56) { var pa = parentDe(); if (pa) aller(pa, 'dehors'); else { Z = { s: 1, tx: 0, ty: 0 }; appliquer(true); } }
}
// ── les gestes ──
function brancher() {
var corps = root.querySelector('.pn__corps'), qi = root.querySelector('[data-q]');
if (qi) { qi.addEventListener('input', function () { q = qi.value; var pos = qi.selectionStart; rendre(); var n = root.querySelector('[data-q]'); if (n) { n.focus(); try { n.setSelectionRange(pos, pos); } catch (e) {} } }); qi.addEventListener('keydown', function (e) { e.stopPropagation(); if (e.key === 'Escape') { q = ''; rendre(); } }); }
var st = stage(); if (st) st.addEventListener('wheel', molette, { passive: false });
if (st) st.addEventListener('keydown', function (e) { if (e.key === '+' || e.key === '=') { Z.s = clamp(Z.s * 1.25, .5, 14); appliquer(true); } else if (e.key === '-') { Z.s = clamp(Z.s / 1.25, .5, 14); appliquer(true); if (Z.s <= 0.56) { var pa = parentDe(); if (pa) aller(pa, 'dehors'); } } });
}
function clic(e) {
var t = e.target;
var a = t.closest('[data-aller]'); if (a) { aller(parse(a.getAttribute('data-aller')), a.getAttribute('data-aller').length > scopeDe(S).length ? 'dedans' : 'dehors'); return; }
var v = t.closest('[data-vue]'); if (v) { vue = v.getAttribute('data-vue'); rendre(); return; }
var b = t.closest('[data-a]');
if (b) {
var act = b.getAttribute('data-a'), p = courant();
if (act === 'motifs' && api && api.motifs) { api.motifs(); return; }
if (act === 'sous') { var n = E.creer('portion', { nom: 'dossier', parent: p ? p.id : null, x: 60 + Math.round(Math.random() * 200), y: 120 + Math.round(Math.random() * 200) }); if (n) E.editerNom(n.id) || setTimeout(function () { E.editerNom(n.id); }, 80); return; }
if (act === 'importer') { E.importer(p ? { k: 'portion', id: p.id } : { k: 'fond', x: 200, y: 200 }); return; }
if (act === 'nouveau' && E.menuNouveau) { var rb = b.getBoundingClientRect(); E.menuNouveau(rb.left, rb.bottom + 4, S.k === 'fichiers' ? { k: 'fs', chemin: S.chemin } : p ? { k: 'portion', id: p.id } : { k: 'fond' }, b); return; }
if (act === 'recracher-tout' && p) { if (E.recracherTout) { E.recracherTout(p.id); return; } var g = 0; while (E.item(p.id) && E.item(p.id).avales.length && g++ < 300) E.recracher(p.id, 0); return; } // une seule écriture (Pi 4)
return;
}
var col = t.closest('[data-couleur]'); if (col && courant()) { var c = col.getAttribute('data-couleur'); E.couleur(courant().id, c === 'glace' ? '' : c); return; }
var rc = t.closest('[data-recracher]'); if (rc && courant()) { E.recracher(courant().id, +rc.getAttribute('data-recracher')); return; }
var ou = t.closest('[data-oublier]'); if (ou && courant()) { E.oublier(courant().id, +ou.getAttribute('data-oublier'), false); return; }
var nm = t.closest('[data-renommer]'); if (nm && courant()) { renommerEntete(nm); return; }
var sq = t.closest('.pc__c');
if (sq && root.contains(sq)) {
var it = sq.hasAttribute('data-bv2-item') ? E.item(sq.getAttribute('data-bv2-item')) : null;
if ((it && (it.t === 'portion' || it.t === 'trou')) || sq.getAttribute('data-fs-type') === 'dir') plonger(sq);
}
}
// un vrai fichier de l'index : dans SON app (le bureau → jOSFiles.ouvrir, docs/dev/33) ; double-clic ou Entrée (26.09) ; son clic droit :
// « ouvrir avec › » (le bureau)
function ouvrirFs(sq) {
var ch = sq.getAttribute('data-fs'), en = (LISTES_FS[S.chemin] || []).filter(function (x) { return x.path === ch; })[0] || { name: ch.split('/').pop(), path: ch };
E.ouvrirFichier({ chemin: ch, nom: en.name, mime: en.mime, taille: en.size, type: E.typeDe(en.name, en.mime), ou: (/^([a-z]+):/.exec(ch) || [0, 'fs'])[1] }, { depuis: 'portion' });
}
function dbl(e) {
var sq = e.target.closest && e.target.closest('[data-fs]');
if (sq && sq.getAttribute('data-fs-type') === 'file') ouvrirFs(sq);
}
function entree(e) {
if (e.key !== 'Enter' || e.altKey || e.ctrlKey || e.metaKey) return;
var sq = e.target && e.target.closest && e.target.closest('[data-fs]');
if (!sq || sq !== e.target || sq.getAttribute('data-fs-type') !== 'file') return;
var F = W.jOSFiles; if (F && F.partout && !F.partout()) return; // xb:fichiers.ouvrir-partout=off : comme avant
e.preventDefault(); e.stopPropagation(); ouvrirFs(sq);
}
function renommerEntete(b) {
var p = courant(); if (!p) return;
var inp = D.createElement('input'); inp.className = 'bv2-ren'; inp.value = E.nomDe(p); inp.maxLength = 80; inp.setAttribute('aria-label', 'nouveau nom');
b.replaceWith(inp); inp.focus(); inp.select();
var fini = false;
function fin(g) { if (fini) return; fini = true; if (g) E.renommer(p.id, inp.value); persister(); rendre(); }
inp.addEventListener('keydown', function (e) { e.stopPropagation(); if (e.key === 'Enter') fin(true); else if (e.key === 'Escape') fin(false); });
inp.addEventListener('blur', function () { fin(true); });
}
root.addEventListener('click', clic);
root.addEventListener('dblclick', dbl);
root.addEventListener('keydown', entree);
E.charger().then(function () {
if (!alive) return;
desabo.push(E.vivant('portion', inst));
var on = function (e) { var r = e && e.detail && e.detail.raison; if (r === 'menu') return; if (r === 'fs' && S.k === 'fichiers' && e.detail.chemin === S.chemin) delete LISTES_FS[S.chemin]; planifier(); }; // (25.09) 'fs' : un fichier écrit / créé dans le vrai dossier montré — relu
W.addEventListener('xb:bureau', on); desabo.push(function () { W.removeEventListener('xb:bureau', on); });
var ro = null; try { ro = new ResizeObserver(function () { if (vue === 'carres') cadrer(); }); ro.observe(root); desabo.push(function () { ro.disconnect(); }); } catch (e) {}
persister(); rendre();
}, function () {
if (!alive) return;
root.innerHTML = '<div class="pn__attente">le bureau n\'a pas pu se charger' + (api && api.motifs ? ' · <button type="button" data-a="motifs" style="font:inherit;color:#ffc46b;background:none;border:0;cursor:pointer">◳ les motifs</button>' : '') + '</div>';
});
return { unmount: function () { alive = false; clearTimeout(rt); desabo.forEach(function (f) { try { f(); } catch (e) {} }); container.innerHTML = ''; }, naviguer: inst.naviguer };
}
// ═══════════════ le montage : le scope décide (demande du bureau > onglet restauré > rien = les motifs) ═══════════════
function mount(container, ctx) {
ctx = ctx || {};
var W = window, E = W.jOSEntrees, coupe = false, d = null, cur = null, fini = false;
try { coupe = !!(E && E.coupe && (E.coupe('portion.nav') || E.coupe('bureau-v2'))); } catch (e) {} // xb:bureau-v2 = off coupe aussi le navigateur
try { d = (!coupe && E && E.demande) ? E.demande('portion') : null; } catch (e2) {}
var nav = !!(E && E.charger && !coupe);
var api = nav ? {
structure: function (sc) { montrer(sc || 'bureau'); },
motifs: function () { try { if (ctx.tab) ctx.tab.scope = null; if (W.jOS && W.jOS._wm) W.jOS._wm.save(); } catch (e) {} montrer(null); }
} : null;
function montrer(sc) {
if (fini) return;
if (cur) { try { cur.unmount(); } catch (e) {} cur = null; }
cur = (sc && nav) ? navigateur(container, ctx, sc, api) : motifs(container, ctx, api);
}
montrer(d || ctx.scope || null);
return { unmount: function () { fini = true; if (cur) { try { cur.unmount(); } catch (e) {} } cur = null; } };
}
window.jOSApps = window.jOSApps || {};
window.jOSApps['portion'] = { manifest: { id: 'portion', name: 'Portion', icon: '▣' }, mount: mount };
})();
</script>