SHA256
CORE/CONTENT test5593 и адаптация UI
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# Static sites
|
||||
|
||||
Рабочая папка для временных статических сайтов, дизайн-примеров и standalone-viewer'ов.
|
||||
|
||||
Все содержимое этой папки деплоится вместе с `shine-UI`, потому что общий UI deploy синхронизирует весь каталог `shine-UI/` в Caddy web root. На текущей схеме отдельная перенастройка Caddy для каждого нового сайта не нужна: Caddy сначала отдает существующие файлы из UI root, а уже потом делает fallback на основной `index.html`.
|
||||
|
||||
НО К UI Никакого отношения не имеет :))
|
||||
@@ -0,0 +1,343 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover,user-scalable=no">
|
||||
<meta name="theme-color" content="#0d1016">
|
||||
<title>Walking Arm Monitor v4 · Axes</title>
|
||||
<style>
|
||||
:root{color-scheme:dark;--bg:#0d1016;--card:#171b24;--line:#2a3140;--text:#f6f7fb;--muted:#98a2b3;--blue:#8db8ff;--good:#7ee2a8;--mid:#ffd479;--bad:#ff8c8c}
|
||||
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}body{margin:0;background:var(--bg);color:var(--text);font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif}main{max-width:760px;margin:auto;padding:16px 14px 38px}.top h1{margin:3px 0 2px;font-size:24px}.top p{margin:0;color:var(--muted);font-size:14px}.card{margin-top:12px;background:var(--card);border:1px solid var(--line);border-radius:22px;padding:16px}.hero{text-align:center;padding:22px 16px}.eyebrow{font-size:12px;letter-spacing:.08em;text-transform:uppercase;color:var(--muted)}#state{font-size:42px;font-weight:900;line-height:1.05;margin:8px 0 5px}.score{font-size:64px;font-weight:900;line-height:1}.score small{font-size:22px;color:var(--muted)}.bar{height:12px;background:#0f1218;border-radius:999px;overflow:hidden;margin:14px 2px 4px}.fill{height:100%;width:0%;background:var(--blue);transition:width .22s ease}.hint{font-size:13px;color:var(--muted);min-height:20px}.grid{display:grid;grid-template-columns:1fr 1fr;gap:10px}.metric{padding:13px;background:#10141b;border-radius:16px}.metric span{display:block;font-size:12px;color:var(--muted)}.metric b{display:block;font-size:25px;margin-top:3px}.metric em{font-style:normal;font-size:12px;color:var(--muted)}button{width:100%;border:0;border-radius:16px;padding:15px 13px;margin-top:8px;font-size:16px;font-weight:800;background:#29303d;color:white;touch-action:manipulation}button.primary{background:var(--blue);color:#07101d}button.good{background:var(--good);color:#07150e}button.warn{background:var(--mid);color:#1b1302}button.stop{background:var(--bad);color:#1b0707}button:disabled{opacity:.42}.row{display:flex;gap:8px}.row>*{flex:1}.settings{display:grid;grid-template-columns:1fr;gap:14px;margin-top:12px}.setting{background:#10141b;border-radius:16px;padding:13px}.setting-head{display:flex;justify-content:space-between;gap:12px;align-items:center;margin-bottom:9px}.setting-head span{font-size:13px;color:var(--muted)}.setting-head b{font-size:15px}.delay-row{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}.delay-btn{margin:0;padding:12px 8px;background:#222936}.delay-btn.active{background:var(--blue);color:#07101d}.axis-row{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}.axis-btn{margin:0;padding:12px 8px;background:#222936}.axis-btn.active{background:var(--good);color:#07150e}.axis-help{font-size:12px;color:var(--muted);line-height:1.35;margin-top:8px}.slider{width:100%;accent-color:#8db8ff}.support{margin-top:8px;font-size:12px;color:var(--muted)}.rec{display:none;align-items:center;justify-content:center;gap:8px;margin:10px 0 4px;font-weight:700}.rec.on{display:flex}.dot{width:10px;height:10px;border-radius:50%;background:#ff5151;box-shadow:0 0 0 5px #ff515122}.small{font-size:13px;color:var(--muted);line-height:1.4}.statusline{margin-top:8px}.pill{display:inline-block;padding:5px 9px;border:1px solid var(--line);border-radius:999px;color:var(--muted);font-size:12px}canvas{display:block;width:100%;height:120px;background:#0e1117;border-radius:14px}.footer{font-size:12px;color:var(--muted);text-align:center;margin-top:12px}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="top"><h1>Рука при ходьбе · v4</h1><p>Распознавание маха по выбранным осям телефона</p></div>
|
||||
|
||||
<section class="card">
|
||||
<button id="startBtn" class="primary">Разрешить датчики</button>
|
||||
<div id="sensorInfo" class="small statusline">Датчики ещё не запущены.</div>
|
||||
</section>
|
||||
|
||||
<section class="card hero">
|
||||
<div class="eyebrow">Текущее состояние</div>
|
||||
<div id="state">—</div>
|
||||
<div class="score"><span id="score">—</span><small>%</small></div>
|
||||
<div class="bar"><div id="fill" class="fill"></div></div>
|
||||
<div id="hint" class="hint">Сначала включи датчики и начни идти.</div>
|
||||
<div id="swingTimer" class="small" style="margin-top:8px;min-height:20px"></div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<button id="soundBtn">🔇 Звук: выкл</button>
|
||||
<div class="settings">
|
||||
<div class="setting">
|
||||
<div class="setting-head"><span>Громкость сигнала</span><b id="volumeValue">100%</b></div>
|
||||
<input id="volumeSlider" class="slider" type="range" min="0" max="100" step="5" value="100" aria-label="Громкость сигнала">
|
||||
</div>
|
||||
<div class="setting">
|
||||
<div class="setting-head"><span>Предупреждать после</span><b id="delayValue">5 секунд</b></div>
|
||||
<div class="delay-row">
|
||||
<button class="delay-btn" data-delay="3">3 с</button>
|
||||
<button class="delay-btn active" data-delay="5">5 с</button>
|
||||
<button class="delay-btn" data-delay="7">7 с</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting">
|
||||
<div class="setting-head"><span>Оси ускорения для распознавания</span><b id="axesValue">Y</b></div>
|
||||
<div class="axis-row">
|
||||
<button class="axis-btn" data-axis="x">X</button>
|
||||
<button class="axis-btn active" data-axis="y">Y</button>
|
||||
<button class="axis-btn" data-axis="z">Z</button>
|
||||
</div>
|
||||
<div class="axis-help">
|
||||
X — влево/вправо по экрану · Y — вдоль телефона от низа к верху · Z — перпендикулярно экрану.
|
||||
По умолчанию включена только Y: в твоём хвате боком она соответствует движению руки вперёд-назад.
|
||||
Переворот телефона на 180° не мешает — учитывается амплитуда, а не знак.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="soundInfo" class="small" style="margin-top:10px">Сигнал выключен. При включении используется максимальная громкость страницы.</div>
|
||||
<div id="vibrationInfo" class="support">Вибрация: проверяется браузером при запуске.</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="grid">
|
||||
<div class="metric"><span>Сигнал распознавания</span><b id="detectRms">—</b><em>м/с² RMS</em></div>
|
||||
<div class="metric"><span>Ось X, RMS 1.5 с</span><b id="xRms">—</b><em>м/с²</em></div>
|
||||
<div class="metric"><span>Ось Y, RMS 1.5 с</span><b id="yRms">—</b><em>м/с²</em></div>
|
||||
<div class="metric"><span>Ось Z, RMS 1.5 с</span><b id="zRms">—</b><em>м/с²</em></div>
|
||||
<div class="metric"><span>Частота датчика</span><b id="hz">—</b><em>Гц</em></div>
|
||||
<div class="metric"><span>Записано</span><b id="samples">0</b><em>отсчётов</em></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="eyebrow">Запись примеров</div>
|
||||
<div id="recLine" class="rec"><span class="dot"></span><span id="recText">Запись</span></div>
|
||||
<div class="row">
|
||||
<button id="stableBtn" class="good">Запись: РОВНО</button>
|
||||
<button id="swingBtn" class="warn">Запись: МАХ</button>
|
||||
</div>
|
||||
<button id="stopBtn" class="stop" disabled>Стоп и скачать CSV</button>
|
||||
<div class="small" style="margin-top:8px">Запись не влияет на распознавание. Можно продолжать собирать примеры и потом прислать CSV.</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="small" style="margin-bottom:8px">Последние секунды: сигнал выбранных осей ускорения</div>
|
||||
<canvas id="chart" width="700" height="150"></canvas>
|
||||
</section>
|
||||
|
||||
<section class="card small">
|
||||
Алгоритм v4 по умолчанию смотрит только на динамическое ускорение вдоль оси Y телефона. Это специально убирает большую часть ложных срабатываний от вертикальной качки тела при быстрой ходьбе. Можно включить X и/или Z вручную. Если включено несколько осей, распознавание берёт самую выраженную из выбранных осей. Пороги для Y настроены по твоим записям «РОВНО» и «МАХ».
|
||||
</section>
|
||||
<div class="footer">Walking Arm Monitor v4 · Axes</div>
|
||||
</main>
|
||||
<script>
|
||||
(()=>{
|
||||
const $=id=>document.getElementById(id);
|
||||
const el={start:$('startBtn'),info:$('sensorInfo'),state:$('state'),score:$('score'),fill:$('fill'),hint:$('hint'),swingTimer:$('swingTimer'),soundBtn:$('soundBtn'),soundInfo:$('soundInfo'),volumeSlider:$('volumeSlider'),volumeValue:$('volumeValue'),delayValue:$('delayValue'),axesValue:$('axesValue'),vibrationInfo:$('vibrationInfo'),detectRms:$('detectRms'),xRms:$('xRms'),yRms:$('yRms'),zRms:$('zRms'),hz:$('hz'),samples:$('samples'),stable:$('stableBtn'),swing:$('swingBtn'),stop:$('stopBtn'),recLine:$('recLine'),recText:$('recText'),chart:$('chart')};
|
||||
let running=false,lastEventAt=0,sampleTimes=[],buf=[],graph=[];
|
||||
let grav={x:0,y:0,z:0},gravReady=false; const gravAlpha=.92;
|
||||
let recording=false,label='',recordStart=0,rows=[];
|
||||
let shownState='WAIT',candidate='WAIT',candidateSince=0,lastUi=0;
|
||||
let soundEnabled=false,audioCtx=null,swingSince=null,lastBeepAt=0,alertDelayMs=5000,alertVolume=1;
|
||||
const selectedAxes={x:false,y:true,z:false};
|
||||
const WINDOW_MS=1500,HOLD_MS=800,GRAPH_N=240,BEEP_EVERY_MS=1200;
|
||||
|
||||
const finite=v=>Number.isFinite(v)?v:null;
|
||||
const clamp=(v,a,b)=>Math.max(a,Math.min(b,v));
|
||||
const hypot3=(x,y,z)=>[x,y,z].every(Number.isFinite)?Math.hypot(x,y,z):null;
|
||||
const fmt=(v,d=1)=>Number.isFinite(v)?v.toFixed(d):'—';
|
||||
|
||||
function thresholds(signal){
|
||||
if(!Number.isFinite(signal)) return 'WAIT';
|
||||
if(signal < 0.85) return 'STABLE';
|
||||
if(signal > 1.15) return 'SWING';
|
||||
return 'MID';
|
||||
}
|
||||
function stabilityScore(signal){
|
||||
if(!Number.isFinite(signal)) return null;
|
||||
return Math.round(clamp(100*(1.65-signal)/(1.65-0.45),0,100));
|
||||
}
|
||||
function setAxis(axis){
|
||||
selectedAxes[axis]=!selectedAxes[axis];
|
||||
if(!selectedAxes.x&&!selectedAxes.y&&!selectedAxes.z){
|
||||
selectedAxes[axis]=true;
|
||||
}
|
||||
document.querySelectorAll('.axis-btn').forEach(btn=>{
|
||||
btn.classList.toggle('active',!!selectedAxes[btn.dataset.axis]);
|
||||
});
|
||||
const names=['x','y','z'].filter(a=>selectedAxes[a]).map(a=>a.toUpperCase());
|
||||
el.axesValue.textContent=names.join('+');
|
||||
buf.length=0;
|
||||
graph.length=0;
|
||||
shownState='WAIT';candidate='WAIT';candidateSince=performance.now();
|
||||
swingSince=null;lastBeepAt=0;
|
||||
}
|
||||
function selectedSignal(m){
|
||||
const vals=[];
|
||||
if(selectedAxes.x&&Number.isFinite(m.x)) vals.push(m.x);
|
||||
if(selectedAxes.y&&Number.isFinite(m.y)) vals.push(m.y);
|
||||
if(selectedAxes.z&&Number.isFinite(m.z)) vals.push(m.z);
|
||||
return vals.length?Math.max(...vals):null;
|
||||
}
|
||||
function commitState(next,now){
|
||||
if(next!==candidate){candidate=next;candidateSince=now;return;}
|
||||
if(next!==shownState && now-candidateSince>=HOLD_MS) shownState=next;
|
||||
}
|
||||
function paintState(score){
|
||||
const map={STABLE:['РОВНО','Рука идёт спокойно вместе с телом.','var(--good)'],MID:['ПЕРЕХОД','Есть движение, но устойчивого маха пока нет.','var(--mid)'],SWING:['МАХ','Обнаружено устойчивое раскачивание руки.','var(--bad)'],WAIT:['—','Нужно примерно 1.5 секунды данных.','var(--blue)']};
|
||||
const [txt,hint,color]=map[shownState]||map.WAIT;
|
||||
if(el.state.textContent!==txt) el.state.textContent=txt;
|
||||
if(el.hint.textContent!==hint) el.hint.textContent=hint;
|
||||
el.state.style.color=color;
|
||||
if(score===null){el.score.textContent='—';el.fill.style.width='0%';}
|
||||
else {el.score.textContent=String(score);el.fill.style.width=score+'%';el.fill.style.background=color;}
|
||||
}
|
||||
|
||||
|
||||
function ensureAudio(){
|
||||
try{
|
||||
if(!audioCtx) audioCtx=new (window.AudioContext||window.webkitAudioContext)();
|
||||
if(audioCtx.state==='suspended') audioCtx.resume();
|
||||
return true;
|
||||
}catch(e){
|
||||
el.soundInfo.textContent='Не удалось включить звук в этом браузере.';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function vibrateAlert(){
|
||||
if('vibrate' in navigator){
|
||||
try{
|
||||
navigator.vibrate([320,120,320]);
|
||||
return true;
|
||||
}catch(_){}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function beep(){
|
||||
if(!soundEnabled||!ensureAudio()) return;
|
||||
const t=audioCtx.currentTime;
|
||||
const master=audioCtx.createGain();
|
||||
const compressor=audioCtx.createDynamicsCompressor();
|
||||
master.gain.setValueAtTime(Math.max(0.001,alertVolume),t);
|
||||
compressor.threshold.setValueAtTime(-12,t);
|
||||
compressor.knee.setValueAtTime(6,t);
|
||||
compressor.ratio.setValueAtTime(12,t);
|
||||
compressor.attack.setValueAtTime(0.002,t);
|
||||
compressor.release.setValueAtTime(0.18,t);
|
||||
master.connect(compressor); compressor.connect(audioCtx.destination);
|
||||
|
||||
const tones=[
|
||||
{freq:1040,type:'square',gain:.72,stop:.28},
|
||||
{freq:1480,type:'square',gain:.40,stop:.22}
|
||||
];
|
||||
for(const tone of tones){
|
||||
const osc=audioCtx.createOscillator(),gain=audioCtx.createGain();
|
||||
osc.type=tone.type; osc.frequency.setValueAtTime(tone.freq,t);
|
||||
gain.gain.setValueAtTime(0.0001,t);
|
||||
gain.gain.exponentialRampToValueAtTime(Math.max(0.001,tone.gain),t+.008);
|
||||
gain.gain.setValueAtTime(Math.max(0.001,tone.gain),t+.13);
|
||||
gain.gain.exponentialRampToValueAtTime(0.0001,t+tone.stop);
|
||||
osc.connect(gain); gain.connect(master);
|
||||
osc.start(t); osc.stop(t+tone.stop+.02);
|
||||
}
|
||||
}
|
||||
function testAlert(){
|
||||
beep();
|
||||
vibrateAlert();
|
||||
}
|
||||
function toggleSound(){
|
||||
soundEnabled=!soundEnabled;
|
||||
if(soundEnabled){
|
||||
if(!ensureAudio()){soundEnabled=false;return;}
|
||||
el.soundBtn.textContent='🔊 Звук: вкл';
|
||||
el.soundBtn.classList.add('primary');
|
||||
const sec=alertDelayMs/1000;
|
||||
el.soundInfo.textContent=`Сигнал включён: предупреждение после ${sec} с непрерывного маха.`;
|
||||
testAlert();
|
||||
}else{
|
||||
el.soundBtn.textContent='🔇 Звук: выкл';
|
||||
el.soundBtn.classList.remove('primary');
|
||||
el.soundInfo.textContent='Сигнал выключен. Настройки громкости и задержки сохранены.';
|
||||
if('vibrate' in navigator){ try{ navigator.vibrate(0); }catch(_){} }
|
||||
}
|
||||
}
|
||||
function setAlertDelay(seconds){
|
||||
alertDelayMs=seconds*1000;
|
||||
el.delayValue.textContent=`${seconds} секунд`;
|
||||
document.querySelectorAll('.delay-btn').forEach(btn=>{
|
||||
btn.classList.toggle('active',Number(btn.dataset.delay)===seconds);
|
||||
});
|
||||
if(soundEnabled) el.soundInfo.textContent=`Сигнал включён: предупреждение после ${seconds} с непрерывного маха.`;
|
||||
}
|
||||
function updateVolume(){
|
||||
alertVolume=Number(el.volumeSlider.value)/100;
|
||||
el.volumeValue.textContent=`${el.volumeSlider.value}%`;
|
||||
}
|
||||
function updateSwingAlert(now){
|
||||
const limitSec=alertDelayMs/1000;
|
||||
if(shownState==='SWING'){
|
||||
if(swingSince===null) swingSince=now;
|
||||
const ms=now-swingSince;
|
||||
const sec=ms/1000;
|
||||
if(ms<alertDelayMs){
|
||||
el.swingTimer.textContent=`Мах подряд: ${sec.toFixed(1)} / ${limitSec.toFixed(1)} с`;
|
||||
}else{
|
||||
el.swingTimer.textContent=soundEnabled?`⚠️ Мах больше ${limitSec} с — звук + вибрация`:`⚠️ Мах больше ${limitSec} с — звук выключен`;
|
||||
if(soundEnabled && now-lastBeepAt>=BEEP_EVERY_MS){
|
||||
beep();
|
||||
vibrateAlert();
|
||||
lastBeepAt=now;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
swingSince=null; lastBeepAt=0;
|
||||
if(el.swingTimer.textContent) el.swingTimer.textContent='';
|
||||
if('vibrate' in navigator){ try{ navigator.vibrate(0); }catch(_){} }
|
||||
}
|
||||
}
|
||||
|
||||
function metrics(now){
|
||||
while(buf.length && buf[0].t < now-WINDOW_MS) buf.shift();
|
||||
if(buf.length<20) return {x:null,y:null,z:null};
|
||||
let sx=0,sy=0,sz=0,nx=0,ny=0,nz=0;
|
||||
for(const q of buf){
|
||||
if(Number.isFinite(q.x)){sx+=q.x*q.x;nx++;}
|
||||
if(Number.isFinite(q.y)){sy+=q.y*q.y;ny++;}
|
||||
if(Number.isFinite(q.z)){sz+=q.z*q.z;nz++;}
|
||||
}
|
||||
return {
|
||||
x:nx?Math.sqrt(sx/nx):null,
|
||||
y:ny?Math.sqrt(sy/ny):null,
|
||||
z:nz?Math.sqrt(sz/nz):null
|
||||
};
|
||||
}
|
||||
|
||||
function startRecord(which){
|
||||
if(!running){el.info.textContent='Сначала нажми «Разрешить датчики».';return;}
|
||||
recording=true;label=which;rows=[];recordStart=performance.now();el.stop.disabled=false;el.recLine.classList.add('on');el.samples.textContent='0';
|
||||
el.recText.textContent=which==='stable'?'Запись: РОВНО':'Запись: МАХ';
|
||||
}
|
||||
function stopRecord(){
|
||||
if(!recording||!rows.length){recording=false;el.stop.disabled=true;el.recLine.classList.remove('on');return;}
|
||||
const header=['t_ms','label','ax','ay','az','raw_ax','raw_ay','raw_az','gyro_alpha','gyro_beta','gyro_gamma','a_mag','g_mag','interval_ms'];
|
||||
const csv=[header.join(','),...rows.map(r=>header.map(k=>r[k]??'').join(','))].join('\n');
|
||||
const blob=new Blob([csv],{type:'text/csv;charset=utf-8'}); const stamp=new Date().toISOString().replace(/[:.]/g,'-');
|
||||
const human=label==='stable'?'STABLE':'SWING'; const name=`walking-arm-${human}-${stamp}.csv`;
|
||||
const a=document.createElement('a');a.href=URL.createObjectURL(blob);a.download=name;document.body.appendChild(a);a.click();setTimeout(()=>{URL.revokeObjectURL(a.href);a.remove();},1000);
|
||||
recording=false;el.stop.disabled=true;el.recLine.classList.remove('on');label='';
|
||||
}
|
||||
|
||||
function onMotion(e){
|
||||
const now=performance.now();lastEventAt=now;sampleTimes.push(now);while(sampleTimes.length&&sampleTimes[0]<now-2000)sampleTimes.shift();
|
||||
const raw=e.accelerationIncludingGravity||{},rx=finite(raw.x),ry=finite(raw.y),rz=finite(raw.z);let ax=null,ay=null,az=null;
|
||||
if(e.acceleration&&[e.acceleration.x,e.acceleration.y,e.acceleration.z].some(Number.isFinite)){ax=finite(e.acceleration.x);ay=finite(e.acceleration.y);az=finite(e.acceleration.z);}
|
||||
else if([rx,ry,rz].every(Number.isFinite)){if(!gravReady){grav={x:rx,y:ry,z:rz};gravReady=true;}grav.x=gravAlpha*grav.x+(1-gravAlpha)*rx;grav.y=gravAlpha*grav.y+(1-gravAlpha)*ry;grav.z=gravAlpha*grav.z+(1-gravAlpha)*rz;ax=rx-grav.x;ay=ry-grav.y;az=rz-grav.z;}
|
||||
const rr=e.rotationRate||{},ga=finite(rr.alpha),gb=finite(rr.beta),gg=finite(rr.gamma); const aMag=hypot3(ax,ay,az),gMag=hypot3(ga,gb,gg);
|
||||
buf.push({t:now,x:ax,y:ay,z:az});
|
||||
const temp={x:Math.abs(ax??NaN),y:Math.abs(ay??NaN),z:Math.abs(az??NaN)};
|
||||
const inst=selectedSignal(temp);
|
||||
graph.push(Number.isFinite(inst)?inst:0);if(graph.length>GRAPH_N)graph.shift();
|
||||
if(recording){rows.push({t_ms:(now-recordStart).toFixed(1),label,ax:ax?.toFixed(6)??'',ay:ay?.toFixed(6)??'',az:az?.toFixed(6)??'',raw_ax:rx?.toFixed(6)??'',raw_ay:ry?.toFixed(6)??'',raw_az:rz?.toFixed(6)??'',gyro_alpha:ga?.toFixed(6)??'',gyro_beta:gb?.toFixed(6)??'',gyro_gamma:gg?.toFixed(6)??'',a_mag:aMag?.toFixed(6)??'',g_mag:gMag?.toFixed(6)??'',interval_ms:finite(e.interval)?.toFixed(3)??''});}
|
||||
}
|
||||
|
||||
async function startSensors(){
|
||||
try{
|
||||
if(typeof DeviceMotionEvent!=='undefined'&&typeof DeviceMotionEvent.requestPermission==='function'){const p=await DeviceMotionEvent.requestPermission();if(p!=='granted')throw new Error('Доступ к датчикам не разрешён');}
|
||||
if(!('DeviceMotionEvent'in window))throw new Error('Этот браузер не поддерживает датчики движения');
|
||||
if(!running){window.addEventListener('devicemotion',onMotion,{passive:true});running=true;}
|
||||
el.start.textContent='Датчики включены';el.start.disabled=true;el.info.textContent='Готово. Возьми телефон в руку и иди как обычно.';el.vibrationInfo.textContent=('vibrate' in navigator)?'Вибрация: поддерживается браузером.':'Вибрация: этот браузер не даёт доступ к вибромотору.';
|
||||
}catch(err){el.info.textContent='Ошибка: '+(err?.message||err);}
|
||||
}
|
||||
|
||||
function draw(){
|
||||
const c=el.chart,ctx=c.getContext('2d'),w=c.width,h=c.height;ctx.clearRect(0,0,w,h);ctx.strokeStyle='#29313f';ctx.lineWidth=1;
|
||||
for(let i=1;i<4;i++){const y=h*i/4;ctx.beginPath();ctx.moveTo(0,y);ctx.lineTo(w,y);ctx.stroke();}
|
||||
if(graph.length>1){const max=Math.max(3.0,...graph);ctx.strokeStyle='#8db8ff';ctx.lineWidth=3;ctx.beginPath();graph.forEach((v,i)=>{const x=i/(GRAPH_N-1)*w,y=h-clamp(v/max,0,1)*h;i?ctx.lineTo(x,y):ctx.moveTo(x,y)});ctx.stroke();}
|
||||
}
|
||||
|
||||
function loop(now){
|
||||
if(now-lastUi>150){
|
||||
lastUi=now;
|
||||
const m=metrics(now),signal=selectedSignal(m),next=thresholds(signal);
|
||||
commitState(next,now);
|
||||
const score=stabilityScore(signal);
|
||||
paintState(score);updateSwingAlert(now);
|
||||
el.detectRms.textContent=fmt(signal,2);
|
||||
el.xRms.textContent=fmt(m.x,2);el.yRms.textContent=fmt(m.y,2);el.zRms.textContent=fmt(m.z,2);
|
||||
const hz=sampleTimes.length>1?(sampleTimes.length-1)/((sampleTimes.at(-1)-sampleTimes[0])/1000):0;
|
||||
el.hz.textContent=hz?hz.toFixed(1):'—';el.samples.textContent=recording?String(rows.length):'0';
|
||||
if(recording)el.recText.textContent=(label==='stable'?'РОВНО':'МАХ')+' · '+((now-recordStart)/1000).toFixed(1)+' с';
|
||||
if(running&&now-lastEventAt>2500)el.info.textContent='Данные датчиков перестали приходить. Проверь HTTPS и разрешения браузера.';
|
||||
draw();
|
||||
}
|
||||
requestAnimationFrame(loop);
|
||||
}
|
||||
|
||||
el.start.addEventListener('click',startSensors);el.soundBtn.addEventListener('click',toggleSound);el.volumeSlider.addEventListener('input',updateVolume);el.volumeSlider.addEventListener('change',()=>{updateVolume();if(soundEnabled)testAlert();});document.querySelectorAll('.delay-btn').forEach(btn=>btn.addEventListener('click',()=>setAlertDelay(Number(btn.dataset.delay))));document.querySelectorAll('.axis-btn').forEach(btn=>btn.addEventListener('click',()=>setAxis(btn.dataset.axis)));el.stable.addEventListener('click',()=>startRecord('stable'));el.swing.addEventListener('click',()=>startRecord('swing'));el.stop.addEventListener('click',stopRecord);updateVolume();setAlertDelay(5);el.vibrationInfo.textContent=('vibrate' in navigator)?'Вибрация: поддерживается браузером.':'Вибрация: этот браузер не даёт доступ к вибромотору.';requestAnimationFrame(loop);
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,57 @@
|
||||
# SHiNE Arweave Viewer v2 — ANS-104 / Frame v1
|
||||
|
||||
Новая версия viewer для формата, где каждый пользовательский блок хранится в Arweave как отдельный ANS-104 DataItem, а `data` DataItem содержит один `SHiNE Frame v1`.
|
||||
|
||||
Основной файл: `index.html`.
|
||||
|
||||
## Быстрый запуск
|
||||
|
||||
Через логин (ключ берётся из Solana PDA):
|
||||
|
||||
```text
|
||||
index.html?login=aidarkc&channel=books
|
||||
```
|
||||
|
||||
Напрямую через blockchain public key, без Solana:
|
||||
|
||||
```text
|
||||
index.html?key=<BASE58_BLOCKCHAIN_PUBLIC_KEY>&channel=books
|
||||
```
|
||||
|
||||
Дополнительные параметры:
|
||||
|
||||
```text
|
||||
&arweaveGateway=https://arweave.net
|
||||
&solanaRpc=https://api.mainnet-beta.solana.com
|
||||
```
|
||||
|
||||
`channel` можно не передавать. Тогда viewer ищет все DataItem пользователя с `App=test5592` и строит список каналов из найденных блоков.
|
||||
|
||||
## Что делает viewer
|
||||
|
||||
1. Если передан `login`, вычисляет PDA `user_login=<login>` программы `SHiNEPr1APdAgNBteUyBXcNovaHctpSjUu8oH2ZJdN6` и читает `blockchainKey`.
|
||||
2. Если передан `key`, использует его напрямую и не обращается к Solana.
|
||||
3. Из Ed25519/Solana public key вычисляет Arweave owner address как `base64url(SHA-256(pubkey32))`.
|
||||
4. Делает Arweave GraphQL запрос по owner + `App=test5592`; `channel` применяется локально после загрузки авторского блокчейна.
|
||||
5. Загружает payload каждого DataItem через gateway `/<DataItemId>`.
|
||||
6. Разбирает payload как SHiNE Frame v1 (`frameCode=0x0001`, header 88 bytes).
|
||||
7. Дедуплицирует повторно опубликованные одинаковые пользовательские блоки по SHA-256 Frame v1.
|
||||
8. Восстанавливает канал/сообщения тем же body parser, который использовал старый viewer.
|
||||
|
||||
## Важно
|
||||
|
||||
При фильтрации по конкретному `channel` viewer получает только блоки с соответствующим тегом `c`. Поэтому он не заявляет полную проверку глобальной `prevHash`-цепочки пользователя: между двумя блоками одного канала могут существовать блоки других каналов. SHA-256 каждого загруженного Frame вычисляется локально.
|
||||
|
||||
Старый `shine-solana-arweave-viewer/` не изменяется; новая версия лежит отдельно в `shine-solana-arweave-viewer-v2/`.
|
||||
|
||||
|
||||
## Проверка данных (v3.3)
|
||||
Нижняя строка показывает краткий итог доступных проверок. Нажатие на неё или `⋮ → Проверка данных` открывает отдельный экран:
|
||||
- локально вычисленный SHA-256 каждого SHiNE Frame;
|
||||
- `prevHash` общей цепочки, когда предыдущий глобальный блок загружен;
|
||||
- `prevLineHash` канальной цепочки, когда указанный предыдущий блок загружен;
|
||||
- наличие DataItem в выборке Arweave owner соответствующего blockchain key;
|
||||
- разрывы «нет данных» отдельно от доказанных несовпадений;
|
||||
- честный статус ANS-104 signature: gateway payload/GraphQL не содержит сырой подписи, поэтому она не помечается как локально перепроверенная.
|
||||
|
||||
`○ нет данных` не является ошибкой. `⚠` появляется только при фактическом несовпадении доступных хэшей.
|
||||
@@ -0,0 +1,26 @@
|
||||
# SHiNE Arweave Viewer v3
|
||||
|
||||
Viewer нового per-action Arweave формата SHiNE.
|
||||
|
||||
## URL
|
||||
- `?login=<login>&channel=<channel>` — получает blockchain key через Solana PDA, затем читает Arweave.
|
||||
- `?key=<base58>&channel=<channel>` — Arweave запускается напрямую; Solana не является блокирующей зависимостью.
|
||||
- без параметров — стартовая форма (логин или blockchain key + необязательный канал).
|
||||
|
||||
## v3
|
||||
- переключатель `Канал / Блоки`;
|
||||
- рекурсивные комментарии скрыты до раскрытия, на любой глубине;
|
||||
- light/dark тема;
|
||||
- меню `⋮`: кэш, Solana RPC, Arweave gateway;
|
||||
- выключение кэша удаляет сохранённые данные каналов;
|
||||
- одна нижняя status bar, по нажатию — подробный журнал;
|
||||
- GraphQL читает от новых Arweave записей к старым (`HEIGHT_DESC`);
|
||||
- до 6 параллельных загрузок Frame;
|
||||
- отображение известных типов и raw-представление любых неизвестных блоков в режиме `Блоки`;
|
||||
- лайки намеренно не отображаются.
|
||||
|
||||
Кэш использует browser localStorage и сериализует BigInt-поля Frame явно. Тема/RPC/gateway являются настройками и не удаляются при отключении кэша.
|
||||
|
||||
## V3.1 — streaming reverse loading
|
||||
|
||||
Arweave history is now processed page-by-page in `HEIGHT_DESC` order. The first GraphQL page (up to 100 DataItems) is downloaded, parsed and rendered immediately. Older pages are then fetched and merged in the background. The bottom status line shows the currently available block range while history expands toward the beginning. Each completed page is also persisted when cache is enabled.
|
||||
@@ -0,0 +1,11 @@
|
||||
# SHiNE Solana Arweave Viewer
|
||||
|
||||
Основной рабочий файл:
|
||||
|
||||
- `index.html`
|
||||
|
||||
Подробное описание работы, параметров и готовых ссылок:
|
||||
|
||||
- `КАК_ЭТО_РАБОТАЕТ.md`
|
||||
|
||||
Viewer собран как автономный single-file HTML и запускается одним файлом без соседних зависимостей.
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,725 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#0f172a" />
|
||||
<title>Дыхание по движению живота</title>
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #07111f;
|
||||
--card: rgba(15, 23, 42, 0.9);
|
||||
--card2: rgba(30, 41, 59, 0.72);
|
||||
--text: #f8fafc;
|
||||
--muted: #94a3b8;
|
||||
--line: rgba(148, 163, 184, 0.18);
|
||||
--accent: #7dd3fc;
|
||||
--accent2: #c4b5fd;
|
||||
--good: #86efac;
|
||||
--warn: #fde68a;
|
||||
--bad: #fca5a5;
|
||||
--shadow: 0 18px 50px rgba(0,0,0,.24);
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at 50% -10%, #14233d 0%, var(--bg) 45%, #040913 100%); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
||||
body { padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom)); }
|
||||
.app { width: min(900px, 100%); margin: 0 auto; }
|
||||
.hero { padding: 8px 4px 14px; }
|
||||
h1 { font-size: clamp(24px, 7vw, 38px); line-height: 1.05; margin: 0 0 8px; letter-spacing: -0.035em; }
|
||||
.subtitle { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
|
||||
.grid { display: grid; gap: 12px; }
|
||||
.card { background: linear-gradient(180deg, rgba(30,41,59,.84), rgba(15,23,42,.9)); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
|
||||
.status-card { padding: 18px; }
|
||||
.status-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
|
||||
.status-main { min-width: 0; }
|
||||
.eyebrow { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; }
|
||||
.phase { font-size: clamp(30px, 10vw, 52px); font-weight: 750; margin-top: 2px; letter-spacing: -.04em; }
|
||||
.phase.inhale { color: var(--accent); }
|
||||
.phase.exhale { color: var(--accent2); }
|
||||
.phase.idle { color: #cbd5e1; }
|
||||
.quality { min-width: 96px; text-align: right; }
|
||||
.quality strong { display: block; font-size: 18px; }
|
||||
.quality span { color: var(--muted); font-size: 12px; }
|
||||
.meter { height: 8px; background: rgba(148,163,184,.12); border-radius: 999px; margin-top: 14px; overflow: hidden; }
|
||||
.meter > i { display: block; height: 100%; width: 0%; border-radius: inherit; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .18s linear; }
|
||||
.calibration { margin-top: 9px; min-height: 20px; color: var(--muted); font-size: 13px; }
|
||||
|
||||
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
|
||||
button { appearance: none; border: 0; border-radius: 16px; padding: 14px 16px; min-height: 50px; font: inherit; font-weight: 700; cursor: pointer; color: #07111f; background: #e2e8f0; }
|
||||
button.primary { background: linear-gradient(135deg, #bae6fd, #ddd6fe); }
|
||||
button.secondary { color: var(--text); background: rgba(148,163,184,.11); border: 1px solid var(--line); }
|
||||
button:disabled { opacity: .45; cursor: not-allowed; }
|
||||
.small-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
|
||||
.small-controls button { padding: 10px 8px; min-height: 42px; font-size: 12px; border-radius: 13px; }
|
||||
|
||||
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; padding: 12px; }
|
||||
.stat { background: rgba(2,6,23,.34); border: 1px solid var(--line); border-radius: 17px; padding: 13px 10px; min-width: 0; }
|
||||
.stat .period { color: var(--muted); font-size: 11px; }
|
||||
.stat .value { font-weight: 800; font-size: clamp(22px, 7vw, 34px); margin-top: 4px; letter-spacing: -.04em; }
|
||||
.stat .unit { color: var(--muted); font-size: 11px; margin-top: 2px; }
|
||||
|
||||
.wave-card { padding: 12px 12px 8px; }
|
||||
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 2px 4px 8px; }
|
||||
.section-head h2 { margin: 0; font-size: 15px; }
|
||||
.section-head span { color: var(--muted); font-size: 11px; text-align: right; }
|
||||
canvas { display: block; width: 100%; height: 170px; border-radius: 16px; background: rgba(2,6,23,.32); }
|
||||
|
||||
.table-card { overflow: hidden; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
|
||||
th, td { text-align: right; padding: 12px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
|
||||
th:first-child, td:first-child { text-align: left; }
|
||||
th { color: var(--muted); font-size: 11px; font-weight: 650; position: sticky; top: 0; background: #111c2f; }
|
||||
tbody tr:last-child td { border-bottom: 0; }
|
||||
.empty { text-align: center !important; color: var(--muted); padding: 28px 14px !important; }
|
||||
|
||||
details { margin-top: 12px; }
|
||||
summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 6px 4px; }
|
||||
.debug { margin-top: 8px; background: rgba(2,6,23,.35); border: 1px solid var(--line); border-radius: 16px; padding: 12px; color: var(--muted); font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }
|
||||
.note { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 12px 4px 0; }
|
||||
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; font-size: 11px; color: var(--muted); }
|
||||
.dot { width: 7px; height: 7px; border-radius: 999px; background: #64748b; }
|
||||
.dot.on { background: var(--good); box-shadow: 0 0 12px rgba(134,239,172,.7); }
|
||||
|
||||
@media (min-width: 720px) {
|
||||
.top-grid { grid-template-columns: 1.15fr .85fr; }
|
||||
.stats { grid-template-columns: 1fr; height: 100%; }
|
||||
canvas { height: 210px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main class="app">
|
||||
<header class="hero">
|
||||
<h1>Дыхание</h1>
|
||||
<p class="subtitle">Положите телефон экраном вверх на живот и лежите спокойно. Приложение использует датчики движения телефона, чтобы оценивать ритм дыхания.</p>
|
||||
</header>
|
||||
|
||||
<div class="grid top-grid">
|
||||
<section class="card status-card">
|
||||
<div class="status-row">
|
||||
<div class="status-main">
|
||||
<div class="eyebrow">Сейчас</div>
|
||||
<div id="phase" class="phase idle">Готово</div>
|
||||
</div>
|
||||
<div class="quality">
|
||||
<strong id="qualityText">—</strong>
|
||||
<span>качество сигнала</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="meter"><i id="meterBar"></i></div>
|
||||
<div id="calibrationText" class="calibration">Нажмите «Начать». Первые 10 секунд — калибровка.</div>
|
||||
|
||||
<div class="controls">
|
||||
<button id="startBtn" class="primary">Начать</button>
|
||||
<button id="stopBtn" class="secondary" disabled>Остановить</button>
|
||||
</div>
|
||||
<div class="small-controls">
|
||||
<button id="recalibrateBtn" class="secondary" disabled>Калибровка</button>
|
||||
<button id="invertBtn" class="secondary" disabled>Вдох ↔ выдох</button>
|
||||
<button id="clearBtn" class="secondary">Очистить</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card stats" aria-label="Средняя длительность дыхательного цикла">
|
||||
<div class="stat">
|
||||
<div class="period">За последнюю 1 минуту</div>
|
||||
<div id="avg1" class="value">—</div>
|
||||
<div id="rate1" class="unit">сек/цикл · — дых./мин</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="period">За последние 3 минуты</div>
|
||||
<div id="avg3" class="value">—</div>
|
||||
<div id="rate3" class="unit">сек/цикл · — дых./мин</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="period">За последние 5 минут</div>
|
||||
<div id="avg5" class="value">—</div>
|
||||
<div id="rate5" class="unit">сек/цикл · — дых./мин</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="card wave-card" style="margin-top:12px">
|
||||
<div class="section-head">
|
||||
<h2>Сигнал движения</h2>
|
||||
<span id="sensorLabel">датчик ещё не запущен</span>
|
||||
</div>
|
||||
<canvas id="wave" width="900" height="210"></canvas>
|
||||
</section>
|
||||
|
||||
<section class="card table-card" style="margin-top:12px">
|
||||
<div class="section-head" style="padding:14px 14px 4px">
|
||||
<h2>Вдохи и выдохи</h2>
|
||||
<span id="cycleCount">0 циклов</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Время</th>
|
||||
<th>Вдох</th>
|
||||
<th>Выдох</th>
|
||||
<th>Цикл</th>
|
||||
<th>Темп</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="breathRows">
|
||||
<tr><td colspan="5" class="empty">Пока нет завершённых циклов</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<details>
|
||||
<summary>Диагностика датчика</summary>
|
||||
<div id="debug" class="debug">—</div>
|
||||
</details>
|
||||
<p class="note">Это экспериментальная оценка ритма дыхания по движению телефона, а не медицинский измерительный прибор. Для наиболее стабильного результата телефон должен лежать свободно и не скользить по одежде.</p>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
const els = {
|
||||
start: $('startBtn'), stop: $('stopBtn'), recal: $('recalibrateBtn'), invert: $('invertBtn'), clear: $('clearBtn'),
|
||||
phase: $('phase'), quality: $('qualityText'), meter: $('meterBar'), cal: $('calibrationText'), sensor: $('sensorLabel'),
|
||||
avg1: $('avg1'), avg3: $('avg3'), avg5: $('avg5'), rate1: $('rate1'), rate3: $('rate3'), rate5: $('rate5'),
|
||||
rows: $('breathRows'), count: $('cycleCount'), debug: $('debug'), canvas: $('wave')
|
||||
};
|
||||
const ctx = els.canvas.getContext('2d');
|
||||
|
||||
const CALIBRATION_MS = 10000;
|
||||
const MIN_HALF_PHASE_MS = 800;
|
||||
const MAX_HALF_PHASE_MS = 20000;
|
||||
const MAX_CYCLE_MS = 40000;
|
||||
const MIN_CYCLE_MS = 1800;
|
||||
const HISTORY_MS = 30000;
|
||||
const G = 9.80665;
|
||||
|
||||
let running = false;
|
||||
let calibrating = false;
|
||||
let calibrationStartedAt = 0;
|
||||
let lastTs = null;
|
||||
let sampleCount = 0;
|
||||
let chosen = null; // {kind:'tilt'|'linear', axis:0..2, sign:1}
|
||||
let inverted = false;
|
||||
let wakeLock = null;
|
||||
let noDataTimer = null;
|
||||
|
||||
let gravity = [0,0,0];
|
||||
let gravityReady = false;
|
||||
let filters = makeFilters();
|
||||
let calibrationSamples = [];
|
||||
let signalHistory = [];
|
||||
let cycleRows = [];
|
||||
let turns = [];
|
||||
let detector = freshDetector();
|
||||
let pending = { inhale: null, exhale: null };
|
||||
let currentPhase = null;
|
||||
let latestSignal = 0;
|
||||
let latestThreshold = 0.002;
|
||||
let latestSNR = 0;
|
||||
let latestInterval = 0;
|
||||
|
||||
function makeFilters() {
|
||||
return Array.from({length: 6}, () => ({fast: null, slow: null, last: 0}));
|
||||
}
|
||||
|
||||
function freshDetector() {
|
||||
return {
|
||||
mode: null, // seekingPeak | seekingTrough
|
||||
candidateValue: null,
|
||||
candidateTs: null,
|
||||
lastTurnTs: null
|
||||
};
|
||||
}
|
||||
|
||||
function ema(prev, value, dt, tau) {
|
||||
if (prev == null || !Number.isFinite(prev)) return value;
|
||||
const a = 1 - Math.exp(-Math.max(0.001, dt) / tau);
|
||||
return prev + a * (value - prev);
|
||||
}
|
||||
|
||||
function variance(arr) {
|
||||
if (!arr.length) return 0;
|
||||
const m = arr.reduce((a,b) => a+b, 0) / arr.length;
|
||||
return arr.reduce((s,v) => s + (v-m)*(v-m), 0) / arr.length;
|
||||
}
|
||||
|
||||
function std(arr) { return Math.sqrt(variance(arr)); }
|
||||
function clamp(v, lo, hi) { return Math.max(lo, Math.min(hi, v)); }
|
||||
function fmtSec(ms) { return (ms / 1000).toFixed(1) + ' c'; }
|
||||
|
||||
async function requestMotionPermission() {
|
||||
if (typeof DeviceMotionEvent === 'undefined') {
|
||||
throw new Error('Этот браузер не поддерживает DeviceMotionEvent.');
|
||||
}
|
||||
if (typeof DeviceMotionEvent.requestPermission === 'function') {
|
||||
const result = await DeviceMotionEvent.requestPermission();
|
||||
if (result !== 'granted') throw new Error('Доступ к датчикам движения не разрешён.');
|
||||
}
|
||||
}
|
||||
|
||||
async function keepAwake() {
|
||||
try {
|
||||
if ('wakeLock' in navigator) wakeLock = await navigator.wakeLock.request('screen');
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
async function start() {
|
||||
if (running) return;
|
||||
try {
|
||||
await requestMotionPermission();
|
||||
} catch (err) {
|
||||
els.cal.textContent = err.message + ' Если это iPhone — откройте страницу по HTTPS и нажмите кнопку ещё раз.';
|
||||
els.phase.textContent = 'Нет доступа';
|
||||
els.phase.className = 'phase idle';
|
||||
return;
|
||||
}
|
||||
|
||||
running = true;
|
||||
sampleCount = 0;
|
||||
lastTs = null;
|
||||
gravityReady = false;
|
||||
gravity = [0,0,0];
|
||||
filters = makeFilters();
|
||||
signalHistory = [];
|
||||
resetDetection(false);
|
||||
beginCalibration();
|
||||
|
||||
window.addEventListener('devicemotion', onMotion, {passive: true});
|
||||
await keepAwake();
|
||||
els.start.disabled = true;
|
||||
els.stop.disabled = false;
|
||||
els.recal.disabled = false;
|
||||
els.invert.disabled = false;
|
||||
els.phase.textContent = 'Калибровка';
|
||||
els.phase.className = 'phase idle';
|
||||
els.sensor.textContent = 'ожидание данных датчика…';
|
||||
|
||||
clearTimeout(noDataTimer);
|
||||
noDataTimer = setTimeout(() => {
|
||||
if (running && sampleCount < 3) {
|
||||
els.cal.textContent = 'Данные от датчика не приходят. Проверьте HTTPS, разрешение Motion & Orientation и попробуйте другой браузер.';
|
||||
els.quality.textContent = 'нет данных';
|
||||
}
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
async function stop() {
|
||||
if (!running) return;
|
||||
running = false;
|
||||
calibrating = false;
|
||||
window.removeEventListener('devicemotion', onMotion);
|
||||
clearTimeout(noDataTimer);
|
||||
if (wakeLock) { try { await wakeLock.release(); } catch (_) {} wakeLock = null; }
|
||||
els.start.disabled = false;
|
||||
els.stop.disabled = true;
|
||||
els.recal.disabled = true;
|
||||
els.invert.disabled = true;
|
||||
els.phase.textContent = 'Остановлено';
|
||||
els.phase.className = 'phase idle';
|
||||
els.cal.textContent = 'Измерение остановлено.';
|
||||
els.meter.style.width = '0%';
|
||||
}
|
||||
|
||||
function beginCalibration() {
|
||||
calibrating = true;
|
||||
calibrationStartedAt = performance.now();
|
||||
calibrationSamples = [];
|
||||
chosen = null;
|
||||
filters = makeFilters();
|
||||
resetDetection(false);
|
||||
els.cal.textContent = 'Калибровка: лежите спокойно и дышите как обычно…';
|
||||
}
|
||||
|
||||
function resetDetection(clearRows = false) {
|
||||
detector = freshDetector();
|
||||
turns = [];
|
||||
pending = { inhale: null, exhale: null };
|
||||
currentPhase = null;
|
||||
if (clearRows) cycleRows = [];
|
||||
renderTable();
|
||||
updateStats();
|
||||
}
|
||||
|
||||
function onMotion(ev) {
|
||||
if (!running) return;
|
||||
const now = performance.now();
|
||||
const dt = lastTs == null ? (ev.interval ? ev.interval/1000 : 0.02) : clamp((now-lastTs)/1000, 0.005, 0.2);
|
||||
lastTs = now;
|
||||
latestInterval = ev.interval || dt*1000;
|
||||
sampleCount++;
|
||||
|
||||
const ag = ev.accelerationIncludingGravity;
|
||||
if (!ag || [ag.x,ag.y,ag.z].some(v => v == null || !Number.isFinite(v))) return;
|
||||
const a = ev.acceleration;
|
||||
const agv = [ag.x, ag.y, ag.z];
|
||||
|
||||
if (!gravityReady) {
|
||||
gravity = agv.slice();
|
||||
gravityReady = true;
|
||||
} else {
|
||||
// Gravity follows slow orientation changes but ignores quick vibration.
|
||||
const tauG = 0.55;
|
||||
for (let i=0;i<3;i++) gravity[i] = ema(gravity[i], agv[i], dt, tauG);
|
||||
}
|
||||
|
||||
const gm = Math.hypot(gravity[0], gravity[1], gravity[2]) || G;
|
||||
const tilt = gravity.map(v => v / gm);
|
||||
const lin = (a && [a.x,a.y,a.z].every(v => v != null && Number.isFinite(v)))
|
||||
? [a.x/G, a.y/G, a.z/G]
|
||||
: agv.map((v,i) => (v-gravity[i])/G);
|
||||
const candidates = [...tilt, ...lin];
|
||||
const band = candidates.map((v, i) => {
|
||||
const f = filters[i];
|
||||
f.fast = ema(f.fast, v, dt, 0.38);
|
||||
f.slow = ema(f.slow, v, dt, 7.0);
|
||||
f.last = f.fast - f.slow;
|
||||
return f.last;
|
||||
});
|
||||
|
||||
if (calibrating) {
|
||||
calibrationSamples.push({t: now, band: band.slice()});
|
||||
const elapsed = now - calibrationStartedAt;
|
||||
const pct = clamp(elapsed / CALIBRATION_MS, 0, 1);
|
||||
els.meter.style.width = (pct*100).toFixed(0) + '%';
|
||||
els.cal.textContent = `Калибровка: ${Math.max(0, Math.ceil((CALIBRATION_MS-elapsed)/1000))} c. Дышите спокойно.`;
|
||||
if (elapsed >= CALIBRATION_MS) finishCalibration();
|
||||
drawSignal(now);
|
||||
updateDebug(tilt, lin);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!chosen) return;
|
||||
const idx = chosen.kind === 'tilt' ? chosen.axis : chosen.axis + 3;
|
||||
latestSignal = band[idx] * chosen.sign;
|
||||
signalHistory.push({t: now, v: latestSignal});
|
||||
trimSignal(now);
|
||||
updateThreshold();
|
||||
detectTurn(now, latestSignal);
|
||||
updateQuality();
|
||||
drawSignal(now);
|
||||
updateDebug(tilt, lin);
|
||||
}
|
||||
|
||||
function finishCalibration() {
|
||||
calibrating = false;
|
||||
const recent = calibrationSamples.filter(s => s.t >= performance.now() - CALIBRATION_MS);
|
||||
const cols = Array.from({length:6}, (_,i) => recent.map(s => s.band[i]));
|
||||
const scores = cols.map(values => {
|
||||
if (values.length < 10) return 0;
|
||||
const s = std(values);
|
||||
// Prefer a coherent slow signal: downsample rough derivative as a noise penalty.
|
||||
let rough = 0;
|
||||
for (let i=1;i<values.length;i++) rough += Math.abs(values[i]-values[i-1]);
|
||||
rough /= Math.max(1, values.length-1);
|
||||
return s / (rough + 1e-6);
|
||||
});
|
||||
|
||||
const tiltStd = cols.slice(0,3).map(std);
|
||||
const linearStd = cols.slice(3,6).map(std);
|
||||
const bestTiltAxis = tiltStd.indexOf(Math.max(...tiltStd));
|
||||
const bestLinearAxis = linearStd.indexOf(Math.max(...linearStd));
|
||||
|
||||
// Tilt is closer to actual abdominal position. Use linear acceleration only when tilt is almost absent.
|
||||
if (tiltStd[bestTiltAxis] >= 0.0012) {
|
||||
chosen = {kind:'tilt', axis:bestTiltAxis, sign:1};
|
||||
} else {
|
||||
chosen = {kind:'linear', axis:bestLinearAxis, sign:1};
|
||||
}
|
||||
|
||||
const labels = ['X','Y','Z'];
|
||||
els.sensor.textContent = `${chosen.kind === 'tilt' ? 'наклон' : 'ускорение'} · ось ${labels[chosen.axis]}`;
|
||||
els.cal.textContent = 'Калибровка завершена. Если вдох и выдох перепутаны — нажмите «Вдох ↔ выдох».';
|
||||
els.meter.style.width = '100%';
|
||||
setTimeout(() => { if (running && !calibrating) els.meter.style.width = '0%'; }, 600);
|
||||
|
||||
signalHistory = [];
|
||||
detector = freshDetector();
|
||||
pending = {inhale:null, exhale:null};
|
||||
}
|
||||
|
||||
function trimSignal(now) {
|
||||
const cutoff = now - HISTORY_MS;
|
||||
while (signalHistory.length && signalHistory[0].t < cutoff) signalHistory.shift();
|
||||
}
|
||||
|
||||
function updateThreshold() {
|
||||
const values = signalHistory.filter(s => s.t >= performance.now()-12000).map(s => s.v);
|
||||
if (values.length < 20) return;
|
||||
const s = std(values);
|
||||
latestThreshold = clamp(s * 0.55, chosen && chosen.kind === 'tilt' ? 0.00045 : 0.00018, 0.035);
|
||||
|
||||
let rough = 0;
|
||||
for (let i=1;i<values.length;i++) rough += Math.abs(values[i]-values[i-1]);
|
||||
rough /= Math.max(1, values.length-1);
|
||||
latestSNR = s / Math.max(rough*4, 1e-6);
|
||||
}
|
||||
|
||||
function detectTurn(now, value) {
|
||||
const d = detector;
|
||||
if (d.mode == null) {
|
||||
d.mode = 'seekingPeak';
|
||||
d.candidateValue = value;
|
||||
d.candidateTs = now;
|
||||
return;
|
||||
}
|
||||
|
||||
if (d.mode === 'seekingPeak') {
|
||||
if (d.candidateValue == null || value > d.candidateValue) {
|
||||
d.candidateValue = value;
|
||||
d.candidateTs = now;
|
||||
}
|
||||
const drop = d.candidateValue - value;
|
||||
const enoughTime = d.lastTurnTs == null || d.candidateTs - d.lastTurnTs >= MIN_HALF_PHASE_MS;
|
||||
if (drop >= latestThreshold && enoughTime) {
|
||||
confirmTurn('peak', d.candidateTs, d.candidateValue);
|
||||
d.mode = 'seekingTrough';
|
||||
d.candidateValue = value;
|
||||
d.candidateTs = now;
|
||||
}
|
||||
} else {
|
||||
if (d.candidateValue == null || value < d.candidateValue) {
|
||||
d.candidateValue = value;
|
||||
d.candidateTs = now;
|
||||
}
|
||||
const rise = value - d.candidateValue;
|
||||
const enoughTime = d.lastTurnTs == null || d.candidateTs - d.lastTurnTs >= MIN_HALF_PHASE_MS;
|
||||
if (rise >= latestThreshold && enoughTime) {
|
||||
confirmTurn('trough', d.candidateTs, d.candidateValue);
|
||||
d.mode = 'seekingPeak';
|
||||
d.candidateValue = value;
|
||||
d.candidateTs = now;
|
||||
}
|
||||
}
|
||||
|
||||
if (d.lastTurnTs != null && now - d.lastTurnTs > MAX_HALF_PHASE_MS) {
|
||||
// Lost the rhythm; start looking again instead of inventing a huge breath.
|
||||
detector = freshDetector();
|
||||
pending = {inhale:null, exhale:null};
|
||||
currentPhase = null;
|
||||
setPhaseUI(null);
|
||||
}
|
||||
}
|
||||
|
||||
function confirmTurn(type, ts, value) {
|
||||
const d = detector;
|
||||
const prev = turns.length ? turns[turns.length-1] : null;
|
||||
if (prev && prev.type === type) return;
|
||||
if (prev && ts - prev.ts < MIN_HALF_PHASE_MS) return;
|
||||
|
||||
const turn = {type, ts, value};
|
||||
turns.push(turn);
|
||||
if (turns.length > 30) turns.shift();
|
||||
d.lastTurnTs = ts;
|
||||
|
||||
if (!prev) return;
|
||||
const duration = ts - prev.ts;
|
||||
if (duration > MAX_HALF_PHASE_MS) return;
|
||||
|
||||
// In the default orientation: trough -> peak = inhale, peak -> trough = exhale.
|
||||
let phase = type === 'peak' ? 'inhale' : 'exhale';
|
||||
if (inverted) phase = phase === 'inhale' ? 'exhale' : 'inhale';
|
||||
currentPhase = phase === 'inhale' ? 'exhale' : 'inhale'; // after the turning point the next phase begins
|
||||
setPhaseUI(currentPhase);
|
||||
|
||||
pending[phase] = {duration, endTs: ts};
|
||||
maybeCompleteCycle(ts);
|
||||
}
|
||||
|
||||
function maybeCompleteCycle(endTs) {
|
||||
if (!pending.inhale || !pending.exhale) return;
|
||||
const cycleMs = pending.inhale.duration + pending.exhale.duration;
|
||||
if (cycleMs < MIN_CYCLE_MS || cycleMs > MAX_CYCLE_MS) {
|
||||
pending = {inhale:null, exhale:null};
|
||||
return;
|
||||
}
|
||||
|
||||
const row = {
|
||||
endPerf: endTs,
|
||||
wallTime: Date.now() - (performance.now() - endTs),
|
||||
inhaleMs: pending.inhale.duration,
|
||||
exhaleMs: pending.exhale.duration,
|
||||
cycleMs
|
||||
};
|
||||
cycleRows.push(row);
|
||||
if (cycleRows.length > 500) cycleRows.shift();
|
||||
|
||||
// Keep the just-started opposite phase only if its end is the most recent turn; otherwise reset.
|
||||
pending = {inhale:null, exhale:null};
|
||||
renderTable();
|
||||
updateStats();
|
||||
}
|
||||
|
||||
function setPhaseUI(phase) {
|
||||
if (!phase) {
|
||||
els.phase.textContent = running ? 'Ищу ритм…' : 'Готово';
|
||||
els.phase.className = 'phase idle';
|
||||
return;
|
||||
}
|
||||
els.phase.textContent = phase === 'inhale' ? 'Вдох' : 'Выдох';
|
||||
els.phase.className = `phase ${phase}`;
|
||||
}
|
||||
|
||||
function updateQuality() {
|
||||
if (signalHistory.length < 20) {
|
||||
els.quality.textContent = '…';
|
||||
return;
|
||||
}
|
||||
const values = signalHistory.filter(s => s.t >= performance.now()-10000).map(s => s.v);
|
||||
const amplitude = std(values);
|
||||
const floor = chosen && chosen.kind === 'tilt' ? 0.0008 : 0.00018;
|
||||
const q = clamp((amplitude / floor) * 24 + clamp(latestSNR,0,2)*22, 0, 100);
|
||||
let label = 'низкое';
|
||||
if (q >= 72) label = 'хорошее';
|
||||
else if (q >= 42) label = 'среднее';
|
||||
els.quality.textContent = label;
|
||||
els.quality.style.color = q >= 72 ? 'var(--good)' : q >= 42 ? 'var(--warn)' : 'var(--bad)';
|
||||
}
|
||||
|
||||
function updateStats() {
|
||||
const now = performance.now();
|
||||
[[1,els.avg1,els.rate1],[3,els.avg3,els.rate3],[5,els.avg5,els.rate5]].forEach(([minutes,valEl,rateEl]) => {
|
||||
const cutoff = now - minutes*60000;
|
||||
const rows = cycleRows.filter(r => r.endPerf >= cutoff);
|
||||
if (!rows.length) {
|
||||
valEl.textContent = '—';
|
||||
rateEl.textContent = 'сек/цикл · — дых./мин';
|
||||
return;
|
||||
}
|
||||
const avgMs = rows.reduce((s,r) => s+r.cycleMs,0) / rows.length;
|
||||
const rate = 60000 / avgMs;
|
||||
valEl.textContent = (avgMs/1000).toFixed(1);
|
||||
rateEl.textContent = `сек/цикл · ${rate.toFixed(1)} дых./мин · n=${rows.length}`;
|
||||
});
|
||||
}
|
||||
|
||||
function renderTable() {
|
||||
els.count.textContent = `${cycleRows.length} ${pluralCycles(cycleRows.length)}`;
|
||||
if (!cycleRows.length) {
|
||||
els.rows.innerHTML = '<tr><td colspan="5" class="empty">Пока нет завершённых циклов</td></tr>';
|
||||
return;
|
||||
}
|
||||
const recent = cycleRows.slice(-40).reverse();
|
||||
els.rows.innerHTML = recent.map(r => {
|
||||
const time = new Date(r.wallTime).toLocaleTimeString('ru-RU', {hour:'2-digit', minute:'2-digit', second:'2-digit'});
|
||||
const rate = 60000 / r.cycleMs;
|
||||
return `<tr><td>${time}</td><td>${fmtSec(r.inhaleMs)}</td><td>${fmtSec(r.exhaleMs)}</td><td><strong>${fmtSec(r.cycleMs)}</strong></td><td>${rate.toFixed(1)}/мин</td></tr>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function pluralCycles(n) {
|
||||
const m10 = n % 10, m100 = n % 100;
|
||||
if (m10 === 1 && m100 !== 11) return 'цикл';
|
||||
if ([2,3,4].includes(m10) && !(m100 >= 12 && m100 <= 14)) return 'цикла';
|
||||
return 'циклов';
|
||||
}
|
||||
|
||||
function drawSignal(now = performance.now()) {
|
||||
const rect = els.canvas.getBoundingClientRect();
|
||||
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
||||
const w = Math.max(320, Math.floor(rect.width*dpr));
|
||||
const h = Math.max(150, Math.floor(rect.height*dpr));
|
||||
if (els.canvas.width !== w || els.canvas.height !== h) {
|
||||
els.canvas.width = w; els.canvas.height = h;
|
||||
}
|
||||
ctx.clearRect(0,0,w,h);
|
||||
|
||||
ctx.strokeStyle = 'rgba(148,163,184,.10)';
|
||||
ctx.lineWidth = 1*dpr;
|
||||
for (let i=1;i<4;i++) {
|
||||
const y = h*i/4;
|
||||
ctx.beginPath(); ctx.moveTo(0,y); ctx.lineTo(w,y); ctx.stroke();
|
||||
}
|
||||
|
||||
if (!signalHistory.length) return;
|
||||
const data = signalHistory.filter(s => s.t >= now-HISTORY_MS);
|
||||
if (data.length < 2) return;
|
||||
const vals = data.map(s=>s.v);
|
||||
const maxAbs = Math.max(latestThreshold*2.5, ...vals.map(v=>Math.abs(v)), 0.001);
|
||||
const mapX = t => ((t-(now-HISTORY_MS))/HISTORY_MS)*w;
|
||||
const mapY = v => h/2 - (v/maxAbs)*(h*0.38);
|
||||
|
||||
ctx.strokeStyle = 'rgba(125,211,252,.95)';
|
||||
ctx.lineWidth = 2*dpr;
|
||||
ctx.beginPath();
|
||||
data.forEach((s,i) => {
|
||||
const x=mapX(s.t), y=mapY(s.v);
|
||||
if (i===0) ctx.moveTo(x,y); else ctx.lineTo(x,y);
|
||||
});
|
||||
ctx.stroke();
|
||||
|
||||
ctx.strokeStyle = 'rgba(196,181,253,.34)';
|
||||
ctx.lineWidth = 1*dpr;
|
||||
[latestThreshold,-latestThreshold].forEach(v => {
|
||||
const y = mapY(v); ctx.beginPath(); ctx.moveTo(0,y); ctx.lineTo(w,y); ctx.stroke();
|
||||
});
|
||||
|
||||
for (const t of turns) {
|
||||
if (t.ts < now-HISTORY_MS) continue;
|
||||
const x = mapX(t.ts), y = mapY(t.value);
|
||||
ctx.fillStyle = t.type === 'peak' ? '#7dd3fc' : '#c4b5fd';
|
||||
ctx.beginPath(); ctx.arc(x,y,3.5*dpr,0,Math.PI*2); ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
function updateDebug(tilt, lin) {
|
||||
const ch = chosen ? `${chosen.kind}/${['X','Y','Z'][chosen.axis]}` : '—';
|
||||
els.debug.textContent = [
|
||||
`samples: ${sampleCount}`,
|
||||
`interval: ${latestInterval.toFixed(1)} ms`,
|
||||
`channel: ${ch}`,
|
||||
`tilt: ${tilt.map(v=>v.toFixed(5)).join(' ')}`,
|
||||
`linear/g: ${lin.map(v=>v.toFixed(5)).join(' ')}`,
|
||||
`signal: ${latestSignal.toFixed(6)}`,
|
||||
`threshold: ${latestThreshold.toFixed(6)}`,
|
||||
`snr-ish: ${latestSNR.toFixed(2)}`,
|
||||
`inverted: ${inverted}`
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function invertPhases() {
|
||||
inverted = !inverted;
|
||||
pending = {inhale:null, exhale:null};
|
||||
turns = [];
|
||||
detector = freshDetector();
|
||||
els.invert.textContent = inverted ? 'Инверсия: вкл' : 'Вдох ↔ выдох';
|
||||
els.cal.textContent = inverted ? 'Направление фаз инвертировано.' : 'Обычное направление фаз.';
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
cycleRows = [];
|
||||
signalHistory = [];
|
||||
turns = [];
|
||||
pending = {inhale:null, exhale:null};
|
||||
detector = freshDetector();
|
||||
renderTable();
|
||||
updateStats();
|
||||
drawSignal();
|
||||
if (running && !calibrating) els.cal.textContent = 'История очищена, измерение продолжается.';
|
||||
}
|
||||
|
||||
els.start.addEventListener('click', start);
|
||||
els.stop.addEventListener('click', stop);
|
||||
els.recal.addEventListener('click', () => { if (running) beginCalibration(); });
|
||||
els.invert.addEventListener('click', invertPhases);
|
||||
els.clear.addEventListener('click', clearAll);
|
||||
window.addEventListener('resize', () => drawSignal());
|
||||
document.addEventListener('visibilitychange', async () => {
|
||||
if (document.visibilityState === 'visible' && running && !wakeLock) await keepAwake();
|
||||
});
|
||||
|
||||
// Recalculate rolling cards even if a motion event pauses briefly.
|
||||
setInterval(() => { if (running) updateStats(); }, 3000);
|
||||
renderTable();
|
||||
updateStats();
|
||||
drawSignal();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,920 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#0f172a" />
|
||||
<title>Дыхание по движению живота</title>
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #07111f;
|
||||
--card: rgba(15, 23, 42, 0.9);
|
||||
--card2: rgba(30, 41, 59, 0.72);
|
||||
--text: #f8fafc;
|
||||
--muted: #94a3b8;
|
||||
--line: rgba(148, 163, 184, 0.18);
|
||||
--accent: #7dd3fc;
|
||||
--accent2: #c4b5fd;
|
||||
--good: #86efac;
|
||||
--warn: #fde68a;
|
||||
--bad: #fca5a5;
|
||||
--shadow: 0 18px 50px rgba(0,0,0,.24);
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at 50% -10%, #14233d 0%, var(--bg) 45%, #040913 100%); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
||||
body { padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom)); }
|
||||
.app { width: min(900px, 100%); margin: 0 auto; }
|
||||
.hero { padding: 8px 4px 14px; }
|
||||
h1 { font-size: clamp(24px, 7vw, 38px); line-height: 1.05; margin: 0 0 8px; letter-spacing: -0.035em; }
|
||||
.subtitle { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
|
||||
.grid { display: grid; gap: 12px; }
|
||||
.card { background: linear-gradient(180deg, rgba(30,41,59,.84), rgba(15,23,42,.9)); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
|
||||
.status-card { padding: 18px; }
|
||||
.status-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
|
||||
.status-main { min-width: 0; }
|
||||
.eyebrow { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; }
|
||||
.phase { font-size: clamp(30px, 10vw, 52px); font-weight: 750; margin-top: 2px; letter-spacing: -.04em; }
|
||||
.phase.inhale { color: var(--accent); }
|
||||
.phase.exhale { color: var(--accent2); }
|
||||
.phase.idle { color: #cbd5e1; }
|
||||
.quality { min-width: 96px; text-align: right; }
|
||||
.quality strong { display: block; font-size: 18px; }
|
||||
.quality span { color: var(--muted); font-size: 12px; }
|
||||
.meter { height: 8px; background: rgba(148,163,184,.12); border-radius: 999px; margin-top: 14px; overflow: hidden; }
|
||||
.meter > i { display: block; height: 100%; width: 0%; border-radius: inherit; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .18s linear; }
|
||||
.calibration { margin-top: 9px; min-height: 20px; color: var(--muted); font-size: 13px; }
|
||||
|
||||
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
|
||||
button { appearance: none; border: 0; border-radius: 16px; padding: 14px 16px; min-height: 50px; font: inherit; font-weight: 700; cursor: pointer; color: #07111f; background: #e2e8f0; }
|
||||
button.primary { background: linear-gradient(135deg, #bae6fd, #ddd6fe); }
|
||||
button.secondary { color: var(--text); background: rgba(148,163,184,.11); border: 1px solid var(--line); }
|
||||
button:disabled { opacity: .45; cursor: not-allowed; }
|
||||
.small-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
|
||||
.small-controls button { padding: 10px 8px; min-height: 42px; font-size: 12px; border-radius: 13px; }
|
||||
|
||||
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; padding: 12px; }
|
||||
.stat { background: rgba(2,6,23,.34); border: 1px solid var(--line); border-radius: 17px; padding: 13px 10px; min-width: 0; }
|
||||
.stat .period { color: var(--muted); font-size: 11px; margin-bottom: 8px; }
|
||||
.triplet { display: grid; gap: 5px; }
|
||||
.metric-line { display:flex; justify-content:space-between; align-items:baseline; gap:8px; }
|
||||
.metric-line span { color:var(--muted); font-size:11px; }
|
||||
.metric-line strong { font-size: clamp(15px, 4vw, 20px); letter-spacing:-.02em; }
|
||||
.metric-line.cycle strong { font-size: clamp(20px, 6vw, 28px); }
|
||||
.stat .unit { color: var(--muted); font-size: 11px; margin-top: 8px; }
|
||||
|
||||
.settings-card { margin-top:12px; padding:14px; }
|
||||
.settings-grid { display:grid; grid-template-columns:1fr; gap:12px; }
|
||||
.setting-row { display:flex; align-items:center; justify-content:space-between; gap:14px; background:rgba(2,6,23,.28); border:1px solid var(--line); border-radius:16px; padding:12px; }
|
||||
.setting-title { font-weight:700; font-size:14px; }
|
||||
.setting-sub { color:var(--muted); font-size:11px; margin-top:3px; line-height:1.35; }
|
||||
.switch { position:relative; width:52px; height:30px; flex:0 0 auto; }
|
||||
.switch input { opacity:0; width:0; height:0; }
|
||||
.slider-switch { position:absolute; inset:0; border-radius:999px; background:rgba(148,163,184,.2); border:1px solid var(--line); transition:.2s; }
|
||||
.slider-switch:before { content:""; position:absolute; width:22px; height:22px; left:3px; top:3px; border-radius:50%; background:#e2e8f0; transition:.2s; }
|
||||
.switch input:checked + .slider-switch { background:linear-gradient(135deg,#7dd3fc,#c4b5fd); }
|
||||
.switch input:checked + .slider-switch:before { transform:translateX(22px); background:#07111f; }
|
||||
.threshold-box { min-width:130px; text-align:right; }
|
||||
.threshold-value { font-size:24px; font-weight:800; letter-spacing:-.04em; }
|
||||
input[type="range"] { width:100%; margin-top:8px; accent-color:#7dd3fc; }
|
||||
.warning-box { margin-top:12px; border-radius:16px; padding:12px 14px; border:1px solid var(--line); background:rgba(2,6,23,.25); display:flex; justify-content:space-between; gap:12px; align-items:center; }
|
||||
.warning-box.alert { border-color:rgba(252,165,165,.55); background:rgba(127,29,29,.18); }
|
||||
.warning-box.ok { border-color:rgba(134,239,172,.35); background:rgba(20,83,45,.14); }
|
||||
.warning-count { font-size:18px; font-weight:800; }
|
||||
|
||||
.wave-card { padding: 12px 12px 8px; }
|
||||
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 2px 4px 8px; }
|
||||
.section-head h2 { margin: 0; font-size: 15px; }
|
||||
.section-head span { color: var(--muted); font-size: 11px; text-align: right; }
|
||||
canvas { display: block; width: 100%; height: 170px; border-radius: 16px; background: rgba(2,6,23,.32); }
|
||||
|
||||
.table-card { overflow: hidden; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
|
||||
th, td { text-align: right; padding: 12px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
|
||||
th:first-child, td:first-child { text-align: left; }
|
||||
th { color: var(--muted); font-size: 11px; font-weight: 650; position: sticky; top: 0; background: #111c2f; }
|
||||
tbody tr:last-child td { border-bottom: 0; }
|
||||
.empty { text-align: center !important; color: var(--muted); padding: 28px 14px !important; }
|
||||
|
||||
details { margin-top: 12px; }
|
||||
summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 6px 4px; }
|
||||
.debug { margin-top: 8px; background: rgba(2,6,23,.35); border: 1px solid var(--line); border-radius: 16px; padding: 12px; color: var(--muted); font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }
|
||||
.note { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 12px 4px 0; }
|
||||
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; font-size: 11px; color: var(--muted); }
|
||||
.dot { width: 7px; height: 7px; border-radius: 999px; background: #64748b; }
|
||||
.dot.on { background: var(--good); box-shadow: 0 0 12px rgba(134,239,172,.7); }
|
||||
|
||||
@media (min-width: 720px) {
|
||||
.top-grid { grid-template-columns: 1.15fr .85fr; }
|
||||
.stats { grid-template-columns: 1fr; height: 100%; }
|
||||
canvas { height: 210px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main class="app">
|
||||
<header class="hero">
|
||||
<h1>Дыхание</h1>
|
||||
<p class="subtitle">Положите телефон экраном вверх на живот и лежите спокойно. Приложение использует датчики движения телефона, чтобы оценивать ритм дыхания.</p>
|
||||
</header>
|
||||
|
||||
<div class="grid top-grid">
|
||||
<section class="card status-card">
|
||||
<div class="status-row">
|
||||
<div class="status-main">
|
||||
<div class="eyebrow">Сейчас</div>
|
||||
<div id="phase" class="phase idle">Готово</div>
|
||||
</div>
|
||||
<div class="quality">
|
||||
<strong id="qualityText">—</strong>
|
||||
<span>качество сигнала</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="meter"><i id="meterBar"></i></div>
|
||||
<div id="calibrationText" class="calibration">Нажмите «Начать». Первые 10 секунд — калибровка.</div>
|
||||
|
||||
<div class="controls">
|
||||
<button id="startBtn" class="primary">Начать</button>
|
||||
<button id="stopBtn" class="secondary" disabled>Остановить</button>
|
||||
</div>
|
||||
<div class="small-controls">
|
||||
<button id="recalibrateBtn" class="secondary" disabled>Калибровка</button>
|
||||
<button id="invertBtn" class="secondary" disabled>Вдох ↔ выдох</button>
|
||||
<button id="clearBtn" class="secondary">Очистить</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card stats" aria-label="Средняя длительность дыхания">
|
||||
<div class="stat">
|
||||
<div class="period">За последнюю 1 минуту</div>
|
||||
<div class="triplet">
|
||||
<div class="metric-line"><span>Вдох</span><strong id="inhale1">—</strong></div>
|
||||
<div class="metric-line"><span>Выдох</span><strong id="exhale1">—</strong></div>
|
||||
<div class="metric-line cycle"><span>Цикл</span><strong id="avg1">—</strong></div>
|
||||
</div>
|
||||
<div id="rate1" class="unit">— дых./мин</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="period">За последние 3 минуты</div>
|
||||
<div class="triplet">
|
||||
<div class="metric-line"><span>Вдох</span><strong id="inhale3">—</strong></div>
|
||||
<div class="metric-line"><span>Выдох</span><strong id="exhale3">—</strong></div>
|
||||
<div class="metric-line cycle"><span>Цикл</span><strong id="avg3">—</strong></div>
|
||||
</div>
|
||||
<div id="rate3" class="unit">— дых./мин</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="period">За последние 5 минут</div>
|
||||
<div class="triplet">
|
||||
<div class="metric-line"><span>Вдох</span><strong id="inhale5">—</strong></div>
|
||||
<div class="metric-line"><span>Выдох</span><strong id="exhale5">—</strong></div>
|
||||
<div class="metric-line cycle"><span>Цикл</span><strong id="avg5">—</strong></div>
|
||||
</div>
|
||||
<div id="rate5" class="unit">— дых./мин</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="card settings-card">
|
||||
<div class="section-head" style="margin-bottom:10px">
|
||||
<h2>Контроль темпа</h2>
|
||||
<span>порог проверяется после каждого полного цикла</span>
|
||||
</div>
|
||||
<div class="settings-grid">
|
||||
<div class="setting-row">
|
||||
<div>
|
||||
<div class="setting-title">Звуковые предупреждения</div>
|
||||
<div class="setting-sub">Если средний цикл за последнюю минуту короче порога: 1 сигнал, затем 2, 3 и т.д.</div>
|
||||
</div>
|
||||
<label class="switch" aria-label="Включить звук">
|
||||
<input id="soundEnabled" type="checkbox" checked>
|
||||
<span class="slider-switch"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div style="min-width:0; flex:1">
|
||||
<div class="setting-title">Минимальный средний цикл</div>
|
||||
<div class="setting-sub">Полный цикл = вдох + выдох. Диапазон 5–15 секунд.</div>
|
||||
<input id="thresholdRange" type="range" min="5" max="15" step="1" value="10">
|
||||
</div>
|
||||
<div class="threshold-box">
|
||||
<div id="thresholdValue" class="threshold-value">10 c</div>
|
||||
<div class="setting-sub">порог</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="warningBox" class="warning-box">
|
||||
<div>
|
||||
<div class="setting-title">Предупреждение</div>
|
||||
<div id="warningText" class="setting-sub">Пока недостаточно данных.</div>
|
||||
</div>
|
||||
<div id="warningCount" class="warning-count">0</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card wave-card" style="margin-top:12px">
|
||||
<div class="section-head">
|
||||
<h2>Сигнал движения</h2>
|
||||
<span id="sensorLabel">датчик ещё не запущен</span>
|
||||
</div>
|
||||
<canvas id="wave" width="900" height="210"></canvas>
|
||||
</section>
|
||||
|
||||
<section class="card table-card" style="margin-top:12px">
|
||||
<div class="section-head" style="padding:14px 14px 4px">
|
||||
<h2>Вдохи и выдохи</h2>
|
||||
<span id="cycleCount">0 циклов</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Время</th>
|
||||
<th>Вдох</th>
|
||||
<th>Выдох</th>
|
||||
<th>Цикл</th>
|
||||
<th>Темп</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="breathRows">
|
||||
<tr><td colspan="5" class="empty">Пока нет завершённых циклов</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<details>
|
||||
<summary>Диагностика датчика</summary>
|
||||
<div id="debug" class="debug">—</div>
|
||||
</details>
|
||||
<p class="note">Это экспериментальная оценка ритма дыхания по движению телефона, а не медицинский измерительный прибор. Для наиболее стабильного результата телефон должен лежать свободно и не скользить по одежде.</p>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
const els = {
|
||||
start: $('startBtn'), stop: $('stopBtn'), recal: $('recalibrateBtn'), invert: $('invertBtn'), clear: $('clearBtn'),
|
||||
phase: $('phase'), quality: $('qualityText'), meter: $('meterBar'), cal: $('calibrationText'), sensor: $('sensorLabel'),
|
||||
avg1: $('avg1'), avg3: $('avg3'), avg5: $('avg5'), rate1: $('rate1'), rate3: $('rate3'), rate5: $('rate5'),
|
||||
inhale1: $('inhale1'), inhale3: $('inhale3'), inhale5: $('inhale5'), exhale1: $('exhale1'), exhale3: $('exhale3'), exhale5: $('exhale5'),
|
||||
soundEnabled: $('soundEnabled'), thresholdRange: $('thresholdRange'), thresholdValue: $('thresholdValue'), warningBox: $('warningBox'), warningText: $('warningText'), warningCount: $('warningCount'),
|
||||
rows: $('breathRows'), count: $('cycleCount'), debug: $('debug'), canvas: $('wave')
|
||||
};
|
||||
const ctx = els.canvas.getContext('2d');
|
||||
|
||||
const CALIBRATION_MS = 10000;
|
||||
const MIN_HALF_PHASE_MS = 800;
|
||||
const MAX_HALF_PHASE_MS = 20000;
|
||||
const MAX_CYCLE_MS = 40000;
|
||||
const MIN_CYCLE_MS = 1800;
|
||||
const HISTORY_MS = 30000;
|
||||
const G = 9.80665;
|
||||
|
||||
let running = false;
|
||||
let calibrating = false;
|
||||
let calibrationStartedAt = 0;
|
||||
let lastTs = null;
|
||||
let sampleCount = 0;
|
||||
let chosen = null; // {kind:'tilt'|'linear', axis:0..2, sign:1}
|
||||
let inverted = false;
|
||||
let wakeLock = null;
|
||||
let noDataTimer = null;
|
||||
|
||||
let gravity = [0,0,0];
|
||||
let gravityReady = false;
|
||||
let filters = makeFilters();
|
||||
let calibrationSamples = [];
|
||||
let signalHistory = [];
|
||||
let cycleRows = [];
|
||||
let turns = [];
|
||||
let detector = freshDetector();
|
||||
let pending = { inhale: null, exhale: null };
|
||||
let currentPhase = null;
|
||||
let latestSignal = 0;
|
||||
let latestThreshold = 0.002;
|
||||
let latestSNR = 0;
|
||||
let latestInterval = 0;
|
||||
let audioCtx = null;
|
||||
let warningLevel = 0;
|
||||
let lastOneMinuteAvgMs = null;
|
||||
|
||||
function makeFilters() {
|
||||
return Array.from({length: 6}, () => ({fast: null, slow: null, last: 0}));
|
||||
}
|
||||
|
||||
function freshDetector() {
|
||||
return {
|
||||
mode: null, // seekingPeak | seekingTrough
|
||||
candidateValue: null,
|
||||
candidateTs: null,
|
||||
lastTurnTs: null
|
||||
};
|
||||
}
|
||||
|
||||
function ema(prev, value, dt, tau) {
|
||||
if (prev == null || !Number.isFinite(prev)) return value;
|
||||
const a = 1 - Math.exp(-Math.max(0.001, dt) / tau);
|
||||
return prev + a * (value - prev);
|
||||
}
|
||||
|
||||
function variance(arr) {
|
||||
if (!arr.length) return 0;
|
||||
const m = arr.reduce((a,b) => a+b, 0) / arr.length;
|
||||
return arr.reduce((s,v) => s + (v-m)*(v-m), 0) / arr.length;
|
||||
}
|
||||
|
||||
function std(arr) { return Math.sqrt(variance(arr)); }
|
||||
function clamp(v, lo, hi) { return Math.max(lo, Math.min(hi, v)); }
|
||||
function fmtSec(ms) { return (ms / 1000).toFixed(1) + ' c'; }
|
||||
|
||||
|
||||
function thresholdSeconds() {
|
||||
return Number(els.thresholdRange.value) || 10;
|
||||
}
|
||||
|
||||
function ensureAudio() {
|
||||
if (!els.soundEnabled.checked) return null;
|
||||
try {
|
||||
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
if (audioCtx.state === 'suspended') audioCtx.resume();
|
||||
return audioCtx;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function playWarningBeeps(count) {
|
||||
if (!els.soundEnabled.checked || count <= 0) return;
|
||||
const ac = ensureAudio();
|
||||
if (!ac) return;
|
||||
const startAt = ac.currentTime + 0.03;
|
||||
const beepLength = 0.12;
|
||||
const gap = 0.13;
|
||||
const maxBeeps = Math.min(count, 20); // защита от бесконечно длинной серии
|
||||
for (let i = 0; i < maxBeeps; i++) {
|
||||
const osc = ac.createOscillator();
|
||||
const gain = ac.createGain();
|
||||
const t0 = startAt + i * (beepLength + gap);
|
||||
osc.type = 'sine';
|
||||
osc.frequency.setValueAtTime(740, t0);
|
||||
gain.gain.setValueAtTime(0.0001, t0);
|
||||
gain.gain.exponentialRampToValueAtTime(0.14, t0 + 0.015);
|
||||
gain.gain.exponentialRampToValueAtTime(0.0001, t0 + beepLength);
|
||||
osc.connect(gain);
|
||||
gain.connect(ac.destination);
|
||||
osc.start(t0);
|
||||
osc.stop(t0 + beepLength + 0.02);
|
||||
}
|
||||
}
|
||||
|
||||
function getWindowAverages(minutes) {
|
||||
const now = performance.now();
|
||||
const cutoff = now - minutes * 60000;
|
||||
const rows = cycleRows.filter(r => r.endPerf >= cutoff);
|
||||
if (!rows.length) return null;
|
||||
return {
|
||||
rows,
|
||||
inhaleMs: rows.reduce((s,r) => s + r.inhaleMs, 0) / rows.length,
|
||||
exhaleMs: rows.reduce((s,r) => s + r.exhaleMs, 0) / rows.length,
|
||||
cycleMs: rows.reduce((s,r) => s + r.cycleMs, 0) / rows.length
|
||||
};
|
||||
}
|
||||
|
||||
function updateWarningUI() {
|
||||
const threshold = thresholdSeconds();
|
||||
els.thresholdValue.textContent = `${threshold} c`;
|
||||
els.warningCount.textContent = String(warningLevel);
|
||||
|
||||
if (lastOneMinuteAvgMs == null) {
|
||||
els.warningBox.className = 'warning-box';
|
||||
els.warningText.textContent = 'Пока недостаточно данных.';
|
||||
return;
|
||||
}
|
||||
const avgSec = lastOneMinuteAvgMs / 1000;
|
||||
if (avgSec < threshold) {
|
||||
els.warningBox.className = 'warning-box alert';
|
||||
els.warningText.textContent = `Средний цикл за 1 минуту ${avgSec.toFixed(1)} c — ниже порога ${threshold} c.`;
|
||||
} else {
|
||||
els.warningBox.className = 'warning-box ok';
|
||||
els.warningText.textContent = `Средний цикл ${avgSec.toFixed(1)} c — порог ${threshold} c соблюдается.`;
|
||||
}
|
||||
}
|
||||
|
||||
function evaluatePaceAndMaybeWarn(playSound = true) {
|
||||
const avg = getWindowAverages(1);
|
||||
lastOneMinuteAvgMs = avg ? avg.cycleMs : null;
|
||||
const thresholdMs = thresholdSeconds() * 1000;
|
||||
|
||||
if (!avg) {
|
||||
warningLevel = 0;
|
||||
updateWarningUI();
|
||||
return;
|
||||
}
|
||||
|
||||
if (avg.cycleMs < thresholdMs) {
|
||||
warningLevel += 1;
|
||||
if (playSound) playWarningBeeps(warningLevel);
|
||||
} else {
|
||||
warningLevel = 0;
|
||||
}
|
||||
updateWarningUI();
|
||||
}
|
||||
|
||||
async function requestMotionPermission() {
|
||||
if (typeof DeviceMotionEvent === 'undefined') {
|
||||
throw new Error('Этот браузер не поддерживает DeviceMotionEvent.');
|
||||
}
|
||||
if (typeof DeviceMotionEvent.requestPermission === 'function') {
|
||||
const result = await DeviceMotionEvent.requestPermission();
|
||||
if (result !== 'granted') throw new Error('Доступ к датчикам движения не разрешён.');
|
||||
}
|
||||
}
|
||||
|
||||
async function keepAwake() {
|
||||
try {
|
||||
if ('wakeLock' in navigator) wakeLock = await navigator.wakeLock.request('screen');
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
async function start() {
|
||||
if (running) return;
|
||||
try {
|
||||
await requestMotionPermission();
|
||||
} catch (err) {
|
||||
els.cal.textContent = err.message + ' Если это iPhone — откройте страницу по HTTPS и нажмите кнопку ещё раз.';
|
||||
els.phase.textContent = 'Нет доступа';
|
||||
els.phase.className = 'phase idle';
|
||||
return;
|
||||
}
|
||||
|
||||
running = true;
|
||||
sampleCount = 0;
|
||||
lastTs = null;
|
||||
gravityReady = false;
|
||||
gravity = [0,0,0];
|
||||
filters = makeFilters();
|
||||
signalHistory = [];
|
||||
resetDetection(false);
|
||||
beginCalibration();
|
||||
|
||||
window.addEventListener('devicemotion', onMotion, {passive: true});
|
||||
await keepAwake();
|
||||
els.start.disabled = true;
|
||||
els.stop.disabled = false;
|
||||
els.recal.disabled = false;
|
||||
els.invert.disabled = false;
|
||||
els.phase.textContent = 'Калибровка';
|
||||
els.phase.className = 'phase idle';
|
||||
els.sensor.textContent = 'ожидание данных датчика…';
|
||||
|
||||
clearTimeout(noDataTimer);
|
||||
noDataTimer = setTimeout(() => {
|
||||
if (running && sampleCount < 3) {
|
||||
els.cal.textContent = 'Данные от датчика не приходят. Проверьте HTTPS, разрешение Motion & Orientation и попробуйте другой браузер.';
|
||||
els.quality.textContent = 'нет данных';
|
||||
}
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
async function stop() {
|
||||
if (!running) return;
|
||||
running = false;
|
||||
calibrating = false;
|
||||
window.removeEventListener('devicemotion', onMotion);
|
||||
clearTimeout(noDataTimer);
|
||||
if (wakeLock) { try { await wakeLock.release(); } catch (_) {} wakeLock = null; }
|
||||
els.start.disabled = false;
|
||||
els.stop.disabled = true;
|
||||
els.recal.disabled = true;
|
||||
els.invert.disabled = true;
|
||||
els.phase.textContent = 'Остановлено';
|
||||
els.phase.className = 'phase idle';
|
||||
els.cal.textContent = 'Измерение остановлено.';
|
||||
els.meter.style.width = '0%';
|
||||
}
|
||||
|
||||
function beginCalibration() {
|
||||
calibrating = true;
|
||||
calibrationStartedAt = performance.now();
|
||||
calibrationSamples = [];
|
||||
chosen = null;
|
||||
filters = makeFilters();
|
||||
resetDetection(false);
|
||||
els.cal.textContent = 'Калибровка: лежите спокойно и дышите как обычно…';
|
||||
}
|
||||
|
||||
function resetDetection(clearRows = false) {
|
||||
detector = freshDetector();
|
||||
turns = [];
|
||||
pending = { inhale: null, exhale: null };
|
||||
currentPhase = null;
|
||||
if (clearRows) cycleRows = [];
|
||||
renderTable();
|
||||
updateStats();
|
||||
}
|
||||
|
||||
function onMotion(ev) {
|
||||
if (!running) return;
|
||||
const now = performance.now();
|
||||
const dt = lastTs == null ? (ev.interval ? ev.interval/1000 : 0.02) : clamp((now-lastTs)/1000, 0.005, 0.2);
|
||||
lastTs = now;
|
||||
latestInterval = ev.interval || dt*1000;
|
||||
sampleCount++;
|
||||
|
||||
const ag = ev.accelerationIncludingGravity;
|
||||
if (!ag || [ag.x,ag.y,ag.z].some(v => v == null || !Number.isFinite(v))) return;
|
||||
const a = ev.acceleration;
|
||||
const agv = [ag.x, ag.y, ag.z];
|
||||
|
||||
if (!gravityReady) {
|
||||
gravity = agv.slice();
|
||||
gravityReady = true;
|
||||
} else {
|
||||
// Gravity follows slow orientation changes but ignores quick vibration.
|
||||
const tauG = 0.55;
|
||||
for (let i=0;i<3;i++) gravity[i] = ema(gravity[i], agv[i], dt, tauG);
|
||||
}
|
||||
|
||||
const gm = Math.hypot(gravity[0], gravity[1], gravity[2]) || G;
|
||||
const tilt = gravity.map(v => v / gm);
|
||||
const lin = (a && [a.x,a.y,a.z].every(v => v != null && Number.isFinite(v)))
|
||||
? [a.x/G, a.y/G, a.z/G]
|
||||
: agv.map((v,i) => (v-gravity[i])/G);
|
||||
const candidates = [...tilt, ...lin];
|
||||
const band = candidates.map((v, i) => {
|
||||
const f = filters[i];
|
||||
f.fast = ema(f.fast, v, dt, 0.38);
|
||||
f.slow = ema(f.slow, v, dt, 7.0);
|
||||
f.last = f.fast - f.slow;
|
||||
return f.last;
|
||||
});
|
||||
|
||||
if (calibrating) {
|
||||
calibrationSamples.push({t: now, band: band.slice()});
|
||||
const elapsed = now - calibrationStartedAt;
|
||||
const pct = clamp(elapsed / CALIBRATION_MS, 0, 1);
|
||||
els.meter.style.width = (pct*100).toFixed(0) + '%';
|
||||
els.cal.textContent = `Калибровка: ${Math.max(0, Math.ceil((CALIBRATION_MS-elapsed)/1000))} c. Дышите спокойно.`;
|
||||
if (elapsed >= CALIBRATION_MS) finishCalibration();
|
||||
drawSignal(now);
|
||||
updateDebug(tilt, lin);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!chosen) return;
|
||||
const idx = chosen.kind === 'tilt' ? chosen.axis : chosen.axis + 3;
|
||||
latestSignal = band[idx] * chosen.sign;
|
||||
signalHistory.push({t: now, v: latestSignal});
|
||||
trimSignal(now);
|
||||
updateThreshold();
|
||||
detectTurn(now, latestSignal);
|
||||
updateQuality();
|
||||
drawSignal(now);
|
||||
updateDebug(tilt, lin);
|
||||
}
|
||||
|
||||
function finishCalibration() {
|
||||
calibrating = false;
|
||||
const recent = calibrationSamples.filter(s => s.t >= performance.now() - CALIBRATION_MS);
|
||||
const cols = Array.from({length:6}, (_,i) => recent.map(s => s.band[i]));
|
||||
const scores = cols.map(values => {
|
||||
if (values.length < 10) return 0;
|
||||
const s = std(values);
|
||||
// Prefer a coherent slow signal: downsample rough derivative as a noise penalty.
|
||||
let rough = 0;
|
||||
for (let i=1;i<values.length;i++) rough += Math.abs(values[i]-values[i-1]);
|
||||
rough /= Math.max(1, values.length-1);
|
||||
return s / (rough + 1e-6);
|
||||
});
|
||||
|
||||
const tiltStd = cols.slice(0,3).map(std);
|
||||
const linearStd = cols.slice(3,6).map(std);
|
||||
const bestTiltAxis = tiltStd.indexOf(Math.max(...tiltStd));
|
||||
const bestLinearAxis = linearStd.indexOf(Math.max(...linearStd));
|
||||
|
||||
// Tilt is closer to actual abdominal position. Use linear acceleration only when tilt is almost absent.
|
||||
if (tiltStd[bestTiltAxis] >= 0.0012) {
|
||||
chosen = {kind:'tilt', axis:bestTiltAxis, sign:1};
|
||||
} else {
|
||||
chosen = {kind:'linear', axis:bestLinearAxis, sign:1};
|
||||
}
|
||||
|
||||
const labels = ['X','Y','Z'];
|
||||
els.sensor.textContent = `${chosen.kind === 'tilt' ? 'наклон' : 'ускорение'} · ось ${labels[chosen.axis]}`;
|
||||
els.cal.textContent = 'Калибровка завершена. Если вдох и выдох перепутаны — нажмите «Вдох ↔ выдох».';
|
||||
els.meter.style.width = '100%';
|
||||
setTimeout(() => { if (running && !calibrating) els.meter.style.width = '0%'; }, 600);
|
||||
|
||||
signalHistory = [];
|
||||
detector = freshDetector();
|
||||
pending = {inhale:null, exhale:null};
|
||||
}
|
||||
|
||||
function trimSignal(now) {
|
||||
const cutoff = now - HISTORY_MS;
|
||||
while (signalHistory.length && signalHistory[0].t < cutoff) signalHistory.shift();
|
||||
}
|
||||
|
||||
function updateThreshold() {
|
||||
const values = signalHistory.filter(s => s.t >= performance.now()-12000).map(s => s.v);
|
||||
if (values.length < 20) return;
|
||||
const s = std(values);
|
||||
latestThreshold = clamp(s * 0.55, chosen && chosen.kind === 'tilt' ? 0.00045 : 0.00018, 0.035);
|
||||
|
||||
let rough = 0;
|
||||
for (let i=1;i<values.length;i++) rough += Math.abs(values[i]-values[i-1]);
|
||||
rough /= Math.max(1, values.length-1);
|
||||
latestSNR = s / Math.max(rough*4, 1e-6);
|
||||
}
|
||||
|
||||
function detectTurn(now, value) {
|
||||
const d = detector;
|
||||
if (d.mode == null) {
|
||||
d.mode = 'seekingPeak';
|
||||
d.candidateValue = value;
|
||||
d.candidateTs = now;
|
||||
return;
|
||||
}
|
||||
|
||||
if (d.mode === 'seekingPeak') {
|
||||
if (d.candidateValue == null || value > d.candidateValue) {
|
||||
d.candidateValue = value;
|
||||
d.candidateTs = now;
|
||||
}
|
||||
const drop = d.candidateValue - value;
|
||||
const enoughTime = d.lastTurnTs == null || d.candidateTs - d.lastTurnTs >= MIN_HALF_PHASE_MS;
|
||||
if (drop >= latestThreshold && enoughTime) {
|
||||
confirmTurn('peak', d.candidateTs, d.candidateValue);
|
||||
d.mode = 'seekingTrough';
|
||||
d.candidateValue = value;
|
||||
d.candidateTs = now;
|
||||
}
|
||||
} else {
|
||||
if (d.candidateValue == null || value < d.candidateValue) {
|
||||
d.candidateValue = value;
|
||||
d.candidateTs = now;
|
||||
}
|
||||
const rise = value - d.candidateValue;
|
||||
const enoughTime = d.lastTurnTs == null || d.candidateTs - d.lastTurnTs >= MIN_HALF_PHASE_MS;
|
||||
if (rise >= latestThreshold && enoughTime) {
|
||||
confirmTurn('trough', d.candidateTs, d.candidateValue);
|
||||
d.mode = 'seekingPeak';
|
||||
d.candidateValue = value;
|
||||
d.candidateTs = now;
|
||||
}
|
||||
}
|
||||
|
||||
if (d.lastTurnTs != null && now - d.lastTurnTs > MAX_HALF_PHASE_MS) {
|
||||
// Lost the rhythm; start looking again instead of inventing a huge breath.
|
||||
detector = freshDetector();
|
||||
pending = {inhale:null, exhale:null};
|
||||
currentPhase = null;
|
||||
setPhaseUI(null);
|
||||
}
|
||||
}
|
||||
|
||||
function confirmTurn(type, ts, value) {
|
||||
const d = detector;
|
||||
const prev = turns.length ? turns[turns.length-1] : null;
|
||||
if (prev && prev.type === type) return;
|
||||
if (prev && ts - prev.ts < MIN_HALF_PHASE_MS) return;
|
||||
|
||||
const turn = {type, ts, value};
|
||||
turns.push(turn);
|
||||
if (turns.length > 30) turns.shift();
|
||||
d.lastTurnTs = ts;
|
||||
|
||||
if (!prev) return;
|
||||
const duration = ts - prev.ts;
|
||||
if (duration > MAX_HALF_PHASE_MS) return;
|
||||
|
||||
// In the default orientation: trough -> peak = inhale, peak -> trough = exhale.
|
||||
let phase = type === 'peak' ? 'inhale' : 'exhale';
|
||||
if (inverted) phase = phase === 'inhale' ? 'exhale' : 'inhale';
|
||||
currentPhase = phase === 'inhale' ? 'exhale' : 'inhale'; // after the turning point the next phase begins
|
||||
setPhaseUI(currentPhase);
|
||||
|
||||
pending[phase] = {duration, endTs: ts};
|
||||
maybeCompleteCycle(ts);
|
||||
}
|
||||
|
||||
function maybeCompleteCycle(endTs) {
|
||||
if (!pending.inhale || !pending.exhale) return;
|
||||
const cycleMs = pending.inhale.duration + pending.exhale.duration;
|
||||
if (cycleMs < MIN_CYCLE_MS || cycleMs > MAX_CYCLE_MS) {
|
||||
pending = {inhale:null, exhale:null};
|
||||
return;
|
||||
}
|
||||
|
||||
const row = {
|
||||
endPerf: endTs,
|
||||
wallTime: Date.now() - (performance.now() - endTs),
|
||||
inhaleMs: pending.inhale.duration,
|
||||
exhaleMs: pending.exhale.duration,
|
||||
cycleMs
|
||||
};
|
||||
cycleRows.push(row);
|
||||
if (cycleRows.length > 500) cycleRows.shift();
|
||||
|
||||
// Keep the just-started opposite phase only if its end is the most recent turn; otherwise reset.
|
||||
pending = {inhale:null, exhale:null};
|
||||
renderTable();
|
||||
updateStats();
|
||||
evaluatePaceAndMaybeWarn(true);
|
||||
}
|
||||
|
||||
function setPhaseUI(phase) {
|
||||
if (!phase) {
|
||||
els.phase.textContent = running ? 'Ищу ритм…' : 'Готово';
|
||||
els.phase.className = 'phase idle';
|
||||
return;
|
||||
}
|
||||
els.phase.textContent = phase === 'inhale' ? 'Вдох' : 'Выдох';
|
||||
els.phase.className = `phase ${phase}`;
|
||||
}
|
||||
|
||||
function updateQuality() {
|
||||
if (signalHistory.length < 20) {
|
||||
els.quality.textContent = '…';
|
||||
return;
|
||||
}
|
||||
const values = signalHistory.filter(s => s.t >= performance.now()-10000).map(s => s.v);
|
||||
const amplitude = std(values);
|
||||
const floor = chosen && chosen.kind === 'tilt' ? 0.0008 : 0.00018;
|
||||
const q = clamp((amplitude / floor) * 24 + clamp(latestSNR,0,2)*22, 0, 100);
|
||||
let label = 'низкое';
|
||||
if (q >= 72) label = 'хорошее';
|
||||
else if (q >= 42) label = 'среднее';
|
||||
els.quality.textContent = label;
|
||||
els.quality.style.color = q >= 72 ? 'var(--good)' : q >= 42 ? 'var(--warn)' : 'var(--bad)';
|
||||
}
|
||||
|
||||
function updateStats() {
|
||||
[
|
||||
[1, els.inhale1, els.exhale1, els.avg1, els.rate1],
|
||||
[3, els.inhale3, els.exhale3, els.avg3, els.rate3],
|
||||
[5, els.inhale5, els.exhale5, els.avg5, els.rate5]
|
||||
].forEach(([minutes, inhaleEl, exhaleEl, cycleEl, rateEl]) => {
|
||||
const avg = getWindowAverages(minutes);
|
||||
if (!avg) {
|
||||
inhaleEl.textContent = '—';
|
||||
exhaleEl.textContent = '—';
|
||||
cycleEl.textContent = '—';
|
||||
rateEl.textContent = '— дых./мин';
|
||||
return;
|
||||
}
|
||||
const rate = 60000 / avg.cycleMs;
|
||||
inhaleEl.textContent = (avg.inhaleMs/1000).toFixed(1) + ' c';
|
||||
exhaleEl.textContent = (avg.exhaleMs/1000).toFixed(1) + ' c';
|
||||
cycleEl.textContent = (avg.cycleMs/1000).toFixed(1) + ' c';
|
||||
rateEl.textContent = `${rate.toFixed(1)} дых./мин · n=${avg.rows.length}`;
|
||||
});
|
||||
|
||||
const oneMinute = getWindowAverages(1);
|
||||
lastOneMinuteAvgMs = oneMinute ? oneMinute.cycleMs : null;
|
||||
updateWarningUI();
|
||||
}
|
||||
|
||||
function renderTable() {
|
||||
els.count.textContent = `${cycleRows.length} ${pluralCycles(cycleRows.length)}`;
|
||||
if (!cycleRows.length) {
|
||||
els.rows.innerHTML = '<tr><td colspan="5" class="empty">Пока нет завершённых циклов</td></tr>';
|
||||
return;
|
||||
}
|
||||
const recent = cycleRows.slice(-40).reverse();
|
||||
els.rows.innerHTML = recent.map(r => {
|
||||
const time = new Date(r.wallTime).toLocaleTimeString('ru-RU', {hour:'2-digit', minute:'2-digit', second:'2-digit'});
|
||||
const rate = 60000 / r.cycleMs;
|
||||
return `<tr><td>${time}</td><td>${fmtSec(r.inhaleMs)}</td><td>${fmtSec(r.exhaleMs)}</td><td><strong>${fmtSec(r.cycleMs)}</strong></td><td>${rate.toFixed(1)}/мин</td></tr>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function pluralCycles(n) {
|
||||
const m10 = n % 10, m100 = n % 100;
|
||||
if (m10 === 1 && m100 !== 11) return 'цикл';
|
||||
if ([2,3,4].includes(m10) && !(m100 >= 12 && m100 <= 14)) return 'цикла';
|
||||
return 'циклов';
|
||||
}
|
||||
|
||||
function drawSignal(now = performance.now()) {
|
||||
const rect = els.canvas.getBoundingClientRect();
|
||||
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
||||
const w = Math.max(320, Math.floor(rect.width*dpr));
|
||||
const h = Math.max(150, Math.floor(rect.height*dpr));
|
||||
if (els.canvas.width !== w || els.canvas.height !== h) {
|
||||
els.canvas.width = w; els.canvas.height = h;
|
||||
}
|
||||
ctx.clearRect(0,0,w,h);
|
||||
|
||||
ctx.strokeStyle = 'rgba(148,163,184,.10)';
|
||||
ctx.lineWidth = 1*dpr;
|
||||
for (let i=1;i<4;i++) {
|
||||
const y = h*i/4;
|
||||
ctx.beginPath(); ctx.moveTo(0,y); ctx.lineTo(w,y); ctx.stroke();
|
||||
}
|
||||
|
||||
if (!signalHistory.length) return;
|
||||
const data = signalHistory.filter(s => s.t >= now-HISTORY_MS);
|
||||
if (data.length < 2) return;
|
||||
const vals = data.map(s=>s.v);
|
||||
const maxAbs = Math.max(latestThreshold*2.5, ...vals.map(v=>Math.abs(v)), 0.001);
|
||||
const mapX = t => ((t-(now-HISTORY_MS))/HISTORY_MS)*w;
|
||||
const mapY = v => h/2 - (v/maxAbs)*(h*0.38);
|
||||
|
||||
ctx.strokeStyle = 'rgba(125,211,252,.95)';
|
||||
ctx.lineWidth = 2*dpr;
|
||||
ctx.beginPath();
|
||||
data.forEach((s,i) => {
|
||||
const x=mapX(s.t), y=mapY(s.v);
|
||||
if (i===0) ctx.moveTo(x,y); else ctx.lineTo(x,y);
|
||||
});
|
||||
ctx.stroke();
|
||||
|
||||
ctx.strokeStyle = 'rgba(196,181,253,.34)';
|
||||
ctx.lineWidth = 1*dpr;
|
||||
[latestThreshold,-latestThreshold].forEach(v => {
|
||||
const y = mapY(v); ctx.beginPath(); ctx.moveTo(0,y); ctx.lineTo(w,y); ctx.stroke();
|
||||
});
|
||||
|
||||
for (const t of turns) {
|
||||
if (t.ts < now-HISTORY_MS) continue;
|
||||
const x = mapX(t.ts), y = mapY(t.value);
|
||||
ctx.fillStyle = t.type === 'peak' ? '#7dd3fc' : '#c4b5fd';
|
||||
ctx.beginPath(); ctx.arc(x,y,3.5*dpr,0,Math.PI*2); ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
function updateDebug(tilt, lin) {
|
||||
const ch = chosen ? `${chosen.kind}/${['X','Y','Z'][chosen.axis]}` : '—';
|
||||
els.debug.textContent = [
|
||||
`samples: ${sampleCount}`,
|
||||
`interval: ${latestInterval.toFixed(1)} ms`,
|
||||
`channel: ${ch}`,
|
||||
`tilt: ${tilt.map(v=>v.toFixed(5)).join(' ')}`,
|
||||
`linear/g: ${lin.map(v=>v.toFixed(5)).join(' ')}`,
|
||||
`signal: ${latestSignal.toFixed(6)}`,
|
||||
`threshold: ${latestThreshold.toFixed(6)}`,
|
||||
`snr-ish: ${latestSNR.toFixed(2)}`,
|
||||
`inverted: ${inverted}`
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function invertPhases() {
|
||||
inverted = !inverted;
|
||||
pending = {inhale:null, exhale:null};
|
||||
turns = [];
|
||||
detector = freshDetector();
|
||||
els.invert.textContent = inverted ? 'Инверсия: вкл' : 'Вдох ↔ выдох';
|
||||
els.cal.textContent = inverted ? 'Направление фаз инвертировано.' : 'Обычное направление фаз.';
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
cycleRows = [];
|
||||
signalHistory = [];
|
||||
turns = [];
|
||||
pending = {inhale:null, exhale:null};
|
||||
detector = freshDetector();
|
||||
warningLevel = 0;
|
||||
lastOneMinuteAvgMs = null;
|
||||
renderTable();
|
||||
updateStats();
|
||||
drawSignal();
|
||||
if (running && !calibrating) els.cal.textContent = 'История очищена, измерение продолжается.';
|
||||
}
|
||||
|
||||
els.start.addEventListener('click', async () => {
|
||||
ensureAudio();
|
||||
await start();
|
||||
});
|
||||
els.stop.addEventListener('click', stop);
|
||||
els.recal.addEventListener('click', () => { if (running) beginCalibration(); });
|
||||
els.invert.addEventListener('click', invertPhases);
|
||||
els.clear.addEventListener('click', clearAll);
|
||||
els.soundEnabled.addEventListener('change', () => {
|
||||
if (els.soundEnabled.checked) ensureAudio();
|
||||
});
|
||||
els.thresholdRange.addEventListener('input', () => {
|
||||
const avg = getWindowAverages(1);
|
||||
lastOneMinuteAvgMs = avg ? avg.cycleMs : null;
|
||||
if (avg && avg.cycleMs >= thresholdSeconds() * 1000) warningLevel = 0;
|
||||
updateWarningUI();
|
||||
});
|
||||
window.addEventListener('resize', () => drawSignal());
|
||||
document.addEventListener('visibilitychange', async () => {
|
||||
if (document.visibilityState === 'visible' && running && !wakeLock) await keepAwake();
|
||||
});
|
||||
|
||||
// Recalculate rolling cards even if a motion event pauses briefly.
|
||||
setInterval(() => { if (running) updateStats(); }, 3000);
|
||||
renderTable();
|
||||
updateStats();
|
||||
updateWarningUI();
|
||||
drawSignal();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,34 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>SHiNE – четыре направления UI</title>
|
||||
<link rel="stylesheet" href="mockups.css">
|
||||
<script src="mockups.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="studio-header">
|
||||
<a class="brand" href="index.html" aria-label="SHiNE – все варианты"><span class="brand-spark">✳</span> SHiNE<span class="brand-caption">DESIGN STUDY / 01</span></a>
|
||||
<span class="draft-label">Концепции · сентябрь 2026</span>
|
||||
</header>
|
||||
<main>
|
||||
<section class="intro">
|
||||
<div><div class="eyebrow">КАНАЛЫ / СООБЩЕНИЯ / ОТВЕТЫ</div><h1>Ближе к разговору.</h1><p>Четыре характера. Один привычный путь от канала к ответу.<br>Выберите экран и сравните – или нажмите на элементы внутри макета.</p></div>
|
||||
<div class="intro-note"><span>01–04</span><p>Меньше визуального шума.<br>Больше места людям и мыслям.</p></div>
|
||||
</section>
|
||||
<section class="review-bar" aria-label="Управление просмотром">
|
||||
<div class="screen-switch" role="group" aria-label="Экран для всех вариантов">
|
||||
<button class="review-button selected" data-screen="list" aria-pressed="true">01 Каналы</button>
|
||||
<button class="review-button" data-screen="feed" aria-pressed="false">02 Сообщения</button>
|
||||
<button class="review-button" data-screen="thread" aria-pressed="false">03 Ветка</button>
|
||||
<button class="review-button" data-screen="reply" aria-pressed="false">04 Ответ</button>
|
||||
</div>
|
||||
<div class="review-options"><label>Роль <select id="role"><option value="reader">Читатель</option><option value="owner">Владелец</option></select></label><label class="keyboard-option"><input type="checkbox" id="keyboard"> Макет клавиатуры</label><a class="compare-link" href="index.html">Все варианты ↗</a></div>
|
||||
</section>
|
||||
<div id="gallery" class="gallery"></div>
|
||||
<section class="decision-note"><span class="eyebrow">С ЧЕГО НАЧАТЬ ОБСУЖДЕНИЕ</span><h2>Сначала удобство. Затем характер.</h2><div class="decision-grid"><p><b>01 / Читаемость</b>Где комфортнее читать длинный пост и замечать новый ответ?</p><p><b>02 / Плотность</b>Нужны просторные сообщения или больше содержимого на одном экране?</p><p><b>03 / Окно ответа</b>Полный экран или лист поверх ветки? Проверьте с макетом клавиатуры.</p></div><p class="disclaimer">Демонстрационные данные. Отправка и реакции работают только внутри этой страницы. Поиск фильтрует примеры. Другие разделы приложения не проектировались. <a href="../DESIGN.md">Дизайн-документ ↗</a></p></section>
|
||||
</main>
|
||||
<footer class="studio-footer"><span>SHiNE / пространство для общения</span><span>Рабочий материал · не финальный дизайн</span></footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,212 @@
|
||||
* { box-sizing: border-box; }
|
||||
:root { color-scheme: light; font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: #242622; background: #f1f0eb; }
|
||||
body { margin: 0; }
|
||||
button, input, textarea, select { font: inherit; }
|
||||
button, a, select { -webkit-tap-highlight-color: transparent; }
|
||||
button { cursor: pointer; }
|
||||
button:disabled { cursor: default; opacity: .4; }
|
||||
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid #728de3; outline-offset: 3px; }
|
||||
a { color: inherit; }
|
||||
.studio-header { margin: 0 42px; padding: 26px 0; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #d5d6ce; gap: 16px; }
|
||||
.brand { display: flex; align-items: center; gap: 9px; font-size: 25px; font-weight: 760; text-decoration: none; letter-spacing: -1px; }
|
||||
.brand-spark { font-size: 36px; font-weight: 400; }
|
||||
.brand-caption { margin-left: 22px; font-size: 10px; letter-spacing: 2px; font-weight: 600; }
|
||||
.draft-label { font-size: 12px; color: #63675f; }
|
||||
main { padding: 0 42px; max-width: 1900px; margin: auto; }
|
||||
.intro { display: flex; justify-content: space-between; align-items: end; padding: 48px 0 34px; gap: 30px; }
|
||||
.eyebrow { font-size: 10px; font-weight: 700; letter-spacing: 1.8px; }
|
||||
h1 { font-size: clamp(34px, 4vw, 60px); line-height: 1.1; letter-spacing: -2.8px; font-weight: 550; margin: 16px 0; }
|
||||
.intro p { color: #62665d; font-size: 14px; line-height: 1.7; margin: 0; }
|
||||
.intro-note { border-left: 1px solid #c6c8bd; padding-left: 24px; min-width: 250px; }
|
||||
.intro-note > span { font-size: 38px; letter-spacing: -2px; }
|
||||
.intro-note p { font-size: 12px; margin-top: 10px; }
|
||||
.review-bar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; align-items: center; padding: 16px 0; border-top: 1px solid #d5d6ce; border-bottom: 1px solid #d5d6ce; }
|
||||
.screen-switch { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||
.review-button { border: 0; padding: 11px 14px; background: transparent; border-radius: 7px; font-size: 12px; color: #62665d; min-height: 42px; }
|
||||
.review-button.selected { background: #292d27; color: white; }
|
||||
.review-options { display: flex; flex-wrap: wrap; align-items: center; gap: 18px; font-size: 12px; color: #62665d; }
|
||||
.review-options label { display: flex; align-items: center; gap: 6px; }
|
||||
.review-options select { padding: 8px; border: 1px solid #d5d6ce; border-radius: 7px; background: transparent; color: #242622; }
|
||||
.compare-link { display: none; }
|
||||
.gallery { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px; padding: 30px 0 36px; align-items: start; }
|
||||
.concept { min-width: 0; }
|
||||
.concept-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
|
||||
.concept-number { font-size: 11px; border: 1px solid #c9cdc2; border-radius: 50%; width: 27px; height: 27px; display: grid; place-items: center; }
|
||||
.concept-heading h2 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -.5px; }
|
||||
.open-concept { margin-left: auto; padding: 10px; text-decoration: none; font-size: 18px; }
|
||||
.concept-description { font-size: 12px; line-height: 1.6; color: #6b7065; min-height: 40px; margin: 0 0 18px; }
|
||||
.phone { --bg: #111212; --surface: #1c1d1d; --text: #f3f3f1; --muted: #a0a2a0; --line: #2c2d2d; --accent: #f3f3f1; --on-accent: #161717; --soft: #252727; position: relative; display: flex; flex-direction: column; height: 760px; width: 100%; max-width: 410px; margin: auto; color: var(--text); background: var(--bg); border: 1px solid #bfc2b8; border-radius: 32px; overflow: hidden; box-shadow: 0 14px 35px #252d2210; font-size: 14px; line-height: 1.45; isolation: isolate; }
|
||||
.phone[data-theme="warm"] { --bg: #faf7f0; --surface: #fffdf8; --text: #302c25; --muted: #7b7264; --line: #e6dfd1; --accent: #93511e; --on-accent: #fffaf3; --soft: #efe6d6; }
|
||||
.phone[data-theme="night"] { --bg: #101b20; --surface: #17272d; --text: #e8f2f1; --muted: #98adaf; --line: #2a3b40; --accent: #94e1ce; --on-accent: #102c27; --soft: #213b3a; }
|
||||
.phone[data-theme="club"] { --bg: #f9fafb; --surface: #fff; --text: #202b3c; --muted: #6b7688; --line: #e2e7ee; --accent: #4c5caa; --on-accent: #fff; --soft: #eaeefa; }
|
||||
.status-bar { display: flex; justify-content: space-between; padding: 15px 24px 6px; font-size: 11px; font-weight: 700; flex: 0 0 38px; }
|
||||
.status-icons { display: flex; gap: 5px; align-items: center; font-size: 10px; }
|
||||
.icon { height: 21px; width: 21px; display: inline-block; vertical-align: middle; flex-shrink: 0; }
|
||||
.status-icons .icon { height: 16px; width: 16px; }
|
||||
.phone button { color: inherit; }
|
||||
.icon-btn { background: transparent; border: 0; width: 44px; height: 44px; flex: 0 0 44px; display: inline-grid; place-items: center; border-radius: 50%; padding: 0; }
|
||||
.icon-btn:hover { background: var(--soft); }
|
||||
.app-header { display: flex; align-items: center; padding: 4px 12px 10px; gap: 6px; min-height: 66px; border-bottom: 1px solid var(--line); }
|
||||
.header-text { flex: 1; min-width: 0; }
|
||||
.header-text h3 { font-size: 17px; letter-spacing: -.4px; margin: 0; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.header-text small { color: var(--muted); font-size: 10px; }
|
||||
.list-header { padding-left: 22px; }
|
||||
.list-header h3 { font-size: 25px; letter-spacing: -.9px; }
|
||||
.mini-brand { color: var(--accent); font-size: 26px; line-height: 1; margin-right: 3px; }
|
||||
.view { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; overscroll-behavior: contain; }
|
||||
.search-field { margin: 15px 18px 10px; display: flex; gap: 9px; align-items: center; background: var(--surface); border-radius: 12px; padding: 0 12px; border: 1px solid var(--line); color: var(--muted); }
|
||||
.search-field input { width: 100%; min-width: 0; border: 0; background: transparent; height: 42px; outline-offset: 0; color: var(--text); font-size: 13px; }
|
||||
.search-field input::placeholder { color: var(--muted); }
|
||||
.filter-tabs { display: flex; padding: 0 18px 12px; gap: 7px; }
|
||||
.filter { font-size: 11px; padding: 0 11px; min-height: 36px; background: transparent; border: 1px solid transparent; border-radius: 20px; color: var(--muted); }
|
||||
.filter[aria-pressed="true"] { color: var(--text); background: var(--soft); }
|
||||
.section-label { padding: 10px 20px 7px; display: flex; justify-content: space-between; text-transform: uppercase; letter-spacing: 1.3px; font-size: 9px; font-weight: 700; color: var(--muted); }
|
||||
.channel-row { display: flex; width: 100%; align-items: center; gap: 12px; padding: 17px 18px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
|
||||
.channel-row:hover { background: var(--soft); }
|
||||
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #bdc5a8; color: #283124; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; font-size: 13px; font-weight: 650; letter-spacing: -.5px; }
|
||||
.avatar.city { background: #ded3bb; color: #635039; }
|
||||
.avatar.blue { background: #bac5d9; color: #354663; }
|
||||
.avatar.rose { background: #d9bcbb; color: #704444; }
|
||||
.avatar.green { background: #b9cdc0; color: #345747; }
|
||||
.avatar.violet { background: #cbc2d9; color: #56476c; }
|
||||
.avatar.self { background: var(--soft); color: var(--accent); }
|
||||
.channel-row .avatar { width: 48px; height: 48px; font-size: 23px; }
|
||||
.channel-copy { min-width: 0; flex: 1; }
|
||||
.channel-copy strong { display: block; font-size: 14px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.channel-copy small { display: block; color: var(--muted); font-size: 10px; margin: 2px 0; }
|
||||
.channel-copy p { margin: 3px 0 0; font-size: 12px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
||||
.channel-tail { display: flex; align-items: end; flex-direction: column; gap: 11px; align-self: stretch; padding-top: 2px; color: var(--muted); font-size: 10px; }
|
||||
.badge { min-width: 20px; height: 20px; background: var(--accent); color: var(--on-accent); padding: 2px 6px; border-radius: 10px; text-align: center; font-size: 10px; font-weight: 700; }
|
||||
.list-tip { padding: 24px 24px 16px; color: var(--muted); font-size: 11px; text-align: center; }
|
||||
.bottom-nav { border-top: 1px solid var(--line); display: flex; justify-content: space-around; flex: 0 0 73px; align-items: start; padding: 9px 6px 12px; background: var(--bg); }
|
||||
.nav-item { border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 8px; width: 20%; min-height: 44px; opacity: .65; }
|
||||
.nav-item[aria-current="page"] { opacity: 1; color: var(--accent); }
|
||||
.nav-item[aria-current="page"] .icon { background: var(--soft); border-radius: 7px; box-shadow: 0 0 0 5px var(--soft); }
|
||||
.channel-intro { margin: 0; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
|
||||
.channel-intro p { margin: 0 0 12px; color: var(--muted); font-size: 12px; line-height: 1.6; }
|
||||
.channel-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||||
.text-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; padding: 0 4px; min-height: 36px; background: transparent; color: var(--accent); font-size: 11px; font-weight: 600; }
|
||||
.text-button .icon { width: 16px; height: 16px; }
|
||||
.pill { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 11px; font-size: 10px; min-height: 36px; }
|
||||
.unread-line { display: flex; align-items: center; gap: 10px; color: var(--accent); font-size: 9px; padding: 13px 20px 0; }
|
||||
.unread-line::before, .unread-line::after { content: ""; height: 1px; flex: 1; background: var(--line); }
|
||||
.post { padding: 18px 18px 10px; border-bottom: 1px solid var(--line); }
|
||||
.post-header { display: flex; align-items: center; gap: 9px; }
|
||||
.post-header .avatar { width: 34px; height: 34px; font-size: 11px; }
|
||||
.author { min-width: 0; flex: 1; font-size: 12px; }
|
||||
.author strong { font-weight: 650; }
|
||||
.author small { color: var(--muted); font-size: 10px; display: block; }
|
||||
.post .more { width: 36px; height: 36px; flex-basis: 36px; color: var(--muted); }
|
||||
.post p { font-size: 14px; line-height: 1.6; margin: 10px 0 12px; overflow-wrap: anywhere; }
|
||||
.post-title { font-weight: 600; }
|
||||
.landscape { height: 142px; overflow: hidden; border-radius: 12px; position: relative; background: #c9d6cf; margin: 10px 0 8px; }
|
||||
.landscape svg { width: 100%; height: 100%; display: block; }
|
||||
.media-caption { position: absolute; bottom: 10px; left: 12px; font-size: 9px; letter-spacing: 1px; color: #fff; text-transform: uppercase; }
|
||||
.post-actions { display: flex; gap: 14px; align-items: center; color: var(--muted); }
|
||||
.action { border: 0; background: transparent; min-height: 44px; display: flex; align-items: center; gap: 6px; padding: 0 2px; font-size: 11px; color: var(--muted); }
|
||||
.action[aria-pressed="true"] { color: #dc7477; }
|
||||
.action[aria-pressed="true"] .icon { fill: currentColor; }
|
||||
.reply-link { margin-left: auto; font-size: 10px; }
|
||||
.attachment { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px; margin: 10px 0; }
|
||||
.attachment > .icon { color: var(--accent); }
|
||||
.attachment strong { font-size: 11px; display: block; }
|
||||
.attachment small { color: var(--muted); display: block; font-size: 10px; }
|
||||
.composer-bar { display: flex; align-items: center; padding: 10px 16px; gap: 10px; border-top: 1px solid var(--line); background: var(--bg); flex: 0 0 auto; }
|
||||
.composer-trigger { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 46px; padding: 10px 14px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 24px; text-align: left; font-size: 12px; }
|
||||
.composer-trigger.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; justify-content: center; font-weight: 650; }
|
||||
.thread-heading { padding: 13px 20px; display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; border-bottom: 1px solid var(--line); }
|
||||
.thread-heading strong { color: var(--text); }
|
||||
.reply { display: flex; padding: 16px 18px 0; gap: 10px; }
|
||||
.reply-body { flex: 1; min-width: 0; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
|
||||
.reply .avatar { width: 32px; height: 32px; font-size: 10px; }
|
||||
.reply p { font-size: 13px; margin: 6px 0 2px; line-height: 1.55; overflow-wrap: anywhere; }
|
||||
.reply small { color: var(--muted); font-size: 10px; }
|
||||
.reply strong { font-size: 12px; }
|
||||
.reply .post-actions { gap: 16px; }
|
||||
.reply-context { color: var(--accent); font-size: 10px; }
|
||||
.empty { padding: 40px 25px; text-align: center; color: var(--muted); font-size: 13px; }
|
||||
.overlay { position: absolute; inset: 38px 0 0; z-index: 5; background: #0009; display: flex; flex-direction: column; justify-content: end; }
|
||||
.sheet { display: flex; flex-direction: column; background: var(--bg); max-height: 100%; min-height: 78%; border-radius: 24px 24px 0 0; overflow: hidden; box-shadow: 0 -8px 40px #0002; }
|
||||
.sheet.full { height: 100%; border-radius: 0; }
|
||||
.sheet-handle { width: 32px; height: 4px; border-radius: 4px; background: var(--line); align-self: center; margin-top: 9px; }
|
||||
.sheet-header { display: flex; align-items: center; padding: 7px 12px; border-bottom: 1px solid var(--line); gap: 6px; }
|
||||
.sheet-header h4 { margin: 0; flex: 1; text-align: center; font-size: 15px; }
|
||||
.sheet-header .expand { color: var(--muted); }
|
||||
.editor-scroll { overflow-y: auto; flex: 1; min-height: 0; padding: 18px; }
|
||||
.source-preview { display: flex; gap: 10px; padding-bottom: 20px; position: relative; }
|
||||
.source-preview::after { content: ""; position: absolute; left: 19px; top: 46px; bottom: 3px; width: 1px; background: var(--line); }
|
||||
.source-preview p { font-size: 12px; color: var(--muted); margin: 5px 0; line-height: 1.5; }
|
||||
.source-preview strong { font-size: 12px; }
|
||||
.source-preview small { color: var(--muted); font-size: 10px; }
|
||||
.editor-row { display: flex; gap: 10px; }
|
||||
.editor-main { flex: 1; min-width: 0; }
|
||||
.editor-main strong { display: block; font-size: 12px; margin: 2px 0; }
|
||||
.editor-main > small { color: var(--muted); display: block; font-size: 10px; margin: 3px 0 10px; }
|
||||
.editor-input { resize: none; border: 0; width: 100%; min-height: 115px; background: transparent; color: var(--text); font-size: 15px; line-height: 1.6; padding: 3px 0; }
|
||||
.editor-input::placeholder { color: var(--muted); }
|
||||
.editor-input:focus-visible { outline: none; box-shadow: 0 2px 0 var(--accent); }
|
||||
.editor-footer { display: flex; align-items: center; gap: 4px; padding: 11px 16px 16px; border-top: 1px solid var(--line); background: var(--bg); }
|
||||
.char-count { color: var(--muted); font-size: 10px; margin-left: auto; margin-right: 10px; }
|
||||
.submit { border: 0; border-radius: 22px; padding: 12px 18px; background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 650; min-height: 44px; }
|
||||
.phone .submit { color: var(--on-accent); }
|
||||
.editor-attachment { margin-top: 10px; display: flex; align-items: center; gap: 6px; padding: 4px 8px; background: var(--soft); border-radius: 10px; font-size: 10px; }
|
||||
.editor-attachment span { flex: 1; overflow-wrap: anywhere; }
|
||||
.keyboard { flex: 0 0 auto; background: var(--surface); padding: 10px 4px 18px; border-top: 1px solid var(--line); }
|
||||
.keyboard-label { font-size: 9px; text-align: center; color: var(--muted); margin-bottom: 10px; }
|
||||
.keys { display: flex; justify-content: center; gap: 3px; margin: 5px 0; }
|
||||
.keys span { display: grid; place-items: center; height: 31px; flex: 1; max-width: 29px; border-radius: 5px; font-size: 13px; color: var(--text); background: var(--soft); box-shadow: 0 1px 0 #0003; }
|
||||
.keys .space { max-width: 150px; flex: 5; font-size: 10px; }
|
||||
.keys .wide { max-width: 45px; flex: 1.7; font-size: 11px; }
|
||||
.menu-sheet { min-height: 0; padding-bottom: 24px; }
|
||||
.menu-content { padding: 10px 20px; }
|
||||
.menu-action { border: 0; background: transparent; width: 100%; text-align: left; display: flex; gap: 12px; align-items: center; min-height: 47px; font-size: 13px; border-bottom: 1px solid var(--line); }
|
||||
.menu-content p { color: var(--muted); font-size: 12px; line-height: 1.6; }
|
||||
.toast { position: absolute; bottom: 86px; left: 18px; right: 18px; padding: 12px 15px; border-radius: 12px; background: var(--text); color: var(--bg); z-index: 10; font-size: 12px; box-shadow: 0 4px 20px #0003; }
|
||||
.concept-notes { margin-top: 19px; font-size: 12px; color: #666d61; line-height: 1.65; }
|
||||
.concept-notes strong { color: #33392f; font-weight: 600; }
|
||||
.swatches { display: flex; gap: 5px; margin-bottom: 12px; }
|
||||
.swatches span { width: 19px; height: 19px; border-radius: 50%; border: 1px solid #0002; }
|
||||
.concept-tag { display: inline-block; border: 1px solid #c9cdc2; padding: 3px 7px; border-radius: 4px; font-size: 9px; letter-spacing: .3px; margin-bottom: 8px; }
|
||||
.decision-note { padding: 36px 0; border-top: 1px solid #d5d6ce; }
|
||||
.decision-note h2 { font-weight: 500; letter-spacing: -.7px; font-size: 27px; margin: 13px 0; }
|
||||
.decision-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 38px; }
|
||||
.decision-grid p { font-size: 13px; line-height: 1.7; color: #62665d; }
|
||||
.decision-grid b { display: block; font-weight: 600; color: #33392f; margin-bottom: 6px; }
|
||||
.disclaimer { font-size: 11px; color: #62665d; line-height: 1.7; margin-top: 24px; }
|
||||
.studio-footer { display: flex; justify-content: space-between; margin: 0 42px; padding: 22px 0; border-top: 1px solid #d5d6ce; color: #73796b; font-size: 10px; gap: 15px; }
|
||||
/* Варианты отличаются также плотностью, иерархией и формой редактора. */
|
||||
.phone[data-theme="mono"] .post { padding-left: 18px; }
|
||||
.phone[data-theme="mono"] .post-content { margin-left: 43px; }
|
||||
.phone[data-theme="mono"] .landscape { height: 128px; }
|
||||
.phone[data-theme="warm"] .channel-row { margin: 0 12px 8px; width: calc(100% - 24px); border: 1px solid var(--line); border-radius: 16px; padding: 14px 12px; background: var(--surface); }
|
||||
.phone[data-theme="warm"] .channel-intro { background: var(--soft); margin: 14px 16px 0; border: 0; border-radius: 16px; }
|
||||
.phone[data-theme="warm"] .post { margin: 14px 12px; padding: 15px 14px 7px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
|
||||
.phone[data-theme="warm"] .post-title { font-family: Georgia, serif; font-size: 20px; line-height: 1.3; }
|
||||
.phone[data-theme="warm"] .reply .avatar { border-radius: 12px; }
|
||||
.phone[data-theme="night"] .list-header { border-bottom: 0; padding-top: 12px; }
|
||||
.phone[data-theme="night"] .channel-intro { background: linear-gradient(125deg, #1d3937, #16272e); border-bottom: 1px solid #36544f; }
|
||||
.phone[data-theme="night"] .channel-row { border-bottom-color: #21343b; }
|
||||
.phone[data-theme="night"] .channel-row:first-child { background: #172b2e; box-shadow: inset 3px 0 var(--accent); }
|
||||
.phone[data-theme="night"] .composer-trigger { border-radius: 13px; }
|
||||
.phone[data-theme="night"] .post-title { font-size: 17px; font-weight: 550; }
|
||||
.phone[data-theme="club"] .channel-row { padding: 12px 16px; gap: 10px; }
|
||||
.phone[data-theme="club"] .channel-row .avatar { width: 42px; height: 42px; border-radius: 13px; }
|
||||
.phone[data-theme="club"] .channel-copy small { display: none; }
|
||||
.phone[data-theme="club"] .filter-tabs { border-bottom: 1px solid var(--line); padding-bottom: 0; gap: 12px; }
|
||||
.phone[data-theme="club"] .filter { border-radius: 0; padding: 0 1px; }
|
||||
.phone[data-theme="club"] .filter[aria-pressed="true"] { background: transparent; color: var(--accent); border-bottom: 2px solid var(--accent); }
|
||||
.phone[data-theme="club"] .post { padding: 12px 16px 5px; }
|
||||
.phone[data-theme="club"] .post p { font-size: 13px; margin: 7px 0; }
|
||||
.phone[data-theme="club"] .landscape { height: 108px; }
|
||||
.phone[data-theme="club"] .channel-intro { padding: 12px 16px 8px; }
|
||||
.phone[data-theme="club"] .channel-intro p { margin-bottom: 5px; }
|
||||
.phone[data-theme="club"] .reply { padding-top: 12px; }
|
||||
.phone[data-theme="club"] .reply-body { border-left: 2px solid var(--line); border-bottom: 0; padding-left: 12px; }
|
||||
.phone[data-theme="club"] .composer-trigger { border-radius: 10px; }
|
||||
.gallery.single { display: block; max-width: 410px; margin: auto; }
|
||||
.single .concept-description { min-height: 0; }
|
||||
body.focused .compare-link { display: inline; }
|
||||
@media (max-width: 1490px) { .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 900px; margin: auto; gap: 40px; } .concept { max-width: 410px; width: 100%; justify-self: center; } }
|
||||
@media (max-width: 760px) { .studio-header { margin: 0 20px; padding: 18px 0; } main { padding: 0 20px; } .brand-caption, .draft-label, .intro-note { display: none; } .intro { padding: 30px 0 24px; } h1 { letter-spacing: -1.5px; } .intro p { font-size: 13px; } .gallery { grid-template-columns: minmax(0, 1fr); gap: 32px; } .screen-switch { display: grid; grid-template-columns: 1fr 1fr; width: 100%; } .review-button { padding: 10px; } .review-options { gap: 12px; } .phone { height: 760px; border-radius: 25px; } .decision-grid { grid-template-columns: 1fr; gap: 0; } .studio-footer { margin: 0 20px; } }
|
||||
@media (max-width: 380px) { main { padding: 0 10px; } .post-actions { gap: 10px; } .phone { font-size: 13px; } .channel-row { padding-left: 12px; padding-right: 12px; gap: 8px; } .header-text h3 { font-size: 15px; } .concept-heading h2 { font-size: 16px; } }
|
||||
@media (prefers-reduced-motion: no-preference) { .sheet { animation: appear .18s ease-out; } @keyframes appear { from { transform: translateY(22px); opacity: .5; } to { transform: translateY(0); opacity: 1; } } }
|
||||
@@ -0,0 +1,246 @@
|
||||
/* Изолированный прототип: без API, импортов приложения и постоянного хранилища. */
|
||||
'use strict';
|
||||
const icons = {
|
||||
back: '<path d="m14 5-7 7 7 7M7 12h14"/>',
|
||||
close: '<path d="m6 6 12 12M6 18 18 6"/>',
|
||||
more: '<circle cx="5" cy="12" r="1"/><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/>',
|
||||
search: '<circle cx="10.5" cy="10.5" r="6.5"/><path d="m16 16 4 4"/>',
|
||||
plus: '<path d="M12 5v14M5 12h14"/>',
|
||||
heart: '<path d="M20.8 4.8a5.5 5.5 0 0 0-7.8 0L12 6l-1.1-1.2a5.5 5.5 0 0 0-7.8 7.8L12 21l8.8-8.4a5.5 5.5 0 0 0 0-7.8Z"/>',
|
||||
chat: '<path d="M21 11.5a9 9 0 0 1-9 9 9.7 9.7 0 0 1-4-.9L3 21l1.4-4.7A9 9 0 1 1 21 11.5Z"/>',
|
||||
share: '<path d="m21 3-7 18-4-8-8-3 19-7ZM10 13 21 3"/>',
|
||||
channels: '<rect x="3" y="4" width="18" height="13" rx="3"/><path d="m8 21 4-4 4 4M7 8h10M7 12h6"/>',
|
||||
people: '<circle cx="9" cy="8" r="3"/><path d="M3 20v-2a6 6 0 0 1 12 0v2M16 5a3 3 0 0 1 0 6M18 14a5 5 0 0 1 3 5"/>',
|
||||
bell: '<path d="M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9M10 21h4"/>',
|
||||
user: '<circle cx="12" cy="7" r="4"/><path d="M4 21v-2a8 8 0 0 1 16 0v2"/>',
|
||||
book: '<path d="M12 5v16M3 4c4-1 6-1 9 1 3-2 5-2 9-1v15c-4-1-6-1-9 2-3-3-5-3-9-2Z"/>',
|
||||
file: '<path d="M14 2H5v20h14V7l-5-5ZM14 2v6h5M8 13h8M8 17h5"/>',
|
||||
attach: '<path d="m9 17 9-9a3 3 0 0 0-4-4L4 14a5 5 0 0 0 7 7L21 11M7 14l8-8"/>',
|
||||
image: '<rect x="3" y="3" width="18" height="18" rx="4"/><circle cx="8" cy="8" r="1"/><path d="m3 17 6-6 4 4 3-3 5 5"/>',
|
||||
expand: '<path d="M14 3h7v7M21 3l-7 7M10 21H3v-7M3 21l7-7"/>',
|
||||
check: '<path d="m5 12 4 4L19 6"/>',
|
||||
edit: '<path d="m15 4 5 5M4 20l5-1L21 7a2 2 0 0 0-4-4L5 15l-1 5Z"/>',
|
||||
wifi: '<path d="M3 8a15 15 0 0 1 18 0M6 12a10 10 0 0 1 12 0M9 16a5 5 0 0 1 6 0M12 20h.01"/>',
|
||||
battery: '<rect x="2" y="6" width="18" height="12" rx="2"/><path d="M23 10v4M5 9h11v6H5Z"/>',
|
||||
};
|
||||
const icon = name => `<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${icons[name] || icons.chat}</svg>`;
|
||||
const escapeText = value => String(value).replace(/[&<>"']/g, c => ({'&':'&', '<':'<', '>':'>', '"':'"', "'":'''}[c]));
|
||||
const button = (action, label, name, extra = '') => `<button class="icon-btn" data-action="${action}" aria-label="${label}" title="${label}" ${extra}>${icon(name)}</button>`;
|
||||
const concepts = [
|
||||
{ id:'mono', number:'01', title:'Чистый монохром', description:'Контент на первом плане. Знакомый ритм Threads.', colors:['#111212','#2c2d2d','#f3f3f1'], tag:'МАКСИМАЛЬНО ПРИВЫЧНО', note:'Плоская лента, аватар на полях и полноэкранный ответ. <strong>Самая нейтральная отправная точка.</strong>' },
|
||||
{ id:'warm', number:'02', title:'Тёплый SHiNE', description:'Бумажные оттенки. Больше воздуха и мягкости.', colors:['#faf7f0','#efe6d6','#93511e'], tag:'МЯГКИЙ И ЛИЧНЫЙ', note:'Карточки отделяют разговоры, тёплый акцент выделяет действия. Ответ открывается <strong>округлым листом снизу.</strong>' },
|
||||
{ id:'night', number:'03', title:'Ночной SHiNE', description:'Глубокий синий. Спокойный свет в деталях.', colors:['#101b20','#213b3a','#94e1ce'], tag:'ХАРАКТЕР SHiNE', note:'Широкий текст и выразительная шапка канала. <strong>Мой кандидат на развитие:</strong> узнаваемый, но сдержанный.' },
|
||||
{ id:'club', number:'04', title:'Компактный клуб', description:'Больше разговоров на одном экране.', colors:['#f9fafb','#eaeefa','#4c5caa'], tag:'ПЛОТНО И СОБРАННО', note:'Компактные строки, подчёркнутые вкладки и линии ответов. Редактор <strong>на весь экран</strong>, без потери контекста.' },
|
||||
];
|
||||
const channels = [
|
||||
{ title:'Город и люди', owner:'anna', slug:'city', symbol:'⌂', color:'city', preview:'Маленькие открытия по дороге домой', time:'12 мин', unread:3, following:true },
|
||||
{ title:'Дизайн каждый день', owner:'mikhail', slug:'design', symbol:'Aa', color:'blue', preview:'Как сделать сложное простым?', time:'38 мин', unread:7, following:true },
|
||||
{ title:'Тихие маршруты', owner:'lena', slug:'walks', symbol:'↗', color:'green', preview:'Сохранили маршрут на выходные', time:'1 ч', unread:2, following:true },
|
||||
{ title:'Книжная полка', owner:'olga', slug:'books', symbol:'≋', color:'rose', preview:'Что сейчас читаете?', time:'2 ч', unread:0, following:true },
|
||||
{ title:'SHiNE · новости', owner:'shine', slug:'news', symbol:'✳', color:'violet', preview:'Место, где начинаются разговоры', time:'вчера', unread:0, following:false },
|
||||
{ title:'Мои заметки', owner:'you', slug:'notes', symbol:'✎', color:'blue', preview:'Идея для следующей встречи', time:'вчера', unread:0, following:false },
|
||||
];
|
||||
let role = 'reader';
|
||||
let showKeyboard = false;
|
||||
const states = new Map();
|
||||
const mainText = 'Иногда лучший маршрут – чуть длиннее обычного. Сегодня свернула к реке и нашла это место. А где вы перезагружаетесь после рабочего дня?';
|
||||
const secondText = 'Собрала наши любимые места в один список. Добавляйте свои находки в ответах!';
|
||||
const landscape = () => `<div class="landscape" role="img" aria-label="Иллюстрация: тихая река, холмы и солнце"><svg viewBox="0 0 400 180" preserveAspectRatio="xMidYMid slice"><rect width="400" height="180" fill="#cad8d0"/><circle cx="290" cy="46" r="24" fill="#f5e7b5"/><path d="M0 87Q65 35 136 79T270 70T400 61V180H0" fill="#8faaa0"/><path d="M0 125Q73 67 155 102T310 86T400 101V180H0" fill="#527b70"/><path d="M0 153Q98 104 184 130T400 110V180H0" fill="#31594f"/><path d="M216 100Q105 130 236 145T201 180H311Q347 151 239 137T242 101Z" fill="#c2d2ba"/><path d="M32 138V59m0 4-15 30h30ZM361 129V47m0 4-18 34h36Z" fill="#30534a" stroke="#30534a" stroke-width="4"/></svg><span class="media-caption">У реки / 18:42</span></div>`;
|
||||
function header(s) {
|
||||
if (s.screen === 'list') return `<header class="app-header list-header"><span class="mini-brand">✳</span><div class="header-text"><h3>Каналы</h3></div>${button('new-channel','Создать канал','plus')}</header>`;
|
||||
return `<header class="app-header">${button('back','Назад','back')}<div class="header-text"><h3>${s.screen === 'thread' ? 'Обсуждение' : escapeText(s.channel.title)}</h3><small>${s.screen === 'thread' ? escapeText(s.channel.title) : '@'+escapeText(s.channel.owner)+' / '+escapeText(s.channel.slug)}</small></div>${button('notifications',s.muted ? 'Включить уведомления' : 'Настроить уведомления','bell')}${button('channel-menu','Меню канала','more')}</header>`;
|
||||
}
|
||||
function nav() {
|
||||
return `<nav class="bottom-nav" aria-label="Разделы приложения">${[['chat','Личные'],['channels','Каналы'],['people','Связи'],['bell','Уведомления'],['user','Профиль']].map(([i,label])=>`<button class="nav-item" data-action="${i==='channels'?'list':'outside'}" ${i==='channels'?'aria-current="page"':''}>${icon(i)}<span>${label}</span></button>`).join('')}</nav>`;
|
||||
}
|
||||
function rows(s) {
|
||||
const filtered = channels.filter(c => (s.filter!=='mine'||c.owner==='you') && (s.filter!=='following'||c.following) && `${c.title} ${c.owner}`.toLowerCase().includes(s.query.toLowerCase()));
|
||||
return filtered.length ? filtered.map(c=>`<button class="channel-row" data-action="open-channel" data-index="${channels.indexOf(c)}"><span class="avatar ${c.color}">${c.symbol}</span><span class="channel-copy"><strong>${c.title}</strong><small>@${c.owner} / ${c.slug}</small><p>${c.preview}</p></span><span class="channel-tail"><span>${c.time}</span>${c.unread?`<span class="badge" aria-label="${c.unread} непрочитанных">${c.unread}</span>`:''}</span></button>`).join('') : '<p class="empty">Каналы не найдены.<br>Попробуйте другое название или логин.</p>';
|
||||
}
|
||||
function list(s) {
|
||||
return `<label class="search-field">${icon('search')}<input data-search aria-label="Поиск каналов" placeholder="Название или @автор" value="${escapeText(s.query)}"></label><div class="filter-tabs" role="group" aria-label="Фильтр каналов">${[['all','Все'],['following','Подписки'],['mine','Мои']].map(([value,label])=>`<button class="filter" data-action="filter" data-value="${value}" aria-pressed="${s.filter===value}">${label}</button>`).join('')}</div><div class="section-label"><span>${s.filter==='mine'?'Ваши каналы':'Ваше пространство'}</span><span>SHiNE</span></div><div class="channel-rows">${rows(s)}</div><p class="list-tip">Хорошие разговоры начинаются<br>с общих интересов.</p>`;
|
||||
}
|
||||
function actions(s, id, count, replies) {
|
||||
const liked = s.likes.has(id);
|
||||
replies = 2 + s.replies.filter(reply => reply.post === id).length;
|
||||
return `<div class="post-actions"><button class="action" data-action="like" data-post="${id}" aria-label="Нравится" aria-pressed="${liked}">${icon('heart')}<span>${count+(liked?1:0)}</span></button><button class="action" data-action="thread" data-post="${id}" aria-label="Открыть ${replies} ответов">${icon('chat')}<span>${replies}</span></button><button class="action" data-action="share" aria-label="Поделиться">${icon('share')}</button><button class="action reply-link" data-action="reply" data-post="${id}">Ответить</button></div>`;
|
||||
}
|
||||
function post(s, second = false) {
|
||||
return `<article class="post"><div class="post-header"><span class="avatar city">АК</span><div class="author"><strong>${escapeText(s.channel.owner==='anna'?'Анна К.':s.channel.owner)}</strong><small>${second?'вчера, 19:10':'12 минут назад'}</small></div><button class="icon-btn more" data-action="post-menu" aria-label="Действия с сообщением">${icon('more')}</button></div><div class="post-content">${second?'<p>Собрала наши любимые места в один список. Добавляйте свои находки в ответах!</p><div class="attachment">'+icon('file')+'<div><strong>Места для прогулок.pdf</strong><small>PDF · 552 КБ</small></div></div>':`<p class="post-title">Маленькие открытия</p><p>${mainText}</p>${landscape()}`}${actions(s, second?'second':'first',second?12:24, second?3:2+s.replies.length)}</div></article>`;
|
||||
}
|
||||
function feed(s) {
|
||||
return `<section class="channel-intro"><p>Замечаем красоту рядом. Делимся местами,<br>историями и маленькими открытиями.</p><div class="channel-tools"><button class="text-button" data-action="contents">${icon('book')} Оглавление</button><button class="pill" data-action="subscribe">${s.subscribed?'Вы подписаны':'Подписаться'}</button></div></section><div class="unread-line">Новые сообщения</div>${post(s)}${post(s,true)}`;
|
||||
}
|
||||
function replyRow(name, initials, color, text, target='') {
|
||||
return `<article class="reply"><span class="avatar ${color}">${initials}</span><div class="reply-body">${target?`<div class="reply-context">В ответ ${escapeText(target)}</div>`:''}<strong>${escapeText(name)}</strong> <small>· сейчас</small><p>${escapeText(text)}</p><div class="post-actions"><button class="action" data-action="reply-to" data-author="${escapeText(name)}" data-text="${escapeText(text)}">${icon('chat')} Ответить</button></div></div></article>`;
|
||||
}
|
||||
function thread(s) {
|
||||
const replies=s.replies.filter(r=>r.post===s.activePost);
|
||||
const second=s.activePost==='second';
|
||||
return `${post(s,second)}<div class="thread-heading"><strong>Ответы · ${2+replies.length}</strong><span>По порядку</span></div>${replyRow('Михаил','МЛ','blue',second?'Спасибо за список! Добавлю ещё парк у старого моста.':'У воды всегда легче выдохнуть. Это возле старого моста?')}${replyRow('Лена','ЛС','green',second?'В выходные попробую один из маршрутов.':'А я ухожу гулять без наушников. Город звучит совсем иначе.')}${replies.map(r=>replyRow('Вы','ВЫ','self',r.text,r.target)).join('')}`;
|
||||
}
|
||||
function composer(s) {
|
||||
if (s.screen==='list') return '';
|
||||
if (s.screen==='feed' && role==='reader') return '';
|
||||
return `<div class="composer-bar"><button class="composer-trigger ${s.screen==='feed'?'primary':''}" data-action="${s.screen==='feed'?'new-post':'reply'}"><span>${s.screen==='feed'?'Написать в канал':'Ответить '+s.channel.owner+'…'}</span>${icon(s.screen==='feed'?'plus':'edit')}</button></div>`;
|
||||
}
|
||||
function render(s) {
|
||||
const previousView = s.phone.querySelector('.view');
|
||||
s.scrolls ||= {};
|
||||
if (previousView && s.renderedScreen) s.scrolls[s.renderedScreen] = previousView.scrollTop;
|
||||
s.phone.innerHTML = `<div class="status-bar"><span>9:41</span><span class="status-icons">${icon('wifi')}${icon('battery')}</span></div>${header(s)}<div class="view">${s.screen==='list'?list(s):s.screen==='feed'?feed(s):thread(s)}</div>${composer(s)}${nav()}`;
|
||||
if(s.screen==='feed') for(const text of s.posts) {
|
||||
const item=document.createElement('article'); item.className='post';
|
||||
const author=document.createElement('strong'); author.textContent='Вы · сейчас';
|
||||
const body=document.createElement('p'); body.textContent=text; item.append(author,body);
|
||||
s.phone.querySelector('.view').append(item);
|
||||
}
|
||||
s.phone.querySelector('.view').scrollTop = s.scrolls[s.screen] || 0;
|
||||
s.renderedScreen = s.screen;
|
||||
if (s.editor) mountEditor(s);
|
||||
}
|
||||
function keyboard() {
|
||||
return `<div class="keyboard" aria-hidden="true"><div class="keyboard-label">Макет клавиатуры · не интерактивный</div>${['йцукенгшщзх','фывапролджэ','ячсмитьбю'].map(row=>`<div class="keys">${[...row].map(c=>`<span>${c}</span>`).join('')}</div>`).join('')}<div class="keys"><span class="wide">123</span><span class="space">Русский</span><span class="wide">↵</span></div></div>`;
|
||||
}
|
||||
function mountEditor(s) {
|
||||
const mode = s.editor;
|
||||
const full = s.id==='mono'||s.id==='club'||s.expanded;
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'overlay';
|
||||
overlay.innerHTML = `<section class="sheet ${full?'full':''}" role="dialog" aria-modal="true" aria-label="${mode==='post'?'Новое сообщение':'Ответ на сообщение'}" tabindex="-1">${full?'':'<div class="sheet-handle"></div>'}<div class="sheet-header">${button('close-editor','Закрыть и сохранить черновик','close')}<h4>${mode==='post'?'Новое сообщение':'Ответ'}</h4>${button('expand','Развернуть или свернуть редактор','expand','aria-pressed="'+full+'"')}</div><div class="editor-scroll">${mode==='post'?'':`<div class="source-preview"><span class="avatar city">${s.replyTo===s.channel.owner?'АК':escapeText(s.replyTo.slice(0,2).toUpperCase())}</span><div><strong>${escapeText(s.replyTo)}</strong><small> · ${escapeText(s.channel.title)}</small><p>${escapeText(s.replyText)}</p></div></div>`}<div class="editor-row"><span class="avatar self">ВЫ</span><div class="editor-main"><strong>Вы</strong><small>${mode==='post'?'Публикация в «'+escapeText(s.channel.title)+'»':'Ответ '+escapeText(s.replyTo)+' · виден в обсуждении'}</small><textarea class="editor-input" maxlength="2000" aria-label="Текст ${mode==='post'?'сообщения':'ответа'}" placeholder="${mode==='post'?'О чём хотите рассказать?':'Продолжите разговор…'}">${escapeText(s.drafts[mode])}</textarea><div class="selected-attachment">${attachmentMarkup(s)}</div></div></div></div><div class="editor-footer">${button('attach','Прикрепить файл','attach')}<input type="file" hidden data-file><span class="char-count">${s.drafts[mode].length} / 2000</span><button class="submit" data-action="send" ${!s.drafts[mode].trim()&&!s.attachments[mode]?'disabled':''}>${mode==='post'?'Опубликовать':'Ответить'}</button></div>${showKeyboard?keyboard():''}</section>`;
|
||||
s.phone.querySelectorAll(':scope > *').forEach(el=>el.inert=true);
|
||||
s.phone.append(overlay);
|
||||
overlay.querySelector('.sheet').focus({preventScroll:true});
|
||||
}
|
||||
function attachmentMarkup(s) {
|
||||
const name = s.attachments[s.editor];
|
||||
return name?`<div class="editor-attachment">${icon('file')}<span>${escapeText(name)}</span>${button('remove-attachment','Удалить вложение','close')}</div>`:'';
|
||||
}
|
||||
function removeOverlay(s) {
|
||||
s.phone.querySelector('.overlay')?.remove();
|
||||
s.phone.querySelectorAll(':scope > *').forEach(el=>el.inert=false);
|
||||
}
|
||||
function closeEditor(s) {
|
||||
s.editor = null;
|
||||
removeOverlay(s);
|
||||
if (s.returnFocus?.isConnected) s.returnFocus.focus({preventScroll:true});
|
||||
else s.phone.querySelector('[data-action="reply"], [data-action="new-post"], [data-action="back"]')?.focus({preventScroll:true});
|
||||
}
|
||||
function openEditor(s, mode='reply', author=s.channel.owner, text=s.activePost==='second'?secondText:mainText, trigger=null) {
|
||||
if (s.editor) closeEditor(s);
|
||||
s.editor=mode;
|
||||
s.replyTo=author;
|
||||
s.replyText=text;
|
||||
s.returnFocus=trigger;
|
||||
s.expanded=false;
|
||||
mountEditor(s);
|
||||
}
|
||||
function toast(s, message) {
|
||||
s.phone.querySelector('.toast')?.remove();
|
||||
clearTimeout(s.toastTimer);
|
||||
const el=document.createElement('div');
|
||||
el.className='toast'; el.setAttribute('role','status'); el.textContent=message;
|
||||
s.phone.append(el);
|
||||
s.toastTimer=setTimeout(()=>el.remove(),3500);
|
||||
}
|
||||
function menu(s, title, contents, trigger) {
|
||||
removeOverlay(s);
|
||||
s.returnFocus=trigger;
|
||||
const el=document.createElement('div'); el.className='overlay';
|
||||
el.innerHTML=`<section class="sheet menu-sheet" role="dialog" aria-modal="true" aria-label="${escapeText(title)}" tabindex="-1"><div class="sheet-handle"></div><div class="sheet-header">${button('close-menu','Закрыть','close')}<h4>${escapeText(title)}</h4><span style="width:44px"></span></div><div class="menu-content">${contents}</div></section>`;
|
||||
s.phone.querySelectorAll(':scope > *').forEach(child=>child.inert=true);
|
||||
s.phone.append(el); el.querySelector('.sheet').focus({preventScroll:true});
|
||||
}
|
||||
const menuAction=(action,label,i='file')=>`<button class="menu-action" data-action="${action}">${icon(i)}${label}</button>`;
|
||||
function updateEditor(s) {
|
||||
const modal=s.phone.querySelector('.overlay');
|
||||
modal.querySelector('.char-count').textContent=`${s.drafts[s.editor].length} / 2000`;
|
||||
modal.querySelector('[data-action="send"]').disabled=!s.drafts[s.editor].trim()&&!s.attachments[s.editor];
|
||||
modal.querySelector('.selected-attachment').innerHTML=attachmentMarkup(s);
|
||||
}
|
||||
function handle(s, event) {
|
||||
const el=event.target.closest('[data-action]');
|
||||
if (!el || el.disabled) return;
|
||||
const action=el.dataset.action;
|
||||
if (action==='filter') { s.filter=el.dataset.value; render(s); }
|
||||
else if (action==='open-channel') { s.channel=channels[Number(el.dataset.index)]; s.screen='feed'; s.activePost='first'; s.replies=[]; s.posts=[]; s.likes.clear(); render(s); }
|
||||
else if (action==='list'||action==='back') { s.screen=action==='list'||s.screen==='feed'?'list':'feed'; render(s); }
|
||||
else if (action==='thread') { s.activePost=el.dataset.post||s.activePost; s.screen='thread'; render(s); }
|
||||
else if (action==='reply'||action==='new-post') { s.activePost=el.dataset.post||s.activePost; openEditor(s,action==='new-post'?'post':'reply',s.channel.owner,s.activePost==='second'?secondText:mainText,el); }
|
||||
else if (action==='reply-to') openEditor(s,'reply',el.dataset.author,el.dataset.text,el);
|
||||
else if (action==='close-editor') { closeEditor(s); toast(s,'Черновик сохранён до закрытия страницы'); }
|
||||
else if (action==='expand') { s.expanded=!s.expanded; removeOverlay(s); mountEditor(s); }
|
||||
else if (action==='attach') s.phone.querySelector('[data-file]').click();
|
||||
else if (action==='remove-attachment') { s.attachments[s.editor]=''; updateEditor(s); }
|
||||
else if (action==='send') {
|
||||
const mode=s.editor;
|
||||
const text=s.drafts[mode].trim();
|
||||
const attachment=s.attachments[mode];
|
||||
if (!text&&!attachment) return;
|
||||
if (mode==='reply') s.replies.push({text:text+(attachment?'\n📎 '+attachment:''),target:s.replyTo,post:s.activePost});
|
||||
else s.posts.push(text+(attachment?'\n📎 '+attachment:''));
|
||||
s.drafts[mode]=''; s.attachments[mode]=''; s.editor=null; s.screen=mode==='reply'?'thread':'feed'; render(s);
|
||||
const view=s.phone.querySelector('.view'); view.scrollTop=view.scrollHeight;
|
||||
s.phone.querySelector('.composer-trigger')?.focus({preventScroll:true}); toast(s,'Отправлено в макете. Данные на сервер не передаются.');
|
||||
}
|
||||
else if (action==='like') {
|
||||
const key=el.dataset.post; const liked=s.likes.has(key); liked?s.likes.delete(key):s.likes.add(key);
|
||||
el.setAttribute('aria-pressed',String(!liked)); el.querySelector('span').textContent=String(Number(el.querySelector('span').textContent)+(liked?-1:1));
|
||||
}
|
||||
else if (action==='share') menu(s,'Поделиться', '<p>В приложении здесь появится системное меню отправки ссылки. В макете внешние ссылки не создаются.</p>'+menuAction('close-menu','Понятно','check'),el);
|
||||
else if (action==='subscribe') { s.subscribed=!s.subscribed; el.textContent=s.subscribed?'Вы подписаны':'Подписаться'; }
|
||||
else if (action==='notifications') { s.muted=!s.muted; el.setAttribute('aria-label',s.muted?'Включить уведомления':'Настроить уведомления'); toast(s,s.muted?'Уведомления канала выключены в макете':'Уведомления канала включены в макете'); }
|
||||
else if (action==='post-menu') menu(s,'Сообщение',menuAction('reactions','Кто поставил лайк','heart')+menuAction('details','Данные записи','file')+(role==='owner'?menuAction('edit-demo','Редактировать','edit'):'')+'<p>Редкие действия собраны здесь, чтобы оставлять больше места самому сообщению.</p>',el);
|
||||
else if (action==='channel-menu') menu(s,s.channel.title,menuAction('about','О канале','channels')+menuAction('contents','Оглавление','book')+menuAction('notifications','Уведомления','bell'),el);
|
||||
else if (action==='contents') menu(s,'Оглавление','<p>С чего начать знакомство с каналом</p>'+menuAction('jump-post','01 · Маленькие открытия','book')+menuAction('jump-file','02 · Наш список любимых мест','file'),el);
|
||||
else if (action==='jump-post'||action==='jump-file') { removeOverlay(s); s.screen='feed'; render(s); s.phone.querySelectorAll('.post')[action==='jump-file'?1:0]?.scrollIntoView({block:'nearest'}); }
|
||||
else if (action==='reactions') menu(s,'Лайки','<p>Все: 24 · основные: 18 · сияющие: 6</p><p>Названия категорий сохранены из текущего приложения. Их объяснение пользователю нужно согласовать отдельно.</p>',el);
|
||||
else if (action==='details') menu(s,'Данные записи','<p>Здесь доступны номер записи, цепочка автора, хэш и подпись. В мокапе технические данные не генерируются.</p>',el);
|
||||
else if (action==='about') menu(s,'О канале','<p>Замечаем красоту рядом. Делимся местами, историями и маленькими открытиями.</p><p>Автор: @'+escapeText(s.channel.owner)+'</p>',el);
|
||||
else if (action==='close-menu') { removeOverlay(s); if(s.returnFocus?.isConnected)s.returnFocus.focus({preventScroll:true}); }
|
||||
else if (action==='new-channel') toast(s,'Создание канала – следующий этап проектирования');
|
||||
else if (action==='edit-demo') toast(s,'Редактор существующего сообщения – следующий этап');
|
||||
else if (action==='outside') toast(s,'Сейчас проектируем каналы. Этот раздел пока вне макета.');
|
||||
}
|
||||
function attachEvents(s) {
|
||||
s.phone.addEventListener('click',event=>handle(s,event));
|
||||
s.phone.addEventListener('input',event=>{
|
||||
if(event.target.matches('[data-search]')) { s.query=event.target.value; s.phone.querySelector('.channel-rows').innerHTML=rows(s); }
|
||||
if(event.target.matches('.editor-input')) { s.drafts[s.editor]=event.target.value; updateEditor(s); }
|
||||
});
|
||||
s.phone.addEventListener('change',event=>{
|
||||
if(event.target.matches('[data-file]')) { s.attachments[s.editor]=event.target.files[0]?.name||''; updateEditor(s); }
|
||||
});
|
||||
s.phone.addEventListener('keydown',event=>{
|
||||
const dialog=s.phone.querySelector('[role="dialog"]');
|
||||
if(!dialog) return;
|
||||
if(event.key==='Escape') { event.preventDefault(); s.editor?closeEditor(s):removeOverlay(s); if(s.returnFocus?.isConnected)s.returnFocus.focus({preventScroll:true}); }
|
||||
if(event.key==='Tab') {
|
||||
const focusable=[...dialog.querySelectorAll('button:not(:disabled), textarea, input:not([hidden])')];
|
||||
const first=focusable[0], last=focusable.at(-1);
|
||||
if(event.shiftKey&&(document.activeElement===first||document.activeElement===dialog)) { event.preventDefault(); last?.focus(); }
|
||||
else if(!event.shiftKey&&(document.activeElement===last||document.activeElement===dialog)) { event.preventDefault(); first?.focus(); }
|
||||
}
|
||||
});
|
||||
}
|
||||
function init() {
|
||||
const query=new URLSearchParams(location.search);
|
||||
const chosen=concepts.find(c=>c.id===query.get('variant'));
|
||||
const gallery=document.getElementById('gallery');
|
||||
if(chosen) {gallery.classList.add('single');document.body.classList.add('focused');}
|
||||
for(const c of chosen?[chosen]:concepts) {
|
||||
const article=document.createElement('section');article.className='concept';article.setAttribute('aria-label',c.title);
|
||||
article.innerHTML=`<div class="concept-heading"><span class="concept-number">${c.number}</span><h2>${c.title}</h2><a class="open-concept" href="?variant=${c.id}" aria-label="Открыть отдельно: ${c.title}">↗</a></div><p class="concept-description">${c.description}</p><div class="phone" data-theme="${c.id}" aria-label="Макет: ${c.title}"></div><div class="concept-notes"><div class="swatches" aria-hidden="true">${c.colors.map(color=>`<span style="background:${color}"></span>`).join('')}</div><span class="concept-tag">${c.tag}</span><div>${c.note}</div></div>`;
|
||||
gallery.append(article);
|
||||
const s={id:c.id,phone:article.querySelector('.phone'),screen:'list',activePost:'first',channel:channels[0],query:'',filter:'all',likes:new Set(),subscribed:true,muted:false,replies:[],posts:[],drafts:{reply:'',post:''},attachments:{reply:'',post:''},editor:null};
|
||||
states.set(c.id,s);render(s);attachEvents(s);
|
||||
}
|
||||
document.querySelectorAll('[data-screen]').forEach(el=>el.addEventListener('click',()=>{
|
||||
document.querySelectorAll('[data-screen]').forEach(b=>{b.classList.toggle('selected',b===el);b.setAttribute('aria-pressed',String(b===el));});
|
||||
for(const s of states.values()) { s.editor=null;s.screen=el.dataset.screen==='reply'?'thread':el.dataset.screen;render(s);if(el.dataset.screen==='reply')openEditor(s); }
|
||||
el.focus({preventScroll:true});
|
||||
}));
|
||||
document.getElementById('role').addEventListener('change',event=>{role=event.target.value;for(const s of states.values())render(s);});
|
||||
document.getElementById('keyboard').addEventListener('change',event=>{showKeyboard=event.target.checked;for(const s of states.values())if(s.editor){removeOverlay(s);mountEditor(s);}event.target.focus({preventScroll:true});});
|
||||
}
|
||||
init();
|
||||
@@ -0,0 +1,98 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>SHiNE static sites</title>
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--bg: #f4f1ec;
|
||||
--panel: #fffaf3;
|
||||
--ink: #171512;
|
||||
--muted: #6f675e;
|
||||
--line: rgba(52, 44, 35, 0.14);
|
||||
--accent: #087a68;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
font-family: Inter, "Segoe UI", system-ui, sans-serif;
|
||||
}
|
||||
|
||||
main {
|
||||
width: min(920px, calc(100% - 32px));
|
||||
margin: 0 auto;
|
||||
padding: 44px 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0 0 10px;
|
||||
font-size: clamp(30px, 5vw, 52px);
|
||||
line-height: 1;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.list {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin-top: 28px;
|
||||
}
|
||||
|
||||
a {
|
||||
display: block;
|
||||
padding: 18px 20px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
background: var(--panel);
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
border-color: rgba(8, 122, 104, 0.45);
|
||||
}
|
||||
|
||||
strong {
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
span {
|
||||
color: var(--muted);
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>SHiNE static sites</h1>
|
||||
<p>Рабочая папка для временных статических сайтов, дизайн-примеров и standalone-viewer'ов.</p>
|
||||
|
||||
<div class="list">
|
||||
<a href="./design-examples/channels-v1/">
|
||||
<strong>Channels design v1</strong>
|
||||
<span>Дизайн-пример экранов каналов.</span>
|
||||
</a>
|
||||
<a href="./arweave-viewer/">
|
||||
<strong>Arweave viewer</strong>
|
||||
<span>Постоянная папка для текущей версии SHiNE Arweave Viewer.</span>
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user