Replace default leaves with precipitation and procedural snowdrifts
This commit is contained in:
1 parent
2c17a52b5e
commit
c85876f1db
13 files changed
+329
-83
No files matched your search
+6
-2
@@ -109,8 +109,8 @@
|
||||
<link rel="stylesheet" href="/api/weather/effect.css">
|
||||
<script src="/api/weather/effect.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="leaf-field" aria-hidden="true"><span class="leaf"></span><span class="leaf"></span><span class="leaf"></span><span class="leaf"></span><span class="leaf"></span><span class="leaf"></span><span class="leaf"></span></div>
|
||||
<body class="weather-page">
|
||||
<div class="weather-field" aria-hidden="true"></div>
|
||||
<main>
|
||||
<section id="authView" class="auth-view">
|
||||
<h1>Админская панель</h1>
|
||||
@@ -165,6 +165,10 @@
|
||||
<p class="error" id="vkError" role="alert"></p><div class="table-wrap"><table><thead><tr><th>Беседа</th><th>Статус</th><th>Рассылка</th><th>Добавлена</th><th>Последняя отправка</th><th>Ошибка</th></tr></thead><tbody id="vkRows"><tr><td class="empty" colspan="6">Загрузка…</td></tr></tbody></table></div>
|
||||
</section>
|
||||
</section>
|
||||
<footer class="snow-footer">Беличья нора
|
||||
<div class="snow-cover-caption"><a class="snow-cover-source" href="https://climate-energy.ru/weather/spravochnik/sndp/climate_sprav-sndp_260630687.php" target="_blank" rel="noopener noreferrer" hidden></a></div>
|
||||
<div class="footer-snowdrift" aria-hidden="true"></div>
|
||||
</footer>
|
||||
</main>
|
||||
|
||||
<dialog id="galleryDialog" aria-label="Скриншоты отчёта">
|
||||
|
||||
+6
-3
@@ -101,8 +101,8 @@
|
||||
<link rel="stylesheet" href="/api/weather/effect.css">
|
||||
<script src="/api/weather/effect.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="leaf-field" aria-hidden="true"><span class="leaf"></span><span class="leaf"></span><span class="leaf"></span><span class="leaf"></span><span class="leaf"></span><span class="leaf"></span><span class="leaf"></span></div>
|
||||
<body class="weather-page">
|
||||
<div class="weather-field" aria-hidden="true"></div>
|
||||
<main>
|
||||
<h1>Генератор отчётов и калькулятор</h1>
|
||||
<p class="muted">Здесь можно подготовить отчёт, посчитать баллы и подать заявку.</p>
|
||||
@@ -290,7 +290,10 @@
|
||||
<div id="renameIdentitySuccess" class="success hidden" role="status" aria-live="polite"></div>
|
||||
</div>
|
||||
</section>
|
||||
<footer class="site-footer">Proudly made by Nyan404 | <a href="https://git.nyan404.ru/nyan404/cwshed-clone">GitLab Page</a></footer>
|
||||
<footer class="site-footer snow-footer">Proudly made by Nyan404 | <a href="https://git.nyan404.ru/nyan404/cwshed-clone">GitLab Page</a>
|
||||
<div class="snow-cover-caption"><a class="snow-cover-source" href="https://climate-energy.ru/weather/spravochnik/sndp/climate_sprav-sndp_260630687.php" target="_blank" rel="noopener noreferrer" hidden></a></div>
|
||||
<div class="footer-snowdrift" aria-hidden="true"></div>
|
||||
</footer>
|
||||
</main>
|
||||
<dialog id="identityDialog" aria-label="Уточнить имя или ID кота" aria-describedby="identityDialogText">
|
||||
<p id="identityDialogText" role="status"></p>
|
||||
|
||||
+37
-31
@@ -1,5 +1,5 @@
|
||||
/* Shared by calculator and admin. Keep all particles below interactive content. */
|
||||
.leaf-field {
|
||||
/* Shared precipitation layer; no decorative particles without reported precipitation. */
|
||||
.weather-field {
|
||||
--rain: #69849a;
|
||||
--snow: #fffefa;
|
||||
--snow-edge: #aab9c5;
|
||||
@@ -9,50 +9,28 @@
|
||||
pointer-events: none;
|
||||
z-index: 0;
|
||||
}
|
||||
.leaf {
|
||||
.weather-particle {
|
||||
position: absolute;
|
||||
top: -3rem;
|
||||
width: 1.1rem;
|
||||
height: 1.65rem;
|
||||
border-radius: 100% 0 100% 0;
|
||||
background: var(--leaf, var(--accent));
|
||||
box-shadow: inset .18rem -.12rem 0 #8e431d;
|
||||
opacity: .68;
|
||||
animation: leaf-fall var(--duration, 15s) linear infinite;
|
||||
animation: snow-fall var(--duration, 12s) linear infinite;
|
||||
}
|
||||
.leaf:nth-child(2n) { background: var(--gold); width: .82rem; height: 1.3rem; --duration: 19s; }
|
||||
.leaf:nth-child(3n) { background: #a84e22; width: 1.35rem; height: 1.85rem; --duration: 22s; }
|
||||
.leaf:nth-child(1) { left: 7%; animation-delay: -4s; }
|
||||
.leaf:nth-child(2) { left: 18%; animation-delay: -12s; }
|
||||
.leaf:nth-child(3) { left: 32%; animation-delay: -7s; }
|
||||
.leaf:nth-child(4) { left: 49%; animation-delay: -16s; }
|
||||
.leaf:nth-child(5) { left: 64%; animation-delay: -2s; }
|
||||
.leaf:nth-child(6) { left: 78%; animation-delay: -10s; }
|
||||
.leaf:nth-child(7) { left: 91%; animation-delay: -18s; }
|
||||
.leaf[data-kind="snow"] {
|
||||
.weather-particle[data-kind="snow"] {
|
||||
width: calc(.45rem * var(--size));
|
||||
height: calc(.45rem * var(--size));
|
||||
border-radius: 50%;
|
||||
background: var(--snow);
|
||||
box-shadow: 0 0 2px var(--snow-edge);
|
||||
opacity: .85;
|
||||
animation-name: snow-fall;
|
||||
}
|
||||
.leaf[data-kind="rain"] {
|
||||
.weather-particle[data-kind="rain"] {
|
||||
width: 1.5px;
|
||||
height: calc(1.6rem * var(--size));
|
||||
border-radius: 2px;
|
||||
background: var(--rain);
|
||||
box-shadow: none;
|
||||
opacity: .4;
|
||||
animation-name: rain-fall;
|
||||
}
|
||||
.weather-paused .leaf { animation-play-state: paused; }
|
||||
@keyframes leaf-fall {
|
||||
0% { transform: translate3d(0, -4rem, 0) rotate(20deg); }
|
||||
45% { transform: translate3d(calc(3.5rem + var(--drift, 0vw) * .45), 48vh, 0) rotate(170deg); }
|
||||
100% { transform: translate3d(calc(-4rem + var(--drift, 0vw)), 112vh, 0) rotate(330deg); }
|
||||
}
|
||||
.weather-paused .weather-particle { animation-play-state: paused; }
|
||||
@keyframes snow-fall {
|
||||
0% { transform: translate3d(0, -4rem, 0); }
|
||||
50% { transform: translate3d(calc(2rem + var(--drift, 0vw) * .5), 50vh, 0); }
|
||||
@@ -62,7 +40,35 @@
|
||||
from { transform: translate3d(0, -4rem, 0) rotate(calc(-1 * var(--rain-angle, 0deg))); }
|
||||
to { transform: translate3d(var(--drift, 0vw), 112vh, 0) rotate(calc(-1 * var(--rain-angle, 0deg))); }
|
||||
}
|
||||
.snow-footer {
|
||||
--snow-shade: #e8eef0;
|
||||
--snow-ridge: #f4f7f7;
|
||||
--snow-front: #fffefa;
|
||||
margin-top: 48px;
|
||||
padding-top: 18px;
|
||||
border-top: 1px solid var(--line);
|
||||
color: var(--muted);
|
||||
font-size: .9rem;
|
||||
}
|
||||
.snow-footer a { color: inherit; text-underline-offset: 3px; }
|
||||
.snow-footer a:hover { color: var(--accent); }
|
||||
.snow-footer a:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
|
||||
.snow-cover-caption { min-height: 24px; margin-top: 8px; font-size: .8rem; line-height: 1.5; }
|
||||
.footer-snowdrift {
|
||||
height: var(--snow-height, 0px);
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
pointer-events: none;
|
||||
}
|
||||
.footer-snowdrift svg { display: block; width: 100%; height: 100%; }
|
||||
.snow-bank-shade { fill: var(--snow-shade); }
|
||||
.snow-bank-ridge { fill: none; stroke: var(--snow-ridge); stroke-width: 2; stroke-linecap: round; }
|
||||
.weather-page main { margin-bottom: 0; padding-bottom: 0; }
|
||||
.snow-bank-front { fill: var(--snow-front); }
|
||||
@media (max-width: 600px) {
|
||||
.snow-footer { margin-top: 32px; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.leaf-field .leaf { animation: none; top: 8vh; opacity: .16; }
|
||||
.leaf:nth-child(n+8) { display: none; }
|
||||
.weather-field .weather-particle { animation: none; top: 8vh; opacity: .16; }
|
||||
.weather-particle:nth-child(n+8) { display: none; }
|
||||
}
|
||||
+110
-37
@@ -1,23 +1,71 @@
|
||||
/* A little Pulkovo weather in the existing autumn background. */
|
||||
/* Pulkovo precipitation and Saint Petersburg snow cover, quietly in the background. */
|
||||
(() => {
|
||||
'use strict';
|
||||
const field = document.querySelector('.leaf-field');
|
||||
const field = document.querySelector('.weather-field');
|
||||
if (!field) return;
|
||||
const refreshMs = 5 * 60 * 1000;
|
||||
let timer;
|
||||
let controller;
|
||||
let nextRefresh = 0;
|
||||
const snowdrift = document.querySelector('.footer-snowdrift');
|
||||
const snowSource = document.querySelector('.snow-cover-source');
|
||||
let lastSignature = '';
|
||||
|
||||
function buildSnowdrifts() {
|
||||
if (!snowdrift) return;
|
||||
const ns = 'http://www.w3.org/2000/svg';
|
||||
const svg = document.createElementNS(ns, 'svg');
|
||||
svg.setAttribute('viewBox', '0 0 1200 160');
|
||||
svg.setAttribute('preserveAspectRatio', 'none');
|
||||
svg.setAttribute('focusable', 'false');
|
||||
const random = (min, max) => min + Math.random() * (max - min);
|
||||
const weights = Array.from({ length: Math.random() < 0.6 ? 2 : 3 }, () => random(0.7, 1.5));
|
||||
const total = weights.reduce((sum, weight) => sum + weight, 0);
|
||||
// One profile per page load. The gentle windward slope rises to a cornice;
|
||||
// a shorter, steeper lee face falls back to the next valley.
|
||||
let x = 0;
|
||||
let y = random(126, 138);
|
||||
let outline = `M0 ${y}`;
|
||||
let shadows = '';
|
||||
let ridges = '';
|
||||
for (const weight of weights) {
|
||||
const width = weight / total * 1200;
|
||||
const end = x + width;
|
||||
const crest = x + width * random(0.54, 0.7);
|
||||
const peak = random(18, 65);
|
||||
const nextY = random(124, 139);
|
||||
const shoulder = x + width * random(0.33, 0.43);
|
||||
const shoulderY = peak + (y - peak) * random(0.12, 0.23);
|
||||
const lee = crest + (end - crest) * random(0.25, 0.42);
|
||||
const leeY = peak + (nextY - peak) * random(0.65, 0.82);
|
||||
outline += ` C${x + width * 0.22} ${y} ${shoulder - width * 0.08} ${shoulderY + 9} ${shoulder} ${shoulderY}`;
|
||||
outline += ` C${crest - width * 0.09} ${peak + 9} ${crest - width * 0.025} ${peak + 4} ${crest} ${peak}`;
|
||||
outline += ` C${crest + width * 0.05} ${peak + 6} ${lee - width * 0.035} ${leeY - 8} ${lee} ${leeY}`;
|
||||
outline += ` C${lee + width * 0.09} ${nextY - 2} ${end - width * 0.1} ${nextY} ${end} ${nextY}`;
|
||||
shadows += ` M${crest} ${peak} C${crest + width * 0.02} ${peak + 18} ${lee - width * 0.06} ${leeY + 2} ${lee} ${leeY + 5}`;
|
||||
shadows += ` Q${lee + width * 0.1} ${nextY + 1} ${end} ${nextY} C${lee + width * 0.09} ${nextY - 2} ${lee} ${leeY} ${crest} ${peak}Z`;
|
||||
ridges += ` M${x + width * 0.18} ${y - 4} Q${shoulder} ${shoulderY - 2} ${crest} ${peak + 4}`;
|
||||
x = end;
|
||||
y = nextY;
|
||||
}
|
||||
for (const [className, path] of [
|
||||
['snow-bank-front', `${outline} V160 H0Z`],
|
||||
['snow-bank-shade', shadows],
|
||||
['snow-bank-ridge', ridges],
|
||||
]) {
|
||||
const shape = document.createElementNS(ns, 'path');
|
||||
shape.setAttribute('class', className);
|
||||
shape.setAttribute('d', path);
|
||||
svg.append(shape);
|
||||
}
|
||||
snowdrift.replaceChildren(svg);
|
||||
}
|
||||
|
||||
function render(weather) {
|
||||
const mode = ['leaves', 'rain', 'snow', 'mixed'].includes(weather.mode) ? weather.mode : 'leaves';
|
||||
const mode = ['rain', 'snow', 'mixed'].includes(weather?.mode) ? weather.mode : 'none';
|
||||
const intensity = Math.max(1, Math.min(3, Number(weather.intensity) || 1));
|
||||
const wind = Math.max(0, Math.min(60, Number(weather.wind_mps) || 0));
|
||||
const signature = `${mode}/${intensity}/${wind}`;
|
||||
if (signature === lastSignature) return;
|
||||
lastSignature = signature;
|
||||
const count = mode === 'leaves' ? 7 : [0, 18, 34, 54][Math.round(intensity)];
|
||||
const duration = (mode === 'rain' ? 1.7 : mode === 'leaves' ? 19 : 12) / (1 + Math.min(wind, 25) / 8);
|
||||
const count = mode === 'none' ? 0 : [0, 18, 34, 54][Math.round(intensity)];
|
||||
const duration = (mode === 'rain' ? 1.7 : 12) / (1 + Math.min(wind, 25) / 8);
|
||||
field.dataset.weather = mode;
|
||||
field.style.setProperty('--drift', `${Math.min(24, wind * 1.2)}vw`);
|
||||
field.style.setProperty('--rain-angle', `${Math.min(30, wind * 1.8)}deg`);
|
||||
@@ -25,7 +73,7 @@
|
||||
for (let index = 0; index < count; index++) {
|
||||
const particle = document.createElement('span');
|
||||
const kind = mode === 'mixed' ? (index % 2 ? 'rain' : 'snow') : mode;
|
||||
particle.className = 'leaf';
|
||||
particle.className = 'weather-particle';
|
||||
particle.dataset.kind = kind;
|
||||
const seconds = (kind === 'rain' && mode === 'mixed' ? duration / 6 : duration) * (0.8 + Math.random() * 0.5);
|
||||
particle.style.left = `${(index + Math.random()) * 100 / count}%`;
|
||||
@@ -37,37 +85,62 @@
|
||||
field.replaceChildren(particles);
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
clearTimeout(timer);
|
||||
if (document.hidden || controller) return;
|
||||
if (Date.now() < nextRefresh) {
|
||||
timer = setTimeout(refresh, nextRefresh - Date.now());
|
||||
return;
|
||||
}
|
||||
controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller?.abort(), 5000);
|
||||
try {
|
||||
const response = await fetch('/api/weather/ulli', { signal: controller.signal, credentials: 'omit', cache: 'no-store' });
|
||||
if (!response.ok) throw new Error('weather unavailable');
|
||||
render(await response.json());
|
||||
} catch {
|
||||
render({ mode: 'leaves', intensity: 1, wind_mps: 0 });
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
controller = null;
|
||||
nextRefresh = Date.now() + refreshMs;
|
||||
if (!document.hidden) timer = setTimeout(refresh, refreshMs);
|
||||
function renderSnowCover(cover) {
|
||||
if (!snowdrift || !snowSource) return;
|
||||
const depth = cover?.depth_cm;
|
||||
const stamp = cover?.observed_on;
|
||||
const available = cover?.available === true && typeof depth === 'number' && Number.isFinite(depth)
|
||||
&& depth >= 0 && depth <= 500 && /^\d{4}-\d{2}-\d{2}$/.test(stamp);
|
||||
snowSource.hidden = !available;
|
||||
snowdrift.dataset.depth = available ? String(depth) : '';
|
||||
// A visual scale, not centimetres rendered 1:1; keep the footer usable in deep snow.
|
||||
snowdrift.style.setProperty('--snow-height', available && depth > 0 ? `${Math.min(144, 20 + Math.sqrt(depth) * 20)}px` : '0px');
|
||||
if (available) {
|
||||
const [year, month, day] = stamp.split('-');
|
||||
snowSource.textContent = `Снежный покров: ${depth.toLocaleString('ru-RU')} см · ${day}.${month}.${year}`;
|
||||
} else {
|
||||
snowSource.textContent = '';
|
||||
}
|
||||
}
|
||||
|
||||
function poll(url, interval, update, fallback) {
|
||||
let timer;
|
||||
let controller;
|
||||
let nextRefresh = 0;
|
||||
async function refresh() {
|
||||
clearTimeout(timer);
|
||||
if (document.hidden || controller) return;
|
||||
if (Date.now() < nextRefresh) {
|
||||
timer = setTimeout(refresh, nextRefresh - Date.now());
|
||||
return;
|
||||
}
|
||||
controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller?.abort(), 6000);
|
||||
try {
|
||||
const response = await fetch(url, { signal: controller.signal, credentials: 'omit', cache: 'no-store' });
|
||||
if (!response.ok) throw new Error('weather unavailable');
|
||||
update(await response.json());
|
||||
} catch {
|
||||
if (!document.hidden) update(fallback);
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
controller = null;
|
||||
nextRefresh = document.hidden ? 0 : Date.now() + interval;
|
||||
if (!document.hidden) timer = setTimeout(refresh, interval);
|
||||
}
|
||||
}
|
||||
return {
|
||||
refresh,
|
||||
pause() { clearTimeout(timer); controller?.abort(); },
|
||||
};
|
||||
}
|
||||
|
||||
buildSnowdrifts();
|
||||
const feeds = [poll('/api/weather/ulli', 5 * 60 * 1000, render, { mode: 'none' })];
|
||||
if (snowdrift) feeds.push(poll('/api/weather/snow-cover', 30 * 60 * 1000, renderSnowCover, { available: false }));
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
field.classList.toggle('weather-paused', document.hidden);
|
||||
if (document.hidden) {
|
||||
clearTimeout(timer);
|
||||
controller?.abort();
|
||||
} else {
|
||||
refresh();
|
||||
}
|
||||
for (const feed of feeds) document.hidden ? feed.pause() : feed.refresh();
|
||||
});
|
||||
refresh();
|
||||
for (const feed of feeds) feed.refresh();
|
||||
})();
|
||||
Reference in new issue
Block a user