Dawnline 0.12.0
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
- The portal's traffic charts show what came down and what went up apart. A device's last 7 days and "Data this month" draw each day both ways: downloads rise above a thin line, uploads hang below it, on one scale. Beside them "↓ 3.2 GB ↑ 557 MB" instead of one total; hover a day for its own, its date where "left" stands - Charts answer the pointer between their bars too, in the portal and in the admin's daily charts (a device's week, a device card's 30 days, the last 30 days): the figures no longer blink back to the total - The calendar under "Access until" plays its days in only when the row is opened, not again each time the page refreshes with it open - On a phone the page comes in from the top down: "Your access" first, then the devices - "Show key" on a router's set-up morphs to "Hide key" with its icon, and brings the keys themselves into focus (it blurred the field names)
This commit is contained in:
1 parent
2f2aaf6c34
commit
fb73ac3a9f
33 files changed
+396
-199
No files matched your search
@@ -4,7 +4,7 @@
|
||||
// scenario picker is picker.ts).
|
||||
|
||||
import type { State } from '../state';
|
||||
import type { Device, Kind, Person } from '../../shared/types';
|
||||
import type { Device, Kind, Pair, Person } from '../../shared/types';
|
||||
|
||||
export const GB = 2 ** 30;
|
||||
const HOUR = 3600;
|
||||
@@ -109,8 +109,11 @@ const label = (s: string) =>
|
||||
/** How busy each day of the week is, Monday first. */
|
||||
const WEEK = [0.9, 1.15, 0.8, 1.05, 1.3, 0.75, 1.1];
|
||||
|
||||
/** The month so far, day by day, adding up to `total` bytes (today only partly gone). */
|
||||
export function monthDays(total: number, t: number): number[] {
|
||||
/** A day split into what the devices sent and received: about a tenth sent, more on a day something backed up. */
|
||||
const split = (v: number, sent: number): Pair => [Math.round(v * sent), v - Math.round(v * sent)];
|
||||
|
||||
/** The month so far, day by day as [rx, tx], adding up to `total` bytes (today only partly gone). */
|
||||
export function monthDays(total: number, t: number): Pair[] {
|
||||
const d = new Date(t * 1000);
|
||||
const days = d.getDate();
|
||||
const w = Array.from({ length: days }, (_, i) => {
|
||||
@@ -118,7 +121,7 @@ export function monthDays(total: number, t: number): number[] {
|
||||
return WEEK[wd] * (i === days - 1 ? 0.45 : 1) * (0.85 + ((i * 37) % 11) / 30);
|
||||
});
|
||||
const sum = w.reduce((a, b) => a + b, 0);
|
||||
return w.map((x) => Math.round((x / sum) * total));
|
||||
return w.map((x, i) => split(Math.round((x / sum) * total), i % 11 === 4 ? 0.4 : 0.08 + ((i * 17) % 9) / 100));
|
||||
}
|
||||
|
||||
/** A window of the day that leaves `t` out (the visitor's hours): the hours scenario is outside it. */
|
||||
@@ -149,7 +152,9 @@ function device(d: DemoDevice, t: number, st: Person['state']): Device {
|
||||
active: true,
|
||||
month: [Math.round(month / 8), Math.round((month * 7) / 8)],
|
||||
total: [Math.round(month / 4), Math.round((month * 7) / 4)],
|
||||
spark: [0.8, 1.3, 0.6, 1.1, 1.6, 0.9, 1].map((f) => (hs ? Math.round(((month / 4) * f) / 7) : 0)),
|
||||
spark: [0.8, 1.3, 0.6, 1.1, 1.6, 0.9, 1].map((f, i) =>
|
||||
split(hs ? Math.round(((month / 4) * f) / 7) : 0, [0.1, 0.14, 0.08, 0.35, 0.11, 0.09, 0.12][i]),
|
||||
),
|
||||
hostname: `${label(d.name)}.user.lan`,
|
||||
browser_key: false,
|
||||
config_stale: d.stale,
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
type Store,
|
||||
} from '../setup';
|
||||
import { accordion } from '../ui/accordion';
|
||||
import { copy, download, sendFile, shareFile } from '../ui/feedback';
|
||||
import { copy, download, sendFile, shareFile, swapIcon } from '../ui/feedback';
|
||||
import { glass } from '../ui/glass';
|
||||
import { menuLine, morphText, setText } from '../ui/morph';
|
||||
import { hint } from '../ui/sheet';
|
||||
@@ -206,7 +206,8 @@ function confLine(line: string, reveal: boolean): Node {
|
||||
const m = /^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(line);
|
||||
if (!m) return document.createTextNode(line);
|
||||
const secret = /^(\s*)(PrivateKey|PresharedKey)\b/.test(line);
|
||||
return h('span', {}, h('span', { class: 'k' }, m[1]), ' ', secret && !reveal ? h('span', { class: 'mask' }, '••••••••••••••••') : m[2]);
|
||||
const value = !secret ? m[2] : reveal ? h('span', { class: 'secret' }, m[2]) : h('span', { class: 'mask' }, '••••••••••••••••');
|
||||
return h('span', {}, h('span', { class: 'k' }, m[1]), ' ', value);
|
||||
}
|
||||
|
||||
/** The .conf for a router: a file card to download (or share), and the configuration folded, its keys hidden. */
|
||||
@@ -217,6 +218,8 @@ export function filePane(cfg: ClientConfig): HTMLElement {
|
||||
pre.replaceChildren(...cfg.conf.split('\n').flatMap((l, i) => (i ? ['\n', confLine(l, reveal)] : [confLine(l, reveal)])));
|
||||
paint();
|
||||
const share = !!shareFile(cfg.filename, cfg.conf);
|
||||
let icon = ic('key');
|
||||
const label = h('span', {}, _('Show key'));
|
||||
const eye = h(
|
||||
'button',
|
||||
{
|
||||
@@ -224,10 +227,11 @@ export function filePane(cfg: ClientConfig): HTMLElement {
|
||||
class: 'btn soft sm',
|
||||
onclick: () => {
|
||||
reveal = !reveal;
|
||||
eye.replaceChildren(ic(reveal ? 'x' : 'key'), h('span', {}, reveal ? _('Hide key') : _('Show key')));
|
||||
icon = swapIcon(icon, reveal ? 'x' : 'key');
|
||||
morphText(label, reveal ? _('Hide key') : _('Show key'));
|
||||
paint();
|
||||
// A key shown comes into focus out of a blur; hidden again, the mask fades back.
|
||||
pre.querySelectorAll('.mask, .k').forEach((x) =>
|
||||
pre.querySelectorAll('.mask, .secret').forEach((x) =>
|
||||
play(
|
||||
x,
|
||||
[
|
||||
@@ -239,8 +243,8 @@ export function filePane(cfg: ClientConfig): HTMLElement {
|
||||
);
|
||||
},
|
||||
},
|
||||
ic('key'),
|
||||
h('span', {}, _('Show key')),
|
||||
icon,
|
||||
label,
|
||||
);
|
||||
const cp = h(
|
||||
'button',
|
||||
|
||||
@@ -109,10 +109,6 @@ msgid_plural "%s of %s slots free"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "%s on %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "%s options"
|
||||
msgstr ""
|
||||
@@ -121,10 +117,6 @@ msgstr ""
|
||||
msgid "%s this month"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "%s used"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/notices.ts
|
||||
msgid "%s your time"
|
||||
msgstr ""
|
||||
@@ -494,6 +486,10 @@ msgstr ""
|
||||
msgid "Download the key"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/ui/bars.ts
|
||||
msgid "Downloaded"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "End date must be YYYY-MM-DD."
|
||||
msgstr ""
|
||||
@@ -1208,6 +1204,10 @@ msgstr ""
|
||||
msgid "Update the connection"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/ui/bars.ts
|
||||
msgid "Uploaded"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/wait.ts
|
||||
msgid "Waiting for the connection"
|
||||
msgstr ""
|
||||
|
||||
@@ -114,10 +114,6 @@ msgstr[0] "Свободно %s из %s места"
|
||||
msgstr[1] "Свободно %s из %s мест"
|
||||
msgstr[2] "Свободно %s из %s мест"
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "%s on %s"
|
||||
msgstr "%s за %s"
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "%s options"
|
||||
msgstr "Действия с устройством %s"
|
||||
@@ -126,10 +122,6 @@ msgstr "Действия с устройством %s"
|
||||
msgid "%s this month"
|
||||
msgstr "%s в этом месяце"
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "%s used"
|
||||
msgstr "%s использовано"
|
||||
|
||||
#: web/src/portal/page/notices.ts
|
||||
msgid "%s your time"
|
||||
msgstr "%s по вашему времени"
|
||||
@@ -499,6 +491,10 @@ msgstr "Скачать файл"
|
||||
msgid "Download the key"
|
||||
msgstr "Скачать ключ"
|
||||
|
||||
#: web/src/portal/ui/bars.ts
|
||||
msgid "Downloaded"
|
||||
msgstr "Получено"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "End date must be YYYY-MM-DD."
|
||||
msgstr "Дата окончания должна быть в формате ГГГГ-ММ-ДД."
|
||||
@@ -1213,6 +1209,10 @@ msgstr "Обновить"
|
||||
msgid "Update the connection"
|
||||
msgstr "Обновить подключение"
|
||||
|
||||
#: web/src/portal/ui/bars.ts
|
||||
msgid "Uploaded"
|
||||
msgstr "Отправлено"
|
||||
|
||||
#: web/src/portal/flows/wait.ts
|
||||
msgid "Waiting for the connection"
|
||||
msgstr "Ждём подключения"
|
||||
|
||||
@@ -33,7 +33,11 @@ let redraw: () => void = () => {};
|
||||
|
||||
/** The first paint comes in: the blocks rise one after the other, the sun rises behind its line. */
|
||||
function intro() {
|
||||
const els = [...app.querySelectorAll('.crumbs, .notice, .sec-head, .dgrid > *, .note-s:not([hidden]), .acc-slot .acc-row, .gone')];
|
||||
// In the order they stand on screen, top to bottom and then left to right: on a phone "Your access" comes before the devices.
|
||||
const els = [...app.querySelectorAll('.crumbs, .notice, .sec-head, .dgrid > *, .note-s:not([hidden]), .acc-slot .acc-row, .gone')]
|
||||
.map((el) => ({ el, at: el.getBoundingClientRect() }))
|
||||
.sort((a, b) => Math.round(a.at.top) - Math.round(b.at.top) || a.at.left - b.at.left)
|
||||
.map((x) => x.el);
|
||||
// Each block rises to its own opacity: a card the admin disabled is dimmed all the way, not at the end.
|
||||
const own = els.map((el) => getComputedStyle(el).opacity);
|
||||
els.forEach((el, i) =>
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
// the month day by day inside; and until when, as the days left over a
|
||||
// calendar of the weeks, with the admin's hours as a bar of the day.
|
||||
|
||||
import type { Person } from '../../shared/types';
|
||||
import type { Pair, Person } from '../../shared/types';
|
||||
import { accessLabel, byDeviceState, bytes, date, daysLeft, endsSoon, parseDay } from '../../shared/format';
|
||||
import { fill, fmt, locale, num, plural } from '../../shared/i18n';
|
||||
import { h, ic, markup } from '../dom';
|
||||
import { calendar, clockOf, hoursFor, minuteAt, monthOf, stretches } from '../days';
|
||||
import { now, today, type State } from '../state';
|
||||
import { accordion, type Accordion } from '../ui/accordion';
|
||||
import { bars, upDown } from '../ui/bars';
|
||||
import { copy } from '../ui/feedback';
|
||||
import { glass } from '../ui/glass';
|
||||
import { morphChanged, setText, textsOf } from '../ui/morph';
|
||||
@@ -93,34 +94,27 @@ function meter(pct: number): HTMLElement {
|
||||
return h('div', { class: 'meter' }, i);
|
||||
}
|
||||
|
||||
/** The month as one bar a day (today in blue, days to come faint), and the total under it. */
|
||||
/** The month a day at a time, down and up (today in blue, days to come flat), what came and went under it. */
|
||||
function month(p: Person, used: number, pct: number): HTMLElement {
|
||||
const { days, day } = monthOf(today());
|
||||
const series = p.month_days ?? [];
|
||||
const max = Math.max(1, ...series);
|
||||
const series = Array.from({ length: day }, (_x, i): Pair => p.month_days?.[i] ?? [0, 0]);
|
||||
const short = (d: number) => dayMonth(`${today().slice(0, 8)}${String(d).padStart(2, '0')}`);
|
||||
// The total, and a bar under the pointer in its place, at once: no morph while the pointer moves.
|
||||
const total = h('b', { class: 'num', 'data-t': 'm-used' }, bytes(used));
|
||||
const read = h('span', { class: 'mread' });
|
||||
/** The month's total, or (`d`) one day's: the number in its sentence. */
|
||||
const say = (v: number, d?: number) => {
|
||||
setText(total, bytes(v));
|
||||
read.replaceChildren(...(d ? fill<Node | string>(_('%s on %s'), total, short(d)) : fill(_('%s used'), total)));
|
||||
// The month's down and up; a day under the pointer puts its own in their place and its date where "left" stands,
|
||||
// at once: no morph while the pointer moves.
|
||||
const read = upDown('m');
|
||||
const left = p.quota_limit ? fmt(_('%s left'), bytes(Math.max(0, p.quota_limit - used))) : _('No limit');
|
||||
const side = h('span', { class: 'num', 'data-t': 'm-left' }, left);
|
||||
const say = (v: Pair, d?: number) => {
|
||||
read.set(v);
|
||||
setText(side, d ? short(d) : left);
|
||||
side.classList.toggle('bad-t', !d && p.state === 'quota');
|
||||
};
|
||||
say(used);
|
||||
const bars = h('div', { class: 'mbars' });
|
||||
for (let i = 0; i < days; i++) {
|
||||
if (i >= day) {
|
||||
bars.appendChild(h('i', { class: 'future' }));
|
||||
continue;
|
||||
}
|
||||
const v = series[i] ?? 0;
|
||||
const b = h('i', { class: i === day - 1 ? 'today' : '' });
|
||||
b.style.height = `${Math.max(3, Math.round((v / max) * 64))}px`;
|
||||
b.addEventListener('pointerenter', () => say(v, i + 1));
|
||||
b.addEventListener('pointerleave', () => say(used));
|
||||
bars.appendChild(b);
|
||||
}
|
||||
say(p.month);
|
||||
const chart = bars(series, 'bars-month', 64, days - day);
|
||||
chart.cols.forEach((col, i) => {
|
||||
col.addEventListener('pointerenter', () => say(series[i], i + 1));
|
||||
col.addEventListener('pointerleave', () => say(p.month));
|
||||
});
|
||||
// "Today" under its bar; the month's ends step aside when it comes close.
|
||||
const td = h('span', { class: 'td' }, _('Today'));
|
||||
td.style.left = pc(day - 0.5, days);
|
||||
@@ -131,23 +125,7 @@ function month(p: Person, used: number, pct: number): HTMLElement {
|
||||
td,
|
||||
h('span', { class: day >= days - 3 ? 'hide' : '' }, short(days)),
|
||||
);
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'month' },
|
||||
bars,
|
||||
axis,
|
||||
h(
|
||||
'div',
|
||||
{ class: 'month-read' },
|
||||
read,
|
||||
h(
|
||||
'span',
|
||||
{ class: `num${p.state === 'quota' ? ' bad-t' : ''}`, 'data-t': 'm-left' },
|
||||
p.quota_limit ? fmt(_('%s left'), bytes(Math.max(0, p.quota_limit - used))) : _('No limit'),
|
||||
),
|
||||
),
|
||||
p.quota_limit ? meter(pct) : null,
|
||||
);
|
||||
return h('div', { class: 'month' }, chart.el, axis, h('div', { class: 'month-read' }, read.el, side), p.quota_limit ? meter(pct) : null);
|
||||
}
|
||||
|
||||
/** The days left as a number over a calendar of the weeks to the end (the last day ringed). */
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
// flows/.
|
||||
|
||||
import type { Device, Person } from '../../shared/types';
|
||||
import { addDays, ago, byDeviceState, bytes, parseDay } from '../../shared/format';
|
||||
import { addDays, ago, byDeviceState, parseDay } from '../../shared/format';
|
||||
import { fmt, locale, num, plural } from '../../shared/i18n';
|
||||
import { h, ic } from '../dom';
|
||||
import { BOUNCY, EASE_IN, EASE_OUT, SMOOTH, play } from '../motion';
|
||||
import { now, today, type RepaintOpts, type State } from '../state';
|
||||
import { bars, sumDays, upDown } from '../ui/bars';
|
||||
import { copy } from '../ui/feedback';
|
||||
import { glass } from '../ui/glass';
|
||||
import { openMenu, type MenuItem } from '../ui/menu';
|
||||
@@ -63,11 +64,12 @@ function dayName(back: number): string {
|
||||
return parseDay(addDays(today(), -back)).toLocaleDateString(locale(), { weekday: 'short', day: 'numeric', month: 'short' });
|
||||
}
|
||||
|
||||
/** Last 7 days as a number and bars; a bar under the pointer puts its own day in the number's place. */
|
||||
/** Last 7 days down and up over their bars; a day under the pointer puts its own numbers in their place. */
|
||||
function usage(d: Device, stale: boolean): HTMLElement {
|
||||
const week = d.spark.reduce((a, b) => a + b, 0);
|
||||
const week = sumDays(d.spark);
|
||||
const lbl = h('span', { class: 'use-lbl' }, _('Last 7 days'));
|
||||
const val = h('span', { class: 'use-val num', 'data-t': `${d.id}:use` }, bytes(week));
|
||||
const val = upDown(d.id);
|
||||
val.set(week);
|
||||
let side: HTMLElement;
|
||||
if (stale)
|
||||
side = h(
|
||||
@@ -83,25 +85,22 @@ function usage(d: Device, stale: boolean): HTMLElement {
|
||||
h('span', {}, _('Update')),
|
||||
);
|
||||
else {
|
||||
const max = Math.max(1, ...d.spark);
|
||||
side = h('div', { class: 'spark' });
|
||||
d.spark.forEach((v, i) => {
|
||||
const chart = bars(d.spark, 'bars-week', 34);
|
||||
side = chart.el;
|
||||
chart.cols.forEach((col, i) => {
|
||||
const back = d.spark.length - 1 - i;
|
||||
const b = h('i', { class: back === 0 ? 'today' : '' });
|
||||
b.style.height = `${Math.max(3, Math.round((v / max) * 34))}px`;
|
||||
// What the pointer reads off the bars changes at once: no morph while it moves.
|
||||
b.addEventListener('pointerenter', () => {
|
||||
col.addEventListener('pointerenter', () => {
|
||||
setText(lbl, dayName(back));
|
||||
setText(val, bytes(v));
|
||||
val.set(d.spark[i]);
|
||||
});
|
||||
b.addEventListener('pointerleave', () => {
|
||||
col.addEventListener('pointerleave', () => {
|
||||
setText(lbl, _('Last 7 days'));
|
||||
setText(val, bytes(week));
|
||||
val.set(week);
|
||||
});
|
||||
side.appendChild(b);
|
||||
});
|
||||
}
|
||||
return h('div', { class: 'dev-use' }, h('div', { class: 'use-txt' }, lbl, val), side);
|
||||
return h('div', { class: 'dev-use' }, h('div', { class: 'use-txt' }, lbl, h('span', { class: 'use-val' }, val.el)), side);
|
||||
}
|
||||
|
||||
function card(d: Device, st: State): HTMLElement {
|
||||
|
||||
@@ -125,28 +125,6 @@
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.mbars {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 3px;
|
||||
height: 64px;
|
||||
}
|
||||
.mbars i {
|
||||
flex: 1;
|
||||
border-radius: 2.5px;
|
||||
background: var(--bar);
|
||||
min-height: 3px;
|
||||
transition: background-color 120ms;
|
||||
}
|
||||
.mbars i.future {
|
||||
background: color-mix(in srgb, var(--bar) 45%, transparent);
|
||||
}
|
||||
.mbars i.today {
|
||||
background: var(--accent);
|
||||
}
|
||||
.mbars i:not(.future):hover {
|
||||
background: var(--text-2);
|
||||
}
|
||||
.month-axis {
|
||||
position: relative;
|
||||
display: flex;
|
||||
@@ -171,7 +149,10 @@
|
||||
font-size: 13px;
|
||||
color: var(--text-2);
|
||||
}
|
||||
.month-read b {
|
||||
.month-read > * {
|
||||
white-space: nowrap;
|
||||
}
|
||||
.month-read .ud {
|
||||
color: var(--text);
|
||||
font-weight: 500;
|
||||
font-size: 15px;
|
||||
@@ -273,7 +254,8 @@
|
||||
.until.soon .cal-g i.end {
|
||||
box-shadow: inset 0 0 0 1.5px var(--warn);
|
||||
}
|
||||
.acc-row.open .cal-g i {
|
||||
/* The days come in when the person opens the row, not when a repaint rebuilds it open. */
|
||||
.acc-row.opened .cal-g i {
|
||||
animation: cal-in 360ms var(--ease-out) backwards;
|
||||
animation-delay: calc(var(--i) * 7ms);
|
||||
}
|
||||
@@ -339,7 +321,7 @@
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.acc-row.open .cal-g i {
|
||||
.acc-row.opened .cal-g i {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/* Traffic by day, both ways (ui/bars.ts): downloads rise above a hairline, uploads hang below it,
|
||||
today in accent; a device card's week and the month in "Your access". Beside them, "↓ 3.9 GB ↑ 819 MB".
|
||||
The columns meet: each takes half the gap on either side, so the pointer reads a day in the gaps too, and
|
||||
the row gives the outer halves back so the bars stand where a plain gap would put them. */
|
||||
|
||||
.bars {
|
||||
--gap: 3px;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex: none;
|
||||
margin-inline: calc(var(--gap) / -2);
|
||||
}
|
||||
.bars-week {
|
||||
--gap: 4px;
|
||||
}
|
||||
.bars .col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-inline: calc(var(--gap) / 2);
|
||||
}
|
||||
.bars-month .col {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.bars .half {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.bars .half.top {
|
||||
justify-content: flex-end;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
.bars i {
|
||||
display: block;
|
||||
border-radius: 2.5px;
|
||||
transition: background-color 120ms;
|
||||
}
|
||||
.bars-week i {
|
||||
width: 6px;
|
||||
border-radius: 3px;
|
||||
transition-duration: 150ms;
|
||||
}
|
||||
.bars .dn {
|
||||
background: color-mix(in srgb, var(--text) 24%, transparent);
|
||||
}
|
||||
.bars .up {
|
||||
background: color-mix(in srgb, var(--text) 11%, transparent);
|
||||
}
|
||||
.bars .today .dn {
|
||||
background: var(--accent);
|
||||
}
|
||||
.bars .today .up {
|
||||
background: color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
}
|
||||
.bars .col:not(.future):hover .dn {
|
||||
background: var(--text-2);
|
||||
}
|
||||
.bars .col:not(.future):hover .up {
|
||||
background: color-mix(in srgb, var(--text-2) 50%, transparent);
|
||||
}
|
||||
.bars .today:hover .dn {
|
||||
background: color-mix(in srgb, var(--accent) 75%, var(--text));
|
||||
}
|
||||
.bars .future i {
|
||||
height: 3px;
|
||||
background: color-mix(in srgb, var(--bar) 45%, transparent);
|
||||
}
|
||||
.bars .axis {
|
||||
position: absolute;
|
||||
left: calc(var(--gap) / 2);
|
||||
right: calc(var(--gap) / 2);
|
||||
height: 1px;
|
||||
background: var(--line);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* ↓ down ↑ up: the arrows are the line icon turned; the upload one step quieter. */
|
||||
.ud {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ud > span {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
}
|
||||
.ud .i {
|
||||
width: 0.8em;
|
||||
height: 0.8em;
|
||||
stroke-width: 2.2;
|
||||
color: var(--text-2);
|
||||
}
|
||||
.ud-dn .i {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.ud-up {
|
||||
color: var(--text-2);
|
||||
}
|
||||
.ud-up .i {
|
||||
transform: rotate(-90deg);
|
||||
color: var(--text-3);
|
||||
}
|
||||
@@ -97,27 +97,6 @@
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
.spark {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 4px;
|
||||
height: 34px;
|
||||
}
|
||||
.spark i {
|
||||
width: 6px;
|
||||
border-radius: 3px;
|
||||
background: var(--bar);
|
||||
transition: background-color 150ms;
|
||||
}
|
||||
.spark i.today {
|
||||
background: var(--accent);
|
||||
}
|
||||
.spark i:hover {
|
||||
background: var(--text-2);
|
||||
}
|
||||
.spark i.today:hover {
|
||||
background: color-mix(in srgb, var(--accent) 75%, var(--text));
|
||||
}
|
||||
.dev .setup-btn {
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
@import './base.css';
|
||||
@import './controls.css';
|
||||
@import './morph.css';
|
||||
@import './bars.css';
|
||||
@import './accordion.css';
|
||||
@import './page.css';
|
||||
@import './devices.css';
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// closed and share their rounded ends; an open row lifts out with 10 px gaps
|
||||
// and its own corners. One row open at a time. A row with nothing to open is a
|
||||
// plain head: no chevron, no click. Inside the sheet it tells the sheet first,
|
||||
// so a code that comes into view gets its width.
|
||||
// so a code that comes into view gets its width. A row the person opens is
|
||||
// `.opened` until it closes: what enters inside it (the calendar's days) keys on
|
||||
// that, so a repaint that rebuilds the row open doesn't play it again.
|
||||
|
||||
import { h, ic } from '../dom';
|
||||
import { EASE_IN, SOFT, play } from '../motion';
|
||||
@@ -98,9 +100,10 @@ export function accordion(
|
||||
const closing = rows.filter((x) => x.classList.contains('open') && (x === r || willOpen));
|
||||
rows.forEach((x) => {
|
||||
x.classList.remove('closing');
|
||||
if (x !== r) x.classList.remove('open');
|
||||
if (x !== r) x.classList.remove('open', 'opened');
|
||||
});
|
||||
r.classList.toggle('open', willOpen);
|
||||
r.classList.toggle('opened', willOpen);
|
||||
corners();
|
||||
const plan = planWidth();
|
||||
rows.forEach((x, i) => {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// Traffic by day, both ways: what a device received rises above a hairline and
|
||||
// what it sent hangs below, on one scale, so a day of uploads shows as itself
|
||||
// rather than as a cap on the downloads. The hairline sits where the two
|
||||
// directions' peaks share the height. Beside the bars, "↓ 3.9 GB ↑ 819 MB".
|
||||
// A day is the router's [rx, tx]: rx came from the device (its upload), tx went
|
||||
// to it (its download).
|
||||
|
||||
import type { Pair } from '../../shared/types';
|
||||
import { bytes } from '../../shared/format';
|
||||
import { h, ic } from '../dom';
|
||||
import { setText } from './morph';
|
||||
|
||||
/** Between the halves, the hairline in the middle of it. */
|
||||
const GAP = 3;
|
||||
|
||||
/** Days added up: what came and what went over all of them. */
|
||||
export const sumDays = (days: Pair[]): Pair => days.reduce<Pair>((a, [rx, tx]) => [a[0] + rx, a[1] + tx], [0, 0]);
|
||||
|
||||
/**
|
||||
* Where the hairline sits and how many px a byte is: each direction's peak gets
|
||||
* its share of the height, the downloads keeping 55–80% of it, so a quiet
|
||||
* upload still shows and a busy one does not flatten the rest.
|
||||
*/
|
||||
export function mirror(days: Pair[], height: number): { top: number; bottom: number; scale: number } {
|
||||
const down = Math.max(1, ...days.map((d) => d[1]));
|
||||
const up = Math.max(1, ...days.map((d) => d[0]));
|
||||
const top = Math.round((height - GAP) * Math.min(0.8, Math.max(0.55, down / (down + up))));
|
||||
const bottom = height - GAP - top;
|
||||
return { top, bottom, scale: Math.min(top / down, bottom / up) };
|
||||
}
|
||||
|
||||
export interface Bars {
|
||||
el: HTMLElement;
|
||||
/** A column a day, for what the pointer reads off them. */
|
||||
cols: HTMLElement[];
|
||||
}
|
||||
|
||||
/** A column a day, today last (in accent); `future`: the days still to come, flat on the hairline. */
|
||||
export function bars(days: Pair[], cls: string, height: number, future = 0): Bars {
|
||||
const { top, bottom, scale } = mirror(days, height);
|
||||
const half = (side: string, px: number, v: number, what: string) => {
|
||||
const bar = h('i', { class: what });
|
||||
bar.style.height = `${Math.max(2, Math.round(v * scale))}px`;
|
||||
const el = h('div', { class: `half ${side}` }, bar);
|
||||
el.style.height = `${px}px`;
|
||||
return el;
|
||||
};
|
||||
const el = h('div', { class: `bars ${cls}`, 'aria-hidden': 'true' });
|
||||
el.style.height = `${height}px`;
|
||||
const cols = days.map(([rx, tx], i) =>
|
||||
el.appendChild(
|
||||
h('div', { class: `col${i === days.length - 1 ? ' today' : ''}` }, half('top', top, tx, 'dn'), half('bottom', bottom, rx, 'up')),
|
||||
),
|
||||
);
|
||||
for (let i = 0; i < future; i++) el.appendChild(h('div', { class: 'col future' }, h('i'))).style.paddingTop = `${top - 2}px`;
|
||||
el.appendChild(h('span', { class: 'axis' })).style.top = `${top + 1}px`;
|
||||
return { el, cols };
|
||||
}
|
||||
|
||||
export interface UpDown {
|
||||
el: HTMLElement;
|
||||
/** Show these, at once (a repaint morphs them by their keys). */
|
||||
set(day: Pair): void;
|
||||
}
|
||||
|
||||
/** "↓ 3.9 GB ↑ 819 MB"; `key` names the two numbers for the repaint's morph. */
|
||||
export function upDown(key: string): UpDown {
|
||||
const side = (cls: string, name: string, num: HTMLElement) =>
|
||||
h('span', { class: cls, title: name }, ic('arrow'), h('span', { class: 'offscreen' }, name), num);
|
||||
const dn = h('span', { class: 'num', 'data-t': `${key}:dn` });
|
||||
const up = h('span', { class: 'num', 'data-t': `${key}:up` });
|
||||
return {
|
||||
el: h('span', { class: 'ud' }, side('ud-dn', _('Downloaded'), dn), side('ud-up', _('Uploaded'), up)),
|
||||
set([rx, tx]) {
|
||||
setText(dn, bytes(tx));
|
||||
setText(up, bytes(rx));
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -41,6 +41,24 @@ export function toast(msg: string, bad = false) {
|
||||
}, 2400);
|
||||
}
|
||||
|
||||
/** An icon that changes in place: the new one pops in where the old one stood. */
|
||||
export function swapIcon(icon: Element, name: string): Element {
|
||||
const next = ic(name, icon.getAttribute('class') ?? 'i');
|
||||
icon.replaceWith(next);
|
||||
play(
|
||||
next,
|
||||
[
|
||||
{ opacity: 0, transform: 'scale(.6)', filter: 'blur(3px)' },
|
||||
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||
],
|
||||
{
|
||||
duration: POP.duration,
|
||||
easing: POP.easing,
|
||||
},
|
||||
);
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* The control that copied says so for a moment: its icon turns into a check
|
||||
* and its "Copy…" label (`.lbl`, a badge's main line) into "Copied". Every
|
||||
@@ -53,22 +71,7 @@ function copied(from: Element) {
|
||||
const label = from.querySelector<HTMLElement>('.lbl, .b-main');
|
||||
const was = label ? textOf(label) : '';
|
||||
from.classList.add('copied');
|
||||
let check: Element | null = null;
|
||||
if (icon) {
|
||||
check = ic('check', icon.getAttribute('class') ?? 'i');
|
||||
icon.replaceWith(check);
|
||||
play(
|
||||
check,
|
||||
[
|
||||
{ opacity: 0, transform: 'scale(.6)', filter: 'blur(3px)' },
|
||||
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||
],
|
||||
{
|
||||
duration: POP.duration,
|
||||
easing: POP.easing,
|
||||
},
|
||||
);
|
||||
}
|
||||
const check = icon ? swapIcon(icon, 'check') : null;
|
||||
if (label) morphText(label, _('Copied'));
|
||||
setTimeout(() => {
|
||||
if (check && icon) check.replaceWith(icon);
|
||||
|
||||
Reference in new issue
Block a user