ploxion-hud/app.blade.php

397 lines
28 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.

{{-- PL0XI0N hud 🌀 — OBJECTIF 1 de RS-7 : le ZOOM INFINI + animations. Une surface canvas unique où TOUT
le xerboxion est un arbre fractal (racine → catégories → ploxions → provides → …). Zoom infini par
RE-BASAGE : quand un nœud remplit l'écran il devient la nouvelle racine (scale borné = zoom sans fin,
la machine-à-jump). LOD : point → tuile → plein. Molette/pinch = zoom, drag = pan, clic = zoom animé
dans un nœud, zoom à fond dans un ploxion = l'ouvrir. Déterministe (layout = index dans le registre). --}}
<style>
.px-hud{position:relative;height:100%;background:var(--xr-bg,#05060c);overflow:hidden;font-family:var(--xr-font-ui,ui-sans-serif,system-ui);touch-action:none}
.px-hud canvas{display:block;width:100%;height:100%}
.px-hud .path{position:absolute;top:8px;left:10px;right:10px;display:flex;gap:6px;align-items:center;font-size:.7rem;color:var(--xr-muted,#8aa0c8);pointer-events:none;text-shadow:0 1px 3px #000;flex-wrap:wrap}
.px-hud .path b{color:var(--xr-accent,#9fd0ff)}
.px-hud .hint{position:absolute;bottom:8px;left:10px;font-size:.62rem;color:var(--xr-muted,#5a6a90);pointer-events:none}
.px-hud .open{position:absolute;bottom:12px;right:12px;background:linear-gradient(135deg,#1a3a7a,#2a5ad0);color:#fff;border:0;border-radius:10px;padding:11px 15px;font-size:.85rem;font-weight:700;cursor:pointer;display:none;box-shadow:0 4px 18px #0008}
.px-hud .open.on{display:block}
.px-hud .reset{position:absolute;top:8px;right:10px;background:var(--xr-surface,#101a34cc);border:1px solid var(--xr-border,#2b3a68);color:var(--xr-text,#cfe0ff);border-radius:8px;padding:6px 10px;font-size:.7rem;cursor:pointer;z-index:4}
.px-hud.in-hud .reset{right:104px} /* dans le HUD overlay : laisse la place au ✕ fermer, plus de superposition */
.px-hud .mode{position:absolute;bottom:34px;left:10px;background:var(--xr-surface,#101a34cc);border:1px solid var(--xr-border,#2b3a68);color:var(--xr-text,#cfe0ff);border-radius:8px;padding:7px 11px;font-size:.72rem;cursor:pointer;z-index:5}
.px-hud .mode.on{border-color:var(--xr-accent,#ffe08a);color:var(--xr-accent,#ffe08a);background:#241f0a}
.px-hud .hcur{position:absolute;z-index:6;width:46px;height:46px;margin:-23px 0 0 -23px;border:3px solid #ffe08a;border-radius:50%;box-shadow:0 0 16px #ffe08a,inset 0 0 10px #ff00a0;display:none;pointer-events:none}
.px-hud .hcur::after{content:"";position:absolute;inset:15px;border-radius:50%;background:#ffe08a;box-shadow:0 0 10px #ffe08a}
.px-hud.cursor-on .hcur{display:block}
.px-hud .vrc{position:absolute;inset:0;display:none;pointer-events:none;background:#000;z-index:1}
.px-hud.vr-on canvas:not(.vrc){opacity:0}
.px-hud.vr-on .vrc{display:block}
.px-hud.vr-on::after{content:"";position:absolute;top:0;bottom:0;left:calc(50% - 1px);width:2px;background:#000;z-index:2;pointer-events:none}
.px-hud .pxlayer{position:absolute;inset:0;pointer-events:none;overflow:hidden}
.px-hud .pxlayer .pxhost{position:absolute;background:var(--xr-surface,#0a0f1c);border:1px solid var(--xr-accent,#2a5ad0);border-radius:14px;overflow:hidden;pointer-events:auto;box-shadow:0 12px 48px #000b}
</style>
<script>
(function () {
'use strict';
function mount(container, ctx) {
container.innerHTML = '<div class="px-hud"><canvas></canvas><canvas class="vrc" data-vrc></canvas>' +
'<div class="pxlayer" data-pxlayer></div>' +
'<div class="path" data-path></div><button class="reset" data-reset>⟲ racine</button>' +
'<button class="mode" data-mode>✛ curseur</button><div class="hcur" data-hcur></div>' +
'<div class="hint">molette / pinch = zoom · glisse = déplacer · clic = plonger · à fond dans un ploxion = ouvrir</div>' +
'<button class="open" data-open>ouvrir ▶</button></div>';
var root = container.querySelector('.px-hud'), cv = root.querySelector('canvas'), g = cv.getContext('2d');
if (ctx && ctx.hud) root.classList.add('in-hud'); // dans le HUD overlay : décale le ⟲ pour ne pas superposer le ✕
var pathEl = root.querySelector('[data-path]'), openBtn = root.querySelector('[data-open]');
var pxlayer = root.querySelector('[data-pxlayer]');
var mounted = null; // { id, host, inst } — ploxion monté LIVE au zoom profond
var frameBigPx = null; // le plus gros nœud-ploxion de la frame courante {id,X,Y,w,h}
var DPR = Math.min(2, window.devicePixelRatio || 1), W = 0, H = 0, aborted = false, raf = null;
var CATCOL = {}; // couleur par catégorie
function hue(s) { var h = 0; for (var i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) % 360; return h; }
// ---------- arbre ----------
var TREE = { name: 'XERBOXION', icon: '🌀', type: 'root', children: null };
var byId = {};
function buildTree(reg) {
var cats = {};
(reg.ploxions || []).forEach(function (p) {
if (p.status === 'idea') return;
var ck = p.category || 'autres';
if (!cats[ck]) cats[ck] = { name: p.cat_label || ck, icon: p.cat_icon || '📦', type: 'cat', key: ck, children: [] };
var node = { name: p.name, icon: p.icon || '▣', type: 'px', id: p.id, cat: ck,
children: (p.provides || []).slice(0, 6).map(function (pv) { return { name: pv, icon: '·', type: 'leaf', children: fractalKids(pv) }; }) };
cats[ck].children.push(node); byId[p.id] = node;
});
TREE.children = Object.keys(cats).sort().map(function (k) { return cats[k]; });
TREE.children.forEach(function (c) { CATCOL[c.key] = hue(c.key); });
}
// enfants synthétiques pour le ZOOM INFINI (au-delà des provides : la fractale continue — machine-à-jump)
function fractalKids(seed) {
var n = 3 + (hue(seed) % 3);
var a = []; for (var i = 0; i < n; i++) a.push({ name: seed + '·' + i, icon: '∴', type: 'frac', seed: seed + i, children: null });
return a;
}
function kidsOf(node) {
if (node.children) return node.children;
if (node.type === 'frac') { node.children = fractalKids(node.seed); return node.children; } // infini
return [];
}
// ---------- caméra (focus + transform lissé) ----------
// point focus-local (0..1) -> écran. cam.scale = px par unité-monde. Re-basage garde scale borné.
var focus = TREE, parents = []; // pile pour re-baser vers le haut
// CAMÉRA = matrice affine : écran = S*monde + T. On n'ease JAMAIS T séparément de S (pivot de
// similitude courant→cible épinglé chaque frame) → zéro dérive (molette/pan/pinch). Re-base = compo matricielle.
var S, TX, TY, Sg, TXg, TYg, prevW, prevH; // matrice COURANTE + CIBLE (6 scalaires, 0 alloc hot-path)
var cam = { x: 0.5, y: 0.5, s: 1 }; // compat : relu par le LOD/draw, réécrit chaque frame
var EASE = 0.2, IN_AT = 3.2, OUT_AT = 0.34, ROOT_MIN = 0.6, HARD_MAX = 8, LEAF_MIN = 0.15, ROOT_PAN_M = 0.5, K_EPS = 3e-3, S_SNAP = 1e-3, T_SNAP = 0.05;
function baseS() { return Math.min(W, H) * 0.86; }
function worldAt(sx, sy) { return { x: (sx - TX) / S, y: (sy - TY) / S }; }
function initCamera() { focus = TREE; parents.length = 0; S = baseS(); TX = W / 2 - S * 0.5; TY = H / 2 - S * 0.5; Sg = S; TXg = TX; TYg = TY; prevW = W; prevH = H; }
function camResize() { if (!(S > 0)) { if (W > 0 && H > 0) initCamera(); return; } var cx = (W / 2 - TX) / S, cy = (H / 2 - TY) / S, zoomRel = S / (Math.min(prevW || W, prevH || H) * 0.86); S = zoomRel * baseS(); TX = W / 2 - S * cx; TY = H / 2 - S * cy; Sg = S; TXg = TX; TYg = TY; prevW = W; prevH = H; }
function snapNow() { S = Sg; TX = TXg; TY = TYg; }
function childRect(i, n) { // grille déterministe dans [0.08..0.92]^2
var cols = Math.ceil(Math.sqrt(n)), rows = Math.ceil(n / cols);
var cxi = i % cols, cyi = Math.floor(i / cols);
var pad = 0.09, span = 1 - pad * 2, cw = span / cols, ch = span / rows;
var m = Math.min(cw, ch) * 0.16;
return { x: pad + cxi * cw + m, y: pad + cyi * ch + m, w: cw - 2 * m, h: ch - 2 * m };
}
function toScreen(wx, wy) { return { X: S * wx + TX, Y: S * wy + TY }; }
// ---------- rendu ----------
function draw() {
g.setTransform(DPR, 0, 0, DPR, 0, 0);
g.clearRect(0, 0, W, H); g.fillStyle = '#05060c'; g.fillRect(0, 0, W, H);
frameBigPx = null;
// si le focus EST un ploxion (re-basé dedans) → il couvre tout le cadre courant
if (focus.type === 'px') { var f0 = toScreen(0, 0), f1 = toScreen(1, 1); frameBigPx = { id: focus.id, X: f0.X, Y: f0.Y, w: f1.X - f0.X, h: f1.Y - f0.Y }; }
drawNode(focus, 0, 0, 1, 1, 0);
// liseré du focus (le cadre courant)
var a = toScreen(0, 0), b = toScreen(1, 1);
g.strokeStyle = 'rgba(120,150,220,.15)'; g.lineWidth = 1; g.strokeRect(a.X, a.Y, b.X - a.X, b.Y - a.Y);
updateOpen();
}
// node occupe le rect monde (ox,oy,ow,oh) en coords focus-local ; profondeur depth
function drawNode(node, ox, oy, ow, oh, depth) {
var kids = kidsOf(node); if (!kids || !kids.length || depth > 3) return;
for (var i = 0; i < kids.length; i++) {
var r = childRect(i, kids.length);
var wx = ox + r.x * ow, wy = oy + r.y * oh, ww = r.w * ow, wh = r.h * oh;
var s = toScreen(wx, wy), s2 = toScreen(wx + ww, wy + wh);
var pw = s2.X - s.X, ph = s2.Y - s.Y;
if (s.X > W || s.Y > H || s2.X < 0 || s2.Y < 0 || pw < 3) continue; // hors écran / trop petit
var kid = kids[i];
if (kid.type === 'px' && (!frameBigPx || pw > frameBigPx.w)) frameBigPx = { id: kid.id, X: s.X, Y: s.Y, w: pw, h: ph };
var col = kid.cat || node.cat || (kid.key) || node.key || 'x';
var hu = CATCOL[col] != null ? CATCOL[col] : hue(String(col));
// tuile
var rad = Math.min(14, pw * 0.14);
g.beginPath(); rr(g, s.X, s.Y, pw, ph, rad);
g.fillStyle = 'hsla(' + hu + ',55%,' + (12 + depth * 4) + '%,.9)';
g.fill(); g.lineWidth = 1; g.strokeStyle = 'hsla(' + hu + ',70%,55%,.5)'; g.stroke();
// contenu selon la taille (LOD)
var cxp = s.X + pw / 2, cyp = s.Y + ph / 2;
if (pw < 26) { /* point */ g.fillStyle = 'hsla(' + hu + ',80%,65%,.9)'; g.beginPath(); g.arc(cxp, cyp, Math.max(1.5, pw * 0.12), 0, 7); g.fill(); }
else {
g.textAlign = 'center'; g.textBaseline = 'middle';
g.font = Math.min(pw * 0.4, ph * 0.5, 40) + 'px system-ui';
g.fillText(kid.icon || '·', cxp, cyp - (pw > 70 ? ph * 0.12 : 0));
if (pw > 70) { g.fillStyle = '#dbe6ff'; g.font = Math.min(pw * 0.11, 15) + 'px system-ui'; clip(g, s.X, s.Y, pw, ph, function () { g.fillText(kid.name, cxp, cyp + ph * 0.30); }); }
}
// récursion (LOD : seulement si le nœud est assez grand → détail = fractale)
if (pw > 130) drawNode(kid, wx, wy, ww, wh, depth + 1);
}
}
function rr(g, x, y, w, h, r) { r = Math.min(r, w / 2, h / 2); g.moveTo(x + r, y); g.arcTo(x + w, y, x + w, y + h, r); g.arcTo(x + w, y + h, x, y + h, r); g.arcTo(x, y + h, x, y, r); g.arcTo(x, y, x + w, y, r); }
function clip(g, x, y, w, h, fn) { g.save(); g.beginPath(); g.rect(x, y, w, h); g.clip(); fn(); g.restore(); }
// ---------- re-basage (zoom infini in ET out ; algèbre matricielle exacte : IN∘OUT = identité) ----------
function childAtCenter() {
var c = worldAt(W / 2, H / 2), kids = kidsOf(focus); if (!kids) return -1;
for (var i = 0; i < kids.length; i++) { var r = childRect(i, kids.length); if (c.x >= r.x && c.x <= r.x + r.w && c.y >= r.y && c.y <= r.y + r.h) return i; }
return -1;
}
function rebase() {
var zoom = S / baseS();
if (zoom > IN_AT) { // IN : un enfant remplit l'écran → il devient le focus
var i = childAtCenter(); if (i < 0) return;
var kids = kidsOf(focus), kid = kids[i]; if (!kidsOf(kid).length) return; // feuille → stop
var r = childRect(i, kids.length);
parents.push({ node: focus, rect: r }); focus = kid;
TX += S * r.x; TY += S * r.y; S *= r.w; // T avec l'ANCIEN S, PUIS S*=r.w
TXg += Sg * r.x; TYg += Sg * r.y; Sg *= r.w; // même transfo sur la cible (k=Sg/S invariant)
} else if (zoom < OUT_AT && parents.length) { // OUT : remonter au parent (inverse EXACT du IN)
var p = parents.pop(), r2 = p.rect; focus = p.node;
S /= r2.w; TX -= S * r2.x; TY -= S * r2.y; // S/=r.w D'ABORD (nouveau S), PUIS T
Sg /= r2.w; TXg -= Sg * r2.x; TYg -= Sg * r2.y;
}
}
function renderPath() {
var chain = parents.map(function (p) { return p.node; }).concat([focus]);
pathEl.innerHTML = chain.map(function (n, i) { return (i ? '<span>›</span> ' : '') + '<b>' + (n.icon || '') + ' ' + esc(n.name) + '</b>'; }).join(' ');
}
function esc(s) { return window.jOSb.esc(s); }
// ---------- montage LIVE d'un ploxion au zoom profond (« tout est utilisable en zoom ») ----------
function positionHost(big) {
var host = mounted.host;
var x = Math.max(-30, big.X), y = Math.max(-30, big.Y);
var w = Math.min(W + 60, big.X + big.w) - x, h = Math.min(H + 60, big.Y + big.h) - y;
host.style.left = x + 'px'; host.style.top = y + 'px'; host.style.width = Math.max(80, w) + 'px'; host.style.height = Math.max(80, h) + 'px';
}
function mountPx(id) {
unmountPx();
var host = document.createElement('div'); host.className = 'pxhost'; pxlayer.appendChild(host);
mounted = { id: id, host: host, inst: null };
var app = window.jOSApps && window.jOSApps[id];
if (app && id !== 'hud') { try { mounted.inst = app.mount(host, { embed: true, inHud: true }) || null; } catch (e) { host.innerHTML = '<div style="padding:16px;color:#9fb">' + esc(id) + '</div>'; } }
else host.innerHTML = '<div style="padding:16px;color:#9fb">' + esc(id) + (id === 'hud' ? ' (le zoom lui-même 🌀)' : ' — ouvre le bureau pour le live') + '</div>';
}
function unmountPx() {
if (!mounted) return;
try { mounted.inst && mounted.inst.unmount && mounted.inst.unmount(); } catch (e) {}
if (mounted.host && mounted.host.parentNode) mounted.host.parentNode.removeChild(mounted.host);
mounted = null;
}
function managePx() {
var big = frameBigPx, IN = W * 0.52, OUT = W * 0.42; // hystérésis
if (big && big.w > IN) { if (!mounted || mounted.id !== big.id) mountPx(big.id); if (mounted) positionHost(big); }
else if (mounted && (!big || big.w < OUT)) unmountPx();
else if (mounted && big) positionHost(big);
}
// ---------- clamp racine (CIBLE seulement) + easing drift-free (pivot de similitude) + snap ----------
function clampRootTarget() {
if (parents.length) return;
if (Sg < ROOT_MIN * baseS()) Sg = ROOT_MIN * baseS();
var m = ROOT_PAN_M, xg = (W / 2 - TXg) / Sg, yg = (H / 2 - TYg) / Sg;
xg = Math.max(-m, Math.min(1 + m, xg)); yg = Math.max(-m, Math.min(1 + m, yg));
TXg = W / 2 - Sg * xg; TYg = H / 2 - Sg * yg;
}
function ease() {
var k = Sg / S;
if (Math.abs(k - 1) > K_EPS) { // zoom : scale géométrique + pivot écran figé → 0 dérive
var Snew = S * Math.pow(k, EASE), rr = Snew / S;
var Px = (TXg - k * TX) / (1 - k), Py = (TYg - k * TY) / (1 - k);
TX = Px - rr * (Px - TX); TY = Py - rr * (Py - TY); S = Snew;
} else { S = Sg; TX += (TXg - TX) * EASE; TY += (TYg - TY) * EASE; } // pan pur (k≈1)
if (Math.abs(Sg - S) < S_SNAP * Sg && Math.abs(TXg - TX) < T_SNAP && Math.abs(TYg - TY) < T_SNAP) { S = Sg; TX = TXg; TY = TYg; }
}
// ---------- boucle 60fps ----------
function loop() {
if (aborted) return;
if (!(S > 0)) { if (W > 0 && H > 0) { prevW = W; prevH = H; initCamera(); } if (!(S > 0)) { raf = requestAnimationFrame(loop); return; } }
gyroPan(); clampRootTarget(); ease(); rebase();
cam.s = S / baseS(); cam.x = (W / 2 - TX) / S; cam.y = (H / 2 - TY) / S; // compat LOD/draw/currentPxId
draw(); if (mode === 'vr') renderVR(); renderPath(); managePx(); pollGamepad();
raf = requestAnimationFrame(loop);
}
// ---------- interactions (pilotent la CIBLE ; l'easing drift-free rejoint) ----------
function zoomAt(px, py, factor) { // zoom molette/pinch vers (px,py) — point fixe exact sur la cible
var lo = (parents.length ? LEAF_MIN : ROOT_MIN) * baseS(), hi = HARD_MAX * baseS();
var ns = Math.max(lo, Math.min(hi, Sg * factor)), k = ns / Sg;
Sg = ns; TXg = px - k * (px - TXg); TYg = py - k * (py - TYg);
}
function panBy(dx, dy) { TX += dx; TY += dy; TXg += dx; TYg += dy; } // pan 1:1 en px écran (courant + cible)
function onPinch(mx, my, dist, lmx, lmy, ldist) { if (lmx != null) panBy(mx - lmx, my - lmy); if (ldist > 0) zoomAt(mx, my, dist / ldist); snapNow(); }
function diveTo(wx, wy) { Sg = (IN_AT + 0.2) * baseS(); TXg = W / 2 - Sg * wx; TYg = H / 2 - Sg * wy; } // plonge → déclenche rebase IN
cv.addEventListener('wheel', function (e) { e.preventDefault(); var rect = cv.getBoundingClientRect(); zoomAt(e.clientX - rect.left, e.clientY - rect.top, Math.exp(-e.deltaY * 0.0015)); }, { passive: false });
var ptrs = {}, lastDist = 0, lastMid = null, dragged = false, downXY = null;
cv.addEventListener('pointerdown', function (e) { cv.setPointerCapture(e.pointerId); ptrs[e.pointerId] = { x: e.clientX, y: e.clientY }; dragged = false; downXY = { x: e.clientX, y: e.clientY }; });
cv.addEventListener('pointermove', function (e) {
if (!ptrs[e.pointerId]) return;
var rect = cv.getBoundingClientRect(); var prev = ptrs[e.pointerId]; ptrs[e.pointerId] = { x: e.clientX, y: e.clientY };
var ids = Object.keys(ptrs);
if (ids.length >= 2) { // pinch : pan du midpoint + zoom focalisé (drift-free, 1:1 doigts)
var a = ptrs[ids[0]], b = ptrs[ids[1]], d = Math.hypot(a.x - b.x, a.y - b.y);
var mx = (a.x + b.x) / 2 - rect.left, my = (a.y + b.y) / 2 - rect.top;
onPinch(mx, my, d, lastMid ? lastMid.x : null, lastMid ? lastMid.y : null, lastDist);
lastMid = { x: mx, y: my }; lastDist = d; dragged = true;
} else { // pan 1:1 en pixels écran
panBy(e.clientX - prev.x, e.clientY - prev.y);
if (Math.abs(e.clientX - downXY.x) + Math.abs(e.clientY - downXY.y) > 6) dragged = true;
}
});
function up(e) { delete ptrs[e.pointerId]; if (Object.keys(ptrs).length < 2) { lastDist = 0; lastMid = null; }
if (!dragged && downXY) { var rect = cv.getBoundingClientRect(); onTap(downXY.x - rect.left, downXY.y - rect.top); } downXY = null; }
cv.addEventListener('pointerup', up); cv.addEventListener('pointercancel', up);
function onTap(px, py) { // tap un enfant → plonge dedans (animé, drift-free)
var kids = kidsOf(focus); if (!kids) return;
for (var i = 0; i < kids.length; i++) {
var r = childRect(i, kids.length), s = toScreen(r.x, r.y), s2 = toScreen(r.x + r.w, r.y + r.h);
if (px >= s.X && px <= s2.X && py >= s.Y && py <= s2.Y) { diveTo(r.x + r.w / 2, r.y + r.h / 2); return; }
}
}
// ouvrir le ploxion quand on est à fond dedans
function currentPxId() {
// focus lui-même est un ploxion, ou l'enfant au centre est un ploxion très zoomé
if (focus.type === 'px') return focus.id;
var i = childAtCenter(); if (i < 0) return null; var kids = kidsOf(focus); var k = kids[i];
return (k && k.type === 'px' && cam.s > 2) ? k.id : null;
}
function updateOpen() { var id = currentPxId(); if (id) { openBtn.classList.add('on'); openBtn.textContent = 'ouvrir ' + id + ' ▶'; openBtn.dataset.id = id; } else openBtn.classList.remove('on'); }
openBtn.onclick = function (e) {
if (e) { e.preventDefault(); e.stopPropagation(); }
var id = openBtn.dataset.id; if (!id) return;
// séquence canonique (comme _nav) : on teste le SUCCÈS, pas l'existence. openPloxion renvoie null sur mobile.
try { if (window.jOSOp && window.jOSOp.openPloxion) { var r = window.jOSOp.openPloxion(id); if (r && r.ok) return; } } catch (_) {}
try { if (window.jOSMobile && window.jOSMobile.open && window.jOSMobile.open(id, id)) return; } catch (_) {}
try { if (window.jOS && window.jOS.openPloxion && window.jOS.openPloxion(id)) return; } catch (_) {}
location.href = '/local#px=' + encodeURIComponent(id); // fallback universel (iPhone : ouvre plein écran)
};
root.querySelector('[data-reset]').onclick = function () { initCamera(); };
// ---------- MODE CURSEUR (manette / flèches clavier) — optionnel, « le jeu des zooms » (RS-7) ----------
var mode = 'touch', hcur = root.querySelector('[data-hcur]'), hc = { x: 0, y: 0 }, gpBtns = {};
function placeCur() { hcur.style.left = hc.x + 'px'; hcur.style.top = hc.y + 'px'; }
var MODES = ['touch', 'cursor', 'gyro', 'vr'];
function setMode(m) {
if (m === 'gyro' || m === 'vr') enableGyro(); else disableGyro();
mode = m; root.classList.toggle('cursor-on', m === 'cursor'); root.classList.toggle('vr-on', m === 'vr');
var b = root.querySelector('[data-mode]'); b.classList.toggle('on', m !== 'touch');
b.textContent = m === 'cursor' ? '✛ curseur' : m === 'gyro' ? '📱 gyro' : m === 'vr' ? '🥽 VR' : '⊹ touch';
if (m === 'cursor') { hc.x = W / 2; hc.y = H / 2; placeCur(); }
}
root.querySelector('[data-mode]').onclick = function () { setMode(MODES[(MODES.indexOf(mode) + 1) % MODES.length]); };
function curMove(dx, dy) { hc.x = Math.max(6, Math.min(W - 6, hc.x + dx)); hc.y = Math.max(6, Math.min(H - 6, hc.y + dy)); placeCur(); }
function curDive() { onTap(hc.x, hc.y); } // plonge dans le nœud sous le curseur
function diveOut() { Sg = OUT_AT * 0.9 * baseS(); } // dézoom d'un niveau (déclenche rebase OUT si parent)
function onKeyCur(e) {
if (mode !== 'cursor') return;
if (e.target && /^(INPUT|TEXTAREA|SELECT)$/.test(e.target.tagName)) return;
var step = e.shiftKey ? 90 : 42, k = e.key;
if (k === 'ArrowUp') curMove(0, -step); else if (k === 'ArrowDown') curMove(0, step);
else if (k === 'ArrowLeft') curMove(-step, 0); else if (k === 'ArrowRight') curMove(step, 0);
else if (k === 'Enter' || k === ' ') curDive(); else if (k === 'Backspace') diveOut();
else return;
e.preventDefault();
}
window.addEventListener('keydown', onKeyCur, true);
function pollGamepad() { // sondée dans la boucle quand mode curseur (Gamepad API — manette)
if (mode !== 'cursor' || !navigator.getGamepads) return;
var pads = navigator.getGamepads();
for (var i = 0; i < pads.length; i++) {
var p = pads[i]; if (!p) continue;
var ax = p.axes[0] || 0, ay = p.axes[1] || 0;
if (Math.abs(ax) > 0.18 || Math.abs(ay) > 0.18) curMove(ax * 13, ay * 13);
if (p.buttons[12] && p.buttons[12].pressed) curMove(0, -11);
if (p.buttons[13] && p.buttons[13].pressed) curMove(0, 11);
if (p.buttons[14] && p.buttons[14].pressed) curMove(-11, 0);
if (p.buttons[15] && p.buttons[15].pressed) curMove(11, 0);
var a = !!(p.buttons[0] && p.buttons[0].pressed), b = !!(p.buttons[1] && p.buttons[1].pressed);
if (a && !gpBtns.a) curDive(); gpBtns.a = a;
if (b && !gpBtns.b) diveOut(); gpBtns.b = b;
}
}
// ---------- MODE GYRO / ACCÉLÉROMÈTRE : incliner le téléphone pour se balader (RS-7) ----------
var gyro = { on: false, baseB: null, baseG: null, b: 0, g: 0 };
function onOrient(e) { if (e.beta == null) return; if (gyro.baseB == null) { gyro.baseB = e.beta; gyro.baseG = e.gamma; } gyro.b = e.beta; gyro.g = e.gamma; }
function enableGyro() {
if (gyro.on) return;
function attach() { gyro.baseB = null; window.addEventListener('deviceorientation', onOrient, true); gyro.on = true; }
try {
if (typeof DeviceOrientationEvent !== 'undefined' && DeviceOrientationEvent.requestPermission) {
DeviceOrientationEvent.requestPermission().then(function (r) { if (r === 'granted') attach(); }).catch(function () {}); // iOS : geste requis (le tap sur le bouton)
} else attach();
} catch (e) {}
}
function disableGyro() { if (!gyro.on) return; try { window.removeEventListener('deviceorientation', onOrient, true); } catch (e) {} gyro.on = false; gyro.baseB = null; }
function gyroPan() {
if ((mode !== 'gyro' && mode !== 'vr') || !gyro.on || gyro.baseB == null) return;
var dB = gyro.b - gyro.baseB, dG = gyro.g - gyro.baseG, dz = 4, gain = 0.55, cap = 22;
var vx = Math.abs(dG) > dz ? Math.max(-cap, Math.min(cap, -dG * gain)) : 0; // incliner G/D → pan horizontal
var vy = Math.abs(dB) > dz ? Math.max(-cap, Math.min(cap, -dB * gain)) : 0; // incliner avant/arrière → pan vertical
if (vx || vy) panBy(vx, vy);
}
// recalibre le « à plat » sur double-tap du bouton mode (utile quand tu changes de posture)
root.querySelector('[data-mode]').addEventListener('dblclick', function () { if (mode === 'gyro' || mode === 'vr') gyro.baseB = null; });
// ---------- MODE VR (cardboard) : la scène dupliquée en 2 yeux + gyro pour regarder autour ----------
// Honnête : carte 2D → pas de vraie profondeur 3D ; c'est un viewer cardboard (2 yeux + léger parallaxe).
var vrc = root.querySelector('.vrc'), vg = vrc.getContext('2d');
function renderVR() {
if (vrc.width !== cv.width || vrc.height !== cv.height) { vrc.width = cv.width; vrc.height = cv.height; }
vg.setTransform(1, 0, 0, 1, 0, 0); vg.clearRect(0, 0, vrc.width, vrc.height);
var hw = vrc.width / 2, hh = vrc.height, par = vrc.width * 0.01; // léger décalage inter-oculaire
vg.drawImage(cv, 0, 0, cv.width, cv.height, -par, 0, hw, hh); // œil gauche
vg.drawImage(cv, 0, 0, cv.width, cv.height, hw + par, 0, hw, hh); // œil droit
}
// ---------- resize + boot ----------
function resize() { var r = root.getBoundingClientRect(); W = r.width; H = r.height; cv.width = W * DPR; cv.height = H * DPR; cv.style.width = W + 'px'; cv.style.height = H + 'px'; camResize(); }
var ro = new ResizeObserver(resize); ro.observe(root); resize();
fetch('/px/registry.json', { cache: 'no-store' }).then(function (r) { return r.ok ? r.json() : null; }).then(function (d) {
if (aborted || !d) return; buildTree(d); loop();
}).catch(function () { loop(); });
return { unmount: function () { aborted = true; cancelAnimationFrame(raf); unmountPx(); disableGyro(); try { window.removeEventListener('keydown', onKeyCur, true); } catch (e) {} try { ro.disconnect(); } catch (e) {} container.innerHTML = ''; } };
}
// ===== XUI (contrat v0) : describe() PUR, marche NON MONTÉ — compte le monde zoomable
// depuis window.__PLOXIONS__ / jOSApps (le registre que le hud met en arbre), jamais le
// DOM. Ne lève jamais. =====
function describe(){
try {
var n = 0, live = 0;
try { n = (window.__PLOXIONS__ && window.__PLOXIONS__.length) || 0; } catch (e0) {}
try { live = Object.keys(window.jOSApps || {}).length; } catch (e1) {}
var items = [
{ p:1, kind:'stat', label:'🌀 zoom infini', value: n ? (n + ' ploxions dans l’arbre') : 'tout le xerboxion en une surface' },
{ p:2, kind:'stat', label:'montables en zoom profond', value: live },
{ p:3, kind:'text', label:'molette/pinch = zoom, re-basage fractal sans fin — à fond dans un ploxion = il s’ouvre LIVE' }
];
return { v:1, id:'hud', title:'Zoom', icon:'🌀', items:items };
} catch (e) {
return { v:1, id:'hud', title:'Zoom', icon:'🌀', items:[{ p:1, kind:'text', label:'Zoom — le zoom infini' }] };
}
}
window.jOSApps = window.jOSApps || {};
window.jOSApps['hud'] = { manifest: { id: 'hud', name: 'Zoom', icon: '🌀' }, mount: mount, describe: describe };
})();
</script>