Dawnline 0.16.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

- The personal page loads faster and costs the router less: its script
  and styles come compressed, stay in the browser until the next update,
  and the icon comes with the page instead of a request of its own
- The page uses the system's own font (SF Pro on Apple devices, Segoe UI
  on Windows, Roboto on Android) instead of downloading one
- The top of the page shows the server's name alone, so it fits on a
  phone
- Text can be selected only where it is there to be copied (addresses,
  file names, the configuration), with the name field's own selection:
  a soft highlight with handles that glides after the pointer
- Sheets scroll without a scrollbar
- Red buttons (Remove) light up under the pointer, as the others do
- Demo: "Demo" and GitHub are one button; on a phone it floats at the
  bottom of the screen, and switching scenarios no longer makes the
  edge fades jump
This commit is contained in:
Aemeath committed 2026-10-24 21:33:48 +03:00
1 parent 750564ab7e
commit 2388603322
91 files changed
+2564 -1027

No files matched your search

+2 -2
View File
@@ -16,7 +16,7 @@ import { fmt, plural } from '../shared/i18n';
type Service = Status['services'][number];
/** Circle colours; the circle stores an index. */
export const CIRCLE_COLORS = ['#3a83f7', '#a78bfa', '#f472b6', '#f59e0b', '#10b981', '#22d3ee', '#ef4444', '#84cc16'];
const CIRCLE_COLORS = ['#3a83f7', '#a78bfa', '#f472b6', '#f59e0b', '#10b981', '#22d3ee', '#ef4444', '#84cc16'];
export const circleDot = (c: Circle | undefined) =>
E('i', { class: 'dl-circle-dot', style: `background:${CIRCLE_COLORS[c?.color ?? 0] ?? CIRCLE_COLORS[0]}` });
@@ -26,7 +26,7 @@ export const homeAccess = (p: Person) => p.access === 'both' || (p.access === 'l
/* ---------- Home services ---------- */
export function serviceDialog(sv: Service | null, prefill: Partial<Service>, onSaved: () => unknown) {
function serviceDialog(sv: Service | null, prefill: Partial<Service>, onSaved: () => unknown) {
const name = input(sv?.name ?? prefill.name ?? '', { placeholder: _('NAS') });
const addr = input(sv?.address ?? prefill.address ?? '', { placeholder: '192.168.1.10', class: 'cbi-input-text dl-mono' });
const ports = input((sv?.ports ?? prefill.ports ?? []).join(', '), {
+1 -1
View File
@@ -295,7 +295,7 @@ export interface LogsInfo {
}
/** The path that makes tunnel clients' internet traffic enter from the LAN. */
export interface LikeHome {
interface LikeHome {
active: boolean;
dev?: string;
address?: string;
+2 -2
View File
@@ -220,7 +220,7 @@ export function plainWg(cfg: AwgConfig): boolean {
}
/** File / key / QR switcher for a client configuration; opens on the file unless asked otherwise. */
export async function connectBlock(cfg: AwgConfig, initial: 'file' | 'key' | 'qr' = 'file'): Promise<HTMLElement> {
async function connectBlock(cfg: AwgConfig, initial: 'file' | 'key' | 'qr' = 'file'): Promise<HTMLElement> {
if (!cfg.has_private_key)
return E(
'div',
@@ -297,7 +297,7 @@ async function applyDisguise(ctx: CoreCtx, srv: Server, m: Method, same: boolean
}
/** Server → AmneziaWG: listening port, what goes into every configuration, disguise, tunnel. */
export function settingsCard(ctx: CoreCtx, srv: Server): HTMLElement {
function settingsCard(ctx: CoreCtx, srv: Server): HTMLElement {
const st: Status = ctx.st;
const port = input(String(srv.port), { inputmode: 'numeric', class: 'cbi-input-text dl-w-port dl-mono' });
const mtu = input(srv.mtu ? String(srv.mtu) : '', {
+1 -1
View File
@@ -6,7 +6,7 @@ import type { Server } from '../../shared/types';
import type { Core } from './common';
import { awg } from './awg';
export type { Core, CoreCtx } from './common';
export type { Core } from './common';
const CORES: Record<string, Core> = { awg };
+2 -2
View File
@@ -7,7 +7,7 @@ import { fmt } from '../shared/i18n';
export type Method = 'balanced' | 'max' | 'off';
/** The router features a method may need (the boolean ones of AwgCaps). */
export type AwgNeed = 'v2' | 'v3';
type AwgNeed = 'v2' | 'v3';
export interface MethodInfo {
id: Method;
@@ -26,7 +26,7 @@ export interface MethodInfo {
}
/** The methods in picker order, in the page's language. */
export function methods(): MethodInfo[] {
function methods(): MethodInfo[] {
return [
{
id: 'off',
+1 -1
View File
@@ -70,7 +70,7 @@ async function toPng(svg: string): Promise<Blob> {
type Invitee = Pick<Person, 'id' | 'name'> & { link?: string | null; links?: string[] };
/** The personal link and its other addresses (person_links); null while the portal is off. */
export async function personLinks(id: string): Promise<{ link: string; links: string[] } | null> {
async function personLinks(id: string): Promise<{ link: string; links: string[] } | null> {
const r = await attempt(() => api.personLinks(id));
if (!r) return null;
if (!r.link) {
+2 -2
View File
@@ -138,7 +138,7 @@ export interface MapData {
* The latest point per device inside the time window: per device and city on a
* person's page, per city in a device's window.
*/
export function visiblePoints(data: MapData, range: Range): GeoPoint[] {
function visiblePoints(data: MapData, range: Range): GeoPoint[] {
const best = new Map<string, GeoPoint>();
for (const p of data.geo.points) {
if (data.person && p.person !== data.person) continue;
@@ -1233,7 +1233,7 @@ function face(slot: { el: HTMLElement; at: [number, number]; who?: string; where
* when `quiet`: a redraw), gone ones leave the row at once and shrink away where they were, the
* "+N" is one element whose number changes, and the plate's width follows smoothly.
*/
export function fillFaces(
function fillFaces(
box: HTMLElement,
faces: Face[],
on: { click: (f: Face, b: HTMLElement) => void; hover: (f: Face | null) => void },
+3 -2
View File
@@ -103,6 +103,7 @@ export function portalPortHelp(port: number, taken: PortHold[], ipLinks: boolean
export const chars = (s: string): number => Array.from(s).length;
const NAME_MAX = 48;
// oxlint-disable-next-line no-control-regex -- control characters are what it refuses
const BAD_NAME = /[<>"\\\u0000-\u001f\u007f]/;
/** "Up to 48 characters (50 now).": a name over its limit. */
@@ -147,7 +148,7 @@ export function isIpv4(s: string): boolean {
return !!m && m.slice(1).every((x) => Number(x) <= 255);
}
export function isIpv6(s: string): boolean {
function isIpv6(s: string): boolean {
return /^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}$/.test(s) && !/:::/.test(s);
}
@@ -161,7 +162,7 @@ export function hostHelp(s: string, port?: number, empty: string | null = null):
if (!t) return empty != null ? { text: empty, bad: false } : { text: _('Enter a hostname or IP address.'), bad: true };
if (/^[a-z]+:\/\//i.test(t)) return { text: _('Leave out https:// - just the name.'), bad: true };
if (/\/.*/.test(t)) return { text: _('Just the name, without a path.'), bad: true };
if (/^[^:\[]+:\d+$/.test(t)) return { text: _('Just the name, without a port (the port is on AmneziaWG).'), bad: true };
if (/^[^:[]+:\d+$/.test(t)) return { text: _('Just the name, without a port (the port is on AmneziaWG).'), bad: true };
if (/\s/.test(t)) return { text: _('A hostname has no spaces.'), bad: true };
if (t.length > 253 || !(HOSTNAME.test(t) || isIpv4(t) || isIpv6(t))) return { text: _('Use a hostname or an IP address.'), bad: true };
const shown = isIpv6(t) ? `[${t}]` : t;
+14 -15
View File
@@ -226,22 +226,21 @@ export class PeoplePage {
render(stAll: Status): Promise<Node> {
const st = this.scope(stAll);
this.st = st;
const page = this;
const sort = E(
'select',
{
class: 'dl-select',
'aria-label': _('Sort'),
change: (ev: Event) => {
page.sort = (ev.target as HTMLSelectElement).value as SortBy;
remember('dl.people.sort', page.sort);
page.decorate();
this.sort = (ev.target as HTMLSelectElement).value as SortBy;
remember('dl.people.sort', this.sort);
this.decorate();
},
},
[
E('option', { value: 'seen', selected: page.sort === 'seen' ? 'selected' : null }, _('Last seen', 'sort')),
E('option', { value: 'name', selected: page.sort === 'name' ? 'selected' : null }, _('Name', 'sort')),
E('option', { value: 'usage', selected: page.sort === 'usage' ? 'selected' : null }, _('Usage', 'sort')),
E('option', { value: 'seen', selected: this.sort === 'seen' ? 'selected' : null }, _('Last seen', 'sort')),
E('option', { value: 'name', selected: this.sort === 'name' ? 'selected' : null }, _('Name', 'sort')),
E('option', { value: 'usage', selected: this.sort === 'usage' ? 'selected' : null }, _('Usage', 'sort')),
],
);
// Find, once the list is long enough to need it; "/" focuses it.
@@ -252,8 +251,8 @@ export class PeoplePage {
'aria-label': _('Find a person or device'),
hidden: st.people.length > 8 ? null : 'hidden',
input: (ev: Event) => {
page.query = (ev.target as HTMLInputElement).value.trim().toLowerCase();
page.decorate();
this.query = (ev.target as HTMLInputElement).value.trim().toLowerCase();
this.decorate();
},
}) as HTMLInputElement;
const onSlash = (ev: KeyboardEvent) => {
@@ -266,14 +265,14 @@ export class PeoplePage {
document.addEventListener('keydown', onSlash);
onNavigate(() => document.removeEventListener('keydown', onSlash));
const wrap = E('div', { class: 'dl-root' }, [
page.serverId
this.serverId
? ''
: E('div', { class: 'dl-pagehead' }, [
E('div', { class: 'dl-stack' }, [
E('h2', { class: 'dl-h1' }, _('People')),
E('span', { class: 'dl-muted dl-people-count' }, this.countText()),
]),
st.servers.length ? button([icon('plus'), ` ${_('Add person')}`], () => page.openCreate(), 'add') : '',
st.servers.length ? button([icon('plus'), ` ${_('Add person')}`], () => this.openCreate(), 'add') : '',
]),
st.servers.length
? ''
@@ -291,7 +290,7 @@ export class PeoplePage {
E('div', { class: 'dl-toolbar-end' }, [
find,
sort,
page.serverId ? button([icon('plus'), ` ${_('Add person')}`], () => page.openCreate(), 'add') : '',
this.serverId ? button([icon('plus'), ` ${_('Add person')}`], () => this.openCreate(), 'add') : '',
]),
]),
this.list,
@@ -303,13 +302,13 @@ export class PeoplePage {
fetch: () => api.status(30),
every: 30,
live: true,
active: () => !!page.el?.isConnected,
apply: (st, quiet) => page.take(st, quiet),
active: () => !!this.el?.isConnected,
apply: (st, quiet) => this.take(st, quiet),
});
// ?add=1 opens Add person once, not again on every server's People tab.
if (!addOpened && new URLSearchParams(location.search).get('add')) {
addOpened = true;
setTimeout(() => page.openCreate(), 100);
setTimeout(() => this.openCreate(), 100);
}
return Promise.resolve(wrap);
}
+1 -1
View File
@@ -181,7 +181,7 @@ export function msAt(st: Stay[], steps: Step[], t: number): number {
return step.start + step.ms * Math.min(0.999, Math.max(0, (t - s.from) / Math.max(1, s.to - s.from)));
}
export const ease = (x: number) => (x <= 0 ? 0 : x >= 1 ? 1 : x < 0.5 ? 2 * x * x : 1 - (-2 * x + 2) ** 2 / 2);
const ease = (x: number) => (x <= 0 ? 0 : x >= 1 ? 1 : x < 0.5 ? 2 * x * x : 1 - (-2 * x + 2) ** 2 / 2);
/** The shimmer's middle (a share of the arc) `q` into a move: it enters before the place it leaves and runs out past the next. */
export function bandMiddle(q: number): number {
+1 -1
View File
@@ -13,7 +13,7 @@ const LOST_AFTER = 3;
* Request tickets: an answer is shown only if nothing newer was shown before
* it. `claim()` invalidates everything in flight (an edit's own answer wins).
*/
export class Sequence {
class Sequence {
private n = 0;
private shown = 0;
next(): number {
+1 -1
View File
@@ -27,7 +27,7 @@ import settings from './settings.css';
import components from './components.css';
import access from './access.css';
export const CSS = [
const CSS = [
base,
people,
controls,
+1 -1
View File
@@ -11,7 +11,7 @@ export function pill(tone: string, text: string, title?: string): HTMLElement {
return E('span', { class: `dl-pill ${tone}`, title: title ?? null }, text);
}
export function stateTone(p: Person): string {
function stateTone(p: Person): string {
if (p.state === 'active') return 'ok';
if (p.state === 'quota' || p.state === 'expired') return 'bad';
return 'warn';
-6
View File
@@ -107,12 +107,6 @@ export function chipToggle(
);
}
/** Mark a chip toggle on or off in place. */
export function setChip(b: HTMLElement, on: boolean) {
b.classList.toggle('on', on);
b.setAttribute('aria-pressed', on ? 'true' : 'false');
}
/**
* Single choice as LuCI's select (a ListValue's widget); the choice is `.value`.
* Unknown values get an option of their own, so nothing is lost on save.
+2 -1
View File
@@ -18,7 +18,8 @@ type OpenMenu = HTMLElement & { dlAnchor?: HTMLElement; dlClose?: () => void };
export function dropdown(anchor: HTMLElement, items: (MenuItem | null)[]) {
const prev = document.querySelector('.dl-dd') as OpenMenu | null;
if (prev) {
prev.dlClose ? prev.dlClose() : prev.remove();
if (prev.dlClose) prev.dlClose();
else prev.remove();
if (prev.dlAnchor === anchor) return;
}
const menu: OpenMenu = E(
+1 -1
View File
@@ -11,7 +11,7 @@ let floating: HTMLElement | null = null;
let anchor: HTMLElement | null = null;
let watch = 0;
export function hideTip() {
function hideTip() {
if (floating) floating.style.display = 'none';
anchor = null;
clearInterval(watch);
+4 -4
View File
@@ -15,7 +15,7 @@ export function markdown(src: string): Node[] {
const parts: (Node | string)[] = [];
const re = /(`[^`]+`)|(\*\*[^*]+\*\*)|(\[[^\]]+\]\((https?:\/\/[^)\s]+)\))|(https?:\/\/[^\s<>()]+[^\s<>().,;:!?])/g;
let last = 0;
for (let m: RegExpExecArray | null; (m = re.exec(s)); ) {
for (let m: RegExpExecArray | null; (m = re.exec(s));) {
if (m.index > last) parts.push(s.slice(last, m.index));
if (m[1]) parts.push(E('code', {}, m[1].slice(1, -1)));
else if (m[2]) parts.push(E('b', {}, m[2].slice(2, -2)));
@@ -38,13 +38,13 @@ export function markdown(src: string): Node[] {
for (const raw of src.replace(/\r/g, '').split('\n')) {
const line = raw.trimEnd();
if (fence) {
if (/^```/.test(line.trim())) {
if (line.trim().startsWith('```')) {
out.push(E('pre', {}, fence.join('\n')));
fence = null;
} else fence.push(raw);
continue;
}
if (/^```/.test(line.trim())) {
if (line.trim().startsWith('```')) {
flush();
fence = [];
continue;
@@ -84,7 +84,7 @@ export function forRouter(md: string): string {
if (h) {
skip = /^install\b/i.test(h[1].trim());
if (/^what.s new$/i.test(h[1].trim())) continue;
} else if (/^\*\*Full Changelog\*\*/.test(line)) skip = false;
} else if (line.startsWith('**Full Changelog**')) skip = false;
if (!skip) out.push(line);
}
return out
+1 -1
View File
@@ -5,7 +5,7 @@
import { addDays, parseDay } from '../shared/format';
export type CellKind = 'past' | 'today' | 'left' | 'end' | 'after';
type CellKind = 'past' | 'today' | 'left' | 'end' | 'after';
export interface Cell {
day: string;
kind: CellKind;
+44 -13
View File
@@ -1,40 +1,71 @@
// What the demo adds to the breadcrumb: the scenario chip right after the path,
// and a GitHub knob (its mark only) just before the page's language picker (none over a card
// alone, which has no picker either). On a phone the pill would crowd out the names, so it
// gives way to a button in the scenario drawer (demo.css). The portal redraws
// the breadcrumb with the page and says when (onCrumbs), so both go back in
// place after each redraw; a language change makes both again in it.
// What the demo adds to the page: "Demo" (it opens the scenarios) and a link to
// GitHub, one split pill. Wide, the pill stands in the breadcrumb just before the
// page's language. On a phone the breadcrumb has no room for it, so it is a dock
// of its own at the bottom right, in <body>, outside the page: the page's
// entrance and a scenario's swap move the page with a transform and a filter,
// which would carry a fixed child along and leave its glass undrawn until they
// end. Over a card alone (no language) only the chip, right after the place, and
// no dock. The portal redraws the breadcrumb with the page and says when
// (onCrumbs), so the pill goes back in place after each redraw; a language
// change makes all of it again in it.
import { h, ic } from '../dom';
import { onLang } from '../i18n';
import { EASE_OUT, play } from '../motion';
import { onCrumbs } from '../page/frame';
import { REPO } from './data';
import { scenarioChip } from './picker';
import { scenarioPicker } from './picker';
import type { DemoRouter } from './router';
export function mountCrumbs(router: DemoRouter) {
const app = document.getElementById('app')!;
const open = scenarioPicker(router);
const demo = (cls: string) =>
h('button', { type: 'button', class: cls, 'aria-haspopup': 'dialog', onclick: open }, h('span', {}, _('Demo')), ic('chevron', 'i'));
const github = (cls: string) =>
h('a', { class: cls, href: REPO, target: '_blank', rel: 'noopener', 'aria-label': _('Dawnline on GitHub') }, ic('github'));
const make = () => ({
chip: scenarioChip(router),
gh: h('a', { class: 'dm-gh', href: REPO, target: '_blank', rel: 'noopener', 'aria-label': _('Dawnline on GitHub') }, ic('github')),
chip: demo('dm-chip'),
gh: github('dm-gh'),
dock: h('div', { class: 'dm-dock' }, demo('dm-dock-demo'), github('dm-dock-gh')),
});
let { chip, gh } = make();
let { chip, gh, dock } = make();
let first = true;
const keep = () => {
const crumbs = app.querySelector('.crumbs');
const path = crumbs?.querySelector('.cr-path');
if (!crumbs || !path) return;
if (path.nextElementSibling !== chip) path.after(chip);
const lang = crumbs.querySelector('.cr-lang');
if (lang && lang.previousElementSibling !== gh) lang.before(gh);
chip.classList.toggle('split', !!lang);
if (!lang) {
gh.remove();
dock.remove();
if (path.nextElementSibling !== chip) path.after(chip);
return;
}
if (lang.previousElementSibling !== gh || gh.previousElementSibling !== chip) lang.before(chip, gh);
if (dock.isConnected) return;
document.body.append(dock);
// It rises from under the screen's edge (with the page's first wave, the first time), on a transform alone:
// Safari leaves a backdrop blur undrawn while the element's opacity is animating, and it would pop in at the end.
play(dock, [{ transform: 'translateY(calc(100% + 64px))' }, { transform: 'none' }], {
duration: 620,
delay: first ? 260 : 0,
easing: EASE_OUT,
fill: 'backwards',
});
first = false;
};
// Each time the page draws its breadcrumb again (a repaint, the language changed).
onCrumbs(keep);
keep();
// The page has redrawn its breadcrumb in the new language by now (main.ts listens first).
onLang(() => {
const was = dock;
chip.remove();
gh.remove();
({ chip, gh } = make());
({ chip, gh, dock } = make());
if (was.isConnected) was.replaceWith(dock);
keep();
});
}
+4 -4
View File
@@ -6,7 +6,7 @@
import type { State } from '../state';
import type { Device, Kind, Pair, Person } from '../../shared/types';
export const GB = 2 ** 30;
const GB = 2 ** 30;
const HOUR = 3600;
const DAY = 86400;
@@ -94,14 +94,14 @@ export function seedDevices(s: ScenarioId, t: number, id: () => string): DemoDev
}
/** The person's state in the scenario: the four the admin's limits stop them in, else active. */
export function personState(s: ScenarioId): Person['state'] {
function personState(s: ScenarioId): Person['state'] {
return s === 'quota' || s === 'hours' || s === 'paused' || s === 'expired' ? s : 'active';
}
export const locked = (s: ScenarioId) => s === 'paused' || s === 'expired';
const locked = (s: ScenarioId) => s === 'paused' || s === 'expired';
export const deviceLimit = (s: ScenarioId) => (s === 'full' ? 3 : 4);
/** The local day (YYYY-MM-DD) of a time: in the demo, the visitor's clock is the router's. */
export function isoDay(t: number): string {
function isoDay(t: number): string {
const d = new Date(t * 1000);
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
}
+94 -38
View File
@@ -1,19 +1,17 @@
/* The portal demo's stylesheet: the portal's own, then the demo's pieces in its tokens — the "Demo"
chip after the breadcrumb's path, the GitHub knob before the page's language, the scenario
rows in the drawer, and the set-up state switch beside the set-up sheet's ×. */
/* The portal demo's stylesheet: the portal's own, then the demo's pieces in its tokens — "Demo" and GitHub as
one split pill before the page's language (on a phone a dock at the bottom), the scenario rows in the drawer,
and the set-up state switch beside the set-up sheet's ×. */
@import '../styles/index.css';
/* The path keeps its width so the chip sits right after it; the page's QR stays at the end. */
.cr-path {
flex: 0 1 auto;
}
/* "Demo" and GitHub, one split pill just before the page's language: as high as the knobs beside it, the halves
2px apart, their inner corners 4px (the outer ones half the height: 999px would scale every radius of a half
down to nothing). Over a card alone the chip stands by itself after the place, 26px and round. */
.dm-chip {
display: inline-flex;
align-items: center;
gap: 4px;
height: 26px;
padding: 0 8px 0 10px;
margin-right: auto;
border-radius: 999px;
background: var(--accent-soft);
color: var(--accent);
@@ -24,53 +22,117 @@
transform 150ms var(--ease-out),
background-color 150ms;
}
.dm-chip:hover {
background: color-mix(in srgb, var(--accent) 20%, transparent);
}
.dm-chip:active {
transform: scale(0.94);
.dm-chip.split {
height: 32px;
padding: 0 10px 0 14px;
border-radius: 16px 4px 4px 16px;
font-size: 14px;
}
.dm-chip .i {
width: 14px;
height: 14px;
transform: rotate(90deg);
}
/* A card alone (paused): the breadcrumb is centred, the chip with it. */
.page.single .dm-chip {
margin-right: 0;
}
/* GitHub: a knob with its mark only, as the QR knob, just before the language. On a phone it would crowd out
the names (the server's and the person's): there it is a button in the drawer instead. */
.dm-gh {
display: inline-grid;
place-items: center;
width: 32px;
width: 38px;
height: 32px;
border-radius: 50%;
background: var(--knob);
color: var(--text);
margin-left: -8px;
padding-right: 2px;
border-radius: 4px 16px 16px 4px;
background: var(--accent-soft);
color: var(--accent);
text-decoration: none;
flex: none;
transition:
transform 150ms var(--ease-out),
background-color 150ms;
}
.dm-gh:hover {
background: color-mix(in srgb, var(--knob), var(--text) 6%);
}
.dm-gh:active {
transform: scale(0.94);
}
.dm-gh .i {
width: 16px;
height: 16px;
}
@media (max-width: 479px) {
/* Pointed at with a mouse only: a tap would leave it lit. */
@media (hover: hover) {
.dm-chip:hover,
.dm-gh:hover {
background: color-mix(in srgb, var(--accent) 20%, transparent);
}
}
.dm-chip:active,
.dm-gh:active {
transform: scale(0.94);
}
/* On a phone the breadcrumb has no room for the pill: it is the dock instead (crumbs.ts), in <body> at the bottom
right, over the bottom fade and under the sheets; glass, 36px, the halves as in the breadcrumb. */
@media (max-width: 559px) {
.dm-chip.split,
.dm-gh {
display: none;
}
}
.dm-dock {
position: fixed;
z-index: 40;
right: max(16px, env(safe-area-inset-right, 0px));
bottom: calc(20px + env(safe-area-inset-bottom, 0px));
display: flex;
gap: 2px;
}
@media (min-width: 560px) {
.dm-dock {
display: none;
}
}
.dm-dock > * {
display: inline-flex;
align-items: center;
justify-content: center;
height: 36px;
color: var(--accent);
font-size: 14px;
font-weight: 600;
letter-spacing: -0.01em;
text-decoration: none;
background: var(--glass-bg);
-webkit-backdrop-filter: blur(28px) saturate(1.8);
backdrop-filter: blur(28px) saturate(1.8);
box-shadow:
inset 0 0 0 1px var(--glass-edge),
var(--glass-shadow);
transition: transform 150ms var(--ease-out);
-webkit-tap-highlight-color: transparent;
}
.dm-dock-demo {
gap: 4px;
padding: 0 10px 0 14px;
border-radius: 18px 5px 5px 18px;
}
.dm-dock-demo .i {
width: 14px;
height: 14px;
transform: rotate(-90deg);
}
.dm-dock-gh {
width: 40px;
border-radius: 5px 18px 18px 5px;
}
.dm-dock-gh .i {
width: 16px;
height: 16px;
}
/* A film over the glass, never in place of it. */
@media (hover: hover) {
.dm-dock > *:hover {
background:
linear-gradient(color-mix(in srgb, var(--text) 7%, transparent), color-mix(in srgb, var(--text) 7%, transparent)), var(--glass-bg);
}
}
.dm-dock > *:active {
transform: scale(0.94);
}
/* The drawer: groups of rows that touch, one step lighter than the sheet, the current one in the accent. */
.dm-group {
@@ -132,7 +194,7 @@
flex: none;
}
/* The drawer's foot: Start over, and on a phone GitHub beside it. */
/* The drawer's foot: Start over. */
.dm-foot {
display: flex;
gap: 8px;
@@ -140,12 +202,6 @@
.dm-foot .btn {
flex: 1;
}
@media (min-width: 480px) {
.dm-gh-alt {
display: none;
}
}
/* The set-up state switch: a pill beside ×, gliding into its place when the device arrives. */
.dm-way {
position: absolute;
+1 -1
View File
@@ -26,7 +26,7 @@ msgstr ""
msgid "Dawnline on GitHub"
msgstr ""
#: web/src/portal/demo/picker.ts
#: web/src/portal/demo/crumbs.ts
msgid "Demo"
msgstr ""
+1 -1
View File
@@ -28,7 +28,7 @@ msgstr "Авто"
msgid "Dawnline on GitHub"
msgstr "Dawnline на GitHub"
#: web/src/portal/demo/picker.ts
#: web/src/portal/demo/crumbs.ts
msgid "Demo"
msgstr "Демо"
+12 -17
View File
@@ -1,8 +1,7 @@
// The demo's scenario picker: the "Demo" chip, opening a drawer with the
// scenarios in groups (glass icon, name, what the page shows) and "Start over".
// Picking one swaps the page in place. Built only from the portal's own parts
// (sheet, glass icons, toast, motion); where the chip sits is crumbs.ts. On a
// phone the drawer's foot also links to GitHub, the breadcrumb having no room.
// The demo's scenario picker: a drawer with the scenarios in groups (glass
// icon, name, what the page shows) and "Start over". Picking one swaps the page
// in place. Built only from the portal's own parts (sheet, glass icons, toast,
// motion); the "Demo" buttons that open it, and where they sit, are crumbs.ts.
import { h, ic } from '../dom';
import { call } from '../api';
@@ -11,7 +10,7 @@ import { closeSheet, head, onSheetEntry, openSheet, sub, type View } from '../ui
import { glass, type Tone } from '../ui/glass';
import { toast } from '../ui/feedback';
import { EASE_OUT, play } from '../motion';
import { REPO, groups, type Scenario, type ScenarioId } from './data';
import { groups, type Scenario, type ScenarioId } from './data';
import type { DemoRouter } from './router';
/** Each scenario's glass icon and tone (the glass set is smaller than the line icons). */
@@ -28,8 +27,8 @@ const LOOK: Record<ScenarioId, [string, Tone]> = {
full: ['phone', 'grey'],
};
/** The chip that opens the scenarios. */
export function scenarioChip(router: DemoRouter): HTMLElement {
/** What opens the scenarios' drawer. */
export function scenarioPicker(router: DemoRouter): () => void {
const app = document.getElementById('app')!;
/** Swap the page in place: it dims away and comes back drawn from the scenario, the link saying which. */
@@ -44,14 +43,16 @@ export function scenarioChip(router: DemoRouter): HTMLElement {
else mark();
closeSheet();
router.use(s);
const out = play(app, [{ opacity: 1 }, { opacity: 0, filter: 'blur(4px)' }], { duration: 160, easing: EASE_OUT, fill: 'forwards' });
// The page, not #app: a filter or a transform on #app would carry its fixed edge fades along until it ends.
const page = app.querySelector<HTMLElement>('.page') ?? app;
const out = play(page, [{ opacity: 1 }, { opacity: 0, filter: 'blur(4px)' }], { duration: 160, easing: EASE_OUT, fill: 'forwards' });
const st = await call<State>('state');
await out.finished;
setState(st);
repaint();
out.cancel();
play(
app,
page,
[
{ opacity: 0, filter: 'blur(4px)', transform: 'translateY(6px)' },
{ opacity: 1, filter: 'none', transform: 'none' },
@@ -94,16 +95,10 @@ export function scenarioChip(router: DemoRouter): HTMLElement {
ic('reset'),
h('span', {}, _('Start over')),
),
h('a', { class: 'btn soft dm-gh-alt', href: REPO, target: '_blank', rel: 'noopener' }, ic('github'), h('span', {}, 'GitHub')),
),
);
return { el, label: _('Try a scenario') };
}
return h(
'button',
{ type: 'button', class: 'dm-chip', 'aria-haspopup': 'dialog', onclick: () => openSheet(scenarios) },
h('span', {}, _('Demo')),
ic('chevron', 'i'),
);
return () => openSheet(scenarios);
}
+1 -1
View File
@@ -51,7 +51,7 @@ export interface RouterOpts {
}
/** A settings sheet waits for the first connection: it comes this long after the settings are shown. */
export const CONNECT_AFTER = [6, 9];
const CONNECT_AFTER = [6, 9];
class Refusal {
constructor(
+1 -1
View File
@@ -59,7 +59,7 @@ const modelReady: Promise<string> = (async () => {
const m = ((await uad.getHighEntropyValues(['model'])).model ?? '').trim();
if (!m || m === 'K') return '';
const g = GALAXY.find(([re]) => re.test(m));
MODEL = g ? `${g[1]} (${m})` : /^SM-/.test(m) ? `Galaxy ${m}` : m;
MODEL = g ? `${g[1]} (${m})` : m.startsWith('SM-') ? `Galaxy ${m}` : m;
} catch {
/* not offered */
}
+1 -1
View File
@@ -67,7 +67,7 @@ export interface SetupCtx {
* A badge: the mark in a tile, two lines, a chevron (an action) or the open
* mark (a store page, in a new tab). `primary`: the one thing to tap in step 2.
*/
export function badge(
function badge(
st: { href?: string; top: string; main: string; mark: string; onclick?: (ev: Event) => void },
primary = false,
): HTMLElement {
+1 -1
View File
@@ -115,7 +115,7 @@ function foldBlock(el: HTMLElement, fold: boolean, instant: boolean) {
type Layout = 'same' | 'router' | 'away' | 'pc-away';
export function setupView(d: Device, cfg: ClientConfig, key: string, here = false): View {
function setupView(d: Device, cfg: ClientConfig, key: string, here = false): View {
const pf = platform();
const apps = appsFor(preset());
const handheld = d.kind === 'phone' || d.kind === 'tablet';
-3
View File
@@ -1,3 +0,0 @@
Geist and Geist Mono are licensed under the SIL Open Font License, Version 1.1.
Copyright (c) 2023 Vercel, in collaboration with basement.studio.
https://github.com/vercel/geist-font/blob/main/OFL.txt
Binary file not shown.
+4
View File
@@ -22,6 +22,7 @@ import { closeDrop, dropOpen } from './ui/drop';
import { closeSheet, sheetOpen } from './ui/sheet';
import { renaming } from './flows/rename';
import { keepPressFootprint } from './ui/press';
import { pageSelection } from './ui/selection';
import { startAdd } from './flows/add';
import { openSetup } from './flows/setup-view';
@@ -211,6 +212,9 @@ onLang(() => {
// A press that shrinks a control under the pointer still lands on it (ui/press.ts).
keepPressFootprint();
// The page's own text selection where text can be selected, as the fields draw theirs (ui/selection.ts).
pageSelection();
// The focus ring only while the keyboard moves focus (base.css .kbd): on from Tab or an arrow, off at a press.
const KEYS = new Set(['Tab', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']);
document.addEventListener('keydown', (e) => KEYS.has(e.key) && document.documentElement.classList.add('kbd'), true);
+2 -2
View File
@@ -78,9 +78,9 @@ export const LEAD = spring(520, 46);
/** The dropdowns, a dialog on a computer and the accordions: POP made softer (about 4% over, 90% there at ~140 ms). */
export const SOFT = spring(380, 28);
/** What follows the pointer (a menu's highlight): there in about 130 ms, no overshoot. */
export const QUICK = spring(900, 60);
const QUICK = spring(900, 60);
/** A highlight gliding from row to row: quick, with a touch of give (about 2% over). */
export const GLIDE = spring(640, 40);
const GLIDE = spring(640, 40);
export const EASE_OUT = 'cubic-bezier(0.23, 1, 0.32, 1)';
export const EASE_IN = 'cubic-bezier(0.55, 0, 1, 0.45)';
+1 -1
View File
@@ -209,7 +209,7 @@ function hoursBar(hours: string, tzOffset: number | undefined): HTMLElement | nu
}
/** The access accordion for this state; `open`: the row to keep open (a repaint), else the data. */
export function accessAccordion(st: State, open = 1): Accordion {
function accessAccordion(st: State, open = 1): Accordion {
const p = st.person;
const used = p.quota_used || p.month[0] + p.month[1];
const pct = p.quota_limit ? Math.min(100, (used / p.quota_limit) * 100) : 0;
+4 -11
View File
@@ -117,10 +117,9 @@ function qrKnob(): HTMLElement {
}
/**
* The breadcrumb: the place, then the person (none when the link stopped
* working); at its end, the language and this page's code for another
* device, on the page itself only (not over a card: paused, link gone,
* nothing loaded).
* The breadcrumb: the place alone (the page is the person's own, so not their
* name); at its end, the language and this page's code for another device, on
* the page itself only (not over a card: paused, link gone, nothing loaded).
*/
/** Who is told the breadcrumb was drawn again (the demo adds its chip and GitHub link to it: demo/crumbs.ts). */
const drawnCrumbs: (() => void)[] = [];
@@ -129,15 +128,9 @@ export const onCrumbs = (fn: () => void) => void drawnCrumbs.push(fn);
export function crumbs(gone = false, card = false) {
if (!crumbsEl) return;
const p = gone ? null : state()?.person;
const place = h('span', { class: p ? '' : 'cur', 'aria-current': p ? null : 'page' }, placeName());
crumbsEl.replaceChildren(
h('span', { class: 'cr-mark' }, markup(LOGO)),
h(
'nav',
{ class: 'cr-path', 'aria-label': _('Breadcrumb') },
place,
p ? [ic('chevron'), h('span', { class: 'cur', 'aria-current': 'page' }, p.name)] : null,
),
h('nav', { class: 'cr-path', 'aria-label': _('Breadcrumb') }, h('span', { class: 'cur', 'aria-current': 'page' }, placeName())),
...(card ? [] : [langPicker()]),
...(p && !card ? [qrKnob()] : []),
);
+2 -2
View File
@@ -26,7 +26,7 @@ export function notice(tone: Tone, icon: string, title: string | null, sub: stri
}
/** The admin's hours as the visitor reads them: "08:00–22:00 your time" (or the router's, said so). */
export function hoursText(hours: string): string {
function hoursText(hours: string): string {
const hw = hoursFor(hours, state()?.tz_offset, -new Date().getTimezoneOffset());
if (!hw) return fmt(_('%s (router time)'), hours.replace('-', '–'));
const span = `${clockOf(hw.from)}–${clockOf(hw.to)}`;
@@ -52,7 +52,7 @@ export function stateNotice(p: Person): [string, string, string] {
}
/** The page's notice, or null when nothing stands in the way. */
export function pageNotice(p: Person): HTMLElement | null {
function pageNotice(p: Person): HTMLElement | null {
if (p.state !== 'active') return notice(p.state === 'quota' || p.state === 'expired' ? 'bad' : 'warn', ...stateNotice(p));
const left = daysLeft(p.expires, today());
return endsSoon(p, left)
+1 -1
View File
@@ -55,7 +55,7 @@ export function appsFor(preset: Preset): AppChoice[] {
return out;
}
export type Mark = 'appstore' | 'googleplay' | 'windows' | 'apple' | 'linux' | 'openwrt' | 'github' | 'site';
type Mark = 'appstore' | 'googleplay' | 'windows' | 'apple' | 'linux' | 'openwrt' | 'github' | 'site';
export interface Store {
href: string;
+1 -1
View File
@@ -52,7 +52,7 @@ export const now = () => current?.now ?? Date.now() / 1000;
/** The platform this page is open on (iPad on Safari says Mac; touch points tell). */
export const platform = (): Platform => platformOf(navigator.userAgent, navigator.maxTouchPoints);
/** The server's disguise is off: plain WireGuard, so any WireGuard app connects. */
export const plainWg = () => current?.server.awg_disguise === false;
const plainWg = () => current?.server.awg_disguise === false;
/** The server's disguise generation, for which apps and versions connect. */
export const preset = (): Preset => current?.server.preset ?? (plainWg() ? 'off' : 'max');
/** The secure twin when this page is plain HTTP, else null. */
+8 -3
View File
@@ -25,18 +25,23 @@ body {
-webkit-font-smoothing: antialiased;
min-height: 100vh;
min-height: 100dvh;
/* An app, not a document: the arrow over text. Controls set the hand; what is typed or copied by
hand (fields, the link, the configuration) keeps the I-beam. */
/* An app, not a document: the arrow over text, and no selecting it (a title, a label, a value is not text to
copy). Controls set the hand; what is typed or copied by hand (fields, the mono text: the link, hostnames, a
file's name; the configuration) can be selected, with the I-beam. */
cursor: default;
-webkit-user-select: none;
user-select: none;
}
body.locked {
overflow: hidden;
}
input,
textarea,
.linkrow .mono,
.mono,
.conf {
cursor: text;
-webkit-user-select: text;
user-select: text;
}
::selection {
background: var(--sel-bg);
+50 -3
View File
@@ -94,6 +94,9 @@
color: #fff;
font-weight: 600;
}
.btn.red:hover {
background: color-mix(in srgb, var(--bad) 82%, transparent);
}
/* Waiting for the router: the button keeps its size, its content blurs away and an orb comes up in
its place (ui/busy.ts runs the change). The orb is B4 Converge from aicss.dev's Orbs, at its own
28px stage and twice its speed: one circle walks a triangle, sharp at each corner and smaller,
@@ -341,7 +344,8 @@
opacity: 0;
transition: opacity 140ms linear;
}
.caret-hd::after {
.caret-hd::after,
.tsel-hd::after {
content: '';
position: absolute;
left: 50%;
@@ -351,16 +355,59 @@
border-radius: 50%;
background: var(--accent);
}
.caret-hd.s::after {
.caret-hd.s::after,
.tsel-hd.s::after {
top: -7px;
}
.caret-hd.e::after {
.caret-hd.e::after,
.tsel-hd.e::after {
bottom: -7px;
}
.field.selecting .caret-sel,
.field.selecting .caret-hd {
opacity: 1;
}
/* The page's own selection (ui/selection.ts), as the fields', where text can be selected (base.css), with a mouse
or trackpad: the native one is see-through, the text keeping its colour (currentcolor), and ours is drawn over it,
one band per line and a handle at each end. A band lies over the text, so it blends: in dark the screen lifts the
ground to the accent wash and leaves the words as they are, in light the multiply. Each band and handle is fixed
in <body> on its own: a box around them would make them blend with nothing but each other. */
.own-tsel .mono::selection,
.own-tsel .mono *::selection,
.own-tsel .conf::selection,
.own-tsel .conf *::selection {
background: transparent;
color: currentcolor;
}
.tsel-band,
.tsel-hd {
position: fixed;
left: 0;
top: 0;
pointer-events: none;
opacity: 0;
transition: opacity 140ms linear;
}
.tsel-band {
border-radius: 4px;
background: color-mix(in srgb, var(--accent) 26%, var(--bg));
mix-blend-mode: screen;
will-change: transform;
}
@media (prefers-color-scheme: light) {
.tsel-band {
mix-blend-mode: multiply;
}
}
.tsel-hd {
width: 2px;
border-radius: 1px;
background: var(--accent);
}
.tsel-band.on,
.tsel-hd.on {
opacity: 1;
}
/* Words on their way to the router (ui/shimmer.ts): the input's own are hidden under a copy that dims and lets a
light band sweep across it, the band the words' colour over a muted base; the caret steps aside meanwhile. */
+2 -6
View File
@@ -38,8 +38,8 @@ body.scrolled .edge-fade.top {
background: linear-gradient(to top in oklab, var(--bg) 0%, transparent 100%);
}
/* The breadcrumb (iconiqui, measured): 32px high, the mark in a 32px box, 15px crumbs 6px apart
with a 14px chevron, the current one brighter. The mark is one colour: the text's. */
/* The breadcrumb (iconiqui, measured): 32px high, the mark in a 32px box, then the place, 15px and
bright (the one crumb: the page is the person's own). The mark is one colour: the text's. */
.crumbs {
display: flex;
align-items: center;
@@ -84,10 +84,6 @@ body.scrolled .edge-fade.top {
color: var(--text);
font-weight: 500;
}
.cr-path .i {
width: 14px;
height: 14px;
}
/* The language (a pick pill, ui/pick.ts): as high as the QR knob beside it, its flag, its code and a chevron
that turns up while the popup is open. */
.cr-lang {
+5
View File
@@ -389,9 +389,14 @@
font: 12px/18px var(--mono);
max-height: 16rem;
overflow: auto;
scrollbar-width: none;
white-space: pre;
color: var(--text-2);
}
/* It scrolls with no bar, as the sheet it sits in. */
.conf::-webkit-scrollbar {
display: none;
}
.conf .k {
color: var(--text);
}
+5
View File
@@ -68,11 +68,16 @@
overflow: hidden;
flex: none;
}
/* It scrolls with no bar: a bar would cut into the sheet's round corners and its glass. */
.sheet-scroll {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
overscroll-behavior: contain;
scrollbar-width: none;
}
.sheet-scroll::-webkit-scrollbar {
display: none;
}
.view {
padding: 0 24px 24px;
+5 -25
View File
@@ -1,29 +1,7 @@
/* The portal's fonts and tokens. Dark first (the skiper21 palette, measured), light by the system's
/* The portal's tokens. Dark first (the skiper21 palette, measured), light by the system's
choice. Surfaces step up in brightness (ground → raised → field → knob) instead of borders; the
accent is the one sky blue, colour otherwise only means state (ok green, warn orange, bad red). */
@font-face {
font-family: Geist;
src: url(geist-latin-wght-normal.woff2) format('woff2');
font-weight: 100 900;
font-display: swap;
unicode-range:
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2190-21FF, U+2212, U+2215;
}
@font-face {
font-family: Geist;
src: url(geist-cyrillic-wght-normal.woff2) format('woff2');
font-weight: 100 900;
font-display: swap;
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
font-family: 'Geist Mono';
src: url(geist-mono-latin-wght-normal.woff2) format('woff2');
font-weight: 100 900;
font-display: swap;
}
:root {
color-scheme: dark;
--bg: #080808;
@@ -84,8 +62,10 @@
--t-orange-a: #ffc08f;
--t-orange-b: #ff8d28;
--font: Geist, -apple-system, system-ui, 'Segoe UI', sans-serif;
--mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
/* Each system's own type, nothing downloaded: SF Pro on Apple, Segoe UI on Windows, Roboto on
Android, the desktop's sans on Linux; SF Mono, Cascadia Mono or Consolas for code. */
--font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', Ubuntu, Cantarell, 'Helvetica Neue', Arial, sans-serif;
--mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, 'Cascadia Mono', Consolas, 'Liberation Mono', 'DejaVu Sans Mono', monospace;
--r-sheet: 36px;
--r-card: 28px;
--r-row: 20px;
+2 -1
View File
@@ -26,7 +26,8 @@ function now(el: Element): Keyframe {
/** What gives way: the button's own elements (a bare word goes into a span first). */
function content(btn: HTMLElement): Element[] {
for (const n of [...btn.childNodes])
// A copy: childNodes is live and the loop replaces nodes in it.
for (const n of Array.from(btn.childNodes))
if (n.nodeType === Node.TEXT_NODE && n.textContent?.trim()) n.replaceWith(h('span', {}, n.textContent));
return [...btn.children].filter((c) => !c.classList.contains('orb'));
}
+1 -1
View File
@@ -25,7 +25,7 @@ export interface Glide {
}
/** The frame the glide is tuned to, in ms. */
const FRAME = 16.67;
export const FRAME = 16.67;
/**
* Move a glide on by `frames` frames (after bencho.dev's one-time code, a softer pull: per frame
+1 -1
View File
@@ -51,7 +51,7 @@ export function toast(msg: string, bad = false) {
}
/** An icon that changes in place: the new one (by name, or one to put back) pops in where the old one stood. */
export function swapIcon(icon: Element, to: string | Element): Element {
function swapIcon(icon: Element, to: string | Element): Element {
const next = typeof to === 'string' ? ic(to, icon.getAttribute('class') ?? 'i') : to;
icon.replaceWith(next);
play(
+1 -1
View File
@@ -136,7 +136,7 @@ const amneziaMark = () =>
let gid = 0;
/** A glass icon as markup (`cls`: its classes, e.g. "gi xl"). */
export function glassSvg(name: string, tone: Tone = 'grey', cls = 'gi'): string {
function glassSvg(name: string, tone: Tone = 'grey', cls = 'gi'): string {
const g = GL[name] ?? GL.other;
const id = `gl${++gid}`;
const detail =
+11 -13
View File
@@ -49,22 +49,20 @@ export function openMenu(anchor: HTMLElement, all: (MenuItem | null)[], title: s
rows.push(b);
return b;
};
const sections: HTMLElement[] = [
...groups.map((g) =>
h(
'div',
{ class: 'pop-grp' },
...g.map((it) =>
item(
it,
'mi',
ic(it.icon),
h('span', { class: 'mi-b' }, h('span', { class: 'mi-l' }, it.label), it.sub ? h('span', { class: 'mi-s' }, it.sub) : null),
),
const sections: HTMLElement[] = groups.map((g) =>
h(
'div',
{ class: 'pop-grp' },
...g.map((it) =>
item(
it,
'mi',
ic(it.icon),
h('span', { class: 'mi-b' }, h('span', { class: 'mi-l' }, it.label), it.sub ? h('span', { class: 'mi-s' }, it.sub) : null),
),
),
),
];
);
// A thin line between sections (iOS's, inset; the rows themselves sit in a 16 px inset).
const body = h(
'div',
+2 -2
View File
@@ -100,12 +100,12 @@ export function kept(a: string[], b: string[]): [number, number][] {
while (q < a.length - p && q < b.length - p && a[a.length - 1 - q] === b[b.length - 1 - q]) q++;
const A = a.slice(p, a.length - q);
const B = b.slice(p, b.length - q);
const L = Array.from({ length: A.length + 1 }, () => new Array<number>(B.length + 1).fill(0));
const L = Array.from({ length: A.length + 1 }, () => Array.from({ length: B.length + 1 }, () => 0));
for (let i = A.length - 1; i >= 0; i--)
for (let j = B.length - 1; j >= 0; j--) L[i][j] = A[i] === B[j] ? L[i + 1][j + 1] + 1 : Math.max(L[i + 1][j], L[i][j + 1]);
const out: [number, number][] = [];
for (let i = 0; i < p; i++) out.push([i, i]);
for (let i = 0, j = 0; i < A.length && j < B.length; ) {
for (let i = 0, j = 0; i < A.length && j < B.length;) {
if (A[i] === B[j]) out.push([p + i++, p + j++]);
else if (L[i + 1][j] >= L[i][j + 1]) i++;
else j++;
+1 -1
View File
@@ -11,7 +11,7 @@ import { appear, EDGE, GAP, opened, vanish } from './drop';
import { glide } from './glide';
import { letterIn, letterOut, morphText, setText } from './morph';
export interface PickOption<T> {
interface PickOption<T> {
value: T;
label: () => string;
/** Before the label, in the popup and on the pill (a dot, a flag): made anew each time it shows. */
+279
View File
@@ -0,0 +1,279 @@
// The page's own text selection, as the name fields draw theirs (ui/caret.ts), with a mouse or trackpad. Little
// of the page can be selected (base.css: what is typed or copied by hand, the mono text and the configuration);
// there the native selection is see-through and this draws an accent wash over each line it covers, a little
// taller than the line, with a handle at each end, as iOS does. Each line's ends glide on the fields' pull
// (glideStep): the wash grows out of where the selection started, follows the pointer, and fades where it stands
// as it collapses; when the text moves or goes (a scroll, a fold, a sheet), it goes along at once. Fields keep their own: a range cannot measure
// an input's text. On a touch screen the system's selection stays, with its own handles.
//
// The wash lies over the text, not under it (it cannot go under every block's), so it blends (controls.css): the
// text keeps its colour and the ground under it takes the accent. It stands on the layer of what holds the
// selection (the page, under its edge fades; a sheet; a dropdown) and is clipped to what clips or scrolls it there.
import { h } from '../dom';
import { calm } from '../motion';
import { FRAME, glideStep, type Glide } from './caret';
/** One run of a line the selection covers, on screen. */
interface Box {
top: number;
height: number;
left: number;
right: number;
}
interface Band {
el: HTMLElement;
top: number;
height: number;
l: Glide;
r: Glide;
}
/** The layer a selection stands on, by what holds it: just over its dropdown or sheet, else under the edge fades. */
const layer = (el: Element): number => (el.closest('.toasts') ? 71 : el.closest('.drop') ? 61 : el.closest('.sheet-root') ? 51 : 29);
/** What shows `el`: the screen, cut by every box around it that clips or scrolls. */
function clipOf(el: Element, seen: Map<Element, Box>): Box {
const had = seen.get(el);
if (had) return had;
const up = el.parentElement;
const c = up ? { ...clipOf(up, seen) } : { top: 0, height: innerHeight, left: 0, right: innerWidth };
const cs = getComputedStyle(el);
if (cs.overflowX !== 'visible' || cs.overflowY !== 'visible') {
const r = el.getBoundingClientRect();
const bottom = Math.min(c.top + c.height, r.bottom);
c.top = Math.max(c.top, r.top);
c.height = Math.max(0, bottom - c.top);
c.left = Math.max(c.left, r.left);
c.right = Math.min(c.right, r.right);
}
seen.set(el, c);
return c;
}
/** The lines `range` covers in what can be selected, one box per run of a line, and the layer they stand on. */
function lines(range: Range): { boxes: Box[]; z: number } {
const root = range.commonAncestorContainer;
const texts: Text[] = [];
if (root instanceof Text) texts.push(root);
else {
const walk = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
for (let n = walk.nextNode(); n; n = walk.nextNode()) if (range.intersectsNode(n)) texts.push(n as Text);
}
const seen = new Map<Element, Box>();
const runs: Box[] = [];
let z = 0;
for (const t of texts) {
const el = t.parentElement;
if (!el) continue;
const cs = getComputedStyle(el);
if ((cs.userSelect || cs.webkitUserSelect) === 'none') continue;
const part = document.createRange();
part.setStart(t, t === range.startContainer ? range.startOffset : 0);
part.setEnd(t, t === range.endContainer ? range.endOffset : t.length);
if (part.collapsed) continue;
z ||= layer(el);
const c = clipOf(el, seen);
for (const q of part.getClientRects()) {
if (q.width < 0.5) continue;
// A little taller than the line, as the fields' wash.
const top = Math.max(c.top, q.top - 1);
const bottom = Math.min(c.top + c.height, q.bottom + 1);
const left = Math.max(c.left, q.left);
const right = Math.min(c.right, q.right);
if (bottom - top >= 0.5 && right - left >= 0.5) runs.push({ top, height: bottom - top, left, right });
}
}
runs.sort((a, b) => a.top - b.top || a.left - b.left);
const boxes: Box[] = [];
for (const q of runs) {
const b = boxes.find((x) => Math.abs(x.top - q.top) < 2 && q.left - x.right < 6 && x.left - q.right < 6);
if (!b) boxes.push({ ...q });
else {
b.left = Math.min(b.left, q.left);
b.right = Math.max(b.right, q.right);
b.height = Math.max(b.height, q.height);
}
}
return { boxes, z };
}
/** The focus before the anchor: the selection was dragged up or to the left. */
function backward(s: Selection): boolean {
if (!s.anchorNode || !s.focusNode) return false;
if (s.anchorNode === s.focusNode) return s.focusOffset < s.anchorOffset;
return !!(s.anchorNode.compareDocumentPosition(s.focusNode) & Node.DOCUMENT_POSITION_PRECEDING);
}
/** Where the selection started, on screen, or null where that has no place (a node with no box). */
function anchorX(s: Selection): number | null {
if (!s.anchorNode) return null;
const r = document.createRange();
r.setStart(s.anchorNode, s.anchorOffset);
const q = r.getBoundingClientRect();
return q.height ? q.left : null;
}
/** Draw the page's selection from now on (a mouse or trackpad only). Call it once. */
export function pageSelection() {
if (!matchMedia('(pointer: fine)').matches) return;
document.documentElement.classList.add('own-tsel');
const h0 = h('span', { class: 'tsel-hd s', 'aria-hidden': 'true' });
const h1 = h('span', { class: 'tsel-hd e', 'aria-hidden': 'true' });
let bands: Band[] = [];
let shown = false;
let gone = 0;
let watch = 0;
let queued = 0;
const jump = (g: Glide) => {
g.x = g.t;
g.v = 0;
};
const draw = () => {
for (const b of bands) {
b.el.style.transform = `translate(${b.l.x.toFixed(2)}px, ${b.top.toFixed(2)}px)`;
b.el.style.width = `${Math.max(0, b.r.x - b.l.x).toFixed(2)}px`;
b.el.style.height = `${b.height.toFixed(2)}px`;
}
const a = bands[0];
const z = bands[bands.length - 1];
if (!a || !z) return;
h0.style.transform = `translate(${(a.l.x - 1).toFixed(2)}px, ${a.top.toFixed(2)}px)`;
h0.style.height = `${a.height.toFixed(2)}px`;
h1.style.transform = `translate(${(z.r.x - 1).toFixed(2)}px, ${z.top.toFixed(2)}px)`;
h1.style.height = `${z.height.toFixed(2)}px`;
};
// One loop for every edge; it stops when all of them rest.
let raf = 0;
let last = 0;
const step = (t: number) => {
const frames = last ? (t - last) / FRAME : 1;
last = t;
let busy = false;
for (const b of bands) for (const g of [b.l, b.r]) if (glideStep(g, frames)) busy = true;
draw();
raf = busy ? requestAnimationFrame(step) : 0;
if (!raf) last = 0;
};
const follow = () => {
if (calm()) {
for (const b of bands) [b.l, b.r].forEach(jump);
return draw();
}
if (!raf) raf = requestAnimationFrame(step);
};
const all = () => [...bands.map((b) => b.el), h0, h1];
// Collapsed: the wash fades where it stands, and is gone once it has.
const fade = () => {
if (!shown) return;
shown = false;
all().forEach((el) => el.classList.remove('on'));
clearTimeout(gone);
gone = window.setTimeout(() => {
if (shown) return;
bands.forEach((b) => b.el.remove());
bands = [];
h0.remove();
h1.remove();
}, 160);
};
/** The selection's lines as they stand; none while a field has the focus (it draws its own). */
const now = (sel: Selection | null) => {
const focus = document.activeElement;
const typing = focus instanceof HTMLInputElement || focus instanceof HTMLTextAreaElement;
return sel && sel.rangeCount && !sel.isCollapsed && !typing ? lines(sel.getRangeAt(0)) : { boxes: [], z: 0 };
};
const place = (still: boolean) => {
const sel = getSelection();
const { boxes, z } = now(sel);
if (!sel || !boxes.length) return fade();
// A new selection grows out of where it started (a wash still fading turns back from where it stands); a line
// it reaches grows from the side it is reached from.
const from = bands.length ? null : anchorX(sel);
const back = backward(sel);
const kept: Band[] = [];
for (const box of boxes) {
let b = bands.find((x) => !kept.includes(x) && Math.abs(x.top - box.top) < 2);
if (!b) {
const x = from ?? (back ? box.right : box.left);
b = {
el: h('span', { class: 'tsel-band', 'aria-hidden': 'true' }),
top: box.top,
height: box.height,
l: { x, v: 0, t: x },
r: { x, v: 0, t: x },
};
document.body.append(b.el);
}
b.top = box.top;
b.height = box.height;
b.l.t = box.left;
b.r.t = box.right;
if (still) [b.l, b.r].forEach(jump);
b.el.style.zIndex = String(z);
kept.push(b);
}
bands.filter((b) => !kept.includes(b)).forEach((b) => b.el.remove());
bands = kept;
h0.style.zIndex = h1.style.zIndex = String(z + 1);
if (!h0.isConnected) document.body.append(h0, h1);
clearTimeout(gone);
draw();
// Drawn where they start before they fade in (a style read in between, so the fade runs).
if (!shown) h0.getBoundingClientRect();
shown = true;
all().forEach((el) => el.classList.add('on'));
follow();
if (!watch) watch = requestAnimationFrame(look);
};
// While it shows, every frame: the text may move or go with no event to say so (a fold closing over it, a
// sheet's view swapped or the sheet shut, a scroll): the wash moves with it at once, or fades where nothing of
// it shows any more. The selection itself stays, as the browser keeps it.
const look = () => {
watch = 0;
if (!shown) return;
if (!queued) {
const { boxes } = now(getSelection());
const same =
boxes.length === bands.length &&
boxes.every((x, i) => {
const b = bands[i];
return (
Math.abs(x.top - b.top) < 0.5 &&
Math.abs(x.height - b.height) < 0.5 &&
Math.abs(x.left - b.l.t) < 0.5 &&
Math.abs(x.right - b.r.t) < 0.5
);
});
if (!same) place(true);
}
if (shown) watch = requestAnimationFrame(look);
};
// After the event: by then the browser has moved its selection.
const soon = () => {
if (!queued)
queued = requestAnimationFrame(() => {
queued = 0;
place(false);
});
};
document.addEventListener('selectionchange', () => soon());
// A press where nothing can be selected lets go of the selection, as a click anywhere does in a document: the
// browser keeps it over text that cannot be selected, and here that is most of the page.
document.addEventListener(
'pointerdown',
(e) => {
if (e.button !== 0 || !(e.target instanceof Element)) return;
const cs = getComputedStyle(e.target);
if ((cs.userSelect || cs.webkitUserSelect) === 'none') getSelection()?.removeAllRanges();
},
true,
);
}
+1 -1
View File
@@ -443,7 +443,7 @@ export function go(factory: ViewFactory) {
swapView(factory());
}
export function back() {
function back() {
if (stack.length < 2 || root.dataset.closing) return;
leave();
stack.pop();
+2 -2
View File
@@ -28,7 +28,7 @@ export interface DeviceLink {
*/
export type SetupState = 'trying' | 'flowing' | 'nodata';
export interface DeviceSetup {
interface DeviceSetup {
state: SetupState;
/** When the watcher first saw it (router clock). */
since: number;
@@ -279,7 +279,7 @@ export interface Status {
like_home: { active: boolean; dev?: string; address?: string; bridged?: boolean; off?: boolean; error?: string };
}
export interface AmneziaFields {
interface AmneziaFields {
host: string;
port: number;
mtu: string;
+1 -1
View File
@@ -121,7 +121,7 @@ export function fromBase64Url(s: string): Uint8Array {
return out;
}
export async function qCompress(data: Uint8Array): Promise<Uint8Array | null> {
async function qCompress(data: Uint8Array): Promise<Uint8Array | null> {
// LuCI's module loader shadows some globals; always go through globalThis.
const g = globalThis as unknown as { CompressionStream?: typeof CompressionStream; Blob: typeof Blob; Response: typeof Response };
if (typeof g.CompressionStream === 'undefined') return null;