ploxion-zoom/app.blade.php

187 lines
10 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{{-- PL0XION zoom — le ZOOM INFINI à la molette = le WORMION (registre : « zoom
infini du contenu à la molette — le wormion »). Le wormion = des ronds dans
des ronds dans des ronds (cf. grammaire géométrique de RS-7) : ici on zoome à
l'INFINI dans des cercles concentriques auto-similaires — plus tu zoomes, plus
il y en a, sans fin. Réparation d'une entrée du marketplace déclarée mais vide.
100% canvas, aucune lib. window.jOSApps['zoom']. mount(c, ctx) -> { unmount }. --}}
<style>
.zm { position:relative; height:100%; background:#04050a; overflow:hidden; cursor:zoom-in;
font-family:ui-sans-serif,system-ui,sans-serif; }
.zm canvas { display:block; width:100%; height:100%; touch-action:none; }
.zm__hud { position:absolute; left:11px; top:10px; font-size:.72rem; color:rgba(170,200,255,.85);
font-family:ui-monospace,monospace; background:rgba(8,12,22,.6); padding:4px 9px; border-radius:8px; pointer-events:none; }
.zm__hud b { color:#fff; }
.zm__hint { position:absolute; right:11px; bottom:10px; font-size:.64rem; color:rgba(160,180,220,.6);
background:rgba(8,12,22,.6); padding:4px 9px; border-radius:8px; pointer-events:none; }
</style>
<script>
(function () {
function mount(container, ctx) {
container.innerHTML = '<div class="zm"><canvas></canvas>'
+ '<div class="zm__hud">🌀 wormion · zoom <b data-z>×1.0</b></div>'
+ '<div class="zm__hint">molette / pinch pour zoomer à l’infini · double-clic = recentrer</div></div>';
var root = container.querySelector('.zm'), cv = container.querySelector('canvas'), cx = cv.getContext('2d');
var hud = container.querySelector('[data-z]');
var RATIO = 1.6; // facteur entre deux cercles successifs
var LOGR = Math.log(RATIO);
var zoom = 0; // zoom logarithmique (continu, infini)
var raf = 0, alive = true;
var baseHue = 200; // teinte de base, repeinte par l'entrée skin (thème actif)
var flyRaf = 0, focusLabel = '', focusTimer = null;
function size() {
var r = root.getBoundingClientRect(), dpr = Math.min(2, window.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 draw() {
var r = root.getBoundingClientRect(), w = r.width, h = r.height, cxp = w / 2, cyp = h / 2;
cx.clearRect(0, 0, w, h);
var maxR = Math.hypot(w, h);
// phase continue : la partie fractionnaire de zoom/LOGR fait « respirer »
// les cercles ; on en dessine assez pour couvrir l'écran à toute échelle.
var phase = (zoom / LOGR);
for (var k = -2; k < 40; k++) {
var rad = 9 * Math.pow(RATIO, k + (phase % 1));
if (rad < 2) continue;
if (rad > maxR) break;
var depth = (k + phase) ; // pour la couleur/opacité
var hue = baseHue + 40 * Math.sin(depth * 0.5);
var op = 0.18 + 0.5 * (1 - Math.min(1, rad / maxR));
cx.beginPath();
cx.arc(cxp, cyp, rad, 0, Math.PI * 2);
cx.strokeStyle = 'hsla(' + hue + ',70%,65%,' + op + ')';
cx.lineWidth = Math.max(0.6, rad * 0.012);
cx.stroke();
// un petit triangle (koin) posé sur le cercle — clin d'œil à la grammaire
if (rad > 24) {
var a = depth * 0.7;
cx.beginPath();
cx.moveTo(cxp + Math.cos(a) * rad, cyp + Math.sin(a) * rad);
cx.lineTo(cxp + Math.cos(a + 0.18) * rad * 0.92, cyp + Math.sin(a + 0.18) * rad * 0.92);
cx.lineTo(cxp + Math.cos(a - 0.18) * rad * 0.92, cyp + Math.sin(a - 0.18) * rad * 0.92);
cx.closePath();
cx.fillStyle = 'hsla(' + (hue + 60) + ',75%,70%,' + (op * 0.8) + ')';
cx.fill();
}
}
hud.textContent = '×' + Math.exp(zoom).toFixed(2) + (focusLabel ? ' → ' + focusLabel : '');
}
function schedule() { if (!raf) raf = requestAnimationFrame(function () { raf = 0; draw(); }); }
// OUT scale (topic ploxion.zoom.scale) : l'échelle partagée du wormion, publiée à chaque
// vrai changement de zoom (molette / pinch / recentrage / vol focus). map + room-map la lisent.
// Léger debounce (rafales de molette), best-effort.
var emitTimer = null;
function emitScale() {
if (emitTimer) clearTimeout(emitTimer);
emitTimer = setTimeout(function () {
emitTimer = null;
try {
if (window.jOSPorts && jOSPorts.emit)
jOSPorts.emit('zoom', 'scale', { scale: Math.exp(zoom), zoom: Math.round(zoom * 1000) / 1000, ring: Math.floor(zoom / LOGR) });
} catch (e) {}
}, 120);
}
// IN focus (depuis marketplace.open via jOSWire) : ouvrir un ploxion fait « voler » le
// wormion — plongée animée de quelques anneaux vers la tuile, label affiché au HUD.
function flyTo(dz, label) {
if (flyRaf) { cancelAnimationFrame(flyRaf); flyRaf = 0; }
if (focusTimer) { clearTimeout(focusTimer); focusTimer = null; }
focusLabel = label || '';
var from = zoom, to = zoom + dz, t0 = performance.now(), DUR = 900;
function step(now) {
flyRaf = 0;
if (!alive) return;
var t = Math.min(1, (now - t0) / DUR), e = 1 - Math.pow(1 - t, 3); // ease-out
zoom = from + (to - from) * e;
draw();
if (t < 1) { flyRaf = requestAnimationFrame(step); }
else {
emitScale();
focusTimer = setTimeout(function () { focusTimer = null; focusLabel = ''; if (alive) schedule(); }, 4000);
}
}
flyRaf = requestAnimationFrame(step);
}
function onFocus(p) {
if (!p || typeof p !== 'object') return;
var id = (typeof p.id === 'string' && p.id) ? p.id : (typeof p.name === 'string' ? p.name : '');
if (!id) return;
flyTo(3 * LOGR, id); // plonge de 3 anneaux vers la tuile ouverte
}
// IN skin (depuis themes.theme via jOSWire) : le canvas peint en dur (#04050a + hsla JS)
// se repeint avec les tokens --xr-* du thème actif (fond + teinte tirée de l'accent).
function hexHue(v) {
if (typeof v !== 'string') return null;
var m = v.trim().match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);
if (!m) return null;
var s = m[1];
if (s.length === 3) s = s.charAt(0) + s.charAt(0) + s.charAt(1) + s.charAt(1) + s.charAt(2) + s.charAt(2);
var r = parseInt(s.slice(0, 2), 16) / 255, g = parseInt(s.slice(2, 4), 16) / 255, b = parseInt(s.slice(4, 6), 16) / 255;
var mx = Math.max(r, g, b), mn = Math.min(r, g, b), d = mx - mn;
if (!d) return 0;
var h = (mx === r) ? ((g - b) / d) % 6 : (mx === g) ? (b - r) / d + 2 : (r - g) / d + 4;
h = Math.round(h * 60); if (h < 0) h += 360;
return h;
}
function onSkin(p) {
if (!p || typeof p !== 'object' || !p.tokens || typeof p.tokens !== 'object') return;
var toks = p.tokens, touched = false;
if (typeof toks.bg === 'string' && toks.bg) { root.style.background = toks.bg; touched = true; }
var h = hexHue(toks.accent) ; if (h == null) h = hexHue(toks.glow);
if (h != null) { baseHue = h; touched = true; }
if (touched) schedule();
}
function onWheel(e) { e.preventDefault(); zoom += (e.deltaY < 0 ? 1 : -1) * 0.12; schedule(); emitScale(); }
cv.addEventListener('wheel', onWheel, { passive: false });
// pinch tactile
var pinch = null;
cv.addEventListener('touchmove', function (e) {
if (e.touches.length === 2) {
e.preventDefault();
var dx = e.touches[0].clientX - e.touches[1].clientX, dy = e.touches[0].clientY - e.touches[1].clientY;
var d = Math.hypot(dx, dy);
if (pinch != null) { zoom += Math.log(d / pinch); schedule(); emitScale(); }
pinch = d;
}
}, { passive: false });
cv.addEventListener('touchend', function () { pinch = null; });
root.addEventListener('dblclick', function () { zoom = 0; focusLabel = ''; schedule(); emitScale(); });
// bus jOSPorts : abonnements aux entrées propres (jOSWire route themes.theme -> zoom.skin,
// marketplace.open -> zoom.focus). off() gardés pour le droit au silence à l'unmount.
var offs = [];
try {
if (window.jOSPorts && jOSPorts.on) {
offs.push(jOSPorts.on('ploxion.zoom.skin', onSkin));
offs.push(jOSPorts.on('ploxion.zoom.focus', onFocus));
}
} catch (e) {}
var ro = new ResizeObserver(function () { size(); draw(); });
ro.observe(root);
size(); draw();
emitScale(); // publie l'échelle initiale (l'échelle partagée existe dès l'ouverture)
return { unmount: function () {
alive = false;
try { ro.disconnect(); } catch (e) {}
if (raf) cancelAnimationFrame(raf);
if (flyRaf) cancelAnimationFrame(flyRaf);
if (emitTimer) clearTimeout(emitTimer);
if (focusTimer) clearTimeout(focusTimer);
offs.forEach(function (f) { try { if (typeof f === 'function') f(); } catch (e) {} });
offs = [];
container.innerHTML = '';
} };
}
window.jOSApps = window.jOSApps || {};
window.jOSApps['zoom'] = { manifest: { id: 'zoom', name: 'Zoom', icon: '🌀' }, mount: mount };
})();
</script>