Dawnline 0.15.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 device menu (⋯) is an iOS-style menu on frosted glass: the copy
  actions show the address they copy, Rename, Reconnect and Remove sit
  under them, and one highlight glides from row to row
- The language picker shows flags; pick a language with a click, or
  press the pill and slide onto one. The flag and the code change in
  place
- The page's QR code opens as a small card under its button, with Copy
  link and Share
- All dropdowns look and behave the same: frosted glass, one open at a
  time, and a press outside, Escape or the button again closes them
- Setting a device up: when it can't finish connecting or connects but
  passes no data, the sheet keeps just the status and what it means.
  No data now says the router drops its traffic because the address
  doesn't match, and the device's card says "Connected, but no data"
  right away instead of "Connected"
- Setting a phone up from another device: Download and Copy for the
  connection sit on its row, next to the arrow
- On iPhone and iPad the caret shows as soon as a field is focused, the
  page no longer zooms on a pinch or a double tap, and sheets and their
  animations run smoother
- A press near the edge of a button or a card always counts, even as it
  shrinks under the pointer
- Animations settle without a jump at the end
- New green, orange and red
- The focus ring shows only while moving around with the keyboard
This commit is contained in:
Aemeath committed 2026-10-22 04:02:54 +03:00
1 parent a1915f070b
commit ba231e7187
51 files changed
+1713 -1062

No files matched your search

