Files
ploxion-themes/app.blade.php

230 lines
17 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 Themes — app cliente jOS. S'enregistre dans window.jOSApps['themes'].
Éditeur de thème EN FENÊTRE : on édite les tokens --xr-* directement sur
document.documentElement -> la VRAIE page derrière la fenêtre se reskine en
live. Enregistre des thèmes custom (localStorage xb-custom-themes, injectés
au pré-paint). 100% client-side. --}}
<script>
(function () {
var TOK = [
['bg','Fond'],['surface','Surface'],['border','Bordure'],
['accent','Accent'],['accent2','Accent 2'],['text','Texte'],
['muted','Texte discret'],['glow','Glow'],['glow2','Glow 2']
];
var KEY = 'xb-custom-themes';
var root = document.documentElement;
// 🎭 Mode UI — galerie des UIs canoniques (ids EXACTS = contrat des deux côtés).
// Les couleurs ci-dessous ne servent QUE au mini-aperçu de chaque carte (inline-style,
// rendu sans dépendre du CSS chargé). L'application réelle = data-theme + themes.css.
var UIS = [
{ id:'chill-tekk', name:'Chill-tekk', icon:'🌀', c:{ bg:'#080e1c', surface:'#0f1a30', accent:'#3fe0d0', accent2:'#ff5cf0', text:'#e7f0ff', muted:'#5f7699' } },
{ id:'windows', name:'Windows', icon:'🪟', c:{ bg:'#f3f3f3', surface:'#ffffff', accent:'#0067c0', accent2:'#5a9bd8', text:'#1a1a1a', muted:'#9aa0a6' } },
{ id:'iphone', name:'iOS', icon:'🍎', c:{ bg:'#f2f2f7', surface:'#ffffff', accent:'#007aff', accent2:'#34c759', text:'#1c1c1e', muted:'#8e8e93' } },
{ id:'android', name:'Android', icon:'🤖', c:{ bg:'#fef7ff', surface:'#ffffff', accent:'#6750a4', accent2:'#7d5260', text:'#1d1b20', muted:'#a89fb0' } },
{ id:'cassette', name:'Cassette', icon:'📼', c:{ bg:'#d8c8a0', surface:'#c8b488', accent:'#e8622a', accent2:'#c0392b', text:'#3a2a18', muted:'#8a7550' } },
{ id:'voiture', name:'Voiture', icon:'🚗', c:{ bg:'#0a0c10', surface:'#12161e', accent:'#ff7a1a', accent2:'#22d3ee', text:'#e8eef6', muted:'#5a6673' } },
{ id:'crt', name:'Terminal CRT', icon:'📟', c:{ bg:'#020402', surface:'#0a140a', accent:'#00ff66', accent2:'#00b347', text:'#00ff66', muted:'#0a7a38' } },
{ id:'papier', name:'Papier', icon:'📄', c:{ bg:'#f4f1ea', surface:'#ffffff', accent:'#1a1a1a', accent2:'#8a8578', text:'#1a1a1a', muted:'#9a9488' } },
{ id:'vaporwave', name:'Vaporwave', icon:'🌴', c:{ bg:'#1a0b2e', surface:'#2a1350', accent:'#ff6ad5', accent2:'#05ffa1', text:'#f5e6ff', muted:'#8a2be2' } },
{ id:'ambre', name:'Ambre CRT', icon:'🟠', c:{ bg:'#040200', surface:'#140e02', accent:'#ffb000', accent2:'#c78700', text:'#ffb000', muted:'#7a5a0a' } },
{ id:'audit', name:'Audit', icon:'🖥️', c:{ bg:'#0a0e0a', surface:'#111811', accent:'#00d47a', accent2:'#ff9f43', text:'#cfeadb', muted:'#4a6a55' } },
{ id:'chill', name:'Chill', icon:'🌿', c:{ bg:'#f4f7f5', surface:'#ffffff', accent:'#7fb8a4', accent2:'#c9a7d8', text:'#2e3b36', muted:'#a3b3ab' } }
];
// ultimate-theme étape B (docs/dev/44-theme.md) : « format » — une enveloppe {themes:…} (le customiseur d'avant) est dépliée : sinon une
// carte « themes » et une feuille cassée ; « échappement » — un nom de thème perso est une DONNÉE (il venait brut dans le HTML)
function customs(){ try { var c = JSON.parse(localStorage.getItem(KEY) || '{}'), t = T(); return c && typeof c === 'object' ? (t && t._i && t.rep && t.rep('format') ? t._i.pm(c) : c) : {}; } catch(e){ return {}; } }
function escH(v){ return String(v == null ? '' : v).replace(/[&<>"']/g, function(ch){ return '&#' + ch.charCodeAt(0) + ';'; }); }
// ré-injecte le CSS des thèmes custom (le <head> ne le fait qu'au chargement -> nécessaire
// pour appliquer un thème synchronisé depuis le boxion sans recharger).
function injectCustomCSS(){ try{ var c=customs(), css=''; for(var k in c){ var v=c[k]; css+='html[data-theme="'+k+'"]{'; for(var p in v){ css+='--xr-'+p+':'+v[p]+';'; } css+='}'; } var s=document.getElementById('xb-custom-themes-css'); if(!s){ s=document.createElement('style'); s.id='xb-custom-themes-css'; document.head.appendChild(s); } s.textContent=css; }catch(e){} }
// sauve les thèmes custom (localStorage + auto-save sur le boxion -> cross-device).
// l'écrivain de jOSTheme (docs/dev/44-theme.md) quand il est là, avec les effets d'avant ; sinon le code d'avant
function T(){ var t = window.jOSTheme; return t && t.regler ? t : null; } // l'écrivain (sur /px, la porte peut n'être que l'applicateur : le repli d'avant)
function setTheme(id, par){ if(T()) T().regler('theme', id, { par: par, choix: 1 }); else { try { localStorage.setItem('xb-theme', id); } catch(e){} root.setAttribute('data-theme', id); } }
function setCustoms(c){ if(T()) { T().regler('customs', c, { boxion: 1, par: 'themes' }); return; } try{ localStorage.setItem(KEY, JSON.stringify(c)); }catch(e){} injectCustomCSS(); try{ if(window.jOSBoxion) jOSBoxion.saveSoon('themes','custom',c,'Mes thèmes'); }catch(e){} }
function readVar(t){ return (getComputedStyle(root).getPropertyValue('--xr-'+t) || '').trim(); }
function isHex(v){ return /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(v); }
// OUT bus (topic ploxion.themes.theme) : publie le thème actif {theme, tokens:{bg,accent,...}}
// à chaque changement réel (édition live, save, use, reset...). Ex: le canvas du zoom repeint
// ses couleurs peintes en dur avec ces tokens. Best-effort + léger debounce (drag de color picker).
var emitTimer = null;
function emitTheme(){
if (emitTimer) clearTimeout(emitTimer);
emitTimer = setTimeout(function(){
emitTimer = null;
try {
if (!window.jOSPorts) return;
var toks = {}; TOK.forEach(function(p){ var v = readVar(p[0]); if (v) toks[p[0]] = v; });
var name = root.getAttribute('data-theme') || localStorage.getItem('xb-theme') || 'chill-tekk';
jOSPorts.emit('themes', 'theme', { theme: name, tokens: toks });
} catch(e){}
}, 120);
}
function describe(){
var cur='chill-tekk';
try{ cur = document.documentElement.getAttribute('data-theme') || localStorage.getItem('xb-theme') || 'chill-tekk'; }catch(e){}
var n = Object.keys(customs()).length;
return { v:1, id:'themes', title:'Thèmes', icon:'🎨', items:[
{ p:1, kind:'stat', label:'thème actif', value: cur },
{ p:3, kind:'stat', label:'thèmes perso', value: n }
]};
}
{{-- ULTIMATE-THEME ÉTAPE C (docs/dev/44-theme.md §12) : ALIAS de Thème › palette — le même geste (un favori, un lien, un tsoin ancien) ouvre la
section qui le reprend ; seul, sur /px/themes, l'adresse devient /px/theme?section=palette. Kill-switch localStorage xb:theme.ploxion=off : l'éditeur d'avant, tel quel. --}}
function versTheme(container, ctx) {
var T = window.jOSTheme, A = window.jOSApps, c = Object.assign({}, ctx || {}, { section: 'palette', alias: 'themes' });
if (!(T && T.ploxion && T.ploxion()) || !A) return null;
if (A.theme && A.theme.mount) return A.theme.mount(container, c);
if (A.monter && A.peut && A.peut('theme')) return A.monter('theme', container, c);
if (ctx && ctx.standalone) { try { window.location.replace('/px/theme?section=palette'); } catch (e) {} return { unmount: function () {} }; }
return null;
}
function mount(el, ctx) {
var th = versTheme(el, ctx); if (th) return th;
el.innerHTML =
'<style>'
+ '.thx{padding:12px;font:13px system-ui,sans-serif;color:var(--xr-text,#e7f0ff)}'
+ '.thx .hd{opacity:.75;margin-bottom:10px;line-height:1.4}'
+ '.thx .row{display:flex;align-items:center;gap:6px;margin-bottom:7px}'
+ '.thx .row label{width:96px;font-size:.78rem;opacity:.8}'
+ '.thx input[type=color]{width:30px;height:26px;border:none;background:none;padding:0;cursor:pointer}'
+ '.thx input[type=text]{flex:1;min-width:0;background:var(--xr-bg,#0b1220);color:var(--xr-text,#e7f0ff);border:1px solid var(--xr-border,#334);border-radius:6px;padding:3px 6px;font:11px monospace}'
+ '.thx .acts{display:flex;flex-wrap:wrap;gap:6px;margin:12px 0}'
+ '.thx button{background:var(--xr-accent,#3fe0d0);color:#08101e;border:none;border-radius:8px;padding:7px 10px;cursor:pointer;font:600 12px system-ui}'
+ '.thx button.ghost{background:transparent;color:var(--xr-text,#e7f0ff);border:1px solid var(--xr-border,#334)}'
+ '.thx .cust{display:flex;gap:4px;align-items:center;margin-bottom:4px}'
+ '.thx .cust b{flex:1;font-weight:400}'
+ '.thx .note{opacity:.6;font-size:.72rem;margin-top:8px}'
+ '.thx .galhd{font-weight:600;margin:2px 0 8px;display:flex;align-items:center;gap:8px;flex-wrap:wrap}'
+ '.thx .galhd .rnd{margin-left:auto;background:transparent;border:1px solid var(--xr-border,#334);color:var(--xr-text,#e7f0ff);border-radius:8px;padding:6px 10px;cursor:pointer;font:600 12px system-ui}'
+ '.thx .gal{display:grid;grid-template-columns:repeat(auto-fill,minmax(118px,1fr));gap:8px;margin-bottom:16px}'
+ '.thx .uic{border:2px solid transparent;border-radius:10px;padding:0;cursor:pointer;background:var(--xr-surface,#0f1a30);overflow:hidden;text-align:left;min-height:44px;display:flex;flex-direction:column;transition:border-color .12s,transform .12s;font:inherit}'
+ '.thx .uic:hover{transform:translateY(-1px)}'
+ '.thx .uic.on{border-color:var(--xr-accent,#3fe0d0);box-shadow:0 0 0 1px var(--xr-accent,#3fe0d0)}'
+ '.thx .uic .pv{height:50px;display:block}'
+ '.thx .uic .pv .bar{height:15px;display:flex;align-items:center;gap:3px;padding:0 6px}'
+ '.thx .uic .pv .dot{width:7px;height:7px;border-radius:50%}'
+ '.thx .uic .pv .ln{height:4px;border-radius:2px;margin:7px 7px 0}'
+ '.thx .uic .cap{padding:5px 7px;display:flex;align-items:center;gap:5px;line-height:1.2;font:600 11px system-ui;color:var(--xr-text,#e7f0ff)}'
+ '.thx .uic .cap small{font-weight:400;opacity:.55;font-size:.66rem;margin-left:auto}'
+ '</style>'
+ '<div class="thx">'
+ ' <div class="galhd">🎭 Mode UI <button class="rnd" data-rnd="1">🎲 Aléatoire</button></div>'
+ ' <div id="thx-gal" class="gal"></div>'
+ ' <div class="hd">🎨 …ou édite les couleurs → la page <b>derrière</b> cette fenêtre se reskine <b>en live</b>.</div>'
+ ' <div id="thx-rows"></div>'
+ ' <div class="acts">'
+ ' <button data-act="save">💾 Enregistrer</button>'
+ ' <button class="ghost" data-act="copy">⧉ CSS</button>'
+ ' <button class="ghost" data-act="reset">↺ Reset</button>'
+ ' <button class="ghost" data-act="new">+ Nouveau (copie chill-tekk)</button>'
+ ' </div>'
+ ' <div id="thx-cust"></div>'
+ ' <div class="note">Tokens = contrat <code>--xr-*</code>. « Enregistrer » = thème custom (localStorage), réinjecté partout au chargement.'
+ (T() && T().rep && T().rep('masque') ? ' Choisir un thème met de côté ce qui le masquerait (un monde css, les couleurs du noyau) ; « ↩ remettre » les rend.' : '') + '</div>'
+ '</div>';
var rows = el.querySelector('#thx-rows');
TOK.forEach(function (p) {
var t = p[0], v = readVar(t);
var row = document.createElement('div'); row.className = 'row';
row.innerHTML = '<label title="--xr-'+t+'">'+p[1]+'</label>'
+ '<input type="color" data-color="'+t+'" '+(isHex(v)?('value="'+v+'"'):'')+'>'
+ '<input type="text" data-tok="'+t+'" value="'+v.replace(/"/g,'')+'">';
rows.appendChild(row);
});
function apply(t, v){ root.style.setProperty('--xr-'+t, v); } // LIVE sur la vraie page
function tokens(){ var o={}; el.querySelectorAll('[data-tok]').forEach(function(i){ if(i.value.trim()) o[i.dataset.tok]=i.value.trim(); }); return o; }
// ---- 🎭 Galerie Mode UI : une carte par UI canonique, clic = applique ----
function curTheme(){ return root.getAttribute('data-theme') || localStorage.getItem('xb-theme') || 'chill-tekk'; }
function syncRows(){ TOK.forEach(function(p){ var tx=el.querySelector('[data-tok="'+p[0]+'"]'); if(tx) tx.value=readVar(p[0]); var co=el.querySelector('[data-color="'+p[0]+'"]'); if(co&&isHex(readVar(p[0]))) co.value=readVar(p[0]); }); }
function markActive(){ var cur=curTheme(); el.querySelectorAll('.uic').forEach(function(b){ b.classList.toggle('on', b.dataset.ui===cur); }); }
function applyUI(id){
setTheme(id, 'themes');
TOK.forEach(function(p){ root.style.removeProperty('--xr-'+p[0]); }); // vire les overrides inline → laisse le thème CSS parler
syncRows(); markActive(); emitTheme();
}
function renderGal(){
var gal = el.querySelector('#thx-gal'); if (!gal) return; gal.innerHTML='';
UIS.forEach(function(u){
var c=u.c;
var b=document.createElement('button'); b.type='button'; b.className='uic'; b.dataset.ui=u.id;
b.title=u.name+' ('+u.id+')';
b.innerHTML =
'<span class="pv" style="background:'+c.bg+'">'
+ '<span class="bar" style="background:'+c.surface+'">'
+ '<span class="dot" style="background:'+c.accent+'"></span>'
+ '<span class="dot" style="background:'+c.accent2+'"></span>'
+ '</span>'
+ '<span class="ln" style="background:'+c.accent+';width:62%"></span>'
+ '<span class="ln" style="background:'+c.muted+';width:44%"></span>'
+ '</span>'
+ '<span class="cap"><span>'+u.icon+'</span><span>'+u.name+'</span><small>'+u.id+'</small></span>';
gal.appendChild(b);
});
markActive();
}
el.querySelector('#thx-gal').addEventListener('click', function(e){
var card=e.target.closest ? e.target.closest('.uic') : null; if(card && card.dataset.ui) applyUI(card.dataset.ui);
});
el.querySelector('.galhd').addEventListener('click', function(e){
if(!e.target.dataset.rnd) return;
var cur=curTheme(), pool=UIS.filter(function(u){ return u.id!==cur; });
if(!pool.length) return; applyUI(pool[Math.floor(Math.random()*pool.length)].id);
});
rows.addEventListener('input', function (e) {
var i = e.target;
if (i.dataset.tok) { apply(i.dataset.tok, i.value); }
else if (i.dataset.color) {
var tx = el.querySelector('[data-tok="'+i.dataset.color+'"]'); if (tx) tx.value = i.value;
apply(i.dataset.color, i.value);
}
emitTheme();
});
function renderCust(){
var c = customs(), box = el.querySelector('#thx-cust'); box.innerHTML = '';
Object.keys(c).forEach(function (slug) {
var d = document.createElement('div'); d.className = 'cust';
d.innerHTML = '<b>★ '+escH(slug.replace(/^custom-/,''))+'</b>'
+ '<button data-use="'+escH(slug)+'">utiliser</button>'
+ '<button class="ghost" data-del="'+escH(slug)+'" style="color:#ff6b6b">×</button>';
box.appendChild(d);
});
}
el.querySelector('.acts').addEventListener('click', function (e) {
var act = e.target.dataset.act; if (!act) return;
if (act === 'reset') { TOK.forEach(function(p){ root.style.removeProperty('--xr-'+p[0]); }); TOK.forEach(function(p){ var tx=el.querySelector('[data-tok="'+p[0]+'"]'); if(tx) tx.value=readVar(p[0]); var co=el.querySelector('[data-color="'+p[0]+'"]'); if(co&&isHex(readVar(p[0]))) co.value=readVar(p[0]); }); emitTheme(); }
else if (act === 'copy') { var o=tokens(),css='html[data-theme="'+(localStorage.getItem('xb-theme')||'chill-tekk')+'"]{';for(var t in o)css+='--xr-'+t+':'+o[t]+';';css+='}'; (navigator.clipboard&&navigator.clipboard.writeText(css)||Promise.reject()).then(function(){alert('CSS copié.');},function(){prompt('Copie :',css);}); }
else if (act === 'new') { alert('Édite les couleurs (la page se reskine live), puis « 💾 Enregistrer » pour en faire un thème.'); }
else if (act === 'save') {
var name=(prompt('Nom du thème :','mon-theme')||'').trim().toLowerCase().replace(/[^a-z0-9-]+/g,'-'); if(!name) return;
var slug='custom-'+name, c=customs(); c[slug]=tokens();
setCustoms(c); setTheme(slug, 'themes');
renderCust(); emitTheme(); alert('Thème « '+slug+' » enregistré + appliqué. Dispo partout (et dans le sélecteur).');
}
});
el.querySelector('#thx-cust').addEventListener('click', function (e) {
var use=e.target.dataset.use, del=e.target.dataset.del;
if (use) { setTheme(use, 'themes'); TOK.forEach(function(p){root.style.removeProperty('--xr-'+p[0]);}); emitTheme(); }
else if (del) { if(!confirm('Supprimer '+del+' ?'))return; var c=customs(); delete c[del]; setCustoms(c); try{ if(localStorage.getItem('xb-theme')===del)localStorage.removeItem('xb-theme'); }catch(e){} renderCust(); emitTheme(); }
});
renderCust();
renderGal();
// publie le thème courant au bus à l'ouverture (les abonnés, ex: zoom, partent du bon skin)
emitTheme();
// reprise depuis le boxion : retrouve tes thèmes custom sur tous tes appareils
try{ if(window.jOSBoxion && jOSBoxion.authed()){ jOSBoxion.load('themes','custom').then(function(it){ if(it && it.data && typeof it.data==='object'){ if(T()) T().regler('customs', it.data, { par: 'themes-boxion' }); else { try{ localStorage.setItem(KEY, JSON.stringify(it.data)); }catch(e){} injectCustomCSS(); } renderCust(); emitTheme(); } }); } }catch(e){}
}
window.jOSApps = window.jOSApps || {};
window.jOSApps['themes'] = { manifest: { id: 'themes', name: 'Thèmes', icon: '🎨' }, mount: mount, describe: describe };
})();
</script>