106 lines
8.1 KiB
PHP
106 lines
8.1 KiB
PHP
{{-- PL0XION capsule — une CAPSULE TEMPORELLE (von Neumann, forge PAR BIONS, pour
|
|
le tsoin engine). RS-7 : « des trucs chill à envoyer dans le futur, chaque
|
|
truc est un repo ». Tu scelles un message ; il est ADRESSÉ à une date future
|
|
et reste caché jusqu'à sa livraison — un tsoin adressé dans le temps. 100%
|
|
local (localStorage). Composé sur window.jOSb + window.jOSTsoin.
|
|
window.jOSApps['capsule']. mount(c,ctx)->{unmount}. --}}
|
|
@include('ploxions._bions')
|
|
<style>
|
|
.cp { display:flex; flex-direction:column; height:100%; background:radial-gradient(circle at 50% 0%, rgba(60,40,110,.25), #0a0b12 70%); color:#ece9f6; font-family:ui-sans-serif,system-ui,sans-serif; font-size:.84rem; }
|
|
.cp__bar { flex:0 0 auto; display:flex; align-items:center; gap:8px; padding:9px 12px; border-bottom:1px solid rgba(150,130,255,.18); }
|
|
.cp__t { font-weight:800; color:#c4b5fd; }
|
|
.cp__new { flex:0 0 auto; padding:11px; display:flex; flex-direction:column; gap:8px; border-bottom:1px solid rgba(150,130,255,.12); }
|
|
.cp__new textarea { box-sizing:border-box; resize:none; min-height:54px; background:rgba(0,0,0,.3); border:1px solid rgba(150,130,255,.25); border-radius:10px; color:#eae6fb; padding:10px; font:0.88rem ui-sans-serif,system-ui; outline:none; }
|
|
.cp__new textarea:focus { border-color:rgba(167,139,250,.6); }
|
|
.cp__when { display:flex; gap:6px; flex-wrap:wrap; align-items:center; }
|
|
.cp__chip { cursor:pointer; font-size:.72rem; padding:5px 11px; border-radius:16px; border:1px solid rgba(150,130,255,.3); background:rgba(28,22,46,.5); color:rgba(220,210,245,.85); }
|
|
.cp__chip.on { background:rgba(124,92,250,.45); border-color:rgba(167,139,250,.7); color:#fff; }
|
|
.cp__seal { cursor:pointer; border-radius:10px; border:0; background:#a78bfa; color:#1a1030; font-weight:800; padding:9px 18px; margin-left:auto; }
|
|
.cp__seal:hover { filter:brightness(1.08); }
|
|
.cp__list { flex:1; min-height:0; overflow-y:auto; padding:10px 11px; display:flex; flex-direction:column; gap:9px; }
|
|
.cp__c { border:1px solid rgba(150,130,255,.2); border-radius:13px; padding:12px; background:rgba(255,255,255,.022); }
|
|
.cp__c.sealed { background:linear-gradient(135deg, rgba(40,30,70,.5), rgba(20,16,36,.5)); }
|
|
.cp__h { display:flex; align-items:center; gap:8px; font-size:.72rem; color:rgba(200,190,235,.7); }
|
|
.cp__h .ic { font-size:1.05rem; } .cp__sp { flex:1; }
|
|
.cp__del { cursor:pointer; border:0; background:none; color:rgba(255,150,150,.6); font-size:.72rem; }
|
|
.cp__body { margin-top:8px; font-size:.92rem; line-height:1.5; white-space:pre-wrap; word-break:break-word; }
|
|
.cp__locked { margin-top:8px; font-size:.82rem; color:rgba(190,180,225,.6); font-style:italic; }
|
|
.cp__cd { color:#c4b5fd; font-weight:700; font-variant-numeric:tabular-nums; }
|
|
.cp__empty { text-align:center; color:rgba(190,180,225,.5); padding:24px; font-size:.85rem; line-height:1.5; }
|
|
@media (max-width:768px) {
|
|
.cp__bar { flex-wrap:nowrap !important; overflow-x:auto; -webkit-overflow-scrolling:touch; min-height:44px; box-sizing:border-box; }
|
|
.cp__bar > * { flex:0 0 auto; white-space:nowrap; }
|
|
.cp__bar > span:last-child { flex:0 1 auto; overflow:hidden; text-overflow:ellipsis; }
|
|
}
|
|
</style>
|
|
<script>
|
|
(function () {
|
|
'use strict';
|
|
var DAY = 86400000;
|
|
var WHENS = [['1 jour', DAY], ['1 semaine', 7 * DAY], ['1 mois', 30 * DAY], ['1 an', 365 * DAY], ['10 ans', 3650 * DAY]];
|
|
|
|
function describe(){
|
|
var store = window.jOSb ? jOSb.store('xb:capsules') : { get: function (d) { return d; } };
|
|
var caps = store.get([]) || [];
|
|
return { v:1, id:'capsule', title:'Capsule', icon:'⏳', items:[
|
|
{ p:1, kind:'stat', label:'capsules scellées', value:caps.length }
|
|
]};
|
|
}
|
|
function mount(container, ctx) {
|
|
var store = window.jOSb ? jOSb.store('xb:capsules') : { get: function (d) { return d; }, set: function () {} };
|
|
var caps = store.get([]) || [], when = DAY, tick = 0;
|
|
container.innerHTML =
|
|
'<div class="cp">'
|
|
+ ' <div class="cp__bar"><span class="cp__t">⏳ Capsule</span><span style="font-size:.66rem;color:rgba(200,190,235,.55)">scelle un truc chill pour le futur</span></div>'
|
|
+ ' <div class="cp__new"><textarea data-text placeholder="un message, une pensée, un état d\'esprit… pour plus tard"></textarea>'
|
|
+ ' <div class="cp__when">' + WHENS.map(function (w, i) { return '<span class="cp__chip' + (i === 0 ? ' on' : '') + '" data-when="' + w[1] + '">' + w[0] + '</span>'; }).join('')
|
|
+ ' <button class="cp__seal" data-seal>⧗ sceller</button></div></div>'
|
|
+ ' <div class="cp__list" data-list></div></div>';
|
|
var elText = container.querySelector('[data-text]'), list = container.querySelector('[data-list]');
|
|
|
|
function fmtLeft(ms) {
|
|
if (ms <= 0) return 'maintenant';
|
|
var d = Math.floor(ms / DAY), h = Math.floor((ms % DAY) / 3600000), m = Math.floor((ms % 3600000) / 60000);
|
|
if (d > 0) return d + 'j ' + h + 'h';
|
|
if (h > 0) return h + 'h ' + m + 'm';
|
|
return m + 'm';
|
|
}
|
|
function fmtDate(ts) { try { return new Date(ts).toLocaleDateString('fr-FR', { day: '2-digit', month: 'short', year: 'numeric' }); } catch (e) { return ''; } }
|
|
function render() {
|
|
if (!caps.length) { list.innerHTML = '<div class="cp__empty">aucune capsule.<br>Écris un truc chill, choisis quand, et scelle-le — il t\'attendra dans le futur.</div>'; return; }
|
|
var now = Date.now();
|
|
list.innerHTML = caps.slice().sort(function (a, b) { return a.at - b.at; }).map(function (c) {
|
|
var open = now >= c.at, left = c.at - now;
|
|
return '<div class="cp__c ' + (open ? 'open' : 'sealed') + '" data-id="' + c.id + '">'
|
|
+ '<div class="cp__h"><span class="ic">' + (open ? '✨' : '🔒') + '</span>'
|
|
+ '<span>' + (open ? 'livrée · scellée le ' + fmtDate(c.sealed) : 'arrive le ' + fmtDate(c.at) + ' · <span class="cp__cd">' + fmtLeft(left) + '</span>') + '</span>'
|
|
+ '<span class="cp__sp"></span><button class="cp__del" data-del="' + c.id + '">✕</button></div>'
|
|
+ (open ? '<div class="cp__body">' + jOSb.esc(c.text) + '</div>' : '<div class="cp__locked">🔮 scellée — révélée à sa livraison</div>')
|
|
+ '</div>';
|
|
}).join('');
|
|
list.querySelectorAll('[data-del]').forEach(function (b) { b.addEventListener('click', function () { caps = caps.filter(function (x) { return x.id !== b.getAttribute('data-del'); }); store.set(caps); render(); }); });
|
|
}
|
|
function seal() {
|
|
var txt = elText.value.trim(); if (!txt) { if (window.jOSb) jOSb.toast(container, 'écris quelque chose d\'abord', { bad: true }); return; }
|
|
var c = { id: 'c' + Date.now().toString(36), text: txt, sealed: Date.now(), at: Date.now() + when };
|
|
caps.push(c); store.set(caps); elText.value = '';
|
|
// c'est un tsoin adressé au futur : on le marque dans la machine à tsoins si elle enregistre
|
|
try { if (window.jOSTsoin && window.jOSTsoin.isOn && window.jOSTsoin.isOn()) window.jOSTsoin.mark('capsule', 'futur ' + fmtDate(c.at)); } catch (e) {}
|
|
if (window.jOSb) jOSb.toast(container, '⧗ capsule scellée — rendez-vous dans le futur');
|
|
render();
|
|
}
|
|
|
|
container.querySelector('[data-seal]').addEventListener('click', seal);
|
|
container.querySelectorAll('[data-when]').forEach(function (ch) { ch.addEventListener('click', function () {
|
|
when = +ch.getAttribute('data-when'); container.querySelectorAll('.cp__chip').forEach(function (x) { x.classList.toggle('on', x === ch); });
|
|
}); });
|
|
|
|
render();
|
|
tick = setInterval(render, 30000); // rafraîchit les comptes à rebours
|
|
return { unmount: function () { if (tick) clearInterval(tick); container.innerHTML = ''; } };
|
|
}
|
|
window.jOSApps = window.jOSApps || {};
|
|
window.jOSApps['capsule'] = { manifest: { id: 'capsule', name: 'Capsule', icon: '⏳' }, mount: mount, describe: describe };
|
|
})();
|
|
</script>
|