+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "dawnline-web",
"version": "0.14.1",
"version": "0.15.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "dawnline-web",
"version": "0.14.1",
"version": "0.15.0",
"license": "MIT",
"dependencies": {
"qrcode-generator": "1.4.4"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dawnline-web",
"version": "0.14.1",
"version": "0.15.0",
"private": true,
"license": "MIT",
"type": "module",
+6 -10
View File
@@ -1,12 +1,13 @@
// What the demo adds to the breadcrumb: the scenario chip right after the path,
// and a GitHub pill just before the page's language picker (none over a card
// 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 knows nothing of either, so both go back in
// 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.
import { h, ic } from '../dom';
import { onLang } from '../i18n';
import { onCrumbs } from '../page/frame';
import { REPO } from './data';
import { scenarioChip } from './picker';
import type { DemoRouter } from './router';
@@ -15,15 +16,9 @@ export function mountCrumbs(router: DemoRouter) {
const app = document.getElementById('app')!;
const make = () => ({
chip: scenarioChip(router),
gh: h(
'a',
{ class: 'dm-gh', href: REPO, target: '_blank', rel: 'noopener', 'aria-label': _('Dawnline on GitHub') },
ic('github'),
h('span', {}, 'GitHub'),
),
gh: h('a', { class: 'dm-gh', href: REPO, target: '_blank', rel: 'noopener', 'aria-label': _('Dawnline on GitHub') }, ic('github')),
});
let { chip, gh } = make();
// Our own insertions call this again: by then both are in place and nothing moves.
const keep = () => {
const crumbs = app.querySelector('.crumbs');
const path = crumbs?.querySelector('.cr-path');
@@ -32,7 +27,8 @@ export function mountCrumbs(router: DemoRouter) {
const lang = crumbs.querySelector('.cr-lang');
if (lang && lang.previousElementSibling !== gh) lang.before(gh);
};
new MutationObserver(keep).observe(app, { childList: true, subtree: true });
// 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(() => {
+15 -111
View File
@@ -1,5 +1,5 @@
/* 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 pill beside the page's QR knob, the scenario
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 ×. */
@import '../styles/index.css';
@@ -40,20 +40,16 @@
margin-right: 0;
}
/* GitHub: a pill of the QR knob's height and fill, just before it. 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. */
/* 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-flex;
align-items: center;
gap: 6px;
display: inline-grid;
place-items: center;
width: 32px;
height: 32px;
padding: 0 12px 0 10px;
border-radius: 999px;
border-radius: 50%;
background: var(--knob);
color: var(--text);
font-size: 14px;
font-weight: 500;
letter-spacing: -0.01em;
text-decoration: none;
flex: none;
transition:
@@ -179,18 +175,8 @@
.dm-way[aria-expanded='true'] {
background: color-mix(in srgb, var(--knob), var(--text) 10%);
}
.dm-way .i {
width: 14px;
height: 14px;
color: var(--text-2);
transform: rotate(90deg);
transition: transform 240ms var(--ease-out);
}
.dm-way[aria-expanded='true'] .i {
transform: rotate(-90deg);
}
.dm-way .dot,
.dm-way-pop .dot {
.pp-pop .dot {
width: 7px;
height: 7px;
border-radius: 50%;
@@ -200,103 +186,21 @@
opacity 150ms;
}
.dm-way .dot.warn,
.dm-way-pop .dot.warn {
.pp-pop .dot.warn {
background: var(--warn);
}
.dm-way .dot.ok,
.dm-way-pop .dot.ok {
.pp-pop .dot.ok {
background: var(--ok);
}
/* Its popup: segments in one pill frame, a step above the sheet each (white on grey in light), a tail down
to the pill, and a dark, softly blurred halo behind that fades out around it. */
.dm-way-pop {
--frame: color-mix(in srgb, var(--field), var(--knob) 55%);
--seg: color-mix(in srgb, var(--knob), var(--text) 2%);
--seg-hover: color-mix(in srgb, var(--knob), var(--text) 6%);
position: fixed;
z-index: 60;
display: flex;
gap: 3px;
padding: 3px;
border-radius: 999px;
background: var(--frame);
box-shadow: var(--pop-shadow);
}
.dm-way-pop::before {
content: '';
position: absolute;
bottom: -5px;
left: var(--tail, 50%);
width: 12px;
height: 12px;
margin-left: -6px;
border-radius: 0 0 3px 0;
background: var(--frame);
transform: rotate(45deg);
}
.dm-way-pop button {
position: relative;
display: inline-flex;
align-items: center;
gap: 6px;
height: 34px;
padding: 0 10px;
border-radius: 10px;
background: var(--seg);
color: color-mix(in srgb, var(--text-2), var(--text-3) 35%);
font-size: 12.5px;
font-weight: 500;
white-space: nowrap;
transition:
color 150ms,
background-color 150ms,
transform 150ms var(--ease-out);
}
/* The ends follow the frame: half the segment's height (a larger radius would shrink every corner). */
.dm-way-pop button:first-of-type {
border-radius: 17px 10px 10px 17px;
padding-left: 13px;
}
.dm-way-pop button:last-of-type {
border-radius: 10px 17px 17px 10px;
padding-right: 13px;
}
.dm-way-pop button:hover {
color: color-mix(in srgb, var(--text-2), var(--text) 45%);
background: var(--seg-hover);
}
.dm-way-pop button:active {
transform: scale(0.96);
}
.dm-way-pop button[aria-checked='true'] {
color: var(--text);
}
.dm-way-pop .dot {
/* The set-up state's dots in the shared popup (styles/pick.css): faint, full on the one picked or pointed at. */
.pp-pop .dot {
background: currentColor;
opacity: 0.5;
}
.dm-way-pop button[aria-checked='true'] .dot,
.dm-way-pop button:hover .dot {
.pp-pop button[aria-checked='true'] .dot,
.pp-pop button:hover .dot,
.pp-pop button.hot .dot {
opacity: 1;
}
.dm-way-halo {
position: fixed;
z-index: 59;
pointer-events: none;
background: radial-gradient(closest-side, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.35) 55%, transparent);
-webkit-backdrop-filter: blur(3px);
backdrop-filter: blur(3px);
-webkit-mask-image: radial-gradient(closest-side, #000 60%, transparent 92%);
mask-image: radial-gradient(closest-side, #000 60%, transparent 92%);
}
@media (prefers-color-scheme: light) {
.dm-way-pop {
--frame: var(--knob);
--seg: var(--raised);
--seg-hover: color-mix(in srgb, var(--raised), var(--text) 4%);
}
.dm-way-halo {
background: radial-gradient(closest-side, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0.07) 55%, transparent);
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover" />
<meta name="color-scheme" content="light dark" />
<meta
name="description"
+32 -121
View File
@@ -1,13 +1,14 @@
// The demo's set-up state switch: a pill beside the set-up sheet's ×, so a visitor can see each state the way
// shows (waiting, knocks that never finish, no data, connected) without a device. Its popup is a row of segments
// in one pill frame, above the pill with a tail pointing at it and a dark halo behind. Only on the set-up view:
// shows (waiting, knocks that never finish, no data, connected) without a device: a pick pill (ui/pick.ts), its
// popup above it. Only on the set-up view:
// another view in the same sheet (a question, a device's page) fades it out. Picking holds the device in that
// state on the demo's router and polls at once; Auto is the demo's own timing.
// state on the demo's router and polls at once; Auto is the demo's own timing, and where each opening starts.
import { h, ic } from '../dom';
import { EASE_IN, EASE_OUT, POP, play } from '../motion';
import { morphText, setText } from '../ui/morph';
import { h } from '../dom';
import { EASE_IN, SMOOTH, play } from '../motion';
import { pollNow } from '../flows/wait';
import { pickPill, type PickPill } from '../ui/pick';
import { onSheetChange } from '../ui/sheet';
import type { DemoWay } from './data';
import type { DemoRouter } from './router';
@@ -21,11 +22,6 @@ const PICKS: [Pick, () => string, Tone][] = [
['nodata', () => _('No data'), 'warn'],
['connected', () => _('Online'), 'ok'],
];
const pick = (p: Pick) => PICKS.find((x) => x[0] === p)!;
/** The gap between the pill and the popup above it, and how far the halo reaches out (up, sideways, down). */
const GAP = 18;
const HALO = { x: 64, up: 48, down: 14 };
/** Gone from where it stands, so one leaving while it still comes in turns back from there. */
function leave(el: Element, frames: Keyframe, ms: number) {
@@ -49,102 +45,27 @@ function leave(el: Element, frames: Keyframe, ms: number) {
export function mountWayPick(router: DemoRouter) {
/** What each device's pill says: what was picked here, else what the router holds it in. */
const shown = new Map<string, Pick>();
let pop: HTMLElement | null = null;
let halo: HTMLElement | null = null;
let anchor: HTMLElement | null = null;
function closePop() {
if (!pop) return;
leave(pop, { transform: 'scale(.96)', filter: 'blur(3px)' }, 120);
if (halo) leave(halo, {}, 160);
anchor?.setAttribute('aria-expanded', 'false');
pop = halo = anchor = null;
}
function openPop(pill: HTMLElement, id: string, paint: () => void) {
const now = shown.get(id) ?? router.wayOf(id);
const m = h(
'div',
{ class: 'dm-way-pop', role: 'menu' },
...PICKS.map(([p, label, tone]) =>
h(
'button',
{
type: 'button',
role: 'menuitemradio',
'aria-checked': String(p === now),
onclick: () => {
closePop();
shown.set(id, p);
router.holdWay(id, p);
paint();
pollNow();
},
},
h('span', { class: `dot ${tone}` }),
label(),
),
),
);
document.body.append(m);
// Centred over the pill, inside the sheet where it fits (else the screen), the tail on the pill's middle.
const r = pill.getBoundingClientRect();
const box = pill.closest('.sheet')?.getBoundingClientRect() ?? { left: 0, right: innerWidth };
const w = m.offsetWidth;
const mid = r.left + r.width / 2;
const lo = Math.max(12, box.left + 10);
const hi = Math.min(innerWidth - 12, box.right - 10);
const left = Math.max(lo, Math.min(mid - w / 2, hi - w));
const top = r.top - GAP - m.offsetHeight;
Object.assign(m.style, { left: `${left}px`, top: `${top}px`, transformOrigin: `${mid - left}px bottom` });
m.style.setProperty('--tail', `${mid - left}px`);
// The halo reaches up and out but stops short of the pill, which stays sharp.
const sc = h('div', { class: 'dm-way-halo' });
Object.assign(sc.style, {
left: `${left - HALO.x}px`,
top: `${top - HALO.up}px`,
width: `${w + HALO.x * 2}px`,
height: `${m.offsetHeight + HALO.up + HALO.down}px`,
});
m.before(sc);
play(sc, [{ opacity: 0 }, { opacity: 1 }], { duration: 220, easing: EASE_OUT });
play(
m,
[
{ opacity: 0, transform: 'scale(.9)', filter: 'blur(4px)' },
{ opacity: 1, transform: 'none', filter: 'none' },
],
{ duration: POP.duration, easing: POP.easing },
);
pop = m;
halo = sc;
anchor = pill;
pill.setAttribute('aria-expanded', 'true');
}
/** The pill on the sheet now. */
let live: PickPill<Pick> | null = null;
function makePill(id: string): HTMLElement {
const dot = h('span', { class: 'dot' });
const lbl = h('span', {});
const pill = h(
'button',
{ type: 'button', class: 'dm-way', 'aria-haspopup': 'menu', 'aria-expanded': 'false', 'aria-label': _('Set-up state') },
dot,
lbl,
ic('chevron', 'i'),
);
const paint = (morph = true) => {
const [, label, tone] = pick(shown.get(id) ?? router.wayOf(id));
dot.className = `dot ${tone}`;
if (morph) morphText(lbl, label());
else setText(lbl, label());
};
paint(false);
pill.addEventListener('click', () => (anchor === pill ? closePop() : (closePop(), openPop(pill, id, () => paint()))));
return pill;
live = pickPill<Pick>({
cls: 'dm-way',
label: () => _('Set-up state'),
options: PICKS.map(([value, label, tone]) => ({ value, label, lead: () => h('span', { class: `dot ${tone}` }) })),
value: shown.get(id) ?? router.wayOf(id),
pick: (p) => {
shown.set(id, p);
router.holdWay(id, p);
pollNow();
// Its width glides with its words (SMOOTH): the title makes room for where it ends.
setTimeout(place, SMOOTH.duration + 40);
},
});
return live.el;
}
function place() {
if (anchor && !anchor.isConnected) closePop();
const sheet = document.querySelector<HTMLElement>('.sheet-root.open .sheet');
const id = router.settingUp();
const setup = !!sheet && !!id && !!sheet.querySelector('.way') && !sheet.classList.contains('asks');
@@ -152,12 +73,18 @@ export function mountWayPick(router: DemoRouter) {
if (setup && el.parentElement === sheet && el.dataset.id === id) return;
el.classList.add('gone');
el.parentElement?.querySelectorAll<HTMLElement>('.vhead').forEach((hd) => (hd.style.paddingRight = ''));
if (anchor === el) closePop();
if (live?.el === el) {
live.close();
live = null;
}
leave(el, { transform: 'scale(.9)', filter: 'blur(3px)' }, 160);
});
if (!sheet || !setup || !id) return;
let pill = sheet.querySelector<HTMLElement>('.dm-way:not(.gone)');
if (!pill) {
// A set-up opened anew starts from the default: the demo's own timing, nothing held from the last time.
shown.delete(id);
if (router.wayOf(id) !== 'auto') router.holdWay(id, 'auto');
pill = makePill(id);
pill.dataset.id = id;
sheet.append(pill);
@@ -179,22 +106,6 @@ export function mountWayPick(router: DemoRouter) {
}
}
new MutationObserver(place).observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] });
document.addEventListener('pointerdown', (e) => {
const t = e.target as Element;
if (pop && !pop.contains(t) && !anchor?.contains(t)) closePop();
});
// Escape takes the popup only, not the sheet under it.
document.addEventListener(
'keydown',
(e) => {
if (!pop || e.key !== 'Escape') return;
e.stopPropagation();
closePop();
},
true,
);
// A wheel or a swipe closes it; the sheet's own scroll as it settles does not.
for (const ev of ['wheel', 'touchmove'])
addEventListener(ev, (e) => pop && !pop.contains(e.target as Node) && closePop(), { passive: true, capture: true });
// The sheet says when it changes (a view shown, the device arrived, the sheet gone): nothing to watch.
onSheetChange(place);
}
+71 -17
View File
@@ -1,22 +1,76 @@
// This page on another device: from the breadcrumb, its link as a code for a
// phone's camera, and the link itself to copy or share.
// This page on another device: a dropdown from the breadcrumb's QR knob (ui/drop.ts: placed, coming and going and
// shut as every dropdown is), the page's link as a code for a phone's camera, and under it Copy link (it says
// Copied for a moment) and Share where the system has it.
import { h } from '../dom';
import { pageUrl } from '../state';
import { linkRow, qrBox } from '../ui/codes';
import { head, openSheet, sub } from '../ui/sheet';
import { h, ic } from '../dom';
import { placeName, pageUrl } from '../state';
import { qrBox } from '../ui/codes';
import { appear, closeDrop, EDGE, GAP, opened, vanish } from '../ui/drop';
import { copy } from '../ui/feedback';
export function showPageCode() {
openSheet(() => {
const url = pageUrl();
const el = h(
/** The card open now, to shut at once when its knob goes with the breadcrumb. */
let open: ((now?: boolean) => void) | null = null;
export const closePageCode = (now = false) => open?.(now);
export function showPageCode(knob: HTMLElement) {
if (knob.getAttribute('aria-expanded') === 'true') return closeDrop();
const url = pageUrl();
const share = typeof navigator.share === 'function';
const card = h(
'div',
{ class: 'pc-card drop', role: 'dialog', 'aria-label': _('Open on another device') },
qrBox(url, true),
h(
'div',
{ class: 'view' },
head(_('Open on another device')),
sub(_('Point its camera at the code: this page opens there.')),
qrBox(url, true),
linkRow(url),
);
return { el, label: _('Open on another device') };
{ class: 'pc-row' },
h(
'button',
{
type: 'button',
class: 'pc-copy',
'aria-label': _('Copy the link'),
onclick: (e: Event) => copy(url, _('Link copied'), e.currentTarget),
},
ic('link'),
h('span', { class: 'lbl' }, _('Copy link')),
),
share
? h(
'button',
{
type: 'button',
class: 'knob',
'aria-label': _('Share the link'),
onclick: () => navigator.share({ url, title: placeName() }).catch(() => undefined),
},
ic('share'),
)
: null,
),
);
document.body.append(card);
// Under the knob where it fits, else over it; centred on it inside the screen's edge, growing from its side.
const r = knob.getBoundingClientRect();
const w = card.offsetWidth;
const ht = card.offsetHeight;
const mid = r.left + r.width / 2;
const left = Math.max(EDGE, Math.min(mid - w / 2, innerWidth - EDGE - w));
const below = r.bottom + GAP + ht <= innerHeight - EDGE || r.top - GAP - ht < EDGE;
const top = below ? r.bottom + GAP : r.top - GAP - ht;
Object.assign(card.style, {
left: `${left + scrollX}px`,
top: `${top + scrollY}px`,
transformOrigin: `${mid - left}px ${below ? 0 : ht}px`,
});
appear(card);
const release = opened(card, knob, close);
open = close;
function close(instant = false) {
if (!release()) return;
if (open === close) open = null;
if (instant) card.remove();
else vanish(card);
}
}
+3 -3
View File
@@ -335,7 +335,7 @@ export interface ConnPill {
}
/**
* Beside ×: the connection itself, to download or copy, where the sheet offers
* On its row, beside the chevron: the connection itself, to download or copy, where the sheet offers
* neither (a phone or a tablet set up from elsewhere). One tooltip for both
* keys, under them: the first waits a beat; once one is up the next comes at
* once and the tooltip glides across (by Tab too, and back to a key while it
@@ -354,11 +354,11 @@ export function connPill(get: () => { text: string; msg: string; file: string; a
let tipT = 0;
let warmUntil = 0;
const words = (b: HTMLElement) => (b === cp && cp.classList.contains('done') ? _('Copied') : (b.getAttribute('aria-label') ?? ''));
// Centred under its key, but never past the sheet's edge (× and its margin to the right).
// Centred under its key, but never past its row's edge (the chevron and the row's inset to the right).
const centre = (b: HTMLElement, t: string) => {
tm.textContent = t;
const w = tm.offsetWidth + 20;
return Math.min(b.offsetLeft + b.offsetWidth / 2, el.offsetWidth + 46 - w / 2);
return Math.min(b.offsetLeft + b.offsetWidth / 2, el.offsetWidth + 30 - w / 2);
};
const at = (x: number) => `translateX(${x}px) translateX(-50%)`;
/** Where the tooltip stands now: mid-fade and mid-glide included. */
+36 -99
View File
@@ -6,8 +6,8 @@
// computer, or another device added from a phone, its link or the connection
// to send there. Which app and where it comes from follow the
// server's disguise and the platform (setup.ts). The wait for the first
// connection sits on top the whole time (wait.ts); on the device itself and for
// a router the steps regroup under it as it goes (can't finish, no data).
// connection sits on top the whole time (wait.ts); once the device is heard
// from (can't finish, no data, connected) what is under it folds away.
import type { ClientConfig, Device } from '../../shared/types';
import { fmt } from '../../shared/i18n';
@@ -17,7 +17,7 @@ import { h, put } from '../dom';
import { SMOOTH, play } from '../motion';
import { APP_NAME, appsFor, deviceNoun, inWebview, keyFileName, sameDevice, setupLink, type AppId } from '../setup';
import { pageUrl, platform, preset, repaint } from '../state';
import { accordion, regrow, type Accordion } from '../ui/accordion';
import { accordion, regrow } from '../ui/accordion';
import { codeRow, linkRow, type CodeRow } from '../ui/codes';
import { once, toast } from '../ui/feedback';
import { glass } from '../ui/glass';
@@ -39,7 +39,6 @@ import {
storeBlock,
type SetupCtx,
} from './setup-parts';
import type { WayState } from '../way';
import { follow, waitWay, watchFirstConnection } from './wait';
async function getConfig(d: Device): Promise<ClientConfig | null> {
@@ -114,66 +113,6 @@ function foldBlock(el: HTMLElement, fold: boolean, instant: boolean) {
};
}
/** The first control in `el` that can take focus now (shown, not disabled). */
const firstControl = (el: Element | null | undefined) =>
[...(el?.querySelectorAll<HTMLElement>('button:not([disabled]), a[href], input:not([disabled])') ?? [])].find(
(x) => x.getClientRects().length > 0,
);
/**
* The steps on the device itself or for a router, as the way goes (way.ts); the
* layouts set up from elsewhere have rows, no steps. Waiting: the steps as
* built (connected is never asked: what shows folds shut as it is, wait.ts
* follow). Can't finish: the network is the likely cause, so they fold
* into one closed row, "Set it up again". No data: only what fixes it, open in
* one row, "Add the connection again" ("Import the configuration again" for a
* router): the connection step without its number and title. A router that
* knocks has AmneziaWG on it already, so its row holds that step alone in both.
* What sits on field inside the row steps up one (accordion.css). "Not on the X
* right now?" (`round`, on the device itself) goes in both: the device is in
* hand. Focus inside what moves (a badge just used) stays in the sheet: on that
* control where it still shows, else on the first one of what holds the steps
* now. Returns whether anything changed.
*/
function regroup(body: HTMLElement, steps: HTMLElement, round: Accordion | null, router: boolean): (st: WayState) => boolean {
const [s1, s2] = [...steps.children].slice(-2) as HTMLElement[];
const gap = steps.querySelector<HTMLElement>(':scope > .steps-gap');
const head2 = [...s2.querySelectorAll<HTMLElement>(':scope > .step-n, :scope > .step-b > .step-t')];
let look: 'steps' | 'again' | 'conn' = 'steps';
let row: HTMLElement | null = null;
return (st) => {
const next = st === 'trying' ? 'again' : st === 'nodata' ? 'conn' : 'steps';
if (next === look) return false;
look = next;
// Moving a focused control out of the page and back drops its focus (to the page under the sheet).
const had = document.activeElement;
const inside = had instanceof HTMLElement && (steps.contains(had) || !!round?.el.contains(had) || !!row?.contains(had));
row?.remove();
row = null;
// The steps show whole wherever they go: opened, the way round folds them away.
round?.setOpen(-1);
if (round) round.el.hidden = next !== 'steps';
const alone = next === 'conn' || (next === 'again' && router);
for (const e of [gap, s1, ...head2]) if (e) e.hidden = alone;
if (next === 'steps') body.append(steps);
else {
const title = next === 'again' ? _('Set it up again') : router ? _('Import the configuration again') : _('Add the connection again');
row = accordion([{ icon: glass('refresh', 'blue'), title, body: [steps] }], { inset: true, open: next === 'conn' ? 0 : -1 }).el;
body.append(row);
}
if (inside) {
const to =
had.isConnected && had.getClientRects().length
? had
: next === 'again'
? row?.querySelector<HTMLElement>('.acc-head')
: firstControl(alone ? s2 : steps);
to?.focus({ preventScroll: true });
}
return true;
};
}
type Layout = 'same' | 'router' | 'away' | 'pc-away';
export function setupView(d: Device, cfg: ClientConfig, key: string, here = false): View {
@@ -280,52 +219,50 @@ export function setupView(d: Device, cfg: ClientConfig, key: string, here = fals
: h('p', { class: 'desc' }, fmt(_('Open this link on the %s to set it up there.'), thereOn)),
linkRow(linkThere),
];
const step1 = () => step('1', title1, [picker(), getBox]);
const step2 = () => step('2', router ? _('Import the configuration') : _('Add the connection'), [addBox]);
const inSteps = layout === 'same' || layout === 'router';
// The connection, one element: its picker (none in step 2: step 1's is there) and its layout's box.
const pickEl = inSteps ? null : picker();
const pick = pickEl ? h('div', { class: 'conn-pick' }, pickEl) : null;
const box = layout === 'away' ? codeBox : layout === 'pc-away' ? sendBox : addBox;
const conn = h('div', { class: 'conn' }, pick, box);
const body = h('div', { class: 'setup' });
if (inWebview(navigator.userAgent))
body.appendChild(
notice('warn', 'shield', null, _('Open this page in Safari or Chrome: the store opens from here, but the app handoff does not.')),
);
let shape: (st: WayState) => boolean = () => false;
const steps = () =>
h(
'div',
{ class: 'steps-wrap' },
layout === 'same' ? h('div', { class: 'steps-gap' }) : null,
step('1', title1, [picker(), getBox]),
step('2', router ? _('Import the configuration') : _('Add the connection'), [conn]),
);
/** The link to the device and the connection beside it, as rows (`open`: the one open as it starts). */
const rows = (icon: string, title: string, open: number, aside: Node | null = null) =>
accordion(
[
{ icon: glass('link'), title: fmt(_('Open your link on the %s'), thereOn), body: linkBody() },
{ icon: glass(icon), title, body: [conn], aside },
],
{ inset: true, open },
).el;
if (layout === 'same') {
// Opened, the way round folds the steps away: the device is not in hand.
const steps = h('div', { class: 'steps-wrap' }, h('div', { class: 'steps-gap' }), step1(), step2());
const s = steps();
const round = accordion([{ icon: glass('link'), title: fmt(_('Not on the %s right now?'), thereOn), body: linkBody() }], {
inset: true,
onToggle: (_i, open, instant) => foldBlock(steps, open, instant),
onToggle: (_i, open, instant) => foldBlock(s, open, instant),
});
body.append(round.el, steps);
shape = regroup(body, steps, round, false);
} else if (layout === 'router') {
const steps = h('div', { class: 'steps-wrap' }, step1(), step2());
body.append(steps);
shape = regroup(body, steps, null, true);
}
body.append(round.el, s);
} else if (layout === 'router') body.append(steps());
// A phone or a tablet set up from here: its link as a code, or the connection as a code for an app it has.
else if (layout === 'away')
body.appendChild(
accordion(
[
{ icon: glass('link'), title: fmt(_('Open your link on the %s'), thereOn), body: linkBody() },
{ icon: glass('app'), title: _('Already has the app'), body: [picker(), codeBox] },
],
{ inset: true, open: 1 },
).el,
);
// The connection's download and copy sit on its own row, while it is open.
else if (layout === 'away') body.append(rows('app', _('Add the connection'), 1, pill?.el ?? null));
// A computer set up from somewhere else, or something else (a TV, a box, a NAS) set up from a phone: its system is
// not known here, so the link goes there and the page there does both steps.
else
body.appendChild(
accordion(
[
{ icon: glass('link'), title: fmt(_('Open your link on the %s'), thereOn), body: linkBody() },
{ icon: glass('key'), title: _('Copy or save the connection'), body: [picker(), sendBox] },
],
{ inset: true, open: 0 },
).el,
);
else body.append(rows('key', _('Copy or save the connection'), 0));
const subline = sub(
layout === 'same'
@@ -335,12 +272,12 @@ export function setupView(d: Device, cfg: ClientConfig, key: string, here = fals
: fmt(_('The app goes on the %s.'), there),
);
const way = waitWay(d);
const wait = follow(d, way, { sub: subline, rest: body, shape });
const wait = follow(d, way, { sub: subline, rest: body });
onLeave(watchFirstConnection(d, wait.seen, wait.gaveUp));
// Closed before the device connected: the page shows what the polls brought.
onClosed(() => repaint());
const title = fmt(_('Set up %s'), d.name);
const el = h('div', { class: 'view' }, head(title, { acts: !!pill }), subline, way.el, body);
return { el, label: title, acts: pill?.el ?? null };
const el = h('div', { class: 'view' }, head(title), subline, way.el, body);
return { el, label: title };
}
+22 -43
View File
@@ -4,8 +4,9 @@
// the sheet around it keeping pace. Connected, the way fills green and its line
// morphs into "<device> connected", × and the sheet's buttons step away,
// everything under the way folds shut and the sheet closes by itself onto the
// page; any other state undoes that. What sits under the way in each state is
// the view's (setup-view.ts hands it over as `Around`).
// page. Can't finish and no data fold what is under the way the same and keep
// the sheet; waiting again unfolds it. What sits under the way is the view's
// (setup-view.ts hands it over as `Around`).
import type { Device } from '../../shared/types';
import { fmt } from '../../shared/i18n';
@@ -13,7 +14,7 @@ import { gone, call } from '../api';
import { h, ic } from '../dom';
import { EASE_IN, EASE_OUT, calm, play } from '../motion';
import { now, repaint, setState, type State } from '../state';
import { menuOpen } from '../ui/menu';
import { dropOpen } from '../ui/drop';
import { morphText, setText, textOf } from '../ui/morph';
import { closeSheet, onClosed, scrollTop, settle, showing } from '../ui/sheet';
import { wayState, type WayState } from '../way';
@@ -34,7 +35,7 @@ function lines(st: WayState, d: Device): [string, string] {
case 'connected':
return [fmt(_('%s connected'), d.name), ''];
case 'nodata':
return [_('Handshake complete, but no data'), _('This device is using an outdated configuration.')];
return [_('Handshake complete, but no data'), _('The router drops its traffic: the address does not match.')];
case 'waiting':
return [_('Waiting for the connection'), ''];
}
@@ -185,7 +186,7 @@ function catchUp(id: string, tries = 4) {
try {
const st = await call<State>('state');
setState(st);
if (!menuOpen()) repaint();
if (!dropOpen()) repaint();
if (!st.person.devices.find((x) => x.id === id)?.online && tries > 1) catchUp(id, tries - 1);
} catch {
/* a hiccup: the page keeps the last answer, as on load */
@@ -274,8 +275,6 @@ export interface Around {
sub: HTMLElement;
/** Everything under the way. */
rest: HTMLElement;
/** Give what is under the way its shape for this state, at once (the glide is here); false: nothing changed. */
shape(st: WayState): boolean;
}
/** Blocks folded away, held at nothing until they come back. */
@@ -337,28 +336,6 @@ function gap(way: HTMLElement, away: boolean) {
play(way, [{ marginBottom: from }, { marginBottom: to }], { duration: 520, easing: EASE_OUT, fill: away ? 'forwards' : 'none' });
}
/** What is under the way takes another shape: it glides to its new height, and what came in blurs in. */
function reshape(a: Around, st: WayState) {
const rest = a.rest;
// From where it stands on screen (a glide under way included) to its new height.
const h0 = rest.getBoundingClientRect().height;
if (!a.shape(st)) return;
rest.getAnimations().forEach((x) => x.cancel());
const h1 = rest.getBoundingClientRect().height;
rest.style.overflow = 'hidden';
play(rest, [{ height: `${h0}px` }, { height: `${h1}px` }], { duration: 420, easing: EASE_OUT }).onfinish = () => {
rest.style.overflow = '';
};
play(
rest,
[
{ opacity: 0.4, filter: 'blur(2px)' },
{ opacity: 1, filter: 'none' },
],
{ duration: 320, easing: EASE_OUT },
);
}
/** What the sheet does as the wait goes on (follow). */
export interface Following {
/** A new state of the way. */
@@ -371,14 +348,23 @@ export interface Following {
* The sheet keeps pace with the way. Connected: × and the buttons beside it
* step away, the sheet goes back up to the way if it was scrolled, everything
* under the way folds shut with the way's gap to it, and after two seconds to
* read it the sheet closes by itself onto the page, the card ringing green. Any
* other state undoes that (× comes back, what folded unfolds) and gives what is
* under the way its shape. The subtitle says what setting up takes, so it shows
* only while waiting: once the device is heard from, or the wait gives up, it
* folds away, the way then right under the head.
* read it the sheet closes by itself onto the page, the card ringing green.
* Can't finish or no data: what is under the way folds shut the same, at once,
* and the sheet stays (adding the connection again would not help: the way
* says what would). Waiting again undoes that (× comes back, what folded
* unfolds). The subtitle says what setting up takes, so it shows only while
* waiting: once the device is heard from, or the wait gives up, it folds away,
* the way then right under the head.
*/
export function follow(d: Device, way: Way, a: Around): Following {
/** What is under the way is folded shut, the way's gap to it with it. */
let shut = false;
const shutRest = (away: boolean) => {
if (shut === away) return;
shut = away;
fold(a.rest, away, 520);
gap(way.el, away);
};
let timers: number[] = [];
const later = (ms: number, f: () => void) => timers.push(window.setTimeout(f, ms));
const seen = (st: WayState) => {
@@ -391,9 +377,7 @@ export function follow(d: Device, way: Way, a: Around): Following {
scrollTop();
later(400, () => {
if (!showing(way.el)) return;
shut = true;
fold(a.rest, true, 520);
gap(way.el, true);
shutRest(true);
// Reading time, not motion: the same with less motion.
later(2400, () => {
// Only this sheet: not one the visitor went on to.
@@ -404,12 +388,7 @@ export function follow(d: Device, way: Way, a: Around): Following {
});
return;
}
if (!shut) return reshape(a, st);
// Folded while it was connected: it unfolds straight into its new shape.
shut = false;
a.shape(st);
fold(a.rest, false, 520);
gap(way.el, false);
shutRest(st !== 'waiting');
};
return {
seen,
+12 -24
View File
@@ -230,10 +230,6 @@ msgstr ""
msgid "Add the connection"
msgstr ""
#: web/src/portal/flows/setup-view.ts
msgid "Add the connection again"
msgstr ""
#: web/src/portal/page/devices.ts
msgid "Add this device"
msgstr ""
@@ -255,10 +251,6 @@ msgstr ""
msgid "Address copied"
msgstr ""
#: web/src/portal/flows/setup-view.ts
msgid "Already has the app"
msgstr ""
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/devices.uc
msgid "AmneziaWG is not installed (%s): install it in Dawnline → Components."
msgstr ""
@@ -378,6 +370,10 @@ msgstr ""
msgid "Copy IP address"
msgstr ""
#: web/src/portal/flows/page-code.ts
msgid "Copy link"
msgstr ""
#: web/src/portal/page/devices.ts
msgid "Copy local address"
msgstr ""
@@ -399,6 +395,7 @@ msgctxt "in a sentence"
msgid "Copy the key"
msgstr ""
#: web/src/portal/flows/page-code.ts
#: web/src/portal/ui/codes.ts
msgid "Copy the link"
msgstr ""
@@ -677,10 +674,6 @@ msgstr ""
msgid "Import the configuration"
msgstr ""
#: web/src/portal/flows/setup-view.ts
msgid "Import the configuration again"
msgstr ""
#: web/src/portal/setup.ts
msgctxt "WireGuard app"
msgid "Import tunnel(s) from file…"
@@ -790,6 +783,7 @@ msgstr ""
msgid "Last connected %s"
msgstr ""
#: web/src/portal/flows/page-code.ts
#: web/src/portal/ui/codes.ts
msgid "Link copied"
msgstr ""
@@ -1037,10 +1031,6 @@ msgstr ""
msgid "Point its camera at the code: the link opens there."
msgstr ""
#: web/src/portal/flows/page-code.ts
msgid "Point its camera at the code: this page opens there."
msgstr ""
#: web/src/portal/flows/add.ts
msgid "Point its camera at the code: your page opens there with this device ready to add."
msgstr ""
@@ -1149,10 +1139,6 @@ msgstr ""
msgid "Server is turned off"
msgstr ""
#: web/src/portal/flows/setup-view.ts
msgid "Set it up again"
msgstr ""
#: web/src/portal/flows/setup-view.ts
#: web/src/portal/page/devices.ts
msgid "Set up %s"
@@ -1182,6 +1168,7 @@ msgstr ""
msgid "Share the file"
msgstr ""
#: web/src/portal/flows/page-code.ts
#: web/src/portal/ui/codes.ts
msgid "Share the link"
msgstr ""
@@ -1274,6 +1261,11 @@ msgstr ""
msgid "The router can’t use what it sends: reconnect it."
msgstr ""
#: web/src/portal/flows/wait.ts
#: web/src/portal/page/devices.ts
msgid "The router drops its traffic: the address does not match."
msgstr ""
#: web/src/portal/flows/setup-parts.ts
msgid "Then come back here and tap"
msgstr ""
@@ -1290,10 +1282,6 @@ msgstr ""
msgid "This device"
msgstr ""
#: web/src/portal/flows/wait.ts
msgid "This device is using an outdated configuration."
msgstr ""
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
msgid "This key is already in use."
msgstr ""
+12 -24
View File
@@ -235,10 +235,6 @@ msgstr "Добавить с самого устройства"
msgid "Add the connection"
msgstr "Добавьте подключение"
#: web/src/portal/flows/setup-view.ts
msgid "Add the connection again"
msgstr "Добавить заново"
#: web/src/portal/page/devices.ts
msgid "Add this device"
msgstr "Добавить это устройство"
@@ -260,10 +256,6 @@ msgstr "Сейчас добавить устройство нельзя: VPN-с
msgid "Address copied"
msgstr "Адрес скопирован"
#: web/src/portal/flows/setup-view.ts
msgid "Already has the app"
msgstr "Приложение уже установлено"
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/devices.uc
msgid "AmneziaWG is not installed (%s): install it in Dawnline → Components."
msgstr "AmneziaWG не установлен (%s): установите его в Dawnline → Компоненты."
@@ -383,6 +375,10 @@ msgstr "Скопировать конфигурацию %s"
msgid "Copy IP address"
msgstr "Скопировать IP-адрес"
#: web/src/portal/flows/page-code.ts
msgid "Copy link"
msgstr "Скопировать ссылку"
#: web/src/portal/page/devices.ts
msgid "Copy local address"
msgstr "Скопировать локальный адрес"
@@ -404,6 +400,7 @@ msgctxt "in a sentence"
msgid "Copy the key"
msgstr "Скопируйте ключ"
#: web/src/portal/flows/page-code.ts
#: web/src/portal/ui/codes.ts
msgid "Copy the link"
msgstr "Скопировать ссылку"
@@ -682,10 +679,6 @@ msgstr "Импорт из файла или архива"
msgid "Import the configuration"
msgstr "Импортируйте конфигурацию"
#: web/src/portal/flows/setup-view.ts
msgid "Import the configuration again"
msgstr "Импортировать заново"
#: web/src/portal/setup.ts
msgctxt "WireGuard app"
msgid "Import tunnel(s) from file…"
@@ -795,6 +788,7 @@ msgstr "За 7 дней"
msgid "Last connected %s"
msgstr "В сети %s"
#: web/src/portal/flows/page-code.ts
#: web/src/portal/ui/codes.ts
msgid "Link copied"
msgstr "Ссылка скопирована"
@@ -1042,10 +1036,6 @@ msgstr "Выберите файл и подключитесь"
msgid "Point its camera at the code: the link opens there."
msgstr "Наведите камеру устройства на код - ссылка откроется на нём."
#: web/src/portal/flows/page-code.ts
msgid "Point its camera at the code: this page opens there."
msgstr "Наведите камеру устройства на код - там откроется эта страница."
#: web/src/portal/flows/add.ts
msgid "Point its camera at the code: your page opens there with this device ready to add."
msgstr "Наведите камеру устройства на код - там откроется ваша страница, и его можно будет сразу добавить."
@@ -1154,10 +1144,6 @@ msgstr "Сервер выключен"
msgid "Server is turned off"
msgstr "Сервер выключен"
#: web/src/portal/flows/setup-view.ts
msgid "Set it up again"
msgstr "Настроить заново"
#: web/src/portal/flows/setup-view.ts
#: web/src/portal/page/devices.ts
msgid "Set up %s"
@@ -1187,6 +1173,7 @@ msgstr "Поделиться файлом"
msgid "Share the file"
msgstr "Поделиться файлом"
#: web/src/portal/flows/page-code.ts
#: web/src/portal/ui/codes.ts
msgid "Share the link"
msgstr "Поделиться ссылкой"
@@ -1279,6 +1266,11 @@ msgstr "У человека нет сервера."
msgid "The router can’t use what it sends: reconnect it."
msgstr "Роутер не принимает то, что отправляет устройство: переподключите его."
#: web/src/portal/flows/wait.ts
#: web/src/portal/page/devices.ts
msgid "The router drops its traffic: the address does not match."
msgstr "Роутер отбрасывает его трафик: адрес не совпадает."
#: web/src/portal/flows/setup-parts.ts
msgid "Then come back here and tap"
msgstr "Затем вернитесь сюда и нажмите"
@@ -1295,10 +1287,6 @@ msgstr "Это подключение стоит на двух устройст
msgid "This device"
msgstr "Это устройство"
#: web/src/portal/flows/wait.ts
msgid "This device is using an outdated configuration."
msgstr "На этом устройстве устаревшая конфигурация."
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
msgid "This key is already in use."
msgstr "Этот ключ уже используется."
+18 -4
View File
@@ -18,9 +18,10 @@ import { fillNotice, stateNotice } from './page/notices';
import { devicesNow, devicesSection, fillDevices } from './page/devices';
import { accessSection, fillAccess } from './page/access';
import { glass, type Tone } from './ui/glass';
import { closeMenu, menuOpen } from './ui/menu';
import { closeDrop, dropOpen } from './ui/drop';
import { closeSheet, sheetOpen } from './ui/sheet';
import { renaming } from './flows/rename';
import { keepPressFootprint } from './ui/press';
import { startAdd } from './flows/add';
import { openSetup } from './flows/setup-view';
@@ -191,7 +192,7 @@ async function refresh() {
try {
setState(await call<State>('state'));
// Not under an open sheet or menu, nor a name being edited on its card.
if (!sheetOpen() && !menuOpen() && !renaming()) render();
if (!sheetOpen() && !dropOpen() && !renaming()) render();
openFromLink();
} catch (e) {
if (gone(e)) linkGone();
@@ -202,15 +203,28 @@ async function refresh() {
// Another language: everything is drawn again in it, the sections too (their headings are text).
onLang(() => {
closeMenu(true);
closeDrop(true);
parts = null;
redraw();
});
// A press that shrinks a control under the pointer still lands on it (ui/press.ts).
keepPressFootprint();
// 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);
document.addEventListener('pointerdown', () => document.documentElement.classList.remove('kbd'), true);
// The page keeps its scale, as an app does: Safari on iOS zooms on a pinch whatever the viewport says, its own
// gesture events are the only way to stop it (the viewport and touch-action take care of the rest).
for (const ev of ['gesturestart', 'gesturechange', 'gestureend'])
document.addEventListener(ev, (e) => e.preventDefault(), { passive: false });
// What the keyboard does never animates.
document.addEventListener('keydown', (e) => {
if (e.key !== 'Escape') return;
if (menuOpen()) closeMenu(true);
if (dropOpen()) closeDrop(true);
else if (sheetOpen()) closeSheet(true);
});
+30 -4
View File
@@ -8,8 +8,25 @@
// BOUNCY is the skiper103 accordion (about 11% overshoot), SMOOTH the skiper21
// tab pill (critically damped). Reduced motion keeps fades and drops travel.
/** Asked once and kept (it answers as the setting changes): play() asks on every animation. */
const REDUCE = typeof matchMedia === 'function' ? matchMedia('(prefers-reduced-motion: reduce)') : null;
/** The visitor asked for less motion: fades only, nothing travels. */
export const calm = (): boolean => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
export const calm = (): boolean => !!REDUCE?.matches;
/** Past this many px² a blur is a large layer's, drawn anew on every frame: it fades without. */
const BIG_BLUR = 30_000;
/**
* A large element's frames without their blur (a fold, an accordion's body, a sheet): opacity, movement and size
* go on as they were. Letters, icons and small things keep theirs.
*/
function lean(el: Element, frames: Keyframe[]): Keyframe[] {
if (!frames.some((f) => 'filter' in f)) return frames;
const r = el.getBoundingClientRect();
if (r.width * r.height < BIG_BLUR) return frames;
return frames.map(({ filter: _f, ...f }) => f);
}
export interface Spring {
/** Until it settles within 0.15% of the end. */
@@ -38,11 +55,16 @@ export function spring(k: number, c: number, m = 1): Spring {
let end = 0;
for (let t = 0; t < 3; t += 0.004) if (Math.abs(1 - x(t)) > 0.0015) end = t;
end += 0.004;
// Cut where it is within 0.15% of the end, the spring still has that much to go: on a large travel (a row
// folding 500 px) a step of a pixel in the last frame. What is left is spread over the way instead, most of
// it near the end, so the curve arrives at 1 exactly and smoothly; overshoot and timing stay as they are.
const rest = 1 - x(end);
const y = (t: number) => x(t) + rest * (t / end) ** 3;
const pts: number[] = [];
for (let i = 0; i <= 64; i++) pts.push(+x((end * i) / 64).toFixed(4));
for (let i = 0; i <= 64; i++) pts.push(+y((end * i) / 64).toFixed(4));
pts[64] = 1;
const duration = Math.round(end * 1000);
return { duration, easing: `linear(${pts.join(', ')})`, at: (ms) => (ms >= duration ? 1 : x(ms / 1000)) };
return { duration, easing: `linear(${pts.join(', ')})`, at: (ms) => (ms >= duration ? 1 : y(ms / 1000)) };
}
/** The accordion, the toast, a card that pops in. */
@@ -57,6 +79,8 @@ export const LEAD = spring(520, 46);
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);
/** A highlight gliding from row to row: quick, with a touch of give (about 2% over). */
export 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)';
@@ -72,6 +96,8 @@ export function publishSprings(root: HTMLElement) {
root.style.setProperty('--spring-soft-dur', `${SOFT.duration}ms`);
root.style.setProperty('--spring-quick', QUICK.easing);
root.style.setProperty('--spring-quick-dur', `${QUICK.duration}ms`);
root.style.setProperty('--spring-glide', GLIDE.easing);
root.style.setProperty('--spring-glide-dur', `${GLIDE.duration}ms`);
}
/**
@@ -79,7 +105,7 @@ export function publishSprings(root: HTMLElement) {
* its fade (short); one that only moves or resizes jumps to its end.
*/
export function play(el: Element, frames: Keyframe[], o: KeyframeAnimationOptions): Animation {
if (!calm()) return el.animate(frames, o);
if (!calm()) return el.animate(lean(el, frames), o);
if (frames.some((f) => 'opacity' in f))
return el.animate(
frames.map((f) => ('opacity' in f ? { opacity: f.opacity } : {})),
+17 -14
View File
@@ -56,6 +56,10 @@ function statusOf(d: Device, p: Person): [string, string, string?] {
// "connected", so say here why nothing works.
if (d.online && p.state === 'quota') return ['warn-t', _('Connected, no data left')];
if (d.online && p.state === 'hours') return ['warn-t', _('Connected, outside your hours')];
// Connected, and what it sends is dropped: the set-up sheet's no data, right away (the router's watcher names it
// only once it held 3 minutes), so a sheet closed on it doesn't leave the card saying Connected.
if (d.online && d.setup?.state === 'nodata')
return ['warn-t', _('Connected, but no data'), _('The router drops its traffic: the address does not match.')];
if (d.link) return ['warn-t', ...linkWords(d.link.state)];
if (d.online) return ['ok-t', _('Connected')];
if (!d.handshake) return ['warn-t', _('Not set up yet')];
@@ -93,8 +97,10 @@ function menuItems(d: Device, st: State): (MenuItem | null)[] {
// How devices at home reach it: only where the router actually lets them through.
...(reachableFromHome(st.person, d)
? [
{ label: _('Copy IP address'), icon: 'copy', run: () => copy(d.address, _('IP address copied')) },
...(d.hostname ? [{ label: _('Copy local address'), icon: 'home', run: () => copy(d.hostname, _('Address copied')) }] : []),
{ label: _('Copy IP address'), icon: 'copy', sub: d.address, run: () => copy(d.address, _('IP address copied')) },
...(d.hostname
? [{ label: _('Copy local address'), icon: 'home', sub: d.hostname, run: () => copy(d.hostname, _('Address copied')) }]
: []),
null,
]
: []),
@@ -171,7 +177,7 @@ function card(d: Device, st: State): HTMLElement {
},
ic('more'),
);
more?.addEventListener('click', () => openMenu(more, items));
more?.addEventListener('click', () => openMenu(more, items, d.name));
return h(
'article',
{ class: `dev${here ? ' is-here' : ''}${d.disabled ? ' off' : ''}`, 'data-id': d.id },
@@ -258,19 +264,16 @@ export function devicesSection(): HTMLElement {
/**
* A card whose width jumps (the grid changed its columns: a window across 560 or 960 px, a phone turned)
* takes its new shape with the layout, at once: gliding there from the old one, its numbers would not fit
* for a moment and wrap. A threshold crossed while the window is resized a little at a time still glides
* (devices.css). The class goes on before the frame is painted, so the glide that began never shows.
* for a moment and wrap. The columns change only there (devices.css, page.css), so those two crossings are what
* it listens for; a window resized between them still glides. The class goes on before the frame is painted, so
* the glide that began never shows.
*/
function snapOnJump(grid: HTMLElement) {
let was = 0;
new ResizeObserver(() => {
const w = grid.querySelector('.dev')?.getBoundingClientRect().width ?? 0;
if (Math.abs(w - was) > 16) {
grid.classList.add('snap');
requestAnimationFrame(() => requestAnimationFrame(() => grid.classList.remove('snap')));
}
was = w;
}).observe(grid);
const snap = () => {
grid.classList.add('snap');
requestAnimationFrame(() => requestAnimationFrame(() => grid.classList.remove('snap')));
};
for (const q of ['(min-width: 560px)', '(min-width: 960px)']) matchMedia(q).addEventListener('change', snap);
}
/** The green ring of a device that just connected (its animation's id, to find it again on a repaint). */
+51 -17
View File
@@ -8,8 +8,8 @@
import { h, ic, markup } from '../dom';
import { EASE_OUT, SOFT, play } from '../motion';
import { placeName, state } from '../state';
import { showPageCode } from '../flows/page-code';
import { openMenu } from '../ui/menu';
import { closePageCode, showPageCode } from '../flows/page-code';
import { pickPill, type PickPill } from '../ui/pick';
import { LANGS, lang, setLang } from '../i18n';
// The sun rises from behind the horizon once, on the visit's first paint.
@@ -70,21 +70,50 @@ export function single(on: boolean) {
pageEl?.classList.toggle('single', on);
}
/** The language: its code and a chevron; the menu lists the languages by their own names. */
// Each language's flag, a disc (styles/pick.css): the Union Jack for English, the tricolour for Russian.
const FLAGS: Record<string, string> = {
en:
'<svg viewBox="15 0 30 30" aria-hidden="true"><path fill="#012169" d="M0 0h60v30H0z"/>' +
'<path stroke="#fff" stroke-width="6" d="M0 0l60 30M60 0L0 30"/><path stroke="#c8102e" stroke-width="2" d="M0 0l60 30M60 0L0 30"/>' +
'<path stroke="#fff" stroke-width="10" d="M30 0v30M0 15h60"/><path stroke="#c8102e" stroke-width="6" d="M30 0v30M0 15h60"/></svg>',
ru:
'<svg viewBox="0 0 30 30" aria-hidden="true"><path fill="#fff" d="M0 0h30v10H0z"/><path fill="#0039a6" d="M0 10h30v10H0z"/>' +
'<path fill="#d52b1e" d="M0 20h30v10H0z"/></svg>',
};
const flag = (code: string) => h('span', { class: 'flag' }, FLAGS[code] ? markup(FLAGS[code]) : null);
/**
* The language: its flag, its code and a chevron; the popup under it lists the languages by their own names. One
* pill for the visit, put back each time the breadcrumb is drawn, so a pick morphs its code after the page redraws.
*/
let langPill: PickPill<string> | null = null;
function langPicker(): HTMLElement {
const b = h(
langPill ??= pickPill({
cls: 'cr-lang',
label: () => _('Language'),
options: LANGS.map((l) => ({ value: l.code, label: () => l.name, lead: () => flag(l.code) })),
value: lang(),
short: (c) => c.toUpperCase(),
prefer: 'below',
pick: (c) => setLang(c),
});
langPill.show(lang());
return langPill.el;
}
/**
* This page's code for another device: one knob for the visit, as the language's pill, so a card open from it
* (flows/page-code.ts) stays where it is as the page redraws.
*/
let qr: HTMLElement | null = null;
function qrKnob(): HTMLElement {
qr ??= h(
'button',
{ type: 'button', class: 'cr-lang', 'aria-label': _('Language'), 'aria-haspopup': 'menu', 'aria-expanded': 'false' },
h('span', {}, lang().toUpperCase()),
ic('chevron', 'i cr-down'),
{ type: 'button', class: 'knob cr-qr', 'aria-haspopup': 'dialog', 'aria-expanded': 'false', onclick: () => showPageCode(qr!) },
ic('qr'),
);
b.addEventListener('click', () =>
openMenu(
b,
LANGS.map((l) => ({ label: l.name, checked: l.code === lang(), run: () => l.code !== lang() && setLang(l.code) })),
),
);
return b;
qr.setAttribute('aria-label', _('Open on another device'));
return qr;
}
/**
@@ -93,6 +122,10 @@ function langPicker(): HTMLElement {
* 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)[] = [];
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;
@@ -106,8 +139,9 @@ export function crumbs(gone = false, card = false) {
p ? [ic('chevron'), h('span', { class: 'cur', 'aria-current': 'page' }, p.name)] : null,
),
...(card ? [] : [langPicker()]),
...(p && !card
? [h('button', { type: 'button', class: 'knob cr-qr', 'aria-label': _('Open on another device'), onclick: showPageCode }, ic('qr'))]
: []),
...(p && !card ? [qrKnob()] : []),
);
// No knob to fold back into: the card goes with it.
if (!qr?.isConnected) closePageCode(true);
drawnCrumbs.forEach((f) => f());
}
+36 -2
View File
@@ -24,10 +24,11 @@
.acc-row.open {
margin-block: 10px;
}
.acc-row.open:first-child {
/* The first and last rows that show (ui/accordion.ts: a row stepped out leaves none of its gap). */
.acc-row.open.first {
margin-top: 0;
}
.acc-row.open:last-child {
.acc-row.open.last {
margin-bottom: 0;
}
.acc-row:not(.open):not(.still):hover {
@@ -90,6 +91,39 @@
transform: translateX(8px);
pointer-events: none;
}
/* Actions on what an open row holds (ui/accordion.ts aside): beside the chevron, over the head's end, coming
in as the row opens and going as it shuts; the title keeps clear of them meanwhile (--aside-w: their width
and a gap). */
.acc-row.has-aside {
position: relative;
--aside-w: 72px;
}
.acc-aside {
position: absolute;
top: 0;
right: 40px;
height: 52px;
display: flex;
align-items: center;
transition:
opacity 200ms var(--ease-out),
filter 200ms var(--ease-out),
transform 200ms var(--ease-out);
}
.acc-row:not(.open) > .acc-aside {
opacity: 0;
filter: blur(4px);
transform: translateX(8px);
pointer-events: none;
visibility: hidden;
transition-property: opacity, filter, transform, visibility;
}
.acc-row.has-aside > .acc-head > .acc-title {
transition: padding-right 200ms var(--ease-out);
}
.acc-row.has-aside.open > .acc-head > .acc-title {
padding-right: var(--aside-w);
}
.acc-chev {
width: 16px;
height: 16px;
+6 -1
View File
@@ -12,6 +12,9 @@ html {
(main.ts), so the browser would hold "Your devices" still while an access row opens or folds, and pull a page
scrolled less than the fold to the very top. A row grows and folds in place; a repaint glides what moves. */
overflow-anchor: none;
/* An app's page, not a document's: a double tap doesn't zoom (the viewport keeps its scale, main.ts stops
Safari's pinch). Taps answer at once, with no wait for a second one. */
touch-action: manipulation;
}
body {
margin: 0;
@@ -60,7 +63,9 @@ a {
:focus {
outline: none;
}
:focus-visible {
/* The focus ring only while the keyboard is moving focus (main.ts sets .kbd on Tab or an arrow and drops it on a
press): focus a script moves, or one left after a click, shows nothing. */
.kbd :focus-visible {
outline: 2px solid color-mix(in srgb, var(--accent) 65%, transparent);
outline-offset: 2px;
}
+19 -2
View File
@@ -216,6 +216,10 @@
color: var(--text);
letter-spacing: -0.012em;
}
/* The system's caret where the field draws none (a touch screen, ui/caret.ts): the accent, as the drawn one. */
.field input {
caret-color: var(--accent);
}
.field input::placeholder {
color: var(--text-3);
}
@@ -433,6 +437,16 @@
.appseg .seg-b.on {
flex: 1 1 56px;
}
/* At rest the pill stands on its item (ui/seg.ts sets --i of --n): the track's 4 px edge and the items before it
(each --b wide) on the left, the items after it on the right; the picked item takes what is left, so does the
pill, whatever the sheet's width. A pick moves it with its own left and right, then hands back. */
.appseg {
--b: 56px;
}
.appseg .seg-pill {
left: calc(4px + var(--i, 0) * var(--b));
right: calc(4px + (var(--n, 1) - 1 - var(--i, 0)) * var(--b));
}
.appseg .seg-b .i {
width: 20px;
height: 20px;
@@ -454,6 +468,9 @@
container-type: inline-size;
}
@container (max-width: 300px) {
.appseg {
--b: 44px;
}
.appseg .seg-b {
flex-basis: 44px;
padding: 0 12px;
@@ -501,7 +518,7 @@
white-space: nowrap;
}
.kind:hover .kind-tile,
.kind:focus-visible .kind-tile {
.kbd .kind:focus-visible .kind-tile {
background: var(--knob);
}
.kind:active .kind-tile {
@@ -510,7 +527,7 @@
.kind:focus-visible {
outline: none;
}
.kind:focus-visible .kind-lbl,
.kbd .kind:focus-visible .kind-lbl,
.kind.on {
color: var(--text);
}
+9 -1
View File
@@ -94,7 +94,7 @@
background: color-mix(in srgb, var(--raised), var(--text) 6%);
}
/* Not when an edit gave focus back to it (flows/rename.ts): only reached with Tab. */
.dev-name.can-edit:focus-visible:not(.quiet) {
.kbd .dev-name.can-edit:focus-visible:not(.quiet) {
box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent);
}
.field.inline,
@@ -187,6 +187,14 @@
.dev.add:hover {
background: color-mix(in srgb, var(--raised), var(--knob) 45%);
}
/* On light the darker step would land on the page's own grey and the card would melt into it: a touch off white,
the words up to full colour. */
@media (prefers-color-scheme: light) {
.dev.add:hover {
background: color-mix(in srgb, var(--raised), var(--text) 2.5%);
color: var(--text);
}
}
.dev.add:active {
transform: scale(0.98);
}
+40
View File
@@ -0,0 +1,40 @@
/* What every dropdown is made of (ui/drop.ts: the ⋯ menu, the pick pills' popups, the page's code): Liquid Glass
(tokens.css --glass-*), the page behind blurred and its colours lifted, a soft even edge, a soft shadow on light
only; over the page and a sheet alike. A dropdown cut to a shape of its own (a pick popup's tail) traces its edge
and casts its shadow itself. */
.drop {
z-index: 60;
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);
}
/* Their one highlight (ui/glide.ts): under the items' icons and words (they sit over it), solid, the same for every
item; it glides on GLIDE and presses in with what it is on. */
.drop-hl {
position: absolute;
left: 0;
top: 0;
z-index: 2;
background: var(--glass-hl);
opacity: 0;
pointer-events: none;
transition:
opacity 160ms var(--ease-out),
scale 150ms var(--ease-out);
}
.drop-hl.moving {
transition:
opacity 160ms var(--ease-out),
scale 150ms var(--ease-out),
translate var(--spring-glide-dur, 400ms) var(--spring-glide, ease-out),
width var(--spring-glide-dur, 400ms) var(--spring-glide, ease-out),
height var(--spring-glide-dur, 400ms) var(--spring-glide, ease-out),
border-radius var(--spring-glide-dur, 400ms) var(--spring-glide, ease-out);
}
.drop-hl.down {
scale: 0.97;
}
+2
View File
@@ -12,3 +12,5 @@
@import './sheet.css';
@import './setup.css';
@import './menu-toast.css';
@import './drop.css';
@import './pick.css';
+92 -60
View File
@@ -1,76 +1,108 @@
/* The ⋯ menu (a highlight that glides after the pointer, tinted for Reconnect and Remove) and the
toast slot at the bottom. */
/* The ⋯ menu (ui/menu.ts): an iOS 26-style menu: Liquid Glass with a soft even edge, rows, thin lines
between groups. And the toast slot at the bottom. */
.menu {
position: fixed;
z-index: 60;
min-width: 224px;
padding: 6px;
border-radius: 20px;
background: var(--field);
box-shadow:
var(--pop-shadow),
inset 0 0 0 1px var(--line);
}
.menu-hl {
/* On the dropdowns' glass (.drop, styles/drop.css). */
.pop {
position: absolute;
left: 6px;
right: 6px;
top: 6px;
height: 40px;
border-radius: 14px;
background: var(--knob);
opacity: 0;
transition: opacity 150ms var(--ease-out);
pointer-events: none;
min-width: 210px;
overflow: hidden;
border-radius: 24px;
}
.menu-hl.moving {
transition:
opacity 150ms var(--ease-out),
transform var(--spring-quick-dur, 300ms) var(--spring-quick, ease-out),
background-color 150ms;
}
.menu-hl.bad {
background: var(--bad-soft);
}
.menu-hl.warn {
background: color-mix(in srgb, var(--warn) 13%, transparent);
}
.mi {
/* The Figma's Menu made compact: 6 px top and bottom, the rows 6 px in. */
.pop-body {
position: relative;
z-index: 1;
display: flex;
flex-direction: column;
padding: 6px 0;
}
.pop-grp {
display: flex;
flex-direction: column;
padding: 0 6px;
}
/* A separator: 21 px high, its line 8 px further in than the rows. */
.pop-sep {
display: flex;
align-items: center;
gap: 12px;
width: 100%;
height: 40px;
padding: 0 12px;
border-radius: 14px;
font-size: 14px;
font-weight: 500;
text-align: left;
height: 13px;
padding: 0 16px;
}
.mi .i {
.pop-sep > span {
flex: 1;
height: 1px;
background: var(--glass-sep);
}
/* A row: 8 px above and below the words (34 high, 50 with a line under the label); the icon further in from the
row's rounded edge (14 px) than it is from the words (10 px), so it doesn't crowd the curve. */
.mi {
position: relative;
display: flex;
align-items: center;
gap: 10px;
width: 100%;
min-height: 34px;
padding: 0 12px 0 14px;
border-radius: 18px;
color: var(--glass-text);
text-align: left;
transition: transform 150ms var(--ease-out);
}
/* Whole rows over the highlight (they have no fill of their own): pressed, a row scales as one layer, and its
words must not drop under the highlight with it. */
.mi {
z-index: 3;
}
.mi:active {
transform: scale(0.97);
}
.kbd .mi:focus-visible {
outline: 2px solid var(--accent);
outline-offset: -2px;
}
.mi > .i {
position: relative;
z-index: 3;
flex: none;
color: currentColor;
transition: scale var(--spring-glide-dur, 400ms) var(--spring-glide, ease-out);
}
.mi > .i {
width: 16px;
height: 16px;
color: var(--text-2);
}
/* An option's check, kept in its place on the others so the names line up. */
.mi .i.off {
visibility: hidden;
.mi.hot > .i {
scale: 1.08;
}
.mi.warn,
.mi.warn .i {
.mi-b {
position: relative;
z-index: 3;
display: flex;
flex-direction: column;
justify-content: center;
gap: 1px;
min-width: 0;
padding: 8px 0;
}
.mi-l {
font-size: 14px;
font-weight: 400;
line-height: 18px;
letter-spacing: -0.2px;
}
.mi-s {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 11.5px;
line-height: 15px;
color: var(--glass-sub);
font-variant-numeric: tabular-nums;
}
.mi.warn {
color: var(--warn);
}
.mi.bad,
.mi.bad .i {
color: var(--bad);
}
.menu-sep {
height: 1px;
margin: 6px 12px;
background: var(--line);
.mi.bad {
color: var(--glass-bad);
}
/* One toast at a time; a new one comes in over the leaving one. */
+6
View File
@@ -3,6 +3,12 @@
.mt {
position: relative;
}
/* While the words change (ui/morph.ts): nothing of them clipped, not even by a box that ends a long line in an
ellipsis; that comes back once they have changed. */
.mt-run {
overflow: visible !important;
text-overflow: clip !important;
}
.mt-ib {
display: inline-block;
white-space: nowrap;
+83 -13
View File
@@ -22,6 +22,13 @@
-webkit-mask-image: linear-gradient(#000 0%, rgba(0, 0, 0, 0.88) 44%, transparent 100%);
mask-image: linear-gradient(#000 0%, rgba(0, 0, 0, 0.88) 44%, transparent 100%);
}
/* On a phone the blur under it is drawn again on every frame of a scroll: the fade to the page's colour alone. */
@media (pointer: coarse) {
.edge-fade.top {
-webkit-backdrop-filter: none;
backdrop-filter: none;
}
}
body.scrolled .edge-fade.top {
opacity: 1;
}
@@ -81,14 +88,14 @@ body.scrolled .edge-fade.top {
width: 14px;
height: 14px;
}
/* The language: a pill as high as the QR knob beside it, its code and a chevron that turns up while
the menu is open. */
/* 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 {
display: inline-flex;
align-items: center;
gap: 4px;
gap: 6px;
height: 32px;
padding: 0 8px 0 12px;
padding: 0 8px 0 8px;
border-radius: 999px;
background: var(--knob);
color: var(--text);
@@ -109,15 +116,8 @@ body.scrolled .edge-fade.top {
.cr-lang[aria-expanded='true'] {
background: color-mix(in srgb, var(--knob), var(--text) 10%);
}
.cr-down {
width: 14px;
height: 14px;
color: var(--text-2);
transform: rotate(90deg);
transition: transform 200ms var(--ease-out);
}
.cr-lang[aria-expanded='true'] .cr-down {
transform: rotate(-90deg);
.cr-lang .pp-chev {
margin-left: -2px;
}
/* Phones: one column, access first. From 960px: devices left, access right and sticky. The foot
@@ -280,3 +280,73 @@ body.scrolled .edge-fade.top {
color: var(--text-2);
text-wrap: balance;
}
/* This page's code for another device (flows/page-code.ts): a card grown out of the QR knob where it stands, on
the ⋯ menu's Liquid Glass; the code on top and under it Copy link and Share. */
.pc-card {
position: absolute;
display: flex;
flex-direction: column;
gap: 8px;
width: 244px;
padding: 10px;
/* The dropdowns' radius (the ⋯ menu's), on their glass (.drop). */
border-radius: 24px;
}
/* Concentric with the card: its radius less the 10 px around the code. */
.pc-card .qrbox.big {
width: 224px;
height: 224px;
border-radius: 14px;
}
.pc-row {
display: flex;
gap: 6px;
}
.pc-row .knob {
width: 36px;
height: 36px;
background: color-mix(in srgb, var(--glass-text) 6%, transparent);
color: var(--glass-text);
}
.pc-row .knob:hover {
background: color-mix(in srgb, var(--glass-text) 11%, transparent);
}
.pc-copy {
flex: 1;
min-width: 0;
height: 36px;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 7px;
padding: 0 14px;
border-radius: 999px;
background: color-mix(in srgb, var(--glass-text) 6%, transparent);
color: var(--glass-text);
font-size: 14px;
font-weight: 500;
letter-spacing: -0.01em;
transition:
transform 150ms var(--ease-out),
background-color 150ms;
}
.pc-copy:hover {
background: color-mix(in srgb, var(--glass-text) 11%, transparent);
}
.pc-copy:active {
transform: scale(0.96);
}
.pc-copy .i {
width: 16px;
height: 16px;
flex: none;
}
.pc-copy .lbl {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.pc-copy.copied {
color: var(--ok);
}
+137
View File
@@ -0,0 +1,137 @@
/* A pick pill (ui/pick.ts): the pill's own look is its class's (the language in the breadcrumb, the demo's
set-up state); here what every one shares: what it leads with, its chevron, and its popup. */
.pp {
touch-action: none;
-webkit-user-select: none;
user-select: none;
}
.pp-lead {
position: relative;
display: inline-flex;
flex: none;
}
/* The one it led with before, blurring away over the new one. */
.pp-lead > .pp-gone {
position: absolute;
inset: 0;
}
.pp-lead[hidden] {
display: none;
}
/* Turned by its own angle (ui/pick.ts), so shutting goes on round to down rather than back. */
.pp-chev {
width: 14px;
height: 14px;
flex: none;
color: var(--text-2);
rotate: 90deg;
transition: rotate 260ms var(--ease-out);
}
/* The popup: segments in one pill frame on Liquid Glass (tokens.css --glass-*), its tail one shape with it (a clip
path, ui/pick.ts) with a soft even edge traced round both.
The segments: clear on the glass as the menu's rows are; the dropdowns' highlight rests on the picked one (it is
what says which is picked) and glides to the one pointed at; the picked one and the one pointed at in full text
colour, the rest in the glass's subtitle colour. */
.pp-pop {
position: fixed;
display: flex;
gap: 3px;
padding: 3px;
}
/* Its edge and shadow are its own (the clip path would cut the dropdowns' off): the ring and the shade. */
.pp-pop.drop {
box-shadow: none;
}
/* Room for the tail, towards the pill. */
.pp-pop.above {
padding-bottom: 9px;
}
.pp-pop.below {
padding-top: 9px;
}
.pp-shade {
position: fixed;
z-index: 59;
border-radius: 999px;
pointer-events: none;
box-shadow: var(--glass-shadow);
}
.pp-ring {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
fill: none;
stroke: var(--glass-edge);
stroke-width: 2;
}
.pp-pop button {
position: relative;
z-index: 3;
display: inline-flex;
align-items: center;
gap: 7px;
height: 34px;
padding: 0 10px;
border-radius: 10px;
color: var(--glass-sub);
font-size: 12.5px;
font-weight: 500;
white-space: nowrap;
transition:
color 150ms,
background-color 150ms,
transform 150ms var(--ease-out);
}
/* The ends follow the frame: half the segment's height (a larger radius would shrink every corner). */
.pp-pop button:first-of-type {
border-radius: 17px 10px 10px 17px;
padding-left: 13px;
}
.pp-pop button:last-of-type {
border-radius: 10px 17px 17px 10px;
padding-right: 13px;
}
/* Under the pointer, or under a finger sliding over from the pill. */
/* Under the pointer, or under a finger sliding over from the pill: the dropdowns' highlight is under it
(ui/glide.ts); its words come up. */
.pp-pop button.hot {
color: var(--glass-text);
}
.pp-pop button:active {
transform: scale(0.96);
}
.pp-pop button[aria-checked='true'] {
color: var(--glass-text);
}
.kbd .pp-pop button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: -2px;
}
/* A language's flag: a 16px disc with a hairline so a white stripe keeps its edge. */
.flag {
position: relative;
width: 16px;
height: 16px;
border-radius: 50%;
overflow: hidden;
flex: none;
}
.flag svg {
display: block;
width: 100%;
height: 100%;
}
.flag::after {
content: '';
position: absolute;
inset: 0;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.pp-pop button:not([aria-checked='true']):not(.hot) .flag {
opacity: 0.7;
}
+6 -4
View File
@@ -22,10 +22,6 @@
.step + .step {
margin-top: 20px;
}
/* No data: the connection step alone in its row (flows/setup-view.ts regroup). */
.step[hidden] + .step {
margin-top: 0;
}
.step-n {
width: 24px;
height: 24px;
@@ -55,6 +51,12 @@
flex-direction: column;
gap: 10px;
}
/* The connection (flows/setup-view.ts): its picker over its box, in step 2, a row or the again-row alike. */
.conn {
display: flex;
flex-direction: column;
gap: 10px;
}
/* The way, as on the old portal: one dotted line, three layers through the same dots (the dots, the
light along them that runs and rests a beat, the green that fills them from the device); the
+10 -13
View File
@@ -14,12 +14,12 @@
.sheet-root.open {
display: block;
}
/* The dim alone, no blur behind it: a blur of the whole page would be drawn again on every frame the sheet and
the dim move, and the system's own sheets dim too. */
.scrim {
position: absolute;
inset: 0;
background: var(--scrim);
-webkit-backdrop-filter: blur(8px);
backdrop-filter: blur(8px);
}
.sheet {
position: absolute;
@@ -135,34 +135,31 @@
top: 22px;
right: 58px;
}
/* The connection's download and copy, on its row beside the chevron: quiet icons in the chevron's grey, a knob
circle behind one under the pointer. */
.hpill {
position: relative;
display: flex;
gap: 2px;
}
.hp-b {
display: grid;
place-items: center;
width: 38px;
width: 32px;
height: 32px;
background: var(--knob);
color: var(--text);
border-radius: 50%;
color: var(--text-2);
transition:
background-color 150ms,
color 150ms,
transform 150ms var(--ease-out);
}
.hp-b:first-of-type {
border-radius: 16px 6px 6px 16px;
}
.hp-b:last-of-type {
border-radius: 6px 16px 16px 6px;
}
.hp-b .i {
width: 16px;
height: 16px;
}
.hp-b:hover {
background: color-mix(in srgb, var(--knob), var(--text) 6%);
background: var(--knob);
color: var(--text);
}
.hp-b:active {
transform: scale(0.94);
+36 -15
View File
@@ -39,14 +39,27 @@
--accent: #4eafff;
--accent-ink: #ffffff;
--accent-soft: rgba(78, 175, 255, 0.13);
--ok: #57d64b;
--ok-soft: rgba(87, 214, 75, 0.14);
--warn: #ff8a3d;
--bad: #ff5c5c;
--bad-soft: rgba(255, 92, 92, 0.13);
--ok: #30d158;
--ok-soft: rgba(48, 209, 88, 0.14);
--warn: #ff8d28;
--bad: #ff383c;
--bad-soft: rgba(255, 56, 60, 0.13);
--sel-bg: rgba(131, 209, 255, 0.25);
--sel-fg: #64c6ff;
--scrim: rgba(8, 8, 8, 0.8);
/* iOS 26's Liquid Glass, Regular (Apple's Figma kit), for what pops over the page (the ⋯ menu, the pick pills'
popups): black 60% with a white 6% film at 67%, blurred and its colours lifted; a soft even edge; its own
text, subtitle and destructive colours; separators a touch softer than the edge; a solid highlight. */
--glass-bg: linear-gradient(rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.04)), rgba(0, 0, 0, 0.4);
--glass-edge: rgba(255, 255, 255, 0.05);
--glass-sep: rgba(255, 255, 255, 0.04);
--glass-text: #f5f5f5;
--glass-sub: #8a8a8a;
--glass-bad: var(--bad);
--glass-hl: color-mix(in srgb, var(--raised), var(--text) 8%);
--glass-hover: color-mix(in srgb, var(--raised), var(--text) 5%);
/* No shadow on dark: the glass's edge sets it apart; on light a soft one. */
--glass-shadow: 0 0 0 transparent;
--line-glass: rgba(255, 255, 255, 0.07);
--pop-shadow: 0 18px 48px -14px rgba(0, 0, 0, 0.75);
--sheet-shadow: 0 24px 64px -16px rgba(0, 0, 0, 0.6);
@@ -65,11 +78,11 @@
--t-blue-a: #a6d9ff;
--t-blue-b: #1d84e6;
--t-green-a: #a8f29c;
--t-green-b: #3aa32c;
--t-green-b: #30d158;
--t-red-a: #ffadad;
--t-red-b: #dc3a3a;
--t-red-b: #ff383c;
--t-orange-a: #ffc08f;
--t-orange-b: #ec6a12;
--t-orange-b: #ff8d28;
--font: Geist, -apple-system, system-ui, 'Segoe UI', sans-serif;
--mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
@@ -98,14 +111,22 @@
--text-3: #a6a6a4;
--accent: #2b9dff;
--accent-soft: rgba(43, 157, 255, 0.12);
--ok: #33a328;
--ok-soft: rgba(51, 163, 40, 0.12);
--warn: #ee6a12;
--bad: #e5484d;
--bad-soft: rgba(229, 72, 77, 0.1);
--ok: #30d158;
--ok-soft: rgba(48, 209, 88, 0.12);
--warn: #ff8d28;
--bad: #ff383c;
--bad-soft: rgba(255, 56, 60, 0.1);
--sel-bg: rgba(78, 175, 255, 0.22);
--sel-fg: #0a76cf;
--scrim: rgba(236, 236, 235, 0.62);
--glass-bg: rgba(245, 245, 245, 0.6);
--glass-edge: rgba(0, 0, 0, 0.04);
--glass-sep: rgba(0, 0, 0, 0.03);
--glass-text: #1a1a1a;
--glass-sub: #727272;
--glass-hl: color-mix(in srgb, var(--raised), var(--text) 11%);
--glass-hover: color-mix(in srgb, var(--raised), var(--text) 4%);
--glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
--line-glass: rgba(0, 0, 0, 0.07);
--pop-shadow: 0 18px 44px -14px rgba(0, 0, 0, 0.2);
--sheet-shadow: 0 24px 64px -18px rgba(0, 0, 0, 0.22);
@@ -123,8 +144,8 @@
--t-blue-a: #7cc4ff;
--t-blue-b: #0a6fd6;
--t-green-a: #82e070;
--t-green-b: #2e8a22;
--t-green-b: #30d158;
--t-red-a: #ff9090;
--t-red-b: #c92a2a;
--t-red-b: #ff383c;
}
}
+18 -5
View File
@@ -23,6 +23,11 @@ export interface AccItem {
val?: Node | null;
/** The body shows the same numbers: the head drops them while open. */
valHide?: boolean;
/**
* Actions on what the row holds, beside the chevron while it is open (gone while it is shut). Beside the head,
* not in it: the head is a button itself.
*/
aside?: Node | null;
body: (Node | null | false | undefined)[];
}
@@ -139,20 +144,28 @@ export function accordion(
);
const r = h(
'div',
{ class: `acc-row${still ? ' still' : ''}${open ? ' open' : ''}` },
{ class: `acc-row${still ? ' still' : ''}${open ? ' open' : ''}${it.aside ? ' has-aside' : ''}` },
headEl,
it.aside ? h('div', { class: 'acc-aside' }, it.aside) : null,
h('div', { class: 'acc-body' }, ...kids),
);
acc.appendChild(r);
return r;
});
const bodyOf = (r: HTMLElement) => r.querySelector('.acc-body') as HTMLElement;
const corners = () =>
rows.forEach((r, i) => {
/** Corners and edges over the rows that show: a row stepped out (only()) leaves no gap or corner behind. */
const corners = () => {
const shown = rows.filter((r) => !r.hidden);
shown.forEach((r, i) => {
const op = r.classList.contains('open');
r.classList.toggle('rt', i === 0 || op || rows[i - 1].classList.contains('open'));
r.classList.toggle('rb', i === rows.length - 1 || op || rows[i + 1].classList.contains('open'));
r.classList.toggle('rt', i === 0 || op || shown[i - 1].classList.contains('open'));
r.classList.toggle('rb', i === shown.length - 1 || op || shown[i + 1].classList.contains('open'));
});
rows.forEach((r) => {
r.classList.toggle('first', r === shown[0]);
r.classList.toggle('last', r === shown[shown.length - 1]);
});
};
const read = (x: HTMLElement) => {
const cs = getComputedStyle(x);
const out: Record<string, string> = {};
+11 -13
View File
@@ -3,10 +3,12 @@
// and blinks as macOS draws it; a selection is an accent wash with a handle at
// each end, as iOS draws it, growing out of the caret and fading back into it.
// The input stays the browser's own (typing, IME, its native selection, made
// see-through): this only draws over it. On a touch screen the system draws its
// own selection and handles, so ours stays off and the caret steps aside while
// one shows. The look is in styles/controls.css; like the rest of the page this
// writes styles through `el.style` only (the CSP drops style attributes).
// see-through): this only draws over it. With a mouse or trackpad only: on a
// touch screen the system's caret stays (in the accent), with its own selection
// and handles. iOS doesn't tell a page reliably where its caret went (a tap in
// the words, a press-and-drag): a drawn one would wait for the first key. The
// look is in styles/controls.css; like the rest of the page this writes styles
// through `el.style` only (the CSP drops style attributes).
//
// Places come from a hidden mirror with the input's own font: the width of the
// text up to a position, less how far the input has scrolled. The pure parts
@@ -87,15 +89,15 @@ export function places(f: FieldText, measure: (text: string) => number): Places
const FONT = ['fontFamily', 'fontSize', 'fontWeight', 'letterSpacing', 'fontFeatureSettings', 'fontVariationSettings'] as const;
/**
* Give the input of `field` (a `.field`) the glide caret and, with a fine pointer, the selection.
* Give the input of `field` (a `.field`) the glide caret and the selection, with a mouse or trackpad.
* Call it once, as the field is built (it measures only once the field is on the page).
*/
export function smoothCaret(field: HTMLElement) {
const input = field.querySelector('input');
if (!input) return;
const fine = matchMedia('(pointer: fine)').matches;
field.classList.add('own-caret');
if (fine) field.classList.add('own-sel');
// A touch screen: the system's caret (controls.css gives it the accent).
if (!matchMedia('(pointer: fine)').matches) return;
field.classList.add('own-caret', 'own-sel');
const wash = h('span', { class: 'caret-sel' });
const h0 = h('span', { class: 'caret-hd s' });
const h1 = h('span', { class: 'caret-hd e' });
@@ -187,7 +189,7 @@ export function smoothCaret(field: HTMLElement) {
all.forEach((g) => jump(g, p.start));
first = false;
}
if (p.range && fine) {
if (p.range) {
// Selecting: the wash grows out of where the caret is, and the caret steps aside. A wash still fading from
// the last selection turns back instead and glides from its old ends to the new ones.
if (!selecting) {
@@ -204,10 +206,6 @@ export function smoothCaret(field: HTMLElement) {
cur.t = p.caret;
field.classList.add('selecting');
caret.classList.remove('on', 'blink');
} else if (p.range) {
// A touch screen: the system's own selection shows.
caret.classList.remove('on', 'blink');
return;
} else {
// Collapsed: the wash fades where it stands, and its ends join the caret once it is gone.
// A click puts the caret where it was clicked at once, as macOS does; typing and the arrows glide.
+84
View File
@@ -0,0 +1,84 @@
// What every dropdown shares (the ⋯ menu, the pick pills' popups, the page's code): its look (.drop,
// styles/drop.css: Liquid Glass, a soft even edge, a soft shadow on light only), one open at a time, the same gap to
// its button and margin to the screen's edge, the same way in (a spring out of where it grows from) and out (back
// towards it, from where it stands), and the same ways to shut it: a press outside it and its button, Escape (the
// sheet under it stays; focus goes back to the button), a resize (at once). Each lays out and fills its own.
import { EASE_IN, POP, play } from '../motion';
/** From its button, and from the screen's edge. */
export const GAP = 8;
export const EDGE = 12;
let current: ((now?: boolean) => void) | null = null;
/** A dropdown is open (the page holds its repaints meanwhile). */
export const dropOpen = () => !!current;
/** Shut the one open (`now`: at once: a sheet opening, the page drawn again in another language). */
export function closeDrop(now = false) {
current?.(now);
}
/** Where an element stands now, mid-motion included. */
function standing(el: Element): Keyframe {
const s = getComputedStyle(el);
return { opacity: s.opacity, transform: s.transform, filter: s.filter === 'none' ? 'blur(0px)' : s.filter };
}
/** In: a spring out of its transform origin. */
export function appear(el: Element) {
play(
el,
[
{ opacity: 0, transform: 'scale(.5)', filter: 'blur(6px)' },
{ opacity: 1, transform: 'none', filter: 'blur(0px)' },
],
{ duration: POP.duration, easing: POP.easing },
);
}
/** Out: back towards its origin from where it stands, then gone. */
export function vanish(el: Element) {
const from = standing(el);
el.getAnimations().forEach((a) => a.cancel());
play(el, [from, { opacity: 0, transform: 'scale(.7)', filter: 'blur(4px)' }], {
duration: 110,
easing: EASE_IN,
fill: 'forwards',
}).onfinish = () => el.remove();
}
/**
* Open `panel` for `button`: another one open shuts at once, and the ways to shut this one are listened for.
* `shut(now)` does the closing itself; what this returns is to be called first thing in it (it lets go of the
* listeners, says the button is shut, and is false when the dropdown was shut already).
*/
export function opened(panel: Element, button: HTMLElement, shut: (now?: boolean) => void): () => boolean {
if (current) current(true);
const outside = (e: PointerEvent) => {
const t = e.target as Node;
if (!panel.contains(t) && !button.contains(t)) shut();
};
const esc = (e: KeyboardEvent) => {
if (e.key !== 'Escape') return;
e.stopPropagation();
shut();
button.focus({ preventScroll: true });
};
const resized = () => shut(true);
document.addEventListener('pointerdown', outside, true);
document.addEventListener('keydown', esc, true);
addEventListener('resize', resized);
button.setAttribute('aria-expanded', 'true');
current = shut;
return () => {
if (current !== shut) return false;
current = null;
document.removeEventListener('pointerdown', outside, true);
document.removeEventListener('keydown', esc, true);
removeEventListener('resize', resized);
button.setAttribute('aria-expanded', 'false');
return true;
};
}
+49
View File
@@ -0,0 +1,49 @@
// The dropdowns' highlight (ui/drop.ts: the ⋯ menu's rows, a pick pill's segments): one for all of a dropdown's
// items, under their icons and words, the glass's solid highlight, the same for every item. It comes in on the item
// the pointer (the keyboard, or a finger sliding over from a pick pill) reaches, glides from item to item on GLIDE
// taking each one's place, size and corners, presses in with it, and fades where the pointer leaves (or goes back to
// the item it rests on: a pick pill's picked segment).
import { h } from '../dom';
export interface Glide {
/** Light this item (null: none). */
light(item: HTMLElement | null): void;
}
/**
* `host`: what holds the items and the highlight, positioned. `rest`: the item the highlight rests on (a pick pill's
* picked segment): it starts there, and goes back there rather than fading when the pointer leaves.
*/
export function glide(host: HTMLElement, items: HTMLElement[], rest: HTMLElement | null = null): Glide {
const hl = h('span', { class: 'drop-hl', 'aria-hidden': 'true' });
host.prepend(hl);
let hot: HTMLElement | null = null;
const light = (item: HTMLElement | null) => {
if (item === hot) return;
hot?.classList.remove('hot');
hot = item;
if (!item) return void (hl.style.opacity = '0');
item.classList.add('hot');
// Gone altogether, it is placed at once and fades in there; still showing, it glides from where it stands.
hl.classList.toggle('moving', +getComputedStyle(hl).opacity > 0.01);
Object.assign(hl.style, {
translate: `${item.offsetLeft}px ${item.offsetTop}px`,
width: `${item.offsetWidth}px`,
height: `${item.offsetHeight}px`,
borderRadius: getComputedStyle(item).borderRadius,
opacity: '1',
});
};
for (const it of items) {
it.addEventListener('pointerenter', () => light(it));
it.addEventListener('focus', () => it.matches(':focus-visible') && light(it));
it.addEventListener('pointerdown', () => {
hl.classList.add('down');
document.addEventListener('pointerup', () => hl.classList.remove('down'), { once: true, capture: true });
});
}
host.addEventListener('pointerleave', () => light(rest));
light(rest);
return { light: (item) => light(item ?? rest) };
}
+92 -101
View File
@@ -1,123 +1,114 @@
// The ⋯ menu: a small panel under (or over) its button, items with an icon,
// a highlight that glides after the pointer and takes the item's colour
// (orange for Reconnect, red for Remove). A choice among options (the
// language) marks the current one with a check instead of icons. One at a
// time; it closes on a press outside, on scroll, on Escape and when its button
// is pressed again.
// The ⋯ menu: an iOS 26-style menu under its button (over it where the screen
// ends): Liquid Glass (the page blurred behind), a soft even edge.
// Laid out as iOS 26's: rows (an icon, the label and a line under it where the
// item has one: the address it copies), a thin line between groups; Reconnect
// orange, Remove red. The dropdowns' highlight glides from row to row. It springs out from the
// button's side and drops back towards it. Shut by a
// press outside, Escape, its button again or a choice. One at a time.
import { h, ic } from '../dom';
import { EASE_IN, POP, play } from '../motion';
import { appear, closeDrop, EDGE, GAP, opened, vanish } from './drop';
import { glide } from './glide';
export interface MenuItem {
label: string;
/** An action's icon; an option (`checked` set) shows a check in its place, on the current one only. */
icon?: string;
checked?: boolean;
/** Its line icon. */
icon: string;
/** Under the label: what it acts on (the address it copies). */
sub?: string;
tone?: 'warn' | 'bad';
run: () => unknown;
}
let menuEl: HTMLElement | null = null;
/** The button the open menu belongs to: pressing it again closes the menu. */
let anchorEl: HTMLElement | null = null;
export const menuOpen = () => !!menuEl;
/** `now`: gone at once (Escape, or another menu opening). */
export function closeMenu(now = false) {
const m = menuEl;
if (!m) return;
menuEl = null;
anchorEl?.setAttribute('aria-expanded', 'false');
anchorEl = null;
if (now) {
m.remove();
return;
/** `all`: null between groups (kept only between items); `title`: what it acts on (the device), for a screen reader. */
export function openMenu(anchor: HTMLElement, all: (MenuItem | null)[], title: string) {
// Its button again: it shuts.
if (anchor.getAttribute('aria-expanded') === 'true') return closeDrop();
const groups: MenuItem[][] = [[]];
for (const it of all) {
if (it) groups[groups.length - 1].push(it);
else if (groups[groups.length - 1].length) groups.push([]);
}
// From where it stands: one closed while it still pops in (a scroll, a second press) goes from there.
const s = getComputedStyle(m);
const a = play(
m,
[
{ opacity: s.opacity, transform: s.transform, filter: s.filter },
{ opacity: 0, transform: 'scale(.96)', filter: 'blur(3px)' },
],
{
duration: 120,
easing: EASE_IN,
fill: 'forwards',
},
);
m.getAnimations().forEach((x) => x !== a && x.cancel());
a.onfinish = () => m.remove();
}
if (!groups[groups.length - 1].length) groups.pop();
/** `items`: null is a separator, kept only between items. */
export function openMenu(anchor: HTMLElement, all: (MenuItem | null)[]) {
if (anchorEl === anchor && menuEl) return closeMenu();
closeMenu(true);
const items = all.filter((it, i) => it || (i > 0 && all[i - 1] && all.slice(i + 1).some(Boolean)));
const hl = h('span', { class: 'menu-hl' });
const m = h('div', { class: 'menu', role: 'menu' }, hl);
for (const it of items) {
if (!it) {
m.appendChild(h('div', { class: 'menu-sep' }));
continue;
}
const rows: HTMLElement[] = [];
const item = (it: MenuItem, cls: string, ...kids: (Node | null)[]) => {
const b = h(
'button',
{
type: 'button',
role: it.checked === undefined ? 'menuitem' : 'menuitemradio',
'aria-checked': it.checked === undefined ? null : String(it.checked),
class: `mi ${it.tone ?? ''}`,
role: 'menuitem',
class: `${cls}${it.tone ? ` ${it.tone}` : ''}`,
onclick: () => {
closeMenu();
close();
it.run();
},
},
it.checked === undefined ? ic(it.icon ?? '') : ic('check', it.checked ? 'i' : 'i off'),
h('span', {}, it.label),
...kids,
);
// The highlight comes in where the pointer is, then glides from item to item. Whether it shows is read off the
// screen: one still fading out (the pointer left and came back) turns back and glides from where it stands;
// only one gone altogether is placed at once.
b.addEventListener('pointerenter', () => {
const seen = +getComputedStyle(hl).opacity > 0.01;
hl.className = `menu-hl${seen ? ' moving' : ''} ${it.tone ?? ''}`;
hl.style.transform = `translateY(${b.offsetTop - 6}px)`;
hl.style.opacity = '1';
});
m.appendChild(b);
}
m.addEventListener('pointerleave', () => (hl.style.opacity = '0'));
document.body.appendChild(m);
const r = anchor.getBoundingClientRect();
const w = m.offsetWidth;
const mh = m.offsetHeight;
// Under the button, or over it where the screen ends: it grows out of the button either way.
const below = r.bottom + 8 + mh < innerHeight - 8;
m.style.left = `${Math.max(12, Math.min(r.right - w, innerWidth - w - 12))}px`;
m.style.top = `${below ? r.bottom + 8 : r.top - 8 - mh}px`;
m.style.transformOrigin = `${below ? 'top' : 'bottom'} right`;
play(
m,
[
{ opacity: 0, transform: 'scale(.9)', filter: 'blur(4px)' },
{ opacity: 1, transform: 'none', filter: 'none' },
],
{
duration: POP.duration,
easing: POP.easing,
},
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),
),
),
),
),
];
// A thin line between sections (iOS's, inset; the rows themselves sit in a 16 px inset).
const body = h(
'div',
{ class: 'pop-body' },
...sections.flatMap((sec, i) => (i ? [h('div', { class: 'pop-sep', 'aria-hidden': 'true' }, h('span')), sec] : [sec])),
);
menuEl = m;
anchorEl = anchor;
anchor.setAttribute('aria-expanded', 'true');
}
const pop = h('div', { class: 'pop drop', role: 'menu', 'aria-label': title }, body);
document.body.append(pop);
document.addEventListener('pointerdown', (e) => {
const t = e.target as Element;
if (menuEl && !menuEl.contains(t) && !anchorEl?.contains(t)) closeMenu();
});
addEventListener('scroll', () => closeMenu(), { passive: true });
// Under the button where it fits, else over it; centred on it, inside the screen's edge, growing from its side.
const k = anchor.getBoundingClientRect();
const w = Math.min(pop.offsetWidth, innerWidth - EDGE * 2);
pop.style.width = `${w}px`;
const ht = pop.offsetHeight;
const mid = k.left + k.width / 2;
const left = Math.max(EDGE, Math.min(mid - w / 2, innerWidth - EDGE - w));
const below = k.bottom + GAP + ht <= innerHeight - EDGE || k.top - GAP - ht < EDGE;
const top = below ? k.bottom + GAP : k.top - GAP - ht;
Object.assign(pop.style, {
left: `${left + scrollX}px`,
top: `${top + scrollY}px`,
transformOrigin: `${mid - left}px ${below ? 0 : ht}px`,
});
appear(pop);
const release = opened(pop, anchor, close);
// The dropdowns' one highlight for the rows (ui/glide.ts).
glide(body, rows);
// Arrows move through the rows (the rest of the keys and presses are the dropdown's: ui/drop.ts).
const keys = (e: KeyboardEvent) => {
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
e.preventDefault();
const i = rows.indexOf(document.activeElement as HTMLElement);
const j = i < 0 ? (e.key === 'ArrowDown' ? 0 : rows.length - 1) : i + (e.key === 'ArrowDown' ? 1 : -1);
rows[Math.max(0, Math.min(rows.length - 1, j))]?.focus({ preventScroll: true });
};
document.addEventListener('keydown', keys, true);
function close(instant = false) {
if (!release()) return;
document.removeEventListener('keydown', keys, true);
if (instant || !anchor.isConnected) pop.remove();
else vanish(pop);
}
}
+33 -21
View File
@@ -121,7 +121,7 @@ function finish(el: HTMLElement) {
clearTimeout(r.timer);
runs.delete(el);
el.getAnimations().forEach((a) => a.cancel());
el.classList.remove('mt', 'mt-ib');
el.classList.remove('mt', 'mt-ib', 'mt-run');
el.textContent = r.text;
}
@@ -162,6 +162,33 @@ export interface MorphOpts {
color?: string;
}
/**
* A letter of a morph leaving: it lifts away as it blurs out (`delay`: its place in the sweep; `from`: how it
* shows). Also what goes with the words as one more letter (a pick pill's flag), so both move as one.
*/
export function letterOut(el: Element, delay = 0, from: Look = SHOWN): Animation {
return play(
el,
[
{ opacity: from.opacity, filter: from.filter, transform: 'none' },
{ opacity: 0, filter: 'blur(4px)', transform: 'translateY(-0.45em)' },
],
{ duration: 220, delay, easing: EASE_IN, fill: 'forwards' },
);
}
/** A letter of a morph coming in: it rises in as it sharpens, after the old ones start to go. */
export function letterIn(el: Element, delay = 0): Animation {
return play(
el,
[
{ opacity: 0, filter: 'blur(4px)', transform: 'translateY(0.45em)' },
{ opacity: 1, filter: 'blur(0px)', transform: 'none' },
],
{ duration: 380, delay: 120 + delay, easing: EASE_OUT, fill: 'backwards' },
);
}
/**
* `el`'s text turns into `next`, letter by letter: the letters both say stay
* and slide to their new places, the others lift away or rise in. `from`: what
@@ -196,6 +223,9 @@ export function morphText(el: HTMLElement, next: string, from = textOf(el), o: M
const flow = whole && cs.display === 'inline';
if (cs.display === 'inline' && !whole) el.classList.add('mt-ib');
if (cs.position === 'static') el.classList.add('mt');
// A box that clips its text (one line ending in an ellipsis) lets it show whole while it changes: the letters
// rise from under the line and blur, and the width glides past the new ones. Clipped again once done.
el.classList.add('mt-run');
let r0: DOMRect | null = live ? midway : null;
let t0 = live?.at ?? at ?? null;
let at0: number[] = [];
@@ -316,26 +346,8 @@ export function morphText(el: HTMLElement, next: string, from = textOf(el), o: M
// A long text keeps the same overall sweep: the steps shorten instead.
const so = Math.min(12, 160 / Math.max(1, out.length));
const si = Math.min(22, 260 / Math.max(1, inn.length));
out.forEach((c, i) =>
play(
c,
[
{ opacity: s0.opacity, filter: s0.filter, transform: 'none' },
{ opacity: 0, filter: 'blur(4px)', transform: 'translateY(-0.45em)' },
],
{ duration: 220, delay: i * so, easing: EASE_IN, fill: 'forwards' },
),
);
inn.forEach((c, i) =>
play(
c,
[
{ opacity: 0, filter: 'blur(4px)', transform: 'translateY(0.45em)' },
{ opacity: 1, filter: 'blur(0px)', transform: 'none' },
],
{ duration: 380, delay: 120 + i * si, easing: EASE_OUT, fill: 'backwards' },
),
);
out.forEach((c, i) => letterOut(c, i * so, s0));
inn.forEach((c, i) => letterIn(c, i * si));
const ends =
Math.max(220 + out.length * so, inn.length ? 120 + inn.length * si + 380 : 0, glides || pairs.length ? SMOOTH.duration : 0) + 40;
runs.set(el, { text: next, timer: window.setTimeout(() => finish(el), ends) });
+323
View File
@@ -0,0 +1,323 @@
// A pill that picks one of a few options (the language in the breadcrumb; the demo's set-up state): what is
// picked and a chevron. Its popup, a dropdown as every other (ui/drop.ts: its glass, its gap, its way in and out,
// what shuts it), is a row of segments in one pill frame beside it, its tail one shape with it, pointing at the pill. A click opens it and another picks; or press the pill, slide onto an option and let go
// there (a quick pick: let go anywhere else after sliding and nothing changes). The chevron turns up as it opens
// and on round to down as it shuts; what the pill says morphs into the one picked. Fixed to the screen (it may open
// on a sheet), it also shuts on a wheel or a swipe, and on Tab.
import { h, ic } from '../dom';
import { EASE_IN, play } from '../motion';
import { appear, EDGE, GAP, opened, vanish } from './drop';
import { glide } from './glide';
import { letterIn, letterOut, morphText, setText } from './morph';
export 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. */
lead?: () => Element;
}
export interface PickPill<T> {
el: HTMLButtonElement;
/** Show this value, without motion (it changed elsewhere). */
show(v: T): void;
close(): void;
}
interface PickOpts<T> {
/** The pill's own class (its look). */
cls: string;
label: () => string;
options: PickOption<T>[];
value: T;
/** What the pill says for a value: the option's label unless given (the language's code). */
short?: (v: T) => string;
pick: (v: T) => void;
/** Where the popup goes first: above the pill (default) or under it; the other side where it does not fit. */
prefer?: 'above' | 'below';
}
/** The tail: its height and half its width at the base. */
const TAIL = 6;
const HALF = 10;
/**
* The popup's outline, `w` × `h`: a pill of radius `r` with its tail at `x` on the top edge (`up`) or the bottom
* one, its shoulders leaving the edge level (so it flows out of the frame) and its tip rounded.
*/
function outline(w: number, ht: number, r: number, x: number, up: boolean): string {
const y0 = up ? TAIL : 0;
const y1 = up ? ht : ht - TAIL;
const tip = up ? 0 : ht;
const n = (v: number) => Math.round(v * 100) / 100;
const tail = (a: number, b: number, base: number) =>
`L ${n(a)} ${base} C ${n(a + (b - a) / 4)} ${base} ${n(x - (b - a) / 8)} ${tip} ${n(x)} ${tip} ` +
`C ${n(x + (b - a) / 8)} ${tip} ${n(b - (b - a) / 4)} ${base} ${n(b)} ${base} `;
return (
`M ${r} ${y0} ${up ? tail(x - HALF, x + HALF, y0) : ''}L ${w - r} ${y0} A ${r} ${r} 0 0 1 ${w - r} ${y1} ` +
`${up ? '' : tail(x + HALF, x - HALF, y1)}L ${r} ${y1} A ${r} ${r} 0 0 1 ${r} ${y0} Z`
);
}
interface Open {
el: HTMLElement;
pop: HTMLElement;
close(): void;
choose(b: HTMLElement): void;
/** The dropdowns' highlight on this segment (ui/glide.ts). */
light(b: HTMLElement | null): void;
/** A press on the pill under way: was the popup open before it, and has it slid since. */
press: { wasOpen: boolean; x: number; y: number; moved: boolean } | null;
}
let open: Open | null = null;
/** Gone from where it stands, so one leaving while it still comes in turns back from there. */
function leave(el: Element, frames: Keyframe, ms: number) {
const s = getComputedStyle(el);
el.getAnimations().forEach((a) => a.cancel());
play(
el,
[
{ opacity: s.opacity, transform: s.transform, filter: s.filter },
{ opacity: 0, ...frames },
],
{
duration: ms,
easing: EASE_IN,
fill: 'forwards',
},
).onfinish = () => el.remove();
}
const optionAt = (x: number, y: number) =>
open ? (document.elementFromPoint(x, y)?.closest<HTMLElement>('.pp-pop button') ?? null) : null;
let wired = false;
function wire() {
if (wired) return;
wired = true;
document.addEventListener(
'pointermove',
(e) => {
const p = open?.press;
if (!open || !p) return;
if (Math.hypot(e.clientX - p.x, e.clientY - p.y) > 6) p.moved = true;
open.light(optionAt(e.clientX, e.clientY));
},
true,
);
document.addEventListener(
'pointerup',
(e) => {
const o = open;
const p = o?.press;
if (!o || !p) return;
o.press = null;
const at = optionAt(e.clientX, e.clientY);
if (at && o.pop.contains(at)) return o.choose(at);
const onPill = o.el.contains(document.elementFromPoint(e.clientX, e.clientY));
// A click on the pill: it opened and stays; open already, it shuts. Slid off and let go elsewhere: nothing.
if (onPill ? p.wasOpen && !p.moved : p.moved) o.close();
},
true,
);
document.addEventListener('pointercancel', () => open && (open.press = null), true);
document.addEventListener(
'keydown',
(e) => {
if (!open) return;
if (e.key === 'Tab') open.close();
else if ((e.key === 'ArrowLeft' || e.key === 'ArrowRight') && open.pop.contains(document.activeElement)) {
e.preventDefault();
const bs = [...open.pop.querySelectorAll<HTMLElement>('button')];
const i = bs.indexOf(document.activeElement as HTMLElement) + (e.key === 'ArrowRight' ? 1 : -1);
bs[Math.max(0, Math.min(bs.length - 1, i))].focus({ preventScroll: true });
}
},
true,
);
for (const ev of ['wheel', 'touchmove'])
addEventListener(ev, (e) => open && !open.pop.contains(e.target as Node) && !open.el.contains(e.target as Node) && open.close(), {
passive: true,
capture: true,
});
}
export function pickPill<T>(o: PickOpts<T>): PickPill<T> {
wire();
let value = o.value;
const opt = (v: T) => o.options.find((x) => x.value === v) ?? o.options[0];
const words = (v: T) => (o.short ? o.short(v) : opt(v).label());
const lead = h('span', { class: 'pp-lead' });
const lbl = h('span', { class: 'pp-t' });
const chev = ic('chevron', 'i pp-chev') as SVGElement;
const el = h(
'button',
{ type: 'button', class: `pp ${o.cls}`, 'aria-haspopup': 'menu', 'aria-expanded': 'false' },
lead,
lbl,
chev,
) as HTMLButtonElement;
/** What it leads with follows the value; `swap`: the old one blurs away over the new one as that pops in. */
const paint = (swap = false) => {
const n = opt(value).lead?.();
const old = swap ? [...lead.children].filter((c) => !c.classList.contains('pp-gone')) : [];
lead.replaceChildren(...old, ...(n ? [n] : []));
lead.hidden = !n && !old.length;
el.setAttribute('aria-label', o.label());
if (!swap) return;
// As the first letter of the words beside it: it goes and comes with them (ui/morph.ts).
for (const c of old) {
c.classList.add('pp-gone');
letterOut(c).onfinish = () => c.remove();
}
if (n) letterIn(n);
};
setText(lbl, words(value));
paint();
// The chevron turns by its own angle, so shutting goes on round (up, left, down) rather than back; once down it
// is 90° again, unseen.
chev.addEventListener('transitionend', () => {
if (chev.style.rotate !== '-270deg') return;
chev.style.transition = 'none';
chev.style.rotate = '';
chev.getBoundingClientRect();
chev.style.transition = '';
});
let me: Open | null = null;
let shade: HTMLElement | null = null;
/** Lets go of what every dropdown listens for (ui/drop.ts). */
let release: () => boolean = () => false;
const close = (now = false) => {
if (!me || !release()) return;
if (now) {
me.pop.remove();
shade?.remove();
} else {
vanish(me.pop);
if (shade) leave(shade, {}, 110);
}
shade = null;
if (open === me) open = null;
me = null;
chev.style.rotate = '-270deg';
};
const choose = (b: HTMLElement) => {
const v = o.options[Number(b.dataset.i)].value;
close();
if (v === value) return;
const was = words(value);
value = v;
// Picking may draw the page again (a language): the pill is the same one, put back; its words morph after.
o.pick(v);
paint(true);
morphText(lbl, words(v), was);
};
const show = (focus: boolean) => {
const pop = h(
'div',
{ class: 'pp-pop drop', role: 'menu', 'aria-label': o.label() },
...o.options.map((x, i) =>
h(
'button',
{
type: 'button',
role: 'menuitemradio',
tabindex: '-1',
'data-i': String(i),
'aria-checked': String(x.value === value),
onclick: (e: Event) => choose(e.currentTarget as HTMLElement),
},
x.lead?.() ?? null,
h('span', {}, x.label()),
),
),
);
document.body.append(pop);
// Centred on the pill, inside its sheet where it fits (else the screen), the tail on the pill's middle and its
// tip the dropdowns' gap from it.
const r = el.getBoundingClientRect();
const box = el.closest('.sheet')?.getBoundingClientRect() ?? { left: 0, right: innerWidth };
const w = pop.offsetWidth;
const ht = pop.offsetHeight;
const mid = r.left + r.width / 2;
const lo = Math.max(EDGE, box.left + 10);
const hi = Math.min(innerWidth - EDGE, box.right - 10);
const left = Math.max(lo, Math.min(mid - w / 2, hi - w));
// The tail is part of the glass (one shape with the frame, a clip path): the popup grows by it towards the pill.
const all = ht + TAIL;
const above = r.top - GAP - all >= EDGE;
const under = r.bottom + GAP + all <= innerHeight - EDGE;
const below = o.prefer === 'below' ? under || !above : !above;
const top = below ? r.bottom + GAP : r.top - GAP - all;
pop.classList.add(below ? 'below' : 'above');
const x = Math.max(ht / 2 + HALF, Math.min(mid - left, w - ht / 2 - HALF));
const shape = outline(w, all, ht / 2, x, below);
Object.assign(pop.style, {
left: `${left}px`,
top: `${top}px`,
height: `${all}px`,
clipPath: `path('${shape}')`,
transformOrigin: `${x}px ${below ? 0 : all}px`,
});
const ring = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
ring.setAttribute('class', 'pp-ring');
ring.setAttribute('aria-hidden', 'true');
ring.setAttribute('viewBox', `0 0 ${w} ${all}`);
const edge = document.createElementNS('http://www.w3.org/2000/svg', 'path');
edge.setAttribute('d', shape);
ring.append(edge);
pop.append(ring);
// The glass's shadow (light only, tokens.css): the clip path would cut one off the popup, so a clear pill under
// its frame casts it (an outer shadow shows only outside its box).
shade = h('div', { class: 'pp-shade', 'aria-hidden': 'true' });
Object.assign(shade.style, {
left: `${left}px`,
top: `${top + (below ? TAIL : 0)}px`,
width: `${w}px`,
height: `${ht}px`,
});
pop.before(shade);
play(shade, [{ opacity: 0 }, { opacity: 1 }], { duration: 220, easing: 'ease-out' });
appear(pop);
release = opened(pop, el, close);
// The highlight rests on the picked segment: it is what says which one is picked.
const { light } = glide(pop, [...pop.querySelectorAll<HTMLElement>('button')], pop.querySelector<HTMLElement>('[aria-checked="true"]'));
me = { el, pop, close, choose, light, press: null };
open = me;
chev.style.rotate = '-90deg';
if (focus) pop.querySelector<HTMLElement>('[aria-checked="true"]')?.focus({ preventScroll: true });
};
let pressedAt = 0;
el.addEventListener('pointerdown', (e) => {
if (e.button !== 0) return;
pressedAt = performance.now();
const wasOpen = !!me;
if (!me) show(false);
me!.press = { wasOpen, x: e.clientX, y: e.clientY, moved: false };
// A touch keeps to what it pressed: let it go, so what is under the finger can be found as it slides.
if (el.hasPointerCapture(e.pointerId)) el.releasePointerCapture(e.pointerId);
});
// The keyboard's click (Return, Space): a press already did what it does.
el.addEventListener('click', () => {
if (performance.now() - pressedAt < 800) return;
if (me) close();
else show(true);
});
return {
el,
show(v) {
if (v === value) return;
value = v;
setText(lbl, words(v));
paint();
},
close,
};
}
+46
View File
@@ -0,0 +1,46 @@
// A control pressed scales down (its :active look, in the stylesheets): let go near its edge after a moment and
// the pointer is outside it by then, so the browser gives the click to what holds both and nothing happens. Here
// what was pressed keeps the footprint it had when pressed: let go inside that and it gets the click, the
// browser's own (to the ancestor) dropped. A mouse or trackpad only: a touch stays with what it pressed.
const PRESSABLE = 'button, a[href], [role="button"], label';
let pressed: { el: HTMLElement; at: DOMRect } | null = null;
/** The browser's own click of this press, to the ancestor, is to be dropped. */
let swallow = false;
export function keepPressFootprint() {
document.addEventListener(
'pointerdown',
(e) => {
const el = e.pointerType === 'mouse' && e.button === 0 ? (e.target as Element).closest?.<HTMLElement>(PRESSABLE) : null;
pressed = el ? { el, at: el.getBoundingClientRect() } : null;
},
true,
);
document.addEventListener(
'pointerup',
(e) => {
const p = pressed;
pressed = null;
if (!p || p.el.contains(e.target as Node)) return;
const { at } = p;
if (e.clientX < at.left || e.clientX > at.right || e.clientY < at.top || e.clientY > at.bottom) return;
swallow = true;
// The click, if the browser sends one, comes right after this; anything later is another press.
setTimeout(() => (swallow = false));
p.el.click();
},
true,
);
document.addEventListener(
'click',
(e) => {
if (!swallow || !e.isTrusted) return;
swallow = false;
e.stopPropagation();
e.preventDefault();
},
true,
);
}
+18 -8
View File
@@ -2,7 +2,10 @@
// name. The pill stretches like skiper21's tabs: its leading edge reaches the
// new item first and the trailing edge follows, so the name fading in is always
// inside it. Items grow by flex-grow (a share of the track, not pixels), so
// they stay right while the sheet around them changes width.
// they stay right while the sheet around them changes width. At rest the pill
// stands where CSS puts it (its item's place among the others: controls.css), so
// a sheet changing width, a phone turned, carry it along with nothing to watch;
// only a pick moves it from here.
import { h, ic } from '../dom';
import { EASE_OUT, LEAD, SMOOTH, calm, play } from '../motion';
@@ -64,11 +67,20 @@ export function iconSeg<T extends string>(items: SegItem<T>[], value: T, onPick:
const b = btns.find((x) => x.dataset.v === value);
return b && b.offsetWidth ? [b.offsetLeft, el.clientWidth - b.offsetLeft - b.offsetWidth] : null;
};
/** At rest: its item's place, for CSS to keep (`--i` of `--n`), nothing inline. */
const placePill = () => {
const e = edges();
if (!e) return;
pill.style.left = `${e[0]}px`;
pill.style.right = `${e[1]}px`;
pill.style.setProperty(
'--i',
String(
Math.max(
0,
btns.findIndex((b) => b.dataset.v === value),
),
),
);
pill.style.setProperty('--n', String(btns.length));
pill.style.left = '';
pill.style.right = '';
};
let raf = 0;
@@ -166,9 +178,7 @@ export function iconSeg<T extends string>(items: SegItem<T>[], value: T, onPick:
}
mark();
new ResizeObserver(() => {
if (!raf) placePill();
}).observe(el);
placePill();
return {
el,
sync(v) {
+18 -3
View File
@@ -8,7 +8,7 @@
import { h, ic } from '../dom';
import { BOUNCY, DRAWER, EASE_IN, EASE_OUT, SMOOTH, SOFT, dismisses, play, rubber, unrubber } from '../motion';
import { closeMenu } from './menu';
import { closeDrop } from './drop';
/** A view: its root, and what the sheet reads from it. */
export interface View {
@@ -134,7 +134,12 @@ function build() {
true,
);
document.body.appendChild(root);
new ResizeObserver(() => startWidth(planWidth())).observe(vp);
// What changes the sheet's width says so itself (a view, a row opening, a code swapped: planWidth); left is the
// window, a phone turned or a desktop window crossing the dialog's width. Once a frame at most.
let resizing = 0;
addEventListener('resize', () => {
if (!resizing) resizing = requestAnimationFrame(() => ((resizing = 0), startWidth(planWidth())));
});
pullToClose();
}
@@ -158,6 +163,12 @@ export function onLeave(fn: () => void) {
left = fn;
}
/** Who is told the sheet changed: a view shown in it, its work done (or not), the sheet gone. */
const watchers: (() => void)[] = [];
/** Told whenever the sheet changes (the demo's state switch: demo/way-pick.ts). */
export const onSheetChange = (fn: () => void) => void watchers.push(fn);
const changed = () => watchers.forEach((f) => f());
/** After this sheet closes (once). */
export function onClosed(fn: () => void) {
closed = fn;
@@ -165,7 +176,7 @@ export function onClosed(fn: () => void) {
export function openSheet(factory: ViewFactory) {
if (!root) build();
closeMenu(true);
closeDrop(true);
if (root.dataset.closing) {
// Still on its way out: the new flow opens once it is gone, as it would have a moment later.
next = factory;
@@ -226,6 +237,7 @@ export function openSheet(factory: ViewFactory) {
/* no history */
}
}
changed();
}
/** `now`: gone at once (Escape: what the keyboard does never animates). */
@@ -295,6 +307,7 @@ function gone() {
const f = closed;
closed = null;
f?.();
changed();
const n = next;
next = null;
if (n) openSheet(n);
@@ -419,6 +432,7 @@ function swapView(v: View) {
fill: 'backwards',
},
);
changed();
}
/** Further into a flow (Add → Open on the device). */
@@ -493,6 +507,7 @@ export function glide(change: () => void, focus: (Element | null | undefined)[]
*/
export function settle(done = true) {
sheetEl?.classList.toggle('arrived', done);
changed();
}
/** The sheet scrolls back to the top (a device connected under a scrolled sheet). */
+3 -2
View File
@@ -3,8 +3,9 @@
// agent the router counts a session that lives as data flowing): waiting,
// can't finish (its knocks reach the router, no handshake follows), connected
// (a handshake since the sheet opened, and data coming through), no data (a
// handshake since then, but nothing in except handshakes and keep-alives: an
// outdated configuration). Pure: flows/wait.ts polls for it and draws it.
// handshake since then, but nothing in except handshakes and keep-alives: it
// sends from an address the router does not expect, so the router drops it).
// Pure: flows/wait.ts polls for it and draws it.
import type { Device } from '../shared/types';