Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f12ca19e7 |
No files matched your search
@@ -1,88 +1,182 @@
|
|||||||
# Dawnline
|
<div align="center">
|
||||||
|
|
||||||
[](https://github.com/tickcount/luci-app-dawnline/actions/workflows/ci.yml)
|
<picture>
|
||||||
[](https://github.com/tickcount/luci-app-dawnline/actions/workflows/build.yml)
|
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-dark.svg">
|
||||||
|
<img alt="Dawnline" src="docs/assets/logo-light.svg" width="88" height="88">
|
||||||
|
</picture>
|
||||||
|
|
||||||
Your OpenWrt router as a private VPN for the people you choose.
|
<h1>Dawnline</h1>
|
||||||
|
|
||||||
Dawnline runs an [AmneziaWG](https://docs.amnezia.org/) server on the router
|
**Your OpenWrt router as a private VPN for the people you choose.**
|
||||||
and gives every person a personal link. They open it, add their own devices
|
|
||||||
(up to the limit you set) and connect with AmneziaVPN or AmneziaWG. You decide
|
|
||||||
what each person may reach: the home network, the internet, or both.
|
|
||||||
|
|
||||||
Dawnline is the successor of [Liminal](https://github.com/tickcount/openwrt-liminal):
|
<a href="https://github.com/tickcount/luci-app-dawnline/releases/latest"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/github/release/tickcount/luci-app-dawnline.svg?variant=secondary&font=geist&mode=dark"><img alt="Latest release" src="https://shieldcn.dev/github/release/tickcount/luci-app-dawnline.svg?variant=secondary&font=geist&mode=light"></picture></a>
|
||||||
the same idea rebuilt around people instead of peers, with a personal portal,
|
<a href="https://github.com/tickcount/luci-app-dawnline/actions/workflows/ci.yml"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/github/ci/tickcount/luci-app-dawnline.svg?variant=secondary&font=geist&mode=dark"><img alt="CI" src="https://shieldcn.dev/github/ci/tickcount/luci-app-dawnline.svg?variant=secondary&font=geist&mode=light"></picture></a>
|
||||||
limits, live traffic and a LuCI admin that follows a modern design.
|
<a href="https://github.com/tickcount/luci-app-dawnline/releases"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/github/downloads/tickcount/luci-app-dawnline.svg?variant=secondary&font=geist&mode=dark"><img alt="Downloads" src="https://shieldcn.dev/github/downloads/tickcount/luci-app-dawnline.svg?variant=secondary&font=geist&mode=light"></picture></a>
|
||||||
|
<a href="LICENSE"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/github/license/tickcount/luci-app-dawnline.svg?variant=secondary&font=geist&mode=dark"><img alt="License" src="https://shieldcn.dev/github/license/tickcount/luci-app-dawnline.svg?variant=secondary&font=geist&mode=light"></picture></a>
|
||||||
|
<br>
|
||||||
|
<a href="https://openwrt.org/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/badge/OpenWrt-24.10%20%C2%B7%20opkg.svg?variant=secondary&font=geist&logo=openwrt&mode=dark"><img alt="OpenWrt 24.10" src="https://shieldcn.dev/badge/OpenWrt-24.10%20%C2%B7%20opkg.svg?variant=secondary&font=geist&logo=openwrt&mode=light"></picture></a>
|
||||||
|
<a href="https://openwrt.org/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/badge/OpenWrt-25.12%20%C2%B7%20apk.svg?variant=secondary&font=geist&logo=openwrt&mode=dark"><img alt="OpenWrt 25.12" src="https://shieldcn.dev/badge/OpenWrt-25.12%20%C2%B7%20apk.svg?variant=secondary&font=geist&logo=openwrt&mode=light"></picture></a>
|
||||||
|
<a href="https://docs.amnezia.org/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/badge/AmneziaWG-2.0%20%C2%B7%203.1.svg?variant=secondary&font=geist&logo=wireguard&mode=dark"><img alt="AmneziaWG 2.0 and 3.1" src="https://shieldcn.dev/badge/AmneziaWG-2.0%20%C2%B7%203.1.svg?variant=secondary&font=geist&logo=wireguard&mode=light"></picture></a>
|
||||||
|
|
||||||

|
[**Quick start**](#-quick-start) · [Features](#-features) · [How it works](#-how-it-works) · [Screenshots](#-a-closer-look) · [FAQ](#-faq) · [Development](#-development)
|
||||||
|
|
||||||
| People | A person |
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
Dawnline runs an [AmneziaWG] server on your OpenWrt router and gives every
|
||||||
|
person you invite **a personal link**. They open it, **add their own phones and
|
||||||
|
computers** and connect with AmneziaVPN, AmneziaWG or WireGuard. You decide
|
||||||
|
**what each of them may reach** (the home network, the internet, or both) and
|
||||||
|
**for how long, how much and when**.
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="docs/screenshots/portal.png" alt="The personal portal: devices and access, and adding a phone in three steps" width="860">
|
||||||
|
<br>
|
||||||
|
<sub>A person's own page: their devices and access. Adding a phone takes three steps, and the page sees it connect.</sub>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## 💡 Why Dawnline?
|
||||||
|
|
||||||
|
Sharing a home VPN usually means making a config file by hand, sending it over
|
||||||
|
a messenger and hoping nobody shares it further. Dawnline turns that around:
|
||||||
|
|
||||||
|
| | A VPN by hand | With Dawnline |
|
||||||
|
|---|---|---|
|
||||||
|
| **Setting up a device** | You make a config and send it | They add it themselves from their link |
|
||||||
|
| **Who can do what** | Everyone gets the same | Home, internet or both, per person |
|
||||||
|
| **Ending access** | Find and delete their peers | A date, a data limit, or one click |
|
||||||
|
| **Knowing what goes on** | Read `wg show` | Who is online, traffic, places, a log |
|
||||||
|
| **When something breaks** | You find out from them | A watchdog notices and repairs it |
|
||||||
|
|
||||||
|
It is the successor of [Liminal]: the same idea rebuilt around people instead
|
||||||
|
of peers, with a personal portal, limits, live traffic and a LuCI admin that
|
||||||
|
follows a modern design.
|
||||||
|
|
||||||
|
## 🚀 Quick start
|
||||||
|
|
||||||
|
1. **Install** on the router (it asks before it changes anything):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sh -c "$(wget -qO- https://raw.githubusercontent.com/tickcount/luci-app-dawnline/main/install.sh)"
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Set up** in LuCI: <kbd>Network</kbd> › <kbd>Dawnline</kbd>, and follow the
|
||||||
|
wizard. It suggests the port, the public address and the networks.
|
||||||
|
3. **Invite** someone: <kbd>Add person</kbd>, then send them the link or the
|
||||||
|
invite card with its QR code. They do the rest.
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
> Behind Cloudflare, give the portal a port Cloudflare proxies: 2053, 2083,
|
||||||
|
> 2087, 2096 or 8443.
|
||||||
|
|
||||||
|
## ✨ Features
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td width="50%" valign="top">
|
||||||
|
<h3>🔗 A link, not an account</h3>
|
||||||
|
<p>Three words, like <code>vpn.example.com/kamiro-telosu-bavine</code>. The link is the key: no sign-up, no password, and a new link locks the old one out at once.</p>
|
||||||
|
</td>
|
||||||
|
<td width="50%" valign="top">
|
||||||
|
<h3>📱 Their own devices</h3>
|
||||||
|
<p>People add, rename and remove devices up to their limit. Adding one walks them through it: the right app, then a QR code, a link, a key or a file.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td valign="top">
|
||||||
|
<h3>👥 People, not peers</h3>
|
||||||
|
<p>One card per person with their devices, who is online, traffic, end date and data limit. Filter by who needs attention or is paused.</p>
|
||||||
|
</td>
|
||||||
|
<td valign="top">
|
||||||
|
<h3>🧭 Who reaches what</h3>
|
||||||
|
<p>The home network, the internet or both; only some networks or devices at home (a NAS, Home Assistant). Family sees family, guests see guests.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td valign="top">
|
||||||
|
<h3>⏳ Limits</h3>
|
||||||
|
<p>End dates, monthly or total data limits, allowed hours, a pause button. Changes apply at once, without dropping anyone else's connection.</p>
|
||||||
|
</td>
|
||||||
|
<td valign="top">
|
||||||
|
<h3>🕶️ Disguise</h3>
|
||||||
|
<p>Presets that make the VPN traffic harder to spot and block, with what each one needs from the apps.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td valign="top">
|
||||||
|
<h3>🏠 Internet like a home device</h3>
|
||||||
|
<p>People's devices go online the way the devices at home do, so your proxies, ad and DNS filters cover them too.</p>
|
||||||
|
</td>
|
||||||
|
<td valign="top">
|
||||||
|
<h3>🗺️ Overview and places</h3>
|
||||||
|
<p>Who is online with what, speed now, the last 30 days, and a map of where people connect from, at city level.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td valign="top">
|
||||||
|
<h3>🩺 Repairs itself</h3>
|
||||||
|
<p>Health checks with one-click fixes, and a watchdog that checks the tunnels, access rules and portal every minute and mends them.</p>
|
||||||
|
</td>
|
||||||
|
<td valign="top">
|
||||||
|
<h3>📦 Updates and backups</h3>
|
||||||
|
<p>Dawnline and AmneziaWG built for your firmware in one place; nightly backups, and export and import to move to another router.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
## 🧩 How it works
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
you(["🛠️ You, in LuCI"]) -- "add a person" --> link["🔗 Their link"]
|
||||||
|
link -- "they open it" --> portal["📱 Their portal"]
|
||||||
|
portal -- "add a device" --> app["App and connection"]
|
||||||
|
app == "AmneziaWG tunnel" ==> router["🌅 Dawnline<br>on your router"]
|
||||||
|
router -- "if allowed" --> home["🏠 Home network"]
|
||||||
|
router -- "if allowed" --> net["🌍 Internet"]
|
||||||
|
```
|
||||||
|
|
||||||
|
1. **You add a person** in LuCI and choose what they may reach, their device
|
||||||
|
limit, an end date or a data limit.
|
||||||
|
2. **They open their link** on any device. The portal is theirs alone: it shows
|
||||||
|
their devices and their access; access and limits stay yours to change.
|
||||||
|
3. **They add a device.** The portal points them to the app for that system and
|
||||||
|
hands over the connection; the router gives each device its own keys.
|
||||||
|
4. **The device connects** through the router's AmneziaWG server, and Dawnline
|
||||||
|
lets through what that person may reach, counts their traffic and keeps to
|
||||||
|
their limits.
|
||||||
|
|
||||||
|
## 📸 A closer look
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="docs/screenshots/overview.png" alt="Overview: who is online, speed, the last 30 days and where people connect from" width="720">
|
||||||
|
<br>
|
||||||
|
<sub><b>Overview</b>: who is online, speed now, the last 30 days and a map of where people connect from.</sub>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td width="50%" valign="top">
|
||||||
|
<img alt="People: everyone on the server, with their devices, data and state" src="docs/screenshots/people.png">
|
||||||
|
<p align="center"><sub><b>People</b>: online, ending soon, over the limit, outside their hours, paused.</sub></p>
|
||||||
|
</td>
|
||||||
|
<td width="50%" valign="top">
|
||||||
|
<img alt="A person: their devices, traffic, places and limits" src="docs/screenshots/person.png">
|
||||||
|
<p align="center"><sub><b>A person</b>: their devices, traffic, places and limits.</sub></p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
## 📋 Requirements
|
||||||
|
|
||||||
|
| | What Dawnline needs |
|
||||||
|---|---|
|
|---|---|
|
||||||
|  |  |
|
| **OpenWrt** | 24.10 (opkg, `.ipk`) or 25.12 (apk, `.apk`) |
|
||||||
|
| **AmneziaWG** | `kmod-amneziawg`, `amneziawg-tools`, `luci-proto-amneziawg`: the installer adds a build made for your firmware when they are missing |
|
||||||
|
| **Free flash** | about 2 MB |
|
||||||
|
|
||||||
| Personal portal | Home network access |
|
## 📥 Install
|
||||||
|---|---|
|
|
||||||
|  |  |
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **People, not peers.** One card per person with device chips, live status,
|
|
||||||
traffic, end date and data limit. Add a person, send them the link or the
|
|
||||||
invite card (QR code), and they do the rest.
|
|
||||||
- **Personal portal.** Every person gets a link made of three words
|
|
||||||
(`https://vpn.example.com/kamiro-telosu-bavine`). The link is the key: no
|
|
||||||
accounts, no sessions, and a new link locks the old one out at once. People
|
|
||||||
add, rename and remove their devices and get each one as a QR code,
|
|
||||||
"Open in AmneziaVPN" (`vpn://`), a key or a `.conf` file. They cannot change
|
|
||||||
access or limits. Links work on the portal's own port with a Let's Encrypt
|
|
||||||
certificate (via ACME), several addresses at once (a Cloudflare-proxied name,
|
|
||||||
a plain IP), the same link at home, and wrong links can redirect to your
|
|
||||||
website. Behind Cloudflare, pick a port it proxies (2053, 2083, 2087, 2096 or
|
|
||||||
8443).
|
|
||||||
- **Access per person**, enforced in an `inet dawnline` nftables table on the
|
|
||||||
tunnel interface: home network only, internet only, or both, and optionally
|
|
||||||
only some home networks or home services (picked from the devices the router
|
|
||||||
sees over DHCP). Devices of different people reach each other never, always,
|
|
||||||
or within circles (family sees family, guests see guests). "Who reaches what"
|
|
||||||
sums up the rules and "Check access" walks them step by step for a device
|
|
||||||
and an address.
|
|
||||||
- **Limits.** End dates (pause, keep, or remove devices when they pass), monthly
|
|
||||||
or total data limits, allowed hours, pause anyone. Devices
|
|
||||||
drop off the tunnel at once (`awg syncconf`, no interface restart).
|
|
||||||
- **Disguise presets** for AmneziaWG obfuscation (junk packets,
|
|
||||||
header and padding parameters), with what each preset needs from the apps.
|
|
||||||
- **Internet like a home device.** Tunnel clients' internet traffic enters the
|
|
||||||
router from the LAN, through a small network namespace on the LAN bridge
|
|
||||||
(needs `kmod-veth`). Whatever handles LAN traffic on the router (proxies, DPI
|
|
||||||
bypass, DNS filters, the `lan` zone) handles VPN clients too, with no
|
|
||||||
per-tool integration.
|
|
||||||
- **Overview.** Who is online with what, speed now, today and the last 30 days,
|
|
||||||
and a map of where people connect from (city level).
|
|
||||||
- **Diagnostics.** Health checks with one-click fixes, including the ones that
|
|
||||||
matter for reaching the portal from outside (DNS, port forwards, reply
|
|
||||||
routing behind proxies such as SSClash/Mihomo, certificate coverage). A
|
|
||||||
watchdog checks the tunnels, access rules, portal, resolver and LuCI link
|
|
||||||
every minute and repairs them on its own (a cron job looks after the agent
|
|
||||||
itself). One log holds people's activity and the service log: tunnel starts
|
|
||||||
and stops with netifd's reasons, repairs and errors (`dawnline log` on the
|
|
||||||
router).
|
|
||||||
- **Updates.** Dawnline itself, AmneziaWG builds for your firmware (choose
|
|
||||||
between [Slava-Shchipunov](https://github.com/Slava-Shchipunov/awg-openwrt)
|
|
||||||
and [2Grey](https://github.com/2Grey/awg-openwrt), AmneziaWG 2.0 or 3.1), and
|
|
||||||
the few OpenWrt packages Dawnline adds.
|
|
||||||
- **Backups** nightly and before risky operations, JSON export/import to move
|
|
||||||
to another router.
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
- OpenWrt **24.10** (opkg, `.ipk`) or **25.12** (apk, `.apk`)
|
|
||||||
- AmneziaWG (`kmod-amneziawg`, `amneziawg-tools`, `luci-proto-amneziawg`):
|
|
||||||
the installer adds a build made for your firmware when it is missing
|
|
||||||
- About 2 MB of free flash
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
On the router:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sh -c "$(wget -qO- https://raw.githubusercontent.com/tickcount/luci-app-dawnline/main/install.sh)"
|
sh -c "$(wget -qO- https://raw.githubusercontent.com/tickcount/luci-app-dawnline/main/install.sh)"
|
||||||
@@ -90,17 +184,21 @@ sh -c "$(wget -qO- https://raw.githubusercontent.com/tickcount/luci-app-dawnline
|
|||||||
|
|
||||||
The installer checks the firmware, the clock, free space and DNS, lets you pick
|
The installer checks the firmware, the clock, free space and DNS, lets you pick
|
||||||
a release (the latest is the default), shows the plan and asks before it
|
a release (the latest is the default), shows the plan and asks before it
|
||||||
changes anything. It downloads the Dawnline package for your package manager,
|
changes anything. It downloads the package for your package manager, checks it
|
||||||
checks it against `sha256sums.txt`, installs AmneziaWG built for your firmware
|
against `sha256sums.txt`, installs AmneziaWG built for your firmware if it is
|
||||||
if it is missing, then installs Dawnline with its dependencies and checks that
|
missing, then installs Dawnline and checks that LuCI can reach it.
|
||||||
LuCI can reach it. Then open **LuCI → Network → Dawnline** and run the setup
|
|
||||||
wizard.
|
|
||||||
|
|
||||||
Before changing anything it saves `/etc/config/{dawnline,network,firewall,dhcp,uhttpd}`
|
> [!NOTE]
|
||||||
and the service state to `/etc/dawnline/installer-backups/` (the newest three
|
> Before changing anything it saves `/etc/config/{dawnline,network,firewall,dhcp,uhttpd}`
|
||||||
are kept); if a step fails, it puts them back. Packages are not rolled back: to
|
> and the service state to `/etc/dawnline/installer-backups/` (the newest three
|
||||||
return to an older release, run the installer with `--tag`. Everything it does
|
> are kept), and puts them back if a step fails. Packages are not rolled back:
|
||||||
is logged to `/tmp/dawnline-install.log`.
|
> to return to an older release, run the installer with `--tag`. Everything it
|
||||||
|
> does is logged to `/tmp/dawnline-install.log`.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Installer options</b></summary>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
With options, download it first:
|
With options, download it first:
|
||||||
|
|
||||||
@@ -117,39 +215,64 @@ sh /tmp/dawnline-install.sh --awg grey # AmneziaWG from 2Grey
|
|||||||
| `-n`, `--dry-run` | Check the system, resolve, download and verify the release; change nothing |
|
| `-n`, `--dry-run` | Check the system, resolve, download and verify the release; change nothing |
|
||||||
| `-v`, `--verbose` / `-q`, `--quiet` | More detail / only warnings and errors |
|
| `-v`, `--verbose` / `-q`, `--quiet` | More detail / only warnings and errors |
|
||||||
| `--tag X.Y.Z` | A given release (`sh install.sh 0.3.1` works too) |
|
| `--tag X.Y.Z` | A given release (`sh install.sh 0.3.1` works too) |
|
||||||
| `--awg auto\|slava\|grey\|skip` | Where AmneziaWG comes from when it is missing: [Slava-Shchipunov](https://github.com/Slava-Shchipunov/awg-openwrt), then [2Grey](https://github.com/2Grey/awg-openwrt) (`auto`, the default), only one of them, or not at all (install it later from **Dawnline → Updates**). `DAWNLINE_AWG` does the same |
|
| `--awg auto\|slava\|grey\|skip` | Where AmneziaWG comes from when it is missing: [Slava-Shchipunov], then [2Grey] (`auto`, the default), only one of them, or not at all (install it later from **Dawnline → Updates**). `DAWNLINE_AWG` does the same |
|
||||||
| `--no-awg` | Same as `--awg skip` |
|
| `--no-awg` | Same as `--awg skip` |
|
||||||
|
|
||||||
When GitHub is slow or blocked, the installer retries downloads through
|
</details>
|
||||||
`ghfast.top` and `gh-proxy.com` on its own. To fetch the installer itself
|
|
||||||
through a mirror:
|
<details>
|
||||||
|
<summary><b>When GitHub is slow or blocked</b></summary>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
The installer retries downloads through `ghfast.top` and `gh-proxy.com` on its
|
||||||
|
own. To fetch the installer itself through a mirror:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sh -c "$(wget -qO- https://cdn.jsdelivr.net/gh/tickcount/luci-app-dawnline@main/install.sh)"
|
sh -c "$(wget -qO- https://cdn.jsdelivr.net/gh/tickcount/luci-app-dawnline@main/install.sh)"
|
||||||
sh -c "$(wget -qO- https://ghfast.top/https://raw.githubusercontent.com/tickcount/luci-app-dawnline/main/install.sh)"
|
sh -c "$(wget -qO- https://ghfast.top/https://raw.githubusercontent.com/tickcount/luci-app-dawnline/main/install.sh)"
|
||||||
```
|
```
|
||||||
|
|
||||||
By hand, from a [release](https://github.com/tickcount/luci-app-dawnline/releases):
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Installing by hand</b></summary>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
From a [release](https://github.com/tickcount/luci-app-dawnline/releases):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
opkg update && opkg install ./luci-app-dawnline-0.1.0.ipk # OpenWrt 24.10
|
opkg update && opkg install ./luci-app-dawnline-0.1.0.ipk # OpenWrt 24.10
|
||||||
apk update && apk add --allow-untrusted ./luci-app-dawnline-0.1.0.apk # OpenWrt 25.12
|
apk update && apk add --allow-untrusted ./luci-app-dawnline-0.1.0.apk # OpenWrt 25.12
|
||||||
```
|
```
|
||||||
|
|
||||||
**Upgrade** from **Dawnline → Updates**, or run the installer again. Settings,
|
</details>
|
||||||
keys and history are kept, and a backup is made first.
|
|
||||||
|
|
||||||
**Remove** on the router:
|
**Upgrade** from <kbd>Dawnline</kbd> › <kbd>Updates</kbd>, or run the installer
|
||||||
|
again. Settings, keys and history are kept, and a backup is made first.
|
||||||
|
|
||||||
|
### Remove
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sh -c "$(wget -qO- https://raw.githubusercontent.com/tickcount/luci-app-dawnline/main/uninstall.sh)"
|
sh -c "$(wget -qO- https://raw.githubusercontent.com/tickcount/luci-app-dawnline/main/uninstall.sh)"
|
||||||
```
|
```
|
||||||
|
|
||||||
It backs up the configuration to `/etc/dawnline/backups`, runs Dawnline's own
|
It backs up the configuration to `/etc/dawnline/backups`, runs Dawnline's own
|
||||||
removal (the same as **Settings → Remove Dawnline from this router**), removes
|
removal (the same as <kbd>Settings</kbd> › <kbd>Remove Dawnline from this router</kbd>),
|
||||||
the package and cleans up what is left. AmneziaWG stays installed, since other
|
removes the package and cleans up what is left. After installing Dawnline
|
||||||
tunnels may use it. After installing Dawnline again, restore the backup in
|
again, restore the backup in <kbd>Settings</kbd> › <kbd>Backups</kbd>.
|
||||||
**Settings → Backups**. With options, download it first:
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> AmneziaWG stays installed, since other tunnels may use it. Add `--remove-awg`
|
||||||
|
> to take it away too.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Uninstaller options</b></summary>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
With options, download it first:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
wget -O /tmp/dawnline-uninstall.sh https://raw.githubusercontent.com/tickcount/luci-app-dawnline/main/uninstall.sh
|
wget -O /tmp/dawnline-uninstall.sh https://raw.githubusercontent.com/tickcount/luci-app-dawnline/main/uninstall.sh
|
||||||
@@ -163,25 +286,83 @@ sh /tmp/dawnline-uninstall.sh --dry-run
|
|||||||
| `--remove-awg` | Also remove AmneziaWG, unless another interface still uses it (`--keep-awg`, the default, keeps it) |
|
| `--remove-awg` | Also remove AmneziaWG, unless another interface still uses it (`--keep-awg`, the default, keeps it) |
|
||||||
| `-n`, `--dry-run` | Show what would be removed; change nothing |
|
| `-n`, `--dry-run` | Show what would be removed; change nothing |
|
||||||
|
|
||||||
By hand: **Settings → Remove Dawnline from this router** (keeps a backup), then
|
By hand: <kbd>Settings</kbd> › <kbd>Remove Dawnline from this router</kbd>
|
||||||
`opkg remove luci-app-dawnline` or `apk del luci-app-dawnline`.
|
(keeps a backup), then `opkg remove luci-app-dawnline` or
|
||||||
|
`apk del luci-app-dawnline`.
|
||||||
|
|
||||||
## What Dawnline changes on the router
|
</details>
|
||||||
|
|
||||||
|
## ❓ FAQ
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Which apps do people use?</b></summary>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
AmneziaVPN or AmneziaWG on phones and computers, and plain WireGuard when the
|
||||||
|
disguise is off. The portal shows each person the app for their system and how
|
||||||
|
to add the connection in it.
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>What happens when someone loses their link?</b></summary>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
Make a new one on their page. The old link stops working at once; their devices
|
||||||
|
keep working, unless you tick the ones to remove with it.
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Does it touch the rest of my router?</b></summary>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
Only what it created, and `dawnline teardown` removes all of it. The full list
|
||||||
|
is under [What Dawnline changes on the router](#-what-dawnline-changes-on-the-router).
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>How do I move to another router?</b></summary>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<kbd>Export JSON</kbd> in <kbd>Settings</kbd> › <kbd>Backups</kbd> on the old
|
||||||
|
one, install Dawnline on the new one and import the file there.
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Where do the places on the map come from?</b></summary>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
From the address a device connects from, looked up at city level and cached on
|
||||||
|
the router. It can be turned off in <kbd>Settings</kbd>.
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
## 🧾 What Dawnline changes on the router
|
||||||
|
|
||||||
Only objects it created: network interfaces tagged `_dawnline`, firewall
|
Only objects it created: network interfaces tagged `_dawnline`, firewall
|
||||||
sections named `dawnline_*`, the `inet dawnline` nft table, `/tmp/hosts/dawnline`,
|
sections named `dawnline_*`, the `inet dawnline` nft table, `/tmp/hosts/dawnline`,
|
||||||
the `dawnline` network namespace with its two veth links (`dlx0`, `dll0`, the
|
the `dawnline` network namespace with its two veth links (`dlx0`, `dll0`, the
|
||||||
latter a port of the LAN bridge), policy rules for the tunnel interfaces with
|
latter a port of the LAN bridge, which needs `kmod-veth`), policy rules for the
|
||||||
one routing table, a second dnsmasq instance on port 5354
|
tunnel interfaces with one routing table, a second dnsmasq instance on port
|
||||||
(`/var/etc/dawnline-dns.conf`), a cron line for the agent's heartbeat check
|
5354 (`/var/etc/dawnline-dns.conf`), a cron line for the agent's heartbeat
|
||||||
and, while the portal is on, a uhttpd instance for it. `dawnline teardown`
|
check and, while the portal is on, a uhttpd instance for it.
|
||||||
removes all of them.
|
`dawnline teardown` removes all of them.
|
||||||
|
|
||||||
Data lives in `/etc/config/dawnline` (mode 0600, contains private keys) and
|
Data lives in `/etc/config/dawnline` (mode 0600, contains private keys) and
|
||||||
`/etc/dawnline/` (usage, events, issued configurations, backups). Live counters
|
`/etc/dawnline/` (usage, events, issued configurations, backups). Live counters
|
||||||
are kept in `/var/run/dawnline` and flushed to flash at most hourly.
|
are kept in `/var/run/dawnline` and flushed to flash at most hourly. Access
|
||||||
|
changes reach the tunnel with `awg syncconf`, without restarting the interface;
|
||||||
|
`dawnline log` on the router shows the service log.
|
||||||
|
|
||||||
## Development
|
## 🛠️ Development
|
||||||
|
|
||||||
```
|
```
|
||||||
package/luci-app-dawnline/
|
package/luci-app-dawnline/
|
||||||
@@ -203,18 +384,25 @@ npm ci
|
|||||||
npm run format # Prettier
|
npm run format # Prettier
|
||||||
npm run ci # format check, types, tests, minified bundles
|
npm run ci # format check, types, tests, minified bundles
|
||||||
|
|
||||||
scripts/lint-ucode.py # static ucode checks
|
scripts/lint-ucode.py # static ucode checks
|
||||||
scripts/check-ucode.sh root@router # compile every ucode file on a router
|
scripts/check-ucode.sh root@router # compile every ucode file on a router
|
||||||
scripts/deploy.sh root@router # install the working tree (backs up configs first)
|
scripts/deploy.sh root@router # install the working tree (backs up configs first)
|
||||||
scripts/build-packages.sh all # .ipk and .apk with the OpenWrt SDK in Docker
|
scripts/build-packages.sh all # .ipk and .apk with the OpenWrt SDK in Docker
|
||||||
scripts/capture-screenshots.mjs # capture docs/screenshots/raw/*.png from a router
|
scripts/capture-screenshots.mjs --demo # README screenshots from a router, a demo cast in place of its people
|
||||||
scripts/frame-screenshots.py # frame them for this README
|
scripts/frame-screenshots.py # frame them for this README
|
||||||
```
|
```
|
||||||
|
|
||||||
The web bundles are committed: CI fails when they are out of date. Pushing a
|
The web bundles are committed: CI fails when they are out of date. Pushing a
|
||||||
tag `vX.Y.Z` (matching `PKG_VERSION`) builds both packages with the OpenWrt SDK
|
tag `vX.Y.Z` (matching `PKG_VERSION`) builds both packages with the OpenWrt SDK
|
||||||
and publishes a release with `sha256sums.txt`.
|
and publishes a release with `sha256sums.txt`.
|
||||||
|
|
||||||
## License
|
---
|
||||||
|
|
||||||
[MIT](LICENSE)
|
<div align="center">
|
||||||
|
<sub>Made for OpenWrt · <a href="LICENSE">MIT license</a> · <a href="#readme">Back to top ↑</a></sub>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
[AmneziaWG]: https://docs.amnezia.org/
|
||||||
|
[Liminal]: https://github.com/tickcount/openwrt-liminal
|
||||||
|
[Slava-Shchipunov]: https://github.com/Slava-Shchipunov/awg-openwrt
|
||||||
|
[2Grey]: https://github.com/2Grey/awg-openwrt
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="16" fill="#ffffff"/><path d="M14 38a18 18 0 0 1 36 0z" fill="#0a0a0a"/><rect x="12" y="43" width="40" height="4" rx="2" fill="#0a0a0a" fill-opacity=".5"/></svg>
|
||||||
|
After Width: | Height: | Size: 254 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="16" fill="#0a0a0a"/><path d="M14 38a18 18 0 0 1 36 0z" fill="#ffffff"/><rect x="12" y="43" width="40" height="4" rx="2" fill="#ffffff" fill-opacity=".5"/></svg>
|
||||||
|
After Width: | Height: | Size: 254 B |
|
Before Width: | Height: | Size: 525 KiB |
|
Before Width: | Height: | Size: 908 KiB After Width: | Height: | Size: 457 KiB |
|
Before Width: | Height: | Size: 639 KiB After Width: | Height: | Size: 397 KiB |
|
Before Width: | Height: | Size: 825 KiB After Width: | Height: | Size: 430 KiB |
|
Before Width: | Height: | Size: 615 KiB After Width: | Height: | Size: 363 KiB |
|
Before Width: | Height: | Size: 138 KiB |
|
Before Width: | Height: | Size: 394 KiB After Width: | Height: | Size: 435 KiB |
|
Before Width: | Height: | Size: 191 KiB After Width: | Height: | Size: 373 KiB |
|
Before Width: | Height: | Size: 327 KiB After Width: | Height: | Size: 407 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 187 KiB |
@@ -6,7 +6,7 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=luci-app-dawnline
|
PKG_NAME:=luci-app-dawnline
|
||||||
PKG_VERSION:=0.9.0
|
PKG_VERSION:=0.10.0
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_LICENSE:=MIT
|
PKG_LICENSE:=MIT
|
||||||
|
|
||||||
|
|||||||
@@ -5,25 +5,25 @@
|
|||||||
'require poll';
|
'require poll';
|
||||||
'require rpc';
|
'require rpc';
|
||||||
'require ui';
|
'require ui';
|
||||||
var bi=Object.create;var Po=Object.defineProperty;var xi=Object.getOwnPropertyDescriptor;var wi=Object.getOwnPropertyNames;var yi=Object.getPrototypeOf,ki=Object.prototype.hasOwnProperty;var $i=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var Ci=(n,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of wi(e))!ki.call(n,a)&&a!==r&&Po(n,a,{get:()=>e[a],enumerable:!(o=xi(e,a))||o.enumerable});return n};var Ei=(n,e,r)=>(r=n!=null?bi(yi(n)):{},Ci(e||!n||!n.__esModule?Po(r,"default",{value:n,enumerable:!0}):r,n));var rr=$i((nr,or)=>{"use strict";var tr=(function(){var n=function(w,v){var y=236,E=17,k=w,z=r[v],f=null,g=0,S=null,T=[],N={},W=function(P,D){g=k*4+17,f=(function(_){for(var I=new Array(_),M=0;M<_;M+=1){I[M]=new Array(_);for(var j=0;j<_;j+=1)I[M][j]=null}return I})(g),q(0,0),q(g-7,0),q(0,g-7),K(),R(),de(P,D),k>=7&&Z(P),S==null&&(S=ge(k,z,T)),Q(S,D)},q=function(P,D){for(var _=-1;_<=7;_+=1)if(!(P+_<=-1||g<=P+_))for(var I=-1;I<=7;I+=1)D+I<=-1||g<=D+I||(0<=_&&_<=6&&(I==0||I==6)||0<=I&&I<=6&&(_==0||_==6)||2<=_&&_<=4&&2<=I&&I<=4?f[P+_][D+I]=!0:f[P+_][D+I]=!1)},Y=function(){for(var P=0,D=0,_=0;_<8;_+=1){W(!0,_);var I=a.getLostPoint(N);(_==0||P>I)&&(P=I,D=_)}return D},R=function(){for(var P=8;P<g-8;P+=1)f[P][6]==null&&(f[P][6]=P%2==0);for(var D=8;D<g-8;D+=1)f[6][D]==null&&(f[6][D]=D%2==0)},K=function(){for(var P=a.getPatternPosition(k),D=0;D<P.length;D+=1)for(var _=0;_<P.length;_+=1){var I=P[D],M=P[_];if(f[I][M]==null)for(var j=-2;j<=2;j+=1)for(var J=-2;J<=2;J+=1)j==-2||j==2||J==-2||J==2||j==0&&J==0?f[I+j][M+J]=!0:f[I+j][M+J]=!1}},Z=function(P){for(var D=a.getBCHTypeNumber(k),_=0;_<18;_+=1){var I=!P&&(D>>_&1)==1;f[Math.floor(_/3)][_%3+g-8-3]=I}for(var _=0;_<18;_+=1){var I=!P&&(D>>_&1)==1;f[_%3+g-8-3][Math.floor(_/3)]=I}},de=function(P,D){for(var _=z<<3|D,I=a.getBCHTypeInfo(_),M=0;M<15;M+=1){var j=!P&&(I>>M&1)==1;M<6?f[M][8]=j:M<8?f[M+1][8]=j:f[g-15+M][8]=j}for(var M=0;M<15;M+=1){var j=!P&&(I>>M&1)==1;M<8?f[8][g-M-1]=j:M<9?f[8][15-M-1+1]=j:f[8][15-M-1]=j}f[g-8][8]=!P},Q=function(P,D){for(var _=-1,I=g-1,M=7,j=0,J=a.getMaskFunction(D),V=g-1;V>0;V-=2)for(V==6&&(V-=1);;){for(var pe=0;pe<2;pe+=1)if(f[I][V-pe]==null){var xe=!1;j<P.length&&(xe=(P[j]>>>M&1)==1);var ne=J(I,V-pe);ne&&(xe=!xe),f[I][V-pe]=xe,M-=1,M==-1&&(j+=1,M=7)}if(I+=_,I<0||g<=I){I-=_,_=-_;break}}},te=function(P,D){for(var _=0,I=0,M=0,j=new Array(D.length),J=new Array(D.length),V=0;V<D.length;V+=1){var pe=D[V].dataCount,xe=D[V].totalCount-pe;I=Math.max(I,pe),M=Math.max(M,xe),j[V]=new Array(pe);for(var ne=0;ne<j[V].length;ne+=1)j[V][ne]=255&P.getBuffer()[ne+_];_+=pe;var De=a.getErrorCorrectPolynomial(xe),Ae=s(j[V],De.getLength()-1),So=Ae.mod(De);J[V]=new Array(De.getLength()-1);for(var ne=0;ne<J[V].length;ne+=1){var To=ne+So.getLength()-J[V].length;J[V][ne]=To>=0?So.getAt(To):0}}for(var _o=0,ne=0;ne<D.length;ne+=1)_o+=D[ne].totalCount;for(var Un=new Array(_o),Xt=0,ne=0;ne<I;ne+=1)for(var V=0;V<D.length;V+=1)ne<j[V].length&&(Un[Xt]=j[V][ne],Xt+=1);for(var ne=0;ne<M;ne+=1)for(var V=0;V<D.length;V+=1)ne<J[V].length&&(Un[Xt]=J[V][ne],Xt+=1);return Un},ge=function(P,D,_){for(var I=l.getRSBlocks(P,D),M=d(),j=0;j<_.length;j+=1){var J=_[j];M.put(J.getMode(),4),M.put(J.getLength(),a.getLengthInBits(J.getMode(),P)),J.write(M)}for(var V=0,j=0;j<I.length;j+=1)V+=I[j].dataCount;if(M.getLengthInBits()>V*8)throw"code length overflow. ("+M.getLengthInBits()+">"+V*8+")";for(M.getLengthInBits()+4<=V*8&&M.put(0,4);M.getLengthInBits()%8!=0;)M.putBit(!1);for(;!(M.getLengthInBits()>=V*8||(M.put(y,8),M.getLengthInBits()>=V*8));)M.put(E,8);return te(M,I)};N.addData=function(P,D){D=D||"Byte";var _=null;switch(D){case"Numeric":_=c(P);break;case"Alphanumeric":_=p(P);break;case"Byte":_=u(P);break;case"Kanji":_=x(P);break;default:throw"mode:"+D}T.push(_),S=null},N.isDark=function(P,D){if(P<0||g<=P||D<0||g<=D)throw P+","+D;return f[P][D]},N.getModuleCount=function(){return g},N.make=function(){if(k<1){for(var P=1;P<40;P++){for(var D=l.getRSBlocks(P,z),_=d(),I=0;I<T.length;I++){var M=T[I];_.put(M.getMode(),4),_.put(M.getLength(),a.getLengthInBits(M.getMode(),P)),M.write(_)}for(var j=0,I=0;I<D.length;I++)j+=D[I].dataCount;if(_.getLengthInBits()<=j*8)break}k=P}W(!1,Y())},N.createTableTag=function(P,D){P=P||2,D=typeof D>"u"?P*4:D;var _="";_+='<table style="',_+=" border-width: 0px; border-style: none;",_+=" border-collapse: collapse;",_+=" padding: 0px; margin: "+D+"px;",_+='">',_+="<tbody>";for(var I=0;I<N.getModuleCount();I+=1){_+="<tr>";for(var M=0;M<N.getModuleCount();M+=1)_+='<td style="',_+=" border-width: 0px; border-style: none;",_+=" border-collapse: collapse;",_+=" padding: 0px; margin: 0px;",_+=" width: "+P+"px;",_+=" height: "+P+"px;",_+=" background-color: ",_+=N.isDark(I,M)?"#000000":"#ffffff",_+=";",_+='"/>';_+="</tr>"}return _+="</tbody>",_+="</table>",_},N.createSvgTag=function(P,D,_,I){var M={};typeof arguments[0]=="object"&&(M=arguments[0],P=M.cellSize,D=M.margin,_=M.alt,I=M.title),P=P||2,D=typeof D>"u"?P*4:D,_=typeof _=="string"?{text:_}:_||{},Line truncated
|
var vi=Object.create;var Po=Object.defineProperty;var bi=Object.getOwnPropertyDescriptor;var xi=Object.getOwnPropertyNames;var wi=Object.getPrototypeOf,yi=Object.prototype.hasOwnProperty;var ki=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var $i=(n,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of xi(e))!yi.call(n,a)&&a!==r&&Po(n,a,{get:()=>e[a],enumerable:!(o=bi(e,a))||o.enumerable});return n};var Ci=(n,e,r)=>(r=n!=null?vi(wi(n)):{},$i(e||!n||!n.__esModule?Po(r,"default",{value:n,enumerable:!0}):r,n));var Wo=ki((Uo,Go)=>{"use strict";var jo=(function(){var n=function(C,k){var y=236,w=17,b=C,H=r[k],f=null,g=0,M=null,T=[],z={},W=function(A,N){g=b*4+17,f=(function(S){for(var O=new Array(S),_=0;_<S;_+=1){O[_]=new Array(S);for(var j=0;j<S;j+=1)O[_][j]=null}return O})(g),q(0,0),q(g-7,0),q(0,g-7),V(),I(),de(A,N),b>=7&&Q(A),M==null&&(M=F(b,H,T)),ee(M,N)},q=function(A,N){for(var S=-1;S<=7;S+=1)if(!(A+S<=-1||g<=A+S))for(var O=-1;O<=7;O+=1)N+O<=-1||g<=N+O||(0<=S&&S<=6&&(O==0||O==6)||0<=O&&O<=6&&(S==0||S==6)||2<=S&&S<=4&&2<=O&&O<=4?f[A+S][N+O]=!0:f[A+S][N+O]=!1)},Z=function(){for(var A=0,N=0,S=0;S<8;S+=1){W(!0,S);var O=a.getLostPoint(z);(S==0||A>O)&&(A=O,N=S)}return N},I=function(){for(var A=8;A<g-8;A+=1)f[A][6]==null&&(f[A][6]=A%2==0);for(var N=8;N<g-8;N+=1)f[6][N]==null&&(f[6][N]=N%2==0)},V=function(){for(var A=a.getPatternPosition(b),N=0;N<A.length;N+=1)for(var S=0;S<A.length;S+=1){var O=A[N],_=A[S];if(f[O][_]==null)for(var j=-2;j<=2;j+=1)for(var Y=-2;Y<=2;Y+=1)j==-2||j==2||Y==-2||Y==2||j==0&&Y==0?f[O+j][_+Y]=!0:f[O+j][_+Y]=!1}},Q=function(A){for(var N=a.getBCHTypeNumber(b),S=0;S<18;S+=1){var O=!A&&(N>>S&1)==1;f[Math.floor(S/3)][S%3+g-8-3]=O}for(var S=0;S<18;S+=1){var O=!A&&(N>>S&1)==1;f[S%3+g-8-3][Math.floor(S/3)]=O}},de=function(A,N){for(var S=H<<3|N,O=a.getBCHTypeInfo(S),_=0;_<15;_+=1){var j=!A&&(O>>_&1)==1;_<6?f[_][8]=j:_<8?f[_+1][8]=j:f[g-15+_][8]=j}for(var _=0;_<15;_+=1){var j=!A&&(O>>_&1)==1;_<8?f[8][g-_-1]=j:_<9?f[8][15-_-1+1]=j:f[8][15-_-1]=j}f[g-8][8]=!A},ee=function(A,N){for(var S=-1,O=g-1,_=7,j=0,Y=a.getMaskFunction(N),J=g-1;J>0;J-=2)for(J==6&&(J-=1);;){for(var ue=0;ue<2;ue+=1)if(f[O][J-ue]==null){var xe=!1;j<A.length&&(xe=(A[j]>>>_&1)==1);var te=Y(O,J-ue);te&&(xe=!xe),f[O][J-ue]=xe,_-=1,_==-1&&(j+=1,_=7)}if(O+=S,O<0||g<=O){O-=S,S=-S;break}}},B=function(A,N){for(var S=0,O=0,_=0,j=new Array(N.length),Y=new Array(N.length),J=0;J<N.length;J+=1){var ue=N[J].dataCount,xe=N[J].totalCount-ue;O=Math.max(O,ue),_=Math.max(_,xe),j[J]=new Array(ue);for(var te=0;te<j[J].length;te+=1)j[J][te]=255&A.getBuffer()[te+S];S+=ue;var De=a.getErrorCorrectPolynomial(xe),Ae=s(j[J],De.getLength()-1),So=Ae.mod(De);Y[J]=new Array(De.getLength()-1);for(var te=0;te<Y[J].length;te+=1){var To=te+So.getLength()-Y[J].length;Y[J][te]=To>=0?So.getAt(To):0}}for(var _o=0,te=0;te<N.length;te+=1)_o+=N[te].totalCount;for(var Gn=new Array(_o),Qt=0,te=0;te<O;te+=1)for(var J=0;J<N.length;J+=1)te<j[J].length&&(Gn[Qt]=j[J][te],Qt+=1);for(var te=0;te<_;te+=1)for(var J=0;J<N.length;J+=1)te<Y[J].length&&(Gn[Qt]=Y[J][te],Qt+=1);return Gn},F=function(A,N,S){for(var O=l.getRSBlocks(A,N),_=d(),j=0;j<S.length;j+=1){var Y=S[j];_.put(Y.getMode(),4),_.put(Y.getLength(),a.getLengthInBits(Y.getMode(),A)),Y.write(_)}for(var J=0,j=0;j<O.length;j+=1)J+=O[j].dataCount;if(_.getLengthInBits()>J*8)throw"code length overflow. ("+_.getLengthInBits()+">"+J*8+")";for(_.getLengthInBits()+4<=J*8&&_.put(0,4);_.getLengthInBits()%8!=0;)_.putBit(!1);for(;!(_.getLengthInBits()>=J*8||(_.put(y,8),_.getLengthInBits()>=J*8));)_.put(w,8);return B(_,O)};z.addData=function(A,N){N=N||"Byte";var S=null;switch(N){case"Numeric":S=c(A);break;case"Alphanumeric":S=p(A);break;case"Byte":S=u(A);break;case"Kanji":S=x(A);break;default:throw"mode:"+N}T.push(S),M=null},z.isDark=function(A,N){if(A<0||g<=A||N<0||g<=N)throw A+","+N;return f[A][N]},z.getModuleCount=function(){return g},z.make=function(){if(b<1){for(var A=1;A<40;A++){for(var N=l.getRSBlocks(A,H),S=d(),O=0;O<T.length;O++){var _=T[O];S.put(_.getMode(),4),S.put(_.getLength(),a.getLengthInBits(_.getMode(),A)),_.write(S)}for(var j=0,O=0;O<N.length;O++)j+=N[O].dataCount;if(S.getLengthInBits()<=j*8)break}b=A}W(!1,Z())},z.createTableTag=function(A,N){A=A||2,N=typeof N>"u"?A*4:N;var S="";S+='<table style="',S+=" border-width: 0px; border-style: none;",S+=" border-collapse: collapse;",S+=" padding: 0px; margin: "+N+"px;",S+='">',S+="<tbody>";for(var O=0;O<z.getModuleCount();O+=1){S+="<tr>";for(var _=0;_<z.getModuleCount();_+=1)S+='<td style="',S+=" border-width: 0px; border-style: none;",S+=" border-collapse: collapse;",S+=" padding: 0px; margin: 0px;",S+=" width: "+A+"px;",S+=" height: "+A+"px;",S+=" background-color: ",S+=z.isDark(O,_)?"#000000":"#ffffff",S+=";",S+='"/>';S+="</tr>"}return S+="</tbody>",S+="</table>",S},z.createSvgTag=function(A,N,S,O){var _={};typeof arguments[0]=="object"&&(_=arguments[0],A=_.cellSize,N=_.margin,S=_.alt,O=_.title),A=A||2,N=typeof N>"u"?A*4:N,S=typeof S=="string"?{text:S}:S||{},S.Line truncated
|
||||||
`}return _%2&&P>0?Ae.substring(0,Ae.length-_-1)+Array(_+1).join("▀"):Ae.substring(0,Ae.length-1)};return N.createASCII=function(P,D){if(P=P||1,P<2)return X(D);P-=1,D=typeof D>"u"?P*2:D;var _=N.getModuleCount()*P+D*2,I=D,M=_-D,j,J,V,pe,xe=Array(P+1).join("██"),ne=Array(P+1).join(" "),De="",Ae="";for(j=0;j<_;j+=1){for(V=Math.floor((j-I)/P),Ae="",J=0;J<_;J+=1)pe=1,I<=J&&J<M&&I<=j&&j<M&&N.isDark(V,Math.floor((J-I)/P))&&(pe=0),Ae+=pe?xe:ne;for(V=0;V<P;V+=1)De+=Ae+`
|
`}return S%2&&A>0?Ae.substring(0,Ae.length-S-1)+Array(S+1).join("▀"):Ae.substring(0,Ae.length-1)};return z.createASCII=function(A,N){if(A=A||1,A<2)return pe(N);A-=1,N=typeof N>"u"?A*2:N;var S=z.getModuleCount()*A+N*2,O=N,_=S-N,j,Y,J,ue,xe=Array(A+1).join("██"),te=Array(A+1).join(" "),De="",Ae="";for(j=0;j<S;j+=1){for(J=Math.floor((j-O)/A),Ae="",Y=0;Y<S;Y+=1)ue=1,O<=Y&&Y<_&&O<=j&&j<_&&z.isDark(J,Math.floor((Y-O)/A))&&(ue=0),Ae+=ue?xe:te;for(J=0;J<A;J+=1)De+=Ae+`
|
||||||
`}return De.substring(0,De.length-1)},N.renderTo2dContext=function(P,D){D=D||2;for(var _=N.getModuleCount(),I=0;I<_;I++)for(var M=0;M<_;M++)P.fillStyle=N.isDark(I,M)?"black":"white",P.fillRect(I*D,M*D,D,D)},N};n.stringToBytesFuncs={default:function(w){for(var v=[],y=0;y<w.length;y+=1){var E=w.charCodeAt(y);v.push(E&255)}return v}},n.stringToBytes=n.stringToBytesFuncs.default,n.createStringToBytes=function(w,v){var y=(function(){for(var k=m(w),z=function(){var R=k.read();if(R==-1)throw"eof";return R},f=0,g={};;){var S=k.read();if(S==-1)break;var T=z(),N=z(),W=z(),q=String.fromCharCode(S<<8|T),Y=N<<8|W;g[q]=Y,f+=1}if(f!=v)throw f+" != "+v;return g})(),E=63;return function(k){for(var z=[],f=0;f<k.length;f+=1){var g=k.charCodeAt(f);if(g<128)z.push(g);else{var S=y[k.charAt(f)];typeof S=="number"?(S&255)==S?z.push(S):(z.push(S>>>8),z.push(S&255)):z.push(E)}}return z}};var e={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},r={L:1,M:0,Q:3,H:2},o={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},a=(function(){var w=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],v=1335,y=7973,E=21522,k={},z=function(f){for(var g=0;f!=0;)g+=1,f>>>=1;return g};return k.getBCHTypeInfo=function(f){for(var g=f<<10;z(g)-z(v)>=0;)g^=v<<z(g)-z(v);return(f<<10|g)^E},k.getBCHTypeNumber=function(f){for(var g=f<<12;z(g)-z(y)>=0;)g^=y<<z(g)-z(y);return f<<12|g},k.getPatternPosition=function(f){return w[f-1]},k.getMaskFunction=function(f){switch(f){case o.PATTERN000:return function(g,S){return(g+S)%2==0};case o.PATTERN001:return function(g,S){return g%2==0};case o.PATTERN010:return function(g,S){return S%3==0};case o.PATTERN011:return function(g,S){return(g+S)%3==0};case o.PATTERN100:return function(g,S){return(Math.floor(g/2)+Math.floor(S/3))%2==0};case o.PATTERN101:return function(g,S){return g*S%2+g*S%3==0};case o.PATTERN110:return function(g,S){return(g*S%2+g*S%3)%2==0};case o.PATTERN111:return function(g,S){return(g*S%3+(g+S)%2)%2==0};default:throw"bad maskPattern:"+f}},k.getErrorCorrectPolynomial=function(f){for(var g=s([1],0),S=0;S<f;S+=1)g=g.multiply(s([1,i.gexp(S)],0));return g},k.getLengthInBits=function(f,g){if(1<=g&&g<10)switch(f){case e.MODE_NUMBER:return 10;case e.MODE_ALPHA_NUM:return 9;case e.MODE_8BIT_BYTE:return 8;case e.MODE_KANJI:return 8;default:throw"mode:"+f}else if(g<27)switch(f){case e.MODE_NUMBER:return 12;case e.MODE_ALPHA_NUM:return 11;case e.MODE_8BIT_BYTE:return 16;case e.MODE_KANJI:return 10;default:throw"mode:"+f}else if(g<41)switch(f){case e.MODE_NUMBER:return 14;case e.MODE_ALPHA_NUM:return 13;case e.MODE_8BIT_BYTE:return 16;case e.MODE_KANJI:return 12;default:throw"mode:"+f}else throw"type:"+g},k.getLostPoint=function(f){for(var g=f.getModuleCount(),S=0,T=0;T<g;T+=1)for(var N=0;N<g;N+=1){for(var W=0,q=f.isDark(T,N),Y=-1;Y<=1;Y+=1)if(!(T+Y<0||g<=T+Y))for(var R=-1;R<=1;R+=1)N+R<0||g<=N+R||Y==0&&R==0||q==f.isDark(T+Y,N+R)&&(W+=1);W>5&&(S+=3+W-5)}for(var T=0;T<g-1;T+=1)for(var N=0;N<g-1;N+=1){var K=0;f.isDark(T,N)&&(K+=1),f.isDark(T+1,N)&&(K+=1),f.isDark(T,N+1)&&(K+=1),f.isDark(T+1,N+1)&&(K+=1),(K==0||K==4)&&(S+=3)}for(var T=0;T<g;T+=1)for(var N=0;N<g-6;N+=1)f.isDark(T,N)&&!f.isDark(T,N+1)&&f.isDark(T,N+2)&&f.isDark(T,N+3)&&f.isDark(T,N+4)&&!f.isDark(T,N+5)&&f.isDark(T,N+6)&&(S+=40);for(var N=0;N<g;N+=1)for(var T=0;T<g-6;T+=1)f.isDark(T,N)&&!f.isDark(T+1,N)&&f.isDark(T+2,N)&&f.isDark(T+3,N)&&f.isDark(T+4,N)&&!f.isDark(T+5,N)&&f.isDark(T+6,N)&&(S+=40);for(var Z=0,N=0;N<g;N+=1)for(var T=0;T<g;T+=1)f.isDark(T,N)&&(Z+=1);var de=Math.abs(100*Z/g/g-50)/5;return S+=de*10,S},k})(),i=(function(){for(var w=new Array(256),v=new Array(256),y=0;y<8;y+=1)w[y]=1<<y;for(var y=8;y<256;y+=1)w[y]=w[y-4]^w[y-5]^w[y-6]^w[y-8];for(var y=0;y<255;y+=1)v[w[y]]=y;var E={};return E.glog=function(k){if(k<1)throw"glog("+k+")";return v[k]},E.gexp=function(k){for(;k<0;)k+=255;for(;k>=256;)k-=255;return w[k]},E})();function s(w,v){if(typeof w.length>"u")throw w.length+"/"+v;var y=(function(){for(var k=0;k<w.length&&w[k]==0;)k+=1;for(var z=new Array(w.length-k+v),f=0;f<w.length-k;f+=1)z[f]=w[f+k];return z})(),E={};return E.getAt=function(k){return y[k]},E.getLength=function(){return y.length},E.multiply=function(k){for(var z=new Array(E.getLength()+k.getLength()-1),f=0;f<E.getLength();f+=1)for(var g=0;g<k.getLength();g+=1)z[f+g]^=i.gexp(i.glog(E.getAt(f))+i.glog(k.getAt(g)));return s(z,0)},E.mod=function(k){if(E.getLength()
Line truncated
|
`}return De.substring(0,De.length-1)},z.renderTo2dContext=function(A,N){N=N||2;for(var S=z.getModuleCount(),O=0;O<S;O++)for(var _=0;_<S;_++)A.fillStyle=z.isDark(O,_)?"black":"white",A.fillRect(O*N,_*N,N,N)},z};n.stringToBytesFuncs={default:function(C){for(var k=[],y=0;y<C.length;y+=1){var w=C.charCodeAt(y);k.push(w&255)}return k}},n.stringToBytes=n.stringToBytesFuncs.default,n.createStringToBytes=function(C,k){var y=(function(){for(var b=m(C),H=function(){var I=b.read();if(I==-1)throw"eof";return I},f=0,g={};;){var M=b.read();if(M==-1)break;var T=H(),z=H(),W=H(),q=String.fromCharCode(M<<8|T),Z=z<<8|W;g[q]=Z,f+=1}if(f!=k)throw f+" != "+k;return g})(),w=63;return function(b){for(var H=[],f=0;f<b.length;f+=1){var g=b.charCodeAt(f);if(g<128)H.push(g);else{var M=y[b.charAt(f)];typeof M=="number"?(M&255)==M?H.push(M):(H.push(M>>>8),H.push(M&255)):H.push(w)}}return H}};var e={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},r={L:1,M:0,Q:3,H:2},o={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},a=(function(){var C=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],k=1335,y=7973,w=21522,b={},H=function(f){for(var g=0;f!=0;)g+=1,f>>>=1;return g};return b.getBCHTypeInfo=function(f){for(var g=f<<10;H(g)-H(k)>=0;)g^=k<<H(g)-H(k);return(f<<10|g)^w},b.getBCHTypeNumber=function(f){for(var g=f<<12;H(g)-H(y)>=0;)g^=y<<H(g)-H(y);return f<<12|g},b.getPatternPosition=function(f){return C[f-1]},b.getMaskFunction=function(f){switch(f){case o.PATTERN000:return function(g,M){return(g+M)%2==0};case o.PATTERN001:return function(g,M){return g%2==0};case o.PATTERN010:return function(g,M){return M%3==0};case o.PATTERN011:return function(g,M){return(g+M)%3==0};case o.PATTERN100:return function(g,M){return(Math.floor(g/2)+Math.floor(M/3))%2==0};case o.PATTERN101:return function(g,M){return g*M%2+g*M%3==0};case o.PATTERN110:return function(g,M){return(g*M%2+g*M%3)%2==0};case o.PATTERN111:return function(g,M){return(g*M%3+(g+M)%2)%2==0};default:throw"bad maskPattern:"+f}},b.getErrorCorrectPolynomial=function(f){for(var g=s([1],0),M=0;M<f;M+=1)g=g.multiply(s([1,i.gexp(M)],0));return g},b.getLengthInBits=function(f,g){if(1<=g&&g<10)switch(f){case e.MODE_NUMBER:return 10;case e.MODE_ALPHA_NUM:return 9;case e.MODE_8BIT_BYTE:return 8;case e.MODE_KANJI:return 8;default:throw"mode:"+f}else if(g<27)switch(f){case e.MODE_NUMBER:return 12;case e.MODE_ALPHA_NUM:return 11;case e.MODE_8BIT_BYTE:return 16;case e.MODE_KANJI:return 10;default:throw"mode:"+f}else if(g<41)switch(f){case e.MODE_NUMBER:return 14;case e.MODE_ALPHA_NUM:return 13;case e.MODE_8BIT_BYTE:return 16;case e.MODE_KANJI:return 12;default:throw"mode:"+f}else throw"type:"+g},b.getLostPoint=function(f){for(var g=f.getModuleCount(),M=0,T=0;T<g;T+=1)for(var z=0;z<g;z+=1){for(var W=0,q=f.isDark(T,z),Z=-1;Z<=1;Z+=1)if(!(T+Z<0||g<=T+Z))for(var I=-1;I<=1;I+=1)z+I<0||g<=z+I||Z==0&&I==0||q==f.isDark(T+Z,z+I)&&(W+=1);W>5&&(M+=3+W-5)}for(var T=0;T<g-1;T+=1)for(var z=0;z<g-1;z+=1){var V=0;f.isDark(T,z)&&(V+=1),f.isDark(T+1,z)&&(V+=1),f.isDark(T,z+1)&&(V+=1),f.isDark(T+1,z+1)&&(V+=1),(V==0||V==4)&&(M+=3)}for(var T=0;T<g;T+=1)for(var z=0;z<g-6;z+=1)f.isDark(T,z)&&!f.isDark(T,z+1)&&f.isDark(T,z+2)&&f.isDark(T,z+3)&&f.isDark(T,z+4)&&!f.isDark(T,z+5)&&f.isDark(T,z+6)&&(M+=40);for(var z=0;z<g;z+=1)for(var T=0;T<g-6;T+=1)f.isDark(T,z)&&!f.isDark(T+1,z)&&f.isDark(T+2,z)&&f.isDark(T+3,z)&&f.isDark(T+4,z)&&!f.isDark(T+5,z)&&f.isDark(T+6,z)&&(M+=40);for(var Q=0,z=0;z<g;z+=1)for(var T=0;T<g;T+=1)f.isDark(T,z)&&(Q+=1);var de=Math.abs(100*Q/g/g-50)/5;return M+=de*10,M},b})(),i=(function(){for(var C=new Array(256),k=new Array(256),y=0;y<8;y+=1)C[y]=1<<y;for(var y=8;y<256;y+=1)C[y]=C[y-4]^C[y-5]^C[y-6]^C[y-8];for(var y=0;y<255;y+=1)k[C[y]]=y;var w={};return w.glog=function(b){if(b<1)throw"glog("+b+")";return k[b]},w.gexp=function(b){for(;b<0;)b+=255;for(;b>=256;)b-=255;return C[b]},w})();function s(C,k){if(typeof C.length>"u")throw C.length+"/"+k;var y=(function(){for(var b=0;b<C.length&&C[b]==0;)b+=1;for(var H=new Array(C.length-b+k),f=0;f<C.length-b;f+=1)H[f]=C[f+b];return H})(),w={};return w.getAt=function(b){return y[b]},w.getLength=function(){return y.length},w.multiply=function(b){for(var H=new Array(w.getLength()+b.getLength()-1),f=0;f<w.getLength();f+=1)for(var g=0;g<b.getLength();g+=1)H[f+g]^=i.gexp(i.glog(w.getAt(f))+i.glog(b.getAt(g)));return s(H,0)},w.mod=function(b){if(w.getLength()
Line truncated
|
||||||
`)}function Fi(n){let e=new Map(n.people.map(o=>[o.id,o.name])),r=new Map(n.people.flatMap(o=>o.devices.map(a=>[a.id,a.name])));return{people:e,devices:r}}function Fe(n,e,r,o="",a=[]){let i=Fi(n),s=[...e.map(p=>({ts:p.ts,category:Bt(p.type),type:p.type,person:p.person?i.people.get(p.person)??p.pname??p.person:"",device:p.device?i.devices.get(p.device)??p.dname??p.device:"",detail:p.detail??"",where:p.where??"",by:Ne(p)??""})),...a.map(p=>({ts:p.ts,category:"system",type:`${p.src}.${p.level}`,person:"",device:"",detail:`${p.who?`${p.who} `:""}${p.msg}${p.detail?`
|
`)}function qi(n){let e=new Map(n.people.map(o=>[o.id,o.name])),r=new Map(n.people.flatMap(o=>o.devices.map(a=>[a.id,a.name])));return{people:e,devices:r}}function Fe(n,e,r,o="",a=[]){let i=qi(n),s=[...e.map(p=>({ts:p.ts,category:It(p.type),type:p.type,person:p.person?i.people.get(p.person)??p.pname??p.person:"",device:p.device?i.devices.get(p.device)??p.dname??p.device:"",detail:p.detail??"",where:p.where??"",by:Ne(p)??""})),...a.map(p=>({ts:p.ts,category:"system",type:`${p.src}.${p.level}`,person:"",device:"",detail:`${p.who?`${p.who} `:""}${p.msg}${p.detail?`
|
||||||
${p.detail}`:""}`,where:Ot[p.src]??p.src,by:""}))].sort((p,u)=>p.ts-u.ts).map(({ts:p,...u})=>({time:new Date(p*1e3).toISOString(),...u})),l=new Date().toISOString().slice(0,10),d=`dawnline-activity${o?`-${o}`:""}-${l}.${r}`;if(r==="json"){Te(d,JSON.stringify(s,null,2),"application/json");return}Te(d,cr(["time","category","type","person","device","detail","where","by"],s),"text/csv")}var qi=[["","Everything"],["7","Older than 7 days"],["30","Older than 30 days"],["90","Older than 90 days"]],pr=n=>n?`${n} event${n===1?"":"s"} removed`:"Nothing matched";function tt(n,e,r,o,a,i=!1){let s=t("select",{class:"cbi-input-select"},[t("option",{value:""},"All categories"),...Mt.map(d=>t("option",{value:d,selected:d===a?"selected":null},ut[d])),i?t("option",{value:"system",selected:a==="system"?"selected":null},"System"):""]),l=t("select",{class:"cbi-input-select"},qi.map(([d,c])=>t("option",{value:d},c)));oe(n,[t("p",{class:"dl-muted"},`${e} This cannot be undone; export first if you want a copy.`),t("label",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Category"),s]),t("label",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Which events"),l])],[ie()," ",H("Clear",async()=>{let d=0;if(s.value!=="system")try{d+=(await A.logsClear({...r,category:s.value,older_days:l.value})).removed}catch(c){U(be(c),"error",1e4);return}if(i&&(s.value==="system"||s.value===""))try{d+=(await A.serviceLogClear(l.value)).removed}catch(c){ae(),U(`${s.value==="system"?"":`Activity: ${pr(d).toLowerCase()}. `}The service log was not cleared: ${be(c)}`,"error",1e4),o();return}ae(),U(pr(d),"success",3e3),o()},"negative")])}function St(n,e,r,o){let a=n==="device"?`Clears ${r}'s daily and monthly traffic history. Their person's totals and data limit are not changed.`:n==="person"?`Clears ${r}'s traffic history and that of their devices. Their data limit starts again from zero.`:"Clears traffic history for everyone. Data limits start again from zero.";oe(n==="all"?"Reset all traffic history?":`Reset traffic history for ${r}?`,[t("p",{class:"dl-muted"},a)],[ie()," ",H("Reset",async()=>{await G(()=>A.usageClear(n,e),"Traffic history reset")&&(ae(),o())},"negative")])}function ve(n,e,r){let o=t("button",{type:"button",role:"switch",class:`dl-switch${n?" on":""}`,"aria-checked":n?"true":"false","aria-label":e,click:()=>{let a=!o.classList.contains("on");eo(o,a),r?.(a)}},t("i"));return o}function eo(n,e){n.classList.toggle("on",e),n.setAttribute("aria-checked",e?"true":"false")}var Pe=n=>n.classList.contains("on");function we(n,e,r={}){n.some(([i])=>i===e)||(n=[...n,[e,e]]);let o=t("div",{class:`dl-seg${r.cls?` ${r.cls}`:""}`,role:"radiogroup","aria-label":r.label??null,"data-value":e}),a=()=>o.querySelectorAll(":scope > button").forEach(i=>{let s=i.dataset.v===o.dataset.value;i.classList.toggle("on",s),i.setAttribute("aria-checked",s?"true":"false")});for(let[i,s]of n)o.appendChild(t("button",{type:"button",role:"radio","data-v":i,click:()=>{i!==o.dataset.value&&(r.optimistic!==!1&&(o.dataset.value=i,a()),r.onChange?.(i))}},s));return a(),o}function qe(n,e,r,o={}){return t("button",{type:"button",...o,class:`dl-chipbtn${e?" on":""}${o.class?` ${o.class}`:""}`,"aria-pressed":e?"true":"false",click:r},n)}function un(n,e){n.classList.toggle("on",e),n.setAttribute("aria-pressed",e?"true":"false")}function se(n,e={}){return t("input",{type:"text",class:"cbi-input-text",value:n,...e})}var Ki={jc:"0",jmin:"0",jmax:"0",s1:"0",s2:"0",s3:"0",s4:"0",h1:"1",h2:"2",h3:"3",h4:"4",i1:"",i2:"",i3:"",i4:"",i5:""},Vi={header_protection_key:"HeaderProtectionKey",content_padding_addition:"ContentPaddingAddition",rekey_after_time:"RekeyAfterTime",rekey_timeout:"RekeyTimeout",reject_after_time:"RejectAfterTime",keepalive_timeout:"KeepaliveTimeout",max_handshake_attempts:"MaxHandshakeAttempts",random_trailers:"RandomTrailers",disable_cookies:"DisableCookies"};function Ji(n){let e={};for(let[r,o]of Object.entries(Vi))n[r]!=null&&n[r]!==""&&(e[o]=String(n[r]));return e}function Yi(n,e){let r=n.amnezia,o=r.obfuscation??{},a=d=>o[d]!=null&&o[d]!==""?String(o[d]):Ki[d],i=r.host.replace(/^\[(.*)\]$/,"$1"),s={H1:a("h1"),H2:a("h2"),H3:a("h3"),H4:a("h4"),I1:a("i1"),I2:a("i2"),I3:a("i3"),I4:a("i4"),I5:a("i5"),Jc:a("jc"),Jmin:a("jmin"),Jmax:a("jmax"),S1:a("s1"),S2:a("s2"),S3:a("s3"),S4:a("s4"),...Ji(o),allowed_ips:r.allowed_ips,client_ip:r.client_ip,client_priv_key:r.client_priv_key,client_pub_key:r.client_pub_key,config:n.conf.replace(/\r?\n/g,`\r
|
${p.detail}`:""}`,where:Bt[p.src]??p.src,by:""}))].sort((p,u)=>p.ts-u.ts).map(({ts:p,...u})=>({time:new Date(p*1e3).toISOString(),...u})),l=new Date().toISOString().slice(0,10),d=`dawnline-activity${o?`-${o}`:""}-${l}.${r}`;if(r==="json"){Te(d,JSON.stringify(s,null,2),"application/json");return}Te(d,dr(["time","category","type","person","device","detail","where","by"],s),"text/csv")}var Ki=[["","Everything"],["7","Older than 7 days"],["30","Older than 30 days"],["90","Older than 90 days"]],cr=n=>n?`${n} event${n===1?"":"s"} removed`:"Nothing matched";function et(n,e,r,o,a,i=!1){let s=t("select",{class:"cbi-input-select"},[t("option",{value:""},"All categories"),...Lt.map(d=>t("option",{value:d,selected:d===a?"selected":null},ut[d])),i?t("option",{value:"system",selected:a==="system"?"selected":null},"System"):""]),l=t("select",{class:"cbi-input-select"},Ki.map(([d,c])=>t("option",{value:d},c)));oe(n,[t("p",{class:"dl-muted"},`${e} This cannot be undone; export first if you want a copy.`),t("label",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Category"),s]),t("label",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Which events"),l])],[ie()," ",D("Clear",async()=>{let d=0;if(s.value!=="system")try{d+=(await P.logsClear({...r,category:s.value,older_days:l.value})).removed}catch(c){U(be(c),"error",1e4);return}if(i&&(s.value==="system"||s.value===""))try{d+=(await P.serviceLogClear(l.value)).removed}catch(c){ae(),U(`${s.value==="system"?"":`Activity: ${cr(d).toLowerCase()}. `}The service log was not cleared: ${be(c)}`,"error",1e4),o();return}ae(),U(cr(d),"success",3e3),o()},"negative")])}function Mt(n,e,r,o){let a=n==="device"?`Clears ${r}'s daily and monthly traffic history. Their person's totals and data limit are not changed.`:n==="person"?`Clears ${r}'s traffic history and that of their devices. Their data limit starts again from zero.`:"Clears traffic history for everyone. Data limits start again from zero.";oe(n==="all"?"Reset all traffic history?":`Reset traffic history for ${r}?`,[t("p",{class:"dl-muted"},a)],[ie()," ",D("Reset",async()=>{await G(()=>P.usageClear(n,e),"Traffic history reset")&&(ae(),o())},"negative")])}function ve(n,e,r){let o=t("button",{type:"button",role:"switch",class:`dl-switch${n?" on":""}`,"aria-checked":n?"true":"false","aria-label":e,click:()=>{let a=!o.classList.contains("on");eo(o,a),r?.(a)}},t("i"));return o}function eo(n,e){n.classList.toggle("on",e),n.setAttribute("aria-checked",e?"true":"false")}var Pe=n=>n.classList.contains("on");function we(n,e,r={}){n.some(([i])=>i===e)||(n=[...n,[e,e]]);let o=t("div",{class:`dl-seg${r.cls?` ${r.cls}`:""}`,role:"radiogroup","aria-label":r.label??null,"data-value":e}),a=()=>o.querySelectorAll(":scope > button").forEach(i=>{let s=i.dataset.v===o.dataset.value;i.classList.toggle("on",s),i.setAttribute("aria-checked",s?"true":"false")});for(let[i,s]of n)o.appendChild(t("button",{type:"button",role:"radio","data-v":i,click:()=>{i!==o.dataset.value&&(r.optimistic!==!1&&(o.dataset.value=i,a()),r.onChange?.(i))}},s));return a(),o}function qe(n,e,r,o={}){return t("button",{type:"button",...o,class:`dl-chipbtn${e?" on":""}${o.class?` ${o.class}`:""}`,"aria-pressed":e?"true":"false",click:r},n)}function hn(n,e){n.classList.toggle("on",e),n.setAttribute("aria-pressed",e?"true":"false")}function le(n,e={}){return t("input",{type:"text",class:"cbi-input-text",value:n,...e})}var Vi={jc:"0",jmin:"0",jmax:"0",s1:"0",s2:"0",s3:"0",s4:"0",h1:"1",h2:"2",h3:"3",h4:"4",i1:"",i2:"",i3:"",i4:"",i5:""},Ji={header_protection_key:"HeaderProtectionKey",content_padding_addition:"ContentPaddingAddition",rekey_after_time:"RekeyAfterTime",rekey_timeout:"RekeyTimeout",reject_after_time:"RejectAfterTime",keepalive_timeout:"KeepaliveTimeout",max_handshake_attempts:"MaxHandshakeAttempts",random_trailers:"RandomTrailers",disable_cookies:"DisableCookies"};function Yi(n){let e={};for(let[r,o]of Object.entries(Ji))n[r]!=null&&n[r]!==""&&(e[o]=String(n[r]));return e}function Zi(n,e){let r=n.amnezia,o=r.obfuscation??{},a=d=>o[d]!=null&&o[d]!==""?String(o[d]):Vi[d],i=r.host.replace(/^\[(.*)\]$/,"$1"),s={H1:a("h1"),H2:a("h2"),H3:a("h3"),H4:a("h4"),I1:a("i1"),I2:a("i2"),I3:a("i3"),I4:a("i4"),I5:a("i5"),Jc:a("jc"),Jmin:a("jmin"),Jmax:a("jmax"),S1:a("s1"),S2:a("s2"),S3:a("s3"),S4:a("s4"),...Yi(o),allowed_ips:r.allowed_ips,client_ip:r.client_ip,client_priv_key:r.client_priv_key,client_pub_key:r.client_pub_key,config:n.conf.replace(/\r?\n/g,`\r
|
||||||
`),hostName:i,mtu:r.mtu,persistent_keep_alive:r.persistent_keep_alive,port:Number(r.port),psk_key:r.psk_key,server_pub_key:r.server_pub_key},l={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(s),port:String(r.port),protocol_version:o.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:e,hostName:i};return r.dns[0]&&(l.dns1=r.dns[0]),r.dns[1]&&(l.dns2=r.dns[1]),l}function Zi(n){let e="";for(let r=0;r<n.length;r+=32768)e+=String.fromCharCode(...n.subarray(r,r+32768));return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function Qi(n){let e=globalThis;if(typeof e.CompressionStream>"u")return null;try{let r=new e.Blob([n]).stream().pipeThrough(new e.CompressionStream("deflate")),o=new Uint8Array(await new e.Response(r).arrayBuffer()),a=new Uint8Array(4+o.length);return new DataView(a.buffer).setUint32(0,n.length,!1),a.set(o,4),a}catch{return null}}async function to(n,e,r=!0){let o=new TextEncoder().encode(JSON.stringify(Yi(n,e))),a=r?await Qi(o):null;return`vpn://${Zi(a??o)}`}var mr=[{id:"off",title:"Off",ic:"zap",stealth:0,speed:4,text:"Plain WireGuard-compatible traffic. Fastest, but easy to recognise and block.",apps:"Any WireGuard app",short:"Any WireGuard app"},{id:"balanced",title:"Balanced",ic:"shield",stealth:3,speed:4,needs:"v2",text:"AmneziaWG 2.0: junk packets, padded packets and a first packet that looks like DNS. For networks that learned to spot 1.0-style junk.",apps:"AmneziaVPN 4.8.12 or newer, AmneziaWG 2.0+ apps",short:"AmneziaWG 2.0+ apps"},{id:"max",title:"Maximum",ic:"lock",stealth:4,speed:3,needs:"v3",text:"AmneziaWG 3.1: encrypted packet headers, random tails and sizes, jittered timing, and a first packet that looks like DNS.",apps:"Apps with AmneziaWG 3.1 (current AmneziaVPN)",short:"AmneziaWG 3.1 apps"}],jt=n=>mr.find(e=>e.id===n),mn=n=>n.v3?"max":n.v2?"balanced":"off",Ut=n=>n==="standard"?"Standard (old)":n==="strong"?"Strong (old)":null,Xi={v2:"Needs AmneziaWG 2.0 or newer on the router (kmod-amneziawg and amneziawg-tools from July 2025 on).",v3:"Needs AmneziaWG 3.1 on the router (kmod-amneziawg and amneziawg-tools 3.1)."},es={v2:"Needs AmneziaWG on the router.",v3:"Needs AmneziaWG 3.1 on the router: install it first."};function ur(n,e){return t("span",{class:"dl-dots",title:`${e}: ${n} of 4`},[t("span",{class:"dl-dots-label"},e),t("span",{class:"dl-dots-row"},[0,1,2,3].map(r=>t("i",{class:r<n?"on":""})))])}function hn(n,e,r,o,a=!0){let i=t("div",{class:"dl-methods",role:"radiogroup","aria-label":"Disguise method"}),s=()=>dom.content(i,mr.map(l=>{let d=!l.needs||n[l.needs],c=l.id===e;return t("button",{type:"button",role:"radio","aria-checked":c?"true":"false","aria-disabled":d?null:"true",class:`dl-method${c?" on":""}${d?"":" off"}`,click:()=>{!d||c||(e=l.id,s(),r(l.id))}},[t("div",{class:"dl-method-head"},[t("span",{class:"dl-method-ic"},b(l.ic)),t("b",{},l.title),l.id===o?t("span",{class:"dl-pill ok"},"Current"):""]),t("p",{},l.text),t("div",{class:"dl-method-meters"},[ur(l.stealth,"Stealth"),ur(l.speed,"Speed")]),t("div",{class:"dl-method-foot"},d?[b(l.id==="off"?"wireguard":"amneziawg"),t("span",{},l.apps)]:[b("alert"),t("span",{},(a?Xi:es)[l.needs])])])}));return s(),i}function hr(n,e){return t("div",{class:"dl-corehead"},[t("h3",{},n),e?t("span",{class:"dl-sub"},e):""])}var fr=[["jc","Jc"],["jmin","Jmin"],["jmax","Jmax"],["s1","S1"],["s2","S2"],["s3","S3"],["s4","S4"],["h1","H1"],["h2","H2"],["h3","H3"],["h4","H4"],["i1","I1"],["i2","I2"],["i3","I3"],["i4","I4"],["i5","I5"],["header_protection_key","HeaderProtectionKey"],["content_padding_addition","ContentPaddingAddition"],["rekey_after_time","RekeyAfterTime"],["rekey_timeout","RekeyTimeout"],["reject_after_time","RejectAfterTime"],["keepalive_timeout","KeepaliveTimeout"],["max_handshake_attempts","MaxHandshakeAttempts"],["random_trailers","RandomTrailers"],["disable_cookies","DisableCookies"]];function ts(n){let e=c=>n[c]!=null&&n[c]!=="",r=fr.filter(([c])=>e(c));if(!r.length)return null;let o=(c,p)=>t("span",{class:"dl-pv"},[t("i",{},p),t("b",{},c==="header_protection_key"?`${n[c].slice(0,6)}••••`:n[c])]),a=(c,p,u,x)=>{let $=fr.filter(([h])=>x.includes(h)&&e(h));return $.length?t("div",{class:"dl-pgroup"},[t("div",{class:"dl-pgroup-head"},[b(p),t("b",{},c)]),t("p",{},u),t("div",{class:"dl-pvals"},$.map(([h,m])=>o(h,m)))]):""},i=Number(n.jc||0),s=(n.i1??"").includes("0x8580")?"A first packet shaped like a DNS answer.":"Extra packets sent before the handshake.",l=r.map(([c,p])=>`${p} = ${n[c]}`).join(`
|
`),hostName:i,mtu:r.mtu,persistent_keep_alive:r.persistent_keep_alive,port:Number(r.port),psk_key:r.psk_key,server_pub_key:r.server_pub_key},l={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(s),port:String(r.port),protocol_version:o.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:e,hostName:i};return r.dns[0]&&(l.dns1=r.dns[0]),r.dns[1]&&(l.dns2=r.dns[1]),l}function Qi(n){let e="";for(let r=0;r<n.length;r+=32768)e+=String.fromCharCode(...n.subarray(r,r+32768));return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function Xi(n){let e=globalThis;if(typeof e.CompressionStream>"u")return null;try{let r=new e.Blob([n]).stream().pipeThrough(new e.CompressionStream("deflate")),o=new Uint8Array(await new e.Response(r).arrayBuffer()),a=new Uint8Array(4+o.length);return new DataView(a.buffer).setUint32(0,n.length,!1),a.set(o,4),a}catch{return null}}async function to(n,e,r=!0){let o=new TextEncoder().encode(JSON.stringify(Zi(n,e))),a=r?await Xi(o):null;return`vpn://${Qi(a??o)}`}var ur=[{id:"off",title:"Off",ic:"zap",stealth:0,speed:4,text:"Plain WireGuard-compatible traffic. Fastest, but easy to recognise and block.",apps:"Any WireGuard app",short:"Any WireGuard app"},{id:"balanced",title:"Balanced",ic:"shield",stealth:3,speed:4,needs:"v2",text:"AmneziaWG 2.0: junk packets, padded packets and a first packet that looks like DNS. For networks that learned to spot 1.0-style junk.",apps:"AmneziaVPN 4.8.12 or newer, AmneziaWG 2.0+ apps",short:"AmneziaWG 2.0+ apps"},{id:"max",title:"Maximum",ic:"lock",stealth:4,speed:3,needs:"v3",text:"AmneziaWG 3.1: encrypted packet headers, random tails and sizes, jittered timing, and a first packet that looks like DNS.",apps:"Apps with AmneziaWG 3.1 (current AmneziaVPN)",short:"AmneziaWG 3.1 apps"}],Ot=n=>ur.find(e=>e.id===n),fn=n=>n.v3?"max":n.v2?"balanced":"off",jt=n=>n==="standard"?"Standard (old)":n==="strong"?"Strong (old)":null,es={v2:"Needs AmneziaWG 2.0 or newer on the router (kmod-amneziawg and amneziawg-tools from July 2025 on).",v3:"Needs AmneziaWG 3.1 on the router (kmod-amneziawg and amneziawg-tools 3.1)."},ts={v2:"Needs AmneziaWG on the router.",v3:"Needs AmneziaWG 3.1 on the router: install it first."};function pr(n,e){return t("span",{class:"dl-dots",title:`${e}: ${n} of 4`},[t("span",{class:"dl-dots-label"},e),t("span",{class:"dl-dots-row"},[0,1,2,3].map(r=>t("i",{class:r<n?"on":""})))])}function gn(n,e,r,o,a=!0){let i=t("div",{class:"dl-methods",role:"radiogroup","aria-label":"Disguise method"}),s=()=>dom.content(i,ur.map(l=>{let d=!l.needs||n[l.needs],c=l.id===e;return t("button",{type:"button",role:"radio","aria-checked":c?"true":"false","aria-disabled":d?null:"true",class:`dl-method${c?" on":""}${d?"":" off"}`,click:()=>{!d||c||(e=l.id,s(),r(l.id))}},[t("div",{class:"dl-method-head"},[t("span",{class:"dl-method-ic"},v(l.ic)),t("b",{},l.title),l.id===o?t("span",{class:"dl-pill ok"},"Current"):""]),t("p",{},l.text),t("div",{class:"dl-method-meters"},[pr(l.stealth,"Stealth"),pr(l.speed,"Speed")]),t("div",{class:"dl-method-foot"},d?[v(l.id==="off"?"wireguard":"amneziawg"),t("span",{},l.apps)]:[v("alert"),t("span",{},(a?es:ts)[l.needs])])])}));return s(),i}function mr(n,e){return t("div",{class:"dl-corehead"},[t("h3",{},n),e?t("span",{class:"dl-sub"},e):""])}var hr=[["jc","Jc"],["jmin","Jmin"],["jmax","Jmax"],["s1","S1"],["s2","S2"],["s3","S3"],["s4","S4"],["h1","H1"],["h2","H2"],["h3","H3"],["h4","H4"],["i1","I1"],["i2","I2"],["i3","I3"],["i4","I4"],["i5","I5"],["header_protection_key","HeaderProtectionKey"],["content_padding_addition","ContentPaddingAddition"],["rekey_after_time","RekeyAfterTime"],["rekey_timeout","RekeyTimeout"],["reject_after_time","RejectAfterTime"],["keepalive_timeout","KeepaliveTimeout"],["max_handshake_attempts","MaxHandshakeAttempts"],["random_trailers","RandomTrailers"],["disable_cookies","DisableCookies"]];function ns(n){let e=c=>n[c]!=null&&n[c]!=="",r=hr.filter(([c])=>e(c));if(!r.length)return null;let o=(c,p)=>t("span",{class:"dl-pv"},[t("i",{},p),t("b",{},c==="header_protection_key"?`${n[c].slice(0,6)}••••`:n[c])]),a=(c,p,u,x)=>{let $=hr.filter(([h])=>x.includes(h)&&e(h));return $.length?t("div",{class:"dl-pgroup"},[t("div",{class:"dl-pgroup-head"},[v(p),t("b",{},c)]),t("p",{},u),t("div",{class:"dl-pvals"},$.map(([h,m])=>o(h,m)))]):""},i=Number(n.jc||0),s=(n.i1??"").includes("0x8580")?"A first packet shaped like a DNS answer.":"Extra packets sent before the handshake.",l=r.map(([c,p])=>`${p} = ${n[c]}`).join(`
|
||||||
`),d=t("div",{class:"dl-pgrid"},[a("Junk packets","zap",i?`${i} random packet${i===1?"":"s"} of ${n.jmin}–${n.jmax} bytes before each handshake.`:"No junk packets.",["jc","jmin","jmax"]),a("Padding","archive","Random bytes in front of handshake, cookie and data packets, so their sizes do not match WireGuard.",["s1","s2","s3","s4"]),a("Packet types","key","The values that replace WireGuard’s recognisable message types.",["h1","h2","h3","h4"]),a("Signatures","globe",s,["i1","i2","i3","i4","i5"]),a("Protection","lock","AmneziaWG 3.1: encrypted headers, random tails and extra padding on data packets.",["header_protection_key","content_padding_addition","random_trailers","disable_cookies"]),a("Timing","clock","Handshake and key timers vary within these ranges instead of WireGuard’s fixed values.",["rekey_after_time","rekey_timeout","reject_after_time","keepalive_timeout","max_handshake_attempts"])]);return t("details",{class:"dl-params"},[t("summary",{},[b("chevron"),t("span",{},"Current parameters"),t("span",{class:"dl-pcount"},String(r.length)),t("span",{class:"dl-spacer"}),t("button",{type:"button",class:"dl-linkbtn",click:c=>{c.preventDefault(),ue(l,"Parameters copied")}},"Copy as config")]),d])}function gr(n,e){if(/^\s*\[.+\]\s*$/.test(n))return t("span",{class:"dl-conf-sec"},n);let r=/^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(n);if(!r)return document.createTextNode(n);let o=/^(\s*)(PrivateKey|PresharedKey)\b/.test(n);return t("span",{},[t("span",{class:"dl-conf-k"},r[1])," ",o&&!e?t("span",{class:"dl-conf-mask"},"••••••••••••••••"):r[2]])}function ns(n){let e=!1,r=t("pre",{class:"dl-conf"}),o=()=>dom.content(r,n.conf.split(`
|
`),d=t("div",{class:"dl-pgrid"},[a("Junk packets","zap",i?`${i} random packet${i===1?"":"s"} of ${n.jmin}–${n.jmax} bytes before each handshake.`:"No junk packets.",["jc","jmin","jmax"]),a("Padding","archive","Random bytes in front of handshake, cookie and data packets, so their sizes do not match WireGuard.",["s1","s2","s3","s4"]),a("Packet types","key","The values that replace WireGuard’s recognisable message types.",["h1","h2","h3","h4"]),a("Signatures","globe",s,["i1","i2","i3","i4","i5"]),a("Protection","lock","AmneziaWG 3.1: encrypted headers, random tails and extra padding on data packets.",["header_protection_key","content_padding_addition","random_trailers","disable_cookies"]),a("Timing","clock","Handshake and key timers vary within these ranges instead of WireGuard’s fixed values.",["rekey_after_time","rekey_timeout","reject_after_time","keepalive_timeout","max_handshake_attempts"])]);return t("details",{class:"dl-params"},[t("summary",{},[v("chevron"),t("span",{},"Current parameters"),t("span",{class:"dl-pcount"},String(r.length)),t("span",{class:"dl-spacer"}),t("button",{type:"button",class:"dl-linkbtn",click:c=>{c.preventDefault(),me(l,"Parameters copied")}},"Copy as config")]),d])}function fr(n,e){if(/^\s*\[.+\]\s*$/.test(n))return t("span",{class:"dl-conf-sec"},n);let r=/^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(n);if(!r)return document.createTextNode(n);let o=/^(\s*)(PrivateKey|PresharedKey)\b/.test(n);return t("span",{},[t("span",{class:"dl-conf-k"},r[1])," ",o&&!e?t("span",{class:"dl-conf-mask"},"••••••••••••••••"):r[2]])}function os(n){let e=!1,r=t("pre",{class:"dl-conf"}),o=()=>dom.content(r,n.conf.split(`
|
||||||
`).flatMap((s,l)=>l?[`
|
`).flatMap((s,l)=>l?[`
|
||||||
`,gr(s,e)]:[gr(s,e)])),a=t("button",{type:"button",class:"dl-chipbtn",click:s=>{s.preventDefault(),e=!e,dom.content(a,[b(e?"x":"key"),e?"Hide key":"Show key"]),o()}},[b("key"),"Show key"]);o();let i=new Blob([n.conf]).size;return t("div",{class:"dl-stack gap8"},[t("div",{class:"dl-filecard"},[t("span",{class:"dl-filecard-ic"},".conf"),t("span",{class:"dl-stack"},[t("span",{class:"dl-mono dl-ellipsis"},n.filename),t("span",{class:"dl-sub"},`AmneziaWG · ${i} bytes · import it in the app`)]),H([b("download")," Download"],()=>Te(n.filename,n.conf,"application/octet-stream"),"positive")]),t("details",{class:"dl-params"},[t("summary",{},[b("chevron"),t("span",{},"Configuration"),t("span",{class:"dl-spacer"}),a,t("button",{type:"button",class:"dl-chipbtn",click:s=>{s.preventDefault(),ue(n.conf,"Configuration copied")}},[b("copy"),"Copy"])]),r])])}function no(n){let e=n.amnezia.obfuscation??{},r={h1:"1",h2:"2",h3:"3",h4:"4"};return Object.entries(e).every(([o,a])=>a==null||a===""||a===(r[o]??"0"))}async function os(n,e="file"){if(!n.has_private_key)return t("div",{class:"dl-hint"},"This device generated its own keys in the browser, so its full configuration only exists on that device.");let r=await to(n,n.server),o={qr:()=>t("div",{class:"dl-qr-pane"},[et(Lt(n.conf),"dl-qr"),t("span",{class:"dl-sub"},no(n)?"Scan with AmneziaVPN or any WireGuard app on the device.":"Scan with AmneziaVPN or AmneziaWG on the device.")]),key:()=>t("div",{class:"dl-stack gap8"},[t("div",{class:"dl-linkbox"},[t("span",{class:"dl-mono"},r),H("Copy",()=>ue(r,"Key copied"))]),t("span",{class:"dl-sub"},"AmneziaVPN → Add server → Insert key. Keep it private.")]),file:()=>ns(n)},a=t("div",{class:"dl-connect-body"}),i=t("div",{class:"dl-seg"}),s=l=>{i.querySelectorAll("button").forEach(d=>d.classList.toggle("on",d.dataset.id===l)),dom.content(a,o[l]())};for(let[l,d]of[["file","File"],["key","Key"],["qr","QR code"]])i.appendChild(t("button",{type:"button","data-id":l,click:()=>s(l)},d));return s(e),t("div",{class:"dl-stack gap12"},[i,a])}async function rs(n,e,r,o){let a=jt(r),s=n.st.people.filter(d=>d.server===e.id).reduce((d,c)=>d+c.devices.length,0);await le(o?"Generate new disguise values?":`Switch to ${a.title}?`,`${s} AmneziaWG device${s===1?" stops":"s stop"} connecting until ${s===1?"it imports its":"they import their"} configuration again (from their personal link or from you).${r==="max"?" They need an app with AmneziaWG 3.1.":r==="balanced"?" They need an app with AmneziaWG 2.0 or newer.":""}${n.st.servers.length===1&&s?" To keep the old disguise for some people, add a second server and move them there.":""}`,o?"Generate and apply":"Switch and apply",!0)&&await G(()=>A.serverObfuscation(e.id,r),o?"New values applied":`${a.title} applied`)&&(U("Devices are marked “Update config” until they import again.","info",6e3),await n.refresh())}function as(n,e){let r=n.st,o=se(String(e.port),{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),a=se(e.mtu?String(e.mtu):"",{placeholder:"Auto",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),i=se(String(e.keepalive??""),{placeholder:"25",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),s=jt(e.preset)?e.preset:void 0,l=s??mn(r.awg),d=H("",()=>rs(n,e,l,l===s),"neutral"),c=()=>dom.content(d,l===s?[b("reset")," Generate new values"]:[`Switch to ${jt(l).title}`]);c();let p=r.awg_state?.tools!==!1,u=[],x=he("UDP port",o,()=>It(Number(o.value),u,`Opened on the WAN firewall automatically.${Number(o.value)===4500?" 4500 is IPsec’s port: most networks let it through.":""}`));A.serverPorts(e.id).then(m=>{u=m.udp_taken??[],x.refresh()}).catch(()=>{});let $=he("MTU",a,()=>Fo(a.value,e.mtus)),h=he("Keep-alive",i,()=>qo(i.value));return Rt("",[hr("AmneziaWG",e.ifname),fe("globe","Listening","Where devices reach this core from the internet",[x]),fe("file","In every device configuration","Changing these marks devices “Update config” until they import again",[$,h]),fe("shield","Disguise","So networks that block VPNs do not recognise the tunnel. Off = plain WireGuard",[Ut(e.preset)?pt("warn",[t("b",{},Ut(e.preset))," is AmneziaWG 1.0 junk only, which networks learned to spot; it is not offered any more. Switch to ",t("b",{},"Balanced")," or ",t("b",{},"Maximum"),": devices import their configuration again."]):"",hn(r.awg,l,m=>{l=m,c()},s,p),p&&!r.awg.v3?pt("info",["This router runs an older AmneziaWG. ",t("b",{},"Maximum")," becomes available with kmod-amneziawg and amneziawg-tools 3.1."]):"",ts(e.obf??{})??"",t("div",{class:"dl-row-end"},[t("span",{class:"dl-sub"},"Applies at once: every AmneziaWG device imports its configuration again."),d])]),t("details",{class:"dl-params"},[t("summary",{},[b("chevron"),t("span",{},"Tunnel"),t("span",{class:"dl-pcount"},"3")]),t("div",{class:"dl-params-body"},[ce("Interface",t("span",{class:"dl-mono"},`${e.ifname} · router ${e.address}`)),ce("Tunnel subnet",t("span",{class:"dl-mono"},e.subnet),"Device addresses come from it."
Line truncated
|
`,fr(s,e)]:[fr(s,e)])),a=t("button",{type:"button",class:"dl-chipbtn",click:s=>{s.preventDefault(),e=!e,dom.content(a,[v(e?"x":"key"),e?"Hide key":"Show key"]),o()}},[v("key"),"Show key"]);o();let i=new Blob([n.conf]).size;return t("div",{class:"dl-stack gap8"},[t("div",{class:"dl-filecard"},[t("span",{class:"dl-filecard-ic"},".conf"),t("span",{class:"dl-stack"},[t("span",{class:"dl-mono dl-ellipsis"},n.filename),t("span",{class:"dl-sub"},`AmneziaWG · ${i} bytes`)]),D([v("download")," Download"],()=>Te(n.filename,n.conf,"application/octet-stream"),"positive")]),t("details",{class:"dl-params"},[t("summary",{},[v("chevron"),t("span",{},"Configuration"),t("span",{class:"dl-spacer"}),a,t("button",{type:"button",class:"dl-chipbtn",click:s=>{s.preventDefault(),me(n.conf,"Configuration copied")}},[v("copy"),"Copy"])]),r])])}function no(n){let e=n.amnezia.obfuscation??{},r={h1:"1",h2:"2",h3:"3",h4:"4"};return Object.entries(e).every(([o,a])=>a==null||a===""||a===(r[o]??"0"))}async function rs(n,e="file"){if(!n.has_private_key)return t("div",{class:"dl-hint"},"This device generated its own keys in the browser, so its full configuration only exists on that device.");let r=await to(n,n.server),o={qr:()=>t("div",{class:"dl-qr-pane"},[an(n.conf),t("span",{class:"dl-sub"},no(n)?"Scan with AmneziaVPN or any WireGuard app on the device.":"Scan with AmneziaVPN or AmneziaWG on the device.")]),key:()=>t("div",{class:"dl-stack gap8"},[t("div",{class:"dl-linkbox"},[t("span",{class:"dl-mono"},r),D("Copy",()=>me(r,"Key copied"))]),t("span",{class:"dl-sub"},"AmneziaVPN → Add server → Insert key. Keep it private.")]),file:()=>os(n)},a=t("div",{class:"dl-connect-body"}),i=t("div",{class:"dl-seg"}),s=l=>{i.querySelectorAll("button").forEach(d=>d.classList.toggle("on",d.dataset.id===l)),dom.content(a,o[l]())};for(let[l,d]of[["file","File"],["key","Key"],["qr","QR code"]])i.appendChild(t("button",{type:"button","data-id":l,click:()=>s(l)},d));return s(e),t("div",{class:"dl-stack gap12"},[i,a])}async function as(n,e,r,o){let a=Ot(r),s=n.st.people.filter(d=>d.server===e.id).reduce((d,c)=>d+c.devices.length,0);await se(o?"Generate new disguise values?":`Switch to ${a.title}?`,`${s} AmneziaWG device${s===1?" stops":"s stop"} connecting until ${s===1?"it imports its":"they import their"} configuration again (from their personal link or from you).${r==="max"?" They need an app with AmneziaWG 3.1.":r==="balanced"?" They need an app with AmneziaWG 2.0 or newer.":""}${n.st.servers.length===1&&s?" To keep the old disguise for some people, add a second server and move them there.":""}`,o?"Generate and apply":"Switch and apply",!0)&&await G(()=>P.serverObfuscation(e.id,r),o?"New values applied":`${a.title} applied`)&&(U("Devices are marked “Update config” until they import again.","info",6e3),await n.refresh())}function is(n,e){let r=n.st,o=le(String(e.port),{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),a=le(e.mtu?String(e.mtu):"",{placeholder:"Auto",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),i=le(String(e.keepalive??""),{placeholder:"25",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),s=Ot(e.preset)?e.preset:void 0,l=s??fn(r.awg),d=D("",()=>as(n,e,l,l===s),"neutral"),c=()=>dom.content(d,l===s?[v("reset")," Generate new values"]:[`Switch to ${Ot(l).title}`]);c();let p=r.awg_state?.tools!==!1,u=[],x=ge("UDP port",o,()=>Rt(Number(o.value),u,`Opened on the WAN firewall automatically.${Number(o.value)===4500?" 4500 is IPsec’s port: most networks let it through.":""}`));P.serverPorts(e.id).then(m=>{u=m.udp_taken??[],x.refresh()}).catch(()=>{});let $=ge("MTU",a,()=>Zo(a.value,e.mtus)),h=ge("Keep-alive",i,()=>Qo(i.value));return Nt("",[mr("AmneziaWG",e.ifname),fe("globe","Listening","Where devices reach this core from the internet",[x]),fe("file","In every device configuration","Changing these marks devices “Update config” until they import again",[$,h]),fe("shield","Disguise","So networks that block VPNs do not recognise the tunnel. Off = plain WireGuard",[jt(e.preset)?ct("warn",[t("b",{},jt(e.preset))," is AmneziaWG 1.0 junk only, which networks learned to spot; it is not offered any more. Switch to ",t("b",{},"Balanced")," or ",t("b",{},"Maximum"),": devices import their configuration again."]):"",gn(r.awg,l,m=>{l=m,c()},s,p),p&&!r.awg.v3?ct("info",["This router runs an older AmneziaWG. ",t("b",{},"Maximum")," becomes available with kmod-amneziawg and amneziawg-tools 3.1."]):"",ns(e.obf??{})??"",t("div",{class:"dl-row-end"},[t("span",{class:"dl-sub"},"Applies at once: every AmneziaWG device imports its configuration again."),d])]),t("details",{class:"dl-params"},[t("summary",{},[v("chevron"),t("span",{},"Tunnel"),t("span",{class:"dl-pcount"},"3")]),t("div",{class:"dl-params-body"},[ce("Interface",t("span",{class:"dl-mono"},`${e.ifname} · router ${e.address}`)),ce("Tunnel subnet",t("span",{class:"dl-mono"},e.subnet),"Device addresses come from it."),ce("Server public key",t("span",{c
Line truncated
|
||||||
`),"Log copied"))]),p,u]),[x],"wide"),h([t("button",{class:"cbi-button cbi-button-neutral spinning",type:"button",disabled:"disabled"},a?"Checking…":"Working…")]);let C=r??null,B=r?.id,w,v=0,y=f=>{B!==f.id&&(B=f.id,e.onJob?.(f))};if(r)e.onJob?.(r);else try{let f=await A.updatesStatus().catch(()=>null);w=f?.job?.id,v=f?.now??0;let g=await A.updatesRun(n);g.job&&g.job.state==="running"&&g.job.id!==w&&(C=g.job,y(g.job))}catch(f){return $=[be(f)],p.textContent=$[0],dom.content(u,t("div",{class:"dl-comp-status warn"},[b("alert"),t("span",{},be(f))])),h([m(!0)]),U(be(f),"error"),null}let E=null,k=0;for(;;){if(await sa(1e3),E=await A.updatesStatus().catch(()=>null),!E){if(++k>60)break;continue}k=0;let f=E.job;if(!f||!ia(f,B,w,v)){if(Date.now()-i>15e3)break;continue}if(y(f),C=f,f.log.length){$=f.log;let g=p.scrollTop+p.clientHeight>=p.scrollHeight-8;p.textContent=$.join(`
|
`),"Log copied"))]),p,u]),[x],"wide"),h([t("button",{class:"cbi-button cbi-button-neutral spinning",type:"button",disabled:"disabled"},a?"Checking…":"Working…")]);let E=r??null,R=r?.id,C,k=0,y=f=>{R!==f.id&&(R=f.id,e.onJob?.(f))};if(r)e.onJob?.(r);else try{let f=await P.updatesStatus().catch(()=>null);C=f?.job?.id,k=f?.now??0;let g=await P.updatesRun(n);g.job&&g.job.state==="running"&&g.job.id!==C&&(E=g.job,y(g.job))}catch(f){return $=[be(f)],p.textContent=$[0],dom.content(u,t("div",{class:"dl-comp-status warn"},[v("alert"),t("span",{},be(f))])),h([m(!0)]),U(be(f),"error"),null}let w=null,b=0;for(;;){if(await ia(1e3),w=await P.updatesStatus().catch(()=>null),!w){if(++b>60)break;continue}b=0;let f=w.job;if(!f||!aa(f,R,C,k)){if(Date.now()-i>15e3)break;continue}if(y(f),E=f,f.log.length){$=f.log;let g=p.scrollTop+p.clientHeight>=p.scrollHeight-8;p.textContent=$.join(`
|
||||||
`),g&&(p.scrollTop=p.scrollHeight)}if(l.textContent=ra(f,e.version??""),!l.isConnected&&l.textContent&&s.after(l),c.textContent=oa((f.finished??E.now)-f.started),f.state==="running"){d.hidden=!f.phase,d.textContent=f.phase;continue}break}if(p.scrollTop=p.scrollHeight,d.hidden=!1,!C||C.state==="running")return d.className="dl-pill warn",d.textContent="No answer",dom.content(u,t("div",{class:"dl-comp-status warn"},[b("alert"),t("span",{},"The router stopped answering. The job may still finish: reopen Components in a minute.")])),h([m()]),e.onDone?.(E),C;if(C.state==="failed")return d.className="dl-pill bad",d.textContent="Failed",dom.content(u,t("div",{class:"dl-comp-status bad"},[b("x"),t("span",{},[t("b",{},C.error??"Operation failed"),a?"":". Nothing else was changed."])])),h([H("Copy log",()=>ue($.join(`
|
`),g&&(p.scrollTop=p.scrollHeight)}if(l.textContent=oa(f,e.version??""),!l.isConnected&&l.textContent&&s.after(l),c.textContent=na((f.finished??w.now)-f.started),f.state==="running"){d.hidden=!f.phase,d.textContent=f.phase;continue}break}if(p.scrollTop=p.scrollHeight,d.hidden=!1,!E||E.state==="running")return d.className="dl-pill warn",d.textContent="No answer",dom.content(u,t("div",{class:"dl-comp-status warn"},[v("alert"),t("span",{},"The router stopped answering. The job may still finish: reopen Components in a minute.")])),h([m()]),e.onDone?.(w),E;if(E.state==="failed")return d.className="dl-pill bad",d.textContent="Failed",dom.content(u,t("div",{class:"dl-comp-status bad"},[v("x"),t("span",{},[t("b",{},E.error??"Operation failed"),a?"":". Nothing else was changed."])])),h([D("Copy log",()=>me($.join(`
|
||||||
`),"Log copied")),m(!0)]),U(`${Ln[o]??"Update"}: ${C.error??"failed"}`,"error"),e.onDone?.(E),C;if(d.className="dl-pill ok",d.textContent="Finished",a&&E){let f=aa(E,o);if(dom.content(u,t("div",{class:`dl-comp-status ${f.tone}`},[b(f.tone==="ok"?"check":f.tone==="warn"?"alert":"download"),t("span",{},f.text)])),U(f.text,f.tone==="warn"?"warning":"success"),e.onDone?.(E),f.update&&e.onUpdate){let g=E;h([m(),H(`Update to ${f.update}`,()=>e.onUpdate(g),"positive")])}else h([m()]),f.tone==="ok"&&setTimeout(()=>u.isConnected&&ae(),1200);return C}if(o==="app"&&C.to){let f=C.to,g=t("span",{},"Waiting for the router to restart its services…");dom.content(u,t("div",{class:"dl-comp-status ok"},[b("check"),t("span",{},[t("b",{},`Dawnline ${f} is installed. `),g])]));let S=()=>{ui.menu?.flushCache(),location.reload()};h([m(),H("Reload now",S,"positive")]),U(`Dawnline updated to ${f}`,"success",6e3);for(let T=1;T<=30;T++)if(g.textContent=`Waiting for the router to restart its services (${T} of 30)…`,await sa(1500),(await A.updatesStatus().catch(()=>null))?.version===f)return g.textContent="Services are back. Reloading…",setTimeout(S,800),C;return g.textContent="Services restarted. Reload the page to use the new version.",C}let z=o==="pkgs"?`Updated ${[...C.result?.pkgs?.updated??[],...C.result?.pkgs?.installed??[]].join(", ")||"system packages"}`:o==="amneziawg"?`AmneziaWG${C.to?` ${C.to}`:""} is installed`:"Operation completed";return dom.content(u,t("div",{class:"dl-comp-status ok"},[b("check"),t("span",{},z)])),h([m()]),U(z,"success"),e.onDone?.(E),C}var Ps={https:"HTTPS for the portal",acme:"ACME certificates",home:"the home-like link",awg:"AmneziaWG"};async function la(n,e,r,o){return!await le(`Install ${e}?`,r,"Install")||(await Jt(n,{title:`Installing ${e}`}))?.state!=="done"?!1:(setTimeout(()=>o?.(),4e3),!0)}function Sn(n){return la("amneziawg:auto","AmneziaWG","Dawnline installs the AmneziaWG build made for this firmware and loads it. If the network service has to restart to learn it, connections drop for a few seconds.",n)}async function Yt(n,e,r){return n==="awg"?Sn(r):e.length?la(`pkgs:${e.join(",")}`,Ps[n],`${e.join(", ")} from the OpenWrt feeds. Dawnline sets the rest up when they arrive.`,r):!0}async function da(n,e){if(n==="awg")return Sn(e);let r=await G(()=>A.updatesStatus());return r?Yt(n,r.needs?.[n]??[],e):!1}var Ds=[["wan","WAN"],["ethernet","Ethernet"],["wifi","Wi-Fi"],["vpn","VPN & tunnels"],["other","Other"]],As={wan:"globe",ethernet:"ethernet",bridge:"bridge",wifi:"wifi",vpn:"tunnel",other:"link"};function ca(n,e,r){let o=n.id,a=e,i=t("div",{class:"dl-stack gap16"},t("section",{class:"dl-setsec"},t("div",{class:"dl-setsec-body"},t("p",{class:"dl-muted"},"Loading interfaces…")))),s,l=!0,d="",c=!0,p=!0,u="all",x=!1,$=ea(a,o,r),h=new Set,m="",C=()=>JSON.stringify([p,l,l?"":d,c,[...h].sort()]),B=()=>s.detected.lan||s.saved.lan||"",w=()=>(l?s.detected.wan||s.saved.wan:d)||"",v=()=>new Map(s.devices.map(R=>[R.name,R])),y=()=>{let R=v();return[...c&&B()?[B()]:[],...[...h].filter(Z=>Z!==B())].filter(Z=>Z!==w()).map(Z=>R.get(Z)??{name:Z,nets:[],missing:!0})},E=(R,K)=>{s=R,K&&(l=R.config.auto_wan,d=R.config.wan_device||R.detected.wan||R.saved.wan||"",c=R.config.auto_lan,p=R.config.lan_like,u=R.config.mesh??(R.config.device_mesh?"all":"off"),h=new Set(R.config.lan_devices),m=C()),q()},k=async R=>{let K=await A.interfaces(o).catch(Z=>(U(Z.message,"error"),null));K&&E(K,R)};function z(R){let K=c&&R.name===B(),Z=!!R.own||!!R.master||R.name===w()||K;return K||h.has(R.name)||!Z&&(R.nets.length>0||!!R.missing)}function f(R){let K=c&&R.name===B(),Z=R.name===w(),de=!K&&h.has(R.name),te=!(!!R.own||!!R.master||Z||K)&&(R.nets.length>0||de||!!R.missing),ge=(de||K)&&!R.zone&&!R.missing,O=R.missing?"Not present right now":R.own?"This server":R.master?`Port of ${R.master}`:Z?`Internet${R.zone?` · zone ${R.zone}`:""}`:R.nets.length?R.nets.join(", "):"No IPv4 network",X=t("button",{type:"button",class:`dl-if${de?" sel":""}${K?" auto":""}${!te&&!de&&!K?" off":""}${ge?" warn":""}`,"aria-pressed":de||K?"true":"false","aria-disabled":te?null:"true",click:()=>{te&&(h.has(R.name)?h.delete(R.name):h.add(R.name),q())}},[t("span",{class:"dl-if-ic"},b(As[R.kind]??"link")),t("span",{class:"dl-if-main"},[t("span",{class:"dl-if-name"},R.name),t("span",{class:"dl-if-sub"},O)]),K?t("span",{class:"dl-if-badge ok"},"Auto"):de?t("span",{class:"dl-if-check"},b("check")):""]);return me(X,()=>[t("div",{class:"dl-tip-title"},R.name),t("div",{class:"dl-muted"},[R.logical?`Interface ${R.logical}`:"No netifd interface",R.zone?` · zone ${R.zone}`:" · no firewall zone"]),R.members.length?t("div",{class:"dl-muted"},`Ports: ${R.members.join(", ")}`):"",R.nets.length?t("div",{class:"dl-mono"},R.nets.join(", ")):"",ge?t("div",{class:"dl-warn"},"Not in a firewall zone: the firewall rejects this traffic."):"",R.master?t("div",{class:"dl-muted"},`Choose ${R.master} to include it.`):""]),X}function g(){let R=s.like_home;return!p||!s.config.lan_
Line truncated
|
`),"Log copied")),m(!0)]),U(`${Mn[o]??"Update"}: ${E.error??"failed"}`,"error"),e.onDone?.(w),E;if(d.className="dl-pill ok",d.textContent="Finished",a&&w){let f=ra(w,o);if(dom.content(u,t("div",{class:`dl-comp-status ${f.tone}`},[v(f.tone==="ok"?"check":f.tone==="warn"?"alert":"download"),t("span",{},f.text)])),U(f.text,f.tone==="warn"?"warning":"success"),e.onDone?.(w),f.update&&e.onUpdate){let g=w;h([m(),D(`Update to ${f.update}`,()=>e.onUpdate(g),"positive")])}else h([m()]),f.tone==="ok"&&setTimeout(()=>u.isConnected&&ae(),1200);return E}if(o==="app"&&E.to){let f=E.to,g=t("span",{},"Waiting for the router to restart its services…");dom.content(u,t("div",{class:"dl-comp-status ok"},[v("check"),t("span",{},[t("b",{},`Dawnline ${f} is installed. `),g])]));let M=()=>{ui.menu?.flushCache(),location.reload()};h([m(),D("Reload now",M,"positive")]),U(`Dawnline updated to ${f}`,"success",6e3);for(let T=1;T<=30;T++)if(g.textContent=`Waiting for the router to restart its services (${T} of 30)…`,await ia(1500),(await P.updatesStatus().catch(()=>null))?.version===f)return g.textContent="Services are back. Reloading…",setTimeout(M,800),E;return g.textContent="Services restarted. Reload the page to use the new version.",E}let H=o==="pkgs"?`Updated ${[...E.result?.pkgs?.updated??[],...E.result?.pkgs?.installed??[]].join(", ")||"system packages"}`:o==="amneziawg"?`AmneziaWG${E.to?` ${E.to}`:""} is installed`:"Operation completed";return dom.content(u,t("div",{class:"dl-comp-status ok"},[v("check"),t("span",{},H)])),h([m()]),U(H,"success"),e.onDone?.(w),E}var Ds={https:"HTTPS for the portal",acme:"ACME certificates",home:"the home-like link",awg:"AmneziaWG"};async function sa(n,e,r,o){return!await se(`Install ${e}?`,r,"Install")||(await Vt(n,{title:`Installing ${e}`}))?.state!=="done"?!1:(setTimeout(()=>o?.(),4e3),!0)}function Tn(n){return sa("amneziawg:auto","AmneziaWG","Dawnline installs the AmneziaWG build made for this firmware and loads it. If the network service has to restart to learn it, connections drop for a few seconds.",n)}async function Jt(n,e,r){return n==="awg"?Tn(r):e.length?sa(`pkgs:${e.join(",")}`,Ds[n],`${e.join(", ")} from the OpenWrt feeds. Dawnline sets the rest up when they arrive.`,r):!0}async function la(n,e){if(n==="awg")return Tn(e);let r=await G(()=>P.updatesStatus());return r?Jt(n,r.needs?.[n]??[],e):!1}var As=[["wan","WAN"],["ethernet","Ethernet"],["wifi","Wi-Fi"],["vpn","VPN & tunnels"],["other","Other"]],Hs={wan:"globe",ethernet:"ethernet",bridge:"bridge",wifi:"wifi",vpn:"tunnel",other:"link"};function da(n,e,r){let o=n.id,a=e,i=t("div",{class:"dl-stack gap16"},t("section",{class:"dl-setsec"},t("div",{class:"dl-setsec-body"},t("p",{class:"dl-muted"},"Loading interfaces…")))),s,l=!0,d="",c=!0,p=!0,u="all",x=!1,$=Xr(a,o,r),h=new Set,m="",E=()=>JSON.stringify([p,l,l?"":d,c,[...h].sort()]),R=()=>s.detected.lan||s.saved.lan||"",C=()=>(l?s.detected.wan||s.saved.wan:d)||"",k=()=>new Map(s.devices.map(I=>[I.name,I])),y=()=>{let I=k();return[...c&&R()?[R()]:[],...[...h].filter(Q=>Q!==R())].filter(Q=>Q!==C()).map(Q=>I.get(Q)??{name:Q,nets:[],missing:!0})},w=(I,V)=>{s=I,V&&(l=I.config.auto_wan,d=I.config.wan_device||I.detected.wan||I.saved.wan||"",c=I.config.auto_lan,p=I.config.lan_like,u=I.config.mesh??(I.config.device_mesh?"all":"off"),h=new Set(I.config.lan_devices),m=E()),q()},b=async I=>{let V=await P.interfaces(o).catch(Q=>(U(Q.message,"error"),null));V&&w(V,I)};function H(I){let V=c&&I.name===R(),Q=!!I.own||!!I.master||I.name===C()||V;return V||h.has(I.name)||!Q&&(I.nets.length>0||!!I.missing)}function f(I){let V=c&&I.name===R(),Q=I.name===C(),de=!V&&h.has(I.name),B=!(!!I.own||!!I.master||Q||V)&&(I.nets.length>0||de||!!I.missing),F=(de||V)&&!I.zone&&!I.missing,ne=I.missing?"Not present right now":I.own?"This server":I.master?`Port of ${I.master}`:Q?`Internet${I.zone?` · zone ${I.zone}`:""}`:I.nets.length?I.nets.join(", "):"No IPv4 network",pe=t("button",{type:"button",class:`dl-if${de?" sel":""}${V?" auto":""}${!B&&!de&&!V?" off":""}${F?" warn":""}`,"aria-pressed":de||V?"true":"false","aria-disabled":B?null:"true",click:()=>{B&&(h.has(I.name)?h.delete(I.name):h.add(I.name),q())}},[t("span",{class:"dl-if-ic"},v(Hs[I.kind]??"link")),t("span",{class:"dl-if-main"},[t("span",{class:"dl-if-name"},I.name),t("span",{class:"dl-if-sub"},ne)]),V?t("span",{class:"dl-if-badge ok"},"Auto"):de?t("span",{class:"dl-if-check"},v("check")):""]);return he(pe,()=>[t("div",{class:"dl-tip-title"},I.name),t("div",{class:"dl-muted"},[I.logical?`Interface ${I.logical}`:"No netifd interface",I.zone?` · zone ${I.zone}`:" · no firewall zone"]),I.members.length?t("div",{class:"dl-muted"},`Ports: ${I.members.join(", ")}`):"",I.nets.length?t("div",{class:"dl-mono"},I.nets.join(", ")):"",F?t("div",{class:"dl-warn"},"Not in a firewall zone: the firewall rejects this traffic."):"",I.master?t("div",{class:"dl-muted"},`Choose ${I.master} to include it.`):""]),pe}function g(){let I=s.like_home;return!p||!s.config.lan_li
Line truncated
|
||||||
`)){let d=l.trimEnd();if(i){/^```/.test(d.trim())?(e.push(t("pre",{},i.join(`
|
`)){let d=l.trimEnd();if(i){/^```/.test(d.trim())?(e.push(t("pre",{},i.join(`
|
||||||
`))),i=null):i.push(l);continue}if(/^```/.test(d.trim())){s(),i=[];continue}let c=/^(#{1,6})\s+(.*)$/.exec(d),p=/^\s*[-*+]\s+(.*)$/.exec(d)??/^\s*\d+[.)]\s+(.*)$/.exec(d);c?(s(),e.push(t("h5",{},r(c[2])))):p?(a.length&&s(),o||(o=t("ul",{}),e.push(o)),o.appendChild(t("li",{},r(p[1])))):d.trim()?(o&&(o=null),a.push(d.trim())):s()}return i&&e.push(t("pre",{},i.join(`
|
`))),i=null):i.push(l);continue}if(/^```/.test(d.trim())){s(),i=[];continue}let c=/^(#{1,6})\s+(.*)$/.exec(d),p=/^\s*[-*+]\s+(.*)$/.exec(d)??/^\s*\d+[.)]\s+(.*)$/.exec(d);c?(s(),e.push(t("h5",{},r(c[2])))):p?(a.length&&s(),o||(o=t("ul",{}),e.push(o)),o.appendChild(t("li",{},r(p[1])))):d.trim()?(o&&(o=null),a.push(d.trim())):s()}return i&&e.push(t("pre",{},i.join(`
|
||||||
`))),s(),e}function Sa(n){let e=[],r=!1;for(let o of n.replace(/\r/g,"").split(`
|
`))),s(),e}function Ma(n){let e=[],r=!1;for(let o of n.replace(/\r/g,"").split(`
|
||||||
`)){let a=/^#{1,6}\s+(.*)$/.exec(o);if(a){if(r=/^install\b/i.test(a[1].trim()),/^what.s new$/i.test(a[1].trim()))continue}else/^\*\*Full Changelog\*\*/.test(o)&&(r=!1);r||e.push(o)}return e.join(`
|
`)){let a=/^#{1,6}\s+(.*)$/.exec(o);if(a){if(r=/^install\b/i.test(a[1].trim()),/^what.s new$/i.test(a[1].trim()))continue}else/^\*\*Full Changelog\*\*/.test(o)&&(r=!1);r||e.push(o)}return e.join(`
|
||||||
`).replace(/\n{3,}/g,`
|
`).replace(/\n{3,}/g,`
|
||||||
|
|
||||||
`).trim()}async function Qt(n,e,r,o){let a=t("div",{class:"dl-notes"},t("p",{class:"dl-muted dl-loading"},"Loading release notes…")),i=t("div",{class:"dl-op-head"}),s="";oe(r,[i,a],[H([b("copy")," Copy"],()=>ue(s,"Release notes copied"))," ",ie("Close")],"wide");try{let l=await A.updatesNotes(n,e,o??"");s=Sa(l.body||"");let d=La(l.url);dom.content(i,[l.published?t("span",{class:"dl-pill"},Ue(l.published)):"",l.prerelease?t("span",{class:"dl-pill warn"},"Pre-release"):"",t("span",{class:"dl-spacer"}),d?t("a",{href:d,target:"_blank",rel:"noopener",class:"dl-linkbtn"},["On GitHub ",b("open")]):""]),dom.content(a,s.trim()?Ma(s):t("p",{class:"dl-muted"},"This release has no notes."))}catch(l){dom.content(a,t("p",{class:"dl-muted"},be(l)))}}var Ta={"6h":"every 6 h","12h":"every 12 h","1d":"daily","7d":"weekly"},Co=n=>n?Ue(n):"";function Vs(n){let e=/^(.{20,}?)(?:;\s|:\s)/.exec(n)?.[1];return e||(n.length<=90?n:`${n.slice(0,90).replace(/[\s,;:]+\S*$/,"")}…`)}function Pa(n,e){let r=n.st,o=r.policy,a=r.kept?.app,i=e?.update&&e.tag?e.tag:r.version,s=x=>()=>Qt("app",x,`What’s new in Dawnline ${x.replace(/^v/,"")}`),l=e?.tag&&(e.update||e.status==="latest")?Js(n,e.tag,e.update?r.version:""):null,d=e?.tag??i,c=o.check&&r.auto?.check?r.auto.check+({"6h":6,"12h":12,"1d":24,"7d":168}[o.interval]??24)*3600:0,p=(x,$)=>t("div",{class:"dl-stack gap4"},[t("span",{class:"dl-metric-label"},x),t("span",{class:"dl-comp-side-v"},$)]),u=[{label:"What’s new",ic:"file",run:s(i)},{label:"Open on GitHub",ic:"globe",run:()=>window.open(`https://github.com/${r.repo}`,"_blank","noopener")},null,{label:`Reinstall ${r.version}`,ic:"reset",warn:!0,run:()=>n.op("app:reinstall","Reinstalling Dawnline",r.version)},a?{label:`Roll back to ${a.version}`,ic:"archive",warn:!0,run:async()=>{await le(`Roll back to Dawnline ${a.version}?`,`The copy kept on the router replaces ${r.version}. A backup of the settings is made first.`,"Roll back")&&n.op("app:rollback","Rolling back Dawnline",r.version)}}:null];return t("section",{class:"dl-panel flush dl-comp-hero"},[t("div",{class:"dl-comp-hero-main"},[t("div",{class:"dl-comp-hero-head"},[t("span",{class:"dl-group-ic"},b("sunrise")),t("b",{class:"dl-comp-name"},"Dawnline"),n.state("app",e,e?.latest??""),t("span",{class:"dl-spacer"}),n.round(()=>n.op("check:app","Checking Dawnline",r.version),u,!0)]),t("div",{class:"dl-comp-verrow"},[t("div",{class:"dl-stack"},[t("div",{class:"dl-comp-big"},[r.version,e?.update?t("small",{},`→ ${e.latest}`):e?.status==="dev"&&e.latest?t("small",{class:"dl-faint"},`release ${e.latest}`):""]),t("span",{class:"dl-faint dl-comp-meta"},e?.error?"":e?.update?e.published?`released ${Co(e.published)}`:"":e?.status==="dev"?"ahead of the latest release":e?`latest release${e.published?` · released ${Co(e.published)}`:""}`:"not checked yet")])]),l?.items.length?t("div",{class:"dl-stack gap4"},[t("ul",{class:"dl-comp-bullets"},l.items.map(x=>t("li",{},x))),l.total>l.items.length?t("button",{type:"button",class:"dl-linkbtn dl-comp-more",click:s(d)},`+${l.total-l.items.length} more in What’s new`):""]):"",e?.error?t("p",{class:"dl-sub dl-comp-lead dl-upd-bad"},e.error):"",e?.update?t("div",{class:"dl-comp-btns"},[H("Update now",()=>n.op("app","Updating Dawnline",r.version),"positive",{disabled:n.busy}),H("What’s new",s(i))]):"",Ys(n)]),t("div",{class:"dl-comp-hero-side"},[p("Source",[b("globe"),t("a",{href:`https://github.com/${r.repo}`,target:"_blank",rel:"noopener"},r.repo)]),p("Auto-update",[o.auto?Ee("ok","On"):Ee("","Off"),t("span",{class:"dl-muted"},o.auto?o.mode==="immediate"?"as soon as found":`${Ta[o.interval]==="weekly"?"weekly":"daily"} at ${o.time}`:o.check?`checks ${Ta[o.interval]}`:"checks off")]),p("Last check",r.check?[re(r.check.time,r.now),c>r.now?t("span",{class:"dl-faint"},`· next in ${xt(c-r.now)}`):""]:["Never"]),p("Rollback",a?[t("span",{class:"dl-mono"},a.version),t("span",{class:"dl-faint"},"kept on flash")]:[t("span",{class:"dl-muted"},o.keep?"Kept after the next update":"Off")])])])}function Js(n,e,r){if(n.notes.has(e))return n.notes.get(e)??null;n.notes.set(e,null);let o=a=>a.replace(/\*\*|`|\[([^\]]+)\]\([^)]*\)/g,(i,s)=>s??"").trim();return(async()=>{let i=((await A.updatesNotes("app",e,"").catch(()=>null))?.body??"").split(`
|
`).trim()}async function Zt(n,e,r,o){let a=t("div",{class:"dl-notes"},t("p",{class:"dl-muted dl-loading"},"Loading release notes…")),i=t("div",{class:"dl-op-head"}),s="";oe(r,[i,a],[D([v("copy")," Copy"],()=>me(s,"Release notes copied"))," ",ie("Close")],"wide");try{let l=await P.updatesNotes(n,e,o??"");s=Ma(l.body||"");let d=Ea(l.url);dom.content(i,[l.published?t("span",{class:"dl-pill"},Ue(l.published)):"",l.prerelease?t("span",{class:"dl-pill warn"},"Pre-release"):"",t("span",{class:"dl-spacer"}),d?t("a",{href:d,target:"_blank",rel:"noopener",class:"dl-linkbtn"},["On GitHub ",v("open")]):""]),dom.content(a,s.trim()?La(s):t("p",{class:"dl-muted"},"This release has no notes."))}catch(l){dom.content(a,t("p",{class:"dl-muted"},be(l)))}}var Sa={"6h":"every 6 h","12h":"every 12 h","1d":"daily","7d":"weekly"},Co=n=>n?Ue(n):"";function Js(n){let e=/^(.{20,}?)(?:;\s|:\s)/.exec(n)?.[1];return e||(n.length<=90?n:`${n.slice(0,90).replace(/[\s,;:]+\S*$/,"")}…`)}function _a(n,e){let r=n.st,o=r.policy,a=r.kept?.app,i=e?.update&&e.tag?e.tag:r.version,s=x=>()=>Zt("app",x,`What’s new in Dawnline ${x.replace(/^v/,"")}`),l=e?.tag&&(e.update||e.status==="latest")?Ys(n,e.tag,e.update?r.version:""):null,d=e?.tag??i,c=o.check&&r.auto?.check?r.auto.check+({"6h":6,"12h":12,"1d":24,"7d":168}[o.interval]??24)*3600:0,p=(x,$)=>t("div",{class:"dl-stack gap4"},[t("span",{class:"dl-metric-label"},x),t("span",{class:"dl-comp-side-v"},$)]),u=[{label:"What’s new",ic:"file",run:s(i)},{label:"Open on GitHub",ic:"globe",run:()=>window.open(`https://github.com/${r.repo}`,"_blank","noopener")},null,{label:`Reinstall ${r.version}`,ic:"reset",warn:!0,run:()=>n.op("app:reinstall","Reinstalling Dawnline",r.version)},a?{label:`Roll back to ${a.version}`,ic:"archive",warn:!0,run:async()=>{await se(`Roll back to Dawnline ${a.version}?`,`The copy kept on the router replaces ${r.version}. A backup of the settings is made first.`,"Roll back")&&n.op("app:rollback","Rolling back Dawnline",r.version)}}:null];return t("section",{class:"dl-panel flush dl-comp-hero"},[t("div",{class:"dl-comp-hero-main"},[t("div",{class:"dl-comp-hero-head"},[t("span",{class:"dl-group-ic"},v("sunrise")),t("b",{class:"dl-comp-name"},"Dawnline"),n.state("app",e,e?.latest??""),t("span",{class:"dl-spacer"}),n.round(()=>n.op("check:app","Checking Dawnline",r.version),u,!0)]),t("div",{class:"dl-comp-verrow"},[t("div",{class:"dl-stack"},[t("div",{class:"dl-comp-big"},[r.version,e?.update?t("small",{},`→ ${e.latest}`):e?.status==="dev"&&e.latest?t("small",{class:"dl-faint"},`release ${e.latest}`):""]),t("span",{class:"dl-faint dl-comp-meta"},e?.error?"":e?.update?e.published?`released ${Co(e.published)}`:"":e?.status==="dev"?"ahead of the latest release":e?`latest release${e.published?` · released ${Co(e.published)}`:""}`:"not checked yet")])]),l?.items.length?t("div",{class:"dl-stack gap4"},[t("ul",{class:"dl-comp-bullets"},l.items.map(x=>t("li",{},x))),l.total>l.items.length?t("button",{type:"button",class:"dl-linkbtn dl-comp-more",click:s(d)},`+${l.total-l.items.length} more in What’s new`):""]):"",e?.error?t("p",{class:"dl-sub dl-comp-lead dl-upd-bad"},e.error):"",e?.update?t("div",{class:"dl-comp-btns"},[D("Update now",()=>n.op("app","Updating Dawnline",r.version),"positive",{disabled:n.busy}),D("What’s new",s(i))]):"",Zs(n)]),t("div",{class:"dl-comp-hero-side"},[p("Source",[v("globe"),t("a",{href:`https://github.com/${r.repo}`,target:"_blank",rel:"noopener"},r.repo)]),p("Auto-update",[o.auto?Ee("ok","On"):Ee("","Off"),t("span",{class:"dl-muted"},o.auto?o.mode==="immediate"?"as soon as found":`${Sa[o.interval]==="weekly"?"weekly":"daily"} at ${o.time}`:o.check?`checks ${Sa[o.interval]}`:"checks off")]),p("Last check",r.check?[re(r.check.time,r.now),c>r.now?t("span",{class:"dl-faint"},`· next in ${xt(c-r.now)}`):""]:["Never"]),p("Rollback",a?[t("span",{class:"dl-mono"},a.version),t("span",{class:"dl-faint"},"kept on flash")]:[t("span",{class:"dl-muted"},o.keep?"Kept after the next update":"Off")])])])}function Ys(n,e,r){if(n.notes.has(e))return n.notes.get(e)??null;n.notes.set(e,null);let o=a=>a.replace(/\*\*|`|\[([^\]]+)\]\([^)]*\)/g,(i,s)=>s??"").trim();return(async()=>{let i=((await P.updatesNotes("app",e,"").catch(()=>null))?.body??"").split(`
|
||||||
`).map(l=>/^\s*[-*+]\s+(.*)$/.exec(l)?.[1]).filter(l=>!!l);i.length||(i=(await A.updatesChanges(r,e).catch(()=>null))?.items??[]);let s={items:i.slice(0,3).map(l=>Vs(o(l))),total:i.length};n.notes.set(e,s),s.items.length&&n.root.isConnected&&n.paint()})(),null}function Ys(n){let e=t("div",{class:"dl-params-body"}),r=t("details",{class:"dl-params dl-comp-vers",open:n.versOpen?"open":null},[t("summary",{},[b("chevron"),t("span",{},"Versions"),t("span",{class:"dl-sub"},"install any release")]),e]);return r.addEventListener("toggle",()=>{n.versOpen=r.open,n.versOpen&&zn(n,e)}),n.versOpen&&zn(n,e),r}async function zn(n,e){let r=se("",{placeholder:"Tag, e.g. 0.3.1",class:"cbi-input-text dl-mono","aria-label":"Release tag"}),o=p=>{if(p=p.trim(),!/^v?[0-9][0-9A-Za-z.+~-]{0,40}$/.test(p))return U("Enter a release tag like 0.3.1","warning");_a(n,p)};r.addEventListener("keydown",p=>{p.key==="Enter"&&(p.preventDefault(),o(r.value))});let a=t("div",{class:"dl-comp-tag"},[r,H("Install",()=>o(r.value),"neutral",{disabled:n.busy})]),i=n.versPage,s=p=>{n.versPage=Math.max(1,n.versPage+p),zn(n,e)},l=p=>t("div",{class:"dl-comp-pager"},[t("button",{type:"button",class:"dl-linkbtn",disabled:i<=1?"disabled":null,click:()=>s(-1)},"← Newer"),t("span",{class:"dl-faint"},`Page ${i}`),t("button",{type:"button",class:"dl-linkbtn",disabled:p?null:"disabled",click:()=>s(1)},"Older →")]),d=n.versCache.get(i);if(!d){dom.content(e,[a,t("p",{class:"dl-muted dl-loading"},"Loading versions…")]);try{d=(await A.updatesReleases(i)).releases}catch(p){if(i!==n.versPage||!e.isConnected)return;dom.content(e,[a,t("div",{class:"dl-row-actions"},[t("span",{class:"dl-muted"},`Failed to load versions: ${be(p)}`),H("Try again",()=>zn(n,e))]),l(!1)]);return}if(n.versCache.set(i,d),i!==n.versPage||!e.isConnected)return}if(!d.length)return dom.content(e,[a,t("p",{class:"dl-muted"},i>1?"No more versions.":"No versions found."),l(!1)]);let c=n.st.version;dom.content(e,[a,...d.map(p=>{let u=p.tag.replace(/^v/,"");return t("div",{class:"dl-comp-ver"},[t("span",{class:"dl-mono"},u),t("span",{class:"dl-sub"},Co(p.published)),p.prerelease?Ee("warn","Pre-release"):"",t("span",{class:"dl-comp-ic"},Le("file","What’s new",()=>Qt("app",p.tag,`What’s new in Dawnline ${u}`))),u===c?Ee("ok","Installed"):H("Install",()=>_a(n,p.tag),"neutral",{disabled:n.busy})])}),l(d.length>=5)])}async function _a(n,e){let r=e.replace(/^v/,"");r.localeCompare(n.st.version,void 0,{numeric:!0})<0&&!await le(`Install Dawnline ${r}?`,`It is older than ${n.st.version}. A backup of the settings is made first; restore it from Settings if something looks wrong.`,"Install")||n.op(`app@${e}`,`Installing Dawnline ${r}`,n.st.version)}function Da(n,e){let r=n.st,o=r.kept?.amneziawg,a=e?.sources??{},i=Object.keys(a),s=e?.current??null,l=s?a[s]:void 0,d=!!e?.ru,c=r.needs?.awg??[],p=c.length?null:e?.installed??null,u=[];s&&p&&u.push({label:"Reinstall this build",warn:!0,ic:"reset",run:()=>n.op(`amneziawg:${s}${d?":ru":""}`,"Reinstalling AmneziaWG",p)}),o&&u.push({label:`Roll back to ${o.version}`,ic:"archive",warn:!0,run:async()=>{await le(`Roll back AmneziaWG to ${o.version}?`,"The build kept on the router is installed again. Every AmneziaWG tunnel restarts for a few seconds.","Roll back")&&n.op("amneziawg:rollback","Rolling back AmneziaWG",p??void 0)}});let x=[e?.release?{label:"What’s new",ic:"file",run:()=>Qt("amneziawg",e.release,`What’s new in the ${l?.label??"AmneziaWG"} build`,s??"slava")}:null,{label:"Open on GitHub",ic:"globe",run:()=>window.open(`https://github.com/${l?.repo??"Slava-Shchipunov/awg-openwrt"}`,"_blank","noopener")},...u.length?[null,...u]:[]].filter((f,g,S)=>f!==null||g>0&&S[g-1]!==null),$=r.tunnels??[],h=$.length?`Switching restarts ${$.length===1?"the tunnel":`${$.length} tunnels`} for a few seconds: ${$.join(", ")}. Devices keep their configurations.`:"Switching takes a few seconds. Devices keep their configurations.",m=$.length>1?`${$.slice(0,-1).join(", ")} and ${$[$.length-1]}`:$[0],C=$.length?`Switching restarts ${m} for a few seconds.`:"Switching takes a few seconds.",B=async f=>{let g=a[f];await le(p?`Switch to AmneziaWG ${g.gen}?`:`Install AmneziaWG ${g.gen}?`,`The ${g.label} build, ${g.version}. ${h}${g.gen==="3.1"?" Devices need AmneziaVPN 3.1 or newer.":""}`,p?"Switch":"Install")&&n.op(`amneziawg:${f}${d?":ru":""}`,p?`Switching to AmneziaWG ${g.gen}`:"Installing AmneziaWG",p??void 0)},w=f=>{let g=a[f],S=s===f&&!!p;return t("div",{class:"dl-row"},[t("span",{class:"dl-row-main dl-stack"},[t("b",{},g.gen?`AmneziaWG ${g.gen}`:"AmneziaWG"),t("span",{class:"dl-sub"},`${g.label} · ${g.gen==="3.1"?"AmneziaVPN 3.1+":"every app"}`)]),t("span",{class:"dl-mono dl-faint dl-comp-bver"},g.version??"none yet"),t("span",{class:"dl-comp-bact"},S?Ee("ok","Active"):g.version?H(p?"Switch":"Install",()=>B(f),p?"neutral":"positive",{disabled:n.busy}):Ee("","No build"))])},v=i.map(f=>a[f]?.newer?`${a[f].label} moves to ${a[f].newer.gen} with OpenWrt ${a[f].newer.tag.replace(
Line truncated
|
`).map(l=>/^\s*[-*+]\s+(.*)$/.exec(l)?.[1]).filter(l=>!!l);i.length||(i=(await P.updatesChanges(r,e).catch(()=>null))?.items??[]);let s={items:i.slice(0,3).map(l=>Js(o(l))),total:i.length};n.notes.set(e,s),s.items.length&&n.root.isConnected&&n.paint()})(),null}function Zs(n){let e=t("div",{class:"dl-params-body"}),r=t("details",{class:"dl-params dl-comp-vers",open:n.versOpen?"open":null},[t("summary",{},[v("chevron"),t("span",{},"Versions"),t("span",{class:"dl-sub"},"install any release")]),e]);return r.addEventListener("toggle",()=>{n.versOpen=r.open,n.versOpen&&Nn(n,e)}),n.versOpen&&Nn(n,e),r}async function Nn(n,e){let r=le("",{placeholder:"Tag, e.g. 0.3.1",class:"cbi-input-text dl-mono","aria-label":"Release tag"}),o=p=>{if(p=p.trim(),!/^v?[0-9][0-9A-Za-z.+~-]{0,40}$/.test(p))return U("Enter a release tag like 0.3.1","warning");Ta(n,p)};r.addEventListener("keydown",p=>{p.key==="Enter"&&(p.preventDefault(),o(r.value))});let a=t("div",{class:"dl-comp-tag"},[r,D("Install",()=>o(r.value),"neutral",{disabled:n.busy})]),i=n.versPage,s=p=>{n.versPage=Math.max(1,n.versPage+p),Nn(n,e)},l=p=>t("div",{class:"dl-comp-pager"},[t("button",{type:"button",class:"dl-linkbtn",disabled:i<=1?"disabled":null,click:()=>s(-1)},"← Newer"),t("span",{class:"dl-faint"},`Page ${i}`),t("button",{type:"button",class:"dl-linkbtn",disabled:p?null:"disabled",click:()=>s(1)},"Older →")]),d=n.versCache.get(i);if(!d){dom.content(e,[a,t("p",{class:"dl-muted dl-loading"},"Loading versions…")]);try{d=(await P.updatesReleases(i)).releases}catch(p){if(i!==n.versPage||!e.isConnected)return;dom.content(e,[a,t("div",{class:"dl-row-actions"},[t("span",{class:"dl-muted"},`Failed to load versions: ${be(p)}`),D("Try again",()=>Nn(n,e))]),l(!1)]);return}if(n.versCache.set(i,d),i!==n.versPage||!e.isConnected)return}if(!d.length)return dom.content(e,[a,t("p",{class:"dl-muted"},i>1?"No more versions.":"No versions found."),l(!1)]);let c=n.st.version;dom.content(e,[a,...d.map(p=>{let u=p.tag.replace(/^v/,"");return t("div",{class:"dl-comp-ver"},[t("span",{class:"dl-mono"},u),t("span",{class:"dl-sub"},Co(p.published)),p.prerelease?Ee("warn","Pre-release"):"",t("span",{class:"dl-comp-ic"},Le("file","What’s new",()=>Zt("app",p.tag,`What’s new in Dawnline ${u}`))),u===c?Ee("ok","Installed"):D("Install",()=>Ta(n,p.tag),"neutral",{disabled:n.busy})])}),l(d.length>=5)])}async function Ta(n,e){let r=e.replace(/^v/,"");r.localeCompare(n.st.version,void 0,{numeric:!0})<0&&!await se(`Install Dawnline ${r}?`,`It is older than ${n.st.version}. A backup of the settings is made first; restore it from Settings if something looks wrong.`,"Install")||n.op(`app@${e}`,`Installing Dawnline ${r}`,n.st.version)}function Pa(n,e){let r=n.st,o=r.kept?.amneziawg,a=e?.sources??{},i=Object.keys(a),s=e?.current??null,l=s?a[s]:void 0,d=!!e?.ru,c=r.needs?.awg??[],p=c.length?null:e?.installed??null,u=[];s&&p&&u.push({label:"Reinstall this build",warn:!0,ic:"reset",run:()=>n.op(`amneziawg:${s}${d?":ru":""}`,"Reinstalling AmneziaWG",p)}),o&&u.push({label:`Roll back to ${o.version}`,ic:"archive",warn:!0,run:async()=>{await se(`Roll back AmneziaWG to ${o.version}?`,"The build kept on the router is installed again. Every AmneziaWG tunnel restarts for a few seconds.","Roll back")&&n.op("amneziawg:rollback","Rolling back AmneziaWG",p??void 0)}});let x=[e?.release?{label:"What’s new",ic:"file",run:()=>Zt("amneziawg",e.release,`What’s new in the ${l?.label??"AmneziaWG"} build`,s??"slava")}:null,{label:"Open on GitHub",ic:"globe",run:()=>window.open(`https://github.com/${l?.repo??"Slava-Shchipunov/awg-openwrt"}`,"_blank","noopener")},...u.length?[null,...u]:[]].filter((f,g,M)=>f!==null||g>0&&M[g-1]!==null),$=r.tunnels??[],h=$.length?`Switching restarts ${$.length===1?"the tunnel":`${$.length} tunnels`} for a few seconds: ${$.join(", ")}. Devices keep their configurations.`:"Switching takes a few seconds. Devices keep their configurations.",m=$.length>1?`${$.slice(0,-1).join(", ")} and ${$[$.length-1]}`:$[0],E=$.length?`Switching restarts ${m} for a few seconds.`:"Switching takes a few seconds.",R=async f=>{let g=a[f];await se(p?`Switch to AmneziaWG ${g.gen}?`:`Install AmneziaWG ${g.gen}?`,`The ${g.label} build, ${g.version}. ${h}${g.gen==="3.1"?" Devices need AmneziaVPN 3.1 or newer.":""}`,p?"Switch":"Install")&&n.op(`amneziawg:${f}${d?":ru":""}`,p?`Switching to AmneziaWG ${g.gen}`:"Installing AmneziaWG",p??void 0)},C=f=>{let g=a[f],M=s===f&&!!p;return t("div",{class:"dl-row"},[t("span",{class:"dl-row-main dl-stack"},[t("b",{},g.gen?`AmneziaWG ${g.gen}`:"AmneziaWG"),t("span",{class:"dl-sub"},`${g.label} · ${g.gen==="3.1"?"AmneziaVPN 3.1+":"every app"}`)]),t("span",{class:"dl-mono dl-faint dl-comp-bver"},g.version??"none yet"),t("span",{class:"dl-comp-bact"},M?Ee("ok","Active"):g.version?D(p?"Switch":"Install",()=>R(f),p?"neutral":"positive",{disabled:n.busy}):Ee("","No build"))])},k=i.map(f=>a[f]?.newer?`${a[f].label} moves to ${a[f].newer.gen} with OpenWrt ${a[f].newer.tag.replace(
Line truncated
|
||||||
`)}a.push(p),l+=c-1}let s=H([b("more")],()=>Ce(s,[{label:"Export CSV",icon:b("download"),run:()=>Fe(r,o,"csv",e.id)},{label:"Export JSON",icon:b("download"),run:()=>Fe(r,o,"json",e.id)},null,{label:`Clear ${e.name}'s activity`,icon:b("trash"),danger:!0,run:()=>tt(`Clear ${e.name}'s activity`,`Removes events about ${e.name} and their devices.`,{person:e.id},()=>n.refresh())}]),"neutral",{title:"Export or clear",class:"cbi-button cbi-button-neutral dl-icon-only"});return t("div",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Activity"),t("span",{class:"dl-sub"},o.length>10?`latest 10 of ${o.length}`:""),t("span",{class:"dl-spacer"}),s]),a.length?a:t("div",{class:"dl-row dl-muted"},"Nothing yet.")])}var Rn=class{constructor(){this.id="";this.events=[];this.mapOpen=!1;this.map=null;this.parts={};this.series=[];this.devSeries={};this.ticks=0;this.fullNext=!1}async fetch(e){let[r,o,a]=await Promise.all([A.status(30),e?A.events(2e3,this.id).catch(()=>null):Promise.resolve(null),e?A.personUsage(this.id,30).catch(()=>null):Promise.resolve(null)]);return{st:r,ev:o?.events??null,use:a}}async load(){return this.id=new URLSearchParams(location.search).get("id")??"",this.fetch(!0)}render(e){this.take(e);let r=this.st.people.find(s=>s.id===this.id);if(!r)return t("div",{class:"dl-empty"},[t("h3",{},"Person not found"),t("p",{},"They may have been removed."),t("a",{class:"cbi-button",href:L.url("admin/network/dawnline/server")},"Back to Servers")]);this.p=r;for(let s of["crumbs","head","devices","traffic","places","activity","limits"])this.parts[s]=t("div",{});this.parts.devices.className="dl-person-devices";let o=t("div",{},[this.parts.crumbs,this.parts.head,t("div",{class:"dl-grid-person"},[t("div",{class:"dl-col"},[this.parts.devices,this.parts.traffic,this.parts.places,this.parts.activity]),t("div",{class:"dl-col"},[this.parts.limits])])]);this.paint();let a=new URLSearchParams(location.search),i=a.get("device")&&r.devices.find(s=>s.id===a.get("device"));return i?setTimeout(()=>Ge(this.p,i,this.deviceOpts()),50):a.get("add")&&setTimeout(()=>ot(this.p,this.deviceOpts()),50),this.poller=rt({fetch:s=>{let l=s||this.fullNext||++this.ticks%4===0;return this.fullNext=!1,this.fetch(l)},every:15,live:!0,active:()=>o.isConnected,apply:(s,l)=>this.apply(s,l)}),o}take(e){this.st=e.st,e.ev&&(this.events=e.ev),e.use&&(this.series=e.use.person,this.devSeries=e.use.devices)}apply(e,r){this.take(e);let o=this.st.people.find(a=>a.id===this.id);if(!o){r||(location.href=Pt(this.p?.server));return}this.p=o,this.paint(r),this.map?.update(this.mapData())}async refresh(){this.fullNext=!0,await this.poller?.refresh()}async patch(e,r){var i;this.poller?.claim();let o=await G(()=>A.personUpdate(this.p.id,e),r);if(!o)return!1;this.poller?.claim();let a=this.st.people.findIndex(s=>s.id===this.p.id);return(i=o.person).rate??(i.rate=this.p.rate),a>=0&&(this.st.people[a]=o.person),this.p=o.person,this.paint(),!0}get today(){return Ie(this.series.length?this.series:this.st.series)}get core(){return Tt(this.st.servers,this.p.server)}deviceOpts(){return{refresh:()=>this.refresh(),geo:this.st.geo,now:this.st.now,today:this.today,core:this.core,events:()=>this.events}}mapData(){return{geo:this.st.geo,people:this.st.people,now:this.st.now,person:this.p.id}}crumbs(){let e=this.p;return t("nav",{class:"dl-crumbs","aria-label":"Breadcrumb"},[t("a",{href:Pt(e.server)},this.st.servers.find(r=>r.id===e.server)?.name??"Servers"),t("span",{},"/"),t("a",{href:Pt(e.server)},"People"),t("span",{},"/"),t("span",{},e.name)])}paint(e=!1){Se(this.parts.crumbs,this.crumbs(),e),Se(this.parts.head,Ua(this),e),Se(this.parts.traffic,Ga(this),e),Se(this.parts.devices,Wa(this),e),Se(this.parts.limits,Za(this),e),this.paintPlaces(e),Se(this.parts.activity,Xa(this),e)}paintPlaces(e=!1){let r=Qa(this);r&&Se(this.parts.places,r,e&&!this.mapOpen)}};var il={ok:"check",warn:"alert",error:"x",skip:"pause"},In=class{constructor(e,r,o,a){this.el=t("div",{});this.wdEl=t("div",{});this.checksEl=t("div",{class:"dl-panel"});this.recentEl=t("div",{class:"dl-panel flush dl-recent"});this.checks=null;this.summary=t("div",{});this.open=new Set;this.st=e,this.sl=r,this.events=o,this.toLog=a,dom.content(this.el,[this.summary,this.wdEl,t("div",{class:"dl-health-cols"},[this.checksEl,this.recentEl])]),this.paintChecks(),this.paintLive(r,o)}async run(e){let r=e?await Dn(e):await A.health().catch(()=>null);r&&(this.take(r),e==="netrestart"&&setTimeout(()=>this.el.isConnected&&void this.run(),5e3))}take(e){this.checks=e.checks,this.paintChecks(),this.paintLive(e,this.events)}paintChecks(){let e=this.checks;if(!e){dom.content(this.summary,""),dom.content(this.checksEl,[t("div",{class:"dl-panel-head"},[t("h3",{},"Checks")]),t("p",{class:"dl-muted dl-loading"},"Running checks…")]);return}let r=e.filter(s=>s.status==="error").length,o=e.filter(s=>s.status==="warn").length;dom.content(this.summary,r?pt("error",`${r} problem${r>1?"s":""} need attention.`):o?pt("warn",`${o} warnLine truncated
|
`)}a.push(p),l+=c-1}let s=D([v("more")],()=>Ce(s,[{label:"Export CSV",icon:v("download"),run:()=>Fe(r,o,"csv",e.id)},{label:"Export JSON",icon:v("download"),run:()=>Fe(r,o,"json",e.id)},null,{label:`Clear ${e.name}'s activity`,icon:v("trash"),danger:!0,run:()=>et(`Clear ${e.name}'s activity`,`Removes events about ${e.name} and their devices.`,{person:e.id},()=>n.refresh())}]),"neutral",{title:"Export or clear",class:"cbi-button cbi-button-neutral dl-icon-only"});return t("div",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Activity"),t("span",{class:"dl-sub"},o.length>10?`latest 10 of ${o.length}`:""),t("span",{class:"dl-spacer"}),s]),a.length?a:t("div",{class:"dl-row dl-muted"},"Nothing yet.")])}var In=class{constructor(){this.id="";this.events=[];this.mapOpen=!1;this.map=null;this.parts={};this.series=[];this.devSeries={};this.ticks=0;this.fullNext=!1}async fetch(e){let[r,o,a]=await Promise.all([P.status(30),e?P.events(2e3,this.id).catch(()=>null):Promise.resolve(null),e?P.personUsage(this.id,30).catch(()=>null):Promise.resolve(null)]);return{st:r,ev:o?.events??null,use:a}}async load(){return this.id=new URLSearchParams(location.search).get("id")??"",this.fetch(!0)}render(e){this.take(e);let r=this.st.people.find(s=>s.id===this.id);if(!r)return t("div",{class:"dl-empty"},[t("h3",{},"Person not found"),t("p",{},"They may have been removed."),t("a",{class:"cbi-button",href:L.url("admin/network/dawnline/server")},"Back to Servers")]);this.p=r;for(let s of["crumbs","head","devices","traffic","places","activity","limits"])this.parts[s]=t("div",{});this.parts.devices.className="dl-person-devices";let o=t("div",{},[this.parts.crumbs,this.parts.head,t("div",{class:"dl-grid-person"},[t("div",{class:"dl-col"},[this.parts.devices,this.parts.traffic,this.parts.places,this.parts.activity]),t("div",{class:"dl-col"},[this.parts.limits])])]);this.paint();let a=new URLSearchParams(location.search),i=a.get("device")&&r.devices.find(s=>s.id===a.get("device"));return i?setTimeout(()=>Ge(this.p,i,this.deviceOpts()),50):a.get("add")&&setTimeout(()=>nt(this.p,this.deviceOpts()),50),this.poller=ot({fetch:s=>{let l=s||this.fullNext||++this.ticks%4===0;return this.fullNext=!1,this.fetch(l)},every:15,live:!0,active:()=>o.isConnected,apply:(s,l)=>this.apply(s,l)}),o}take(e){this.st=e.st,e.ev&&(this.events=e.ev),e.use&&(this.series=e.use.person,this.devSeries=e.use.devices)}apply(e,r){this.take(e);let o=this.st.people.find(a=>a.id===this.id);if(!o){r||(location.href=_t(this.p?.server));return}this.p=o,this.paint(r),this.map?.update(this.mapData())}async refresh(){this.fullNext=!0,await this.poller?.refresh()}async patch(e,r){var i;this.poller?.claim();let o=await G(()=>P.personUpdate(this.p.id,e),r);if(!o)return!1;this.poller?.claim();let a=this.st.people.findIndex(s=>s.id===this.p.id);return(i=o.person).rate??(i.rate=this.p.rate),a>=0&&(this.st.people[a]=o.person),this.p=o.person,this.paint(),!0}get today(){return Ie(this.series.length?this.series:this.st.series)}get core(){return St(this.st.servers,this.p.server)}deviceOpts(){return{refresh:()=>this.refresh(),geo:this.st.geo,now:this.st.now,today:this.today,core:this.core,events:()=>this.events}}mapData(){return{geo:this.st.geo,people:this.st.people,now:this.st.now,person:this.p.id}}crumbs(){let e=this.p;return t("nav",{class:"dl-crumbs","aria-label":"Breadcrumb"},[t("a",{href:_t(e.server)},this.st.servers.find(r=>r.id===e.server)?.name??"Servers"),t("span",{},"/"),t("a",{href:_t(e.server)},"People"),t("span",{},"/"),t("span",{},e.name)])}paint(e=!1){Se(this.parts.crumbs,this.crumbs(),e),Se(this.parts.head,ja(this),e),Se(this.parts.traffic,Ua(this),e),Se(this.parts.devices,Ga(this),e),Se(this.parts.limits,Ya(this),e),this.paintPlaces(e),Se(this.parts.activity,Qa(this),e)}paintPlaces(e=!1){let r=Za(this);r&&Se(this.parts.places,r,e&&!this.mapOpen)}};var sl={ok:"check",warn:"alert",error:"x",skip:"pause"},Bn=class{constructor(e,r,o,a){this.el=t("div",{});this.wdEl=t("div",{});this.checksEl=t("div",{class:"dl-panel"});this.recentEl=t("div",{class:"dl-panel flush dl-recent"});this.checks=null;this.summary=t("div",{});this.open=new Set;this.st=e,this.sl=r,this.events=o,this.toLog=a,dom.content(this.el,[this.summary,this.wdEl,t("div",{class:"dl-health-cols"},[this.checksEl,this.recentEl])]),this.paintChecks(),this.paintLive(r,o)}async run(e){let r=e?await An(e):await P.health().catch(()=>null);r&&(this.take(r),e==="netrestart"&&setTimeout(()=>this.el.isConnected&&void this.run(),5e3))}take(e){this.checks=e.checks,this.paintChecks(),this.paintLive(e,this.events)}paintChecks(){let e=this.checks;if(!e){dom.content(this.summary,""),dom.content(this.checksEl,[t("div",{class:"dl-panel-head"},[t("h3",{},"Checks")]),t("p",{class:"dl-muted dl-loading"},"Running checks…")]);return}let r=e.filter(s=>s.status==="error").length,o=e.filter(s=>s.status==="warn").length;dom.content(this.summary,r?ct("error",`${r} problem${r>1?"s":""} need attention.`):o?ct("warn",`${o} warnLine truncated
|
||||||
`);function gi(){let n=document.createElement("style");return n.dataset.dawnline="1",n.textContent=Cl,n}function ht(n){return()=>{let e=new n;return Object.assign({load:()=>e.load(),render:async o=>{let a=await e.render(o),i=document.createElement("div");return i.className="dl-root",i.append(gi(),a),i},addFooter(){return e.noFooter?document.createElement("div"):this.super("addFooter",[])}},{handleSave:null,handleSaveApply:null,handleReset:null})}}var v1=ht(Zt),b1=ht(mt),x1=ht(Zt),w1=ht(Hn),y1=ht(Rn),k1=ht(jn),$1=ht(Nn);function vi(n){return()=>({load:()=>(ui.menu?.flushCache(),location.replace(`${L.url("admin/network/dawnline/diagnostics")}${n?`?tab=${n}`:""}`),new Promise(()=>{})),render:()=>document.createElement("div"),handleSave:null,handleSaveApply:null,handleReset:null})}var C1=vi(""),E1=vi("log");return baseclass.extend({ activity: E1, diagnostics: k1, health: C1, overview: v1, people: b1, person: y1, server: x1, settings: w1, updates: $1 });
|
`);function fi(){let n=document.createElement("style");return n.dataset.dawnline="1",n.textContent=El,n}function ht(n){return()=>{let e=new n;return Object.assign({load:()=>e.load(),render:async o=>{let a=await e.render(o),i=document.createElement("div");return i.className="dl-root",i.append(fi(),a),i},addFooter(){return e.noFooter?document.createElement("div"):this.super("addFooter",[])}},{handleSave:null,handleSaveApply:null,handleReset:null})}}var C1=ht(Yt),E1=ht(mt),L1=ht(Yt),M1=ht(zn),S1=ht(In),T1=ht(Un),_1=ht(Rn);function gi(n){return()=>({load:()=>(ui.menu?.flushCache(),location.replace(`${L.url("admin/network/dawnline/diagnostics")}${n?`?tab=${n}`:""}`),new Promise(()=>{})),render:()=>document.createElement("div"),handleSave:null,handleSaveApply:null,handleReset:null})}var P1=gi(""),D1=gi("log");return baseclass.extend({ activity: D1, diagnostics: T1, health: P1, overview: C1, people: E1, person: S1, server: L1, settings: M1, updates: _1 });
|
||||||
@@ -1 +1 @@
|
|||||||
@font-face{font-family:Geist;src:url(geist-latin-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap;unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+20AC,U+2122,U+2190-21FF,U+2212,U+2215}@font-face{font-family:Geist;src:url(geist-cyrillic-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap;unicode-range:U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116}@font-face{font-family:Geist Mono;src:url(geist-mono-latin-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap}:root{--ease-out: cubic-bezier(.23, 1, .32, 1);--ease-in: cubic-bezier(.55, 0, 1, .45);--ease-drawer: cubic-bezier(.32, .72, 0, 1);--spring: linear( 0, .022, .079, .158, .249, .344, .438, .527, .61, .684, .749, .805, .852, .891, .923, .949, .969, .984, .996, 1.004, 1.009, 1.013, 1.014, 1.015, 1.015, 1.014, 1.013, 1.012, 1.01, 1.009, 1.008, 1.006, 1.005, 1.004, 1.003, 1.002, 1.002, 1.001, 1.001, 1.001, 1 );--spring-pop: linear( 0, .034, .122, .244, .383, .526, .662, .785, .889, .974, 1.038, 1.083, 1.111, 1.124, 1.126, 1.119, 1.106, 1.09, 1.072, 1.054, 1.038, 1.023, 1.01, 1, .993, .988, .985, .984, .984, .985, .987, .989, .992, .994, .996, .998, .999, 1, 1.001, 1.002, 1 );--dur-press: .12s;--dur-hover: .15s;--dur-pop: .18s;--dur-swap: .26s;--dur-enter: .44s;--dur-sheet: .44s;--dur-exit: .16s;--bg: #fcfcfc;--card: #ffffff;--elevated: #ffffff;--text: #0d0d0d;--muted: #5d5d5d;--faint: #8f8f8f;--line: #0000001a;--input: #00000026;--soft: #0d0d0d0d;--soft-hover: #0d0d0d1a;--primary: #0d0d0d;--primary-fg: #ffffff;--accent: #3a83f7;--info: #2c67c5;--ok: #00a240;--ok-wash: #00a24026;--warn: #e25507;--warn-wash: #e2550726;--bad: #e02e2a;--bad-wash: #e02e2a1f;--chart: #3a83f7;--track: #0d0d0d1a;--scrim: #00000040;--shadow: 0 1px 2px -1px #00000014;--shadow-xl: 0 8px 16px -4px #0000001f;--radius: 16px;--mono: "Geist Mono", ui-monospace, Menlo, monospace;color-scheme:light dark}@media(prefers-color-scheme:dark){:root{--bg: #000000;--card: #0a0a0a;--elevated: #131313;--text: #ededed;--muted: #edededa6;--faint: #ededed78;--line: #ededed13;--input: #ededed24;--soft: #ededed0d;--soft-hover: #ededed1a;--primary: #ededed;--primary-fg: #131313;--accent: #006efe;--info: #5ba2fe;--ok: #40c977;--ok-wash: #40c97726;--warn: #ff8549;--warn-wash: #ff854926;--bad: #ff6764;--bad-wash: #ff676422;--chart: #3a83f7;--track: #ededed1a;--scrim: #00000099;--shadow: none;--shadow-xl: 0 8px 16px -4px #00000080}}*{box-sizing:border-box}html,body{margin:0}html{scrollbar-gutter:stable}body{background:var(--bg);color:var(--text);font:400 15px/22px Geist,-apple-system,system-ui,Segoe UI,sans-serif;-webkit-font-smoothing:antialiased;min-height:100vh;min-height:100dvh;cursor:default}input,textarea,.linkrow .mono,.conf{cursor:text}body.locked{overflow:hidden}a{color:var(--info);text-decoration:none}a:hover{text-decoration:underline}a.btn:hover,a.badge:hover{text-decoration:none}h1,h2{margin:0;font-weight:500;letter-spacing:-.01em}h1{font-size:24px;line-height:32px}h2{font-size:16px;line-height:24px}.muted{color:var(--muted)}.faint{color:var(--faint)}.s{font-size:13px;line-height:18px}.ok{color:var(--ok)}.warn{color:var(--warn)}.strong{font-weight:500}.center{text-align:center}.mono{font-family:var(--mono);font-size:12px}.stack{display:flex;flex-direction:column;gap:2px;min-width:0}.stack.gap{gap:10px}.grow{flex:1}.row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.row.gap{gap:8px;flex-wrap:nowrap}.row-baseline{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}.offscreen{position:fixed;left:-9999px;opacity:0}.top{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:max(12px,env(safe-area-inset-top)) 16px 12px;border-bottom:1px solid var(--line);position:sticky;top:0;background:color-mix(in srgb,var(--bg) 85%,transparent);backdrop-filter:saturate(180%) blur(12px);z-index:5}.brand{display:flex;align-items:center;gap:8px;font-weight:500;min-width:0}.brand .faint{font-weight:400}.logo{display:inline-flex;width:22px;height:22px;color:var(--text)}.logo svg{width:100%;height:100%}.wrap{width:100%;max-width:1048px;margin:0 auto;padding:20px 16px max(32px,env(safe-area-inset-bottom));display:flex;flex-direction:column;gap:20px}.hello{display:flex;align-items:center;gap:12px}.avatar{width:44px;height:44px;border-radius:50%;background:var(--soft-hover);display:inline-flex;align-items:center;justify-content:center;font-size:14px;font-weight:600;position:relative;flex:0 0 auto}.avatar.online:after{content:"";position:absolute;right:0;bottom:0;width:10px;height:10px;border-radius:50%;background:var(--ok);box-shadow:0 0 0 3px var(--bg)}.notice{display:flex;gap:10px;align-items:flex-start;padding:12px 14px;border-radius:12px;background:var(--warn-wash);font-size:14px}.notice.bad{background:var(--bad-wash)}.notice .ic{color:var(--warn)}.notice.bad .ic{color:var(--bad)}.alert{display:flex;gap:12px;align-items:center;padding:12px 16px;border:1px solid var(--line);bordLine truncated
|
@font-face{font-family:Geist;src:url(geist-latin-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap;unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+20AC,U+2122,U+2190-21FF,U+2212,U+2215}@font-face{font-family:Geist;src:url(geist-cyrillic-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap;unicode-range:U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116}@font-face{font-family:Geist Mono;src:url(geist-mono-latin-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap}:root{color-scheme:dark;--bg: #080808;--raised: #121212;--field: #161616;--knob: #232323;--seg: rgba(237, 237, 237, .05);--seg-shadow: none;--line: rgba(255, 255, 255, .06);--text: #ededed;--text-2: #8c8c8a;--text-3: #4f4f4e;--accent: #4eafff;--accent-ink: #ffffff;--accent-soft: rgba(78, 175, 255, .13);--ok: #57d64b;--ok-soft: rgba(87, 214, 75, .14);--warn: #ff8a3d;--bad: #ff5c5c;--bad-soft: rgba(255, 92, 92, .13);--sel-bg: rgba(131, 209, 255, .25);--sel-fg: #64c6ff;--scrim: rgba(8, 8, 8, .8);--line-glass: rgba(255, 255, 255, .07);--pop-shadow: 0 18px 48px -14px rgba(0, 0, 0, .75);--sheet-shadow: 0 24px 64px -16px rgba(0, 0, 0, .6);--bar: rgba(237, 237, 237, .13);--toast: #232323;--toast-fg: #ededed;--qr-bg: #0a0a0a;--gi-a: rgba(255, 255, 255, .58);--gi-b: rgba(255, 255, 255, .14);--gi-rim: rgba(255, 255, 255, .5);--gi-edge: rgba(0, 0, 0, 0);--gi-detail: #ffffff;--t-grey-a: #cfcfcd;--t-grey-b: #5a5a59;--t-blue-a: #a6d9ff;--t-blue-b: #1d84e6;--t-green-a: #a8f29c;--t-green-b: #3aa32c;--t-red-a: #ffadad;--t-red-b: #dc3a3a;--t-orange-a: #ffc08f;--t-orange-b: #ec6a12;--font: Geist, -apple-system, system-ui, "Segoe UI", sans-serif;--mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;--r-sheet: 36px;--r-card: 28px;--r-row: 20px;--r-field: 16px;--r-tile: 12px;--ease-out: cubic-bezier(.23, 1, .32, 1);--gutter-l: max(16px, env(safe-area-inset-left, 0px));--gutter-r: max(16px, env(safe-area-inset-right, 0px))}@media(prefers-color-scheme:light){:root{color-scheme:light;--bg: #f2f2f1;--raised: #ffffff;--field: #f3f3f2;--knob: #e8e8e7;--seg: #ffffff;--seg-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 0 0 .5px rgba(0, 0, 0, .05);--line: rgba(0, 0, 0, .07);--text: #0b0b0b;--text-2: #6d6d6b;--text-3: #a6a6a4;--accent: #2b9dff;--accent-soft: rgba(43, 157, 255, .12);--ok: #33a328;--ok-soft: rgba(51, 163, 40, .12);--warn: #ee6a12;--bad: #e5484d;--bad-soft: rgba(229, 72, 77, .1);--sel-bg: rgba(78, 175, 255, .22);--sel-fg: #0a76cf;--scrim: rgba(236, 236, 235, .62);--line-glass: rgba(0, 0, 0, .07);--pop-shadow: 0 18px 44px -14px rgba(0, 0, 0, .2);--sheet-shadow: 0 24px 64px -18px rgba(0, 0, 0, .22);--bar: rgba(11, 11, 11, .11);--toast: #0b0b0b;--toast-fg: #f2f2f1;--qr-bg: #ffffff;--gi-a: rgba(250, 250, 249, .72);--gi-b: rgba(206, 206, 204, .5);--gi-rim: rgba(255, 255, 255, .9);--gi-edge: rgba(0, 0, 0, .11);--gi-detail: rgba(28, 28, 28, .72);--t-grey-a: #a9a9a7;--t-grey-b: #3d3d3c;--t-blue-a: #7cc4ff;--t-blue-b: #0a6fd6;--t-green-a: #82e070;--t-green-b: #2e8a22;--t-red-a: #ff9090;--t-red-b: #c92a2a}}*{box-sizing:border-box}html{-webkit-text-size-adjust:100%;scrollbar-gutter:stable}body{margin:0;background:var(--bg);color:var(--text);font:400 15px/22px var(--font);letter-spacing:-.011em;-webkit-font-smoothing:antialiased;min-height:100vh;min-height:100dvh;cursor:default}body.locked{overflow:hidden}input,textarea,.linkrow .mono,.conf{cursor:text}::selection{background:var(--sel-bg);color:var(--sel-fg)}button{font:inherit;color:inherit;letter-spacing:inherit;background:none;border:0;padding:0;margin:0;cursor:pointer;-webkit-tap-highlight-color:transparent}button:disabled{cursor:default}a{color:inherit;text-decoration:none}:focus{outline:none}:focus-visible{outline:2px solid color-mix(in srgb,var(--accent) 65%,transparent);outline-offset:2px}[hidden]{display:none!important}.offscreen{position:fixed;left:-9999px;top:0;opacity:0}.mono{font-family:var(--mono);letter-spacing:0}.num{font-variant-numeric:tabular-nums}.ok-t{color:var(--ok)}.warn-t{color:var(--warn)}.bad-t{color:var(--bad)}.here-t{color:var(--accent)}.i{width:18px;height:18px;flex:none}.gi{width:24px;height:24px;flex:none;overflow:visible;--ta: var(--t-grey-a);--tb: var(--t-grey-b)}.gi.t-blue{--ta: var(--t-blue-a);--tb: var(--t-blue-b)}.gi.t-green{--ta: var(--t-green-a);--tb: var(--t-green-b)}.gi.t-red{--ta: var(--t-red-a);--tb: var(--t-red-b)}.gi.t-orange{--ta: var(--t-orange-a);--tb: var(--t-orange-b)}.gi .ta{stop-color:var(--ta)}.gi .tb{stop-color:var(--tb)}.gi .fa{stop-color:var(--gi-a)}.gi .fb{stop-color:var(--gi-b)}.gi .fc{stop-color:var(--ta);stop-opacity:.28}.gi .ge{stroke:var(--gi-edge)}.gi .gr{stroke:var(--gi-rim)}.gi .gd{stroke:var(--gi-detail)}.gi .gdf{color:var(--gi-detail)}.knob{width:32px;height:32px;border-radius:50%;background:var(--knob);color:var(--text);display:grid;place-items:center;flex:none;transition:transform .15s var(--ease-out),background-color .15s}.knob:hover{background:color-miLine truncated
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";(()=>{var _n=Object.create;var dt=Object.defineProperty;var Sn=Object.getOwnPropertyDescriptor;var Pn=Object.getOwnPropertyNames;var Dn=Object.getPrototypeOf,Hn=Object.prototype.hasOwnProperty;var Bn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Nn=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Pn(t))!Hn.call(e,s)&&s!==n&&dt(e,s,{get:()=>t[s],enumerable:!(a=Sn(t,s))||a.enumerable});return e};var Rn=(e,t,n)=>(n=e!=null?_n(Dn(e)):{},Nn(t||!e||!e.__esModule?dt(n,"default",{value:e,enumerable:!0}):n,e));var xt=Bn((wt,bt)=>{"use strict";var yt=(function(){var e=function(v,y){var g=236,k=17,d=v,M=n[y],l=null,o=0,C=null,f=[],x={},B=function(u,p){o=d*4+17,l=(function(c){for(var h=new Array(c),w=0;w<c;w+=1){h[w]=new Array(c);for(var A=0;A<c;A+=1)h[w][A]=null}return h})(o),N(0,0),N(o-7,0),N(0,o-7),z(),F(),ne(u,p),d>=7&&Z(u),C==null&&(C=$e(d,M,f)),Y(C,p)},N=function(u,p){for(var c=-1;c<=7;c+=1)if(!(u+c<=-1||o<=u+c))for(var h=-1;h<=7;h+=1)p+h<=-1||o<=p+h||(0<=c&&c<=6&&(h==0||h==6)||0<=h&&h<=6&&(c==0||c==6)||2<=c&&c<=4&&2<=h&&h<=4?l[u+c][p+h]=!0:l[u+c][p+h]=!1)},I=function(){for(var u=0,p=0,c=0;c<8;c+=1){B(!0,c);var h=s.getLostPoint(x);(c==0||u>h)&&(u=h,p=c)}return p},F=function(){for(var u=8;u<o-8;u+=1)l[u][6]==null&&(l[u][6]=u%2==0);for(var p=8;p<o-8;p+=1)l[6][p]==null&&(l[6][p]=p%2==0)},z=function(){for(var u=s.getPatternPosition(d),p=0;p<u.length;p+=1)for(var c=0;c<u.length;c+=1){var h=u[p],w=u[c];if(l[h][w]==null)for(var A=-2;A<=2;A+=1)for(var D=-2;D<=2;D+=1)A==-2||A==2||D==-2||D==2||A==0&&D==0?l[h+A][w+D]=!0:l[h+A][w+D]=!1}},Z=function(u){for(var p=s.getBCHTypeNumber(d),c=0;c<18;c+=1){var h=!u&&(p>>c&1)==1;l[Math.floor(c/3)][c%3+o-8-3]=h}for(var c=0;c<18;c+=1){var h=!u&&(p>>c&1)==1;l[c%3+o-8-3][Math.floor(c/3)]=h}},ne=function(u,p){for(var c=M<<3|p,h=s.getBCHTypeInfo(c),w=0;w<15;w+=1){var A=!u&&(h>>w&1)==1;w<6?l[w][8]=A:w<8?l[w+1][8]=A:l[o-15+w][8]=A}for(var w=0;w<15;w+=1){var A=!u&&(h>>w&1)==1;w<8?l[8][o-w-1]=A:w<9?l[8][15-w-1+1]=A:l[8][15-w-1]=A}l[o-8][8]=!u},Y=function(u,p){for(var c=-1,h=o-1,w=7,A=0,D=s.getMaskFunction(p),_=o-1;_>0;_-=2)for(_==6&&(_-=1);;){for(var G=0;G<2;G+=1)if(l[h][_-G]==null){var W=!1;A<u.length&&(W=(u[A]>>>w&1)==1);var H=D(h,_-G);H&&(W=!W),l[h][_-G]=W,w-=1,w==-1&&(A+=1,w=7)}if(h+=c,h<0||o<=h){h-=c,c=-c;break}}},de=function(u,p){for(var c=0,h=0,w=0,A=new Array(p.length),D=new Array(p.length),_=0;_<p.length;_+=1){var G=p[_].dataCount,W=p[_].totalCount-G;h=Math.max(h,G),w=Math.max(w,W),A[_]=new Array(G);for(var H=0;H<A[_].length;H+=1)A[_][H]=255&u.getBuffer()[H+c];c+=G;var X=s.getErrorCorrectPolynomial(W),ee=b(A[_],X.getLength()-1),lt=ee.mod(X);D[_]=new Array(X.getLength()-1);for(var H=0;H<D[_].length;H+=1){var ct=H+lt.getLength()-D[_].length;D[_][H]=ct>=0?lt.getAt(ct):0}}for(var ut=0,H=0;H<p.length;H+=1)ut+=p[H].totalCount;for(var Ge=new Array(ut),_e=0,H=0;H<h;H+=1)for(var _=0;_<p.length;_+=1)H<A[_].length&&(Ge[_e]=A[_][H],_e+=1);for(var H=0;H<w;H+=1)for(var _=0;_<p.length;_+=1)H<D[_].length&&(Ge[_e]=D[_][H],_e+=1);return Ge},$e=function(u,p,c){for(var h=m.getRSBlocks(u,p),w=L(),A=0;A<c.length;A+=1){var D=c[A];w.put(D.getMode(),4),w.put(D.getLength(),s.getLengthInBits(D.getMode(),u)),D.write(w)}for(var _=0,A=0;A<h.length;A+=1)_+=h[A].dataCount;if(w.getLengthInBits()>_*8)throw"code length overflow. ("+w.getLengthInBits()+">"+_*8+")";for(w.getLengthInBits()+4<=_*8&&w.put(0,4);w.getLengthInBits()%8!=0;)w.putBit(!1);for(;!(w.getLengthInBits()>=_*8||(w.put(g,8),w.getLengthInBits()>=_*8));)w.put(k,8);return de(w,h)};x.addData=function(u,p){p=p||"Byte";var c=null;switch(p){case"Numeric":c=T(u);break;case"Alphanumeric":c=E(u);break;case"Byte":c=P(u);break;case"Kanji":c=K(u);break;default:throw"mode:"+p}f.push(c),C=null},x.isDark=function(u,p){if(u<0||o<=u||p<0||o<=p)throw u+","+p;return l[u][p]},x.getModuleCount=function(){return o},x.make=function(){if(d<1){for(var u=1;u<40;u++){for(var p=m.getRSBlocks(u,M),c=L(),h=0;h<f.length;h++){var w=f[h];c.put(w.getMode(),4),c.put(w.getLength(),s.getLengthInBits(w.getMode(),u)),w.write(c)}for(var A=0,h=0;h<p.length;h++)A+=p[h].dataCount;if(c.getLengthInBits()<=A*8)break}d=u}B(!1,I())},x.createTableTag=function(u,p){u=u||2,p=typeof p=="undefined"?u*4:p;var c="";c+='<table style="',c+=" border-width: 0px; border-style: none;",c+=" border-collapse: collapse;",c+=" padding: 0px; margin: "+p+"px;",c+='">',c+="<tbody>";for(var h=0;h<x.getModuleCount();h+=1){c+="<tr>";for(var w=0;w<x.getModuleCount();w+=1)c+='<td style="',c+=" border-width: 0px; border-style: none;",c+=" border-collapse: collapse;",c+=" padding: 0px; margin: 0px;",c+=" width: "+u+"px;",c+=" height: "+u+"px;",c+=" background-color: ",c+=x.isDark(h,w)?"#000000":"#ffffff",c+=";",c+='"/>';c+="</tr>"}return c+="</tbody>",c+="</table>",c},x.createSvgTag=function(u,p,c,h){var w={};typeof arguments[0]=="object"&&(w=arguments[0],u=w.cellSize,p=w.margin,c=w.alt,h=w.title),u=u||2,p=typeof p=="undefined"?u*4:p,c=typeof c=="string"?{text:c}:c||{},c.text=c.texLine truncated
|
"use strict";(()=>{var Oo=Object.create;var On=Object.defineProperty;var Ro=Object.getOwnPropertyDescriptor;var No=Object.getOwnPropertyNames;var Io=Object.getPrototypeOf,Fo=Object.prototype.hasOwnProperty;var Ko=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var qo=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of No(e))!Fo.call(t,o)&&o!==n&&On(t,o,{get:()=>e[o],enumerable:!(r=Ro(e,o))||r.enumerable});return t};var Go=(t,e,n)=>(n=t!=null?Oo(Io(t)):{},qo(e||!t||!t.__esModule?On(n,"default",{value:t,enumerable:!0}):n,t));var gr=Ko((hr,mr)=>{"use strict";var fr=(function(){var t=function(d,m){var s=236,h=17,f=d,E=n[m],p=null,l=0,L=null,x=[],C={},R=function(w,k){l=f*4+17,p=(function(y){for(var T=new Array(y),S=0;S<y;S+=1){T[S]=new Array(y);for(var D=0;D<y;D+=1)T[S][D]=null}return T})(l),I(0,0),I(l-7,0),I(0,l-7),et(),Q(),it(w,k),f>=7&&ot(w),L==null&&(L=$t(f,E,x)),G(L,k)},I=function(w,k){for(var y=-1;y<=7;y+=1)if(!(w+y<=-1||l<=w+y))for(var T=-1;T<=7;T+=1)k+T<=-1||l<=k+T||(0<=y&&y<=6&&(T==0||T==6)||0<=T&&T<=6&&(y==0||y==6)||2<=y&&y<=4&&2<=T&&T<=4?p[w+y][k+T]=!0:p[w+y][k+T]=!1)},z=function(){for(var w=0,k=0,y=0;y<8;y+=1){R(!0,y);var T=o.getLostPoint(C);(y==0||w>T)&&(w=T,k=y)}return k},Q=function(){for(var w=8;w<l-8;w+=1)p[w][6]==null&&(p[w][6]=w%2==0);for(var k=8;k<l-8;k+=1)p[6][k]==null&&(p[6][k]=k%2==0)},et=function(){for(var w=o.getPatternPosition(f),k=0;k<w.length;k+=1)for(var y=0;y<w.length;y+=1){var T=w[k],S=w[y];if(p[T][S]==null)for(var D=-2;D<=2;D+=1)for(var K=-2;K<=2;K+=1)D==-2||D==2||K==-2||K==2||D==0&&K==0?p[T+D][S+K]=!0:p[T+D][S+K]=!1}},ot=function(w){for(var k=o.getBCHTypeNumber(f),y=0;y<18;y+=1){var T=!w&&(k>>y&1)==1;p[Math.floor(y/3)][y%3+l-8-3]=T}for(var y=0;y<18;y+=1){var T=!w&&(k>>y&1)==1;p[y%3+l-8-3][Math.floor(y/3)]=T}},it=function(w,k){for(var y=E<<3|k,T=o.getBCHTypeInfo(y),S=0;S<15;S+=1){var D=!w&&(T>>S&1)==1;S<6?p[S][8]=D:S<8?p[S+1][8]=D:p[l-15+S][8]=D}for(var S=0;S<15;S+=1){var D=!w&&(T>>S&1)==1;S<8?p[8][l-S-1]=D:S<9?p[8][15-S-1+1]=D:p[8][15-S-1]=D}p[l-8][8]=!w},G=function(w,k){for(var y=-1,T=l-1,S=7,D=0,K=o.getMaskFunction(k),N=l-1;N>0;N-=2)for(N==6&&(N-=1);;){for(var X=0;X<2;X+=1)if(p[T][N-X]==null){var nt=!1;D<w.length&&(nt=(w[D]>>>S&1)==1);var q=K(T,N-X);q&&(nt=!nt),p[T][N-X]=nt,S-=1,S==-1&&(D+=1,S=7)}if(T+=y,T<0||l<=T){T-=y,y=-y;break}}},V=function(w,k){for(var y=0,T=0,S=0,D=new Array(k.length),K=new Array(k.length),N=0;N<k.length;N+=1){var X=k[N].dataCount,nt=k[N].totalCount-X;T=Math.max(T,X),S=Math.max(S,nt),D[N]=new Array(X);for(var q=0;q<D[N].length;q+=1)D[N][q]=255&w.getBuffer()[q+y];y+=X;var gt=o.getErrorCorrectPolynomial(nt),vt=c(D[N],gt.getLength()-1),Dn=vt.mod(gt);K[N]=new Array(gt.getLength()-1);for(var q=0;q<K[N].length;q+=1){var Bn=q+Dn.getLength()-K[N].length;K[N][q]=Bn>=0?Dn.getAt(Bn):0}}for(var Hn=0,q=0;q<k.length;q+=1)Hn+=k[q].totalCount;for(var on=new Array(Hn),Ae=0,q=0;q<T;q+=1)for(var N=0;N<k.length;N+=1)q<D[N].length&&(on[Ae]=D[N][q],Ae+=1);for(var q=0;q<S;q+=1)for(var N=0;N<k.length;N+=1)q<K[N].length&&(on[Ae]=K[N][q],Ae+=1);return on},$t=function(w,k,y){for(var T=g.getRSBlocks(w,k),S=v(),D=0;D<y.length;D+=1){var K=y[D];S.put(K.getMode(),4),S.put(K.getLength(),o.getLengthInBits(K.getMode(),w)),K.write(S)}for(var N=0,D=0;D<T.length;D+=1)N+=T[D].dataCount;if(S.getLengthInBits()>N*8)throw"code length overflow. ("+S.getLengthInBits()+">"+N*8+")";for(S.getLengthInBits()+4<=N*8&&S.put(0,4);S.getLengthInBits()%8!=0;)S.putBit(!1);for(;!(S.getLengthInBits()>=N*8||(S.put(s,8),S.getLengthInBits()>=N*8));)S.put(h,8);return V(S,T)};C.addData=function(w,k){k=k||"Byte";var y=null;switch(k){case"Numeric":y=u(w);break;case"Alphanumeric":y=M(w);break;case"Byte":y=b(w);break;case"Kanji":y=A(w);break;default:throw"mode:"+k}x.push(y),L=null},C.isDark=function(w,k){if(w<0||l<=w||k<0||l<=k)throw w+","+k;return p[w][k]},C.getModuleCount=function(){return l},C.make=function(){if(f<1){for(var w=1;w<40;w++){for(var k=g.getRSBlocks(w,E),y=v(),T=0;T<x.length;T++){var S=x[T];y.put(S.getMode(),4),y.put(S.getLength(),o.getLengthInBits(S.getMode(),w)),S.write(y)}for(var D=0,T=0;T<k.length;T++)D+=k[T].dataCount;if(y.getLengthInBits()<=D*8)break}f=w}R(!1,z())},C.createTableTag=function(w,k){w=w||2,k=typeof k=="undefined"?w*4:k;var y="";y+='<table style="',y+=" border-width: 0px; border-style: none;",y+=" border-collapse: collapse;",y+=" padding: 0px; margin: "+k+"px;",y+='">',y+="<tbody>";for(var T=0;T<C.getModuleCount();T+=1){y+="<tr>";for(var S=0;S<C.getModuleCount();S+=1)y+='<td style="',y+=" border-width: 0px; border-style: none;",y+=" border-collapse: collapse;",y+=" padding: 0px; margin: 0px;",y+=" width: "+w+"px;",y+=" height: "+w+"px;",y+=" background-color: ",y+=C.isDark(T,S)?"#000000":"#ffffff",y+=";",y+='"/>';y+="</tr>"}return y+="</tbody>",y+="</table>",y},C.createSvgTag=function(w,k,y,T){var S={};typeof arguments[0]=="object"&&(S=arguments[0],w=S.cellSize,k=S.margin,y=S.alt,T=S.title),w=w||2,k=typeof k=="undefined"?w*4:k,y=typeof y=="string"?{text:y}:y||{Line truncated
|
||||||
`}return c%2&&u>0?ee.substring(0,ee.length-c-1)+Array(c+1).join("▀"):ee.substring(0,ee.length-1)};return x.createASCII=function(u,p){if(u=u||1,u<2)return q(p);u-=1,p=typeof p=="undefined"?u*2:p;var c=x.getModuleCount()*u+p*2,h=p,w=c-p,A,D,_,G,W=Array(u+1).join("██"),H=Array(u+1).join(" "),X="",ee="";for(A=0;A<c;A+=1){for(_=Math.floor((A-h)/u),ee="",D=0;D<c;D+=1)G=1,h<=D&&D<w&&h<=A&&A<w&&x.isDark(_,Math.floor((D-h)/u))&&(G=0),ee+=G?W:H;for(_=0;_<u;_+=1)X+=ee+`
|
`}return y%2&&w>0?vt.substring(0,vt.length-y-1)+Array(y+1).join("▀"):vt.substring(0,vt.length-1)};return C.createASCII=function(w,k){if(w=w||1,w<2)return rn(k);w-=1,k=typeof k=="undefined"?w*2:k;var y=C.getModuleCount()*w+k*2,T=k,S=y-k,D,K,N,X,nt=Array(w+1).join("██"),q=Array(w+1).join(" "),gt="",vt="";for(D=0;D<y;D+=1){for(N=Math.floor((D-T)/w),vt="",K=0;K<y;K+=1)X=1,T<=K&&K<S&&T<=D&&D<S&&C.isDark(N,Math.floor((K-T)/w))&&(X=0),vt+=X?nt:q;for(N=0;N<w;N+=1)gt+=vt+`
|
||||||
`}return X.substring(0,X.length-1)},x.renderTo2dContext=function(u,p){p=p||2;for(var c=x.getModuleCount(),h=0;h<c;h++)for(var w=0;w<c;w++)u.fillStyle=x.isDark(h,w)?"black":"white",u.fillRect(h*p,w*p,p,p)},x};e.stringToBytesFuncs={default:function(v){for(var y=[],g=0;g<v.length;g+=1){var k=v.charCodeAt(g);y.push(k&255)}return y}},e.stringToBytes=e.stringToBytesFuncs.default,e.createStringToBytes=function(v,y){var g=(function(){for(var d=V(v),M=function(){var F=d.read();if(F==-1)throw"eof";return F},l=0,o={};;){var C=d.read();if(C==-1)break;var f=M(),x=M(),B=M(),N=String.fromCharCode(C<<8|f),I=x<<8|B;o[N]=I,l+=1}if(l!=y)throw l+" != "+y;return o})(),k=63;return function(d){for(var M=[],l=0;l<d.length;l+=1){var o=d.charCodeAt(l);if(o<128)M.push(o);else{var C=g[d.charAt(l)];typeof C=="number"?(C&255)==C?M.push(C):(M.push(C>>>8),M.push(C&255)):M.push(k)}}return M}};var t={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},n={L:1,M:0,Q:3,H:2},a={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},s=(function(){var v=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],y=1335,g=7973,k=21522,d={},M=function(l){for(var o=0;l!=0;)o+=1,l>>>=1;return o};return d.getBCHTypeInfo=function(l){for(var o=l<<10;M(o)-M(y)>=0;)o^=y<<M(o)-M(y);return(l<<10|o)^k},d.getBCHTypeNumber=function(l){for(var o=l<<12;M(o)-M(g)>=0;)o^=g<<M(o)-M(g);return l<<12|o},d.getPatternPosition=function(l){return v[l-1]},d.getMaskFunction=function(l){switch(l){case a.PATTERN000:return function(o,C){return(o+C)%2==0};case a.PATTERN001:return function(o,C){return o%2==0};case a.PATTERN010:return function(o,C){return C%3==0};case a.PATTERN011:return function(o,C){return(o+C)%3==0};case a.PATTERN100:return function(o,C){return(Math.floor(o/2)+Math.floor(C/3))%2==0};case a.PATTERN101:return function(o,C){return o*C%2+o*C%3==0};case a.PATTERN110:return function(o,C){return(o*C%2+o*C%3)%2==0};case a.PATTERN111:return function(o,C){return(o*C%3+(o+C)%2)%2==0};default:throw"bad maskPattern:"+l}},d.getErrorCorrectPolynomial=function(l){for(var o=b([1],0),C=0;C<l;C+=1)o=o.multiply(b([1,i.gexp(C)],0));return o},d.getLengthInBits=function(l,o){if(1<=o&&o<10)switch(l){case t.MODE_NUMBER:return 10;case t.MODE_ALPHA_NUM:return 9;case t.MODE_8BIT_BYTE:return 8;case t.MODE_KANJI:return 8;default:throw"mode:"+l}else if(o<27)switch(l){case t.MODE_NUMBER:return 12;case t.MODE_ALPHA_NUM:return 11;case t.MODE_8BIT_BYTE:return 16;case t.MODE_KANJI:return 10;default:throw"mode:"+l}else if(o<41)switch(l){case t.MODE_NUMBER:return 14;case t.MODE_ALPHA_NUM:return 13;case t.MODE_8BIT_BYTE:return 16;case t.MODE_KANJI:return 12;default:throw"mode:"+l}else throw"type:"+o},d.getLostPoint=function(l){for(var o=l.getModuleCount(),C=0,f=0;f<o;f+=1)for(var x=0;x<o;x+=1){for(var B=0,N=l.isDark(f,x),I=-1;I<=1;I+=1)if(!(f+I<0||o<=f+I))for(var F=-1;F<=1;F+=1)x+F<0||o<=x+F||I==0&&F==0||N==l.isDark(f+I,x+F)&&(B+=1);B>5&&(C+=3+B-5)}for(var f=0;f<o-1;f+=1)for(var x=0;x<o-1;x+=1){var z=0;l.isDark(f,x)&&(z+=1),l.isDark(f+1,x)&&(z+=1),l.isDark(f,x+1)&&(z+=1),l.isDark(f+1,x+1)&&(z+=1),(z==0||z==4)&&(C+=3)}for(var f=0;f<o;f+=1)for(var x=0;x<o-6;x+=1)l.isDark(f,x)&&!l.isDark(f,x+1)&&l.isDark(f,x+2)&&l.isDark(f,x+3)&&l.isDark(f,x+4)&&!l.isDark(f,x+5)&&l.isDark(f,x+6)&&(C+=40);for(var x=0;x<o;x+=1)for(var f=0;f<o-6;f+=1)l.isDark(f,x)&&!l.isDark(f+1,x)&&l.isDark(f+2,x)&&l.isDark(f+3,x)&&l.isDark(f+4,x)&&!l.isDark(f+5,x)&&l.isDark(f+6,x)&&(C+=40);for(var Z=0,x=0;x<o;x+=1)for(var f=0;f<o;f+=1)l.isDark(f,x)&&(Z+=1);var ne=Math.abs(100*Z/o/o-50)/5;return C+=ne*10,C},d})(),i=(function(){for(var v=new Array(256),y=new Array(256),g=0;g<8;g+=1)v[g]=1<<g;for(var g=8;g<256;g+=1)v[g]=v[g-4]^v[g-5]^v[g-6]^v[g-8];for(var g=0;g<255;g+=1)y[v[g]]=g;var k={};return k.glog=function(d){if(d<1)throw"glog("+d+")";return y[d]},k.gexp=function(d){for(;d<0;)d+=255;for(;d>=256;)d-=255;return v[d]},k})();function b(v,y){if(typeof v.length=="undefined")throw v.length+"/"+y;var g=(function(){for(var d=0;d<v.length&&v[d]==0;)d+=1;for(var M=new Array(v.length-d+y),l=0;l<v.length-d;l+=1)M[l]=v[l+d];return M})(),k={};return k.getAt=function(d){return g[d]},k.getLength=function(){return g.length},k.multiply=function(d){for(var M=new Array(k.getLength()+d.getLength()-1),l=0;l<k.getLength();l+=1)for(var o=0;o<d.getLength();o+=1)M[l+o]^=i.gexp(i.glog(k.getAt(l))+i.glog(d.getAt(o)));return b(M,0)},k.mod=function(d){if(k.getL
Line truncated
|
`}return gt.substring(0,gt.length-1)},C.renderTo2dContext=function(w,k){k=k||2;for(var y=C.getModuleCount(),T=0;T<y;T++)for(var S=0;S<y;S++)w.fillStyle=C.isDark(T,S)?"black":"white",w.fillRect(T*k,S*k,k,k)},C};t.stringToBytesFuncs={default:function(d){for(var m=[],s=0;s<d.length;s+=1){var h=d.charCodeAt(s);m.push(h&255)}return m}},t.stringToBytes=t.stringToBytesFuncs.default,t.createStringToBytes=function(d,m){var s=(function(){for(var f=P(d),E=function(){var Q=f.read();if(Q==-1)throw"eof";return Q},p=0,l={};;){var L=f.read();if(L==-1)break;var x=E(),C=E(),R=E(),I=String.fromCharCode(L<<8|x),z=C<<8|R;l[I]=z,p+=1}if(p!=m)throw p+" != "+m;return l})(),h=63;return function(f){for(var E=[],p=0;p<f.length;p+=1){var l=f.charCodeAt(p);if(l<128)E.push(l);else{var L=s[f.charAt(p)];typeof L=="number"?(L&255)==L?E.push(L):(E.push(L>>>8),E.push(L&255)):E.push(h)}}return E}};var e={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},n={L:1,M:0,Q:3,H:2},r={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},o=(function(){var d=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],m=1335,s=7973,h=21522,f={},E=function(p){for(var l=0;p!=0;)l+=1,p>>>=1;return l};return f.getBCHTypeInfo=function(p){for(var l=p<<10;E(l)-E(m)>=0;)l^=m<<E(l)-E(m);return(p<<10|l)^h},f.getBCHTypeNumber=function(p){for(var l=p<<12;E(l)-E(s)>=0;)l^=s<<E(l)-E(s);return p<<12|l},f.getPatternPosition=function(p){return d[p-1]},f.getMaskFunction=function(p){switch(p){case r.PATTERN000:return function(l,L){return(l+L)%2==0};case r.PATTERN001:return function(l,L){return l%2==0};case r.PATTERN010:return function(l,L){return L%3==0};case r.PATTERN011:return function(l,L){return(l+L)%3==0};case r.PATTERN100:return function(l,L){return(Math.floor(l/2)+Math.floor(L/3))%2==0};case r.PATTERN101:return function(l,L){return l*L%2+l*L%3==0};case r.PATTERN110:return function(l,L){return(l*L%2+l*L%3)%2==0};case r.PATTERN111:return function(l,L){return(l*L%3+(l+L)%2)%2==0};default:throw"bad maskPattern:"+p}},f.getErrorCorrectPolynomial=function(p){for(var l=c([1],0),L=0;L<p;L+=1)l=l.multiply(c([1,a.gexp(L)],0));return l},f.getLengthInBits=function(p,l){if(1<=l&&l<10)switch(p){case e.MODE_NUMBER:return 10;case e.MODE_ALPHA_NUM:return 9;case e.MODE_8BIT_BYTE:return 8;case e.MODE_KANJI:return 8;default:throw"mode:"+p}else if(l<27)switch(p){case e.MODE_NUMBER:return 12;case e.MODE_ALPHA_NUM:return 11;case e.MODE_8BIT_BYTE:return 16;case e.MODE_KANJI:return 10;default:throw"mode:"+p}else if(l<41)switch(p){case e.MODE_NUMBER:return 14;case e.MODE_ALPHA_NUM:return 13;case e.MODE_8BIT_BYTE:return 16;case e.MODE_KANJI:return 12;default:throw"mode:"+p}else throw"type:"+l},f.getLostPoint=function(p){for(var l=p.getModuleCount(),L=0,x=0;x<l;x+=1)for(var C=0;C<l;C+=1){for(var R=0,I=p.isDark(x,C),z=-1;z<=1;z+=1)if(!(x+z<0||l<=x+z))for(var Q=-1;Q<=1;Q+=1)C+Q<0||l<=C+Q||z==0&&Q==0||I==p.isDark(x+z,C+Q)&&(R+=1);R>5&&(L+=3+R-5)}for(var x=0;x<l-1;x+=1)for(var C=0;C<l-1;C+=1){var et=0;p.isDark(x,C)&&(et+=1),p.isDark(x+1,C)&&(et+=1),p.isDark(x,C+1)&&(et+=1),p.isDark(x+1,C+1)&&(et+=1),(et==0||et==4)&&(L+=3)}for(var x=0;x<l;x+=1)for(var C=0;C<l-6;C+=1)p.isDark(x,C)&&!p.isDark(x,C+1)&&p.isDark(x,C+2)&&p.isDark(x,C+3)&&p.isDark(x,C+4)&&!p.isDark(x,C+5)&&p.isDark(x,C+6)&&(L+=40);for(var C=0;C<l;C+=1)for(var x=0;x<l-6;x+=1)p.isDark(x,C)&&!p.isDark(x+1,C)&&p.isDark(x+2,C)&&p.isDark(x+3,C)&&p.isDark(x+4,C)&&!p.isDark(x+5,C)&&p.isDark(x+6,C)&&(L+=40);for(var ot=0,C=0;C<l;C+=1)for(var x=0;x<l;x+=1)p.isDark(x,C)&&(ot+=1);var it=Math.abs(100*ot/l/l-50)/5;return L+=it*10,L},f})(),a=(function(){for(var d=new Array(256),m=new Array(256),s=0;s<8;s+=1)d[s]=1<<s;for(var s=8;s<256;s+=1)d[s]=d[s-4]^d[s-5]^d[s-6]^d[s-8];for(var s=0;s<255;s+=1)m[d[s]]=s;var h={};return h.glog=function(f){if(f<1)throw"glog("+f+")";return m[f]},h.gexp=function(f){for(;f<0;)f+=255;for(;f>=256;)f-=255;return d[f]},h})();function c(d,m){if(typeof d.length=="undefined")throw d.length+"/"+m;var s=(function(){for(var f=0;f<d.length&&d[f]==0;)f+=1;for(var E=new Array(d.length-f+m),p=0;p<d.length-f;p+=1)E[p]=d[p+f];return E})(),h={};return h.getAt=function(f){return s[f]},h.getLength=function(){return s.length},h.multiply=function(f){for(var E=new Array(h.getLength()+f.getLength()-1),p=0;p<h.getLength();p+=1)for(var l=0;l<f.getLength();l+=1)E[p+l]^=a.gexp(a.glog(h.getAt(p))+a.glog(f.getAt(l)));return c(E,0)},h.mod=function(
Line truncated
|
||||||
`),hostName:i,mtu:n.mtu,persistent_keep_alive:n.persistent_keep_alive,port:Number(n.port),psk_key:n.psk_key,server_pub_key:n.server_pub_key},m={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(b),port:String(n.port),protocol_version:a.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:t,hostName:i};return n.dns[0]&&(m.dns1=n.dns[0]),n.dns[1]&&(m.dns2=n.dns[1]),m}function Un(e){let t="";for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function Wn(e){let t=globalThis;if(typeof t.CompressionStream=="undefined")return null;try{let n=new t.Blob([e]).stream().pipeThrough(new t.CompressionStream("deflate")),a=new Uint8Array(await new t.Response(n).arrayBuffer()),s=new Uint8Array(4+a.length);return new DataView(s.buffer).setUint32(0,e.length,!1),s.set(a,4),s}catch{return null}}async function Lt(e,t,n=!0){let a=new TextEncoder().encode(JSON.stringify(zn(e,t))),s=n?await Wn(a):null;return`vpn://${Un(s!=null?s:a)}`}var Tt=e=>e.replace(/^vpn:\/\//,"");function r(e,t={},...n){let a=document.createElement(e);for(let[i,b]of Object.entries(t))b==null||b===!1||(i.startsWith("on")&&typeof b=="function"?a.addEventListener(i.slice(2),b):i==="class"?a.className=String(b):b===!0?a.setAttribute(i,""):a.setAttribute(i,String(b)));let s=i=>{i==null||i===!1||(Array.isArray(i)?i.forEach(s):a.appendChild(typeof i=="string"?document.createTextNode(i):i))};return n.forEach(s),a}function R(e){let t=r("span",{class:"ic"});return t.innerHTML=He(e,"ic-svg"),t}var se=()=>typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches,re={out:"cubic-bezier(0.23, 1, 0.32, 1)",in:"cubic-bezier(0.55, 0, 1, 0.45)",drawer:"cubic-bezier(0.32, 0.72, 0, 1)"};function At(e){var n;let t=e.closest(".sheet-panel");return t?(t.dataset.hold=String(+((n=t.dataset.hold)!=null?n:0)+1),()=>{var s;let a=+((s=t.dataset.hold)!=null?s:1)-1;a>0?t.dataset.hold=String(a):delete t.dataset.hold}):()=>{}}function Yn(e,t){return e<=0||t<=0?0:(1-1/(e*.55/t+1))*t}function Vn(e,t,n){return e<=0||t<-.1?!1:t>.4||e>n/3}var Et=e=>Math.round(Math.min(380,Math.max(220,200+e*.35)));function ae(e,t){e.classList.remove(t),e.offsetWidth,e.classList.add(t)}function $t(e,t){let n=0,a=0,s=!1,i=null,b=new ResizeObserver(()=>{if(e.dataset.hold){i==null||i.cancel(),e.classList.remove("morphing","morphing-w"),n=e.offsetHeight,a=e.offsetWidth;return}let m=getComputedStyle(e),L=i?parseFloat(m.height):n,T=i?parseFloat(m.width):a;i==null||i.cancel(),e.classList.remove("morphing","morphing-w");let E=e.offsetHeight,P=e.offsetWidth,K=e.dataset.morph==="width"||s;delete e.dataset.morph;let O=a!==0&&P!==a;if(n=E,a=P,!L||se()||O&&!K)return;let U=Math.abs(E-L),V=K?Math.abs(P-T):0;if(U<2&&V<2)return;s=V>=2,e.classList.add("morphing"),e.classList.toggle("morphing-w",s);let j=e.animate(s?[{height:`${L}px`,width:`${T}px`},{height:`${E}px`,width:`${P}px`}]:[{height:`${L}px`},{height:`${E}px`}],{duration:Et(Math.max(U,V)),easing:re.out});i=j;let Q=()=>{i===j&&(i=null,s=!1,e.classList.remove("morphing","morphing-w"))};j.onfinish=Q,j.oncancel=Q});return b.observe(t),()=>b.disconnect()}function _t(e,t,n=0){let a=[...e.childNodes];if(!a.length||!e.isConnected){e.replaceChildren(...t);return}let s=getComputedStyle(e),i=document.createElement("div");i.className="ghost",i.setAttribute("aria-hidden","true"),i.inert=!0,Object.assign(i.style,{display:s.display==="flex"?"flex":"block",flexDirection:s.flexDirection,alignItems:s.alignItems,gap:s.gap,top:s.paddingTop,left:s.paddingLeft,right:s.paddingRight}),i.append(...a),e.replaceChildren(i,...t);let b=se(),m=i.animate([{opacity:1,transform:"none"},{opacity:0,transform:b?"none":`translateX(${-n*8}px)`}],{duration:120,easing:re.out,fill:"forwards"}),L=()=>i.remove();m.onfinish=L,m.oncancel=L;for(let T of t)T instanceof HTMLElement&&T.animate(b?[{opacity:0},{opacity:1}]:[{opacity:0,transform:`translate(${n*12}px, ${n?0:6}px)`,filter:"blur(4px)"},{opacity:1,transform:"none",filter:"blur(0)"}],{duration:b?160:280,delay:50,easing:re.out,fill:"backwards"})}function St(e){return!e||!e.isConnected?Promise.resolve():e.animate(se()?[{opacity:1},{opacity:0}]:[{opacity:1,transform:"none",filter:"blur(0)"},{opacity:0,transform:"scale(0.96)",filter:"blur(4px)"}],{duration:200,easing:re.in,fill:"forwards"}).finished.then(()=>{},()=>{})}var Pt=e=>new Promise(t=>setTimeout(t,se()?0:e)),Ce={ms:520,contentMs:300,blur:4,drift:6,scale:.98};async function Dt(e){if(!e.isConnected)return;let t=At(e),n=parseFloat(getComputedStyle(e.parentElement).rowGap)||0,a=e.offsetHeight;e.style.overflow="hidden",e.style.transformOrigin="50% 0",e.inert=!0;let s=()=>{};se()?await e.animate([{opacity:1},{opacity:0}],{duration:160,easing:re.out,fill:"forwards"}).finished.then(s,s):(e.animate([{opacity:1,filter:"blur(0px)",transform:"none"},{opacity:0,filter:`blur(${Ce.blur}px)`,transform:`tr
Line truncated
|
`),hostName:a,mtu:n.mtu,persistent_keep_alive:n.persistent_keep_alive,port:Number(n.port),psk_key:n.psk_key,server_pub_key:n.server_pub_key},g={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(c),port:String(n.port),protocol_version:r.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:e,hostName:a};return n.dns[0]&&(g.dns1=n.dns[0]),n.dns[1]&&(g.dns2=n.dns[1]),g}function bi(t){let e="";for(let n=0;n<t.length;n+=32768)e+=String.fromCharCode(...t.subarray(n,n+32768));return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function wi(t){let e=globalThis;if(typeof e.CompressionStream=="undefined")return null;try{let n=new e.Blob([t]).stream().pipeThrough(new e.CompressionStream("deflate")),r=new Uint8Array(await new e.Response(n).arrayBuffer()),o=new Uint8Array(4+r.length);return new DataView(o.buffer).setUint32(0,t.length,!1),o.set(r,4),o}catch{return null}}async function Ln(t,e,n=!0){let r=new TextEncoder().encode(JSON.stringify(xi(t,e))),o=n?await wi(r):null;return`vpn://${bi(o!=null?o:r)}`}var Zr=t=>t.replace(/^vpn:\/\//,"");var to=["height","marginTop","marginBottom","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius"];function qt(t,e={}){let n=i("div",{class:`acc${e.inset?" inset":""}`}),r=t.map((u,M)=>{var $;let b=u.body.filter(d=>!!d),A=!b.length,O=[u.icon,i("span",{class:"acc-title"},i("span",{class:"t"},u.title),($=u.tag)!=null?$:null),u.val?i("span",{class:`acc-val${u.valHide?" hide-open":""}`},u.val):null],B=M===e.open&&!A,P=A?i("div",{class:"acc-head"},...O):i("button",{type:"button",class:"acc-head","aria-expanded":String(B),onclick:()=>v(H)},...O,F("chevron","i acc-chev")),H=i("div",{class:`acc-row${A?" still":""}${B?" open":""}`},P,i("div",{class:"acc-body"},...b));return n.appendChild(H),H}),o=u=>u.querySelector(".acc-body"),a=()=>r.forEach((u,M)=>{let b=u.classList.contains("open");u.classList.toggle("rt",M===0||b||r[M-1].classList.contains("open")),u.classList.toggle("rb",M===r.length-1||b||r[M+1].classList.contains("open"))}),c=u=>{let M=getComputedStyle(u),b={};for(let A of to)b[A]=A==="height"?`${u.getBoundingClientRect().height}px`:M[A];return b},g=()=>r.forEach(u=>{var M;return(M=u.querySelector("button.acc-head"))==null?void 0:M.setAttribute("aria-expanded",String(u.classList.contains("open")))});function v(u){var B;let M=r.map(c);r.forEach(P=>P.getAnimations().forEach(H=>H.cancel())),r.forEach(P=>o(P).getAnimations().forEach(H=>H.cancel()));let b=!u.classList.contains("open"),A=r.filter(P=>P.classList.contains("open")&&(P===u||b));r.forEach(P=>{P.classList.remove("closing"),P!==u&&P.classList.remove("open")}),u.classList.toggle("open",b),a();let O=ce();r.forEach((P,H)=>{let $=c(P);to.some(d=>M[H][d]!==$[d])&&(A.includes(P)&&P.classList.add("closing"),_(P,[M[H],$],{duration:Et.duration,easing:Et.easing}).onfinish=()=>P.classList.remove("closing"))}),A.forEach(P=>_(o(P),[{opacity:1},{opacity:0,filter:"blur(2px)"}],{duration:160,easing:J,fill:"forwards"})),b&&_(o(u),[{opacity:0,filter:"blur(2px)"},{opacity:1,filter:"blur(0px)"}],{duration:300,easing:"cubic-bezier(0,0,.58,1)"}),de(O),g(),(B=e.onToggle)==null||B.call(e,r.indexOf(u),b,!1)}return a(),{el:n,openIndex:()=>r.findIndex(u=>u.classList.contains("open")),setOpen(u){r.forEach((M,b)=>M.classList.toggle("open",b===u&&!M.classList.contains("still"))),a(),g(),r.forEach((M,b)=>{var A;return(A=e.onToggle)==null?void 0:A.call(e,b,M.classList.contains("open"),!0)})}}}function eo(t,e,n){let r=i("span",{class:"seg-pill"}),o=i("div",{class:"seg appseg",role:"tablist"},r),a=t.map(A=>{let O=i("button",{type:"button",class:"seg-b",role:"tab","aria-label":A.label,title:A.label,onclick:()=>b(A.value)},F(A.icon),i("span",{class:"seg-l"},A.label));return O.dataset.v=A.value,o.appendChild(O),O}),c=A=>A.querySelector(".seg-l"),g=()=>a.forEach(A=>{let O=A.dataset.v===e;A.classList.toggle("on",O),A.setAttribute("aria-selected",String(O))}),v=()=>{let A=a.find(O=>O.dataset.v===e);return A&&A.offsetWidth?[A.offsetLeft,o.clientWidth-A.offsetLeft-A.offsetWidth]:null},u=()=>{let A=v();A&&(r.style.left=`${A[0]}px`,r.style.right=`${A[1]}px`)},M=0;function b(A){if(A===e)return;let O=a.findIndex(C=>C.dataset.v===e),B=a.findIndex(C=>C.dataset.v===A),P=getComputedStyle(r),H=parseFloat(P.left)||0,$=parseFloat(P.right)||0,d=a.map(C=>parseFloat(getComputedStyle(C).flexGrow)||0),m=c(a[O]),s=m.getBoundingClientRect().width;[...a,...a.map(c)].forEach(C=>C.getAnimations().forEach(R=>R.cancel())),e=A,g(),a.forEach((C,R)=>{let I=R===B?1:0;d[R]!==I&&_(C,[{flexGrow:d[R]},{flexGrow:I}],{duration:U.duration,easing:U.easing})}),_(m,[{opacity:1,maxWidth:`${s}px`,marginLeft:"0px"},{opacity:0,maxWidth:"0px",marginLeft:"-8px"}],{duration:220,easing:"ease-out"}),_(c(a[B]),[{opacity:0,filter:"blur(4px)"},{opacity:1,filter:"none"}],{duration:280,delay:70,easing:Y,fill:"backwards"});let h=B>O,f=Lt()?U:Fn,E=performance.now(),p=Math.m
Line truncated
|
||||||
`).flatMap((b,m)=>m?[`
|
`).flatMap((u,M)=>M?[`
|
||||||
`,sn(b,t)]:[sn(b,t)])),i&&n.querySelectorAll(".conf-v, .conf-mask").forEach(b=>b.classList.add("unmask"))},s=r("button",{class:"btn small",onclick:i=>{i.preventDefault(),t=!t,s.replaceChildren(R(t?"x":"key"),r("span",{},t?"Hide key":"Show key")),ae(s,"swap"),a(!0)}},R("key"),r("span",{},"Show key"));return a(),r("div",{class:"pane"},r("div",{class:"filecard"},r("span",{class:"filecard-ic"},".conf"),r("span",{class:"stack"},r("span",{class:"mono ellipsis"},e.filename),r("span",{class:"faint s"},xn()?"For computers and routers: import it in any WireGuard app":"For computers and routers: import it in AmneziaWG or AmneziaVPN")),Ie(e.filename,e.conf)?r("button",{class:"btn primary",onclick:()=>Ie(e.filename,e.conf)()},R("open"),r("span",{},"Share file")):r("button",{class:"btn primary",onclick:()=>st(e.filename,e.conf)},R("download"),r("span",{},"Download"))),r("details",{class:"confbox"},r("summary",{},R("chevron"),r("span",{},"Configuration"),r("span",{class:"grow"}),s,r("button",{class:"btn small",onclick:i=>{i.preventDefault(),ge(e.conf,"Configuration copied",i.currentTarget)}},R("copy"),r("span",{},"Copy"))),n))}async function hr(e,t){var n;e.connected(),(n=e.el.closest(".sheet-panel"))==null||n.scrollTo({top:0,behavior:se()?"auto":"smooth"}),await Pt(400),await Promise.all(t.map(a=>Dt(a))),await new Promise(a=>setTimeout(a,2e3)),te!=null&&te.contains(e.el)&&!e.el.closest(".ghost")&&ue()}function Tn(e,t=4){window.setTimeout(async()=>{var n;try{let a=await fe("state");S=a,!te&&!me&&Me(a),!((n=a.person.devices.find(s=>s.id===e))!=null&&n.online)&&t>1&&Tn(e,t-1)}catch{}},1500)}function gr(e,t,n){let a=pn(),s=0,i=0,b=!1,m=Date.now(),L=async()=>{if(s=0,!b){if(Date.now()-m>6e5){b=!0,n();return}if(document.hidden){T();return}try{let P=await fe("state");S=P;let K=P.person.devices.find(O=>O.id===e.id);if(K&&K.handshake>a){b=!0,t(),K.online||Tn(e.id);return}}catch(P){if(P.status===404||P.status===401){b=!0;return}}i++,T()}},T=()=>{!b&&!s&&(s=window.setTimeout(L,i<6?5e3:i<12?15e3:3e4))},E=()=>{!document.hidden&&!b&&!s&&L()};return document.addEventListener("visibilitychange",E),T(),()=>{b=!0,s&&clearTimeout(s),document.removeEventListener("visibilitychange",E)}}var An=e=>`dl.app.${e.id}`;function mr(e){try{let t=localStorage.getItem(An(e));return t==="vpn"||t==="awg"||t==="wg"?t:null}catch{return null}}function vr(e,t){try{localStorage.setItem(An(e),t)}catch{}}var on={vpn:"amnezia",awg:"amneziawg",wg:"wireguard"},yr={ios:"apple",android:"googleplay",windows:"windows",mac:"apple",linux:"linux",unknown:"other"};function le(e,t=!1,n){var i;let a=[r("span",{class:"badge-ic"},R(e.mark)),r("span",{class:"badge-txt"},r("span",{class:"badge-top"},e.top),r("span",{class:"badge-main"},e.main)),r("span",{class:"badge-chev"},R("chevron"))],s=`badge${t?" primary":""}`;return e.onclick?r("button",{type:"button",class:s,onclick:e.onclick,"data-m":n},a):r("a",{class:s,href:e.href,target:(i=e.href)!=null&&i.startsWith("vpn:")?null:"_blank",rel:"noopener noreferrer","data-m":n},a)}function ln(e,t){return r("div",{class:"pills"},t.map(n=>r("button",{type:"button",class:`pill${n.on?" on":""}`,onclick:n.pick,"data-m":`${e}:${n.id}`},n.icon?R(n.icon):null,r("span",{},n.label))))}var we=(e,t,...n)=>r("div",{class:"step"},r("div",{class:"step-head"},r("span",{class:"step-n"},e),r("span",{class:"step-title"},t)),...n);function wr(e){let t=typeof navigator.share=="function";return r("div",{class:"linkrow"},r("span",{class:"mono ellipsis"},e.replace(/^https?:\/\//,"")),r("button",{type:"button",class:"btn small",onclick:n=>ge(e,"Link copied",n.currentTarget)},"Copy"),t?r("button",{type:"button",class:"icon-btn soft","aria-label":"Share the link",onclick:()=>{var n;return navigator.share({url:e,title:(n=S==null?void 0:S.title)!=null?n:"Dawnline"}).catch(()=>{})}},R("share")):null)}async function Ke(e,t){var $e;let n=t!=null?t:await pr(e);if(!n)return;let a=await Lt(n,n.server),s=Yt(ur()),i=bn(),b=e.kind==="phone"||e.kind==="tablet",m=e.kind==="router",L=i==="ios"||i==="android",T=Wt(e.kind),E=($e=mr(e))!=null?$e:m?"awg":"vpn";s.some($=>$.id===E)||(E=m?"awg":"vpn");let P=T.length?T.includes(i)?i:"windows":i,K=Ut(e.kind,i),O=()=>T.length?P===i:K,U=()=>b||P==="ios"||P==="android",V=!1,j=!1,Q="app",v=null,y=r("div",{class:"setup"}),g=Gt(e.kind),k=en(e.kind),d=!1,M=$=>{var q;return(q=s.find(u=>u.id===$))!=null?q:s[0]},l=()=>ln("app",s.filter($=>!m||$.id!=="vpn").map($=>({id:$.id,label:$.name,icon:on[$.id],on:$.id===E,pick:()=>{E=$.id,vr(e,E),Y()}}))),o=()=>ln("os",T.map($=>({id:$,label:$===i?tn($):Xe[$],icon:yr[$],on:$===P,pick:()=>{P=$,Y()}}))),C=()=>{let $=m?Je(E):Vt(E,P);return $?[$.alt?[r("div",{class:"badges2"},le($,!1,"store"),le($.alt,!1,"store-alt")),r("span",{class:"faint s"},$.alt.why)]:le($,!1,"store"),ke(M(E))?r("span",{class:"faint s","data-m":"update"},ke(M(E))):null]:[r("span",{class:"muted s"},`Get ${oe[E]} on the ${Xe[P]} and come back here.`)]},f=()=>we("1",[r("span",{class:"grow","data-m":"get"},`Get ${oe[E]}`),s.length>1&&!V?r("b
Line truncated
|
`,ro(u,e)]:[ro(u,e)]));r();let o=!!Wt(t.filename,t.conf),a=i("button",{type:"button",class:"btn soft sm",onclick:()=>{e=!e,a.replaceChildren(F(e?"x":"key"),i("span",{},e?"Hide key":"Show key")),r(),n.querySelectorAll(".mask, .k").forEach(u=>_(u,[{filter:"blur(4px)",opacity:.4},{filter:"none",opacity:1}],{duration:320,easing:Y}))}},F("key"),i("span",{},"Show key")),c=i("button",{type:"button",class:"btn soft sm",onclick:u=>pt(t.conf,"Configuration copied",u.currentTarget)},F("copy"),i("span",{class:"lbl"},"Copy")),g=i("div",{class:"filecard"},i("div",{class:"fc-row"},i("span",{class:"filecard-ic"},".conf"),i("span",{class:"t"},i("span",{class:"mono"},t.filename),i("span",{},"For computers and routers"))),i("button",{type:"button",class:"btn accent sm block",onclick:()=>ye(t.filename,t.conf)},F(o?"open":"download"),i("span",{},o?"Share file":"Download"))),v=qt([{icon:j("file"),title:"Configuration",body:[i("div",{class:"confbar"},a,c),n]}],{inset:!0});return i("div",{class:"step-box"},g,v.el)}function fo(t){let e=i("span",{class:"osm-p"},at[t]),n=Dr(me(t,"ios"),me(t,"android"));return{el:i("span",{class:"scanline"},i("span",{},"In ",e,":"),n.el),set(r){Z(e,at[r],void 0,{whole:!0}),n.set(me(r,"ios"),me(r,"android"))}}}function ho(t){let e=i("span",{class:"tt"}),n=i("span",{class:"tt-m"}),r=i("span",{class:"hp-tip","aria-hidden":"true"},e,n),o=i("button",{type:"button",class:"hp-b",onclick:()=>ye(t().file,t().text)},F("download")),a=i("button",{type:"button",class:"hp-b"},F("copy")),c=i("div",{class:"hpill",role:"group","aria-label":"The connection","data-key":"conn"},o,a,r),g=null,v=0,u=0,M=s=>{var h;return s===a&&a.classList.contains("done")?"Copied":(h=s.getAttribute("aria-label"))!=null?h:""},b=(s,h)=>{n.textContent=h;let f=n.offsetWidth+20;return Math.min(s.offsetLeft+s.offsetWidth/2,c.offsetWidth+46-f/2)},A=s=>`translateX(${s}px) translateX(-50%)`,O=s=>{let h=getComputedStyle(r).transform;r.getAnimations().forEach(f=>f.cancel()),r.style.transform=A(s),_(r,[{transform:h},{transform:A(s)}],{duration:U.duration,easing:U.easing})},B=s=>Z(e,s),P=s=>{if(clearTimeout(v),g===s&&r.classList.contains("on"))return;if(g=s,r.classList.contains("on")){let f=M(s);return O(b(s,f)),B(f)}let h=()=>{let f=M(s);bt(e,f);let E=b(s,f);r.getAnimations().forEach(p=>p.cancel()),r.style.transform=A(E),r.classList.add("on"),_(r,[{opacity:0,transform:`${A(E)} translateY(-3px) scale(.96)`,filter:"blur(3px)"},{opacity:1,transform:A(E),filter:"blur(0px)"}],{duration:220,easing:Y})};performance.now()<u?h():v=window.setTimeout(h,420)},H=()=>{clearTimeout(v),g=null,r.classList.contains("on")&&(u=performance.now()+500,r.classList.remove("on"),_(r,[{opacity:1},{opacity:0}],{duration:120,easing:"ease-out"}))};for(let s of[o,a])s.addEventListener("pointerenter",h=>{h.pointerType==="mouse"&&P(s)}),s.addEventListener("focus",()=>{s.matches(":focus-visible")&&P(s)}),s.addEventListener("blur",H);c.addEventListener("pointerleave",H);let $=s=>{let h=F(s);a.querySelector("svg").replaceWith(h),_(h,[{opacity:0,transform:"scale(.6)",filter:"blur(3px)"},{opacity:1,transform:"none",filter:"none"}],{duration:yt.duration,easing:yt.easing})},d=()=>{if(g!==a||!r.classList.contains("on"))return;let s=M(a);O(b(a,s)),B(s)},m=0;return a.addEventListener("click",()=>{let s=t();pt(s.text,s.msg),clearTimeout(m),a.classList.contains("done")||(a.classList.add("done"),$("check"),d()),m=window.setTimeout(()=>{a.classList.remove("done"),$("copy"),d()},1600)}),{el:c,sync(){let s=t().app;o.setAttribute("aria-label",`Download ${s} config`),a.setAttribute("aria-label",`Copy ${s} config`)}}}function go(t){let e=i("b",{},"Waiting for the connection"),n=i("span",{class:"ws",hidden:!0}),r=i("div",{class:"way",role:"status","aria-live":"polite"},i("div",{class:"way-row"},i("span",{class:"way-end"},F(t.kind)),i("span",{class:"way-track"},i("span",{class:"way-glow"},i("i")),i("span",{class:"way-fill"})),i("span",{class:"way-end home"},F("server"))),i("div",{class:"way-text"},i("span",{class:"t"},e,n)));return{el:r,connected(){r.classList.add("done"),Z(e,`${t.name} connected`)},gaveUp(){r.classList.add("stopped"),Z(e,"No connection yet"),n.textContent="Close this and open it again to keep checking.",n.hidden=!1,_(e.parentElement,[{opacity:0,filter:"blur(4px)"},{opacity:1,filter:"none"}],{duration:280,easing:Y})}}}function vo(t,e=4){window.setTimeout(async()=>{var n;try{let r=await ut("state");xt(r),be()||Mt(),!((n=r.person.devices.find(o=>o.id===t))!=null&&n.online)&&e>1&&vo(t,e-1)}catch{}},1500)}function yo(t,e,n){let r=te(),o=0,a=0,c=!1,g=Date.now(),v=async()=>{if(o=0,!c){if(Date.now()-g>6e5){c=!0,n();return}if(document.hidden)return u();try{let b=await ut("state");xt(b);let A=b.person.devices.find(O=>O.id===t.id);if(A&&A.handshake>r){c=!0,e(),A.online||vo(t.id);return}}catch(b){if(Oe(b)){c=!0;return}}a++,u()}},u=()=>{!c&&!o&&(o=window.setTimeout(v,a<6?5e3:a<12?15e3:3e4))},M=()=>{!document.hidden&&!c&&!o&&v()};return document.addEventListener("visibilitychange",M),u(),()=>{c=!0,o
Line truncated
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import { readfile, stat, unlink } from 'fs';
|
import { readfile, stat, unlink } from 'fs';
|
||||||
import {
|
import {
|
||||||
q, sh, sh_out, rand_int, rand_bytes, valid_key, ip2int, translit, ensure_dir, write_file, read_json, write_json, lock, unlock,
|
q, sh, sh_out, rand_int, rand_bytes, valid_key, ip2int, tunnel_name, ensure_dir, write_file, read_json, write_json, lock, unlock,
|
||||||
slog, iface_status, DATA_DIR, RUN_DIR
|
slog, iface_status, DATA_DIR, RUN_DIR
|
||||||
} from 'dawnline.util';
|
} from 'dawnline.util';
|
||||||
import * as core from 'dawnline.core';
|
import * as core from 'dawnline.core';
|
||||||
@@ -336,25 +336,6 @@ export function obf_neutral(o) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* The .conf file name doubles as the tunnel name in WireGuard apps (15
|
|
||||||
* characters at most): the device first, so a person's devices stay apart,
|
|
||||||
* and a number when the cut would still make two of them alike.
|
|
||||||
*/
|
|
||||||
function conf_filename(m, p, dev) {
|
|
||||||
let label = (d) => trim(substr(trim(replace(lc(translit(d.name + '-' + p.id)), /[^a-z0-9]+/g, '-'), '-'), 0, 15), '-');
|
|
||||||
let order = sort(map(p.devices, (id) => m.devices[id]),
|
|
||||||
(a, b) => (a.created - b.created) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
||||||
let seen = {};
|
|
||||||
for (let d in order) {
|
|
||||||
let l = label(d);
|
|
||||||
let n = seen[l] = (seen[l] ?? 0) + 1;
|
|
||||||
if (d.id == dev.id)
|
|
||||||
return (n > 1 ? trim(substr(l, 0, 15 - length(`-${n}`)), '-') + `-${n}` : l) + '.conf';
|
|
||||||
}
|
|
||||||
return label(dev) + '.conf';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The junk a device sends is its own: within the preset's own ranges, the
|
* The junk a device sends is its own: within the preset's own ranges, the
|
||||||
* count and sizes are shifted a little by the device (deterministic, so the
|
* count and sizes are shifted a little by the device (deterministic, so the
|
||||||
@@ -423,7 +404,8 @@ export function client_config(m, dev) {
|
|||||||
name: dev.name,
|
name: dev.name,
|
||||||
person: p.name,
|
person: p.name,
|
||||||
server: srv.name,
|
server: srv.name,
|
||||||
filename: conf_filename(m, p, dev),
|
// The file name is the tunnel's name in WireGuard apps: the server's, in the portal and the admin alike.
|
||||||
|
filename: `${tunnel_name(srv.name)}.conf`,
|
||||||
conf: join('\n', lines) + '\n',
|
conf: join('\n', lines) + '\n',
|
||||||
has_private_key: dev.private_key != '',
|
has_private_key: dev.private_key != '',
|
||||||
amnezia: {
|
amnezia: {
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ export function load(c) {
|
|||||||
portal_alt: g('portal_alt'),
|
portal_alt: g('portal_alt'),
|
||||||
portal_cert: g('portal_cert'),
|
portal_cert: g('portal_cert'),
|
||||||
portal_key: g('portal_key'),
|
portal_key: g('portal_key'),
|
||||||
portal_title: g('portal_title'),
|
|
||||||
// Where unknown portal links go instead of a bare 404 (empty = 404).
|
// Where unknown portal links go instead of a bare 404 (empty = 404).
|
||||||
portal_redirect: g('portal_redirect'),
|
portal_redirect: g('portal_redirect'),
|
||||||
default_device_limit: g('default_device_limit'),
|
default_device_limit: g('default_device_limit'),
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ export function uhttpd() {
|
|||||||
store.transact((w, m) => w.delete('dawnline', 'settings', 'portal_443'));
|
store.transact((w, m) => w.delete('dawnline', 'settings', 'portal_443'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** The portal names itself after the server now (the breadcrumb, the tab): its own title setting is gone. */
|
||||||
|
function portal_title() {
|
||||||
|
let c = cursor();
|
||||||
|
c.load('dawnline');
|
||||||
|
if (c.get('dawnline', 'settings', 'portal_title') != null)
|
||||||
|
store.transact((w, m) => w.delete('dawnline', 'settings', 'portal_title'));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Steps that cannot tell from the config whether they ran are recorded in
|
* Steps that cannot tell from the config whether they ran are recorded in
|
||||||
* `settings.migrated` (a list), so they run exactly once.
|
* `settings.migrated` (a list), so they run exactly once.
|
||||||
@@ -101,4 +109,5 @@ export function run() {
|
|||||||
word_codes();
|
word_codes();
|
||||||
uhttpd();
|
uhttpd();
|
||||||
auto_mtu();
|
auto_mtu();
|
||||||
|
portal_title();
|
||||||
};
|
};
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
// that answers anything not shaped like a link (its not_found() twin).
|
// that answers anything not shaped like a link (its not_found() twin).
|
||||||
|
|
||||||
import { stat, readfile } from 'fs';
|
import { stat, readfile } from 'fs';
|
||||||
import { read_json, write_json, ensure_dir, lock, unlock, cloudflare_ip, ip2int, today, tunnel_name, VERSION, RUN_DIR } from 'dawnline.util';
|
import { read_json, write_json, ensure_dir, lock, unlock, cloudflare_ip, ip2int, today, VERSION, RUN_DIR } from 'dawnline.util';
|
||||||
import * as core from 'dawnline.core';
|
import * as core from 'dawnline.core';
|
||||||
import * as awg from 'dawnline.awg';
|
import * as awg from 'dawnline.awg';
|
||||||
import * as live from 'dawnline.live';
|
import * as live from 'dawnline.live';
|
||||||
@@ -64,8 +64,8 @@ const NOT_READY = "Adding devices isn't available right now: the VPN server isn'
|
|||||||
|
|
||||||
// States the admin stopped the person in: the portal only shows, it changes nothing.
|
// States the admin stopped the person in: the portal only shows, it changes nothing.
|
||||||
const LOCKED = {
|
const LOCKED = {
|
||||||
paused: 'Your access is paused by the admin.',
|
paused: 'Your access is paused.',
|
||||||
expired: 'Your access has ended. Ask the admin to extend it.',
|
expired: 'Your access has ended.',
|
||||||
};
|
};
|
||||||
|
|
||||||
function html_escape(s) {
|
function html_escape(s) {
|
||||||
@@ -241,11 +241,16 @@ function rate_action(r) {
|
|||||||
|
|
||||||
/* ---------- pages ---------- */
|
/* ---------- pages ---------- */
|
||||||
|
|
||||||
|
/** What the page is called (the tab, the first crumb): the person's server, or Dawnline. */
|
||||||
|
function place(r) {
|
||||||
|
return r.person ? r.m.servers[r.person.server]?.name || 'Dawnline' : 'Dawnline';
|
||||||
|
}
|
||||||
|
|
||||||
/** The app shell; it reads the code from its own URL and sends it along. */
|
/** The app shell; it reads the code from its own URL and sends it along. */
|
||||||
function shell(r) {
|
function shell(r) {
|
||||||
// The build's time joins the version so every update busts the hour-long asset cache.
|
// The build's time joins the version so every update busts the hour-long asset cache.
|
||||||
let v = `?v=${VERSION}.${stat(`${ASSETS}/portal.js`)?.mtime ?? 0}`;
|
let v = `?v=${VERSION}.${stat(`${ASSETS}/portal.js`)?.mtime ?? 0}`;
|
||||||
let base = r.base, title = r.title;
|
let base = r.base, title = place(r);
|
||||||
headers(r, '200 OK', {
|
headers(r, '200 OK', {
|
||||||
'Content-Type': 'text/html; charset=utf-8',
|
'Content-Type': 'text/html; charset=utf-8',
|
||||||
'Content-Security-Policy': "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data: blob:; font-src 'self'; " +
|
'Content-Security-Policy': "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data: blob:; font-src 'self'; " +
|
||||||
@@ -338,17 +343,24 @@ function need_https(r) {
|
|||||||
send_json(r, '403 Forbidden', { error: 'Open this link over HTTPS to get the connection settings.', https_url: u });
|
send_json(r, '403 Forbidden', { error: 'Open this link over HTTPS to get the connection settings.', https_url: u });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The router's offset from UTC in minutes: the admin sets hours in its time, the page shows the visitor's. */
|
||||||
|
function tz_offset() {
|
||||||
|
let t = time();
|
||||||
|
return int((timegm(localtime(t)) - t) / 60);
|
||||||
|
}
|
||||||
|
|
||||||
/** Everything the page shows. */
|
/** Everything the page shows. */
|
||||||
function state(r) {
|
function state(r) {
|
||||||
let m = r.m, person = r.person;
|
let m = r.m, person = r.person;
|
||||||
let usage = core.load_usage();
|
let usage = core.load_usage();
|
||||||
let v = view.person_view(m, person, usage, live.dump(m), view.states(m, usage));
|
let v = view.person_view(m, person, usage, live.dump(m), view.states(m, usage));
|
||||||
v.state = person_state(m, person, usage);
|
v.state = person_state(m, person, usage);
|
||||||
|
// Day by day this month, for the page's chart (the admin's views have no use for it).
|
||||||
|
v.month_days = view.month_days(usage.people?.[person.id]);
|
||||||
let srv = m.servers[person.server];
|
let srv = m.servers[person.server];
|
||||||
// The device this page was opened from, through the tunnel or beside it.
|
// The device this page was opened from, through the tunnel or beside it.
|
||||||
let here = view.device_here(v.devices, r.peer);
|
let here = view.device_here(v.devices, r.peer);
|
||||||
return {
|
return {
|
||||||
title: r.title,
|
|
||||||
person: v,
|
person: v,
|
||||||
here,
|
here,
|
||||||
server: {
|
server: {
|
||||||
@@ -367,6 +379,8 @@ function state(r) {
|
|||||||
today: today(),
|
today: today(),
|
||||||
// Its clock too: "last connected 3 min ago" is measured against it, not the phone's.
|
// Its clock too: "last connected 3 min ago" is measured against it, not the phone's.
|
||||||
now: time(),
|
now: time(),
|
||||||
|
// And its time zone: hours are set in the router's time, shown in the visitor's.
|
||||||
|
tz_offset: tz_offset(),
|
||||||
version: VERSION,
|
version: VERSION,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -383,15 +397,6 @@ function api_state(r) {
|
|||||||
send_json(r, '200 OK', state(r));
|
send_json(r, '200 OK', state(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A configuration as the person gets it: the file, and so the tunnel the apps
|
|
||||||
* name after it, is the server's name. The admin's downloads keep the device
|
|
||||||
* in the name: one browser fetches many of them.
|
|
||||||
*/
|
|
||||||
function own_config(c) {
|
|
||||||
return c ? { ...c, filename: `${tunnel_name(c.server)}.conf` } : c;
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_add(r) {
|
function api_add(r) {
|
||||||
need_open(r);
|
need_open(r);
|
||||||
need_https(r);
|
need_https(r);
|
||||||
@@ -401,7 +406,7 @@ function api_add(r) {
|
|||||||
rate_action(r);
|
rate_action(r);
|
||||||
let res = guard(r, () => devices.add(r.person.id, b.name, b.kind, { by: 'portal', public_key: b.public_key }));
|
let res = guard(r, () => devices.add(r.person.id, b.name, b.kind, { by: 'portal', public_key: b.public_key }));
|
||||||
reload(r);
|
reload(r);
|
||||||
send_json(r, '200 OK', { id: res.id, config: own_config(res.config), state: state(r) });
|
send_json(r, '200 OK', { id: res.id, config: res.config, state: state(r) });
|
||||||
}
|
}
|
||||||
|
|
||||||
function api_config(r, id) {
|
function api_config(r, id) {
|
||||||
@@ -409,7 +414,7 @@ function api_config(r, id) {
|
|||||||
need_open(r);
|
need_open(r);
|
||||||
need_https(r);
|
need_https(r);
|
||||||
awg.mark_issued(r.m, d.id);
|
awg.mark_issued(r.m, d.id);
|
||||||
send_json(r, '200 OK', own_config(awg.client_config(r.m, d)));
|
send_json(r, '200 OK', awg.client_config(r.m, d));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** POST /devices/<id> { action }: what each action does; the answer carries the new state. */
|
/** POST /devices/<id> { action }: what each action does; the answer carries the new state. */
|
||||||
@@ -424,7 +429,7 @@ const ACTIONS = {
|
|||||||
if (!devices.ready())
|
if (!devices.ready())
|
||||||
fail(r, '503 Service Unavailable', NOT_READY);
|
fail(r, '503 Service Unavailable', NOT_READY);
|
||||||
let config = guard(r, () => devices.reconnect(d.id, { by: 'portal', person: r.person.id, defer: d.address == r.peer }));
|
let config = guard(r, () => devices.reconnect(d.id, { by: 'portal', person: r.person.id, defer: d.address == r.peer }));
|
||||||
return { config: own_config(config) };
|
return { config };
|
||||||
},
|
},
|
||||||
'delete': (r, d, b) => {
|
'delete': (r, d, b) => {
|
||||||
guard(r, () => devices.remove(d.id, { by: 'portal', person: r.person.id }));
|
guard(r, () => devices.remove(d.id, { by: 'portal', person: r.person.id }));
|
||||||
@@ -490,7 +495,6 @@ export function handle(io) {
|
|||||||
method: env.REQUEST_METHOD ?? 'GET',
|
method: env.REQUEST_METHOD ?? 'GET',
|
||||||
peer: env.REMOTE_ADDR ?? '',
|
peer: env.REMOTE_ADDR ?? '',
|
||||||
buckets: buckets(env),
|
buckets: buckets(env),
|
||||||
title: m.settings.portal_title || 'Dawnline',
|
|
||||||
// The port in the visitor's address bar ([v6]:port, name:port, or the default).
|
// The port in the visitor's address bar ([v6]:port, name:port, or the default).
|
||||||
hsts: https && (match(host, /:([0-9]+)$/)?.[1] ?? '443') == '443',
|
hsts: https && (match(host, /:([0-9]+)$/)?.[1] ?? '443') == '443',
|
||||||
person: null,
|
person: null,
|
||||||
|
|||||||
@@ -107,9 +107,9 @@ export function to_int(v, dflt, lo, hi) {
|
|||||||
/* ---------- the settings section ---------- */
|
/* ---------- the settings section ---------- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* type: bool | int | enum | host | hosts | url | file | domain | ipv4 | time | text | targets
|
* type: bool | int | enum | host | hosts | url | file | domain | ipv4 | time | targets
|
||||||
* dflt: the parsed default; restart: the portal (uhttpd) must restart when it changes;
|
* dflt: the parsed default; restart: the portal (uhttpd) must restart when it changes;
|
||||||
* min/max: ints and text length; values: enums; msg: the error for a bad value.
|
* min/max: ints; values: enums; msg: the error for a bad value.
|
||||||
*/
|
*/
|
||||||
export const SETTINGS = {
|
export const SETTINGS = {
|
||||||
portal_enabled: { type: 'bool', dflt: false, restart: true },
|
portal_enabled: { type: 'bool', dflt: false, restart: true },
|
||||||
@@ -117,7 +117,6 @@ export const SETTINGS = {
|
|||||||
portal_alt: { type: 'hosts', dflt: [], restart: true, msg: 'Other addresses must be hostnames or IP addresses.' },
|
portal_alt: { type: 'hosts', dflt: [], restart: true, msg: 'Other addresses must be hostnames or IP addresses.' },
|
||||||
portal_port: { type: 'int', dflt: 8443, min: 1, max: 65535, restart: true,
|
portal_port: { type: 'int', dflt: 8443, min: 1, max: 65535, restart: true,
|
||||||
msg: 'Choose a free port between 1 and 65535 (not 22, 53, 80 or 443).' },
|
msg: 'Choose a free port between 1 and 65535 (not 22, 53, 80 or 443).' },
|
||||||
portal_title: { type: 'text', dflt: 'Dawnline', max: 64, msg: 'Portal title: up to 64 characters on one line.' },
|
|
||||||
portal_redirect: { type: 'url', dflt: '', msg: 'Redirect must be a full http:// or https:// address.' },
|
portal_redirect: { type: 'url', dflt: '', msg: 'Redirect must be a full http:// or https:// address.' },
|
||||||
portal_cert: { type: 'file', dflt: '', restart: true },
|
portal_cert: { type: 'file', dflt: '', restart: true },
|
||||||
portal_key: { type: 'file', dflt: '', restart: true },
|
portal_key: { type: 'file', dflt: '', restart: true },
|
||||||
@@ -226,10 +225,6 @@ export function validate(key, val) {
|
|||||||
if (!match(val, /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/))
|
if (!match(val, /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/))
|
||||||
bad(spec, key);
|
bad(spec, key);
|
||||||
}
|
}
|
||||||
else if (t == 'text') {
|
|
||||||
if (ulength(val) > spec.max || match(val, /[[:cntrl:]]/))
|
|
||||||
bad(spec, key);
|
|
||||||
}
|
|
||||||
return val;
|
return val;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs';
|
import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs';
|
||||||
|
|
||||||
export const VERSION = '0.9.0';
|
export const VERSION = '0.10.0';
|
||||||
/** GitHub repository with Dawnline releases (updates and the installer). */
|
/** GitHub repository with Dawnline releases (updates and the installer). */
|
||||||
export const REPO = 'tickcount/luci-app-dawnline';
|
export const REPO = 'tickcount/luci-app-dawnline';
|
||||||
export const RUN_DIR = '/var/run/dawnline';
|
export const RUN_DIR = '/var/run/dawnline';
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ export function spark(rec, n) {
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Daily totals (rx+tx) from the 1st of this month to today, oldest first (the portal's month chart). */
|
||||||
|
export function month_days(rec) {
|
||||||
|
return spark(rec, +substr(day_key_ago(0), 8, 2));
|
||||||
|
};
|
||||||
|
|
||||||
/** The device holds an older configuration than the one it would get now. */
|
/** The device holds an older configuration than the one it would get now. */
|
||||||
function config_stale(m, d) {
|
function config_stale(m, d) {
|
||||||
m._issued ??= awg.issued();
|
m._issued ??= awg.issued();
|
||||||
|
|||||||
@@ -10,11 +10,13 @@
|
|||||||
//
|
//
|
||||||
// scripts/capture-screenshots.mjs [--router https://router.lan] [--person id]
|
// scripts/capture-screenshots.mjs [--router https://router.lan] [--person id]
|
||||||
// [--mask real=shown ...] [--name real=shown ...]
|
// [--mask real=shown ...] [--name real=shown ...]
|
||||||
// [--only overview,people]
|
// [--only overview,people] [--demo]
|
||||||
//
|
//
|
||||||
// --mask replaces text on every page before the capture (a domain, a name);
|
// --mask replaces text on every page before the capture (a domain, a name);
|
||||||
// --name does the same for a person's name in any case, and for their initials.
|
// --name does the same for a person's name in any case, and for their initials.
|
||||||
// Public IPv4 addresses are always swapped for documentation ones (203.0.113.x).
|
// Public IPv4 addresses are always swapped for documentation ones (203.0.113.x).
|
||||||
|
// --demo shows a made-up cast instead of the router's people (scripts/screenshot-demo.mjs):
|
||||||
|
// the router's answers are rewritten in the headless browser on their way to the page.
|
||||||
|
|
||||||
import { execFileSync, spawn } from 'node:child_process';
|
import { execFileSync, spawn } from 'node:child_process';
|
||||||
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||||
@@ -22,12 +24,20 @@ import { tmpdir } from 'node:os';
|
|||||||
import { dirname, join, resolve } from 'node:path';
|
import { dirname, join, resolve } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { createInterface } from 'node:readline';
|
import { createInterface } from 'node:readline';
|
||||||
|
import { demoRpc } from './screenshot-demo.mjs';
|
||||||
|
|
||||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||||
const RAW = join(ROOT, 'docs', 'screenshots', 'raw');
|
const RAW = join(ROOT, 'docs', 'screenshots', 'raw');
|
||||||
const SCALE = 2;
|
const SCALE = 2;
|
||||||
|
|
||||||
const args = { router: 'https://outline.lan', person: '', mask: [], names: [], only: [] };
|
const args = {
|
||||||
|
router: 'https://outline.lan',
|
||||||
|
person: '',
|
||||||
|
mask: [],
|
||||||
|
names: [],
|
||||||
|
only: [],
|
||||||
|
demo: false,
|
||||||
|
};
|
||||||
for (let i = 2; i < process.argv.length; i++) {
|
for (let i = 2; i < process.argv.length; i++) {
|
||||||
const a = process.argv[i];
|
const a = process.argv[i];
|
||||||
const v = () => process.argv[++i] ?? die(`${a} needs a value`);
|
const v = () => process.argv[++i] ?? die(`${a} needs a value`);
|
||||||
@@ -36,6 +46,7 @@ for (let i = 2; i < process.argv.length; i++) {
|
|||||||
else if (a === '--mask') args.mask.push(v().split('=', 2));
|
else if (a === '--mask') args.mask.push(v().split('=', 2));
|
||||||
else if (a === '--name') args.names.push(v().split('=', 2));
|
else if (a === '--name') args.names.push(v().split('=', 2));
|
||||||
else if (a === '--only') args.only = v().split(',');
|
else if (a === '--only') args.only = v().split(',');
|
||||||
|
else if (a === '--demo') args.demo = true;
|
||||||
else die(`unknown argument ${a}`);
|
else die(`unknown argument ${a}`);
|
||||||
}
|
}
|
||||||
if ([...args.mask, ...args.names].some((m) => m.length !== 2 || !m[0])) die('--mask and --name take real=shown');
|
if ([...args.mask, ...args.names].some((m) => m.length !== 2 || !m[0])) die('--mask and --name take real=shown');
|
||||||
@@ -100,31 +111,26 @@ const SHOTS = [
|
|||||||
url: (s) => `${LUCI}/person?id=${encodeURIComponent(s.person)}`,
|
url: (s) => `${LUCI}/person?id=${encodeURIComponent(s.person)}`,
|
||||||
width: 1400,
|
width: 1400,
|
||||||
ready: '.dl-grid-person .dl-row',
|
ready: '.dl-grid-person .dl-row',
|
||||||
// Down to the end of Access & limits; activity rows that would be cut are hidden.
|
// Where they connected from, on the map.
|
||||||
|
prep: `(() => {
|
||||||
|
const b = [...document.querySelectorAll('.dl-grid-person button')].find((x) => x.textContent.trim() === 'Show map');
|
||||||
|
b?.click();
|
||||||
|
})()`,
|
||||||
|
settle: 6000,
|
||||||
|
// Down to the end of Access & limits or of the map, whichever is lower; activity rows that would be cut are hidden.
|
||||||
clip: `(() => {
|
clip: `(() => {
|
||||||
const c = ${column}, cut = document.querySelector('.dl-grid-person > .dl-col:last-child').getBoundingClientRect().bottom + 40;
|
const c = ${column}, cols = document.querySelectorAll('.dl-grid-person > .dl-col');
|
||||||
|
const places = cols[0].children[2];
|
||||||
|
const cut = Math.max(cols[1].getBoundingClientRect().bottom, places ? places.getBoundingClientRect().bottom : 0) + 40;
|
||||||
document.querySelectorAll('.dl-grid-person .dl-row').forEach((r) => {
|
document.querySelectorAll('.dl-grid-person .dl-row').forEach((r) => {
|
||||||
if (r.getBoundingClientRect().bottom > cut - 8) r.style.visibility = 'hidden';
|
if (r.getBoundingClientRect().bottom > cut - 8) r.style.visibility = 'hidden';
|
||||||
});
|
});
|
||||||
|
// Activity that would start right at the cut goes too, its heading with it.
|
||||||
|
const act = cols[0].children[3];
|
||||||
|
if (act && act.getBoundingClientRect().top > cut - 120) act.style.visibility = 'hidden';
|
||||||
return { x: c.x, y: 0, width: c.w, height: cut };
|
return { x: c.x, y: 0, width: c.w, height: cut };
|
||||||
})()`,
|
})()`,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'access',
|
|
||||||
url: () => `${LUCI}/server?section=access`,
|
|
||||||
width: 1400,
|
|
||||||
ready: 'section.dl-ifcard details',
|
|
||||||
// The home network card alone, its folded lists closed.
|
|
||||||
prep: `(() => {
|
|
||||||
const card = [...document.querySelectorAll('section.dl-ifcard')].find((s) => s.querySelector('details'));
|
|
||||||
card.querySelectorAll('details[open]').forEach((d) => (d.open = false));
|
|
||||||
card.setAttribute('data-shot', '');
|
|
||||||
})()`,
|
|
||||||
clip: `(() => {
|
|
||||||
const r = document.querySelector('[data-shot]').getBoundingClientRect();
|
|
||||||
return { x: r.left - 12, y: r.top - 12, width: r.width + 24, height: r.height + 24 };
|
|
||||||
})()`,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'portal',
|
name: 'portal',
|
||||||
url: (s) => s.portal,
|
url: (s) => s.portal,
|
||||||
@@ -156,7 +162,17 @@ const MASK = `((pairs, inits) => {
|
|||||||
if (!doc.has(m)) doc.set(m, '203.0.113.' + (24 + doc.size));
|
if (!doc.has(m)) doc.set(m, '203.0.113.' + (24 + doc.size));
|
||||||
return doc.get(m);
|
return doc.get(m);
|
||||||
};
|
};
|
||||||
const swap = (s) => pairs.reduce((t, [a, b]) => t.split(a).join(b), s).replace(/\\b\\d{1,3}(?:\\.\\d{1,3}){3}\\b/g, ip);
|
// IPv6 too, unless link-local or private (fe80::, fc00::/7).
|
||||||
|
const ip6 = (m) => {
|
||||||
|
if (/^(fe8|fe9|fea|feb|fc|fd)/i.test(m)) return m;
|
||||||
|
if (!doc.has(m)) doc.set(m, '2001:db8::' + (24 + doc.size));
|
||||||
|
return doc.get(m);
|
||||||
|
};
|
||||||
|
const swap = (s) =>
|
||||||
|
pairs
|
||||||
|
.reduce((t, [a, b]) => t.split(a).join(b), s)
|
||||||
|
.replace(/\\b\\d{1,3}(?:\\.\\d{1,3}){3}\\b/g, ip)
|
||||||
|
.replace(/\\b(?:[0-9a-f]{1,4}:){3,7}[0-9a-f]{1,4}\\b/gi, ip6);
|
||||||
const w = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
const w = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
||||||
for (let n; (n = w.nextNode()); ) {
|
for (let n; (n = w.nextNode()); ) {
|
||||||
const ini = inits.find(([a]) => n.nodeValue.trim() === a);
|
const ini = inits.find(([a]) => n.nodeValue.trim() === a);
|
||||||
@@ -203,6 +219,7 @@ async function connect(wsUrl) {
|
|||||||
let id = 0;
|
let id = 0;
|
||||||
const pending = new Map();
|
const pending = new Map();
|
||||||
const waiters = [];
|
const waiters = [];
|
||||||
|
const listeners = [];
|
||||||
ws.onmessage = (m) => {
|
ws.onmessage = (m) => {
|
||||||
const msg = JSON.parse(m.data);
|
const msg = JSON.parse(m.data);
|
||||||
if (msg.id && pending.has(msg.id)) {
|
if (msg.id && pending.has(msg.id)) {
|
||||||
@@ -210,6 +227,7 @@ async function connect(wsUrl) {
|
|||||||
pending.delete(msg.id);
|
pending.delete(msg.id);
|
||||||
msg.error ? fail(new Error(msg.error.message)) : ok(msg.result);
|
msg.error ? fail(new Error(msg.error.message)) : ok(msg.result);
|
||||||
} else if (msg.method) {
|
} else if (msg.method) {
|
||||||
|
for (const l of listeners.filter((x) => x.method === msg.method)) l.fn(msg.params);
|
||||||
for (const w of waiters.filter((x) => x.method === msg.method)) {
|
for (const w of waiters.filter((x) => x.method === msg.method)) {
|
||||||
waiters.splice(waiters.indexOf(w), 1);
|
waiters.splice(waiters.indexOf(w), 1);
|
||||||
w.ok(msg.params);
|
w.ok(msg.params);
|
||||||
@@ -222,7 +240,8 @@ async function connect(wsUrl) {
|
|||||||
ws.send(JSON.stringify({ id, method, params }));
|
ws.send(JSON.stringify({ id, method, params }));
|
||||||
});
|
});
|
||||||
const waitFor = (method) => new Promise((ok) => waiters.push({ method, ok }));
|
const waitFor = (method) => new Promise((ok) => waiters.push({ method, ok }));
|
||||||
return { send, waitFor, close: () => ws.close() };
|
const on = (method, fn) => listeners.push({ method, fn });
|
||||||
|
return { send, waitFor, on, close: () => ws.close() };
|
||||||
}
|
}
|
||||||
|
|
||||||
const sleep = (ms) => new Promise((ok) => setTimeout(ok, ms));
|
const sleep = (ms) => new Promise((ok) => setTimeout(ok, ms));
|
||||||
@@ -255,10 +274,40 @@ async function main() {
|
|||||||
const pages = await (await fetch(`http://127.0.0.1:${port}/json/list`)).json();
|
const pages = await (await fetch(`http://127.0.0.1:${port}/json/list`)).json();
|
||||||
const page = await connect(pages.find((p) => p.type === 'page').webSocketDebuggerUrl);
|
const page = await connect(pages.find((p) => p.type === 'page').webSocketDebuggerUrl);
|
||||||
await page.send('Page.enable');
|
await page.send('Page.enable');
|
||||||
await page.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: 'dark' }] });
|
await page.send('Emulation.setEmulatedMedia', {
|
||||||
|
features: [{ name: 'prefers-color-scheme', value: 'dark' }],
|
||||||
|
});
|
||||||
|
// The person shown on the Person page; known once People has loaded (or from --person).
|
||||||
|
const s = { person: args.person, portal: '' };
|
||||||
|
if (args.demo) {
|
||||||
|
page.on('Fetch.requestPaused', async (e) => {
|
||||||
|
try {
|
||||||
|
const r = await page.send('Fetch.getResponseBody', {
|
||||||
|
requestId: e.requestId,
|
||||||
|
});
|
||||||
|
const body = r.base64Encoded ? Buffer.from(r.body, 'base64').toString('utf8') : r.body;
|
||||||
|
const out = demoRpc(e.request.postData ?? '', body, s.person);
|
||||||
|
await page.send('Fetch.fulfillRequest', {
|
||||||
|
requestId: e.requestId,
|
||||||
|
responseCode: e.responseStatusCode ?? 200,
|
||||||
|
responseHeaders: e.responseHeaders ?? [],
|
||||||
|
body: Buffer.from(out, 'utf8').toString('base64'),
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
await page.send('Fetch.continueRequest', { requestId: e.requestId }).catch(() => {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await page.send('Fetch.enable', {
|
||||||
|
patterns: [{ urlPattern: '*ubus*', requestStage: 'Response' }],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const evaluate = async (expression) => {
|
const evaluate = async (expression) => {
|
||||||
const r = await page.send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true });
|
const r = await page.send('Runtime.evaluate', {
|
||||||
|
expression,
|
||||||
|
awaitPromise: true,
|
||||||
|
returnByValue: true,
|
||||||
|
});
|
||||||
if (r.exceptionDetails) throw new Error(r.exceptionDetails.exception?.description ?? r.exceptionDetails.text);
|
if (r.exceptionDetails) throw new Error(r.exceptionDetails.exception?.description ?? r.exceptionDetails.text);
|
||||||
return r.result.value;
|
return r.result.value;
|
||||||
};
|
};
|
||||||
@@ -276,7 +325,12 @@ async function main() {
|
|||||||
};
|
};
|
||||||
// A tall window: Outline scrolls #maincontent, not the page, so it must hold everything.
|
// A tall window: Outline scrolls #maincontent, not the page, so it must hold everything.
|
||||||
const viewport = (width, height = 2600) =>
|
const viewport = (width, height = 2600) =>
|
||||||
page.send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: SCALE, mobile: false });
|
page.send('Emulation.setDeviceMetricsOverride', {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
deviceScaleFactor: SCALE,
|
||||||
|
mobile: false,
|
||||||
|
});
|
||||||
|
|
||||||
await viewport(1400);
|
await viewport(1400);
|
||||||
await go(`${args.router}/cgi-bin/luci/`);
|
await go(`${args.router}/cgi-bin/luci/`);
|
||||||
@@ -297,13 +351,10 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The person to show (the first one on People unless --person) and their personal link.
|
// The person to show (the first one on People unless --person) and their personal link.
|
||||||
const s = { person: args.person, portal: '' };
|
|
||||||
await go(`${LUCI}/server?section=people`);
|
await go(`${LUCI}/server?section=people`);
|
||||||
await waitSel('.dl-srvbody a[href*="dawnline/person"]');
|
await waitSel('.dl-srvbody a[href*="dawnline/person"]');
|
||||||
if (!s.person)
|
if (!s.person)
|
||||||
s.person = await evaluate(
|
s.person = await evaluate(`new URL(document.querySelector('.dl-srvbody a[href*="dawnline/person"]').href).searchParams.get('id')`);
|
||||||
`new URL(document.querySelector('.dl-srvbody a[href*="dawnline/person"]').href).searchParams.get('id')`,
|
|
||||||
);
|
|
||||||
s.portal = await evaluate(`L.require('rpc').then((rpc) =>
|
s.portal = await evaluate(`L.require('rpc').then((rpc) =>
|
||||||
rpc.declare({ object: 'luci.dawnline', method: 'person_links', params: ['id'] })(${JSON.stringify(s.person)}))
|
rpc.declare({ object: 'luci.dawnline', method: 'person_links', params: ['id'] })(${JSON.stringify(s.person)}))
|
||||||
.then((r) => r.link ?? r.links?.[0] ?? '')`);
|
.then((r) => r.link ?? r.links?.[0] ?? '')`);
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""Put the README screenshots into a browser window on a dawn gradient.
|
"""Frame the README screenshots the way the portal draws its own surfaces.
|
||||||
|
|
||||||
Raw captures live in docs/screenshots/raw/<name>.png at SCALE device pixels
|
Raw captures live in docs/screenshots/raw/<name>.png at SCALE device pixels
|
||||||
per CSS pixel (scripts/capture-screenshots.mjs takes them); the framed images
|
per CSS pixel (scripts/capture-screenshots.mjs takes them); the framed images
|
||||||
are written to docs/screenshots/<name>.png at the same scale. Needs a
|
are written to docs/screenshots/<name>.png at the same scale. Each page sits on
|
||||||
|
a panel like the portal's sheets (#121212, radius 36, 16px around it, the page
|
||||||
|
inside at radius 20) on the portal's own black. A shot in FLOWS gets its steps
|
||||||
|
in a row in front of the page's lower edge, numbered: sheets captured alone on
|
||||||
|
a transparent page (raw/<step>.png, FLOW_MARGIN around each). Needs a
|
||||||
Chromium-based browser for the headless render (BROWSER=/path/to/chrome,
|
Chromium-based browser for the headless render (BROWSER=/path/to/chrome,
|
||||||
default: Brave or Chrome on macOS).
|
default: Brave or Chrome on macOS).
|
||||||
Run: scripts/frame-screenshots.py
|
Run: scripts/frame-screenshots.py [name ...] (all of them when no name is given)
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
@@ -18,16 +22,18 @@ import tempfile
|
|||||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||||
RAW = os.path.join(ROOT, 'docs', 'screenshots', 'raw')
|
RAW = os.path.join(ROOT, 'docs', 'screenshots', 'raw')
|
||||||
OUT = os.path.join(ROOT, 'docs', 'screenshots')
|
OUT = os.path.join(ROOT, 'docs', 'screenshots')
|
||||||
|
FONT = os.path.join(ROOT, 'package', 'luci-app-dawnline', 'root', 'usr', 'share', 'dawnline', 'portal', 'assets',
|
||||||
|
'geist-latin-wght-normal.woff2')
|
||||||
|
|
||||||
# name -> what the address bar shows
|
SHOTS = ['overview', 'people', 'person', 'portal']
|
||||||
SHOTS = {
|
# name -> the steps in front of its page, in order (raw captures). Taken with demo data, not on a router:
|
||||||
'overview': 'router.lan · Dawnline',
|
# adding a device there would add one.
|
||||||
'people': 'router.lan · Dawnline · People',
|
FLOWS = {
|
||||||
'person': 'router.lan · Dawnline · Myata',
|
'portal': ['portal-add-1', 'portal-add-2', 'portal-add-3'],
|
||||||
'portal': 'vpn.example.com/kamiro-telosu-bavine',
|
|
||||||
'access': 'router.lan · Dawnline · Home · Access',
|
|
||||||
}
|
}
|
||||||
PAD_X, PAD_Y, BAR = 120, 96, 40
|
PAD_X, PAD_Y, INSET = 96, 80, 16 # canvas around the panel; panel around the page
|
||||||
|
FLOW_MARGIN = (56, 40, 56, 72) # around a step's sheet in its capture: left, top, right, bottom
|
||||||
|
STEP_GAP, STEP_OVER, STEP_PAD = 28, 150, 120 # between steps; how far they reach over the page; canvas beside them
|
||||||
SCALE = 2
|
SCALE = 2
|
||||||
|
|
||||||
CANDIDATES = [
|
CANDIDATES = [
|
||||||
@@ -39,26 +45,18 @@ CANDIDATES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
TEMPLATE = """<!doctype html><html><head><meta charset="utf-8"><style>
|
TEMPLATE = """<!doctype html><html><head><meta charset="utf-8"><style>
|
||||||
|
@font-face{{font-family:Geist;src:url('file://{font}') format('woff2');font-weight:100 900}}
|
||||||
html,body{{margin:0;width:{w}px;height:{h}px;overflow:hidden}}
|
html,body{{margin:0;width:{w}px;height:{h}px;overflow:hidden}}
|
||||||
body{{display:flex;align-items:center;justify-content:center;
|
body{{position:relative;background:#080808}}
|
||||||
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
|
.panel{{position:absolute;left:{px}px;top:{py}px;width:{pw}px;height:{ph}px;
|
||||||
background:
|
border-radius:36px;background:#121212;box-shadow:inset 0 0 0 1px rgba(255,255,255,.05),0 30px 80px rgba(0,0,0,.5)}}
|
||||||
radial-gradient({gw}px {gh}px at 50% 118%, rgba(255,140,70,.55), rgba(255,140,70,0) 70%),
|
.page{{position:absolute;left:{x}px;top:{y}px;width:{iw}px;height:{ih}px;display:block;border-radius:20px;
|
||||||
radial-gradient({gw2}px {gh2}px at 50% 100%, rgba(250,90,120,.30), rgba(250,90,120,0) 70%),
|
box-shadow:0 0 0 1px rgba(255,255,255,.04)}}
|
||||||
linear-gradient(180deg,#070a14 0%,#0c1226 55%,#1a1430 100%)}}
|
.sheet{{position:absolute;display:block;filter:drop-shadow(0 24px 48px rgba(0,0,0,.6))}}
|
||||||
.win{{width:{iw}px;border-radius:14px;overflow:hidden;background:#000;
|
.n{{position:absolute;width:34px;height:34px;border-radius:50%;display:grid;place-items:center;
|
||||||
box-shadow:0 0 0 1px rgba(255,255,255,.08),0 40px 120px rgba(0,0,0,.65),0 10px 30px rgba(0,0,0,.4)}}
|
font:600 16px Geist,sans-serif;color:#ededed;background:#232323;
|
||||||
.bar{{height:{bar}px;background:#15171c;display:flex;align-items:center;gap:8px;padding:0 16px;
|
box-shadow:0 0 0 1px rgba(255,255,255,.12),0 6px 16px rgba(0,0,0,.5)}}
|
||||||
border-bottom:1px solid rgba(255,255,255,.06);position:relative}}
|
</style></head><body><div class="panel"></div><img class="page" src="file://{src}">{steps}</body></html>"""
|
||||||
.dot{{width:12px;height:12px;border-radius:50%}}
|
|
||||||
.url{{position:absolute;left:50%;transform:translateX(-50%);height:24px;padding:0 14px;border-radius:7px;
|
|
||||||
background:#0d0f13;color:#8b8f98;font-size:13px;display:flex;align-items:center;gap:6px;white-space:nowrap}}
|
|
||||||
.url svg{{width:11px;height:11px;fill:none;stroke:#8b8f98;stroke-width:2}}
|
|
||||||
img{{display:block;width:{iw}px;height:{ih}px}}
|
|
||||||
</style></head><body><div class="win"><div class="bar">
|
|
||||||
<span class="dot" style="background:#ff5f57"></span><span class="dot" style="background:#febc2e"></span><span class="dot" style="background:#28c840"></span>
|
|
||||||
<span class="url"><svg viewBox="0 0 24 24"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/></svg>{url}</span>
|
|
||||||
</div><img src="file://{src}"></div></body></html>"""
|
|
||||||
|
|
||||||
|
|
||||||
def png_size(path):
|
def png_size(path):
|
||||||
@@ -67,22 +65,53 @@ def png_size(path):
|
|||||||
return struct.unpack('>II', head[16:24])
|
return struct.unpack('>II', head[16:24])
|
||||||
|
|
||||||
|
|
||||||
|
def layout(iw, ih, flow):
|
||||||
|
"""Where the page goes and its steps in a row in front of its lower edge: (width, height, page x, page y, steps)."""
|
||||||
|
w, h = iw + 2 * (INSET + PAD_X), ih + 2 * (INSET + PAD_Y)
|
||||||
|
x, y = PAD_X + INSET, PAD_Y + INSET
|
||||||
|
if not flow:
|
||||||
|
return w, h, x, y, ''
|
||||||
|
ml, mt, mr, mb = FLOW_MARGIN
|
||||||
|
sizes = [tuple(v // SCALE for v in png_size(src)) for src in flow]
|
||||||
|
row = sum(pw - ml - mr for pw, _ in sizes) + STEP_GAP * (len(sizes) - 1)
|
||||||
|
w = max(w, row + 2 * STEP_PAD)
|
||||||
|
x = (w - iw) // 2
|
||||||
|
top = y + ih - STEP_OVER
|
||||||
|
h = top + max(ph - mt - mb for _, ph in sizes) + PAD_Y
|
||||||
|
out, sx = [], (w - row) // 2
|
||||||
|
for i, (src, (pw, ph)) in enumerate(zip(flow, sizes)):
|
||||||
|
out.append(f'<img class="sheet" src="file://{src}" style="left:{sx - ml}px;top:{top - mt}px;width:{pw}px;height:{ph}px">')
|
||||||
|
out.append(f'<span class="n" style="left:{sx - 14}px;top:{top - 14}px">{i + 1}</span>')
|
||||||
|
sx += pw - ml - mr + STEP_GAP
|
||||||
|
return w, h, x, y, ''.join(out)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
browser = next((b for b in CANDIDATES if b and os.path.exists(b)), None)
|
browser = next((b for b in CANDIDATES if b and os.path.exists(b)), None)
|
||||||
if not browser:
|
if not browser:
|
||||||
sys.exit('No Chromium-based browser found; set BROWSER=/path/to/chrome')
|
sys.exit('No Chromium-based browser found; set BROWSER=/path/to/chrome')
|
||||||
|
only = sys.argv[1:]
|
||||||
|
unknown = [n for n in only if n not in SHOTS]
|
||||||
|
if unknown:
|
||||||
|
sys.exit(f'unknown screenshot {", ".join(unknown)} (one of {", ".join(SHOTS)})')
|
||||||
tmp = tempfile.mkdtemp()
|
tmp = tempfile.mkdtemp()
|
||||||
for name, url in SHOTS.items():
|
for name in SHOTS:
|
||||||
|
if only and name not in only:
|
||||||
|
continue
|
||||||
src = os.path.join(RAW, f'{name}.png')
|
src = os.path.join(RAW, f'{name}.png')
|
||||||
if not os.path.exists(src):
|
if not os.path.exists(src):
|
||||||
print(f'skip {name}: no raw capture')
|
print(f'skip {name}: no raw capture')
|
||||||
continue
|
continue
|
||||||
iw, ih = (v // SCALE for v in png_size(src))
|
iw, ih = (v // SCALE for v in png_size(src))
|
||||||
w, h = iw + 2 * PAD_X, ih + BAR + 2 * PAD_Y
|
flow = [os.path.join(RAW, f'{step}.png') for step in FLOWS.get(name, [])]
|
||||||
|
if not all(os.path.exists(p) for p in flow):
|
||||||
|
print(f'{name}: a step is missing, the page alone')
|
||||||
|
flow = []
|
||||||
|
w, h, x, y, steps = layout(iw, ih, flow)
|
||||||
html = os.path.join(tmp, f'{name}.html')
|
html = os.path.join(tmp, f'{name}.html')
|
||||||
with open(html, 'w', encoding='utf-8') as f:
|
with open(html, 'w', encoding='utf-8') as f:
|
||||||
f.write(TEMPLATE.format(w=w, h=h, iw=iw, ih=ih, bar=BAR, url=url, src=src,
|
f.write(TEMPLATE.format(w=w, h=h, x=x, y=y, iw=iw, ih=ih, px=x - INSET, py=y - INSET, pw=iw + 2 * INSET,
|
||||||
gw=int(w * .8), gh=int(h * .5), gw2=int(w * .6), gh2=int(h * .45)))
|
ph=ih + 2 * INSET, src=src, font=FONT, steps=steps))
|
||||||
out = os.path.join(OUT, f'{name}.png')
|
out = os.path.join(OUT, f'{name}.png')
|
||||||
subprocess.run([browser, '--headless=new', '--disable-gpu', '--hide-scrollbars', '--allow-file-access-from-files',
|
subprocess.run([browser, '--headless=new', '--disable-gpu', '--hide-scrollbars', '--allow-file-access-from-files',
|
||||||
f'--force-device-scale-factor={SCALE}', f'--window-size={w},{h}', f'--screenshot={out}', f'file://{html}'],
|
f'--force-device-scale-factor={SCALE}', f'--window-size={w},{h}', f'--screenshot={out}', f'file://{html}'],
|
||||||
|
|||||||
@@ -0,0 +1,397 @@
|
|||||||
|
// Demo data for the README screenshots (scripts/capture-screenshots.mjs --demo):
|
||||||
|
// the router's own answers (luci.dawnline status, events) with a made-up cast in
|
||||||
|
// place of its people, devices, places and activity, in the states the
|
||||||
|
// screenshots should show (online, ending soon, over the limit, paused, ended,
|
||||||
|
// outside their hours). The router's ids stay, so every page keeps working; it
|
||||||
|
// is only ever read.
|
||||||
|
|
||||||
|
// The admin counts in binary units: "100 GB" is 100 GiB.
|
||||||
|
const GB = 2 ** 30;
|
||||||
|
const MIN = 60;
|
||||||
|
const HOUR = 3600;
|
||||||
|
const DAY = 86400;
|
||||||
|
|
||||||
|
/** Where the cast connects from: [lat, lon, country, cc, network]. */
|
||||||
|
const CITIES = {
|
||||||
|
Lisbon: [38.7223, -9.1393, 'Portugal', 'PT', 'MEO'],
|
||||||
|
Porto: [41.1579, -8.6291, 'Portugal', 'PT', 'NOS'],
|
||||||
|
Sintra: [38.8029, -9.3817, 'Portugal', 'PT', 'Vodafone Portugal'],
|
||||||
|
Madrid: [40.4168, -3.7038, 'Spain', 'ES', 'Telefonica de Espana'],
|
||||||
|
Barcelona: [41.3874, 2.1686, 'Spain', 'ES', 'Orange Espagne'],
|
||||||
|
Berlin: [52.52, 13.405, 'Germany', 'DE', 'Deutsche Telekom'],
|
||||||
|
Milan: [45.4642, 9.19, 'Italy', 'IT', 'TIM'],
|
||||||
|
Amsterdam: [52.3676, 4.9041, 'Netherlands', 'NL', 'KPN'],
|
||||||
|
Paris: [48.8566, 2.3522, 'France', 'FR', 'Orange'],
|
||||||
|
London: [51.5072, -0.1276, 'United Kingdom', 'GB', 'BT'],
|
||||||
|
Stockholm: [59.3293, 18.0686, 'Sweden', 'SE', 'Telia'],
|
||||||
|
};
|
||||||
|
/** The router's own place. */
|
||||||
|
const HOME = 'Lisbon';
|
||||||
|
/** Shared at home (Access): what a Home-only person can be limited to. */
|
||||||
|
const SERVICES = [
|
||||||
|
{ id: 'demo-nas', name: 'NAS', address: '10.0.1.20', ports: ['445', '5000'] },
|
||||||
|
{
|
||||||
|
id: 'demo-ha',
|
||||||
|
name: 'Home Assistant',
|
||||||
|
address: '10.0.1.30',
|
||||||
|
ports: ['8123'],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
/** How busy each day of the week is, Monday first. */
|
||||||
|
const WEEK = [0.9, 1.15, 0.8, 1.05, 1.3, 0.75, 1.1];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Who the screenshots show, the --person first (the Person page), each with
|
||||||
|
* their city. A device: [name, kind, when it was last seen, GB this month,
|
||||||
|
* earlier places as 'City:days ago']; when: 'online', 'mins:N', 'hours:N',
|
||||||
|
* 'days:N', 'never', 'stale' (settings changed since), 'disabled'. Its last
|
||||||
|
* place is the person's city unless `at` names another.
|
||||||
|
*/
|
||||||
|
export const CAST = [
|
||||||
|
{
|
||||||
|
name: 'Lena Ortiz',
|
||||||
|
city: 'Lisbon',
|
||||||
|
limit: 4,
|
||||||
|
quota: 100,
|
||||||
|
used: 38.6,
|
||||||
|
note: 'Family',
|
||||||
|
devices: [
|
||||||
|
['iPhone 16', 'phone', 'online', 14.2, ['Sintra:3', 'Porto:9', 'Madrid:16']],
|
||||||
|
['MacBook Pro', 'computer', 'hours:3', 21.9, ['Berlin:12']],
|
||||||
|
['iPad Air', 'tablet', 'never', 0],
|
||||||
|
],
|
||||||
|
added: [['iPad Air', 2, 'portal']],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Marco Rossi',
|
||||||
|
city: 'Milan',
|
||||||
|
ends: 4,
|
||||||
|
devices: [
|
||||||
|
['Pixel 9', 'phone', 'online', 6.4, ['Barcelona:8']],
|
||||||
|
['ThinkPad X1', 'computer', 'days:1', 12.8],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Yuki Tanaka',
|
||||||
|
city: 'Amsterdam',
|
||||||
|
state: 'quota',
|
||||||
|
quota: 20,
|
||||||
|
used: 20.4,
|
||||||
|
devices: [
|
||||||
|
['Galaxy S24', 'phone', 'hours:6', 14.1, ['Paris:5']],
|
||||||
|
['Living room TV', 'other', 'stale', 6.3],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Sam Okafor',
|
||||||
|
city: 'London',
|
||||||
|
state: 'paused',
|
||||||
|
paused: 3,
|
||||||
|
devices: [
|
||||||
|
['Gaming PC', 'computer', 'days:9', 3.1],
|
||||||
|
['Steam Deck', 'other', 'disabled', 0],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Nora Lindqvist',
|
||||||
|
city: 'Stockholm',
|
||||||
|
state: 'expired',
|
||||||
|
ends: -3,
|
||||||
|
devices: [['iPhone 13 mini', 'phone', 'days:4', 1.2]],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Mia Ortiz',
|
||||||
|
city: 'Lisbon',
|
||||||
|
state: 'hours',
|
||||||
|
hours: '07:00-21:00',
|
||||||
|
limit: 1,
|
||||||
|
devices: [['Fire HD 10', 'tablet', 'hours:11', 2.6]],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const slug = (s) =>
|
||||||
|
s
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9]+/g, '-')
|
||||||
|
.replace(/^-|-$/g, '');
|
||||||
|
const date = (t) => new Date(t * 1000).toISOString().slice(0, 10);
|
||||||
|
const seen = (when, now) => {
|
||||||
|
const [k, n] = when.split(':');
|
||||||
|
const v = +n || 0;
|
||||||
|
return (
|
||||||
|
{
|
||||||
|
online: now - 40,
|
||||||
|
mins: now - v * MIN,
|
||||||
|
hours: now - v * HOUR,
|
||||||
|
days: now - v * DAY,
|
||||||
|
stale: now - 2 * DAY,
|
||||||
|
disabled: now - 41 * DAY,
|
||||||
|
}[k] ?? 0
|
||||||
|
);
|
||||||
|
};
|
||||||
|
/** A week of daily totals that adds up to about a quarter of the month, today last (nothing before it was first seen). */
|
||||||
|
const week = (gb, last, now) =>
|
||||||
|
[0.8, 1.3, 0.6, 1.1, 1.6, 0.9, 1].map((f, i) => (!gb || now - (6 - i) * DAY < last - DAY ? 0 : Math.round(((gb / 4) * f * GB) / 7)));
|
||||||
|
let ipN = 10;
|
||||||
|
/** A documentation address (the capture swaps public addresses for these anyway). */
|
||||||
|
const ip = () => `203.0.113.${ipN++}`;
|
||||||
|
const where = (city) => `${city} · ${CITIES[city][4]}`;
|
||||||
|
|
||||||
|
/** What the last status made of the router's ids, for the calls that come after it (events, usage). */
|
||||||
|
const demo = { events: [], people: new Map(), days: [], now: 0 };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daily traffic over `days` (oldest first) for `gb` this month: busier some days of the week, today
|
||||||
|
* only partly gone. Each day's [rx, tx] in bytes, rx (from the devices) about an eighth.
|
||||||
|
*/
|
||||||
|
function daily(days, gb, now) {
|
||||||
|
const month = days[days.length - 1].slice(0, 7);
|
||||||
|
const w = days.map((d, i) => {
|
||||||
|
const wd = (new Date(`${d}T12:00:00Z`).getUTCDay() + 6) % 7;
|
||||||
|
const today = i === days.length - 1 ? ((now % DAY) / DAY) * 0.9 + 0.1 : 1;
|
||||||
|
return WEEK[wd] * (0.85 + ((i * 37) % 11) / 30) * today;
|
||||||
|
});
|
||||||
|
const inMonth = w.reduce((s, x, i) => s + (days[i].startsWith(month) ? x : 0), 0) || 1;
|
||||||
|
return w.map((x) => {
|
||||||
|
const b = (x / inMonth) * gb * GB;
|
||||||
|
return [Math.round(b * 0.12), Math.round(b * 0.88)];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const usage = (days, pairs) => days.map((day, i) => ({ day, rx: pairs[i][0], tx: pairs[i][1] }));
|
||||||
|
|
||||||
|
/** The places a device was at, oldest first: [city, ts, ip]. */
|
||||||
|
function trail(c, d, hs, now) {
|
||||||
|
if (!hs) return [];
|
||||||
|
const earlier = (d[4] ?? []).map((s) => {
|
||||||
|
const [city, ago] = s.split(':');
|
||||||
|
return [city, now - +ago * DAY - 5 * HOUR, ip()];
|
||||||
|
});
|
||||||
|
return [...earlier.reverse(), [c.city, hs, ip()]];
|
||||||
|
}
|
||||||
|
|
||||||
|
function demoStatus(st, first) {
|
||||||
|
const now = st.now;
|
||||||
|
ipN = 10;
|
||||||
|
const real = [...st.people].sort((a, b) => (a.id === first ? -1 : b.id === first ? 1 : a.id < b.id ? -1 : 1));
|
||||||
|
const spare = real.flatMap((p) => p.devices);
|
||||||
|
const points = [];
|
||||||
|
const events = [];
|
||||||
|
const people = CAST.map((c, i) => {
|
||||||
|
const base = real[i] ?? {
|
||||||
|
...real[real.length - 1],
|
||||||
|
id: `demo-${i}`,
|
||||||
|
devices: [],
|
||||||
|
};
|
||||||
|
const state = c.state ?? 'active';
|
||||||
|
const devices = c.devices.map((cd, j) => {
|
||||||
|
const [name, kind, when, gb] = cd;
|
||||||
|
const tpl = base.devices[j] ?? {
|
||||||
|
...spare[j % spare.length],
|
||||||
|
id: `${base.id}-demo-${j}`,
|
||||||
|
address: `10.8.0.${200 + i * 8 + j}`,
|
||||||
|
};
|
||||||
|
const hs = when === 'never' ? 0 : seen(when, now);
|
||||||
|
const online = when === 'online' && !['paused', 'expired', 'hours'].includes(state);
|
||||||
|
const places = trail(c, cd, hs, now);
|
||||||
|
places.forEach(([city, ts, addr], k) => {
|
||||||
|
const [lat, lon, country, cc, org] = CITIES[city];
|
||||||
|
const current = online && k === places.length - 1;
|
||||||
|
points.push({
|
||||||
|
person: base.id,
|
||||||
|
device: tpl.id,
|
||||||
|
ip: addr,
|
||||||
|
ts,
|
||||||
|
online: current,
|
||||||
|
lat,
|
||||||
|
lon,
|
||||||
|
city,
|
||||||
|
country,
|
||||||
|
cc,
|
||||||
|
asn: 0,
|
||||||
|
org,
|
||||||
|
});
|
||||||
|
const ev = {
|
||||||
|
person: base.id,
|
||||||
|
device: tpl.id,
|
||||||
|
pname: c.name,
|
||||||
|
dname: name,
|
||||||
|
dkind: kind,
|
||||||
|
};
|
||||||
|
// Online now: connected a while ago (the handshake renews every few minutes); otherwise on for a couple of hours.
|
||||||
|
events.push({
|
||||||
|
...ev,
|
||||||
|
type: 'connect',
|
||||||
|
detail: addr,
|
||||||
|
where: where(city),
|
||||||
|
ts: current ? now - 95 * MIN - j * 13 * MIN : ts - 2 * HOUR,
|
||||||
|
});
|
||||||
|
if (!current) events.push({ ...ev, type: 'disconnect', ts });
|
||||||
|
});
|
||||||
|
// A phone in hand switches between Wi-Fi and mobile data.
|
||||||
|
if (online && kind === 'phone') {
|
||||||
|
const [, , addr] = places[places.length - 1];
|
||||||
|
events.push({
|
||||||
|
person: base.id,
|
||||||
|
device: tpl.id,
|
||||||
|
pname: c.name,
|
||||||
|
dname: name,
|
||||||
|
dkind: kind,
|
||||||
|
type: 'roam',
|
||||||
|
detail: `${ip()} → ${addr}`,
|
||||||
|
ts: now - 25 * MIN,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...tpl,
|
||||||
|
name,
|
||||||
|
kind,
|
||||||
|
online,
|
||||||
|
active: online,
|
||||||
|
handshake: hs,
|
||||||
|
endpoint: places.length ? places[places.length - 1][2] : '',
|
||||||
|
config_stale: when === 'stale',
|
||||||
|
disabled: when === 'disabled',
|
||||||
|
month: [Math.round(gb * 0.12 * GB), Math.round(gb * 0.88 * GB)],
|
||||||
|
total: [Math.round(gb * 0.3 * GB), Math.round(gb * 2.2 * GB)],
|
||||||
|
spark: week(gb, hs, now),
|
||||||
|
hostname: hs ? `${slug(name)}.${slug(c.name.split(' ')[0])}.lan` : '',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
for (const [name, ago, by] of c.added ?? []) {
|
||||||
|
const d = devices.find((x) => x.name === name);
|
||||||
|
if (d)
|
||||||
|
events.push({
|
||||||
|
person: base.id,
|
||||||
|
device: d.id,
|
||||||
|
pname: c.name,
|
||||||
|
dname: name,
|
||||||
|
dkind: d.kind,
|
||||||
|
type: 'device_added',
|
||||||
|
detail: name,
|
||||||
|
by,
|
||||||
|
ts: now - ago * DAY,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (c.paused)
|
||||||
|
events.push({
|
||||||
|
person: base.id,
|
||||||
|
pname: c.name,
|
||||||
|
type: 'paused',
|
||||||
|
by: 'admin',
|
||||||
|
ts: now - c.paused * DAY,
|
||||||
|
});
|
||||||
|
const month = devices.reduce((s, d) => [s[0] + d.month[0], s[1] + d.month[1]], [0, 0]);
|
||||||
|
const live = devices.some((d) => d.online);
|
||||||
|
demo.people.set(base.id, {
|
||||||
|
devices: devices.map((d, j) => [d.id, c.devices[j][3]]),
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
...base,
|
||||||
|
name: c.name,
|
||||||
|
state,
|
||||||
|
paused: state === 'paused',
|
||||||
|
hours: c.hours ?? '',
|
||||||
|
note: c.note ?? '',
|
||||||
|
expires: c.ends !== undefined ? date(now + c.ends * DAY) : '',
|
||||||
|
device_limit: c.limit ?? Math.max(3, devices.length),
|
||||||
|
quota_gb: c.quota ?? 0,
|
||||||
|
quota_period: 'month',
|
||||||
|
quota_limit: (c.quota ?? 0) * GB,
|
||||||
|
quota_used: Math.round((c.used ?? (month[0] + month[1]) / GB) * GB),
|
||||||
|
bonus_gb: 0,
|
||||||
|
month,
|
||||||
|
total: [month[0] * 3, month[1] * 3],
|
||||||
|
online: devices.filter((d) => d.online).length,
|
||||||
|
last_seen: Math.max(0, ...devices.map((d) => d.handshake)),
|
||||||
|
rate: (base.rate ?? []).map(([t], k) => [t, live ? 12000 + ((k * 7919) % 9000) : 0, live ? 120000 + ((k * 104729) % 90000) : 0]),
|
||||||
|
devices,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const devices = people.flatMap((p) => p.devices);
|
||||||
|
const month = people.reduce((s, p) => [s[0] + p.month[0], s[1] + p.month[1]], [0, 0]);
|
||||||
|
events.sort((a, b) => a.ts - b.ts);
|
||||||
|
demo.events = events;
|
||||||
|
points.sort((a, b) => b.ts - a.ts);
|
||||||
|
demo.now = now;
|
||||||
|
demo.days = (st.series ?? []).map((x) => x.day);
|
||||||
|
if (!demo.days.length) for (let k = 29; k >= 0; k--) demo.days.push(date(now - k * DAY));
|
||||||
|
const all = CAST.reduce((s, c) => s + c.devices.reduce((t, d) => t + d[3], 0), 0);
|
||||||
|
const series = usage(demo.days, daily(demo.days, all, now));
|
||||||
|
const today = series[series.length - 1];
|
||||||
|
const [lat, lon, country, cc, org] = CITIES[HOME];
|
||||||
|
return {
|
||||||
|
...st,
|
||||||
|
people,
|
||||||
|
totals: {
|
||||||
|
...st.totals,
|
||||||
|
people: people.length,
|
||||||
|
devices: devices.length,
|
||||||
|
online: devices.filter((d) => d.online).length,
|
||||||
|
active: people.filter((p) => p.state === 'active').length,
|
||||||
|
today: [today.rx, today.tx],
|
||||||
|
month,
|
||||||
|
},
|
||||||
|
series,
|
||||||
|
servers: st.servers.map((x) => ({ ...x, series })),
|
||||||
|
services: st.services?.length ? st.services : SERVICES,
|
||||||
|
geo: st.geo && {
|
||||||
|
...st.geo,
|
||||||
|
home: { lat, lon, city: HOME, country, cc, asn: 0, org },
|
||||||
|
points,
|
||||||
|
},
|
||||||
|
events: events.slice(-60),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A ubus JSON-RPC exchange (LuCI batches calls into one request) with the
|
||||||
|
* luci.dawnline answers made into the demo; anything else as it came.
|
||||||
|
*/
|
||||||
|
export function demoRpc(request, response, first) {
|
||||||
|
let req;
|
||||||
|
let res;
|
||||||
|
try {
|
||||||
|
req = JSON.parse(request);
|
||||||
|
res = JSON.parse(response);
|
||||||
|
} catch {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
const calls = new Map((Array.isArray(req) ? req : [req]).map((c) => [c.id, c.params ?? []]));
|
||||||
|
const fix = (r) => {
|
||||||
|
const [, object, method, args] = calls.get(r?.id) ?? [];
|
||||||
|
const data = r?.result?.[1];
|
||||||
|
if (object !== 'luci.dawnline' || !data || typeof data !== 'object') return r;
|
||||||
|
if (method === 'status' && Array.isArray(data.people)) return { ...r, result: [r.result[0], demoStatus(data, first)] };
|
||||||
|
if (method === 'person_usage' && demo.people.has(args?.id) && demo.days.length) {
|
||||||
|
const devs = demo.people.get(args.id).devices ?? [];
|
||||||
|
const per = Object.fromEntries(devs.map(([id, gb]) => [id, daily(demo.days, gb, demo.now)]));
|
||||||
|
const sum = demo.days.map((_, i) => devs.reduce((s, [id]) => [s[0] + per[id][i][0], s[1] + per[id][i][1]], [0, 0]));
|
||||||
|
const devices = Object.fromEntries(devs.map(([id]) => [id, usage(demo.days, per[id])]));
|
||||||
|
return {
|
||||||
|
...r,
|
||||||
|
result: [r.result[0], { ...data, person: usage(demo.days, sum), devices }],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Every check passes: the screenshots show Dawnline, not this router's own setup.
|
||||||
|
if (method === 'health' && Array.isArray(data.checks))
|
||||||
|
return {
|
||||||
|
...r,
|
||||||
|
result: [
|
||||||
|
r.result[0],
|
||||||
|
{
|
||||||
|
...data,
|
||||||
|
checks: data.checks.map((c) => (c.status === 'warn' || c.status === 'error' ? { ...c, status: 'ok', problem: null } : c)),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
if (method === 'events' && Array.isArray(data.events)) {
|
||||||
|
const mine = demo.events.filter((e) => !args?.person || e.person === args.person);
|
||||||
|
return {
|
||||||
|
...r,
|
||||||
|
result: [r.result[0], { ...data, events: mine, total: mine.length }],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
};
|
||||||
|
return JSON.stringify(Array.isArray(res) ? res.map(fix) : fix(res));
|
||||||
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
# Test fixture: a small installation (one server, two people, one device).
|
# Test fixture: a small installation (one server, two people, one device).
|
||||||
# migrate.test.uc expects bob's random code, the server's stored MTU 1380 and
|
# migrate.test.uc expects bob's random code, the server's stored MTU 1380,
|
||||||
# uhttpd's error_page: the one-time steps remove them.
|
# the old portal title and uhttpd's error_page: the one-time steps remove them.
|
||||||
|
|
||||||
config settings 'settings'
|
config settings 'settings'
|
||||||
option portal_enabled '1'
|
option portal_enabled '1'
|
||||||
option portal_port '8443'
|
option portal_port '8443'
|
||||||
option portal_host 'vpn.example.com'
|
option portal_host 'vpn.example.com'
|
||||||
|
option portal_title 'My VPN'
|
||||||
option log_connections '0'
|
option log_connections '0'
|
||||||
option update_interval '7d'
|
option update_interval '7d'
|
||||||
list update_targets 'app'
|
list update_targets 'app'
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ test('before: the fixture holds the old state', () => {
|
|||||||
let c = conf('dawnline');
|
let c = conf('dawnline');
|
||||||
eq(c.get('dawnline', 'bob', 'code'), 'XyZ12345', 'random code');
|
eq(c.get('dawnline', 'bob', 'code'), 'XyZ12345', 'random code');
|
||||||
eq(c.get('dawnline', 'main', 'mtu'), '1380', 'stored MTU');
|
eq(c.get('dawnline', 'main', 'mtu'), '1380', 'stored MTU');
|
||||||
|
eq(c.get('dawnline', 'settings', 'portal_title'), 'My VPN', 'a portal title');
|
||||||
eq(conf('uhttpd').get('uhttpd', 'main', 'error_page'), '/cgi-bin/dawnline-portal', 'portal as error page');
|
eq(conf('uhttpd').get('uhttpd', 'main', 'error_page'), '/cgi-bin/dawnline-portal', 'portal as error page');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ test('run: the steps change what they must', () => {
|
|||||||
eq(c.get('dawnline', 'main', 'mtu'), null, 'MTU is automatic');
|
eq(c.get('dawnline', 'main', 'mtu'), null, 'MTU is automatic');
|
||||||
eq(c.get('dawnline', 'main', 'subnet'), '10.9.0.0/29', 'the rest of the server stays');
|
eq(c.get('dawnline', 'main', 'subnet'), '10.9.0.0/29', 'the rest of the server stays');
|
||||||
eq(c.get('dawnline', 'settings', 'portal_443'), null, 'no portal_443');
|
eq(c.get('dawnline', 'settings', 'portal_443'), null, 'no portal_443');
|
||||||
|
eq(c.get('dawnline', 'settings', 'portal_title'), null, 'no portal title');
|
||||||
eq(conf('uhttpd').get('uhttpd', 'main', 'error_page'), null, 'error page gone');
|
eq(conf('uhttpd').get('uhttpd', 'main', 'error_page'), null, 'error page gone');
|
||||||
eq(conf('uhttpd').get('uhttpd', 'main', 'home'), '/www', 'the rest of uhttpd stays');
|
eq(conf('uhttpd').get('uhttpd', 'main', 'home'), '/www', 'the rest of uhttpd stays');
|
||||||
eq(stat('/etc/config/dawnline').perm, { setuid: false, setgid: false, sticky: false,
|
eq(stat('/etc/config/dawnline').perm, { setuid: false, setgid: false, sticky: false,
|
||||||
|
|||||||
@@ -77,13 +77,6 @@ test('validate: time', () => {
|
|||||||
throws(() => schema.validate('update_time', '23:60'), /HH:MM/, 'minute 60');
|
throws(() => schema.validate('update_time', '23:60'), /HH:MM/, 'minute 60');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('validate: text', () => {
|
|
||||||
eq(schema.validate('portal_title', 'My VPN'), 'My VPN', 'plain');
|
|
||||||
eq(schema.validate('portal_title', replace(sprintf('%64s', ''), ' ', 'a')), replace(sprintf('%64s', ''), ' ', 'a'), '64 characters');
|
|
||||||
throws(() => schema.validate('portal_title', replace(sprintf('%65s', ''), ' ', 'a')), /64 characters/, '65 characters');
|
|
||||||
throws(() => schema.validate('portal_title', 'a\nb'), /64 characters/, 'control character');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('validate: targets', () => {
|
test('validate: targets', () => {
|
||||||
eq(schema.validate('update_targets', [ 'app', 'bogus', 'app', 'amneziawg' ]), [ 'app', 'amneziawg' ], 'known ones, once');
|
eq(schema.validate('update_targets', [ 'app', 'bogus', 'app', 'amneziawg' ]), [ 'app', 'amneziawg' ], 'known ones, once');
|
||||||
eq(schema.validate('update_targets', []), [ 'none' ], 'empty is a choice');
|
eq(schema.validate('update_targets', []), [ 'none' ], 'empty is a choice');
|
||||||
@@ -110,8 +103,6 @@ test('get', () => {
|
|||||||
eq(schema.get({ home_dns_fallback: 'none' }, 'home_dns_fallback'), '', 'none reads as empty');
|
eq(schema.get({ home_dns_fallback: 'none' }, 'home_dns_fallback'), '', 'none reads as empty');
|
||||||
eq(schema.get({}, 'home_dns_fallback'), '1.1.1.1', 'missing ipv4');
|
eq(schema.get({}, 'home_dns_fallback'), '1.1.1.1', 'missing ipv4');
|
||||||
eq(schema.get({ home_dns_fallback: '300.1.1.1' }, 'home_dns_fallback'), '1.1.1.1', 'bad ipv4');
|
eq(schema.get({ home_dns_fallback: '300.1.1.1' }, 'home_dns_fallback'), '1.1.1.1', 'bad ipv4');
|
||||||
eq(schema.get({}, 'portal_title'), 'Dawnline', 'missing text');
|
|
||||||
eq(schema.get({ portal_title: '' }, 'portal_title'), 'Dawnline', 'empty text');
|
|
||||||
eq(schema.get({ portal_host: 'vpn.example.com' }, 'portal_host'), 'vpn.example.com', 'host passes through');
|
eq(schema.get({ portal_host: 'vpn.example.com' }, 'portal_host'), 'vpn.example.com', 'host passes through');
|
||||||
eq(schema.get({ other: 'raw' }, 'other'), 'raw', 'unknown key is the raw value');
|
eq(schema.get({ other: 'raw' }, 'other'), 'raw', 'unknown key is the raw value');
|
||||||
eq(schema.get(null, 'portal_port'), 8443, 'no section');
|
eq(schema.get(null, 'portal_port'), 8443, 'no section');
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// dawnline.view: which device a portal page was opened from.
|
// dawnline.view: which device a portal page was opened from, and the usage series it draws.
|
||||||
import * as view from 'dawnline.view';
|
import * as view from 'dawnline.view';
|
||||||
|
import { day_key_ago } from 'dawnline.util';
|
||||||
|
|
||||||
const devs = [
|
const devs = [
|
||||||
{ id: 'd_1', address: '10.0.0.2', online: true, endpoint: '203.0.113.7' },
|
{ id: 'd_1', address: '10.0.0.2', online: true, endpoint: '203.0.113.7' },
|
||||||
@@ -18,3 +19,20 @@ test('device_here', () => {
|
|||||||
eq(view.device_here(devs, ''), null, 'no address');
|
eq(view.device_here(devs, ''), null, 'no address');
|
||||||
eq(view.device_here([ { id: 'd_5', address: '10.0.0.6', online: true, endpoint: '' } ], ''), null, 'no address, no endpoint');
|
eq(view.device_here([ { id: 'd_5', address: '10.0.0.6', online: true, endpoint: '' } ], ''), null, 'no address, no endpoint');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('month_days', () => {
|
||||||
|
let n = +substr(day_key_ago(0), 8, 2);
|
||||||
|
let days = {};
|
||||||
|
// On the 1st, today is the 1st: then only today's own value.
|
||||||
|
if (n > 1)
|
||||||
|
days[day_key_ago(n - 1)] = [ 1, 2 ];
|
||||||
|
days[day_key_ago(0)] = [ 5, 7 ];
|
||||||
|
// Last month's last day stays out of this month's chart.
|
||||||
|
days[day_key_ago(n)] = [ 100, 100 ];
|
||||||
|
let s = view.month_days({ days });
|
||||||
|
eq(length(s), n, 'one bar a day, from the 1st to today');
|
||||||
|
eq(s[n - 1], 12, 'today last, received and sent together');
|
||||||
|
eq(s[0], n > 1 ? 3 : 12, 'the 1st first');
|
||||||
|
eq(length(view.month_days(null)), n, 'no usage yet: zeros');
|
||||||
|
eq(view.month_days(null)[0], 0, 'a day without traffic is zero');
|
||||||
|
});
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "dawnline-web",
|
"name": "dawnline-web",
|
||||||
"version": "0.9.0",
|
"version": "0.10.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "dawnline-web",
|
"name": "dawnline-web",
|
||||||
"version": "0.9.0",
|
"version": "0.10.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"qrcode-generator": "1.4.4"
|
"qrcode-generator": "1.4.4"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dawnline-web",
|
"name": "dawnline-web",
|
||||||
"version": "0.9.0",
|
"version": "0.10.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import { confirmDialog } from '../ui/modal';
|
|||||||
import { copyText, downloadFile } from '../ui/files';
|
import { copyText, downloadFile } from '../ui/files';
|
||||||
import { attempt, notify } from '../ui/toast';
|
import { attempt, notify } from '../ui/toast';
|
||||||
import { input } from '../ui/controls';
|
import { input } from '../ui/controls';
|
||||||
import { callout, card, firstBad, group, liveRow, row, svg } from '../ui/layout';
|
import { callout, card, firstBad, group, liveRow, row } from '../ui/layout';
|
||||||
|
import { qrCode } from '../ui/qr';
|
||||||
import { keepaliveHelp, mtuHelp, portHelp, type PortHold } from '../netcheck';
|
import { keepaliveHelp, mtuHelp, portHelp, type PortHold } from '../netcheck';
|
||||||
import { qrSvg } from '../../shared/qr';
|
|
||||||
import { vpnKey } from '../../shared/vpnkey';
|
import { vpnKey } from '../../shared/vpnkey';
|
||||||
import { icon } from '../../shared/icons';
|
import { icon } from '../../shared/icons';
|
||||||
import { methodInfo, methodPicker, type Method, defaultMethod, legacyTitle } from '../disguise';
|
import { methodInfo, methodPicker, type Method, defaultMethod, legacyTitle } from '../disguise';
|
||||||
@@ -171,7 +171,7 @@ function fileCard(cfg: AwgConfig): HTMLElement {
|
|||||||
E('span', { class: 'dl-filecard-ic' }, '.conf'),
|
E('span', { class: 'dl-filecard-ic' }, '.conf'),
|
||||||
E('span', { class: 'dl-stack' }, [
|
E('span', { class: 'dl-stack' }, [
|
||||||
E('span', { class: 'dl-mono dl-ellipsis' }, cfg.filename),
|
E('span', { class: 'dl-mono dl-ellipsis' }, cfg.filename),
|
||||||
E('span', { class: 'dl-sub' }, `AmneziaWG · ${size} bytes · import it in the app`),
|
E('span', { class: 'dl-sub' }, `AmneziaWG · ${size} bytes`),
|
||||||
]),
|
]),
|
||||||
button([icon('download'), ' Download'], () => downloadFile(cfg.filename, cfg.conf, 'application/octet-stream'), 'positive'),
|
button([icon('download'), ' Download'], () => downloadFile(cfg.filename, cfg.conf, 'application/octet-stream'), 'positive'),
|
||||||
]),
|
]),
|
||||||
@@ -218,7 +218,7 @@ export async function connectBlock(cfg: AwgConfig, initial: 'file' | 'key' | 'qr
|
|||||||
const panes: Record<string, () => Node> = {
|
const panes: Record<string, () => Node> = {
|
||||||
qr: () =>
|
qr: () =>
|
||||||
E('div', { class: 'dl-qr-pane' }, [
|
E('div', { class: 'dl-qr-pane' }, [
|
||||||
svg(qrSvg(cfg.conf), 'dl-qr'),
|
qrCode(cfg.conf),
|
||||||
E(
|
E(
|
||||||
'span',
|
'span',
|
||||||
{ class: 'dl-sub' },
|
{ class: 'dl-sub' },
|
||||||
@@ -437,6 +437,6 @@ export const awg: Core = {
|
|||||||
overviewTile,
|
overviewTile,
|
||||||
connectBlock,
|
connectBlock,
|
||||||
qrText: (cfg) => cfg.conf,
|
qrText: (cfg) => cfg.conf,
|
||||||
appKey: { label: 'Copy AmneziaVPN key', make: (cfg) => vpnKey(cfg, cfg.server) },
|
appKey: { label: 'Copy AmneziaVPN config', make: (cfg) => vpnKey(cfg, cfg.server) },
|
||||||
file: { label: 'Download .conf', make: (cfg) => ({ name: cfg.filename, text: cfg.conf }) },
|
file: { label: 'Download AmneziaWG config', make: (cfg) => ({ name: cfg.filename, text: cfg.conf }) },
|
||||||
};
|
};
|
||||||
@@ -11,10 +11,10 @@ import { copyText, downloadFile } from './ui/files';
|
|||||||
import { dropdown, type MenuItem } from './ui/menu';
|
import { dropdown, type MenuItem } from './ui/menu';
|
||||||
import { drawer } from './ui/drawer';
|
import { drawer } from './ui/drawer';
|
||||||
import { attempt, notify } from './ui/toast';
|
import { attempt, notify } from './ui/toast';
|
||||||
import { liveField, svg } from './ui/layout';
|
import { liveField } from './ui/layout';
|
||||||
|
import { qrCode } from './ui/qr';
|
||||||
import { nameHelp } from './netcheck';
|
import { nameHelp } from './netcheck';
|
||||||
import { deviceStatus } from './ui/badges';
|
import { deviceStatus } from './ui/badges';
|
||||||
import { qrSvg } from '../shared/qr';
|
|
||||||
import { ago, bytes, isoDay, KIND_LABEL, KINDS, todayOf } from '../shared/format';
|
import { ago, bytes, isoDay, KIND_LABEL, KINDS, todayOf } from '../shared/format';
|
||||||
import { icon } from '../shared/icons';
|
import { icon } from '../shared/icons';
|
||||||
import { eventBy } from './events/model';
|
import { eventBy } from './events/model';
|
||||||
@@ -420,7 +420,7 @@ export function quickMenu(anchor: HTMLElement, p: Person, d: Device, o: DeviceOp
|
|||||||
modal(
|
modal(
|
||||||
`${d.name} · QR code`,
|
`${d.name} · QR code`,
|
||||||
E('div', { class: 'dl-qr-pane' }, [
|
E('div', { class: 'dl-qr-pane' }, [
|
||||||
svg(qrSvg(core.qrText(c)), 'dl-qr'),
|
qrCode(core.qrText(c)),
|
||||||
E(
|
E(
|
||||||
'span',
|
'span',
|
||||||
{ class: 'dl-sub' },
|
{ class: 'dl-sub' },
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { E } from './e';
|
|||||||
import { ago, initials } from '../shared/format';
|
import { ago, initials } from '../shared/format';
|
||||||
import { icon, iconSvg } from '../shared/icons';
|
import { icon, iconSvg } from '../shared/icons';
|
||||||
import { onNavigate } from './ui/nav';
|
import { onNavigate } from './ui/nav';
|
||||||
|
import { isDark } from './ui/theme';
|
||||||
import { placeKey, shimmerOpacity } from './places/model';
|
import { placeKey, shimmerOpacity } from './places/model';
|
||||||
|
|
||||||
// mapcn requires maplibre-gl ^6 (the globe projection came with 5): an ES module, its worker beside it.
|
// mapcn requires maplibre-gl ^6 (the globe projection came with 5): an ES module, its worker beside it.
|
||||||
@@ -71,12 +72,6 @@ function loadMapLibre(host: HTMLElement): Promise<any> {
|
|||||||
return loading;
|
return loading;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDark(): boolean {
|
|
||||||
const attr = document.documentElement.getAttribute('data-darkmode');
|
|
||||||
if (attr != null) return attr === 'true';
|
|
||||||
return window.matchMedia?.('(prefers-color-scheme: dark)').matches ?? false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A click on a marker brings the map at least this close (a city). */
|
/** A click on a marker brings the map at least this close (a city). */
|
||||||
const CLICK_ZOOM = 10;
|
const CLICK_ZOOM = 10;
|
||||||
/** Places closer than this are one city: a click shows them together at city level. */
|
/** Places closer than this are one city: a click shows them together at city level. */
|
||||||
|
|||||||
@@ -244,13 +244,6 @@ export function urlHelp(s: string): Help {
|
|||||||
return { text: 'Wrong links are sent there instead of a “Not found”.', bad: false };
|
return { text: 'Wrong links are sent there instead of a “Not found”.', bad: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The portal's title: up to 64 characters on one line. */
|
|
||||||
export function titleHelp(s: string): Help {
|
|
||||||
if (chars(s) > 64) return { text: `Up to 64 characters (${chars(s)} now).`, bad: true };
|
|
||||||
if (/[\u0000-\u001f\u007f]/.test(s)) return { text: 'One line, please.', bad: true };
|
|
||||||
return { text: 'Shown in the browser tab and at the top of the portal.', bad: false };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The home domain for device hostnames (schema domain): lowercase letters, digits, dashes, dots. */
|
/** The home domain for device hostnames (schema domain): lowercase letters, digits, dashes, dots. */
|
||||||
export function domainHelp(s: string, example = 'phone.myata'): Help {
|
export function domainHelp(s: string, example = 'phone.myata'): Help {
|
||||||
const t = s.trim();
|
const t = s.trim();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { button } from '../../ui/button';
|
|||||||
import { cancelButton, closeModal, modal } from '../../ui/modal';
|
import { cancelButton, closeModal, modal } from '../../ui/modal';
|
||||||
import { input, isOn, sw } from '../../ui/controls';
|
import { input, isOn, sw } from '../../ui/controls';
|
||||||
import { firstBad, group, liveRow, needRow, row } from '../../ui/layout';
|
import { firstBad, group, liveRow, needRow, row } from '../../ui/layout';
|
||||||
import { hostHelp, portalPortHelp, titleHelp, urlHelp } from '../../netcheck';
|
import { hostHelp, portalPortHelp, urlHelp } from '../../netcheck';
|
||||||
import { icon } from '../../../shared/icons';
|
import { icon } from '../../../shared/icons';
|
||||||
import { fmtDay } from '../../../shared/format';
|
import { fmtDay } from '../../../shared/format';
|
||||||
import { installMissing } from '../../pkgs';
|
import { installMissing } from '../../pkgs';
|
||||||
@@ -29,7 +29,6 @@ export function portalCard(host: SettingsHost): HTMLElement {
|
|||||||
const c = host.d.cert;
|
const c = host.d.cert;
|
||||||
const pOn = sw(eff.portal_enabled, 'Enable portal');
|
const pOn = sw(eff.portal_enabled, 'Enable portal');
|
||||||
const port = input(s.portal_port, { placeholder: '8443', inputmode: 'numeric', class: 'cbi-input-text dl-w-port' });
|
const port = input(s.portal_port, { placeholder: '8443', inputmode: 'numeric', class: 'cbi-input-text dl-w-port' });
|
||||||
const title = input(s.portal_title, { placeholder: 'Dawnline' });
|
|
||||||
const redirect = input(s.portal_redirect, { placeholder: 'Show “Not found”', class: 'cbi-input-text dl-mono' });
|
const redirect = input(s.portal_redirect, { placeholder: 'Show “Not found”', class: 'cbi-input-text dl-mono' });
|
||||||
const other = input('', { placeholder: 'vpn.example.com or an IP', 'aria-label': 'Other address' });
|
const other = input('', { placeholder: 'vpn.example.com or an IP', 'aria-label': 'Other address' });
|
||||||
const isIp = (h: string) => /^\d{1,3}(\.\d{1,3}){3}$/.test(h);
|
const isIp = (h: string) => /^\d{1,3}(\.\d{1,3}){3}$/.test(h);
|
||||||
@@ -279,7 +278,6 @@ export function portalCard(host: SettingsHost): HTMLElement {
|
|||||||
portalPortHelp(port.value.trim() === '' ? eff.portal_port : Number(port.value), host.d.tcp_taken ?? [], picked.some(isIp)),
|
portalPortHelp(port.value.trim() === '' ? eff.portal_port : Number(port.value), host.d.tcp_taken ?? [], picked.some(isIp)),
|
||||||
);
|
);
|
||||||
refreshPort = listenRow.refresh;
|
refreshPort = listenRow.refresh;
|
||||||
const titleRow = liveRow('Title', title, () => titleHelp(title.value));
|
|
||||||
const redirectRow = liveRow('Unknown links', redirect, () => urlHelp(redirect.value));
|
const redirectRow = liveRow('Unknown links', redirect, () => urlHelp(redirect.value));
|
||||||
const custom = !!(s.portal_cert && s.portal_key);
|
const custom = !!(s.portal_cert && s.portal_key);
|
||||||
const kind = !c ? 'Portal is off' : custom ? 'Your files' : c.self_signed ? 'Self-signed' : 'Let’s Encrypt';
|
const kind = !c ? 'Portal is off' : custom ? 'Your files' : c.self_signed ? 'Self-signed' : 'Let’s Encrypt';
|
||||||
@@ -371,7 +369,7 @@ export function portalCard(host: SettingsHost): HTMLElement {
|
|||||||
E('span', { class: 'dl-muted' }, 'A page where each person adds and manages their devices with their personal link.'),
|
E('span', { class: 'dl-muted' }, 'A page where each person adds and manages their devices with their personal link.'),
|
||||||
httpsRow ? E('div', { class: 'dl-list' }, [httpsRow]) : '',
|
httpsRow ? E('div', { class: 'dl-list' }, [httpsRow]) : '',
|
||||||
group('network', 'Port', 'How the portal listens (80 and 443 stay free)', [listenRow]),
|
group('network', 'Port', 'How the portal listens (80 and 443 stay free)', [listenRow]),
|
||||||
group('edit', 'Appearance', 'What people see', [titleRow, redirectRow]),
|
group('edit', 'Appearance', 'What people see', [redirectRow]),
|
||||||
group('link', 'Addresses', 'Pick one or more; the first is the main link', [
|
group('link', 'Addresses', 'Pick one or more; the first is the main link', [
|
||||||
opts,
|
opts,
|
||||||
E('div', { class: 'dl-stack gap8' }, [
|
E('div', { class: 'dl-stack gap8' }, [
|
||||||
@@ -388,7 +386,7 @@ export function portalCard(host: SettingsHost): HTMLElement {
|
|||||||
'Save',
|
'Save',
|
||||||
() => {
|
() => {
|
||||||
// The help lines already say what is wrong: do not send it anyway.
|
// The help lines already say what is wrong: do not send it anyway.
|
||||||
const bad = firstBad([listenRow, titleRow, redirectRow]);
|
const bad = firstBad([listenRow, redirectRow]);
|
||||||
if (bad) {
|
if (bad) {
|
||||||
notify(bad, 'warning');
|
notify(bad, 'warning');
|
||||||
return;
|
return;
|
||||||
@@ -399,7 +397,6 @@ export function portalCard(host: SettingsHost): HTMLElement {
|
|||||||
portal_host: picked[0] ?? '',
|
portal_host: picked[0] ?? '',
|
||||||
portal_alt: picked.slice(1),
|
portal_alt: picked.slice(1),
|
||||||
portal_port: port.value,
|
portal_port: port.value,
|
||||||
portal_title: title.value,
|
|
||||||
portal_redirect: redirect.value.trim(),
|
portal_redirect: redirect.value.trim(),
|
||||||
},
|
},
|
||||||
'Saved',
|
'Saved',
|
||||||
|
|||||||
@@ -47,7 +47,9 @@
|
|||||||
.dl-pgrid.flush { padding: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
.dl-pgrid.flush { padding: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||||
@media (max-width: 640px) { .dl-pgrid.flush { grid-template-columns: minmax(0, 1fr); } }
|
@media (max-width: 640px) { .dl-pgrid.flush { grid-template-columns: minmax(0, 1fr); } }
|
||||||
.dl-qr-pane { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
|
.dl-qr-pane { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
|
||||||
.dl-qr { width: min(280px, 72vw); aspect-ratio: 1; background: #fff; padding: 8px; border-radius: 12px; box-shadow: inset 0 0 0 1px var(--dl-line); }
|
.dl-qr { width: min(280px, 72vw); aspect-ratio: 1; background: #0a0a0a; border-radius: 18px; overflow: hidden; }
|
||||||
|
/* The portal's round look: its own card colour (black at night, white by day), the light one ringed. */
|
||||||
|
.dl-qr.light { background: #fff; box-shadow: inset 0 0 0 1px var(--dl-line); }
|
||||||
.dl-qr svg { display: block; width: 100%; height: 100%; }
|
.dl-qr svg { display: block; width: 100%; height: 100%; }
|
||||||
.dl-filecard { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: var(--dl-soft); min-width: 0; }
|
.dl-filecard { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: var(--dl-soft); min-width: 0; }
|
||||||
.dl-filecard > .dl-stack { flex: 1; min-width: 0; }
|
.dl-filecard > .dl-stack { flex: 1; min-width: 0; }
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// A device's QR code, in the portal's round look: light dots on black on the
|
||||||
|
// dark theme, the same dots dark on white on a light one (shared/qr.ts).
|
||||||
|
|
||||||
|
import { qrSvg } from '../../shared/qr';
|
||||||
|
import { svg } from './layout';
|
||||||
|
import { isDark } from './theme';
|
||||||
|
|
||||||
|
export function qrCode(text: string): HTMLElement {
|
||||||
|
const dark = isDark();
|
||||||
|
return svg(qrSvg(text, 3, true, dark ? 'night' : 'day'), `dl-qr${dark ? '' : ' light'}`);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Which theme the admin shows: Outline switches light and dark in place with
|
||||||
|
// html[data-darkmode]; without it, the system's choice. Read where something
|
||||||
|
// is drawn in the theme's own colours (the map, QR codes).
|
||||||
|
|
||||||
|
export function isDark(): boolean {
|
||||||
|
const attr = document.documentElement.getAttribute('data-darkmode');
|
||||||
|
if (attr != null) return attr === 'true';
|
||||||
|
return window.matchMedia?.('(prefers-color-scheme: dark)').matches ?? false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// The portal's API: one fetch per call to the router, under the personal link.
|
||||||
|
// No sessions and no cookies: the code in the path is the key. A refused call
|
||||||
|
// throws an ApiError carrying the status and, for a plain-HTTP visitor, the
|
||||||
|
// HTTPS twin of the link.
|
||||||
|
|
||||||
|
import { base } from './state';
|
||||||
|
|
||||||
|
export class ApiError extends Error {
|
||||||
|
constructor(
|
||||||
|
public status: number,
|
||||||
|
message: string,
|
||||||
|
/** The HTTPS twin of this link, when the answer was "not over plain HTTP". */
|
||||||
|
public httpsUrl?: string,
|
||||||
|
) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function call<T>(path: string, body?: unknown): Promise<T> {
|
||||||
|
const res = await fetch(`${base}/api/${path}`, {
|
||||||
|
method: body === undefined ? 'GET' : 'POST',
|
||||||
|
credentials: 'omit',
|
||||||
|
headers: body === undefined ? {} : { 'Content-Type': 'application/json' },
|
||||||
|
body: body === undefined ? undefined : JSON.stringify(body),
|
||||||
|
cache: 'no-store',
|
||||||
|
});
|
||||||
|
// Any shape: an error answer may be empty or not JSON at all.
|
||||||
|
let data: { error?: string; https_url?: string } | null = null;
|
||||||
|
try {
|
||||||
|
data = await res.json();
|
||||||
|
} catch {
|
||||||
|
/* empty */
|
||||||
|
}
|
||||||
|
if (!res.ok) throw new ApiError(res.status, data?.error ?? `Request failed (${res.status})`, data?.https_url || undefined);
|
||||||
|
return data as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The link stopped working (code regenerated, person removed). */
|
||||||
|
export const gone = (e: unknown) => e instanceof ApiError && (e.status === 404 || e.status === 401);
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
// The days and hours the access section draws, as plain data: the weeks left
|
||||||
|
// as a calendar, the admin's hours moved into the visitor's time, the month as
|
||||||
|
// one bar a day. Pure (no DOM): page/access.ts draws it; dates are the
|
||||||
|
// router's (`today` from its state), never the browser's calendar.
|
||||||
|
|
||||||
|
import { addDays, parseDay } from '../shared/format';
|
||||||
|
|
||||||
|
export type CellKind = 'past' | 'today' | 'left' | 'end' | 'after';
|
||||||
|
export interface Cell {
|
||||||
|
day: string;
|
||||||
|
kind: CellKind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The weeks from this one to the one the access ends in, Monday first, one
|
||||||
|
* cell a day: gone, today, left, the last day, after it. Null when that would
|
||||||
|
* take more than `maxWeeks` (far ends: the number of days says it alone).
|
||||||
|
*/
|
||||||
|
export function calendar(today: string, end: string, maxWeeks = 10): Cell[] | null {
|
||||||
|
const dow = (d: string) => (parseDay(d).getDay() + 6) % 7;
|
||||||
|
const first = addDays(today, -dow(today));
|
||||||
|
const last = addDays(end, 6 - dow(end));
|
||||||
|
const cells: Cell[] = [];
|
||||||
|
for (let d = first; d <= last; d = addDays(d, 1)) {
|
||||||
|
cells.push({ day: d, kind: d < today ? 'past' : d === today ? 'today' : d < end ? 'left' : d === end ? 'end' : 'after' });
|
||||||
|
if (cells.length > maxWeeks * 7) return null;
|
||||||
|
}
|
||||||
|
return cells;
|
||||||
|
}
|
||||||
|
|
||||||
|
const HM = /^([01]?\d|2[0-3]):([0-5]\d)$/;
|
||||||
|
/** "08:30" → 510, or null for anything else. */
|
||||||
|
export function minuteOf(t: string): number | null {
|
||||||
|
const m = HM.exec(t.trim());
|
||||||
|
return m ? +m[1] * 60 + +m[2] : null;
|
||||||
|
}
|
||||||
|
const wrap = (m: number) => ((m % 1440) + 1440) % 1440;
|
||||||
|
export const clockOf = (m: number) => `${String(Math.floor(wrap(m) / 60)).padStart(2, '0')}:${String(wrap(m) % 60).padStart(2, '0')}`;
|
||||||
|
|
||||||
|
export interface Hours {
|
||||||
|
/** Start and end, minutes after midnight in the visitor's time. */
|
||||||
|
from: number;
|
||||||
|
to: number;
|
||||||
|
/** In the visitor's time (the router told its offset), or the router's own. */
|
||||||
|
yours: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The admin's hours ("08:00-22:00", router time) in the visitor's time. The
|
||||||
|
* offsets are minutes east of UTC; without the router's offset the hours stay
|
||||||
|
* in the router's time. Null when they cannot be read.
|
||||||
|
*/
|
||||||
|
export function hoursFor(hours: string, routerOffset: number | undefined, visitorOffset: number): Hours | null {
|
||||||
|
const [a, b] = hours.split('-');
|
||||||
|
const from = minuteOf(a ?? '');
|
||||||
|
const to = minuteOf(b ?? '');
|
||||||
|
if (from == null || to == null) return null;
|
||||||
|
const shift = routerOffset == null ? 0 : visitorOffset - routerOffset;
|
||||||
|
return { from: wrap(from + shift), to: wrap(to + shift), yours: routerOffset != null };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The window as stretches of the day: one, or two when it runs past midnight. */
|
||||||
|
export const stretches = (h: Hours): [number, number][] =>
|
||||||
|
h.from < h.to
|
||||||
|
? [[h.from, h.to]]
|
||||||
|
: [
|
||||||
|
[h.from, 1440],
|
||||||
|
[0, h.to],
|
||||||
|
];
|
||||||
|
|
||||||
|
/** The moment `nowSec` (epoch seconds) as minutes after midnight at `offset` minutes east of UTC. */
|
||||||
|
export const minuteAt = (nowSec: number, offset: number) => wrap(Math.floor(nowSec / 60) + offset);
|
||||||
|
|
||||||
|
/** The days of today's month: how many, and which one today is (1-based). */
|
||||||
|
export function monthOf(today: string): { days: number; day: number } {
|
||||||
|
const d = parseDay(today);
|
||||||
|
return { days: new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate(), day: d.getDate() };
|
||||||
|
}
|
||||||
@@ -1,12 +1,22 @@
|
|||||||
// The portal's two DOM builders: an element from a tag, attributes and
|
// The portal's DOM builders: an element from a tag, attributes and children;
|
||||||
// children, and an icon. No framework; shared by the page (main.ts) and the
|
// an icon; markup that is ours (icons, glass icons, QR codes) as an element.
|
||||||
// pieces drawn outside it (waitpath.ts).
|
// No framework. The page's CSP forbids inline styles, so nothing here writes a
|
||||||
|
// `style` attribute: styles set from script go through `el.style`.
|
||||||
|
|
||||||
import { iconSvg } from '../shared/icons';
|
import { iconSvg } from '../shared/icons';
|
||||||
|
|
||||||
export type Attrs = Record<string, string | number | boolean | EventListener | null | undefined>;
|
export type Attrs = Record<string, string | number | boolean | EventListener | null | undefined>;
|
||||||
export type Kid = Node | string | null | undefined | false | Kid[];
|
export type Kid = Node | string | null | undefined | false | Kid[];
|
||||||
|
|
||||||
|
function append(el: Node, kids: Kid[]) {
|
||||||
|
const add = (c: Kid) => {
|
||||||
|
if (c == null || c === false) return;
|
||||||
|
if (Array.isArray(c)) c.forEach(add);
|
||||||
|
else el.appendChild(typeof c === 'string' ? document.createTextNode(c) : c);
|
||||||
|
};
|
||||||
|
kids.forEach(add);
|
||||||
|
}
|
||||||
|
|
||||||
export function h(tag: string, attrs: Attrs = {}, ...kids: Kid[]): HTMLElement {
|
export function h(tag: string, attrs: Attrs = {}, ...kids: Kid[]): HTMLElement {
|
||||||
const el = document.createElement(tag);
|
const el = document.createElement(tag);
|
||||||
for (const [k, v] of Object.entries(attrs)) {
|
for (const [k, v] of Object.entries(attrs)) {
|
||||||
@@ -16,17 +26,22 @@ export function h(tag: string, attrs: Attrs = {}, ...kids: Kid[]): HTMLElement {
|
|||||||
else if (v === true) el.setAttribute(k, '');
|
else if (v === true) el.setAttribute(k, '');
|
||||||
else el.setAttribute(k, String(v));
|
else el.setAttribute(k, String(v));
|
||||||
}
|
}
|
||||||
const add = (c: Kid) => {
|
append(el, kids);
|
||||||
if (c == null || c === false) return;
|
|
||||||
if (Array.isArray(c)) c.forEach(add);
|
|
||||||
else el.appendChild(typeof c === 'string' ? document.createTextNode(c) : c);
|
|
||||||
};
|
|
||||||
kids.forEach(add);
|
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ic(name: string): HTMLElement {
|
/** Replace what `el` holds with `kids` (nested lists flattened, empty ones skipped). */
|
||||||
const s = h('span', { class: 'ic' });
|
export function put(el: HTMLElement, ...kids: Kid[]) {
|
||||||
s.innerHTML = iconSvg(name, 'ic-svg');
|
el.replaceChildren();
|
||||||
return s;
|
append(el, kids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Our own markup (never anything a visitor or the router typed) as one element. */
|
||||||
|
export function markup(html: string): Element {
|
||||||
|
const t = document.createElement('template');
|
||||||
|
t.innerHTML = html.trim();
|
||||||
|
return t.content.firstElementChild!;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A line icon (`svg.i`, stroke = currentColor), sized by CSS. */
|
||||||
|
export const ic = (name: string, cls = 'i'): Element => markup(iconSvg(name, cls));
|
||||||
@@ -0,0 +1,214 @@
|
|||||||
|
// Adding a device: what it is (four kinds; phones and tablets are one choice,
|
||||||
|
// the same apps and the same smaller packets) and its name, guessed from the
|
||||||
|
// browser when it is this device; then straight on to its set-up. Or the page
|
||||||
|
// opens on the device itself, from a code, ready to add it there.
|
||||||
|
|
||||||
|
import type { ClientConfig, Kind } from '../../shared/types';
|
||||||
|
import { KIND_LABEL } from '../../shared/format';
|
||||||
|
import { ApiError, call } from '../api';
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { EASE_OUT, play } from '../motion';
|
||||||
|
import { addLink } from '../setup';
|
||||||
|
import { pageUrl, repaint, setState, state, type State } from '../state';
|
||||||
|
import { linkRow, qrBox } from '../ui/codes';
|
||||||
|
import { once, toast } from '../ui/feedback';
|
||||||
|
import { glass } from '../ui/glass';
|
||||||
|
import { morphText } from '../ui/morph';
|
||||||
|
import { go, head, hint, openSheet, sub, type View } from '../ui/sheet';
|
||||||
|
import { secureFirst, showSecure } from './secure';
|
||||||
|
import { continueSetup } from './setup-view';
|
||||||
|
|
||||||
|
// Best guess at the device this page is open on (the browser never tells its real name).
|
||||||
|
const UA = navigator.userAgent;
|
||||||
|
const IPAD = /iPad/.test(UA) || (/Macintosh/.test(UA) && navigator.maxTouchPoints > 1);
|
||||||
|
|
||||||
|
function guessKind(): Kind {
|
||||||
|
if (IPAD || /Tablet/i.test(UA) || (/Android/.test(UA) && !/Mobile/.test(UA))) return 'tablet';
|
||||||
|
if (/Android|iPhone|Mobile/i.test(UA)) return 'phone';
|
||||||
|
return 'computer';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Samsung model codes → names people know (S and A series; the code stays in brackets). */
|
||||||
|
const GALAXY: [RegExp, string][] = [
|
||||||
|
[/^SM-S93/, 'Galaxy S25'],
|
||||||
|
[/^SM-S92/, 'Galaxy S24'],
|
||||||
|
[/^SM-S91/, 'Galaxy S23'],
|
||||||
|
[/^SM-S90/, 'Galaxy S22'],
|
||||||
|
[/^SM-G99/, 'Galaxy S21'],
|
||||||
|
[/^SM-F9/, 'Galaxy Z Fold'],
|
||||||
|
[/^SM-F7/, 'Galaxy Z Flip'],
|
||||||
|
[/^SM-A5/, 'Galaxy A5x'],
|
||||||
|
[/^SM-A3/, 'Galaxy A3x'],
|
||||||
|
[/^SM-X/, 'Galaxy Tab'],
|
||||||
|
];
|
||||||
|
|
||||||
|
/** Android model from Client Hints (Chrome); filled in shortly after the page loads. */
|
||||||
|
let MODEL = '';
|
||||||
|
const modelReady: Promise<string> = (async () => {
|
||||||
|
const uad = (navigator as Navigator & { userAgentData?: { getHighEntropyValues(h: string[]): Promise<{ model?: string }> } })
|
||||||
|
.userAgentData;
|
||||||
|
if (!uad || !/Android/.test(UA)) return '';
|
||||||
|
try {
|
||||||
|
const m = ((await uad.getHighEntropyValues(['model'])).model ?? '').trim();
|
||||||
|
if (!m || m === 'K') return '';
|
||||||
|
const g = GALAXY.find(([re]) => re.test(m));
|
||||||
|
MODEL = g ? `${g[1]} (${m})` : /^SM-/.test(m) ? `Galaxy ${m}` : m;
|
||||||
|
} catch {
|
||||||
|
/* not offered */
|
||||||
|
}
|
||||||
|
return MODEL;
|
||||||
|
})();
|
||||||
|
|
||||||
|
function guessName(kind: Kind): string {
|
||||||
|
if (/iPhone/.test(UA)) return 'iPhone';
|
||||||
|
if (IPAD) return 'iPad';
|
||||||
|
if (/Android/.test(UA)) return MODEL || (kind === 'tablet' ? 'Android tablet' : 'Android phone');
|
||||||
|
if (/CrOS/.test(UA)) return 'Chromebook';
|
||||||
|
if (/Mac OS X/.test(UA)) return 'Mac';
|
||||||
|
if (/Windows/.test(UA)) return 'Windows PC';
|
||||||
|
if (/Linux/.test(UA)) return 'Linux PC';
|
||||||
|
return KIND_LABEL[kind];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Phones and tablets are one choice. The device is still kept as a phone or a
|
||||||
|
* tablet (the lines say "the tablet"): on the device itself the browser tells
|
||||||
|
* which; picked from elsewhere it is a phone.
|
||||||
|
*/
|
||||||
|
type Pick = 'computer' | 'mobile' | 'router' | 'other';
|
||||||
|
const PICK_LABEL: Record<Pick, string> = { computer: 'PC', mobile: 'Mobile', router: 'Router', other: 'Other' };
|
||||||
|
const pickOf = (k: Kind): Pick => (k === 'phone' || k === 'tablet' ? 'mobile' : k);
|
||||||
|
const kindOf = (p: Pick): Kind => (p !== 'mobile' ? p : guessKind() === 'tablet' ? 'tablet' : 'phone');
|
||||||
|
|
||||||
|
export function startAdd() {
|
||||||
|
const st = state();
|
||||||
|
if (!st || st.locked) return;
|
||||||
|
if (!st.can_add) return toast(`You have reached your limit of ${st.person.device_limit} devices`, true);
|
||||||
|
if (secureFirst()) return;
|
||||||
|
openSheet(vAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
function vAdd(): View {
|
||||||
|
const st = state()!;
|
||||||
|
const p = st.person;
|
||||||
|
// The kinds this router takes, as the four choices.
|
||||||
|
const picks = (['computer', 'mobile', 'router', 'other'] as Pick[]).filter((k) => st.kinds.some((x) => pickOf(x) === k));
|
||||||
|
let pick: Pick = picks.includes(pickOf(guessKind())) ? pickOf(guessKind()) : picks[0];
|
||||||
|
let edited = false;
|
||||||
|
const taken = new Set(p.devices.map((d) => d.name.toLowerCase()));
|
||||||
|
const suggest = (k: Pick) => {
|
||||||
|
const n = k === pickOf(guessKind()) ? guessName(kindOf(k)) : k === 'mobile' ? 'Phone' : KIND_LABEL[k];
|
||||||
|
if (!taken.has(n.toLowerCase())) return n;
|
||||||
|
for (let i = 2; i < 20; i++) if (!taken.has(`${n} ${i}`.toLowerCase())) return `${n} ${i}`;
|
||||||
|
return n;
|
||||||
|
};
|
||||||
|
|
||||||
|
const kinds = h('div', { class: 'kinds', role: 'radiogroup', 'aria-label': 'What is it?' });
|
||||||
|
kinds.style.setProperty('--n', String(picks.length));
|
||||||
|
const tiles = picks.map((k) => {
|
||||||
|
const t = h(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'kind', role: 'radio', 'aria-label': PICK_LABEL[k], onclick: () => choose(k) },
|
||||||
|
h('span', { class: 'kind-tile' }, glass(k, 'blue')),
|
||||||
|
h('span', { class: 'kind-lbl' }, PICK_LABEL[k]),
|
||||||
|
);
|
||||||
|
kinds.appendChild(t);
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
const input = h('input', { type: 'text', maxlength: 48, required: true, 'aria-label': 'Name', autocomplete: 'off' }) as HTMLInputElement;
|
||||||
|
const goBtn = h('button', { class: 'go ready', type: 'submit', 'aria-label': 'Create connection' }, ic('arrow')) as HTMLButtonElement;
|
||||||
|
const err = h('p', { class: 'hint bad-t', hidden: true });
|
||||||
|
const say = (msg: string) => {
|
||||||
|
// Already showing: its words change in place.
|
||||||
|
if (!err.hidden) return morphText(err, msg);
|
||||||
|
err.textContent = msg;
|
||||||
|
err.hidden = false;
|
||||||
|
play(
|
||||||
|
err,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: 'translateY(-4px)' },
|
||||||
|
{ opacity: 1, transform: 'none' },
|
||||||
|
],
|
||||||
|
{ duration: 220, easing: EASE_OUT },
|
||||||
|
);
|
||||||
|
};
|
||||||
|
input.value = suggest(pick);
|
||||||
|
input.addEventListener('input', () => {
|
||||||
|
edited = true;
|
||||||
|
goBtn.classList.toggle('ready', !!input.value.trim());
|
||||||
|
err.hidden = true;
|
||||||
|
});
|
||||||
|
// The Android model arrives a moment later: use it unless they started typing.
|
||||||
|
void modelReady.then(() => {
|
||||||
|
if (!edited && pick === pickOf(guessKind())) input.value = suggest(pick);
|
||||||
|
});
|
||||||
|
// The picked tile rings itself where it stands (the ring does not travel between tiles).
|
||||||
|
function choose(k: Pick) {
|
||||||
|
pick = k;
|
||||||
|
tiles.forEach((t, i) => {
|
||||||
|
const on = picks[i] === k;
|
||||||
|
t.classList.toggle('on', on);
|
||||||
|
t.setAttribute('aria-checked', String(on));
|
||||||
|
});
|
||||||
|
if (!edited) {
|
||||||
|
input.value = suggest(k);
|
||||||
|
goBtn.classList.add('ready');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
choose(pick);
|
||||||
|
|
||||||
|
const form = h('form', { class: 'field', autocomplete: 'off' }, input, goBtn);
|
||||||
|
form.addEventListener('submit', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const name = input.value.trim();
|
||||||
|
if (!name) return;
|
||||||
|
if (taken.has(name.toLowerCase())) return say('You already have a device with this name.');
|
||||||
|
void once(goBtn, async () => {
|
||||||
|
try {
|
||||||
|
const r = await call<{ id: string; config: ClientConfig; state: State }>('devices', { name, kind: kindOf(pick) });
|
||||||
|
setState(r.state);
|
||||||
|
repaint({ pop: r.id });
|
||||||
|
const dev = r.state.person.devices.find((d) => d.id === r.id)!;
|
||||||
|
await continueSetup(dev, r.config);
|
||||||
|
} catch (er) {
|
||||||
|
if (er instanceof ApiError && er.httpsUrl) return showSecure(er.httpsUrl);
|
||||||
|
say((er as Error).message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const viaLink = h(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'btn soft block', onclick: () => go(vLink) },
|
||||||
|
ic('qr'),
|
||||||
|
h('span', {}, 'Add it from the device'),
|
||||||
|
);
|
||||||
|
const free = p.device_limit - p.devices.length;
|
||||||
|
const el = h(
|
||||||
|
'div',
|
||||||
|
{ class: 'view' },
|
||||||
|
head('Add a device'),
|
||||||
|
sub(`${free} of ${p.device_limit} slots free`),
|
||||||
|
kinds,
|
||||||
|
hint('Phones and tablets get a smaller packet size that suits mobile networks.'),
|
||||||
|
form,
|
||||||
|
err,
|
||||||
|
h('div', { class: 'or' }, 'OR'),
|
||||||
|
viaLink,
|
||||||
|
);
|
||||||
|
el.querySelector('.hint')!.classList.add('kinds-note');
|
||||||
|
return { el, label: 'Add a device' };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The page on the device itself, ready to add it: the link as a code for its camera, and as text. */
|
||||||
|
function vLink(): View {
|
||||||
|
const link = addLink(pageUrl());
|
||||||
|
const el = h(
|
||||||
|
'div',
|
||||||
|
{ class: 'view' },
|
||||||
|
head('Open on the device', { back: true }),
|
||||||
|
sub('Point its camera at the code: your page opens there with this device ready to add.'),
|
||||||
|
qrBox(link, true),
|
||||||
|
linkRow(link),
|
||||||
|
);
|
||||||
|
return { el, label: 'Open on the device' };
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
// A device's own actions from its ⋯ menu: Rename, Reconnect (new keys, then
|
||||||
|
// the set-up of the new ones) and Remove. A question comes before what cannot
|
||||||
|
// be undone; the action's button stays busy until the router answers.
|
||||||
|
|
||||||
|
import type { ClientConfig, Device } from '../../shared/types';
|
||||||
|
import { call } from '../api';
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { EASE_IN, play } from '../motion';
|
||||||
|
import { repaint, setState, state, type State } from '../state';
|
||||||
|
import { once, toast } from '../ui/feedback';
|
||||||
|
import { glass, type Tone } from '../ui/glass';
|
||||||
|
import { closeSheet, head, onClosed, openSheet, type View } from '../ui/sheet';
|
||||||
|
import { secureFirst } from './secure';
|
||||||
|
import { continueSetup } from './setup-view';
|
||||||
|
|
||||||
|
/** A question before something that cannot be undone: the action's icon in its colour, what happens, Cancel and the action. */
|
||||||
|
function ask(o: { icon: string; tone: Tone; title: string; text: string; action: string; cls: string; run: () => Promise<void> }): View {
|
||||||
|
const ok = h(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: `btn ${o.cls}`, onclick: (ev: Event) => once(ev.currentTarget as HTMLButtonElement, o.run) },
|
||||||
|
// In an element: a busy button blurs its content away for the orb (ui/busy.ts).
|
||||||
|
h('span', {}, o.action),
|
||||||
|
) as HTMLButtonElement;
|
||||||
|
const el = h(
|
||||||
|
'div',
|
||||||
|
{ class: 'view' },
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'center-col ask' },
|
||||||
|
glass(o.icon, o.tone, 'gi xl'),
|
||||||
|
h('h3', {}, o.title),
|
||||||
|
h('p', {}, o.text),
|
||||||
|
h('div', { class: 'btnrow' }, h('button', { type: 'button', class: 'btn soft', onclick: () => closeSheet() }, 'Cancel'), ok),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return { el, label: o.title, asks: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function rename(d: Device) {
|
||||||
|
openSheet(() => {
|
||||||
|
const input = h('input', { type: 'text', maxlength: 48, 'aria-label': 'Device name', autocomplete: 'off' }) as HTMLInputElement;
|
||||||
|
input.value = d.name;
|
||||||
|
const save = h('button', { class: 'go', type: 'submit', 'aria-label': 'Save' }, ic('check')) as HTMLButtonElement;
|
||||||
|
input.addEventListener('input', () => save.classList.toggle('ready', !!input.value.trim() && input.value.trim() !== d.name));
|
||||||
|
const form = h('form', { class: 'field', autocomplete: 'off' }, input, save);
|
||||||
|
form.addEventListener('submit', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const name = input.value.trim();
|
||||||
|
if (!name || name === d.name) return;
|
||||||
|
void once(save, async () => {
|
||||||
|
try {
|
||||||
|
const r = await call<{ state: State }>(`devices/${d.id}`, { action: 'rename', name });
|
||||||
|
setState(r.state);
|
||||||
|
onClosed(() => {
|
||||||
|
repaint();
|
||||||
|
toast('Renamed');
|
||||||
|
});
|
||||||
|
closeSheet();
|
||||||
|
} catch (er) {
|
||||||
|
toast((er as Error).message, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
setTimeout(() => input.select(), 60);
|
||||||
|
return { el: h('div', { class: 'view' }, head(`Rename ${d.name}`), form), label: `Rename ${d.name}` };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a device up from scratch (a new phone, the app reinstalled, settings the
|
||||||
|
* admin changed): new keys, so what it holds stops working; it shows "Not set
|
||||||
|
* up yet" until it connects with the new configuration, which the sheet goes on to.
|
||||||
|
*/
|
||||||
|
export function reconnect(d: Device) {
|
||||||
|
if (secureFirst()) return;
|
||||||
|
const here = state()?.here === d.id;
|
||||||
|
openSheet(() =>
|
||||||
|
ask({
|
||||||
|
icon: 'refresh',
|
||||||
|
tone: 'orange',
|
||||||
|
title: `Reconnect ${d.name}?`,
|
||||||
|
text: here
|
||||||
|
? 'It gets new keys. This device is connected through its current settings: it disconnects a few seconds after you confirm. Add the new ones that open next.'
|
||||||
|
: 'It gets new keys and its current settings stop working. Set it up again with the new ones that open next.',
|
||||||
|
action: 'Reconnect',
|
||||||
|
cls: 'accent',
|
||||||
|
run: async () => {
|
||||||
|
try {
|
||||||
|
const r = await call<{ config: ClientConfig; state: State }>(`devices/${d.id}`, { action: 'reconnect' });
|
||||||
|
setState(r.state);
|
||||||
|
repaint();
|
||||||
|
await continueSetup(r.state.person.devices.find((x) => x.id === d.id) ?? { ...d, handshake: 0 }, r.config);
|
||||||
|
} catch (er) {
|
||||||
|
toast((er as Error).message, true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeDevice(d: Device) {
|
||||||
|
openSheet(() =>
|
||||||
|
ask({
|
||||||
|
icon: 'trash',
|
||||||
|
tone: 'red',
|
||||||
|
title: `Remove ${d.name}?`,
|
||||||
|
text: 'Its connection stops working at once. You can add it again later.',
|
||||||
|
action: 'Remove',
|
||||||
|
cls: 'red',
|
||||||
|
run: async () => {
|
||||||
|
try {
|
||||||
|
const r = await call<{ state: State }>(`devices/${d.id}`, { action: 'delete' });
|
||||||
|
setState(r.state);
|
||||||
|
// The card goes first; the rest then glide into its place.
|
||||||
|
onClosed(() => {
|
||||||
|
const card = document.querySelector(`.dev[data-id="${CSS.escape(d.id)}"]`);
|
||||||
|
const done = () => {
|
||||||
|
repaint();
|
||||||
|
toast('Device removed');
|
||||||
|
};
|
||||||
|
if (!card) return done();
|
||||||
|
play(
|
||||||
|
card,
|
||||||
|
[
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
{ opacity: 0, transform: 'scale(.9)', filter: 'blur(6px)' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: 220,
|
||||||
|
easing: EASE_IN,
|
||||||
|
fill: 'forwards',
|
||||||
|
},
|
||||||
|
).onfinish = done;
|
||||||
|
});
|
||||||
|
closeSheet();
|
||||||
|
} catch (er) {
|
||||||
|
toast((er as Error).message, true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
import { h } from '../dom';
|
||||||
|
import { pageUrl } from '../state';
|
||||||
|
import { linkRow, qrBox } from '../ui/codes';
|
||||||
|
import { head, openSheet, sub } from '../ui/sheet';
|
||||||
|
|
||||||
|
export function showPageCode() {
|
||||||
|
openSheet(() => {
|
||||||
|
const url = pageUrl();
|
||||||
|
const el = 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' };
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// A plain-HTTP link (an IP address) shows the page, but keys only travel
|
||||||
|
// encrypted: adding or setting up a device sends the visitor to the HTTPS twin
|
||||||
|
// first. Its certificate is the router's own, so the browser warns once; say so.
|
||||||
|
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { httpsTwin } from '../state';
|
||||||
|
import { glass } from '../ui/glass';
|
||||||
|
import { head, hint, openSheet, sub, type View } from '../ui/sheet';
|
||||||
|
|
||||||
|
function vSecure(url: string): View {
|
||||||
|
const el = h(
|
||||||
|
'div',
|
||||||
|
{ class: 'view' },
|
||||||
|
head('Open the link securely'),
|
||||||
|
sub('Connection settings only travel encrypted'),
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'center-col secure' },
|
||||||
|
glass('lock', 'blue', 'gi xl'),
|
||||||
|
h('p', {}, 'This page is open without encryption. To add or set up a device, open the same link over HTTPS:'),
|
||||||
|
),
|
||||||
|
// The same tab: the HTTPS page replaces this one.
|
||||||
|
h('a', { class: 'btn accent block', href: url }, ic('lock'), h('span', {}, 'Open securely')),
|
||||||
|
hint('The browser may warn that the certificate is not trusted: it is this router’s own. Choose to continue (“Advanced” → “Proceed”).'),
|
||||||
|
);
|
||||||
|
el.lastElementChild!.classList.add('secure-note');
|
||||||
|
return { el, label: 'Open the link securely' };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The HTTPS twin's sheet (here, or the one the router named in a refusal). */
|
||||||
|
export const showSecure = (url: string) => openSheet(() => vSecure(url));
|
||||||
|
|
||||||
|
/** Over plain HTTP: the twin's sheet instead, and true (the caller stops). */
|
||||||
|
export function secureFirst(): boolean {
|
||||||
|
const twin = httpsTwin();
|
||||||
|
if (!twin) return false;
|
||||||
|
showSecure(twin);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,408 @@
|
|||||||
|
// The pieces the set-up sheet is made of: store badges, the step that adds the
|
||||||
|
// connection (a link, the share sheet, a key or a file, as the app and the
|
||||||
|
// device allow), the panel that sends the connection to another device, the
|
||||||
|
// .conf for a router, the Download / Copy keys beside × and the line saying
|
||||||
|
// where an app scans a code. The rules behind them are setup.ts.
|
||||||
|
|
||||||
|
import type { ClientConfig, Device } from '../../shared/types';
|
||||||
|
import { h, ic, type Kid } from '../dom';
|
||||||
|
import { EASE_OUT, POP, SMOOTH, play } from '../motion';
|
||||||
|
import {
|
||||||
|
APP_NAME,
|
||||||
|
PLATFORM_LABEL,
|
||||||
|
importSteps,
|
||||||
|
keyFileName,
|
||||||
|
opensKeyLinks,
|
||||||
|
routerStore,
|
||||||
|
scanPath,
|
||||||
|
storeFor,
|
||||||
|
type AppId,
|
||||||
|
type Platform,
|
||||||
|
type Store,
|
||||||
|
} from '../setup';
|
||||||
|
import { accordion } from '../ui/accordion';
|
||||||
|
import { copy, download, sendFile, shareFile } from '../ui/feedback';
|
||||||
|
import { glass } from '../ui/glass';
|
||||||
|
import { menuLine, morphText, setText } from '../ui/morph';
|
||||||
|
import { hint } from '../ui/sheet';
|
||||||
|
|
||||||
|
export const APP_ICON: Record<AppId, string> = { vpn: 'amnezia', awg: 'amneziawg', wg: 'wireguard' };
|
||||||
|
|
||||||
|
/** The app a device was set up with last time, so the sheet reopens on it. */
|
||||||
|
const memo = (d: Device) => `dl.app.${d.id}`;
|
||||||
|
export function recallApp(d: Device): AppId | null {
|
||||||
|
try {
|
||||||
|
const v = localStorage.getItem(memo(d));
|
||||||
|
return v === 'vpn' || v === 'awg' || v === 'wg' ? v : null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export function rememberApp(d: Device, app: AppId) {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(memo(d), app);
|
||||||
|
} catch {
|
||||||
|
/* private mode */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What the steps work with: the device, its configuration, the key, and the choices made. */
|
||||||
|
export interface SetupCtx {
|
||||||
|
d: Device;
|
||||||
|
cfg: ClientConfig;
|
||||||
|
key: string;
|
||||||
|
/** The platform this page is open on. */
|
||||||
|
pf: Platform;
|
||||||
|
/** "the phone": the device in a sentence. */
|
||||||
|
there: string;
|
||||||
|
app(): AppId;
|
||||||
|
/** The page is open on the device being set up. */
|
||||||
|
same(): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A badge: the mark in a tile, two lines, a chevron (an action) or the open
|
||||||
|
* mark (a store page, in a new tab). `primary`: the one thing to tap in step 2.
|
||||||
|
*/
|
||||||
|
export function badge(
|
||||||
|
st: { href?: string; top: string; main: string; mark: string; onclick?: (ev: Event) => void },
|
||||||
|
primary = false,
|
||||||
|
): HTMLElement {
|
||||||
|
const inner = [
|
||||||
|
h('span', { class: 'b-ic' }, ic(st.mark)),
|
||||||
|
h('span', { class: 'b-t' }, h('span', { class: 'b-top' }, st.top), h('span', { class: 'b-main' }, st.main)),
|
||||||
|
ic(st.onclick || st.href?.startsWith('vpn:') ? 'chevron' : 'open'),
|
||||||
|
];
|
||||||
|
const cls = `badge${primary ? ' primary' : ''}`;
|
||||||
|
if (st.onclick) return h('button', { type: 'button', class: cls, onclick: st.onclick }, inner);
|
||||||
|
// A vpn:// key opens the app in place: no new tab.
|
||||||
|
const app = st.href?.startsWith('vpn:');
|
||||||
|
return h('a', { class: cls, href: st.href, target: app ? null : '_blank', rel: 'noopener noreferrer' }, inner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Where the app comes from: the store (and, on Android, the APK beside it), or a line to go and get it. */
|
||||||
|
export function storeBlock(app: AppId, os: Platform, router: boolean): Kid[] {
|
||||||
|
const st: Store | null = router ? routerStore(app) : storeFor(app, os);
|
||||||
|
if (!st) return [hint(`Get ${APP_NAME[app]} on the ${PLATFORM_LABEL[os]} and come back here.`)];
|
||||||
|
// Android: the store can fail (no Google Play, or it hides the app), so the APK sits beside it.
|
||||||
|
if (st.alt) return [h('div', { class: 'badges2' }, badge(st), badge(st.alt)), hint(st.alt.why)];
|
||||||
|
return [badge(st)];
|
||||||
|
}
|
||||||
|
|
||||||
|
const howto = (steps: [string, string][]) =>
|
||||||
|
h(
|
||||||
|
'ol',
|
||||||
|
{ class: 'howto' },
|
||||||
|
steps.map(([text, bold]) => h('li', {}, text.replace(/ → $/, ' ›'), bold ? [' ', h('b', {}, bold)] : null)),
|
||||||
|
);
|
||||||
|
|
||||||
|
const linkBtn = (label: string, run: (ev: Event) => void) => h('button', { type: 'button', onclick: run }, label);
|
||||||
|
|
||||||
|
/** Step 2: a link for AmneziaVPN, the file for the others, in the words of where they go. */
|
||||||
|
export function connectKids(c: SetupCtx): Kid[] {
|
||||||
|
const app = c.app();
|
||||||
|
const name = APP_NAME[app];
|
||||||
|
const hereHandheld = c.pf === 'ios' || c.pf === 'android';
|
||||||
|
// On the phone being set up, a link opens AmneziaVPN only on Android; an
|
||||||
|
// iPhone takes the key as a .vpn file from the share sheet.
|
||||||
|
const inHand = c.same() && hereHandheld;
|
||||||
|
const copyKey = (ev: Event) => copy(c.key, 'Key copied', ev.currentTarget);
|
||||||
|
const send = app === 'vpn' && inHand && !opensKeyLinks(c.pf) ? shareFile(keyFileName(c.cfg.filename), c.key) : null;
|
||||||
|
if (app === 'vpn' && inHand && (opensKeyLinks(c.pf) || send))
|
||||||
|
return [
|
||||||
|
send
|
||||||
|
? badge({ top: 'Then come back here and tap', main: 'Send to AmneziaVPN', mark: 'amnezia', onclick: () => void send() }, true)
|
||||||
|
: badge({ href: c.key, top: 'Then come back here and tap', main: 'Open in AmneziaVPN', mark: 'amnezia' }, true),
|
||||||
|
hint(
|
||||||
|
send ? 'Pick AmneziaVPN in the share sheet. Not there? ' : 'Nothing opened? ',
|
||||||
|
linkBtn('Copy the key', copyKey),
|
||||||
|
' and add it in the app.',
|
||||||
|
),
|
||||||
|
];
|
||||||
|
if (app === 'vpn')
|
||||||
|
return [
|
||||||
|
badge({ top: 'The connection as one key', main: 'Copy the key', mark: 'copy', onclick: copyKey }, true),
|
||||||
|
howto([
|
||||||
|
['Open AmneziaVPN', ''],
|
||||||
|
['Add server › ', 'Insert key'],
|
||||||
|
['Paste the key and connect', ''],
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
const share = hereHandheld ? shareFile(c.cfg.filename, c.cfg.conf) : null;
|
||||||
|
return [
|
||||||
|
share
|
||||||
|
? badge(
|
||||||
|
{
|
||||||
|
top: c.same() ? `Straight into ${name}` : `Send it to the ${c.there}`,
|
||||||
|
main: 'Share the file',
|
||||||
|
mark: 'share',
|
||||||
|
onclick: () => void share(),
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
: badge(
|
||||||
|
{
|
||||||
|
top: 'Then import it in the app',
|
||||||
|
main: 'Download the file',
|
||||||
|
mark: 'download',
|
||||||
|
onclick: () => download(c.cfg.filename, c.cfg.conf),
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
// In the words of the app where the file goes: the phone in hand, or the computer's system.
|
||||||
|
howto(importSteps(app, c.pf, c.cfg.filename, !!share && c.same())),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A computer set up from elsewhere: the connection to send there, as the key or the file. */
|
||||||
|
export function sendKids(c: SetupCtx): Kid[] {
|
||||||
|
const app = c.app();
|
||||||
|
const btn = (icon: string, label: string, run: (ev: Event) => void) =>
|
||||||
|
h('button', { type: 'button', class: 'btn soft sm', onclick: run }, ic(icon), h('span', { class: 'lbl' }, label));
|
||||||
|
if (app === 'vpn') {
|
||||||
|
const file = keyFileName(c.cfg.filename);
|
||||||
|
const share = !!shareFile(file, c.key);
|
||||||
|
return [
|
||||||
|
h('p', { class: 'desc' }, `Send it to the ${c.there} in a message or a note, then in AmneziaVPN: Add server › Insert key.`),
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'btnrow2' },
|
||||||
|
btn('copy', 'Copy the key', (ev) => copy(c.key, 'Key copied', ev.currentTarget)),
|
||||||
|
btn(share ? 'share' : 'download', share ? 'Share as a file' : 'Download the key', () => sendFile(file, c.key)),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
const share = !!shareFile(c.cfg.filename, c.cfg.conf);
|
||||||
|
return [
|
||||||
|
h('p', { class: 'desc' }, `Send it to the ${c.there}, then import `, h('b', {}, c.cfg.filename), ` in ${APP_NAME[app]}.`),
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'btnrow2' },
|
||||||
|
btn(share ? 'share' : 'download', share ? 'Share the file' : 'Download the file', () => sendFile(c.cfg.filename, c.cfg.conf)),
|
||||||
|
btn('copy', 'Copy the configuration', (ev) => copy(c.cfg.conf, 'Configuration copied', ev.currentTarget)),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One configuration line, highlighted; private and preshared keys masked unless shown. */
|
||||||
|
function confLine(line: string, reveal: boolean): Node {
|
||||||
|
if (/^\s*\[.+\]\s*$/.test(line)) return h('span', { class: 'sec' }, line);
|
||||||
|
const m = /^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(line);
|
||||||
|
if (!m) return document.createTextNode(line);
|
||||||
|
const secret = /^(\s*)(PrivateKey|PresharedKey)\b/.test(line);
|
||||||
|
return h('span', {}, h('span', { class: 'k' }, m[1]), ' ', secret && !reveal ? h('span', { class: 'mask' }, '••••••••••••••••') : m[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The .conf for a router: a file card to download (or share), and the configuration folded, its keys hidden. */
|
||||||
|
export function filePane(cfg: ClientConfig): HTMLElement {
|
||||||
|
let reveal = false;
|
||||||
|
const pre = h('pre', { class: 'conf' });
|
||||||
|
const paint = () =>
|
||||||
|
pre.replaceChildren(...cfg.conf.split('\n').flatMap((l, i) => (i ? ['\n', confLine(l, reveal)] : [confLine(l, reveal)])));
|
||||||
|
paint();
|
||||||
|
const share = !!shareFile(cfg.filename, cfg.conf);
|
||||||
|
const eye = h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
class: 'btn soft sm',
|
||||||
|
onclick: () => {
|
||||||
|
reveal = !reveal;
|
||||||
|
eye.replaceChildren(ic(reveal ? 'x' : 'key'), h('span', {}, reveal ? 'Hide key' : 'Show key'));
|
||||||
|
paint();
|
||||||
|
// A key shown comes into focus out of a blur; hidden again, the mask fades back.
|
||||||
|
pre.querySelectorAll('.mask, .k').forEach((x) =>
|
||||||
|
play(
|
||||||
|
x,
|
||||||
|
[
|
||||||
|
{ filter: 'blur(4px)', opacity: 0.4 },
|
||||||
|
{ filter: 'none', opacity: 1 },
|
||||||
|
],
|
||||||
|
{ duration: 320, easing: EASE_OUT },
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ic('key'),
|
||||||
|
h('span', {}, 'Show key'),
|
||||||
|
);
|
||||||
|
const cp = h(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'btn soft sm', onclick: (ev: Event) => copy(cfg.conf, 'Configuration copied', ev.currentTarget) },
|
||||||
|
ic('copy'),
|
||||||
|
h('span', { class: 'lbl' }, 'Copy'),
|
||||||
|
);
|
||||||
|
const card = h(
|
||||||
|
'div',
|
||||||
|
{ class: 'filecard' },
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'fc-row' },
|
||||||
|
h('span', { class: 'filecard-ic' }, '.conf'),
|
||||||
|
h('span', { class: 't' }, h('span', { class: 'mono' }, cfg.filename), h('span', {}, 'For computers and routers')),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'btn accent sm block', onclick: () => sendFile(cfg.filename, cfg.conf) },
|
||||||
|
ic(share ? 'open' : 'download'),
|
||||||
|
h('span', {}, share ? 'Share file' : 'Download'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const conf = accordion([{ icon: glass('file'), title: 'Configuration', body: [h('div', { class: 'confbar' }, eye, cp), pre] }], {
|
||||||
|
inset: true,
|
||||||
|
});
|
||||||
|
return h('div', { class: 'step-box' }, card, conf.el);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ScanLine {
|
||||||
|
el: HTMLElement;
|
||||||
|
/** Another app picked: its name and its path morph in place. */
|
||||||
|
set(app: AppId): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "In AmneziaWG: + › Create from QR code", with both phone systems' wording where they differ. */
|
||||||
|
export function scanLine(app: AppId): ScanLine {
|
||||||
|
const name = h('span', { class: 'osm-p' }, APP_NAME[app]);
|
||||||
|
const path = menuLine(scanPath(app, 'ios'), scanPath(app, 'android'));
|
||||||
|
return {
|
||||||
|
el: h('span', { class: 'scanline' }, h('span', {}, 'In ', name, ':'), path.el),
|
||||||
|
set(a) {
|
||||||
|
morphText(name, APP_NAME[a], undefined, { whole: true });
|
||||||
|
path.set(scanPath(a, 'ios'), scanPath(a, 'android'));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConnPill {
|
||||||
|
el: HTMLElement;
|
||||||
|
/** The labels follow the app picked. */
|
||||||
|
sync(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Beside ×: 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. Copied: a check, and the tooltip says so.
|
||||||
|
*/
|
||||||
|
export function connPill(get: () => { text: string; msg: string; file: string; app: string }): ConnPill {
|
||||||
|
const tt = h('span', { class: 'tt' });
|
||||||
|
const tm = h('span', { class: 'tt-m' });
|
||||||
|
const tip = h('span', { class: 'hp-tip', 'aria-hidden': 'true' }, tt, tm);
|
||||||
|
const dl = h('button', { type: 'button', class: 'hp-b', onclick: () => sendFile(get().file, get().text) }, ic('download'));
|
||||||
|
const cp = h('button', { type: 'button', class: 'hp-b' }, ic('copy'));
|
||||||
|
const el = h('div', { class: 'hpill', role: 'group', 'aria-label': 'The connection', 'data-key': 'conn' }, dl, cp, tip);
|
||||||
|
|
||||||
|
let tipFor: HTMLElement | null = null;
|
||||||
|
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).
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
const at = (x: number) => `translateX(${x}px) translateX(-50%)`;
|
||||||
|
const glideTo = (x: number) => {
|
||||||
|
const from = getComputedStyle(tip).transform;
|
||||||
|
tip.getAnimations().forEach((a) => a.cancel());
|
||||||
|
tip.style.transform = at(x);
|
||||||
|
play(tip, [{ transform: from }, { transform: at(x) }], { duration: SMOOTH.duration, easing: SMOOTH.easing });
|
||||||
|
};
|
||||||
|
// Another key's words, or "Copied": what the two share slides, the rest morphs; the pill glides with it.
|
||||||
|
const reword = (t: string) => morphText(tt, t);
|
||||||
|
const show = (b: HTMLElement) => {
|
||||||
|
clearTimeout(tipT);
|
||||||
|
if (tipFor === b && tip.classList.contains('on')) return;
|
||||||
|
tipFor = b;
|
||||||
|
if (tip.classList.contains('on')) {
|
||||||
|
const t = words(b);
|
||||||
|
glideTo(centre(b, t));
|
||||||
|
return reword(t);
|
||||||
|
}
|
||||||
|
const up = () => {
|
||||||
|
const t = words(b);
|
||||||
|
setText(tt, t);
|
||||||
|
const x = centre(b, t);
|
||||||
|
tip.getAnimations().forEach((a) => a.cancel());
|
||||||
|
tip.style.transform = at(x);
|
||||||
|
tip.classList.add('on');
|
||||||
|
play(
|
||||||
|
tip,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: `${at(x)} translateY(-3px) scale(.96)`, filter: 'blur(3px)' },
|
||||||
|
{ opacity: 1, transform: at(x), filter: 'blur(0px)' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: 220,
|
||||||
|
easing: EASE_OUT,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
if (performance.now() < warmUntil) up();
|
||||||
|
else tipT = window.setTimeout(up, 420);
|
||||||
|
};
|
||||||
|
const hide = () => {
|
||||||
|
clearTimeout(tipT);
|
||||||
|
tipFor = null;
|
||||||
|
if (!tip.classList.contains('on')) return;
|
||||||
|
warmUntil = performance.now() + 500;
|
||||||
|
tip.classList.remove('on');
|
||||||
|
play(tip, [{ opacity: 1 }, { opacity: 0 }], { duration: 120, easing: 'ease-out' });
|
||||||
|
};
|
||||||
|
for (const b of [dl, cp]) {
|
||||||
|
b.addEventListener('pointerenter', (e) => {
|
||||||
|
if (e.pointerType === 'mouse') show(b);
|
||||||
|
});
|
||||||
|
b.addEventListener('focus', () => {
|
||||||
|
if (b.matches(':focus-visible')) show(b);
|
||||||
|
});
|
||||||
|
b.addEventListener('blur', hide);
|
||||||
|
}
|
||||||
|
el.addEventListener('pointerleave', hide);
|
||||||
|
|
||||||
|
const icon = (name: string) => {
|
||||||
|
const n = ic(name);
|
||||||
|
cp.querySelector('svg')!.replaceWith(n);
|
||||||
|
play(
|
||||||
|
n,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: 'scale(.6)', filter: 'blur(3px)' },
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
],
|
||||||
|
{ duration: POP.duration, easing: POP.easing },
|
||||||
|
);
|
||||||
|
};
|
||||||
|
// Copied: the key shows a check and the tooltip says so, then both go back.
|
||||||
|
const sayCopy = () => {
|
||||||
|
if (tipFor !== cp || !tip.classList.contains('on')) return;
|
||||||
|
const t = words(cp);
|
||||||
|
glideTo(centre(cp, t));
|
||||||
|
reword(t);
|
||||||
|
};
|
||||||
|
let back = 0;
|
||||||
|
cp.addEventListener('click', () => {
|
||||||
|
const c = get();
|
||||||
|
void copy(c.text, c.msg);
|
||||||
|
clearTimeout(back);
|
||||||
|
if (!cp.classList.contains('done')) {
|
||||||
|
cp.classList.add('done');
|
||||||
|
icon('check');
|
||||||
|
sayCopy();
|
||||||
|
}
|
||||||
|
back = window.setTimeout(() => {
|
||||||
|
cp.classList.remove('done');
|
||||||
|
icon('copy');
|
||||||
|
sayCopy();
|
||||||
|
}, 1600);
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
el,
|
||||||
|
sync() {
|
||||||
|
const app = get().app;
|
||||||
|
dl.setAttribute('aria-label', `Download ${app} config`);
|
||||||
|
cp.setAttribute('aria-label', `Copy ${app} config`);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,254 @@
|
|||||||
|
// Setting a device up: one sheet. Its layout follows where the page is open:
|
||||||
|
// on the device itself, two steps (get the app, add the connection) with a way
|
||||||
|
// round folded under the wait; a router, its packages and the file; a phone or
|
||||||
|
// a tablet set up from elsewhere, its link as a code or the connection as a
|
||||||
|
// code for an app it has; a computer set up from elsewhere, 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).
|
||||||
|
|
||||||
|
import type { ClientConfig, Device } from '../../shared/types';
|
||||||
|
import { vpnKey, vpnQrText } from '../../shared/vpnkey';
|
||||||
|
import { ApiError, call } from '../api';
|
||||||
|
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 } from '../ui/accordion';
|
||||||
|
import { codeRow, linkRow, type CodeRow } from '../ui/codes';
|
||||||
|
import { once, toast } from '../ui/feedback';
|
||||||
|
import { glass } from '../ui/glass';
|
||||||
|
import { morphInto, morphText } from '../ui/morph';
|
||||||
|
import { iconSeg, type IconSeg } from '../ui/seg';
|
||||||
|
import { glide, go, head, onClosed, onLeave, openSheet, sub, type View } from '../ui/sheet';
|
||||||
|
import { notice } from '../page/notices';
|
||||||
|
import { secureFirst, showSecure } from './secure';
|
||||||
|
import {
|
||||||
|
APP_ICON,
|
||||||
|
connPill,
|
||||||
|
connectKids,
|
||||||
|
filePane,
|
||||||
|
recallApp,
|
||||||
|
rememberApp,
|
||||||
|
scanLine,
|
||||||
|
type ScanLine,
|
||||||
|
sendKids,
|
||||||
|
storeBlock,
|
||||||
|
type SetupCtx,
|
||||||
|
} from './setup-parts';
|
||||||
|
import { arrive, waitWay, watchFirstConnection } from './wait';
|
||||||
|
|
||||||
|
async function getConfig(d: Device): Promise<ClientConfig | null> {
|
||||||
|
try {
|
||||||
|
return await call<ClientConfig>(`devices/${d.id}/config`);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof ApiError && e.httpsUrl) showSecure(e.httpsUrl);
|
||||||
|
else toast((e as Error).message, true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set up a device from its card: the configuration first (the button waits for it), then the sheet. */
|
||||||
|
export async function openSetup(d: Device, from?: EventTarget | null) {
|
||||||
|
if (secureFirst()) return;
|
||||||
|
const run = async () => {
|
||||||
|
const cfg = await getConfig(d);
|
||||||
|
if (!cfg) return;
|
||||||
|
const key = await vpnKey(cfg, cfg.server);
|
||||||
|
openSheet(() => setupView(d, cfg, key));
|
||||||
|
};
|
||||||
|
if (from instanceof HTMLButtonElement) await once(from, run);
|
||||||
|
else await run();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Further in a flow (Add, Reconnect): the configuration the router just sent, in the open sheet. */
|
||||||
|
export async function continueSetup(d: Device, cfg: ClientConfig) {
|
||||||
|
const key = await vpnKey(cfg, cfg.server);
|
||||||
|
go(() => setupView(d, cfg, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A numbered step: its number, a title, what to do. */
|
||||||
|
function step(n: string, title: Node | string, kids: (Node | null)[]): HTMLElement {
|
||||||
|
return h(
|
||||||
|
'div',
|
||||||
|
{ class: 'step' },
|
||||||
|
h('span', { class: 'step-n' }, n),
|
||||||
|
h('div', { class: 'step-b' }, typeof title === 'string' ? h('span', { class: 'step-t' }, title) : title, kids),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fold a block away (height, then gone) or bring it back; `instant` without motion. */
|
||||||
|
function foldBlock(el: HTMLElement, fold: boolean, instant: boolean) {
|
||||||
|
const cur = el.hidden ? 0 : el.getBoundingClientRect().height;
|
||||||
|
el.getAnimations().forEach((a) => a.cancel());
|
||||||
|
if (instant) {
|
||||||
|
el.hidden = fold;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
el.style.overflow = 'hidden';
|
||||||
|
el.hidden = false;
|
||||||
|
const to = fold ? 0 : el.getBoundingClientRect().height;
|
||||||
|
const [a, b] = fold ? [1, 0] : [0, 1];
|
||||||
|
play(
|
||||||
|
el,
|
||||||
|
[
|
||||||
|
{ height: `${cur}px`, opacity: a, filter: `blur(${4 - a * 4}px)` },
|
||||||
|
{ height: `${to}px`, opacity: b, filter: `blur(${4 - b * 4}px)` },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: SMOOTH.duration,
|
||||||
|
easing: SMOOTH.easing,
|
||||||
|
},
|
||||||
|
).onfinish = () => {
|
||||||
|
el.style.overflow = '';
|
||||||
|
el.hidden = fold;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
type Layout = 'same' | 'router' | 'away' | 'pc-away';
|
||||||
|
|
||||||
|
export function setupView(d: Device, cfg: ClientConfig, key: string): View {
|
||||||
|
const pf = platform();
|
||||||
|
const apps = appsFor(preset());
|
||||||
|
const handheld = d.kind === 'phone' || d.kind === 'tablet';
|
||||||
|
const router = d.kind === 'router';
|
||||||
|
const same = sameDevice(d.kind, pf);
|
||||||
|
const layout: Layout = same ? 'same' : router ? 'router' : handheld ? 'away' : 'pc-away';
|
||||||
|
const there = deviceNoun(d.kind);
|
||||||
|
// A router takes AmneziaWG (or WireGuard), never AmneziaVPN.
|
||||||
|
const choices = apps.filter((a) => !router || a.id !== 'vpn');
|
||||||
|
let app: AppId = recallApp(d) ?? (router ? 'awg' : 'vpn');
|
||||||
|
if (!choices.some((a) => a.id === app)) app = choices[0].id;
|
||||||
|
const c: SetupCtx = { d, cfg, key, pf, there, app: () => app, same: () => same };
|
||||||
|
|
||||||
|
// The pickers and the boxes a pick changes live across repaints: a pick only
|
||||||
|
// refills what it changes, so the pills glide and nothing else in the sheet moves.
|
||||||
|
const segs: IconSeg<AppId>[] = [];
|
||||||
|
const picker = () => {
|
||||||
|
if (choices.length < 2) return null;
|
||||||
|
const s = iconSeg(
|
||||||
|
choices.map((a) => ({ value: a.id, label: a.name, icon: APP_ICON[a.id] })),
|
||||||
|
app,
|
||||||
|
(v) => {
|
||||||
|
app = v;
|
||||||
|
rememberApp(d, v);
|
||||||
|
segs.forEach((x) => x.sync(v));
|
||||||
|
// The sheet glides to its new height; inside, what changed morphs (morphInto).
|
||||||
|
glide(fill);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
segs.push(s);
|
||||||
|
return s.el;
|
||||||
|
};
|
||||||
|
const title1 = h('span', { class: 'step-t' });
|
||||||
|
const getBox = h('div', { class: 'step-box' });
|
||||||
|
const addBox = h('div', { class: 'step-box' });
|
||||||
|
const codeBox = h('div', { class: 'step-box' });
|
||||||
|
const sendBox = h('div', { class: 'step-box' });
|
||||||
|
let code: CodeRow | null = null;
|
||||||
|
let scan: ScanLine | null = null;
|
||||||
|
let codeApp: AppId | null = null;
|
||||||
|
const pill =
|
||||||
|
layout === 'away'
|
||||||
|
? connPill(() => ({
|
||||||
|
...(app === 'vpn'
|
||||||
|
? { text: key, msg: 'Key copied', file: keyFileName(cfg.filename) }
|
||||||
|
: { text: cfg.conf, msg: 'Configuration copied', file: cfg.filename }),
|
||||||
|
app: APP_NAME[app],
|
||||||
|
}))
|
||||||
|
: null;
|
||||||
|
|
||||||
|
/** Everything a pick changes, refilled in place. */
|
||||||
|
function fill() {
|
||||||
|
morphText(title1, router ? `Get ${APP_NAME[app]} on the router` : `Get ${APP_NAME[app]}`, undefined, { whole: true });
|
||||||
|
morphInto(getBox, storeBlock(app, pf, router));
|
||||||
|
// The router's file is the same for either app: it stays as it is (a folded configuration stays folded).
|
||||||
|
if (!router) morphInto(addBox, connectKids(c));
|
||||||
|
else if (!addBox.firstChild) put(addBox, filePane(cfg));
|
||||||
|
const text = app === 'vpn' ? vpnQrText(key) : cfg.conf;
|
||||||
|
// Another app: its words morph in place, the code changes only when it holds something else (codes.ts).
|
||||||
|
if (code && scan && code.el.isConnected) {
|
||||||
|
if (codeApp !== app) {
|
||||||
|
code.swap(text);
|
||||||
|
scan.set(app);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scan = scanLine(app);
|
||||||
|
code = codeRow(text, [scan.el]);
|
||||||
|
codeBox.replaceChildren(code.el);
|
||||||
|
}
|
||||||
|
codeApp = app;
|
||||||
|
morphInto(sendBox, sendKids(c));
|
||||||
|
pill?.sync();
|
||||||
|
}
|
||||||
|
fill();
|
||||||
|
|
||||||
|
// Not on the device: the link goes there (as a code for a phone's camera); the page there does the rest.
|
||||||
|
const linkThere = setupLink(pageUrl(), d.id);
|
||||||
|
const linkBody = () => [
|
||||||
|
handheld
|
||||||
|
? codeRow(linkThere, [h('span', {}, 'Point its camera at the code: the link opens there.')]).el
|
||||||
|
: h('p', { class: 'desc' }, `Open this link on the ${there} to set it up there.`),
|
||||||
|
linkRow(linkThere),
|
||||||
|
];
|
||||||
|
const step1 = () => step('1', title1, [picker(), getBox]);
|
||||||
|
const step2 = () => step('2', router ? 'Import the configuration' : 'Add the connection', [addBox]);
|
||||||
|
|
||||||
|
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.'),
|
||||||
|
);
|
||||||
|
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 round = accordion([{ icon: glass('link'), title: `Not on the ${there} right now?`, body: linkBody() }], {
|
||||||
|
inset: true,
|
||||||
|
onToggle: (_i, open, instant) => foldBlock(steps, open, instant),
|
||||||
|
});
|
||||||
|
body.append(round.el, steps);
|
||||||
|
} else if (layout === 'router') body.append(step1(), step2());
|
||||||
|
// 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: `Open your link on the ${there}`, body: linkBody() },
|
||||||
|
{ icon: glass('app'), title: 'Already has the app', body: [picker(), codeBox] },
|
||||||
|
],
|
||||||
|
{ inset: true, open: 1 },
|
||||||
|
).el,
|
||||||
|
);
|
||||||
|
// A computer set up from somewhere else: 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: `Open your link on the ${there}`, body: linkBody() },
|
||||||
|
{ icon: glass('key'), title: 'Copy or save the connection', body: [picker(), sendBox] },
|
||||||
|
],
|
||||||
|
{ inset: true, open: 0 },
|
||||||
|
).el,
|
||||||
|
);
|
||||||
|
|
||||||
|
const way = waitWay(d);
|
||||||
|
let finished = false;
|
||||||
|
onLeave(
|
||||||
|
watchFirstConnection(
|
||||||
|
d,
|
||||||
|
() => {
|
||||||
|
if (finished) return;
|
||||||
|
finished = true;
|
||||||
|
void arrive(way, body, d);
|
||||||
|
},
|
||||||
|
way.gaveUp,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// Closed before the device connected: the page shows what the polls brought.
|
||||||
|
onClosed(() => repaint());
|
||||||
|
|
||||||
|
const subline =
|
||||||
|
layout === 'same' ? 'Two steps, about a minute' : router ? 'The packages and the file for OpenWrt' : `The app goes on the ${there}.`;
|
||||||
|
const el = h('div', { class: 'view' }, head(`Set up ${d.name}`, { acts: !!pill }), sub(subline), way.el, body);
|
||||||
|
return { el, label: `Set up ${d.name}`, acts: pill?.el ?? null };
|
||||||
|
}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
// Waiting for a new device's first connection: the way from the device to the
|
||||||
|
// server (a light runs along it while the page waits), the polling behind it,
|
||||||
|
// and what happens when it comes: the way fills green and its line morphs into
|
||||||
|
// "<device> connected", the sheet's buttons step away, the steps fold shut,
|
||||||
|
// and the sheet closes by itself onto the page.
|
||||||
|
|
||||||
|
import type { Device } from '../../shared/types';
|
||||||
|
import { gone, call } from '../api';
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { EASE_OUT, play } from '../motion';
|
||||||
|
import { now, repaint, setState, type State } from '../state';
|
||||||
|
import { menuOpen } from '../ui/menu';
|
||||||
|
import { morphText } from '../ui/morph';
|
||||||
|
import { closeSheet, onClosed, scrollTop, settle, showing } from '../ui/sheet';
|
||||||
|
|
||||||
|
export interface Way {
|
||||||
|
el: HTMLElement;
|
||||||
|
connected(): void;
|
||||||
|
gaveUp(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function waitWay(d: Device): Way {
|
||||||
|
const line = h('b', {}, 'Waiting for the connection');
|
||||||
|
const more = h('span', { class: 'ws', hidden: true });
|
||||||
|
const el = h(
|
||||||
|
'div',
|
||||||
|
{ class: 'way', role: 'status', 'aria-live': 'polite' },
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'way-row' },
|
||||||
|
h('span', { class: 'way-end' }, ic(d.kind)),
|
||||||
|
h('span', { class: 'way-track' }, h('span', { class: 'way-glow' }, h('i')), h('span', { class: 'way-fill' })),
|
||||||
|
h('span', { class: 'way-end home' }, ic('server')),
|
||||||
|
),
|
||||||
|
h('div', { class: 'way-text' }, h('span', { class: 't' }, line, more)),
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
el,
|
||||||
|
connected() {
|
||||||
|
el.classList.add('done');
|
||||||
|
morphText(line, `${d.name} connected`);
|
||||||
|
},
|
||||||
|
gaveUp() {
|
||||||
|
el.classList.add('stopped');
|
||||||
|
morphText(line, 'No connection yet');
|
||||||
|
more.textContent = 'Close this and open it again to keep checking.';
|
||||||
|
more.hidden = false;
|
||||||
|
play(
|
||||||
|
line.parentElement!,
|
||||||
|
[
|
||||||
|
{ opacity: 0, filter: 'blur(4px)' },
|
||||||
|
{ opacity: 1, filter: 'none' },
|
||||||
|
],
|
||||||
|
{ duration: 280, easing: EASE_OUT },
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The first connection was seen (a fresh handshake) before the agent's watcher
|
||||||
|
* marked the device online, a second at most: ask again shortly, a few times,
|
||||||
|
* and repaint the page with the answer, so the card goes on to "Connected"
|
||||||
|
* instead of staying on "Last connected just now".
|
||||||
|
*/
|
||||||
|
function catchUp(id: string, tries = 4) {
|
||||||
|
window.setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
const st = await call<State>('state');
|
||||||
|
setState(st);
|
||||||
|
if (!menuOpen()) 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 */
|
||||||
|
}
|
||||||
|
}, 1500);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Poll for the first connection of a device that never connected: 5 s at
|
||||||
|
* first, then slower, for ten minutes at most (then `gaveUp`), not while the
|
||||||
|
* tab is hidden (every poll is a process on the router), and never again once
|
||||||
|
* the link stopped working. `arrived` runs once. Returns the stop function.
|
||||||
|
*/
|
||||||
|
export function watchFirstConnection(d: Device, arrived: () => void, gaveUp: () => void): () => void {
|
||||||
|
// The first connection is a handshake newer than this sheet (router clock), not `online`:
|
||||||
|
// that follows the agent's watcher, which can lag the handshake by a poll, and a device
|
||||||
|
// set up again with new keys still reports the last handshake of its old ones.
|
||||||
|
const opened = now();
|
||||||
|
let timer = 0;
|
||||||
|
let polls = 0;
|
||||||
|
let done = false;
|
||||||
|
const started = Date.now();
|
||||||
|
const poll = async () => {
|
||||||
|
timer = 0;
|
||||||
|
if (done) return;
|
||||||
|
if (Date.now() - started > 600_000) {
|
||||||
|
done = true;
|
||||||
|
gaveUp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (document.hidden) return schedule();
|
||||||
|
try {
|
||||||
|
const st = await call<State>('state');
|
||||||
|
setState(st);
|
||||||
|
const dev = st.person.devices.find((x) => x.id === d.id);
|
||||||
|
if (dev && dev.handshake > opened) {
|
||||||
|
done = true;
|
||||||
|
arrived();
|
||||||
|
if (!dev.online) catchUp(d.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (gone(e)) {
|
||||||
|
done = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
polls++;
|
||||||
|
schedule();
|
||||||
|
};
|
||||||
|
const schedule = () => {
|
||||||
|
if (!done && !timer) timer = window.setTimeout(poll, polls < 6 ? 5000 : polls < 12 ? 15000 : 30000);
|
||||||
|
};
|
||||||
|
const onVisible = () => {
|
||||||
|
if (!document.hidden && !done && !timer) void poll();
|
||||||
|
};
|
||||||
|
document.addEventListener('visibilitychange', onVisible);
|
||||||
|
schedule();
|
||||||
|
return () => {
|
||||||
|
done = true;
|
||||||
|
if (timer) clearTimeout(timer);
|
||||||
|
document.removeEventListener('visibilitychange', onVisible);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const beat = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The first connection arrived. The way fills green and says so (the sheet
|
||||||
|
* goes back up to it if it was scrolled), the buttons beside × step away; then
|
||||||
|
* everything under the way, which did its job, folds shut. Two seconds to read
|
||||||
|
* it, and the sheet closes by itself onto the page, the card ringing green.
|
||||||
|
*/
|
||||||
|
export async function arrive(way: Way, rest: HTMLElement, d: Device) {
|
||||||
|
way.connected();
|
||||||
|
settle();
|
||||||
|
scrollTop();
|
||||||
|
await beat(400);
|
||||||
|
if (!showing(way.el)) return;
|
||||||
|
rest.style.overflow = 'hidden';
|
||||||
|
play(
|
||||||
|
rest,
|
||||||
|
[
|
||||||
|
{ height: `${rest.offsetHeight}px`, opacity: 1, filter: 'none' },
|
||||||
|
{ height: '0px', opacity: 0, filter: 'blur(4px)' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: 520,
|
||||||
|
easing: EASE_OUT,
|
||||||
|
fill: 'forwards',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
play(way.el, [{ marginBottom: '18px' }, { marginBottom: '0px' }], { duration: 520, easing: EASE_OUT, fill: 'forwards' });
|
||||||
|
// Reading time, not motion: the same with less motion.
|
||||||
|
await beat(2400);
|
||||||
|
// Only this sheet: not one the visitor went on to.
|
||||||
|
if (!showing(way.el)) return;
|
||||||
|
onClosed(() => repaint({ flash: d.id }));
|
||||||
|
closeSheet();
|
||||||
|
}
|
||||||
@@ -1,36 +1,91 @@
|
|||||||
// Portal motion: the moves between two states the DOM alone would snap
|
// Portal motion: the springs and curves every animation runs on, the one way
|
||||||
// between — a sheet's height following its content, cards that changed place
|
// to start an animation from script, and the pure decisions behind a sheet
|
||||||
// after a repaint, a pane swapped for another, a sheet pulled down, a copy
|
// pulled down. What moves and when lives with each piece (ui/, page/, flows/);
|
||||||
// button saying it worked. This module measures and starts them; the curves,
|
// one-shot CSS keyframes live in the stylesheets.
|
||||||
// durations and every one-shot keyframe live in portal.css ("Motion").
|
|
||||||
//
|
//
|
||||||
// Everything checks `calm()` (prefers-reduced-motion) and then only fades.
|
// Springs are physical (stiffness, damping) and sampled into CSS `linear()`, so
|
||||||
// The pure decisions (rubber band, when a pull dismisses) are exported for tests.
|
// a transition in CSS and an animation from script follow the same curve:
|
||||||
|
// BOUNCY is the skiper103 accordion (about 11% overshoot), SMOOTH the skiper21
|
||||||
|
// tab pill (critically damped). Reduced motion keeps fades and drops travel.
|
||||||
|
|
||||||
/** The visitor asked for less motion: fades only, nothing travels. */
|
/** 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 => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||||
|
|
||||||
/** The curves of portal.css, for animations started from script. */
|
export interface Spring {
|
||||||
const EASE = {
|
/** Until it settles within 0.15% of the end. */
|
||||||
out: 'cubic-bezier(0.23, 1, 0.32, 1)',
|
duration: number;
|
||||||
in: 'cubic-bezier(0.55, 0, 1, 0.45)',
|
/** The curve as CSS `linear()`. */
|
||||||
drawer: 'cubic-bezier(0.32, 0.72, 0, 1)',
|
easing: string;
|
||||||
};
|
/** Progress at `ms` (overshoots past 1 on a bouncy spring). */
|
||||||
|
at(ms: number): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A spring of stiffness `k` and damping `c` (mass 1), sampled into 64 steps. */
|
||||||
|
export function spring(k: number, c: number, m = 1): Spring {
|
||||||
|
const w0 = Math.sqrt(k / m);
|
||||||
|
const z = c / (2 * Math.sqrt(k * m));
|
||||||
|
const x = (t: number): number => {
|
||||||
|
if (z < 0.999) {
|
||||||
|
const wd = w0 * Math.sqrt(1 - z * z);
|
||||||
|
return 1 - Math.exp(-z * w0 * t) * (Math.cos(wd * t) + ((z * w0) / wd) * Math.sin(wd * t));
|
||||||
|
}
|
||||||
|
if (z <= 1.001) return 1 - Math.exp(-w0 * t) * (1 + w0 * t);
|
||||||
|
const r = Math.sqrt(z * z - 1);
|
||||||
|
const s1 = -w0 * (z - r);
|
||||||
|
const s2 = -w0 * (z + r);
|
||||||
|
return 1 - (s2 * Math.exp(s1 * t) - s1 * Math.exp(s2 * t)) / (s2 - s1);
|
||||||
|
};
|
||||||
|
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;
|
||||||
|
const pts: number[] = [];
|
||||||
|
for (let i = 0; i <= 64; i++) pts.push(+x((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)) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The accordion, the toast, a card that pops in. */
|
||||||
|
export const BOUNCY = spring(300, 20);
|
||||||
|
/** Pills, widths and heights: no overshoot. */
|
||||||
|
export const SMOOTH = spring(300, 35);
|
||||||
|
/** Small things that pop: a check, a menu. */
|
||||||
|
export const POP = spring(520, 24);
|
||||||
|
/** The leading edge of a stretching pill: faster than SMOOTH, no overshoot. */
|
||||||
|
export const LEAD = spring(520, 46);
|
||||||
|
/** A dialog on a computer and the accordions: the menu's pop made softer (about 4% over, 90% there at ~140 ms). */
|
||||||
|
export const SOFT = spring(380, 28);
|
||||||
|
/** What follows the pointer (a menu's highlight): there in about 130 ms, no overshoot. */
|
||||||
|
export const QUICK = spring(900, 60);
|
||||||
|
|
||||||
|
export const EASE_OUT = 'cubic-bezier(0.23, 1, 0.32, 1)';
|
||||||
|
export const EASE_IN = 'cubic-bezier(0.55, 0, 1, 0.45)';
|
||||||
|
export const DRAWER = 'cubic-bezier(0.32, 0.72, 0, 1)';
|
||||||
|
|
||||||
|
/** The springs as CSS variables, for transitions written in the stylesheets. */
|
||||||
|
export function publishSprings(root: HTMLElement) {
|
||||||
|
root.style.setProperty('--spring-bouncy', BOUNCY.easing);
|
||||||
|
root.style.setProperty('--spring-bouncy-dur', `${BOUNCY.duration}ms`);
|
||||||
|
root.style.setProperty('--spring-smooth', SMOOTH.easing);
|
||||||
|
root.style.setProperty('--spring-smooth-dur', `${SMOOTH.duration}ms`);
|
||||||
|
root.style.setProperty('--spring-soft', SOFT.easing);
|
||||||
|
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`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A block inside a sheet animating its own height: the sheet's edge follows it
|
* Start an animation. With reduced motion, an animation that fades keeps only
|
||||||
* frame by frame on its own, so followHeight holds off meanwhile (a count:
|
* its fade (short); one that only moves or resizes jumps to its end.
|
||||||
* several such blocks may move at once).
|
|
||||||
*/
|
*/
|
||||||
function hold(el: Element): () => void {
|
export function play(el: Element, frames: Keyframe[], o: KeyframeAnimationOptions): Animation {
|
||||||
const panel = el.closest<HTMLElement>('.sheet-panel');
|
if (!calm()) return el.animate(frames, o);
|
||||||
if (!panel) return () => undefined;
|
if (frames.some((f) => 'opacity' in f))
|
||||||
panel.dataset.hold = String(+(panel.dataset.hold ?? 0) + 1);
|
return el.animate(
|
||||||
return () => {
|
frames.map((f) => ('opacity' in f ? { opacity: f.opacity } : {})),
|
||||||
const n = +(panel.dataset.hold ?? 1) - 1;
|
{ duration: Math.min(Number(o.duration ?? 200), 160), easing: 'ease-out', fill: o.fill },
|
||||||
if (n > 0) panel.dataset.hold = String(n);
|
);
|
||||||
else delete panel.dataset.hold;
|
return el.animate(frames, { ...o, duration: 0, delay: 0 });
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Distance past an edge → how far it actually goes: resistance grows with the pull. */
|
/** Distance past an edge → how far it actually goes: resistance grows with the pull. */
|
||||||
@@ -46,416 +101,3 @@ export function dismisses(dy: number, velocity: number, height: number): boolean
|
|||||||
if (dy <= 0 || velocity < -0.1) return false;
|
if (dy <= 0 || velocity < -0.1) return false;
|
||||||
return velocity > 0.4 || dy > height / 3;
|
return velocity > 0.4 || dy > height / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A height change takes longer the further it goes, inside the house range. */
|
|
||||||
export const morphMs = (dist: number): number => Math.round(Math.min(380, Math.max(220, 200 + dist * 0.35)));
|
|
||||||
|
|
||||||
/** Restart a one-shot CSS animation class on an element that already had it. */
|
|
||||||
export function replay(el: Element, cls: string) {
|
|
||||||
el.classList.remove(cls);
|
|
||||||
void (el as HTMLElement).offsetWidth;
|
|
||||||
el.classList.add(cls);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keep `panel`'s size following `content`: whatever changes inside (a tab, a
|
|
||||||
* fold, a whole new sheet), the panel eases from the height it shows to the new
|
|
||||||
* one instead of jumping. Interruptible: a change mid-way starts from where it
|
|
||||||
* is. A width change (a window resize) only records, unless the panel asked for
|
|
||||||
* it (`data-morph="width"`: a question turning into a sheet), and then width
|
|
||||||
* and height morph together. Returns the stop.
|
|
||||||
*/
|
|
||||||
export function followHeight(panel: HTMLElement, content: HTMLElement): () => void {
|
|
||||||
let lastH = 0,
|
|
||||||
lastW = 0,
|
|
||||||
widthToo = false;
|
|
||||||
let anim: Animation | null = null;
|
|
||||||
const ro = new ResizeObserver(() => {
|
|
||||||
// Something inside moves its own height (hold): only keep up with the size.
|
|
||||||
if (panel.dataset.hold) {
|
|
||||||
anim?.cancel();
|
|
||||||
panel.classList.remove('morphing', 'morphing-w');
|
|
||||||
lastH = panel.offsetHeight;
|
|
||||||
lastW = panel.offsetWidth;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const cs = getComputedStyle(panel);
|
|
||||||
const shownH = anim ? parseFloat(cs.height) : lastH;
|
|
||||||
const shownW = anim ? parseFloat(cs.width) : lastW;
|
|
||||||
anim?.cancel();
|
|
||||||
// Measure the natural size: without the uncapped width of a morph still under way.
|
|
||||||
panel.classList.remove('morphing', 'morphing-w');
|
|
||||||
const h = panel.offsetHeight,
|
|
||||||
w = panel.offsetWidth;
|
|
||||||
// Asked now, or still on its way from an earlier ask.
|
|
||||||
const asked = panel.dataset.morph === 'width' || widthToo;
|
|
||||||
delete panel.dataset.morph;
|
|
||||||
const resized = lastW !== 0 && w !== lastW;
|
|
||||||
lastH = h;
|
|
||||||
lastW = w;
|
|
||||||
if (!shownH || calm() || (resized && !asked)) return;
|
|
||||||
const dh = Math.abs(h - shownH),
|
|
||||||
dw = asked ? Math.abs(w - shownW) : 0;
|
|
||||||
if (dh < 2 && dw < 2) return;
|
|
||||||
widthToo = dw >= 2;
|
|
||||||
panel.classList.add('morphing');
|
|
||||||
panel.classList.toggle('morphing-w', widthToo);
|
|
||||||
const a = panel.animate(
|
|
||||||
widthToo
|
|
||||||
? [
|
|
||||||
{ height: `${shownH}px`, width: `${shownW}px` },
|
|
||||||
{ height: `${h}px`, width: `${w}px` },
|
|
||||||
]
|
|
||||||
: [{ height: `${shownH}px` }, { height: `${h}px` }],
|
|
||||||
{ duration: morphMs(Math.max(dh, dw)), easing: EASE.out },
|
|
||||||
);
|
|
||||||
anim = a;
|
|
||||||
const done = () => {
|
|
||||||
if (anim !== a) return;
|
|
||||||
anim = null;
|
|
||||||
widthToo = false;
|
|
||||||
panel.classList.remove('morphing', 'morphing-w');
|
|
||||||
};
|
|
||||||
a.onfinish = done;
|
|
||||||
a.oncancel = done;
|
|
||||||
});
|
|
||||||
ro.observe(content);
|
|
||||||
return () => ro.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Swap `box`'s content for `next`: the old content fades out where it was
|
|
||||||
* (lifted out of the flow, so the box already takes the new height) while the
|
|
||||||
* new one comes in. `dir` -1 / 1: the new content comes from the left / right.
|
|
||||||
*/
|
|
||||||
export function swap(box: HTMLElement, next: Node[], dir = 0) {
|
|
||||||
const old = [...box.childNodes];
|
|
||||||
if (!old.length || !box.isConnected) {
|
|
||||||
box.replaceChildren(...next);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// The ghost lays the old content out as the box did, over the box's padding edge.
|
|
||||||
const cs = getComputedStyle(box);
|
|
||||||
const ghost = document.createElement('div');
|
|
||||||
ghost.className = 'ghost';
|
|
||||||
ghost.setAttribute('aria-hidden', 'true');
|
|
||||||
ghost.inert = true;
|
|
||||||
Object.assign(ghost.style, {
|
|
||||||
display: cs.display === 'flex' ? 'flex' : 'block',
|
|
||||||
flexDirection: cs.flexDirection,
|
|
||||||
alignItems: cs.alignItems,
|
|
||||||
gap: cs.gap,
|
|
||||||
top: cs.paddingTop,
|
|
||||||
left: cs.paddingLeft,
|
|
||||||
right: cs.paddingRight,
|
|
||||||
});
|
|
||||||
ghost.append(...old);
|
|
||||||
box.replaceChildren(ghost, ...next);
|
|
||||||
// The old content drops away fast (it sits under the new one, see .ghost) so the two never read together.
|
|
||||||
const still = calm();
|
|
||||||
const out = ghost.animate(
|
|
||||||
[
|
|
||||||
{ opacity: 1, transform: 'none' },
|
|
||||||
{ opacity: 0, transform: still ? 'none' : `translateX(${-dir * 8}px)` },
|
|
||||||
],
|
|
||||||
{ duration: 120, easing: EASE.out, fill: 'forwards' },
|
|
||||||
);
|
|
||||||
const drop = () => ghost.remove();
|
|
||||||
out.onfinish = drop;
|
|
||||||
out.oncancel = drop;
|
|
||||||
for (const n of next)
|
|
||||||
if (n instanceof HTMLElement)
|
|
||||||
n.animate(
|
|
||||||
still
|
|
||||||
? [{ opacity: 0 }, { opacity: 1 }]
|
|
||||||
: [
|
|
||||||
{ opacity: 0, transform: `translate(${dir * 12}px, ${dir ? 0 : 6}px)`, filter: 'blur(4px)' },
|
|
||||||
{ opacity: 1, transform: 'none', filter: 'blur(0)' },
|
|
||||||
],
|
|
||||||
{ duration: still ? 160 : 280, delay: 50, easing: EASE.out, fill: 'backwards' },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Play an element's way out before it is removed (it keeps its place until then). */
|
|
||||||
export function leave(el: Element | null | undefined): Promise<void> {
|
|
||||||
if (!el || !el.isConnected) return Promise.resolve();
|
|
||||||
const a = el.animate(
|
|
||||||
calm()
|
|
||||||
? [{ opacity: 1 }, { opacity: 0 }]
|
|
||||||
: [
|
|
||||||
{ opacity: 1, transform: 'none', filter: 'blur(0)' },
|
|
||||||
{ opacity: 0, transform: 'scale(0.96)', filter: 'blur(4px)' },
|
|
||||||
],
|
|
||||||
{ duration: 200, easing: EASE.in, fill: 'forwards' },
|
|
||||||
);
|
|
||||||
return a.finished.then(
|
|
||||||
() => undefined,
|
|
||||||
() => undefined,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A beat between the steps of a sequence; none when the visitor asked for less motion. */
|
|
||||||
export const beat = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, calm() ? 0 : ms));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The accordion's look: the height closes on the drawer curve over `ms`; the
|
|
||||||
* content dissolves faster, from the start, as blocks leave elsewhere (blur, a
|
|
||||||
* small rise and shrink, on the strong ease-out over `contentMs`).
|
|
||||||
*/
|
|
||||||
const FOLD = { ms: 520, contentMs: 300, blur: 4, drift: 6, scale: 0.98 };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fold a block shut like an accordion and take it out: its height closes from
|
|
||||||
* the bottom edge (the sheet's edge comes with it) while its content dissolves
|
|
||||||
* into a blur. Less motion: it fades.
|
|
||||||
*/
|
|
||||||
export async function fold(el: HTMLElement): Promise<void> {
|
|
||||||
if (!el.isConnected) return;
|
|
||||||
const release = hold(el);
|
|
||||||
const gap = parseFloat(getComputedStyle(el.parentElement as HTMLElement).rowGap) || 0;
|
|
||||||
const h = el.offsetHeight;
|
|
||||||
el.style.overflow = 'hidden';
|
|
||||||
el.style.transformOrigin = '50% 0';
|
|
||||||
el.inert = true;
|
|
||||||
const done = () => undefined;
|
|
||||||
if (calm())
|
|
||||||
await el.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 160, easing: EASE.out, fill: 'forwards' }).finished.then(done, done);
|
|
||||||
else {
|
|
||||||
el.animate(
|
|
||||||
[
|
|
||||||
{ opacity: 1, filter: 'blur(0px)', transform: 'none' },
|
|
||||||
{ opacity: 0, filter: `blur(${FOLD.blur}px)`, transform: `translateY(${-FOLD.drift}px) scale(${FOLD.scale})` },
|
|
||||||
],
|
|
||||||
{ duration: FOLD.contentMs, easing: EASE.out, fill: 'forwards' },
|
|
||||||
);
|
|
||||||
await el
|
|
||||||
.animate(
|
|
||||||
[
|
|
||||||
{ height: `${h}px`, marginTop: '0px' },
|
|
||||||
{ height: '0px', marginTop: `${-gap}px` },
|
|
||||||
],
|
|
||||||
{ duration: FOLD.ms, easing: EASE.drawer, fill: 'forwards' },
|
|
||||||
)
|
|
||||||
.finished.then(done, done);
|
|
||||||
}
|
|
||||||
el.remove();
|
|
||||||
release();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The opposite, for a line that just got something to say: it opens from no
|
|
||||||
* height to its own (the sheet's edge comes with it) and comes into focus.
|
|
||||||
*/
|
|
||||||
export function grow(el: HTMLElement) {
|
|
||||||
if (!el.isConnected || calm()) return replay(el, 'swap');
|
|
||||||
const release = hold(el);
|
|
||||||
const gap = parseFloat(getComputedStyle(el.parentElement as HTMLElement).rowGap) || 0;
|
|
||||||
const h = el.offsetHeight;
|
|
||||||
el.style.overflow = 'hidden';
|
|
||||||
const a = el.animate(
|
|
||||||
[
|
|
||||||
{ height: '0px', marginTop: `${-gap}px`, opacity: 0, filter: 'blur(4px)' },
|
|
||||||
{ height: `${h}px`, marginTop: '0px', opacity: 1, filter: 'blur(0px)' },
|
|
||||||
],
|
|
||||||
{ duration: 380, easing: EASE.drawer },
|
|
||||||
);
|
|
||||||
const end = () => {
|
|
||||||
el.style.overflow = '';
|
|
||||||
release();
|
|
||||||
};
|
|
||||||
a.onfinish = end;
|
|
||||||
a.oncancel = end;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The page's first paint: the blocks matching `selector` rise in, in reading
|
|
||||||
* order (top to bottom, then left to right, whatever the layout), at most
|
|
||||||
* eight steps apart. portal.css draws `.intro`; `--i` is the step.
|
|
||||||
*/
|
|
||||||
export function intro(root: ParentNode, selector: string) {
|
|
||||||
const els = [...root.querySelectorAll<HTMLElement>(selector)].map((el) => ({ el, r: el.getBoundingClientRect() }));
|
|
||||||
els.sort((a, b) => Math.round(a.r.top - b.r.top) || a.r.left - b.r.left);
|
|
||||||
els.forEach(({ el }, i) => {
|
|
||||||
el.style.setProperty('--i', String(Math.min(i, 8)));
|
|
||||||
el.classList.add('intro');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Where the keyed blocks of a page are and what its keyed values say, before a repaint. */
|
|
||||||
export interface Snap {
|
|
||||||
at: Map<string, { x: number; y: number }>;
|
|
||||||
text: Map<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function snap(root: ParentNode): Snap {
|
|
||||||
const at = new Map<string, { x: number; y: number }>();
|
|
||||||
const text = new Map<string, string>();
|
|
||||||
root.querySelectorAll<HTMLElement>('[data-key]').forEach((el) => {
|
|
||||||
const r = el.getBoundingClientRect();
|
|
||||||
at.set(el.dataset.key as string, { x: r.left + scrollX, y: r.top + scrollY });
|
|
||||||
});
|
|
||||||
root.querySelectorAll<HTMLElement>('[data-v]').forEach((el) => text.set(el.dataset.v as string, el.textContent ?? ''));
|
|
||||||
return { at, text };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* After a repaint: a keyed block that moved glides from where it was (FLIP),
|
|
||||||
* one that is new rises in, a keyed value that changed comes into focus.
|
|
||||||
* Keyed blocks are never nested, so no move is counted twice.
|
|
||||||
*/
|
|
||||||
export function settle(root: ParentNode, before: Snap) {
|
|
||||||
const still = calm();
|
|
||||||
root.querySelectorAll<HTMLElement>('[data-key]').forEach((el) => {
|
|
||||||
const was = before.at.get(el.dataset.key as string);
|
|
||||||
if (!was) {
|
|
||||||
el.classList.add('enter');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (still) return;
|
|
||||||
const r = el.getBoundingClientRect();
|
|
||||||
const dx = was.x - (r.left + scrollX),
|
|
||||||
dy = was.y - (r.top + scrollY);
|
|
||||||
if (Math.abs(dx) < 1 && Math.abs(dy) < 1) return;
|
|
||||||
el.animate([{ transform: `translate(${dx}px, ${dy}px)` }, { transform: 'none' }], {
|
|
||||||
duration: morphMs(Math.hypot(dx, dy)),
|
|
||||||
easing: EASE.out,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
root.querySelectorAll<HTMLElement>('[data-v]').forEach((el) => {
|
|
||||||
const was = before.text.get(el.dataset.v as string);
|
|
||||||
if (was != null && was !== el.textContent) el.classList.add('swap');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A repaint of a sheet's content that keeps its motion: keyed controls
|
|
||||||
* (`data-m`) that flipped on or off get `to-on` / `to-off`, whose keyframes
|
|
||||||
* start from the other look; one whose text changed comes into focus (`swap`);
|
|
||||||
* one marked `data-glide` that moved within its parent (a chip beside a chevron
|
|
||||||
* that went) glides there.
|
|
||||||
*/
|
|
||||||
export function restyle(root: ParentNode, paint: () => void) {
|
|
||||||
const state = (el: Element) => el.classList.contains('on') || el.classList.contains('open');
|
|
||||||
// What it says: its text, or `data-sig` where the text says nothing (a QR code).
|
|
||||||
const says = (el: HTMLElement) => el.dataset.sig ?? el.textContent ?? '';
|
|
||||||
const inParent = (el: HTMLElement) => {
|
|
||||||
const r = el.getBoundingClientRect(),
|
|
||||||
p = (el.parentElement as HTMLElement).getBoundingClientRect();
|
|
||||||
return { x: r.left - p.left, y: r.top - p.top };
|
|
||||||
};
|
|
||||||
const before = new Map<string, { on: boolean; says: string }>();
|
|
||||||
root.querySelectorAll<HTMLElement>('[data-m]').forEach((el) => before.set(el.dataset.m as string, { on: state(el), says: says(el) }));
|
|
||||||
const placed = new Map<string, { x: number; y: number }>();
|
|
||||||
root.querySelectorAll<HTMLElement>('[data-glide]').forEach((el) => placed.set(el.dataset.glide as string, inParent(el)));
|
|
||||||
paint();
|
|
||||||
if (!calm())
|
|
||||||
root.querySelectorAll<HTMLElement>('[data-glide]').forEach((el) => {
|
|
||||||
const was = placed.get(el.dataset.glide as string);
|
|
||||||
if (!was) return;
|
|
||||||
const now = inParent(el);
|
|
||||||
const dx = was.x - now.x,
|
|
||||||
dy = was.y - now.y;
|
|
||||||
if (Math.abs(dx) >= 1 || Math.abs(dy) >= 1)
|
|
||||||
el.animate([{ transform: `translate(${dx}px, ${dy}px)` }, { transform: 'none' }], { duration: 280, easing: EASE.out });
|
|
||||||
});
|
|
||||||
root.querySelectorAll<HTMLElement>('[data-m]').forEach((el) => {
|
|
||||||
const was = before.get(el.dataset.m as string);
|
|
||||||
if (!was) return;
|
|
||||||
if (was.on !== state(el)) el.classList.add(state(el) ? 'to-on' : 'to-off');
|
|
||||||
else if (was.says !== says(el)) el.classList.add('swap');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A copy button in its "Copied" moment: what to put back, and when. */
|
|
||||||
const COPIED = new WeakMap<HTMLElement, { timer: number; icon: string | null; label: string | null }>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A copy button says it worked where the finger is: its icon turns into a
|
|
||||||
* check and a "Copy" label into "Copied", for a moment. Other labels (a host
|
|
||||||
* name on a chip) stay. `check` is the check icon's markup.
|
|
||||||
*/
|
|
||||||
export function copied(btn: HTMLElement | null | undefined, check: string) {
|
|
||||||
if (!btn) return;
|
|
||||||
const icon = btn.querySelector<HTMLElement>('.ic');
|
|
||||||
const label =
|
|
||||||
btn.querySelector<HTMLElement>('.badge-main') ??
|
|
||||||
btn.querySelector<HTMLElement>(':scope > span:not(.ic)') ??
|
|
||||||
(btn.children.length ? null : btn);
|
|
||||||
const was = COPIED.get(btn) ?? { timer: 0, icon: icon?.innerHTML ?? null, label: label?.textContent ?? null };
|
|
||||||
clearTimeout(was.timer);
|
|
||||||
const says = !!label && (label.classList.contains('badge-main') || /^copy$/i.test(was.label ?? ''));
|
|
||||||
const show = (svg: string | null, text: string | null) => {
|
|
||||||
if (icon && svg != null && icon.innerHTML !== svg) {
|
|
||||||
icon.innerHTML = svg;
|
|
||||||
replay(icon, 'swap-ic');
|
|
||||||
}
|
|
||||||
if (label && says && text != null && label.textContent !== text) {
|
|
||||||
label.textContent = text;
|
|
||||||
replay(label, 'swap');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
show(check, 'Copied');
|
|
||||||
btn.classList.add('copied');
|
|
||||||
was.timer = window.setTimeout(() => {
|
|
||||||
COPIED.delete(btn);
|
|
||||||
btn.classList.remove('copied');
|
|
||||||
show(was.icon, was.label);
|
|
||||||
}, 1600);
|
|
||||||
COPIED.set(btn, was);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A button waiting for the router: after a beat (no flash on a quick answer) a spinner takes the label's place. */
|
|
||||||
export function busy(btn: HTMLElement): () => void {
|
|
||||||
const t = window.setTimeout(() => btn.classList.add('busy'), 250);
|
|
||||||
return () => {
|
|
||||||
clearTimeout(t);
|
|
||||||
btn.classList.remove('busy');
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Let a bottom sheet be pulled down by its grab bar and head (a question: all of it): the panel
|
|
||||||
* follows the finger (with resistance upwards), the scrim fades with it, and
|
|
||||||
* on release it either goes (`close`) or springs back. Only while `bottom()`
|
|
||||||
* (the sheet sits at the bottom: phones). The release transitions start from
|
|
||||||
* the dragged spot because the inline transform and `.dragging` go together.
|
|
||||||
*/
|
|
||||||
export function pullToClose(panel: HTMLElement, scrim: HTMLElement, close: () => void, bottom: () => boolean) {
|
|
||||||
panel.addEventListener('pointerdown', (e) => {
|
|
||||||
const t = e.target as Element;
|
|
||||||
if (!bottom() || e.button !== 0 || !t.closest('.grab, .sheet-head, .ask') || t.closest('button, a, input')) return;
|
|
||||||
const y0 = e.clientY,
|
|
||||||
h = panel.offsetHeight;
|
|
||||||
let dy = 0;
|
|
||||||
const trail: { t: number; y: number }[] = [{ t: e.timeStamp, y: e.clientY }];
|
|
||||||
try {
|
|
||||||
panel.setPointerCapture(e.pointerId);
|
|
||||||
} catch {
|
|
||||||
/* a pointer the browser no longer tracks: the pull still follows while it is over the panel */
|
|
||||||
}
|
|
||||||
panel.classList.add('dragging');
|
|
||||||
const move = (ev: PointerEvent) => {
|
|
||||||
const raw = ev.clientY - y0;
|
|
||||||
dy = raw < 0 ? -rubber(-raw, h) : raw;
|
|
||||||
panel.style.transform = `translateY(${dy}px)`;
|
|
||||||
scrim.style.opacity = String(1 - Math.max(0, dy) / h);
|
|
||||||
trail.push({ t: ev.timeStamp, y: ev.clientY });
|
|
||||||
while (trail.length > 2 && ev.timeStamp - trail[0].t > 100) trail.shift();
|
|
||||||
};
|
|
||||||
const up = (ev: PointerEvent) => {
|
|
||||||
panel.removeEventListener('pointermove', move);
|
|
||||||
panel.removeEventListener('pointerup', up);
|
|
||||||
panel.removeEventListener('pointercancel', up);
|
|
||||||
const first = trail[0],
|
|
||||||
last = trail[trail.length - 1];
|
|
||||||
const v = last.t > first.t ? (last.y - first.y) / (last.t - first.t) : 0;
|
|
||||||
panel.classList.remove('dragging');
|
|
||||||
panel.style.transform = '';
|
|
||||||
scrim.style.opacity = '';
|
|
||||||
if (ev.type === 'pointerup' && dismisses(dy, v, h)) close();
|
|
||||||
};
|
|
||||||
panel.addEventListener('pointermove', move);
|
|
||||||
panel.addEventListener('pointerup', up);
|
|
||||||
panel.addEventListener('pointercancel', up);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,311 @@
|
|||||||
|
// "Your access", set by the admin: one accordion of three rows. What the
|
||||||
|
// access reaches (home and internet as two tiles, and the names devices at
|
||||||
|
// home reach this person's devices by); the data, as a ring in the head and
|
||||||
|
// the month day by day inside; and until when, as the days left over a
|
||||||
|
// calendar of the weeks, with the admin's hours as a bar of the day.
|
||||||
|
|
||||||
|
import type { Person } from '../../shared/types';
|
||||||
|
import { ACCESS_LABEL, byDeviceState, bytes, date, daysLeft, endsSoon, parseDay } from '../../shared/format';
|
||||||
|
import { h, ic, markup } from '../dom';
|
||||||
|
import { calendar, clockOf, hoursFor, minuteAt, monthOf, stretches } from '../days';
|
||||||
|
import { now, today, type State } from '../state';
|
||||||
|
import { accordion, type Accordion } from '../ui/accordion';
|
||||||
|
import { copy } from '../ui/feedback';
|
||||||
|
import { glass } from '../ui/glass';
|
||||||
|
import { morphChanged, setText, textsOf } from '../ui/morph';
|
||||||
|
import { reachableFromHome } from './devices';
|
||||||
|
|
||||||
|
const desc = (text: string) => h('p', { class: 'desc' }, text);
|
||||||
|
/** A share of a length, as a CSS percentage. */
|
||||||
|
const pc = (part: number, whole: number) => `${((part / whole) * 100).toFixed(2)}%`;
|
||||||
|
|
||||||
|
/** What the access reaches, as two tiles: the home network and the internet, each in or out. */
|
||||||
|
function reachTiles(access: Person['access']): HTMLElement {
|
||||||
|
const tile = (on: boolean, icon: string, name: string, sub: string) =>
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: `reach-tile${on ? '' : ' off'}` },
|
||||||
|
glass(icon, on ? 'blue' : 'grey', 'gi rt-ic'),
|
||||||
|
h('b', {}, name),
|
||||||
|
h('span', { class: 'rt-sub' }, on ? sub : 'Not included'),
|
||||||
|
h('span', { class: 'rt-mark', 'aria-label': on ? 'Included' : 'Not included' }, ic(on ? 'check' : 'minus')),
|
||||||
|
);
|
||||||
|
return h(
|
||||||
|
'div',
|
||||||
|
{ class: 'reach2' },
|
||||||
|
tile(access !== 'internet', 'home', 'Home network', 'Devices at home'),
|
||||||
|
tile(access !== 'lan', 'globe', 'Internet', 'Through the router'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** How other devices at home reach this person's devices: once, here, only where the router lets them through. */
|
||||||
|
function namesAtHome(p: Person, mesh: boolean): Node[] {
|
||||||
|
const named = byDeviceState(p.devices).filter((d) => d.hostname && reachableFromHome(p, d));
|
||||||
|
if (!named.length) return [];
|
||||||
|
const first = named[0].hostname;
|
||||||
|
const dot0 = first.indexOf('.');
|
||||||
|
const domain = dot0 > 0 ? first.slice(dot0) : '';
|
||||||
|
return [
|
||||||
|
h(
|
||||||
|
'span',
|
||||||
|
{ class: 'lbl-s' },
|
||||||
|
mesh ? 'Devices at home and on this VPN reach yours as ' : 'Other devices at home reach yours as ',
|
||||||
|
h('span', { class: 'mono' }, `name${domain}`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'names' },
|
||||||
|
named.map((d) => {
|
||||||
|
const dot = d.hostname.indexOf('.');
|
||||||
|
return h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
class: 'namechip',
|
||||||
|
title: d.name,
|
||||||
|
'aria-label': `Copy ${d.hostname}`,
|
||||||
|
onclick: (ev: Event) => copy(d.hostname, 'Address copied', ev.currentTarget),
|
||||||
|
},
|
||||||
|
h('span', {}, dot > 0 ? [d.hostname.slice(0, dot), h('span', { class: 'faint' }, d.hostname.slice(dot))] : d.hostname),
|
||||||
|
ic('copy'),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Used against the limit, as a small ring (its colour: fine, nearly full, full). */
|
||||||
|
function ring(pct: number): Element {
|
||||||
|
const c = 2 * Math.PI * 6;
|
||||||
|
const tone = pct >= 100 ? ' bad' : pct >= 90 ? ' warn' : '';
|
||||||
|
return markup(
|
||||||
|
`<svg class="ring" viewBox="0 0 16 16" aria-hidden="true"><circle class="trk" cx="8" cy="8" r="6" fill="none" stroke-width="2.4"/>` +
|
||||||
|
`<circle class="arc${tone}" cx="8" cy="8" r="6" fill="none" stroke-width="2.4" stroke-linecap="round" stroke-dasharray="${((c * pct) / 100).toFixed(2)} ${c.toFixed(2)}"/></svg>`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function meter(pct: number): HTMLElement {
|
||||||
|
const i = h('i', { class: pct >= 100 ? 'bad' : pct >= 90 ? 'warn' : '' });
|
||||||
|
i.style.width = `${pct.toFixed(1)}%`;
|
||||||
|
return h('div', { class: 'meter' }, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The month as one bar a day (today in blue, days to come faint), and the total under it. */
|
||||||
|
function month(p: Person, used: number, pct: number): HTMLElement {
|
||||||
|
const { days, day } = monthOf(today());
|
||||||
|
const series = p.month_days ?? [];
|
||||||
|
const max = Math.max(1, ...series);
|
||||||
|
const short = (d: number) =>
|
||||||
|
parseDay(`${today().slice(0, 8)}${String(d).padStart(2, '0')}`).toLocaleDateString('en-GB', { day: 'numeric', month: 'short' });
|
||||||
|
// The total, and a bar under the pointer in its place, at once: no morph while the pointer moves.
|
||||||
|
const total = h('b', { class: 'num', 'data-t': 'm-used' }, bytes(used));
|
||||||
|
const tail = h('span', {}, ' used');
|
||||||
|
const read = h('span', { class: 'mread' }, total, tail);
|
||||||
|
const bars = h('div', { class: 'mbars' });
|
||||||
|
for (let i = 0; i < days; i++) {
|
||||||
|
if (i >= day) {
|
||||||
|
bars.appendChild(h('i', { class: 'future' }));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const v = series[i] ?? 0;
|
||||||
|
const b = h('i', { class: i === day - 1 ? 'today' : '' });
|
||||||
|
b.style.height = `${Math.max(3, Math.round((v / max) * 64))}px`;
|
||||||
|
b.addEventListener('pointerenter', () => {
|
||||||
|
setText(total, bytes(v));
|
||||||
|
setText(tail, ` on ${short(i + 1)}`);
|
||||||
|
});
|
||||||
|
b.addEventListener('pointerleave', () => {
|
||||||
|
setText(total, bytes(used));
|
||||||
|
setText(tail, ' used');
|
||||||
|
});
|
||||||
|
bars.appendChild(b);
|
||||||
|
}
|
||||||
|
// "Today" under its bar; the month's ends step aside when it comes close.
|
||||||
|
const td = h('span', { class: 'td' }, 'Today');
|
||||||
|
td.style.left = pc(day - 0.5, days);
|
||||||
|
const axis = h(
|
||||||
|
'div',
|
||||||
|
{ class: 'month-axis' },
|
||||||
|
h('span', { class: day <= 4 ? 'hide' : '' }, short(1)),
|
||||||
|
td,
|
||||||
|
h('span', { class: day >= days - 3 ? 'hide' : '' }, short(days)),
|
||||||
|
);
|
||||||
|
return h(
|
||||||
|
'div',
|
||||||
|
{ class: 'month' },
|
||||||
|
bars,
|
||||||
|
axis,
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'month-read' },
|
||||||
|
read,
|
||||||
|
h(
|
||||||
|
'span',
|
||||||
|
{ class: `num${p.state === 'quota' ? ' bad-t' : ''}`, 'data-t': 'm-left' },
|
||||||
|
p.quota_limit ? `${bytes(Math.max(0, p.quota_limit - used))} left` : 'No limit',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
p.quota_limit ? meter(pct) : null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The days left as a number over a calendar of the weeks to the end (the last day ringed). */
|
||||||
|
function untilCal(p: Person, left: number): HTMLElement {
|
||||||
|
const day = (d: string) => parseDay(d).toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short' });
|
||||||
|
const cells = calendar(today(), p.expires);
|
||||||
|
const cal = cells
|
||||||
|
? h(
|
||||||
|
'div',
|
||||||
|
{ class: 'cal', 'aria-hidden': 'true' },
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'cal-h' },
|
||||||
|
['M', 'T', 'W', 'T', 'F', 'S', 'S'].map((x) => h('span', {}, x)),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'cal-g' },
|
||||||
|
cells.map((c, i) => {
|
||||||
|
const el = h('i', { class: c.kind, title: day(c.day) });
|
||||||
|
el.style.setProperty('--i', String(i));
|
||||||
|
return el;
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
return h(
|
||||||
|
'div',
|
||||||
|
{ class: `until${endsSoon(p, left) ? ' soon' : ''}` },
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'until-num' },
|
||||||
|
h('b', { class: 'num' }, String(left)),
|
||||||
|
h('span', {}, `${left === 1 ? 'day' : 'days'} left`),
|
||||||
|
h('span', { class: 'until-sub' }, `Ends ${day(p.expires)}`),
|
||||||
|
),
|
||||||
|
cal,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The day as 24 hours in the visitor's time: the admin's window filled, now marked. */
|
||||||
|
function hoursBar(hours: string, tzOffset: number | undefined): HTMLElement | null {
|
||||||
|
const visitor = -new Date().getTimezoneOffset();
|
||||||
|
const hw = hoursFor(hours, tzOffset, visitor);
|
||||||
|
if (!hw) return null;
|
||||||
|
// The router's clock, read in the visitor's zone (or the router's, without its offset).
|
||||||
|
const at = minuteAt(now(), hw.yours ? visitor : (tzOffset ?? visitor));
|
||||||
|
const segs = stretches(hw);
|
||||||
|
const inside = segs.some(([a, b]) => at >= a && at < b);
|
||||||
|
const bar = h('div', { class: 'hours-bar' });
|
||||||
|
for (const [a, b] of segs) {
|
||||||
|
const i = h('i');
|
||||||
|
i.style.left = pc(a, 1440);
|
||||||
|
i.style.width = pc(b - a, 1440);
|
||||||
|
bar.appendChild(i);
|
||||||
|
}
|
||||||
|
const mark = h('span', { class: `hours-now${inside ? '' : ' out'}`, title: `Now, ${clockOf(at)}` });
|
||||||
|
mark.style.left = pc(at, 1440);
|
||||||
|
bar.appendChild(mark);
|
||||||
|
return h(
|
||||||
|
'div',
|
||||||
|
{ class: 'hours' },
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'hours-top' },
|
||||||
|
h('span', {}, hw.yours ? 'Hours, your time' : 'Hours, router time'),
|
||||||
|
h('b', { class: 'num' }, `${clockOf(hw.from)}–${clockOf(hw.to)}`),
|
||||||
|
),
|
||||||
|
bar,
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'hours-axis' },
|
||||||
|
['00', '06', '12', '18', '24'].map((x) => h('span', {}, x)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The access accordion for this state; `open`: the row to keep open (a repaint), else the data. */
|
||||||
|
export function accessAccordion(st: State, open = 1): Accordion {
|
||||||
|
const p = st.person;
|
||||||
|
const used = p.quota_used || p.month[0] + p.month[1];
|
||||||
|
const pct = p.quota_limit ? Math.min(100, (used / p.quota_limit) * 100) : 0;
|
||||||
|
// A total over the whole access only with a limit; otherwise it is this month's count.
|
||||||
|
const total = p.quota_period === 'total' && !!p.quota_gb;
|
||||||
|
const left = daysLeft(p.expires, today());
|
||||||
|
const untilVal = p.expires
|
||||||
|
? h(
|
||||||
|
'span',
|
||||||
|
{ class: 'until-val' },
|
||||||
|
h('span', { class: 'num', 'data-t': 'until-date' }, date(p.expires).replace(/ \d{4}$/, '')),
|
||||||
|
left != null
|
||||||
|
? h(
|
||||||
|
'span',
|
||||||
|
{ class: `num ${left < 0 ? 'bad-t' : endsSoon(p, left) ? 'warn-t' : 'ok-t'}`, 'data-t': 'until-left' },
|
||||||
|
left >= 0 ? `${left} day${left === 1 ? '' : 's'}` : 'ended',
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
)
|
||||||
|
: h('span', {}, 'No end date');
|
||||||
|
const untilBody = [
|
||||||
|
!p.expires ? null : left != null && left < 0 ? desc(`It ended on ${date(p.expires)}.`) : untilCal(p, left ?? 0),
|
||||||
|
p.hours ? hoursBar(p.hours, st.tz_offset) : null,
|
||||||
|
];
|
||||||
|
return accordion(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
icon: glass(p.access === 'internet' ? 'globe' : p.access === 'lan' ? 'home' : 'shield'),
|
||||||
|
title: ACCESS_LABEL[p.access],
|
||||||
|
body: [reachTiles(p.access), ...namesAtHome(p, !!st.server.device_mesh)],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: glass('chart'),
|
||||||
|
title: total ? 'Data used' : 'Data this month',
|
||||||
|
val: h(
|
||||||
|
'span',
|
||||||
|
{ class: 'data-val' },
|
||||||
|
p.quota_limit ? ring(pct) : null,
|
||||||
|
h(
|
||||||
|
'span',
|
||||||
|
{ class: 'num', 'data-t': 'data-val' },
|
||||||
|
`${bytes(used)}${p.quota_limit ? ` / ${bytes(p.quota_limit)}` : ' · no limit'}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
valHide: true,
|
||||||
|
body: [
|
||||||
|
total ? desc(`${bytes(used)} of ${bytes(p.quota_limit)} in total.`) : month(p, used, pct),
|
||||||
|
desc(
|
||||||
|
!p.quota_limit
|
||||||
|
? 'No data limit. The count starts again on the 1st.'
|
||||||
|
: total
|
||||||
|
? 'A total for your whole access, it does not reset.'
|
||||||
|
: 'Resets on the 1st.',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
// No end date and no hours: nothing to open, the row just says so.
|
||||||
|
{ icon: glass('calendar'), title: 'Access until', val: untilVal, valHide: !!p.expires && (left ?? 0) >= 0, body: untilBody },
|
||||||
|
],
|
||||||
|
{ open },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The section, built once; `fillAccess` puts the accordion in. */
|
||||||
|
export function accessSection(): HTMLElement {
|
||||||
|
return h(
|
||||||
|
'section',
|
||||||
|
{ class: 'access', id: 'access', 'aria-label': 'Your access' },
|
||||||
|
h('div', { class: 'sec-head' }, h('h2', {}, 'Your access')),
|
||||||
|
h('div', { class: 'acc-slot' }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let shown: Accordion | null = null;
|
||||||
|
/** The accordion for this state, the same row open as before. */
|
||||||
|
export function fillAccess(section: HTMLElement, st: State) {
|
||||||
|
const acc = accessAccordion(st, shown ? shown.openIndex() : 1);
|
||||||
|
// The values it showed: what changed morphs from it.
|
||||||
|
const said = textsOf(section);
|
||||||
|
section.querySelector('.acc-slot')!.replaceChildren(acc.el);
|
||||||
|
if (shown) morphChanged(section, said);
|
||||||
|
shown = acc;
|
||||||
|
}
|
||||||
@@ -0,0 +1,293 @@
|
|||||||
|
// "Your devices": a card per device (the one this page is open on first, then
|
||||||
|
// by state), the card to add one, and the count. A repaint keeps the grid:
|
||||||
|
// cards that stay glide to their new places, a new one pops in, one that just
|
||||||
|
// connected rings green for a moment. What a card's buttons start lives in
|
||||||
|
// flows/.
|
||||||
|
|
||||||
|
import type { Device, Person } from '../../shared/types';
|
||||||
|
import { addDays, ago, byDeviceState, bytes, parseDay } from '../../shared/format';
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { BOUNCY, EASE_IN, EASE_OUT, SMOOTH, play } from '../motion';
|
||||||
|
import { now, today, type RepaintOpts, type State } from '../state';
|
||||||
|
import { copy } from '../ui/feedback';
|
||||||
|
import { glass } from '../ui/glass';
|
||||||
|
import { openMenu, type MenuItem } from '../ui/menu';
|
||||||
|
import { morphChanged, morphText, setText, textsOf } from '../ui/morph';
|
||||||
|
import { startAdd } from '../flows/add';
|
||||||
|
import { reconnect, removeDevice, rename } from '../flows/device-actions';
|
||||||
|
import { openSetup } from '../flows/setup-view';
|
||||||
|
|
||||||
|
/** The home network can open connections to it: home access, active, and the device on. */
|
||||||
|
export const reachableFromHome = (p: Person, d: Device) => p.access !== 'internet' && p.state === 'active' && !d.disabled;
|
||||||
|
|
||||||
|
/** The status line: its class and words (short, on one line; the full wording shows on hover). */
|
||||||
|
function statusOf(d: Device, p: Person): [string, string] {
|
||||||
|
if (d.disabled) return ['', 'Disabled'];
|
||||||
|
// The Update pill beside it says what to do.
|
||||||
|
if (d.config_stale && d.handshake) return ['warn-t', 'Settings changed'];
|
||||||
|
// Over the data limit or outside the hours the tunnel stays up but passes nothing: the app says
|
||||||
|
// "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'];
|
||||||
|
if (d.online) return ['ok-t', 'Connected'];
|
||||||
|
if (!d.handshake) return ['warn-t', 'Not set up yet'];
|
||||||
|
return ['', `Last connected ${ago(d.handshake, now())}`];
|
||||||
|
}
|
||||||
|
|
||||||
|
function menuItems(d: Device, st: State): (MenuItem | null)[] {
|
||||||
|
return [
|
||||||
|
// 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') }] : []),
|
||||||
|
null,
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
// A device the admin turned off can't be renamed, set up again or removed here (the router refuses).
|
||||||
|
...(d.disabled
|
||||||
|
? []
|
||||||
|
: [
|
||||||
|
{ label: 'Rename', icon: 'edit', run: () => rename(d) },
|
||||||
|
{ label: 'Reconnect', icon: 'refresh', tone: 'warn' as const, run: () => reconnect(d) },
|
||||||
|
{ label: 'Remove', icon: 'trash', tone: 'bad' as const, run: () => removeDevice(d) },
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "Today", "Yesterday", "Tue 13 Oct": a spark bar's day, on the router's calendar. */
|
||||||
|
function dayName(back: number): string {
|
||||||
|
if (back === 0) return 'Today';
|
||||||
|
if (back === 1) return 'Yesterday';
|
||||||
|
return parseDay(addDays(today(), -back)).toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short' });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Last 7 days as a number and bars; a bar under the pointer puts its own day in the number's place. */
|
||||||
|
function usage(d: Device, stale: boolean): HTMLElement {
|
||||||
|
const week = d.spark.reduce((a, b) => a + b, 0);
|
||||||
|
const lbl = h('span', { class: 'use-lbl' }, 'Last 7 days');
|
||||||
|
const val = h('span', { class: 'use-val num', 'data-t': `${d.id}:use` }, bytes(week));
|
||||||
|
let side: HTMLElement;
|
||||||
|
if (stale)
|
||||||
|
side = h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
class: 'upd-pill',
|
||||||
|
'aria-label': 'Update the connection',
|
||||||
|
title: 'Its settings changed: update the connection',
|
||||||
|
onclick: () => reconnect(d),
|
||||||
|
},
|
||||||
|
ic('refresh'),
|
||||||
|
h('span', {}, 'Update'),
|
||||||
|
);
|
||||||
|
else {
|
||||||
|
const max = Math.max(1, ...d.spark);
|
||||||
|
side = h('div', { class: 'spark' });
|
||||||
|
d.spark.forEach((v, i) => {
|
||||||
|
const back = d.spark.length - 1 - i;
|
||||||
|
const b = h('i', { class: back === 0 ? 'today' : '' });
|
||||||
|
b.style.height = `${Math.max(3, Math.round((v / max) * 34))}px`;
|
||||||
|
// What the pointer reads off the bars changes at once: no morph while it moves.
|
||||||
|
b.addEventListener('pointerenter', () => {
|
||||||
|
setText(lbl, dayName(back));
|
||||||
|
setText(val, bytes(v));
|
||||||
|
});
|
||||||
|
b.addEventListener('pointerleave', () => {
|
||||||
|
setText(lbl, 'Last 7 days');
|
||||||
|
setText(val, bytes(week));
|
||||||
|
});
|
||||||
|
side.appendChild(b);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return h('div', { class: 'dev-use' }, h('div', { class: 'use-txt' }, lbl, val), side);
|
||||||
|
}
|
||||||
|
|
||||||
|
function card(d: Device, st: State): HTMLElement {
|
||||||
|
const p = st.person;
|
||||||
|
const locked = !!st.locked;
|
||||||
|
// The device this page was opened from (through the tunnel): it is connected, so say which one it is instead.
|
||||||
|
const here = st.here === d.id;
|
||||||
|
const [cls, words] = here ? ['here-t', 'This device'] : statusOf(d, p);
|
||||||
|
const setUp = !d.handshake && !d.disabled;
|
||||||
|
const stale = d.config_stale && !setUp && !locked && !d.disabled;
|
||||||
|
// On one line; the exact time, or the whole wording, on hover.
|
||||||
|
const title =
|
||||||
|
!here && d.handshake && !d.online && !d.disabled && !d.config_stale
|
||||||
|
? new Date(d.handshake * 1000).toLocaleString('en-GB')
|
||||||
|
: stale
|
||||||
|
? 'Settings changed, update needed'
|
||||||
|
: words;
|
||||||
|
const items = menuItems(d, st);
|
||||||
|
const more =
|
||||||
|
locked || !items.length
|
||||||
|
? null
|
||||||
|
: h(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'knob more', 'aria-label': `${d.name} options`, 'aria-haspopup': 'menu', 'aria-expanded': 'false' },
|
||||||
|
ic('more'),
|
||||||
|
);
|
||||||
|
more?.addEventListener('click', () => openMenu(more, items));
|
||||||
|
return h(
|
||||||
|
'article',
|
||||||
|
{ class: `dev${here ? ' is-here' : ''}${d.disabled ? ' off' : ''}`, 'data-id': d.id },
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'dev-top' },
|
||||||
|
glass(d.kind, here ? 'blue' : 'grey'),
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'dev-id' },
|
||||||
|
h('span', { class: 'dev-name', 'data-t': `${d.id}:name` }, d.name),
|
||||||
|
h('span', { class: `dev-stat ${cls}`, title, 'data-t': `${d.id}:stat` }, words),
|
||||||
|
),
|
||||||
|
more,
|
||||||
|
),
|
||||||
|
// Stopped by the admin: a device never set up has nothing to show.
|
||||||
|
setUp && locked
|
||||||
|
? null
|
||||||
|
: setUp
|
||||||
|
? h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
class: 'btn tint block setup-btn',
|
||||||
|
'aria-label': `Set up ${d.name}`,
|
||||||
|
onclick: (ev: Event) => openSetup(d, ev.currentTarget),
|
||||||
|
},
|
||||||
|
ic('qr'),
|
||||||
|
h('span', {}, 'Connect'),
|
||||||
|
)
|
||||||
|
: usage(d, stale),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nothing yet: one card that says what comes, with the button. */
|
||||||
|
const firstCard = (mobile: boolean) =>
|
||||||
|
h(
|
||||||
|
'div',
|
||||||
|
{ class: 'dev first', 'data-id': 'first' },
|
||||||
|
glass('plus', 'blue'),
|
||||||
|
h('b', {}, 'Add your first device'),
|
||||||
|
h('p', {}, 'Two steps, about a minute: get the app, then add the connection.'),
|
||||||
|
h(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'btn accent block', onclick: startAdd },
|
||||||
|
ic('plus'),
|
||||||
|
h('span', {}, mobile ? 'Add this phone' : 'Add this device'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const addCard = () =>
|
||||||
|
h('button', { type: 'button', class: 'dev add', 'data-id': 'add', onclick: startAdd }, glass('plus'), h('span', {}, 'Add device'));
|
||||||
|
|
||||||
|
/** The section, built once; `fill` puts the cards in. */
|
||||||
|
export function devicesSection(): HTMLElement {
|
||||||
|
return h(
|
||||||
|
'section',
|
||||||
|
{ class: 'devices', id: 'devices', 'aria-label': 'Your devices' },
|
||||||
|
h('div', { class: 'sec-head' }, h('h2', {}, 'Your devices'), h('span', { class: 'aside num' })),
|
||||||
|
h('div', { class: 'dgrid' }),
|
||||||
|
h('p', { class: 'note-s limit', hidden: true }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The cards for this state, moving from where they were. */
|
||||||
|
export function fillDevices(section: HTMLElement, st: State, o: RepaintOpts = {}) {
|
||||||
|
const p = st.person;
|
||||||
|
const grid = section.querySelector('.dgrid') as HTMLElement;
|
||||||
|
// A repaint (not the first paint, which brings everything in): what newly shows comes in too.
|
||||||
|
const repainting = grid.childElementCount > 0;
|
||||||
|
const first = new Map([...grid.querySelectorAll<HTMLElement>('[data-id]')].map((c) => [c.dataset.id, c.getBoundingClientRect()]));
|
||||||
|
// What each card said (a name, its status, its week): what changed morphs from it once the cards are in place.
|
||||||
|
const said = textsOf(grid);
|
||||||
|
// The device this page was opened from comes first.
|
||||||
|
const order = byDeviceState(p.devices).sort((a, b) => Number(b.id === st.here) - Number(a.id === st.here));
|
||||||
|
const cards = order.map((d) => card(d, st));
|
||||||
|
const free = st.locked ? 0 : Math.max(0, p.device_limit - p.devices.length);
|
||||||
|
const mobile = matchMedia('(max-width: 959px)').matches || /Android|iPhone|iPad/.test(navigator.userAgent);
|
||||||
|
if (!p.devices.length && free) cards.push(firstCard(mobile));
|
||||||
|
// Paused or ended: the router refuses a new device, so there is no card to offer one (the notice says why).
|
||||||
|
else if (st.can_add && !st.locked) cards.push(addCard());
|
||||||
|
grid.classList.toggle('empty', !p.devices.length);
|
||||||
|
grid.replaceChildren(...cards);
|
||||||
|
for (const c of cards) {
|
||||||
|
const f = first.get(c.dataset.id);
|
||||||
|
const l = c.getBoundingClientRect();
|
||||||
|
if (c.dataset.id === o.pop)
|
||||||
|
play(
|
||||||
|
c,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: 'scale(.9)', filter: 'blur(6px)' },
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: BOUNCY.duration,
|
||||||
|
easing: BOUNCY.easing,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
else if (f && (f.left !== l.left || f.top !== l.top))
|
||||||
|
play(c, [{ transform: `translate(${f.left - l.left}px, ${f.top - l.top}px)` }, { transform: 'none' }], {
|
||||||
|
duration: SMOOTH.duration,
|
||||||
|
easing: SMOOTH.easing,
|
||||||
|
});
|
||||||
|
// New on a repaint (Add device once a slot frees up): it comes in the way a removed card leaves, a beat after.
|
||||||
|
else if (!f && repainting)
|
||||||
|
play(
|
||||||
|
c,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: 'scale(.9)', filter: 'blur(6px)' },
|
||||||
|
{ opacity: getComputedStyle(c).opacity, transform: 'none', filter: 'none' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: SMOOTH.duration,
|
||||||
|
delay: 60,
|
||||||
|
easing: SMOOTH.easing,
|
||||||
|
fill: 'backwards',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (c.dataset.id === o.flash)
|
||||||
|
c.animate([{ boxShadow: 'inset 0 0 0 1.5px var(--ok)' }, { boxShadow: 'inset 0 0 0 1.5px transparent' }], {
|
||||||
|
duration: 1800,
|
||||||
|
easing: 'ease-out',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (repainting) morphChanged(grid, said);
|
||||||
|
const count = section.querySelector('.sec-head .aside') as HTMLElement;
|
||||||
|
const n = `${p.devices.length} of ${p.device_limit}`;
|
||||||
|
if (repainting) morphText(count, n);
|
||||||
|
else count.textContent = n;
|
||||||
|
// The admin may add devices past the limit.
|
||||||
|
count.classList.toggle('warn-t', p.devices.length > p.device_limit);
|
||||||
|
const limit = section.querySelector('.limit') as HTMLElement;
|
||||||
|
const was = limit.hidden;
|
||||||
|
const hide = st.can_add || !!st.locked;
|
||||||
|
limit.textContent = `You have reached your limit of ${p.device_limit} devices. Remove one to add another.`;
|
||||||
|
limit.getAnimations().forEach((a) => a.cancel());
|
||||||
|
// A slot freed: the note fades the way it came, then leaves the layout.
|
||||||
|
if (repainting && !was && hide) {
|
||||||
|
const a = play(
|
||||||
|
limit,
|
||||||
|
[
|
||||||
|
{ opacity: 1, filter: 'none' },
|
||||||
|
{ opacity: 0, filter: 'blur(4px)' },
|
||||||
|
],
|
||||||
|
{ duration: 200, easing: EASE_IN, fill: 'forwards' },
|
||||||
|
);
|
||||||
|
a.onfinish = () => {
|
||||||
|
limit.hidden = true;
|
||||||
|
a.cancel();
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
limit.hidden = hide;
|
||||||
|
if (repainting && was && !hide)
|
||||||
|
play(
|
||||||
|
limit,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: 'translateY(6px)', filter: 'blur(4px)' },
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
],
|
||||||
|
{ duration: 420, easing: EASE_OUT },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
// The page's frame: no navbar. The page fades out under the screen's top and
|
||||||
|
// bottom edges (the top fade only once it scrolls, so the breadcrumb at rest
|
||||||
|
// stays crisp), and opens with a breadcrumb: the Dawnline mark, the place (the
|
||||||
|
// server's name) and the person. The content goes in `body`.
|
||||||
|
|
||||||
|
import { h, ic, markup } from '../dom';
|
||||||
|
import { placeName, state } from '../state';
|
||||||
|
import { showPageCode } from '../flows/page-code';
|
||||||
|
|
||||||
|
// The sun rises from behind the horizon once, on the visit's first paint.
|
||||||
|
const LOGO =
|
||||||
|
'<svg class="logo" viewBox="0 0 24 24" aria-hidden="true"><defs><clipPath id="dl-sky"><rect width="24" height="17"/></clipPath></defs>' +
|
||||||
|
'<g clip-path="url(#dl-sky)"><path class="sun" d="M3 15a9 9 0 0 1 18 0z"/></g><rect class="bar" x="2" y="17" width="20" height="2" rx="1"/></svg>';
|
||||||
|
|
||||||
|
let crumbsEl: HTMLElement | null = null;
|
||||||
|
let bodyEl: HTMLElement | null = null;
|
||||||
|
let pageEl: HTMLElement | null = null;
|
||||||
|
|
||||||
|
/** The frame, built once into #app; returns the slot the page's content goes in. */
|
||||||
|
export function frame(app: HTMLElement): HTMLElement {
|
||||||
|
if (bodyEl) return bodyEl;
|
||||||
|
crumbsEl = h('header', { class: 'crumbs' });
|
||||||
|
bodyEl = h('div', { class: 'page-body' });
|
||||||
|
app.replaceChildren(
|
||||||
|
h('div', { class: 'edge-fade top', 'aria-hidden': 'true' }),
|
||||||
|
h('div', { class: 'edge-fade bot', 'aria-hidden': 'true' }),
|
||||||
|
(pageEl = h('main', { class: 'page' }, crumbsEl, bodyEl)),
|
||||||
|
);
|
||||||
|
const onScroll = () => document.body.classList.toggle('scrolled', scrollY > 2);
|
||||||
|
addEventListener('scroll', onScroll, { passive: true });
|
||||||
|
onScroll();
|
||||||
|
return bodyEl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One card in place of the page (the link gone, nothing loaded, access paused): it and the breadcrumb sit in the middle of the screen. */
|
||||||
|
export function single(on: boolean) {
|
||||||
|
pageEl?.classList.toggle('single', on);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The breadcrumb: the place, then the person (none when the link stopped
|
||||||
|
* working); at its end, this page's code for another device, on the page
|
||||||
|
* itself only (not over a card: paused, link gone, nothing loaded).
|
||||||
|
*/
|
||||||
|
export function crumbs(gone = false, card = false) {
|
||||||
|
if (!crumbsEl) return;
|
||||||
|
const p = gone ? null : state()?.person;
|
||||||
|
const place = h('span', { class: p ? '' : 'cur', 'aria-current': p ? null : 'page' }, placeName());
|
||||||
|
crumbsEl.replaceChildren(
|
||||||
|
h('span', { class: 'cr-mark' }, markup(LOGO)),
|
||||||
|
h(
|
||||||
|
'nav',
|
||||||
|
{ class: 'cr-path', 'aria-label': 'Breadcrumb' },
|
||||||
|
place,
|
||||||
|
p ? [ic('chevron'), h('span', { class: 'cur', 'aria-current': 'page' }, p.name)] : null,
|
||||||
|
),
|
||||||
|
...(p && !card
|
||||||
|
? [h('button', { type: 'button', class: 'knob cr-qr', 'aria-label': 'Open on another device', onclick: showPageCode }, ic('qr'))]
|
||||||
|
: []),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// What stops the person's devices, said once at the top of the page: paused,
|
||||||
|
// ended, out of data, outside the hours, the server off or missing, or access
|
||||||
|
// ending soon. A notice wears its tone (orange or red) in its tint.
|
||||||
|
|
||||||
|
import type { Person } from '../../shared/types';
|
||||||
|
import { daysLeft, date, endsIn, endsSoon } from '../../shared/format';
|
||||||
|
import { h } from '../dom';
|
||||||
|
import { clockOf, hoursFor } from '../days';
|
||||||
|
import { state, today } from '../state';
|
||||||
|
import { glass } from '../ui/glass';
|
||||||
|
|
||||||
|
export type Tone = 'warn' | 'bad';
|
||||||
|
|
||||||
|
export function notice(tone: Tone, icon: string, title: string | null, sub: string): HTMLElement {
|
||||||
|
return h(
|
||||||
|
'div',
|
||||||
|
{ class: `notice ${tone}` },
|
||||||
|
glass(icon, tone === 'bad' ? 'red' : 'orange'),
|
||||||
|
h('div', { class: 't' }, title ? h('b', {}, title) : null, h('span', {}, sub)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The admin's hours as the visitor reads them: "08:00–22:00 your time" (or the router's, said so). */
|
||||||
|
export function hoursText(hours: string): string {
|
||||||
|
const hw = hoursFor(hours, state()?.tz_offset, -new Date().getTimezoneOffset());
|
||||||
|
if (!hw) return `${hours.replace('-', '–')} (router time)`;
|
||||||
|
return `${clockOf(hw.from)}–${clockOf(hw.to)} ${hw.yours ? 'your time' : '(router time)'}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Why the person's devices can't connect: icon, a short title, and a line that adds to it (never says it again). */
|
||||||
|
export function stateNotice(p: Person): [string, string, string] {
|
||||||
|
switch (p.state) {
|
||||||
|
case 'server_off':
|
||||||
|
return ['server', 'Server is disabled', 'Your devices can’t connect until it’s enabled again.'];
|
||||||
|
case 'no_server':
|
||||||
|
return ['server', 'No server yet', 'You haven’t been added to one.'];
|
||||||
|
case 'quota':
|
||||||
|
return ['chart', 'Out of data', 'Nothing gets through until it resets.'];
|
||||||
|
case 'expired':
|
||||||
|
return ['calendar', 'Access ended', 'Your devices can’t connect until it’s extended.'];
|
||||||
|
case 'hours':
|
||||||
|
return ['clock', 'Outside your hours', `Open ${hoursText(p.hours)}.`];
|
||||||
|
default:
|
||||||
|
return ['pause', 'Access paused', 'Your devices can’t connect until it’s resumed.'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The page's notice, or null when nothing stands in the way. */
|
||||||
|
export function pageNotice(p: Person): HTMLElement | null {
|
||||||
|
if (p.state !== 'active') return notice(p.state === 'quota' || p.state === 'expired' ? 'bad' : 'warn', ...stateNotice(p));
|
||||||
|
const left = daysLeft(p.expires, today());
|
||||||
|
return endsSoon(p, left) ? notice('warn', 'calendar', `Access ${endsIn(left as number)}`, `On ${date(p.expires)}.`) : null;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// Setting up a device: which app, where it comes from, and whether the page
|
// Setting up a device: which app, where it comes from, and whether the page
|
||||||
// is open on the device being set up. Pure: the sheet in main.ts draws it.
|
// is open on the device being set up. Pure: the set-up sheet (flows/) draws it.
|
||||||
|
|
||||||
import type { Kind } from '../shared/types';
|
import type { Kind } from '../shared/types';
|
||||||
|
|
||||||
@@ -33,45 +33,21 @@ export function sameDevice(kind: Kind, platform: Platform): boolean {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The systems a kind may run, when that is the person's call: a computer's
|
|
||||||
* desktop systems, any system for an "other" device (a TV box runs Android, a
|
|
||||||
* NAS Linux). A phone's or a tablet's is read from the browser.
|
|
||||||
*/
|
|
||||||
export const osGroup = (kind: Kind): Platform[] =>
|
|
||||||
kind === 'computer' ? ['windows', 'mac', 'linux'] : kind === 'other' ? ['ios', 'android', 'windows', 'mac', 'linux'] : [];
|
|
||||||
|
|
||||||
export interface AppChoice {
|
export interface AppChoice {
|
||||||
id: AppId;
|
id: AppId;
|
||||||
name: string;
|
name: string;
|
||||||
/** The version this server needs, as "4.8.12" or ""; "current" when only the newest will do. */
|
|
||||||
need: string;
|
|
||||||
sub: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The apps that connect to a server with this disguise, the recommended one first. */
|
/** The apps that connect to a server with this disguise, the recommended one first; any WireGuard app without one. */
|
||||||
export function appsFor(preset: Preset): AppChoice[] {
|
export function appsFor(preset: Preset): AppChoice[] {
|
||||||
const need = {
|
|
||||||
off: { vpn: '', awg: '' },
|
|
||||||
balanced: { vpn: '4.8.12', awg: '2.0' },
|
|
||||||
max: { vpn: 'current', awg: '3.1' },
|
|
||||||
legacy: { vpn: '', awg: '' },
|
|
||||||
}[preset];
|
|
||||||
const out: AppChoice[] = [
|
const out: AppChoice[] = [
|
||||||
{ id: 'vpn', name: APP_NAME.vpn, need: need.vpn, sub: 'Connects from a link, no files' },
|
{ id: 'vpn', name: APP_NAME.vpn },
|
||||||
{ id: 'awg', name: APP_NAME.awg, need: need.awg, sub: 'The light client: a file or a QR code' },
|
{ id: 'awg', name: APP_NAME.awg },
|
||||||
];
|
];
|
||||||
if (preset === 'off') out.push({ id: 'wg', name: APP_NAME.wg, need: '', sub: 'Any WireGuard app: this server has no disguise' });
|
if (preset === 'off') out.push({ id: 'wg', name: APP_NAME.wg });
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** "This server needs AmneziaVPN 4.8.12 or newer. …", or "" when any version will do. */
|
|
||||||
export function updateLine(app: AppChoice): string {
|
|
||||||
if (!app.need) return '';
|
|
||||||
const what = app.need === 'current' ? `the current version of ${app.name}` : `${app.name} ${app.need} or newer`;
|
|
||||||
return `This server needs ${what}. Installed a while ago? Update it in the store.`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Mark = 'appstore' | 'googleplay' | 'windows' | 'apple' | 'linux' | 'openwrt' | 'github' | 'site';
|
export type Mark = 'appstore' | 'googleplay' | 'windows' | 'apple' | 'linux' | 'openwrt' | 'github' | 'site';
|
||||||
|
|
||||||
export interface Store {
|
export interface Store {
|
||||||
@@ -157,7 +133,8 @@ export const routerStore = (app: AppId): Store =>
|
|||||||
main: 'wireguard-tools',
|
main: 'wireguard-tools',
|
||||||
mark: 'openwrt',
|
mark: 'openwrt',
|
||||||
}
|
}
|
||||||
: { href: 'https://openwrt.org/packages/start', top: 'OpenWrt packages', main: 'amneziawg-tools + kmod', mark: 'openwrt' };
|
: // One line on a phone: the kernel module goes on top.
|
||||||
|
{ href: 'https://openwrt.org/packages/start', top: 'OpenWrt packages + kmod', main: 'amneziawg-tools', mark: 'openwrt' };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does AmneziaVPN here open a `vpn://` link? Only the Android app registers the
|
* Does AmneziaVPN here open a `vpn://` link? Only the Android app registers the
|
||||||
@@ -234,13 +211,15 @@ export function setupFromHash(hash: string): string | null {
|
|||||||
return /^#setup=(d_[0-9a-f]{8})$/.exec(hash)?.[1] ?? null;
|
return /^#setup=(d_[0-9a-f]{8})$/.exec(hash)?.[1] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The personal link that opens straight on "Add a device": for the device itself to add, from its own browser. */
|
||||||
|
export const addLink = (page: string): string => `${page}#add`;
|
||||||
|
|
||||||
|
/** Does the link ask to add a device (`#add`)? */
|
||||||
|
export const wantsAdd = (hash: string): boolean => hash === '#add';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "the phone", "the computer": the device being set up, in a sentence. The
|
* "the phone", "the computer": the device being set up, in a sentence. The
|
||||||
* sheet's title already names it; the lines under it do not repeat the name.
|
* sheet's title already names it; the lines under it do not repeat the name.
|
||||||
*/
|
*/
|
||||||
export const deviceNoun = (kind: Kind): string =>
|
export const deviceNoun = (kind: Kind): string =>
|
||||||
({ phone: 'phone', tablet: 'tablet', computer: 'computer', router: 'router', other: 'device' })[kind];
|
({ phone: 'phone', tablet: 'tablet', computer: 'computer', router: 'router', other: 'device' })[kind];
|
||||||
|
|
||||||
/** "This iPhone", "This Mac": the pill for the device in hand. */
|
|
||||||
export const hereLabel = (platform: Platform): string =>
|
|
||||||
({ ios: 'This iPhone', android: 'This phone', windows: 'This PC', mac: 'This Mac', linux: 'This PC', unknown: 'This device' })[platform];
|
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
// The page's state: the router's last answer, its clock and calendar, where the
|
||||||
|
// page is open and what the server runs. Everything that draws reads it from
|
||||||
|
// here. It also holds the one hook back to the page (`repaint`), so a flow can
|
||||||
|
// redraw the page without knowing how the page is built (main.ts sets it).
|
||||||
|
|
||||||
|
import type { Kind, Person } from '../shared/types';
|
||||||
|
import { isoDay } from '../shared/format';
|
||||||
|
import { platformOf, type Platform, type Preset } from './setup';
|
||||||
|
|
||||||
|
export interface State {
|
||||||
|
person: Person;
|
||||||
|
/** device_mesh: devices with home access reach each other through the tunnel. */
|
||||||
|
/** awg_disguise: false = plain WireGuard, any WireGuard app connects. */
|
||||||
|
server: { name?: string; endpoint: string; device_mesh?: boolean; awg_disguise?: boolean; preset?: Preset };
|
||||||
|
/** The device this page was opened from (through the tunnel), if any. */
|
||||||
|
here?: string | null;
|
||||||
|
can_add: boolean;
|
||||||
|
/** The admin stopped the person (paused, access ended): the page only shows. */
|
||||||
|
locked?: boolean;
|
||||||
|
/** Over plain HTTP: the same link over HTTPS, where the connection settings are. */
|
||||||
|
https_url?: string | null;
|
||||||
|
kinds: Kind[];
|
||||||
|
version: string;
|
||||||
|
/** The router's day (YYYY-MM-DD) when it sends one; the browser's otherwise. */
|
||||||
|
today?: string;
|
||||||
|
/** The router's clock (epoch seconds): relative times are measured against it, not the phone's. */
|
||||||
|
now?: number;
|
||||||
|
/** The router's UTC offset in minutes: the admin sets hours in its time, the page shows the visitor's. */
|
||||||
|
tz_offset?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
let current: State | null = null;
|
||||||
|
|
||||||
|
export const state = (): State | null => current;
|
||||||
|
export function setState(st: State | null) {
|
||||||
|
current = st;
|
||||||
|
}
|
||||||
|
|
||||||
|
const app = document.getElementById('app')!;
|
||||||
|
/** The page's path: the personal link. Its last part is the code (no sessions). */
|
||||||
|
export const base = app.dataset.base ?? '';
|
||||||
|
export const code = /^\/[a-z]{6}-[a-z]{6}-[a-z]{6}$/.test(base) ? base.slice(1) : '';
|
||||||
|
/** This page's own address, without the fragment: what a link to another device carries. */
|
||||||
|
export const pageUrl = () => location.origin + location.pathname;
|
||||||
|
|
||||||
|
/** Today on the router, for days left and chart labels. */
|
||||||
|
export const today = () => current?.today ?? isoDay(new Date());
|
||||||
|
/** Now on the router (seconds), for "last connected 3 min ago". */
|
||||||
|
export const now = () => current?.now ?? Date.now() / 1000;
|
||||||
|
|
||||||
|
/** The platform this page is open on (iPad on Safari says Mac; touch points tell). */
|
||||||
|
export const platform = (): Platform => platformOf(navigator.userAgent, navigator.maxTouchPoints);
|
||||||
|
/** The server's disguise is off: plain WireGuard, so any WireGuard app connects. */
|
||||||
|
export const plainWg = () => current?.server.awg_disguise === false;
|
||||||
|
/** The server's disguise generation, for which apps and versions connect. */
|
||||||
|
export const preset = (): Preset => current?.server.preset ?? (plainWg() ? 'off' : 'max');
|
||||||
|
/** The secure twin when this page is plain HTTP, else null. */
|
||||||
|
export const httpsTwin = () => current?.https_url || null;
|
||||||
|
/** The place this page belongs to: the server's name, "Dawnline" where there is none to name. */
|
||||||
|
export const placeName = () => current?.server.name || 'Dawnline';
|
||||||
|
|
||||||
|
export interface RepaintOpts {
|
||||||
|
/** A card that is new: it pops in. */
|
||||||
|
pop?: string;
|
||||||
|
/** A card that just connected: a green ring fades on it. */
|
||||||
|
flash?: string;
|
||||||
|
}
|
||||||
|
let painter: (o: RepaintOpts) => void = () => undefined;
|
||||||
|
/** main.ts: how to draw the page again. */
|
||||||
|
export function onRepaint(fn: (o: RepaintOpts) => void) {
|
||||||
|
painter = fn;
|
||||||
|
}
|
||||||
|
/** Draw the page again from the current state (a flow changed something). */
|
||||||
|
export const repaint = (o: RepaintOpts = {}) => painter(o);
|
||||||
@@ -0,0 +1,345 @@
|
|||||||
|
/* "Your access": what it reaches as two tiles and the names at home; the data as a ring in the head
|
||||||
|
and the month day by day inside; until when as the days left over a calendar of the weeks, and
|
||||||
|
the hours as a bar of the day. */
|
||||||
|
|
||||||
|
.reach2 {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.reach-tile {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1px;
|
||||||
|
padding: 12px 12px 12px 14px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background: var(--field);
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.reach-tile .rt-ic {
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
.reach-tile b {
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.015em;
|
||||||
|
}
|
||||||
|
.reach-tile .rt-sub {
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 16px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.reach-tile .rt-mark {
|
||||||
|
position: absolute;
|
||||||
|
top: 12px;
|
||||||
|
right: 12px;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
border-radius: 50%;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
background: var(--ok-soft);
|
||||||
|
color: var(--ok);
|
||||||
|
}
|
||||||
|
.reach-tile .rt-mark .i {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
stroke-width: 2.4;
|
||||||
|
}
|
||||||
|
.reach-tile.off b {
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.reach-tile.off .rt-sub {
|
||||||
|
color: var(--text-3);
|
||||||
|
}
|
||||||
|
.reach-tile.off .rt-ic {
|
||||||
|
opacity: 0.45;
|
||||||
|
}
|
||||||
|
.reach-tile.off .rt-mark {
|
||||||
|
background: var(--knob);
|
||||||
|
color: var(--text-3);
|
||||||
|
}
|
||||||
|
.lbl-s {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.names {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.namechip {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
height: 32px;
|
||||||
|
padding: 0 10px 0 12px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: var(--field);
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 13px;
|
||||||
|
letter-spacing: 0;
|
||||||
|
transition:
|
||||||
|
background-color 150ms,
|
||||||
|
transform 150ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.namechip:hover {
|
||||||
|
background: var(--knob);
|
||||||
|
}
|
||||||
|
.namechip:active {
|
||||||
|
transform: scale(0.96);
|
||||||
|
}
|
||||||
|
.namechip .faint {
|
||||||
|
color: var(--text-3);
|
||||||
|
}
|
||||||
|
.namechip .i {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ring {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
}
|
||||||
|
.ring .trk {
|
||||||
|
stroke: var(--bar);
|
||||||
|
}
|
||||||
|
.ring .arc {
|
||||||
|
stroke: var(--accent);
|
||||||
|
}
|
||||||
|
.ring .arc.warn {
|
||||||
|
stroke: var(--warn);
|
||||||
|
}
|
||||||
|
.ring .arc.bad {
|
||||||
|
stroke: var(--bad);
|
||||||
|
}
|
||||||
|
.month {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.mbars {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 3px;
|
||||||
|
height: 64px;
|
||||||
|
}
|
||||||
|
.mbars i {
|
||||||
|
flex: 1;
|
||||||
|
border-radius: 2.5px;
|
||||||
|
background: var(--bar);
|
||||||
|
min-height: 3px;
|
||||||
|
transition: background-color 120ms;
|
||||||
|
}
|
||||||
|
.mbars i.future {
|
||||||
|
background: color-mix(in srgb, var(--bar) 45%, transparent);
|
||||||
|
}
|
||||||
|
.mbars i.today {
|
||||||
|
background: var(--accent);
|
||||||
|
}
|
||||||
|
.mbars i:not(.future):hover {
|
||||||
|
background: var(--text-2);
|
||||||
|
}
|
||||||
|
.month-axis {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-3);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.month-axis .td {
|
||||||
|
position: absolute;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
.month-axis .hide {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
.month-read {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: baseline;
|
||||||
|
margin-top: 10px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.month-read b {
|
||||||
|
color: var(--text);
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 15px;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
.meter {
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: var(--bar);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.meter > i {
|
||||||
|
display: block;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: var(--accent);
|
||||||
|
}
|
||||||
|
.meter > i.warn {
|
||||||
|
background: var(--warn);
|
||||||
|
}
|
||||||
|
.meter > i.bad {
|
||||||
|
background: var(--bad);
|
||||||
|
}
|
||||||
|
|
||||||
|
.until {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
padding: 14px 16px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background: var(--field);
|
||||||
|
}
|
||||||
|
.until-num {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.until-num b {
|
||||||
|
font-size: 36px;
|
||||||
|
line-height: 40px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: -0.045em;
|
||||||
|
}
|
||||||
|
.until-num span {
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 18px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.until-num .until-sub {
|
||||||
|
margin-top: 8px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-3);
|
||||||
|
}
|
||||||
|
.until.soon .until-num b {
|
||||||
|
color: var(--warn);
|
||||||
|
}
|
||||||
|
.cal {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
.cal-h,
|
||||||
|
.cal-g {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(7, 10px);
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
.cal-h span {
|
||||||
|
font-size: 9px;
|
||||||
|
line-height: 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-3);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.cal-g i {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: color-mix(in srgb, var(--text) 16%, transparent);
|
||||||
|
}
|
||||||
|
.cal-g i.past {
|
||||||
|
background: color-mix(in srgb, var(--text) 5%, transparent);
|
||||||
|
}
|
||||||
|
.cal-g i.today {
|
||||||
|
background: var(--accent);
|
||||||
|
}
|
||||||
|
.cal-g i.end {
|
||||||
|
background: transparent;
|
||||||
|
box-shadow: inset 0 0 0 1.5px var(--accent);
|
||||||
|
}
|
||||||
|
.cal-g i.after {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
.until.soon .cal-g i.today {
|
||||||
|
background: var(--warn);
|
||||||
|
}
|
||||||
|
.until.soon .cal-g i.end {
|
||||||
|
box-shadow: inset 0 0 0 1.5px var(--warn);
|
||||||
|
}
|
||||||
|
.acc-row.open .cal-g i {
|
||||||
|
animation: cal-in 360ms var(--ease-out) backwards;
|
||||||
|
animation-delay: calc(var(--i) * 7ms);
|
||||||
|
}
|
||||||
|
@keyframes cal-in {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.hours {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 14px 16px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background: var(--field);
|
||||||
|
}
|
||||||
|
.hours-top {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: baseline;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.hours-top b {
|
||||||
|
color: var(--text);
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 15px;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
.hours-bar {
|
||||||
|
position: relative;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||||
|
}
|
||||||
|
.hours-bar i {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: color-mix(in srgb, var(--ok) 70%, transparent);
|
||||||
|
}
|
||||||
|
.hours-now {
|
||||||
|
position: absolute;
|
||||||
|
top: -4px;
|
||||||
|
width: 2px;
|
||||||
|
height: 16px;
|
||||||
|
margin-left: -1px;
|
||||||
|
border-radius: 1px;
|
||||||
|
background: var(--text);
|
||||||
|
box-shadow: 0 0 0 2px var(--field);
|
||||||
|
}
|
||||||
|
.hours-now.out {
|
||||||
|
background: var(--warn);
|
||||||
|
}
|
||||||
|
.hours-axis {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--text-3);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.acc-row.open .cal-g i {
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
/* The bouncy accordion: rows touch while closed and share their rounded ends; an open row lifts
|
||||||
|
out with 10px gaps and its own corners (ui/accordion.ts animates between the two shapes). Inside
|
||||||
|
the sheet ("inset") the rows sit one step lighter than the sheet. */
|
||||||
|
|
||||||
|
.acc {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.acc-row {
|
||||||
|
background: var(--raised);
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 0;
|
||||||
|
padding: 0 8px;
|
||||||
|
transition: background-color 150ms;
|
||||||
|
}
|
||||||
|
.acc-row.rt {
|
||||||
|
border-top-left-radius: var(--r-row);
|
||||||
|
border-top-right-radius: var(--r-row);
|
||||||
|
}
|
||||||
|
.acc-row.rb {
|
||||||
|
border-bottom-left-radius: var(--r-row);
|
||||||
|
border-bottom-right-radius: var(--r-row);
|
||||||
|
}
|
||||||
|
.acc-row.open {
|
||||||
|
margin-block: 10px;
|
||||||
|
}
|
||||||
|
.acc-row.open:first-child {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
.acc-row.open:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
.acc-row:not(.open):not(.still):hover {
|
||||||
|
background: color-mix(in srgb, var(--raised), var(--knob) 40%);
|
||||||
|
}
|
||||||
|
.acc-head {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
height: 52px;
|
||||||
|
padding: 0 6px 0 8px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.acc-row.still .acc-head {
|
||||||
|
cursor: default;
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
|
.acc-head .gi {
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
}
|
||||||
|
.acc-title {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.acc-title .t {
|
||||||
|
min-width: 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
/* A row whose body shows its numbers drops them from its head while open. */
|
||||||
|
.acc-val {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: var(--text-2);
|
||||||
|
font-size: 14px;
|
||||||
|
white-space: nowrap;
|
||||||
|
transition:
|
||||||
|
opacity 200ms var(--ease-out),
|
||||||
|
filter 200ms var(--ease-out),
|
||||||
|
transform 260ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.acc-val > span {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.acc-row.open .acc-val.hide-open {
|
||||||
|
opacity: 0;
|
||||||
|
filter: blur(4px);
|
||||||
|
transform: translateX(8px);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.acc-chev {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
color: var(--text-2);
|
||||||
|
transform: rotate(90deg);
|
||||||
|
transition: transform var(--spring-soft-dur, 470ms) var(--spring-soft, ease);
|
||||||
|
}
|
||||||
|
.acc-row.open .acc-chev {
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
}
|
||||||
|
.acc-body {
|
||||||
|
display: none;
|
||||||
|
padding: 0 8px 16px 40px;
|
||||||
|
}
|
||||||
|
.acc-row.open .acc-body,
|
||||||
|
.acc-row.closing .acc-body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
.acc .desc {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
.acc.inset .acc-row {
|
||||||
|
background: var(--field);
|
||||||
|
}
|
||||||
|
.acc.inset .acc-row:not(.open):not(.still):hover {
|
||||||
|
background: color-mix(in srgb, var(--field), var(--knob) 50%);
|
||||||
|
}
|
||||||
|
.acc.inset .acc-body {
|
||||||
|
padding-left: 8px;
|
||||||
|
}
|
||||||
|
.acc.inset .seg {
|
||||||
|
background: color-mix(in srgb, var(--knob) 65%, var(--field));
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.acc-chev {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
/* The ground every part stands on: the reset, the type, focus and selection, the small utilities,
|
||||||
|
the icons (line icons and the glass ones). */
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
html {
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
/* The page keeps its width when a sheet locks the scroll: no sideways jump behind the scrim. */
|
||||||
|
scrollbar-gutter: stable;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: var(--bg);
|
||||||
|
color: var(--text);
|
||||||
|
font: 400 15px/22px var(--font);
|
||||||
|
letter-spacing: -0.011em;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
min-height: 100vh;
|
||||||
|
min-height: 100dvh;
|
||||||
|
/* An app, not a document: the arrow over text. Controls set the hand; what is typed or copied by
|
||||||
|
hand (fields, the link, the configuration) keeps the I-beam. */
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
body.locked {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
input,
|
||||||
|
textarea,
|
||||||
|
.linkrow .mono,
|
||||||
|
.conf {
|
||||||
|
cursor: text;
|
||||||
|
}
|
||||||
|
::selection {
|
||||||
|
background: var(--sel-bg);
|
||||||
|
color: var(--sel-fg);
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
font: inherit;
|
||||||
|
color: inherit;
|
||||||
|
letter-spacing: inherit;
|
||||||
|
background: none;
|
||||||
|
border: 0;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
button:disabled {
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
:focus {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
:focus-visible {
|
||||||
|
outline: 2px solid color-mix(in srgb, var(--accent) 65%, transparent);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
[hidden] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
.offscreen {
|
||||||
|
position: fixed;
|
||||||
|
left: -9999px;
|
||||||
|
top: 0;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
.mono {
|
||||||
|
font-family: var(--mono);
|
||||||
|
letter-spacing: 0;
|
||||||
|
}
|
||||||
|
.num {
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
.ok-t {
|
||||||
|
color: var(--ok);
|
||||||
|
}
|
||||||
|
.warn-t {
|
||||||
|
color: var(--warn);
|
||||||
|
}
|
||||||
|
.bad-t {
|
||||||
|
color: var(--bad);
|
||||||
|
}
|
||||||
|
.here-t {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* line icons */
|
||||||
|
.i {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* glass icons: the colours come from here (the CSP drops style attributes) */
|
||||||
|
.gi {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
flex: none;
|
||||||
|
overflow: visible;
|
||||||
|
--ta: var(--t-grey-a);
|
||||||
|
--tb: var(--t-grey-b);
|
||||||
|
}
|
||||||
|
.gi.t-blue {
|
||||||
|
--ta: var(--t-blue-a);
|
||||||
|
--tb: var(--t-blue-b);
|
||||||
|
}
|
||||||
|
.gi.t-green {
|
||||||
|
--ta: var(--t-green-a);
|
||||||
|
--tb: var(--t-green-b);
|
||||||
|
}
|
||||||
|
.gi.t-red {
|
||||||
|
--ta: var(--t-red-a);
|
||||||
|
--tb: var(--t-red-b);
|
||||||
|
}
|
||||||
|
.gi.t-orange {
|
||||||
|
--ta: var(--t-orange-a);
|
||||||
|
--tb: var(--t-orange-b);
|
||||||
|
}
|
||||||
|
.gi .ta {
|
||||||
|
stop-color: var(--ta);
|
||||||
|
}
|
||||||
|
.gi .tb {
|
||||||
|
stop-color: var(--tb);
|
||||||
|
}
|
||||||
|
.gi .fa {
|
||||||
|
stop-color: var(--gi-a);
|
||||||
|
}
|
||||||
|
.gi .fb {
|
||||||
|
stop-color: var(--gi-b);
|
||||||
|
}
|
||||||
|
.gi .fc {
|
||||||
|
stop-color: var(--ta);
|
||||||
|
stop-opacity: 0.28;
|
||||||
|
}
|
||||||
|
.gi .ge {
|
||||||
|
stroke: var(--gi-edge);
|
||||||
|
}
|
||||||
|
.gi .gr {
|
||||||
|
stroke: var(--gi-rim);
|
||||||
|
}
|
||||||
|
.gi .gd {
|
||||||
|
stroke: var(--gi-detail);
|
||||||
|
}
|
||||||
|
.gi .gdf {
|
||||||
|
color: var(--gi-detail);
|
||||||
|
}
|
||||||
@@ -0,0 +1,660 @@
|
|||||||
|
/* The controls every part uses: round knobs, buttons (and their busy orb), the field with its
|
||||||
|
go button, the icon picker, the kinds with their ring, badges, hints and menu paths, the link row,
|
||||||
|
QR codes and the row that puts a code beside its words. */
|
||||||
|
|
||||||
|
.knob {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--knob);
|
||||||
|
color: var(--text);
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
flex: none;
|
||||||
|
transition:
|
||||||
|
transform 150ms var(--ease-out),
|
||||||
|
background-color 150ms;
|
||||||
|
}
|
||||||
|
.knob:hover {
|
||||||
|
background: color-mix(in srgb, var(--knob), var(--text) 6%);
|
||||||
|
}
|
||||||
|
.knob:active {
|
||||||
|
transform: scale(0.8);
|
||||||
|
}
|
||||||
|
.knob .i {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
}
|
||||||
|
.knob.back .i {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
.knob[aria-expanded='true'] {
|
||||||
|
background: color-mix(in srgb, var(--knob), var(--text) 10%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
height: 48px;
|
||||||
|
border-radius: 999px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 0 20px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.015em;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
transition:
|
||||||
|
transform 200ms var(--ease-out),
|
||||||
|
background-color 200ms var(--ease-out),
|
||||||
|
color 200ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.btn:active {
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
.btn.block {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.btn.sm {
|
||||||
|
height: 40px;
|
||||||
|
font-size: 15px;
|
||||||
|
padding: 0 16px;
|
||||||
|
}
|
||||||
|
.btn.accent {
|
||||||
|
background: var(--accent);
|
||||||
|
color: var(--accent-ink);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.btn.accent:hover {
|
||||||
|
background: color-mix(in srgb, var(--accent) 82%, transparent);
|
||||||
|
}
|
||||||
|
/* The quiet accent: a card's Connect, tinted rather than filled. */
|
||||||
|
.btn.tint {
|
||||||
|
background: var(--accent-soft);
|
||||||
|
color: var(--accent);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.btn.tint:hover {
|
||||||
|
background: color-mix(in srgb, var(--accent) 20%, transparent);
|
||||||
|
}
|
||||||
|
.btn.tint:active {
|
||||||
|
background: color-mix(in srgb, var(--accent) 24%, transparent);
|
||||||
|
}
|
||||||
|
.btn.soft {
|
||||||
|
background: var(--knob);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.btn.soft:hover {
|
||||||
|
background: color-mix(in srgb, var(--knob), var(--text) 6%);
|
||||||
|
}
|
||||||
|
.btn.red {
|
||||||
|
background: var(--bad);
|
||||||
|
color: #fff;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
/* Waiting for the router: the button keeps its size, its content blurs away and an orb comes up in
|
||||||
|
its place (ui/busy.ts runs the change). The orb is B4 Converge from aicss.dev's Orbs, at its own
|
||||||
|
28px stage and twice its speed: one circle walks a triangle, sharp at each corner and smaller,
|
||||||
|
softer in between; a second breathes in the middle. */
|
||||||
|
.busy {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.orb {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
margin: auto;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
overflow: hidden;
|
||||||
|
contain: strict;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.orb i {
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
|
width: 7px;
|
||||||
|
height: 7px;
|
||||||
|
margin: -3.5px 0 0 -3.5px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: currentColor;
|
||||||
|
animation: orb-converge 1.8s linear infinite both;
|
||||||
|
}
|
||||||
|
.orb i:nth-child(2) {
|
||||||
|
animation: orb-breathe 1.8s ease-in-out infinite both;
|
||||||
|
}
|
||||||
|
/* Top, bottom right, bottom left: a beat at each corner, then away (ease-in) and in (ease-out). */
|
||||||
|
@keyframes orb-converge {
|
||||||
|
0% {
|
||||||
|
transform: translate(0px, -5px) scale(1);
|
||||||
|
filter: blur(0);
|
||||||
|
animation-timing-function: linear;
|
||||||
|
}
|
||||||
|
10% {
|
||||||
|
transform: translate(0px, -5px) scale(1);
|
||||||
|
filter: blur(0);
|
||||||
|
animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45);
|
||||||
|
}
|
||||||
|
22% {
|
||||||
|
transform: translate(2.15px, -1.25px) scale(0.72);
|
||||||
|
filter: blur(0.8px);
|
||||||
|
animation-timing-function: cubic-bezier(0.33, 1, 0.68, 1);
|
||||||
|
}
|
||||||
|
33% {
|
||||||
|
transform: translate(4.3px, 2.5px) scale(1);
|
||||||
|
filter: blur(0);
|
||||||
|
animation-timing-function: linear;
|
||||||
|
}
|
||||||
|
43% {
|
||||||
|
transform: translate(4.3px, 2.5px) scale(1);
|
||||||
|
filter: blur(0);
|
||||||
|
animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45);
|
||||||
|
}
|
||||||
|
55% {
|
||||||
|
transform: translate(0px, 2.5px) scale(0.72);
|
||||||
|
filter: blur(0.8px);
|
||||||
|
animation-timing-function: cubic-bezier(0.33, 1, 0.68, 1);
|
||||||
|
}
|
||||||
|
66% {
|
||||||
|
transform: translate(-4.3px, 2.5px) scale(1);
|
||||||
|
filter: blur(0);
|
||||||
|
animation-timing-function: linear;
|
||||||
|
}
|
||||||
|
77% {
|
||||||
|
transform: translate(-4.3px, 2.5px) scale(1);
|
||||||
|
filter: blur(0);
|
||||||
|
animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45);
|
||||||
|
}
|
||||||
|
88% {
|
||||||
|
transform: translate(-2.15px, -1.25px) scale(0.72);
|
||||||
|
filter: blur(0.8px);
|
||||||
|
animation-timing-function: cubic-bezier(0.33, 1, 0.68, 1);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translate(0px, -5px) scale(1);
|
||||||
|
filter: blur(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes orb-breathe {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
opacity: 0.16;
|
||||||
|
filter: blur(2.4px);
|
||||||
|
transform: scale(1.2);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.32;
|
||||||
|
filter: blur(1.6px);
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.field {
|
||||||
|
height: 48px;
|
||||||
|
border-radius: var(--r-field);
|
||||||
|
background: var(--field);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 0 4px 0 16px;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: box-shadow 200ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.field:focus-within {
|
||||||
|
box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--text) 16%, transparent);
|
||||||
|
}
|
||||||
|
.field input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
border: 0;
|
||||||
|
outline: 0;
|
||||||
|
background: transparent;
|
||||||
|
padding: 0;
|
||||||
|
font: 500 16px/24px var(--font);
|
||||||
|
color: var(--text);
|
||||||
|
letter-spacing: -0.012em;
|
||||||
|
}
|
||||||
|
.field input::placeholder {
|
||||||
|
color: var(--text-3);
|
||||||
|
}
|
||||||
|
.go {
|
||||||
|
width: 48px;
|
||||||
|
height: 40px;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: var(--knob);
|
||||||
|
color: var(--text-3);
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
flex: none;
|
||||||
|
transition:
|
||||||
|
background-color 200ms var(--ease-out),
|
||||||
|
color 200ms var(--ease-out),
|
||||||
|
transform 200ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.go .i {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
.go.ready {
|
||||||
|
background: var(--accent);
|
||||||
|
color: var(--accent-ink);
|
||||||
|
}
|
||||||
|
.go.ready:active {
|
||||||
|
transform: scale(0.9);
|
||||||
|
}
|
||||||
|
.go:not(.ready) {
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The icon picker (skiper21's tabs): icons only, the picked one widens and shows its name. */
|
||||||
|
.seg {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
height: 48px;
|
||||||
|
padding: 0 4px;
|
||||||
|
border-radius: var(--r-field);
|
||||||
|
background: var(--field);
|
||||||
|
}
|
||||||
|
.seg-pill {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 4px;
|
||||||
|
height: 40px;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: var(--seg);
|
||||||
|
box-shadow: var(--seg-shadow);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.seg-b {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
height: 40px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-3);
|
||||||
|
white-space: nowrap;
|
||||||
|
transition: color 200ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.seg-b.on {
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.seg-b:not(.on):hover {
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.appseg .seg-b {
|
||||||
|
flex: 0 0 56px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
justify-content: safe center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 0 18px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.appseg .seg-b.on {
|
||||||
|
flex: 1 1 56px;
|
||||||
|
}
|
||||||
|
.appseg .seg-b .i {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
.appseg .seg-l {
|
||||||
|
max-width: 0;
|
||||||
|
opacity: 0;
|
||||||
|
margin-left: -8px;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.appseg .seg-b.on .seg-l {
|
||||||
|
max-width: 180px;
|
||||||
|
opacity: 1;
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
/* Three apps on a phone: the icons take less room, so the picked one's name fits whole. */
|
||||||
|
.appseg {
|
||||||
|
container-type: inline-size;
|
||||||
|
}
|
||||||
|
@container (max-width: 300px) {
|
||||||
|
.appseg .seg-b {
|
||||||
|
flex-basis: 44px;
|
||||||
|
padding: 0 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* What a new device is: four tiles, the picked one ringed in place; the label under its tile. */
|
||||||
|
.kinds {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr));
|
||||||
|
gap: 8px;
|
||||||
|
position: relative;
|
||||||
|
container-type: inline-size;
|
||||||
|
}
|
||||||
|
.kind {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
color: var(--text-3);
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
transition: color 200ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.kind-tile {
|
||||||
|
width: 100%;
|
||||||
|
height: 56px;
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--field);
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
transition:
|
||||||
|
background-color 200ms var(--ease-out),
|
||||||
|
transform 200ms var(--ease-out),
|
||||||
|
box-shadow 220ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.kind.on .kind-tile {
|
||||||
|
box-shadow: inset 0 0 0 1.5px var(--accent);
|
||||||
|
}
|
||||||
|
.kind-lbl {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.kind:hover .kind-tile,
|
||||||
|
.kind:focus-visible .kind-tile {
|
||||||
|
background: var(--knob);
|
||||||
|
}
|
||||||
|
.kind:active .kind-tile {
|
||||||
|
transform: scale(0.94);
|
||||||
|
}
|
||||||
|
.kind:focus-visible {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.kind:focus-visible .kind-lbl,
|
||||||
|
.kind.on {
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.kind .gi {
|
||||||
|
width: 26px;
|
||||||
|
height: 26px;
|
||||||
|
filter: grayscale(1);
|
||||||
|
opacity: 0.55;
|
||||||
|
transition:
|
||||||
|
filter 260ms var(--ease-out),
|
||||||
|
opacity 260ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.kind.on .gi {
|
||||||
|
filter: none;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
@container (max-width: 330px) {
|
||||||
|
.kind-tile {
|
||||||
|
height: 50px;
|
||||||
|
}
|
||||||
|
.kind {
|
||||||
|
font-size: 11.5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.or {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
margin: 22px 0;
|
||||||
|
color: var(--text-3);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: 0.06em;
|
||||||
|
}
|
||||||
|
.or::before,
|
||||||
|
.or::after {
|
||||||
|
content: '';
|
||||||
|
flex: 1;
|
||||||
|
height: 1px;
|
||||||
|
background: var(--line);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A store (or an action) as a tile: its mark, two lines, a chevron or the open mark. */
|
||||||
|
.badge {
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
height: 60px;
|
||||||
|
padding: 0 14px 0 12px;
|
||||||
|
border-radius: 18px;
|
||||||
|
background: var(--field);
|
||||||
|
transition:
|
||||||
|
background-color 200ms,
|
||||||
|
transform 200ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.badge:hover {
|
||||||
|
background: var(--knob);
|
||||||
|
}
|
||||||
|
.badge:active {
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
.badge .b-ic {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: var(--text);
|
||||||
|
color: var(--raised);
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
.badge .b-ic .i {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
.badge .b-t {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.badge .b-top {
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 16px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.badge .b-main {
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 20px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.badge > .i {
|
||||||
|
color: var(--text-3);
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
}
|
||||||
|
/* Step 2 is neutral like the other tiles; only its mark keeps the accent. */
|
||||||
|
.badge.primary .b-ic {
|
||||||
|
background: var(--accent-soft);
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
.badges2 {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.badges2 .badge {
|
||||||
|
padding: 0 10px;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
.badges2 .badge > .i {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.badges2 .b-ic {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
}
|
||||||
|
.hint {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 18px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.hint a,
|
||||||
|
.hint button {
|
||||||
|
color: var(--accent);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.howto {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.howto li {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.howto li + li::before {
|
||||||
|
content: '›';
|
||||||
|
color: var(--text-3);
|
||||||
|
}
|
||||||
|
.howto b {
|
||||||
|
color: var(--text);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.linkrow {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
height: 44px;
|
||||||
|
padding: 0 4px 0 14px;
|
||||||
|
border-radius: 14px;
|
||||||
|
background: color-mix(in srgb, var(--knob) 72%, var(--field));
|
||||||
|
}
|
||||||
|
.view > .linkrow {
|
||||||
|
background: var(--field);
|
||||||
|
}
|
||||||
|
.linkrow .mono {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
font-size: 13px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
user-select: all;
|
||||||
|
}
|
||||||
|
.linkrow .knob {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
.linkrow .knob:hover {
|
||||||
|
background: var(--knob);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* QR codes: the night look on a dark theme, dark on white on a light one; a dense code fills its row. */
|
||||||
|
.qrbox {
|
||||||
|
position: relative;
|
||||||
|
width: 148px;
|
||||||
|
height: 148px;
|
||||||
|
flex: none;
|
||||||
|
border-radius: 18px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--qr-bg);
|
||||||
|
}
|
||||||
|
.qrbox.light {
|
||||||
|
box-shadow: inset 0 0 0 1px var(--line);
|
||||||
|
}
|
||||||
|
.qrbox.big {
|
||||||
|
width: 208px;
|
||||||
|
height: 208px;
|
||||||
|
border-radius: 24px;
|
||||||
|
align-self: center;
|
||||||
|
}
|
||||||
|
.qrbox.big + .linkrow {
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
.qrbox.dense {
|
||||||
|
width: 100%;
|
||||||
|
max-width: none;
|
||||||
|
height: auto;
|
||||||
|
aspect-ratio: 1;
|
||||||
|
align-self: stretch;
|
||||||
|
border-radius: 22px;
|
||||||
|
}
|
||||||
|
.qrbox svg {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
/* A code swapping for another: the old one lies over the new one while it fades. */
|
||||||
|
.qrbox > svg.old {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
}
|
||||||
|
.coderow {
|
||||||
|
display: flex;
|
||||||
|
gap: 14px;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
.coderow.stacked {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
.coderow .side {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.coderow .side b {
|
||||||
|
color: var(--text);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.side .words {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.side .words.old {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.side .arr {
|
||||||
|
color: var(--text-2);
|
||||||
|
font-weight: 400;
|
||||||
|
margin: 0 6px;
|
||||||
|
}
|
||||||
|
@media (max-width: 380px) {
|
||||||
|
.coderow {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
/* The orb's own still frame: the front circle sharp, the other two a soft halo behind it. */
|
||||||
|
.orb i {
|
||||||
|
animation: none;
|
||||||
|
opacity: 0.3;
|
||||||
|
filter: blur(1.4px);
|
||||||
|
}
|
||||||
|
.orb i:first-child {
|
||||||
|
opacity: 1;
|
||||||
|
filter: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
/* "Your devices": the grid, a card per device (its glass icon, name and one-line status, ⋯; the week
|
||||||
|
as a number and bars, the Update pill, or Connect), the card that adds one, the first device. */
|
||||||
|
|
||||||
|
.dgrid {
|
||||||
|
display: grid;
|
||||||
|
gap: 10px;
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
@media (min-width: 560px) {
|
||||||
|
.dgrid {
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.dev {
|
||||||
|
background: var(--raised);
|
||||||
|
border-radius: var(--r-card);
|
||||||
|
padding: 8px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.dev.is-here {
|
||||||
|
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 32%, transparent);
|
||||||
|
}
|
||||||
|
.dev.off {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
.dev-top {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 8px 6px 6px 10px;
|
||||||
|
}
|
||||||
|
.dev-top .gi {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
}
|
||||||
|
.dev-id {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.dev-name {
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 22px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
/* Every card the same height: a one-line status. */
|
||||||
|
.dev-stat {
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 18px;
|
||||||
|
color: var(--text-2);
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.dev-stat.ok-t {
|
||||||
|
color: var(--ok);
|
||||||
|
}
|
||||||
|
.dev-stat.warn-t {
|
||||||
|
color: var(--warn);
|
||||||
|
}
|
||||||
|
.dev-stat.here-t {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
.dev-use {
|
||||||
|
margin-top: auto;
|
||||||
|
background: var(--field);
|
||||||
|
border-radius: var(--r-row);
|
||||||
|
padding: 12px 14px 12px 16px;
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
min-height: 66px;
|
||||||
|
}
|
||||||
|
.use-txt {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.use-lbl {
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 18px;
|
||||||
|
color: var(--text-2);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.use-val {
|
||||||
|
font-size: 17px;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
.spark {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 4px;
|
||||||
|
height: 34px;
|
||||||
|
}
|
||||||
|
.spark i {
|
||||||
|
width: 6px;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: var(--bar);
|
||||||
|
transition: background-color 150ms;
|
||||||
|
}
|
||||||
|
.spark i.today {
|
||||||
|
background: var(--accent);
|
||||||
|
}
|
||||||
|
.spark i:hover {
|
||||||
|
background: var(--text-2);
|
||||||
|
}
|
||||||
|
.spark i.today:hover {
|
||||||
|
background: color-mix(in srgb, var(--accent) 75%, var(--text));
|
||||||
|
}
|
||||||
|
.dev .setup-btn {
|
||||||
|
margin-top: auto;
|
||||||
|
}
|
||||||
|
.upd-pill {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
align-self: center;
|
||||||
|
gap: 6px;
|
||||||
|
height: 32px;
|
||||||
|
padding: 0 12px 0 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
flex: none;
|
||||||
|
background: color-mix(in srgb, var(--warn) 14%, transparent);
|
||||||
|
color: var(--warn);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
transition:
|
||||||
|
background-color 150ms,
|
||||||
|
transform 150ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.upd-pill:hover {
|
||||||
|
background: color-mix(in srgb, var(--warn) 22%, transparent);
|
||||||
|
}
|
||||||
|
.upd-pill:active {
|
||||||
|
transform: scale(0.94);
|
||||||
|
}
|
||||||
|
.upd-pill .i {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
}
|
||||||
|
.dev.add {
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 144px;
|
||||||
|
gap: 10px;
|
||||||
|
color: var(--text-2);
|
||||||
|
font-weight: 500;
|
||||||
|
transition:
|
||||||
|
background-color 200ms var(--ease-out),
|
||||||
|
transform 200ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.dev.add:hover {
|
||||||
|
background: color-mix(in srgb, var(--raised), var(--knob) 45%);
|
||||||
|
}
|
||||||
|
.dev.add:active {
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
.dev.add .gi {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
}
|
||||||
|
/* Nothing yet: one card across the grid, what comes and the button. */
|
||||||
|
.dev.first {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
align-items: center;
|
||||||
|
text-align: center;
|
||||||
|
padding: 28px 24px 24px;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.dev.first .gi {
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
.dev.first b {
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
.dev.first p {
|
||||||
|
margin: 0 0 14px;
|
||||||
|
color: var(--text-2);
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
max-width: 34ch;
|
||||||
|
text-wrap: balance;
|
||||||
|
}
|
||||||
|
.dev.first .btn {
|
||||||
|
max-width: 320px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
/* Dawnline personal portal: the stylesheet, one file per part, joined into one portal.css by the
|
||||||
|
build (tsup.config.ts). Order matters only where a later part refines an earlier one. */
|
||||||
|
@import './tokens.css';
|
||||||
|
@import './base.css';
|
||||||
|
@import './controls.css';
|
||||||
|
@import './morph.css';
|
||||||
|
@import './accordion.css';
|
||||||
|
@import './page.css';
|
||||||
|
@import './devices.css';
|
||||||
|
@import './access.css';
|
||||||
|
@import './sheet.css';
|
||||||
|
@import './setup.css';
|
||||||
|
@import './menu-toast.css';
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
/* The ⋯ menu (a highlight that glides after the pointer, tinted for Reconnect and Remove) 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 {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
.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 {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
.mi .i {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.mi.warn,
|
||||||
|
.mi.warn .i {
|
||||||
|
color: var(--warn);
|
||||||
|
}
|
||||||
|
.mi.bad,
|
||||||
|
.mi.bad .i {
|
||||||
|
color: var(--bad);
|
||||||
|
}
|
||||||
|
.menu-sep {
|
||||||
|
height: 1px;
|
||||||
|
margin: 6px 12px;
|
||||||
|
background: var(--line);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* One toast at a time; a new one comes in over the leaving one. */
|
||||||
|
.toasts {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 42px;
|
||||||
|
bottom: calc(24px + env(safe-area-inset-bottom, 0px));
|
||||||
|
z-index: 70;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: flex-end;
|
||||||
|
pointer-events: none;
|
||||||
|
padding-left: var(--gutter-l);
|
||||||
|
padding-right: var(--gutter-r);
|
||||||
|
}
|
||||||
|
.toast {
|
||||||
|
position: absolute;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
height: 42px;
|
||||||
|
padding: 0 18px 0 13px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--toast);
|
||||||
|
color: var(--toast-fg);
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
box-shadow: var(--pop-shadow);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.toast .i {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
color: var(--ok);
|
||||||
|
}
|
||||||
|
.toast.bad .i {
|
||||||
|
color: var(--bad);
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/* A text morphing in place (ui/morph.ts): the new letters in the flow, the old ones laid over them
|
||||||
|
against the edge that stays put while they go; done, it is plain text again. */
|
||||||
|
.mt {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.mt-ib {
|
||||||
|
display: inline-block;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.mt-new {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.mt-old {
|
||||||
|
position: absolute;
|
||||||
|
white-space: nowrap;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.mt-new.w,
|
||||||
|
.mt-old.w {
|
||||||
|
white-space: inherit;
|
||||||
|
}
|
||||||
|
.mt-new i,
|
||||||
|
.mt-old i {
|
||||||
|
font-style: normal;
|
||||||
|
display: inline-block;
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
@@ -0,0 +1,238 @@
|
|||||||
|
/* The page's frame: the edge fades, the breadcrumb, the two columns and their heads, the notice that
|
||||||
|
says what stops the devices, and the card that stands alone when the link stopped working. */
|
||||||
|
|
||||||
|
/* The page fades out under the edges (iconiqui's dia-text, measured): on top a blur that thins out
|
||||||
|
over a darkening ramp, once the page scrolls; at the bottom only the ramp. Above the page, under
|
||||||
|
sheets, menus and toasts. */
|
||||||
|
.edge-fade {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 30;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.edge-fade.top {
|
||||||
|
top: 0;
|
||||||
|
height: calc(80px + env(safe-area-inset-top, 0px));
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 200ms;
|
||||||
|
background: linear-gradient(var(--bg) 0%, color-mix(in srgb, var(--bg) 75%, transparent) 50%, transparent 100%);
|
||||||
|
-webkit-backdrop-filter: blur(12px);
|
||||||
|
backdrop-filter: blur(12px);
|
||||||
|
-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%);
|
||||||
|
}
|
||||||
|
body.scrolled .edge-fade.top {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.edge-fade.bot {
|
||||||
|
bottom: 0;
|
||||||
|
height: calc(96px + env(safe-area-inset-bottom, 0px));
|
||||||
|
background: linear-gradient(to top in oklab, var(--bg) 0%, transparent 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The breadcrumb (iconiqui, measured): 32px high, the mark in a 32px box, 15px crumbs 6px apart
|
||||||
|
with a 14px chevron, the current one brighter. The mark is one colour: the text's. */
|
||||||
|
.crumbs {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
height: 32px;
|
||||||
|
margin: 0 0 32px;
|
||||||
|
}
|
||||||
|
.cr-mark {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
.logo {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
flex: none;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.logo .sun,
|
||||||
|
.logo .bar {
|
||||||
|
fill: var(--text);
|
||||||
|
}
|
||||||
|
.cr-path {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 22px;
|
||||||
|
letter-spacing: -0.15px;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.cr-path span {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.cr-path .cur {
|
||||||
|
color: var(--text);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.cr-path .i {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Phones: one column, access first. From 960px: devices left, access right and sticky. The foot
|
||||||
|
clears the bottom fade at the end of the scroll. */
|
||||||
|
.page {
|
||||||
|
max-width: 1072px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding-left: var(--gutter-l);
|
||||||
|
padding-right: var(--gutter-r);
|
||||||
|
padding-block: calc(40px + env(safe-area-inset-top, 0px)) 112px;
|
||||||
|
}
|
||||||
|
.cols {
|
||||||
|
display: grid;
|
||||||
|
gap: 40px;
|
||||||
|
}
|
||||||
|
.cols > .access {
|
||||||
|
order: -1;
|
||||||
|
}
|
||||||
|
@media (min-width: 960px) {
|
||||||
|
.cols {
|
||||||
|
grid-template-columns: minmax(0, 1fr) 384px;
|
||||||
|
gap: 36px;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
.cols > .access {
|
||||||
|
order: 0;
|
||||||
|
position: sticky;
|
||||||
|
top: calc(84px + env(safe-area-inset-top, 0px));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.sec-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 0 4px 12px;
|
||||||
|
}
|
||||||
|
.sec-head h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 28px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.025em;
|
||||||
|
}
|
||||||
|
.sec-head .aside {
|
||||||
|
color: var(--text-3);
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.sec-head .aside.warn-t {
|
||||||
|
color: var(--warn);
|
||||||
|
}
|
||||||
|
.note-s {
|
||||||
|
margin: 12px 4px 0;
|
||||||
|
color: var(--text-3);
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A notice wears its tone: the fill tinted, the rim a little stronger. */
|
||||||
|
.notice {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 14px;
|
||||||
|
padding: 14px 18px 14px 14px;
|
||||||
|
border-radius: 24px;
|
||||||
|
background: var(--raised);
|
||||||
|
margin: 0 0 22px;
|
||||||
|
}
|
||||||
|
.notice .gi {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
}
|
||||||
|
.notice .t {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.notice b {
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 22px;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
.notice span {
|
||||||
|
color: var(--text-2);
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
|
.notice.warn {
|
||||||
|
background: color-mix(in srgb, var(--warn) 10%, var(--raised));
|
||||||
|
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--warn) 22%, transparent);
|
||||||
|
}
|
||||||
|
.notice.bad {
|
||||||
|
background: color-mix(in srgb, var(--bad) 10%, var(--raised));
|
||||||
|
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bad) 22%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The page when there is nothing else: the link stopped working, or nothing could load. */
|
||||||
|
/* One card in place of the page: the breadcrumb over it, the two together in the middle of the screen. */
|
||||||
|
.page.single {
|
||||||
|
min-height: 100vh;
|
||||||
|
min-height: 100dvh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding-block: calc(24px + env(safe-area-inset-top, 0px)) calc(24px + env(safe-area-inset-bottom, 0px));
|
||||||
|
}
|
||||||
|
/* Centred on its words, the mark hanging to their left, then nudged right by about half the mark's width:
|
||||||
|
to the eye the mark and words together sit in the middle. The row keeps room for the mark on both sides. */
|
||||||
|
.page.single .crumbs {
|
||||||
|
position: relative;
|
||||||
|
left: 12px;
|
||||||
|
max-width: calc(100% - 84px);
|
||||||
|
margin: 0 0 16px;
|
||||||
|
}
|
||||||
|
.page.single .cr-mark {
|
||||||
|
position: absolute;
|
||||||
|
right: calc(100% + 10px);
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
.page.single .page-body {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 400px;
|
||||||
|
}
|
||||||
|
.page.single .gone {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.gone {
|
||||||
|
max-width: 400px;
|
||||||
|
margin: 12vh auto 0;
|
||||||
|
padding: 32px 24px 28px;
|
||||||
|
border-radius: var(--r-sheet);
|
||||||
|
background: var(--raised);
|
||||||
|
text-align: center;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.gone .gi {
|
||||||
|
width: 56px;
|
||||||
|
height: 56px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
.gone h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 22px;
|
||||||
|
line-height: 28px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.03em;
|
||||||
|
}
|
||||||
|
.gone p {
|
||||||
|
margin: 6px 0 0;
|
||||||
|
color: var(--text-2);
|
||||||
|
text-wrap: balance;
|
||||||
|
}
|
||||||
@@ -0,0 +1,318 @@
|
|||||||
|
/* The set-up sheet: the numbered steps, the way from the device to the server while the page waits
|
||||||
|
(and its line morphing into "<device> connected"), the .conf for a router, and the scan line that
|
||||||
|
speaks for both phone systems. */
|
||||||
|
|
||||||
|
.setup {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.setup .notice {
|
||||||
|
margin: 0 0 16px;
|
||||||
|
}
|
||||||
|
/* The steps fold to nothing under the way round: their gap is a block inside them, not padding
|
||||||
|
(a border-box never folds below its padding). */
|
||||||
|
.steps-gap {
|
||||||
|
height: 22px;
|
||||||
|
}
|
||||||
|
.step {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
.step + .step {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
.step-n {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--knob);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
.step-b {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
.step-t {
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
.step-box {
|
||||||
|
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
|
||||||
|
router's end lights up last, when the green gets there. */
|
||||||
|
.way {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 12px 14px;
|
||||||
|
border-radius: 20px;
|
||||||
|
background: var(--field);
|
||||||
|
margin-bottom: 18px;
|
||||||
|
}
|
||||||
|
.way-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
.way-end {
|
||||||
|
width: 34px;
|
||||||
|
height: 34px;
|
||||||
|
border-radius: 11px;
|
||||||
|
background: var(--knob);
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
flex: none;
|
||||||
|
color: var(--text-2);
|
||||||
|
transition:
|
||||||
|
background-color 400ms var(--ease-out),
|
||||||
|
color 400ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.way-end .i {
|
||||||
|
width: 17px;
|
||||||
|
height: 17px;
|
||||||
|
}
|
||||||
|
.way-end.home {
|
||||||
|
color: var(--accent);
|
||||||
|
background: color-mix(in srgb, var(--accent) 14%, transparent);
|
||||||
|
}
|
||||||
|
.way-track {
|
||||||
|
position: relative;
|
||||||
|
flex: 1;
|
||||||
|
height: 8px;
|
||||||
|
}
|
||||||
|
.way-track::before,
|
||||||
|
.way-glow,
|
||||||
|
.way-fill {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
-webkit-mask: radial-gradient(circle, #000 1.4px, transparent 1.9px) 0 50% / 9px 8px repeat-x;
|
||||||
|
mask: radial-gradient(circle, #000 1.4px, transparent 1.9px) 0 50% / 9px 8px repeat-x;
|
||||||
|
}
|
||||||
|
.way-track::before {
|
||||||
|
background: var(--text-3);
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
.way-glow {
|
||||||
|
overflow: hidden;
|
||||||
|
transition: opacity 200ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.way-glow i {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: linear-gradient(90deg, transparent 32%, var(--accent) 50%, transparent 68%);
|
||||||
|
transform: translateX(-70%);
|
||||||
|
animation: way-run 2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
|
||||||
|
}
|
||||||
|
@keyframes way-run {
|
||||||
|
0% {
|
||||||
|
transform: translateX(-70%);
|
||||||
|
}
|
||||||
|
72%,
|
||||||
|
100% {
|
||||||
|
transform: translateX(70%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.way-fill {
|
||||||
|
background: var(--ok);
|
||||||
|
clip-path: inset(0 100% 0 0);
|
||||||
|
transition: clip-path 700ms var(--ease-out) 80ms;
|
||||||
|
}
|
||||||
|
.way.done .way-fill {
|
||||||
|
clip-path: inset(0);
|
||||||
|
}
|
||||||
|
.way.done .way-glow,
|
||||||
|
.way.stopped .way-glow {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
.way.done .way-end {
|
||||||
|
color: var(--ok);
|
||||||
|
background: var(--ok-soft);
|
||||||
|
}
|
||||||
|
.way.done .way-end.home {
|
||||||
|
transition-delay: 600ms;
|
||||||
|
}
|
||||||
|
.way.done .way-end.home .i {
|
||||||
|
animation: way-pop 420ms var(--spring-bouncy, ease) 600ms backwards;
|
||||||
|
}
|
||||||
|
@keyframes way-pop {
|
||||||
|
from {
|
||||||
|
transform: scale(0.6);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.way-text {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 30px;
|
||||||
|
margin-top: 10px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.way-text .t {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
/* The line morphs into "<device> connected" (ui/morph.ts) and turns green. */
|
||||||
|
.way-text b {
|
||||||
|
position: relative;
|
||||||
|
display: inline-flex;
|
||||||
|
justify-content: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
transition: color 300ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.way-text .ws {
|
||||||
|
color: var(--text-2);
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 18px;
|
||||||
|
}
|
||||||
|
.way.done .way-text b {
|
||||||
|
color: var(--ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The .conf for a router: a file card, and the configuration folded with its keys masked. */
|
||||||
|
.filecard {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: 18px;
|
||||||
|
background: var(--field);
|
||||||
|
}
|
||||||
|
.fc-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.filecard-ic {
|
||||||
|
width: 38px;
|
||||||
|
height: 46px;
|
||||||
|
border-radius: 9px;
|
||||||
|
background: var(--knob);
|
||||||
|
font: 600 10px/1 var(--mono);
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
color: var(--text-2);
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
.filecard .t {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.filecard .t .mono {
|
||||||
|
font-size: 13px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.filecard .t span:last-child {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-2);
|
||||||
|
line-height: 16px;
|
||||||
|
}
|
||||||
|
.confbar {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.conf {
|
||||||
|
margin: 0;
|
||||||
|
padding: 12px 14px;
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--field);
|
||||||
|
font: 12px/18px var(--mono);
|
||||||
|
max-height: 16rem;
|
||||||
|
overflow: auto;
|
||||||
|
white-space: pre;
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
.conf .k {
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.conf .sec {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
.conf .mask {
|
||||||
|
color: var(--text-3);
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Where the app scans, for both phone systems: the mark and the word that differs change in place. */
|
||||||
|
.osm {
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
.osm-ic {
|
||||||
|
display: inline-grid;
|
||||||
|
width: 1.05em;
|
||||||
|
height: 1.05em;
|
||||||
|
margin-right: 0.25em;
|
||||||
|
vertical-align: -0.16em;
|
||||||
|
}
|
||||||
|
.osm-ic > svg {
|
||||||
|
grid-area: 1 / 1;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
.osm-ic .eye {
|
||||||
|
fill: var(--field);
|
||||||
|
}
|
||||||
|
.osm-p {
|
||||||
|
display: inline-block;
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
|
/* "In AmneziaWG:" and the path on one line; where they don't fit, the path goes under it whole, and
|
||||||
|
stays there while it morphs (never split, never a part dropping on its own). */
|
||||||
|
.scanline {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: baseline;
|
||||||
|
column-gap: 0.3em;
|
||||||
|
}
|
||||||
|
.scanline .osm {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
/* A narrow screen: the path under the label for every app, so switching apps never moves it between lines. */
|
||||||
|
@media (max-width: 440px) {
|
||||||
|
.scanline {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.way-text b .mt-old {
|
||||||
|
color: var(--text-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.way-glow {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.way-fill {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
.way.done .way-end.home .i {
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,281 @@
|
|||||||
|
/* The sheet: a drawer floating at the bottom on every width, × and a view's own buttons pinned in its
|
||||||
|
corner, the views inside (head, line under it), and the question look (Remove, Reconnect). */
|
||||||
|
|
||||||
|
/* Closed, the sheet is out of the page (display, not visibility): each open computes its styles
|
||||||
|
afresh. Hidden by visibility, Chromium could keep the inherited "hidden" on the views' box after a
|
||||||
|
quick close and reopen (a double tap on Reconnect), and the sheet opened empty but for its buttons. */
|
||||||
|
.sheet-root {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 50;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.sheet-root.open {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.scrim {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: var(--scrim);
|
||||||
|
-webkit-backdrop-filter: blur(8px);
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
}
|
||||||
|
.sheet {
|
||||||
|
position: absolute;
|
||||||
|
left: var(--gutter-l);
|
||||||
|
right: var(--gutter-r);
|
||||||
|
bottom: calc(16px + env(safe-area-inset-bottom, 0px));
|
||||||
|
margin: 0 auto;
|
||||||
|
max-width: 400px;
|
||||||
|
max-height: calc(100% - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
|
||||||
|
background: var(--raised);
|
||||||
|
border-radius: var(--r-sheet);
|
||||||
|
box-shadow: var(--sheet-shadow);
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
/* On a computer (and a tablet held wide): a dialog in the middle of the screen, which comes up from
|
||||||
|
its centre (ui/sheet.ts); a phone keeps the drawer at the bottom. The breakpoint is the one the
|
||||||
|
sheet widens at for a dense code. Centred by the layout, not a transform, so its text stays on the
|
||||||
|
pixel grid and its own transform stays free for the motion. */
|
||||||
|
@media (min-width: 760px) {
|
||||||
|
.sheet-root.open {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.sheet {
|
||||||
|
position: relative;
|
||||||
|
left: auto;
|
||||||
|
right: auto;
|
||||||
|
bottom: auto;
|
||||||
|
margin: 0;
|
||||||
|
width: calc(100% - var(--gutter-l) - var(--gutter-r));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.sheet .x {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 3;
|
||||||
|
right: 22px;
|
||||||
|
top: 22px;
|
||||||
|
}
|
||||||
|
.vp {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
.sheet-scroll {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
}
|
||||||
|
.view {
|
||||||
|
padding: 0 24px 24px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
/* Pulled down by its head to close: the head takes the touch, the rest scrolls. */
|
||||||
|
.vhead {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
height: 76px;
|
||||||
|
padding-right: 44px;
|
||||||
|
flex: none;
|
||||||
|
cursor: grab;
|
||||||
|
touch-action: none;
|
||||||
|
}
|
||||||
|
.vhead h2 {
|
||||||
|
flex: 1;
|
||||||
|
margin: 0;
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 28px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.5px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.vhead.center h2 {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.vhead.with-acts {
|
||||||
|
padding-right: 126px;
|
||||||
|
}
|
||||||
|
.vsub {
|
||||||
|
margin: -16px 0 18px;
|
||||||
|
color: var(--text-2);
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
|
.vhead.center + .vsub {
|
||||||
|
text-align: center;
|
||||||
|
margin: -6px auto 24px;
|
||||||
|
max-width: 32ch;
|
||||||
|
text-wrap: balance;
|
||||||
|
}
|
||||||
|
.kinds-note {
|
||||||
|
margin: 14px 2px 16px;
|
||||||
|
}
|
||||||
|
.view > .hint.bad-t {
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
.secure-note {
|
||||||
|
margin-top: 12px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A view's own buttons beside × and pinned like it: icons only, each the size and colour of ×; the
|
||||||
|
two join with tighter inner corners. */
|
||||||
|
.sheet-acts {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 3;
|
||||||
|
top: 22px;
|
||||||
|
right: 58px;
|
||||||
|
}
|
||||||
|
.hpill {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
.hp-b {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
width: 38px;
|
||||||
|
height: 32px;
|
||||||
|
background: var(--knob);
|
||||||
|
color: var(--text);
|
||||||
|
transition:
|
||||||
|
background-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%);
|
||||||
|
}
|
||||||
|
.hp-b:active {
|
||||||
|
transform: scale(0.94);
|
||||||
|
}
|
||||||
|
.hp-b.done {
|
||||||
|
color: var(--ok);
|
||||||
|
}
|
||||||
|
/* Their tooltip: a small toast-coloured pill under the keys, one for both. */
|
||||||
|
.hp-tip {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 4;
|
||||||
|
left: 0;
|
||||||
|
top: calc(100% + 8px);
|
||||||
|
height: 26px;
|
||||||
|
padding: 0 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--toast);
|
||||||
|
color: var(--toast-fg);
|
||||||
|
font: 500 12px/1 var(--font);
|
||||||
|
letter-spacing: -0.1px;
|
||||||
|
white-space: nowrap;
|
||||||
|
box-shadow:
|
||||||
|
0 0 0 1px var(--line-glass),
|
||||||
|
var(--pop-shadow);
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
overflow: hidden;
|
||||||
|
transform-origin: 50% 0;
|
||||||
|
}
|
||||||
|
.hp-tip.on {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.hp-tip .tt {
|
||||||
|
position: relative;
|
||||||
|
display: inline-flex;
|
||||||
|
justify-content: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.hp-tip .tt-m {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
visibility: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
/* Connected: nothing is left to do here, so × and the view's buttons step away; the sheet then closes by itself. */
|
||||||
|
.sheet .x,
|
||||||
|
.sheet-acts {
|
||||||
|
transition:
|
||||||
|
transform 150ms var(--ease-out),
|
||||||
|
background-color 150ms,
|
||||||
|
opacity 240ms var(--ease-out),
|
||||||
|
filter 240ms var(--ease-out),
|
||||||
|
scale 240ms var(--ease-out);
|
||||||
|
}
|
||||||
|
.sheet.arrived .x,
|
||||||
|
.sheet.arrived .sheet-acts {
|
||||||
|
opacity: 0;
|
||||||
|
filter: blur(3px);
|
||||||
|
scale: 0.9;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A question before something that cannot be undone. */
|
||||||
|
.center-col {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.center-col.ask {
|
||||||
|
padding-top: 28px;
|
||||||
|
}
|
||||||
|
.center-col.secure {
|
||||||
|
padding-top: 4px;
|
||||||
|
}
|
||||||
|
.center-col .gi.xl {
|
||||||
|
width: 64px;
|
||||||
|
height: 64px;
|
||||||
|
margin: 8px 0 16px;
|
||||||
|
}
|
||||||
|
.center-col h3 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 28px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: -0.5px;
|
||||||
|
}
|
||||||
|
.center-col p {
|
||||||
|
margin: 6px 0 22px;
|
||||||
|
color: var(--text-2);
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 21px;
|
||||||
|
max-width: 30ch;
|
||||||
|
text-wrap: balance;
|
||||||
|
}
|
||||||
|
.center-col.secure p {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
.btnrow {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.btnrow .btn {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.btnrow2 {
|
||||||
|
display: grid;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.btnrow2 .btn {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
/* The portal's fonts and tokens. Dark first (the skiper21 palette, measured), light by the system's
|
||||||
|
choice. Surfaces step up in brightness (ground → raised → field → knob) instead of borders; the
|
||||||
|
accent is the one sky blue, colour otherwise only means state (ok green, warn orange, bad red). */
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: Geist;
|
||||||
|
src: url(geist-latin-wght-normal.woff2) format('woff2');
|
||||||
|
font-weight: 100 900;
|
||||||
|
font-display: swap;
|
||||||
|
unicode-range:
|
||||||
|
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2190-21FF, U+2212, U+2215;
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: Geist;
|
||||||
|
src: url(geist-cyrillic-wght-normal.woff2) format('woff2');
|
||||||
|
font-weight: 100 900;
|
||||||
|
font-display: swap;
|
||||||
|
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Geist Mono';
|
||||||
|
src: url(geist-mono-latin-wght-normal.woff2) format('woff2');
|
||||||
|
font-weight: 100 900;
|
||||||
|
font-display: swap;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
color-scheme: dark;
|
||||||
|
--bg: #080808;
|
||||||
|
--raised: #121212;
|
||||||
|
--field: #161616;
|
||||||
|
--knob: #232323;
|
||||||
|
--seg: rgba(237, 237, 237, 0.05);
|
||||||
|
--seg-shadow: none;
|
||||||
|
--line: rgba(255, 255, 255, 0.06);
|
||||||
|
--text: #ededed;
|
||||||
|
--text-2: #8c8c8a;
|
||||||
|
--text-3: #4f4f4e;
|
||||||
|
--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);
|
||||||
|
--sel-bg: rgba(131, 209, 255, 0.25);
|
||||||
|
--sel-fg: #64c6ff;
|
||||||
|
--scrim: rgba(8, 8, 8, 0.8);
|
||||||
|
--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);
|
||||||
|
--bar: rgba(237, 237, 237, 0.13);
|
||||||
|
--toast: #232323;
|
||||||
|
--toast-fg: #ededed;
|
||||||
|
--qr-bg: #0a0a0a;
|
||||||
|
/* glass icons: the frosted pane, its rim and edge, the detail strokes; the tones' two stops */
|
||||||
|
--gi-a: rgba(255, 255, 255, 0.58);
|
||||||
|
--gi-b: rgba(255, 255, 255, 0.14);
|
||||||
|
--gi-rim: rgba(255, 255, 255, 0.5);
|
||||||
|
--gi-edge: rgba(0, 0, 0, 0);
|
||||||
|
--gi-detail: #ffffff;
|
||||||
|
--t-grey-a: #cfcfcd;
|
||||||
|
--t-grey-b: #5a5a59;
|
||||||
|
--t-blue-a: #a6d9ff;
|
||||||
|
--t-blue-b: #1d84e6;
|
||||||
|
--t-green-a: #a8f29c;
|
||||||
|
--t-green-b: #3aa32c;
|
||||||
|
--t-red-a: #ffadad;
|
||||||
|
--t-red-b: #dc3a3a;
|
||||||
|
--t-orange-a: #ffc08f;
|
||||||
|
--t-orange-b: #ec6a12;
|
||||||
|
|
||||||
|
--font: Geist, -apple-system, system-ui, 'Segoe UI', sans-serif;
|
||||||
|
--mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
|
||||||
|
--r-sheet: 36px;
|
||||||
|
--r-card: 28px;
|
||||||
|
--r-row: 20px;
|
||||||
|
--r-field: 16px;
|
||||||
|
--r-tile: 12px;
|
||||||
|
--ease-out: cubic-bezier(0.23, 1, 0.32, 1);
|
||||||
|
--gutter-l: max(16px, env(safe-area-inset-left, 0px));
|
||||||
|
--gutter-r: max(16px, env(safe-area-inset-right, 0px));
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: light) {
|
||||||
|
:root {
|
||||||
|
color-scheme: light;
|
||||||
|
--bg: #f2f2f1;
|
||||||
|
--raised: #ffffff;
|
||||||
|
--field: #f3f3f2;
|
||||||
|
--knob: #e8e8e7;
|
||||||
|
--seg: #ffffff;
|
||||||
|
--seg-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 0.5px rgba(0, 0, 0, 0.05);
|
||||||
|
--line: rgba(0, 0, 0, 0.07);
|
||||||
|
--text: #0b0b0b;
|
||||||
|
--text-2: #6d6d6b;
|
||||||
|
--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);
|
||||||
|
--sel-bg: rgba(78, 175, 255, 0.22);
|
||||||
|
--sel-fg: #0a76cf;
|
||||||
|
--scrim: rgba(236, 236, 235, 0.62);
|
||||||
|
--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);
|
||||||
|
--bar: rgba(11, 11, 11, 0.11);
|
||||||
|
--toast: #0b0b0b;
|
||||||
|
--toast-fg: #f2f2f1;
|
||||||
|
--qr-bg: #ffffff;
|
||||||
|
--gi-a: rgba(250, 250, 249, 0.72);
|
||||||
|
--gi-b: rgba(206, 206, 204, 0.5);
|
||||||
|
--gi-rim: rgba(255, 255, 255, 0.9);
|
||||||
|
--gi-edge: rgba(0, 0, 0, 0.11);
|
||||||
|
--gi-detail: rgba(28, 28, 28, 0.72);
|
||||||
|
--t-grey-a: #a9a9a7;
|
||||||
|
--t-grey-b: #3d3d3c;
|
||||||
|
--t-blue-a: #7cc4ff;
|
||||||
|
--t-blue-b: #0a6fd6;
|
||||||
|
--t-green-a: #82e070;
|
||||||
|
--t-green-b: #2e8a22;
|
||||||
|
--t-red-a: #ff9090;
|
||||||
|
--t-red-b: #c92a2a;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
// The accordion (skiper103's motion, on a softer spring): rows touch while
|
||||||
|
// closed and share their rounded ends; an open row lifts out with 10 px gaps
|
||||||
|
// and its own corners. One row open at a time. A row with nothing to open is a
|
||||||
|
// plain head: no chevron, no click. Inside the sheet it tells the sheet first,
|
||||||
|
// so a code that comes into view gets its width.
|
||||||
|
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { EASE_IN, SOFT, play } from '../motion';
|
||||||
|
import { planWidth, startWidth } from './sheet';
|
||||||
|
|
||||||
|
export interface AccItem {
|
||||||
|
icon: Element;
|
||||||
|
title: string;
|
||||||
|
/** Beside the title (a chip). */
|
||||||
|
tag?: Node | null;
|
||||||
|
/** At the head's end (numbers). */
|
||||||
|
val?: Node | null;
|
||||||
|
/** The body shows the same numbers: the head drops them while open. */
|
||||||
|
valHide?: boolean;
|
||||||
|
body: (Node | null | false | undefined)[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Accordion {
|
||||||
|
el: HTMLElement;
|
||||||
|
/** The open row, or -1. */
|
||||||
|
openIndex(): number;
|
||||||
|
/** Open this row (or none), without motion: a repaint keeps what was open. */
|
||||||
|
setOpen(i: number): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The properties the rows animate between their closed and open shapes. */
|
||||||
|
const PROPS = [
|
||||||
|
'height',
|
||||||
|
'marginTop',
|
||||||
|
'marginBottom',
|
||||||
|
'borderTopLeftRadius',
|
||||||
|
'borderTopRightRadius',
|
||||||
|
'borderBottomLeftRadius',
|
||||||
|
'borderBottomRightRadius',
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export function accordion(
|
||||||
|
items: AccItem[],
|
||||||
|
o: { inset?: boolean; open?: number; onToggle?: (i: number, open: boolean, instant: boolean) => void } = {},
|
||||||
|
): Accordion {
|
||||||
|
const acc = h('div', { class: `acc${o.inset ? ' inset' : ''}` });
|
||||||
|
const rows = items.map((it, i) => {
|
||||||
|
const kids = it.body.filter((k): k is Node => !!k);
|
||||||
|
const still = !kids.length;
|
||||||
|
const inner = [
|
||||||
|
it.icon,
|
||||||
|
h('span', { class: 'acc-title' }, h('span', { class: 't' }, it.title), it.tag ?? null),
|
||||||
|
it.val ? h('span', { class: `acc-val${it.valHide ? ' hide-open' : ''}` }, it.val) : null,
|
||||||
|
];
|
||||||
|
const open = i === o.open && !still;
|
||||||
|
const headEl = still
|
||||||
|
? h('div', { class: 'acc-head' }, ...inner)
|
||||||
|
: h(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'acc-head', 'aria-expanded': String(open), onclick: () => toggle(r) },
|
||||||
|
...inner,
|
||||||
|
ic('chevron', 'i acc-chev'),
|
||||||
|
);
|
||||||
|
const r = h(
|
||||||
|
'div',
|
||||||
|
{ class: `acc-row${still ? ' still' : ''}${open ? ' open' : ''}` },
|
||||||
|
headEl,
|
||||||
|
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) => {
|
||||||
|
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'));
|
||||||
|
});
|
||||||
|
const read = (x: HTMLElement) => {
|
||||||
|
const cs = getComputedStyle(x);
|
||||||
|
const out: Record<string, string> = {};
|
||||||
|
for (const p of PROPS) out[p] = p === 'height' ? `${x.getBoundingClientRect().height}px` : cs[p];
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
const aria = () =>
|
||||||
|
rows.forEach((x) => x.querySelector('button.acc-head')?.setAttribute('aria-expanded', String(x.classList.contains('open'))));
|
||||||
|
|
||||||
|
function toggle(r: HTMLElement) {
|
||||||
|
const before = rows.map(read);
|
||||||
|
rows.forEach((x) => x.getAnimations().forEach((a) => a.cancel()));
|
||||||
|
rows.forEach((x) =>
|
||||||
|
bodyOf(x)
|
||||||
|
.getAnimations()
|
||||||
|
.forEach((a) => a.cancel()),
|
||||||
|
);
|
||||||
|
const willOpen = !r.classList.contains('open');
|
||||||
|
const closing = rows.filter((x) => x.classList.contains('open') && (x === r || willOpen));
|
||||||
|
rows.forEach((x) => {
|
||||||
|
x.classList.remove('closing');
|
||||||
|
if (x !== r) x.classList.remove('open');
|
||||||
|
});
|
||||||
|
r.classList.toggle('open', willOpen);
|
||||||
|
corners();
|
||||||
|
const plan = planWidth();
|
||||||
|
rows.forEach((x, i) => {
|
||||||
|
const after = read(x);
|
||||||
|
if (!PROPS.some((p) => before[i][p] !== after[p])) return;
|
||||||
|
if (closing.includes(x)) x.classList.add('closing');
|
||||||
|
play(x, [before[i], after], { duration: SOFT.duration, easing: SOFT.easing }).onfinish = () => x.classList.remove('closing');
|
||||||
|
});
|
||||||
|
closing.forEach((x) =>
|
||||||
|
play(bodyOf(x), [{ opacity: 1 }, { opacity: 0, filter: 'blur(2px)' }], { duration: 160, easing: EASE_IN, fill: 'forwards' }),
|
||||||
|
);
|
||||||
|
if (willOpen)
|
||||||
|
play(
|
||||||
|
bodyOf(r),
|
||||||
|
[
|
||||||
|
{ opacity: 0, filter: 'blur(2px)' },
|
||||||
|
{ opacity: 1, filter: 'blur(0px)' },
|
||||||
|
],
|
||||||
|
{ duration: 300, easing: 'cubic-bezier(0,0,.58,1)' },
|
||||||
|
);
|
||||||
|
startWidth(plan);
|
||||||
|
aria();
|
||||||
|
o.onToggle?.(rows.indexOf(r), willOpen, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
corners();
|
||||||
|
return {
|
||||||
|
el: acc,
|
||||||
|
openIndex: () => rows.findIndex((x) => x.classList.contains('open')),
|
||||||
|
setOpen(i) {
|
||||||
|
rows.forEach((x, k) => x.classList.toggle('open', k === i && !x.classList.contains('still')));
|
||||||
|
corners();
|
||||||
|
aria();
|
||||||
|
rows.forEach((x, k) => o.onToggle?.(k, x.classList.contains('open'), true));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
// A button held busy while the router answers: its content blurs away and an
|
||||||
|
// orb comes up through the blur in its place, then the other way round. The orb
|
||||||
|
// is B4 Converge from aicss.dev's Orbs (controls.css draws it). Each change starts
|
||||||
|
// from where the last one stands, so an answer that lands mid-change turns back
|
||||||
|
// without a jump.
|
||||||
|
|
||||||
|
import { h } from '../dom';
|
||||||
|
import { EASE_IN, EASE_OUT, play } from '../motion';
|
||||||
|
|
||||||
|
const SHOWN: Keyframe = { opacity: 1, filter: 'blur(0px)', transform: 'none' };
|
||||||
|
const GONE: Keyframe = { opacity: 0, filter: 'blur(5px)', transform: 'scale(.86)' };
|
||||||
|
const ORB_GONE: Keyframe = { opacity: 0, filter: 'blur(5px)', transform: 'scale(.6)' };
|
||||||
|
/** Out quick, in a little later and slower: the two cross in the blur. */
|
||||||
|
const OUT = { duration: 180, easing: EASE_IN, fill: 'forwards' } as const;
|
||||||
|
const IN = { duration: 340, delay: 70, easing: EASE_OUT, fill: 'backwards' } as const;
|
||||||
|
/** Until the orb is all the way in: a quicker answer waits for it, so the orb never just flickers. */
|
||||||
|
export const BUSY_IN = IN.delay + IN.duration;
|
||||||
|
|
||||||
|
const runs = new WeakMap<HTMLElement, Animation[]>();
|
||||||
|
|
||||||
|
/** Where an element stands now, mid-animation included. */
|
||||||
|
function now(el: Element): Keyframe {
|
||||||
|
const s = getComputedStyle(el);
|
||||||
|
return { opacity: s.opacity, filter: s.filter === 'none' ? 'blur(0px)' : s.filter, transform: s.transform };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What gives way: the button's own elements (a bare word goes into a span first). */
|
||||||
|
function content(btn: HTMLElement): Element[] {
|
||||||
|
for (const n of [...btn.childNodes])
|
||||||
|
if (n.nodeType === Node.TEXT_NODE && n.textContent?.trim()) n.replaceWith(h('span', {}, n.textContent));
|
||||||
|
return [...btn.children].filter((c) => !c.classList.contains('orb'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The new change takes over: the old one stops once the new one is in place (nothing paints between). */
|
||||||
|
function hand(btn: HTMLElement, next: Animation[]) {
|
||||||
|
const old = runs.get(btn) ?? [];
|
||||||
|
runs.set(btn, next);
|
||||||
|
old.forEach((a) => a.cancel());
|
||||||
|
}
|
||||||
|
|
||||||
|
export function busyOn(btn: HTMLElement) {
|
||||||
|
btn.querySelector(':scope > .orb')?.remove();
|
||||||
|
const parts = content(btn);
|
||||||
|
const from = parts.map(now);
|
||||||
|
const orb = h('span', { class: 'orb', 'aria-hidden': 'true' }, h('i'), h('i'));
|
||||||
|
btn.append(orb);
|
||||||
|
btn.classList.add('busy');
|
||||||
|
btn.setAttribute('aria-busy', 'true');
|
||||||
|
hand(btn, [...parts.map((p, i) => play(p, [from[i], GONE], OUT)), play(orb, [ORB_GONE, SHOWN], IN)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function busyOff(btn: HTMLElement) {
|
||||||
|
const orb = btn.querySelector(':scope > .orb');
|
||||||
|
const parts = content(btn);
|
||||||
|
const next = [...(orb ? [play(orb, [now(orb), ORB_GONE], OUT)] : []), ...parts.map((p) => play(p, [now(p), SHOWN], IN))];
|
||||||
|
hand(btn, next);
|
||||||
|
btn.removeAttribute('aria-busy');
|
||||||
|
Promise.all(next.map((a) => a.finished)).then(
|
||||||
|
() => {
|
||||||
|
if (runs.get(btn) !== next) return; // busy again meanwhile
|
||||||
|
runs.delete(btn);
|
||||||
|
next.forEach((a) => a.cancel());
|
||||||
|
orb?.remove();
|
||||||
|
btn.classList.remove('busy');
|
||||||
|
},
|
||||||
|
() => {},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
// What goes to another device: a QR code and the words that go with it, and a
|
||||||
|
// link as text with Copy and Share. Codes follow the theme: the night look
|
||||||
|
// (light dots on black) on a dark one, the same dots dark on white on a light
|
||||||
|
// one, redrawn in place when the system's theme changes. A dense code (an
|
||||||
|
// AmneziaVPN key) fills its row; the sheet widens for it (ui/sheet.ts).
|
||||||
|
|
||||||
|
import { denseQr, qrSvg } from '../../shared/qr';
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { EASE_IN, EASE_OUT, play } from '../motion';
|
||||||
|
import { placeName } from '../state';
|
||||||
|
import { copy } from './feedback';
|
||||||
|
|
||||||
|
const LIGHT = matchMedia('(prefers-color-scheme: light)');
|
||||||
|
const look = () => (LIGHT.matches ? 'day' : 'night');
|
||||||
|
|
||||||
|
function paint(box: HTMLElement, text: string) {
|
||||||
|
box.dataset.qr = text;
|
||||||
|
box.classList.toggle('dense', denseQr(text));
|
||||||
|
box.classList.toggle('light', LIGHT.matches);
|
||||||
|
box.innerHTML = qrSvg(text, 3, true, look());
|
||||||
|
// The modules across: how wide the sheet must be for a camera to read it.
|
||||||
|
box.dataset.mods = String((box.firstElementChild as SVGSVGElement | null)?.viewBox.baseVal.width ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function qrBox(text: string, big = false): HTMLElement {
|
||||||
|
const box = h('div', { class: `qrbox${big ? ' big' : ''}` });
|
||||||
|
paint(box, text);
|
||||||
|
return box;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIGHT.addEventListener('change', () =>
|
||||||
|
document.querySelectorAll<HTMLElement>('.qrbox[data-qr]').forEach((b) => {
|
||||||
|
// Mid cross-fade a box holds two codes: the old one goes, the new one is drawn again.
|
||||||
|
b.querySelector('svg.old')?.remove();
|
||||||
|
paint(b, b.dataset.qr!);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
export interface CodeRow {
|
||||||
|
el: HTMLElement;
|
||||||
|
/** Another code in the same place: it comes in over the old one, which then goes; new words too, if given (else they stay, to change in place). */
|
||||||
|
swap(next: string, words?: Node[]): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A code and its words: side by side, or a dense code full width with the words under it. */
|
||||||
|
export function codeRow(text: string, words: Node[]): CodeRow {
|
||||||
|
const box = qrBox(text);
|
||||||
|
let shown = h('div', { class: 'words' }, words);
|
||||||
|
const side = h('div', { class: 'side' }, shown);
|
||||||
|
const el = h('div', { class: `coderow${box.classList.contains('dense') ? ' stacked' : ''}` }, box, side);
|
||||||
|
return {
|
||||||
|
el,
|
||||||
|
swap(next, nextWords) {
|
||||||
|
// The same code for another app (AmneziaWG and WireGuard take one file): only the words change.
|
||||||
|
const oldSvg = box.dataset.qr === next ? null : box.querySelector('svg');
|
||||||
|
if (oldSvg) {
|
||||||
|
paint(box, next);
|
||||||
|
el.classList.toggle('stacked', box.classList.contains('dense'));
|
||||||
|
const newSvg = box.querySelector('svg')!;
|
||||||
|
oldSvg.classList.add('old');
|
||||||
|
box.appendChild(oldSvg);
|
||||||
|
// The new code comes in first, the old one goes after it: the place is never empty.
|
||||||
|
play(newSvg, [{ opacity: 0 }, { opacity: 1 }], { duration: 200, easing: EASE_OUT });
|
||||||
|
play(oldSvg, [{ opacity: 1 }, { opacity: 0 }], { duration: 220, delay: 110, easing: EASE_IN, fill: 'forwards' }).onfinish = () =>
|
||||||
|
oldSvg.remove();
|
||||||
|
}
|
||||||
|
if (!nextWords) return;
|
||||||
|
const oldWords = shown;
|
||||||
|
shown = h('div', { class: 'words' }, nextWords);
|
||||||
|
side.appendChild(shown);
|
||||||
|
oldWords.classList.add('old');
|
||||||
|
play(
|
||||||
|
shown,
|
||||||
|
[
|
||||||
|
{ opacity: 0, filter: 'blur(3px)' },
|
||||||
|
{ opacity: 1, filter: 'blur(0px)' },
|
||||||
|
],
|
||||||
|
{ duration: 220, easing: EASE_OUT },
|
||||||
|
);
|
||||||
|
play(
|
||||||
|
oldWords,
|
||||||
|
[
|
||||||
|
{ opacity: 1, filter: 'blur(0px)' },
|
||||||
|
{ opacity: 0, filter: 'blur(3px)' },
|
||||||
|
],
|
||||||
|
{ duration: 200, delay: 90, easing: EASE_IN, fill: 'forwards' },
|
||||||
|
).onfinish = () => oldWords.remove();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A link as text with Copy and, where the browser has one, the share sheet. */
|
||||||
|
export function linkRow(url: string): HTMLElement {
|
||||||
|
const share = typeof navigator.share === 'function';
|
||||||
|
return h(
|
||||||
|
'div',
|
||||||
|
{ class: 'linkrow' },
|
||||||
|
h('span', { class: 'mono' }, url.replace(/^https?:\/\//, '')),
|
||||||
|
h(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'knob', 'aria-label': 'Copy the link', onclick: (ev: Event) => copy(url, 'Link copied', ev.currentTarget) },
|
||||||
|
ic('copy'),
|
||||||
|
),
|
||||||
|
share
|
||||||
|
? h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
class: 'knob',
|
||||||
|
'aria-label': 'Share the link',
|
||||||
|
onclick: () => navigator.share({ url, title: placeName() }).catch(() => undefined),
|
||||||
|
},
|
||||||
|
ic('share'),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
// What a tap answers with: a toast, a copy (and the check on the control that
|
||||||
|
// copied), a file shared or downloaded, a button held busy until the router
|
||||||
|
// answers. Toasts sit in one bottom slot, one at a time.
|
||||||
|
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { BOUNCY, EASE_IN, POP, calm, play } from '../motion';
|
||||||
|
import { platform } from '../state';
|
||||||
|
import { BUSY_IN, busyOff, busyOn } from './busy';
|
||||||
|
import { morphText, textOf } from './morph';
|
||||||
|
|
||||||
|
let slot: HTMLElement | null = null;
|
||||||
|
let shown: HTMLElement | null = null;
|
||||||
|
let timer = 0;
|
||||||
|
|
||||||
|
const leave = (t: HTMLElement, frames: Keyframe[], ms: number) =>
|
||||||
|
(play(t, frames, { duration: ms, easing: EASE_IN, fill: 'forwards' }).onfinish = () => t.remove());
|
||||||
|
|
||||||
|
/** One toast at a time: a new one sends the last away first. */
|
||||||
|
export function toast(msg: string, bad = false) {
|
||||||
|
slot ??= document.body.appendChild(h('div', { class: 'toasts' }));
|
||||||
|
if (shown) leave(shown, [{ opacity: 1 }, { opacity: 0, transform: 'scale(.96)', filter: 'blur(4px)' }], 140);
|
||||||
|
const t = h('div', { class: `toast${bad ? ' bad' : ''}`, role: 'status' }, ic(bad ? 'alert' : 'check'), h('span', {}, msg));
|
||||||
|
slot.appendChild(t);
|
||||||
|
shown = t;
|
||||||
|
play(
|
||||||
|
t,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: 'translateY(18px) scale(.9)', filter: 'blur(6px)' },
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: BOUNCY.duration,
|
||||||
|
easing: BOUNCY.easing,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = window.setTimeout(() => {
|
||||||
|
if (shown !== t) return;
|
||||||
|
shown = null;
|
||||||
|
leave(t, [{ opacity: 1 }, { opacity: 0, transform: 'translateY(6px) scale(.96)', filter: 'blur(4px)' }], 180);
|
||||||
|
}, 2400);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The control that copied says so for a moment: its icon turns into a check
|
||||||
|
* and a "Copy…" label (`.lbl`, a badge's main line) into "Copied".
|
||||||
|
*/
|
||||||
|
function copied(from: Element) {
|
||||||
|
if (from.classList.contains('copied')) return;
|
||||||
|
const icon = from.querySelector('svg.i');
|
||||||
|
const label = from.querySelector<HTMLElement>('.lbl, .b-main');
|
||||||
|
const was = label ? textOf(label) : '';
|
||||||
|
from.classList.add('copied');
|
||||||
|
let check: Element | null = null;
|
||||||
|
if (icon) {
|
||||||
|
check = ic('check', icon.getAttribute('class') ?? 'i');
|
||||||
|
icon.replaceWith(check);
|
||||||
|
play(
|
||||||
|
check,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: 'scale(.6)', filter: 'blur(3px)' },
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: POP.duration,
|
||||||
|
easing: POP.easing,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (label && /^Copy/.test(was)) morphText(label, 'Copied');
|
||||||
|
setTimeout(() => {
|
||||||
|
if (check && icon) check.replaceWith(icon);
|
||||||
|
if (label && /^Copy/.test(was)) morphText(label, was);
|
||||||
|
from.classList.remove('copied');
|
||||||
|
}, 1600);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** `from`: the control that copied, which then shows a check for a moment. */
|
||||||
|
export async function copy(text: string, what = 'Copied', from?: EventTarget | null) {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
} catch {
|
||||||
|
const ta = h('textarea', { class: 'offscreen' }, text) as HTMLTextAreaElement;
|
||||||
|
document.body.appendChild(ta);
|
||||||
|
ta.select();
|
||||||
|
const ok = document.execCommand('copy');
|
||||||
|
ta.remove();
|
||||||
|
if (!ok) return toast('Copying is blocked here. Select the text and copy it by hand.', true);
|
||||||
|
}
|
||||||
|
if (from instanceof Element) copied(from);
|
||||||
|
toast(what);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On an iPhone a share sheet hands the file straight to the VPN app, where a
|
||||||
|
* download would land in Files. Returns the action, or null where files
|
||||||
|
* cannot be shared.
|
||||||
|
*/
|
||||||
|
export function shareFile(name: string, text: string): (() => Promise<void>) | null {
|
||||||
|
const nav = navigator as Navigator & { canShare?: (d: unknown) => boolean };
|
||||||
|
// Only iOS: there AmneziaWG, WireGuard and AmneziaVPN take a file from the
|
||||||
|
// share sheet. On Android neither app is a share target (and Chrome does not
|
||||||
|
// share .conf files), so a download goes into the app's own file picker;
|
||||||
|
// desktop browsers claim they can share files and then do nothing.
|
||||||
|
if (platform() !== 'ios') return null;
|
||||||
|
if (typeof nav.share !== 'function' || typeof File === 'undefined') return null;
|
||||||
|
const file = new File([text], name, { type: 'application/octet-stream' });
|
||||||
|
if (!nav.canShare?.({ files: [file] })) return null;
|
||||||
|
return async () => {
|
||||||
|
try {
|
||||||
|
// The file alone: with a title, "Save to Files" also writes the title as a .txt.
|
||||||
|
await nav.share({ files: [file] });
|
||||||
|
} catch (e) {
|
||||||
|
// Cancelled: nothing to do. Refused by the browser: the file still has to get out.
|
||||||
|
if ((e as Error)?.name !== 'AbortError') download(name, text);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function download(name: string, text: string) {
|
||||||
|
// Not text/plain: Safari would save "name.conf.txt".
|
||||||
|
const url = URL.createObjectURL(new Blob([text], { type: 'application/octet-stream' }));
|
||||||
|
const a = h('a', { href: url, download: name, class: 'offscreen' });
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
setTimeout(() => {
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
a.remove();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The file out: the share sheet where the browser hands it to an app, a download elsewhere. */
|
||||||
|
export function sendFile(name: string, text: string) {
|
||||||
|
const share = shareFile(name, text);
|
||||||
|
if (share) void share();
|
||||||
|
else download(name, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run an action once: its button goes busy (the orb) on the click and stays
|
||||||
|
* disabled until the router answers; a quick answer keeps the orb until it is
|
||||||
|
* all the way in.
|
||||||
|
*/
|
||||||
|
export async function once(btn: HTMLButtonElement, fn: () => Promise<void>) {
|
||||||
|
if (btn.disabled) return;
|
||||||
|
btn.disabled = true;
|
||||||
|
busyOn(btn);
|
||||||
|
const t0 = performance.now();
|
||||||
|
try {
|
||||||
|
await fn();
|
||||||
|
} finally {
|
||||||
|
const wait = calm() ? 0 : BUSY_IN - (performance.now() - t0);
|
||||||
|
if (wait > 0) await new Promise((r) => setTimeout(r, wait));
|
||||||
|
busyOff(btn);
|
||||||
|
btn.disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
// Glass icons: a tinted back shape, the same shape blurred behind a frosted
|
||||||
|
// front pane, a rim, and the detail strokes on top. The shapes are ours; every
|
||||||
|
// colour comes from the stylesheet (tone classes and the --gi-* tokens), never
|
||||||
|
// from a style attribute, which the page's CSP would drop.
|
||||||
|
|
||||||
|
import { iconSvg } from '../../shared/icons';
|
||||||
|
import { markup } from '../dom';
|
||||||
|
|
||||||
|
export type Tone = 'grey' | 'blue' | 'green' | 'red' | 'orange';
|
||||||
|
|
||||||
|
interface Shape {
|
||||||
|
/** The tinted back shape. */
|
||||||
|
b: string;
|
||||||
|
/** The frosted front pane. */
|
||||||
|
f: string;
|
||||||
|
/** Detail strokes on the pane; null: the AmneziaVPN mark instead. */
|
||||||
|
d: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const GL: Record<string, Shape> = {
|
||||||
|
phone: {
|
||||||
|
b: '<rect x="10" y="2" width="10" height="16" rx="3"/>',
|
||||||
|
f: '<rect x="4" y="5" width="11.5" height="17" rx="3.2"/>',
|
||||||
|
d: '<path d="M8.3 19h3.9"/>',
|
||||||
|
},
|
||||||
|
mobile: {
|
||||||
|
b: '<rect x="8.5" y="2" width="13.5" height="17" rx="2.6"/>',
|
||||||
|
f: '<rect x="2.5" y="7" width="9.5" height="15" rx="2.6"/>',
|
||||||
|
d: '<path d="M6 19.4h2.5"/>',
|
||||||
|
},
|
||||||
|
tablet: {
|
||||||
|
b: '<rect x="9.5" y="2" width="12" height="15" rx="2.6"/>',
|
||||||
|
f: '<rect x="2.5" y="5.5" width="14.5" height="16.5" rx="2.8"/>',
|
||||||
|
d: '<path d="M8 19h3.5"/>',
|
||||||
|
},
|
||||||
|
computer: {
|
||||||
|
b: '<rect x="6" y="14" width="17" height="7" rx="2.2"/>',
|
||||||
|
f: '<rect x="1.5" y="3.5" width="19" height="13" rx="2.6"/>',
|
||||||
|
d: '<path d="M5.5 12.5h5"/>',
|
||||||
|
},
|
||||||
|
router: {
|
||||||
|
b: '<rect x="5.5" y="2" width="2.8" height="11" rx="1.4"/><rect x="15.7" y="2" width="2.8" height="11" rx="1.4"/>',
|
||||||
|
f: '<rect x="2" y="10.5" width="20" height="10.5" rx="3"/>',
|
||||||
|
d: '<path d="M6.6 15.75h.4M10 15.75h.4" stroke-width="2.4"/>',
|
||||||
|
},
|
||||||
|
other: { b: '<circle cx="16" cy="8" r="6"/>', f: '<rect x="2.5" y="8" width="14" height="14" rx="3.6"/>', d: '' },
|
||||||
|
plus: {
|
||||||
|
b: '<rect x="9" y="2" width="13" height="13" rx="4"/>',
|
||||||
|
f: '<circle cx="10" cy="14" r="8"/>',
|
||||||
|
d: '<path d="M10 10.6v6.8M6.6 14h6.8"/>',
|
||||||
|
},
|
||||||
|
globe: {
|
||||||
|
b: '<circle cx="16" cy="8" r="6"/>',
|
||||||
|
f: '<circle cx="10.5" cy="13.5" r="8.5"/>',
|
||||||
|
d: '<path d="M2.5 13.5h16" stroke-width="1.1"/><path d="M10.5 5.2c2.4 2.6 2.4 14 0 16.6M10.5 5.2c-2.4 2.6-2.4 14 0 16.6" stroke-width="1.1"/>',
|
||||||
|
},
|
||||||
|
home: {
|
||||||
|
b: '<rect x="12" y="2" width="10" height="10" rx="3"/>',
|
||||||
|
f: '<path d="M2.5 11.6 10.5 5l8 6.6V20a2 2 0 0 1-2 2h-12a2 2 0 0 1-2-2z"/>',
|
||||||
|
d: '<path d="M8.8 22v-4.2h3.4V22"/>',
|
||||||
|
},
|
||||||
|
shield: {
|
||||||
|
b: '<circle cx="16" cy="8" r="6"/>',
|
||||||
|
f: '<path d="M10.5 4.5l7.5 2.8v5.4c0 4.6-3.2 7.4-7.5 8.8C6.2 20.1 3 17.3 3 12.7V7.3z"/>',
|
||||||
|
d: '<path d="M7.3 13.2l2.3 2.3 4.2-4.6"/>',
|
||||||
|
},
|
||||||
|
chart: {
|
||||||
|
b: '<rect x="14.5" y="2" width="7" height="20" rx="2.6"/>',
|
||||||
|
f: '<rect x="2.5" y="8.5" width="14" height="13.5" rx="3.4"/>',
|
||||||
|
d: '<path d="M6 18l2.8-3 2.2 1.8L14 12.8"/>',
|
||||||
|
},
|
||||||
|
calendar: {
|
||||||
|
b: '<rect x="8.5" y="2" width="13.5" height="13" rx="3"/>',
|
||||||
|
f: '<rect x="2" y="6" width="15.5" height="16" rx="3.4"/>',
|
||||||
|
d: '<path d="M2.4 10.6h14.7" stroke-width="1"/><path d="M6.2 14.6h.4M9.5 14.6h.4M12.8 14.6h.4M6.2 18h.4M9.5 18h.4" stroke-width="2.2"/>',
|
||||||
|
},
|
||||||
|
clock: { b: '<circle cx="16" cy="8" r="6"/>', f: '<circle cx="10.5" cy="13.5" r="8.5"/>', d: '<path d="M10.5 9v4.8l3 1.8"/>' },
|
||||||
|
pause: {
|
||||||
|
b: '<rect x="12" y="2" width="10" height="10" rx="3"/>',
|
||||||
|
f: '<circle cx="10.5" cy="13.5" r="8.5"/>',
|
||||||
|
d: '<path d="M8.6 10.5v6M12.4 10.5v6"/>',
|
||||||
|
},
|
||||||
|
server: {
|
||||||
|
b: '<rect x="7" y="2" width="15" height="8" rx="2.6"/>',
|
||||||
|
f: '<rect x="2" y="8" width="16" height="14" rx="3"/>',
|
||||||
|
d: '<path d="M5.5 12.5h.4M5.5 17.5h.4" stroke-width="2.4"/><path d="M2.4 15h15.2" stroke-width="1"/>',
|
||||||
|
},
|
||||||
|
link: {
|
||||||
|
b: '<rect x="11.5" y="1.5" width="8" height="14" rx="4" transform="rotate(45 15.5 8.5)"/>',
|
||||||
|
f: '<rect x="4.5" y="8.5" width="8" height="14" rx="4" transform="rotate(45 8.5 15.5)"/>',
|
||||||
|
d: '<path d="M9.8 14.2l4.4-4.4"/>',
|
||||||
|
},
|
||||||
|
key: {
|
||||||
|
b: '<rect x="10" y="10" width="12.5" height="5" rx="2.5"/><rect x="17" y="13" width="3.4" height="6" rx="1.4"/>',
|
||||||
|
f: '<circle cx="8" cy="12.5" r="6.5"/>',
|
||||||
|
d: '<circle cx="6.6" cy="12.5" r="1.7"/>',
|
||||||
|
},
|
||||||
|
lock: {
|
||||||
|
b: '<rect x="7" y="2" width="10" height="11" rx="5"/>',
|
||||||
|
f: '<rect x="3" y="9" width="18" height="13" rx="3.4"/>',
|
||||||
|
d: '<path d="M12 14v3"/>',
|
||||||
|
},
|
||||||
|
check: {
|
||||||
|
b: '<circle cx="14.5" cy="9.5" r="7.5"/>',
|
||||||
|
f: '<circle cx="10.5" cy="13.5" r="8.5"/>',
|
||||||
|
d: '<path d="M6.6 13.8l2.7 2.7 5.3-5.6"/>',
|
||||||
|
},
|
||||||
|
trash: {
|
||||||
|
b: '<rect x="3" y="2.5" width="18" height="5" rx="2.3"/>',
|
||||||
|
f: '<path d="M4.8 8.5h14.4l-1.1 11.6a2.2 2.2 0 0 1-2.2 1.9H8.1a2.2 2.2 0 0 1-2.2-1.9z"/>',
|
||||||
|
d: '<path d="M10 12v6M14 12v6"/>',
|
||||||
|
},
|
||||||
|
refresh: {
|
||||||
|
b: '<circle cx="16" cy="8" r="6"/>',
|
||||||
|
f: '<circle cx="10.5" cy="13.5" r="8.5"/>',
|
||||||
|
d: '<path d="M14.2 11.3a4.2 4.2 0 1 0 .3 3.6"/><path d="M14.6 8.8v2.8h-2.8"/>',
|
||||||
|
},
|
||||||
|
app: { b: '<circle cx="16" cy="8" r="6"/>', f: '<rect x="2.5" y="7.5" width="14.5" height="14.5" rx="4.2"/>', d: null },
|
||||||
|
file: {
|
||||||
|
b: '<rect x="9" y="2" width="12.5" height="15" rx="3"/>',
|
||||||
|
f: '<rect x="2.5" y="6" width="13.5" height="16" rx="3.2"/>',
|
||||||
|
d: '<path d="M6.2 11h6.5M6.2 14.5h6.5M6.2 18h4"/>',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/** The AmneziaVPN mark without its own svg: drawn on the "app" pane. */
|
||||||
|
const amneziaMark = () =>
|
||||||
|
iconSvg('amnezia', '')
|
||||||
|
.replace(/^<svg[^>]*>/, '')
|
||||||
|
.replace(/<\/svg>$/, '');
|
||||||
|
|
||||||
|
let gid = 0;
|
||||||
|
/** A glass icon as markup (`cls`: its classes, e.g. "gi xl"). */
|
||||||
|
export function glassSvg(name: string, tone: Tone = 'grey', cls = 'gi'): string {
|
||||||
|
const g = GL[name] ?? GL.other;
|
||||||
|
const id = `gl${++gid}`;
|
||||||
|
const detail =
|
||||||
|
g.d === null
|
||||||
|
? `<g class="gdf" transform="translate(5.15 10.15) scale(.385)">${amneziaMark()}</g>`
|
||||||
|
: `<g class="gd" fill="none" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">${g.d}</g>`;
|
||||||
|
return (
|
||||||
|
`<svg class="${cls} t-${tone}" viewBox="0 0 24 24" aria-hidden="true"><defs>` +
|
||||||
|
`<linearGradient id="${id}b" x1="0" y1="0" x2="1" y2="1"><stop offset="0" class="ta"/><stop offset="1" class="tb"/></linearGradient>` +
|
||||||
|
`<linearGradient id="${id}f" x1="0" y1="0" x2="0" y2="1"><stop offset="0" class="fa"/><stop offset=".55" class="fb"/><stop offset="1" class="fc"/></linearGradient>` +
|
||||||
|
`<clipPath id="${id}c">${g.f}</clipPath><filter id="${id}x" x="-40%" y="-40%" width="180%" height="180%"><feGaussianBlur stdDeviation="1.5"/></filter></defs>` +
|
||||||
|
`<g fill="url(#${id}b)">${g.b}</g><g clip-path="url(#${id}c)"><g fill="url(#${id}b)" filter="url(#${id}x)">${g.b}</g></g>` +
|
||||||
|
`<g fill="url(#${id}f)">${g.f}</g><g class="ge" fill="none" stroke-width="1.1">${g.f}</g>` +
|
||||||
|
`<g class="gr" fill="none" stroke-width=".6">${g.f}</g>${detail}</svg>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A glass icon as an element. */
|
||||||
|
export const glass = (name: string, tone: Tone = 'grey', cls = 'gi'): Element => markup(glassSvg(name, tone, cls));
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
// 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). One at a time; it closes on a press
|
||||||
|
// outside, on scroll, on Escape and when its button is pressed again.
|
||||||
|
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { EASE_IN, POP, play } from '../motion';
|
||||||
|
|
||||||
|
export interface MenuItem {
|
||||||
|
label: string;
|
||||||
|
icon: 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;
|
||||||
|
}
|
||||||
|
play(m, [{ opacity: 1 }, { opacity: 0, transform: 'scale(.96)', filter: 'blur(3px)' }], {
|
||||||
|
duration: 120,
|
||||||
|
easing: EASE_IN,
|
||||||
|
fill: 'forwards',
|
||||||
|
}).onfinish = () => m.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** `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 b = h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
role: 'menuitem',
|
||||||
|
class: `mi ${it.tone ?? ''}`,
|
||||||
|
onclick: () => {
|
||||||
|
closeMenu();
|
||||||
|
it.run();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ic(it.icon),
|
||||||
|
h('span', {}, it.label),
|
||||||
|
);
|
||||||
|
// The highlight comes in where the pointer is, then glides from item to item.
|
||||||
|
b.addEventListener('pointerenter', () => {
|
||||||
|
hl.className = `menu-hl${hl.style.opacity === '1' ? ' 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,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
menuEl = m;
|
||||||
|
anchorEl = anchor;
|
||||||
|
anchor.setAttribute('aria-expanded', 'true');
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('pointerdown', (e) => {
|
||||||
|
const t = e.target as Element;
|
||||||
|
if (menuEl && !menuEl.contains(t) && !anchorEl?.contains(t)) closeMenu();
|
||||||
|
});
|
||||||
|
addEventListener('scroll', () => closeMenu(), { passive: true });
|
||||||
@@ -0,0 +1,585 @@
|
|||||||
|
// Words that change in place morph letter by letter: the old letters lift away
|
||||||
|
// with a blur, the new ones rise in one after another, and the width glides
|
||||||
|
// between them. Every text the page or a sheet changes while it shows goes
|
||||||
|
// through `morphText`: a card's name and status after a repaint, the counts and
|
||||||
|
// values, a label that says "Copied", a line that says what happened (the way:
|
||||||
|
// "iPad connected"), and a menu path for another app or the other phone system
|
||||||
|
// (`menuLine`: where the app scans, iOS "Create", Android "Scan").
|
||||||
|
|
||||||
|
import { h, ic, markup, put, type Kid } from '../dom';
|
||||||
|
import { EASE_IN, EASE_OUT, POP, SMOOTH, calm, play } from '../motion';
|
||||||
|
|
||||||
|
/** Each character as its own inline box, so each can move. */
|
||||||
|
const letters = (w: string): HTMLElement[] => [...w].map((ch) => h('i', {}, ch));
|
||||||
|
|
||||||
|
interface Run {
|
||||||
|
/** What it is turning into. */
|
||||||
|
text: string;
|
||||||
|
timer: number;
|
||||||
|
}
|
||||||
|
const runs = new WeakMap<HTMLElement, Run>();
|
||||||
|
|
||||||
|
/** What `el` says: while it morphs, what it is turning into. */
|
||||||
|
export const textOf = (el: HTMLElement): string => runs.get(el)?.text ?? el.textContent ?? '';
|
||||||
|
|
||||||
|
/** Where `el`'s words sit (their own box, not the element's). */
|
||||||
|
function wordsBox(el: HTMLElement): DOMRect {
|
||||||
|
const r = document.createRange();
|
||||||
|
r.selectNodeContents(el);
|
||||||
|
return r.getBoundingClientRect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Where each character of `el`'s plain text starts, from the first (kerning and all). */
|
||||||
|
function spacing(el: HTMLElement): number[] {
|
||||||
|
const node = el.firstChild;
|
||||||
|
if (!node || node.nodeType !== Node.TEXT_NODE) return [];
|
||||||
|
const r = document.createRange();
|
||||||
|
const out: number[] = [];
|
||||||
|
let o = 0;
|
||||||
|
for (const ch of node.textContent ?? '') {
|
||||||
|
r.setStart(node, o);
|
||||||
|
r.setEnd(node, o + ch.length);
|
||||||
|
out.push(r.getBoundingClientRect().left);
|
||||||
|
o += ch.length;
|
||||||
|
}
|
||||||
|
return out.map((x) => x - out[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The letters stood where the plain text's characters stand. One by one they
|
||||||
|
* lose the font's kerning, so the word turning back into text would shift on
|
||||||
|
* its last frame; a nudge each and they land exactly on it.
|
||||||
|
*/
|
||||||
|
function space(box: Element, at: number[]) {
|
||||||
|
const kids = [...box.children] as HTMLElement[];
|
||||||
|
if (!kids.length) return;
|
||||||
|
const start = kids[0].getBoundingClientRect().left;
|
||||||
|
kids.forEach((c, i) => {
|
||||||
|
if (!i || at[i] === undefined) return;
|
||||||
|
const dx = start + at[i] - c.getBoundingClientRect().left;
|
||||||
|
if (Math.abs(dx) > 0.01) c.style.marginLeft = `${dx}px`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The letters both texts keep, in order: pairs of [old index, new index]. What
|
||||||
|
* they share at the start and at the end stays together; in between, the
|
||||||
|
* longest run of letters in common (a longest common subsequence).
|
||||||
|
*/
|
||||||
|
export function kept(a: string[], b: string[]): [number, number][] {
|
||||||
|
let p = 0;
|
||||||
|
while (p < a.length && p < b.length && a[p] === b[p]) p++;
|
||||||
|
let q = 0;
|
||||||
|
while (q < a.length - p && q < b.length - p && a[a.length - 1 - q] === b[b.length - 1 - q]) q++;
|
||||||
|
const A = a.slice(p, a.length - q);
|
||||||
|
const B = b.slice(p, b.length - q);
|
||||||
|
const L = Array.from({ length: A.length + 1 }, () => new Array<number>(B.length + 1).fill(0));
|
||||||
|
for (let i = A.length - 1; i >= 0; i--)
|
||||||
|
for (let j = B.length - 1; j >= 0; j--) L[i][j] = A[i] === B[j] ? L[i + 1][j + 1] + 1 : Math.max(L[i + 1][j], L[i][j + 1]);
|
||||||
|
const out: [number, number][] = [];
|
||||||
|
for (let i = 0; i < p; i++) out.push([i, i]);
|
||||||
|
for (let i = 0, j = 0; i < A.length && j < B.length; ) {
|
||||||
|
if (A[i] === B[j]) out.push([p + i++, p + j++]);
|
||||||
|
else if (L[i + 1][j] >= L[i][j + 1]) i++;
|
||||||
|
else j++;
|
||||||
|
}
|
||||||
|
for (let k = q; k > 0; k--) out.push([a.length - k, b.length - k]);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A morph under way on `el` ends where it was going: its words as plain text. */
|
||||||
|
function finish(el: HTMLElement) {
|
||||||
|
const r = runs.get(el);
|
||||||
|
if (!r) return;
|
||||||
|
clearTimeout(r.timer);
|
||||||
|
runs.delete(el);
|
||||||
|
el.getAnimations().forEach((a) => a.cancel());
|
||||||
|
el.classList.remove('mt', 'mt-ib');
|
||||||
|
el.textContent = r.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Plain, at once: a morph under way on `el` stops where it is going. */
|
||||||
|
export function setText(el: HTMLElement, text: string) {
|
||||||
|
finish(el);
|
||||||
|
el.textContent = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MorphOpts {
|
||||||
|
/** The words change as a whole instead: the old blur away where they stood as the new come in. */
|
||||||
|
whole?: boolean;
|
||||||
|
/** false where something else moves what follows (a width gliding inside a wrapping list would reflow it mid-way). */
|
||||||
|
glide?: boolean;
|
||||||
|
/**
|
||||||
|
* Where the old words stand on screen now, when `el` no longer holds them in
|
||||||
|
* the same layout (morphInto: put back, they could wrap another way): whole
|
||||||
|
* words go from there, and the width does not glide.
|
||||||
|
*/
|
||||||
|
at?: DOMRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `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
|
||||||
|
* it said before a repaint rebuilt it (the new element already says `next`).
|
||||||
|
* The old letters keep to the edge
|
||||||
|
* that stays put while the width changes (the start of a line, the end of a
|
||||||
|
* value on the right, the middle of a centred line). Done, it holds plain text
|
||||||
|
* again: a box that ends in an ellipsis keeps it.
|
||||||
|
*/
|
||||||
|
export function morphText(el: HTMLElement, next: string, from = textOf(el), o: MorphOpts = {}) {
|
||||||
|
const { whole = false, at } = o;
|
||||||
|
// Placed by the caller, the width does not glide: what follows is moved by the caller too.
|
||||||
|
const glide = (o.glide ?? true) && !at;
|
||||||
|
// Interrupted mid-way: the width carries on from where it is on screen, not from where that morph was going.
|
||||||
|
const midway = runs.has(el) ? el.getBoundingClientRect().width : null;
|
||||||
|
finish(el);
|
||||||
|
// Nothing to watch move: no motion asked for, or not on screen (a folded row, a closed sheet).
|
||||||
|
if (from === next || calm() || !el.getClientRects().length) {
|
||||||
|
el.textContent = next;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const cs = getComputedStyle(el);
|
||||||
|
// Letters need a box whose width can glide; words that change whole keep the text's own flow (they
|
||||||
|
// may wrap), and what follows them is moved by the caller (morphInto) instead.
|
||||||
|
const flow = whole && cs.display === 'inline';
|
||||||
|
if (cs.display === 'inline' && !whole) el.classList.add('mt-ib');
|
||||||
|
if (cs.position === 'static') el.classList.add('mt');
|
||||||
|
let r0: DOMRect | null = null;
|
||||||
|
let t0 = at ?? null;
|
||||||
|
let at0: number[] = [];
|
||||||
|
if (!t0) {
|
||||||
|
el.textContent = from;
|
||||||
|
r0 = el.getBoundingClientRect();
|
||||||
|
t0 = wordsBox(el);
|
||||||
|
at0 = spacing(el);
|
||||||
|
}
|
||||||
|
el.textContent = next;
|
||||||
|
const r1 = el.getBoundingClientRect();
|
||||||
|
const at1 = spacing(el);
|
||||||
|
const w0 = midway ?? r0?.width ?? r1.width;
|
||||||
|
const glides = glide && !flow && !!r0 && Math.abs(r1.width - w0) > 0.5;
|
||||||
|
const edge = !glides || !r0 || Math.abs(r1.left - r0.left) < 0.5 ? 'start' : Math.abs(r1.right - r0.right) < 0.5 ? 'end' : 'middle';
|
||||||
|
|
||||||
|
const neu = h('span', { class: whole ? 'mt-new w' : 'mt-new' }, whole ? next : letters(next));
|
||||||
|
const old = h('span', { class: whole ? 'mt-old w' : 'mt-old', 'aria-hidden': 'true' }, whole ? from : letters(from));
|
||||||
|
// Whole words wrap as they did: the old ones keep the width they took.
|
||||||
|
if (whole) old.style.width = `${t0.width + 1}px`;
|
||||||
|
el.replaceChildren(neu, old);
|
||||||
|
// Held at the plain text's width until the letters turn back into it, so what follows never steps.
|
||||||
|
if (glides)
|
||||||
|
play(el, [{ width: `${w0}px` }, { width: `${r1.width}px` }], {
|
||||||
|
duration: SMOOTH.duration,
|
||||||
|
easing: SMOOTH.easing,
|
||||||
|
fill: 'forwards',
|
||||||
|
});
|
||||||
|
// The old letters go from exactly where they stood on screen, against the box as it is now: a box
|
||||||
|
// its text left empty sits lower (on the baseline), and would carry them down with it.
|
||||||
|
const r2 = el.getBoundingClientRect();
|
||||||
|
const place = (dx: number, dy: number) => {
|
||||||
|
old.style.top = `${dy}px`;
|
||||||
|
if (edge === 'end') old.style.right = `${-dx}px`;
|
||||||
|
else if (edge === 'middle') {
|
||||||
|
old.style.left = '50%';
|
||||||
|
old.style.translate = `calc(-50% + ${dx}px) 0`;
|
||||||
|
} else old.style.left = `${dx}px`;
|
||||||
|
};
|
||||||
|
const x0 = edge === 'end' ? t0.right - r2.right : edge === 'middle' ? (t0.left + t0.right - r2.left - r2.right) / 2 : t0.left - r2.left;
|
||||||
|
place(x0, t0.top - r2.top);
|
||||||
|
// Then onto the old words exactly: the box's top is not the text's (the line's leading sits above it).
|
||||||
|
const t2 = wordsBox(old);
|
||||||
|
place(x0 + t0.left - t2.left, t0.top - r2.top + t0.top - t2.top);
|
||||||
|
if (whole) {
|
||||||
|
play(
|
||||||
|
old,
|
||||||
|
[
|
||||||
|
{ opacity: 1, filter: 'blur(0px)' },
|
||||||
|
{ opacity: 0, filter: 'blur(4px)' },
|
||||||
|
],
|
||||||
|
{ duration: 180, easing: EASE_IN, fill: 'forwards' },
|
||||||
|
);
|
||||||
|
play(
|
||||||
|
neu,
|
||||||
|
[
|
||||||
|
{ opacity: 0, filter: 'blur(4px)' },
|
||||||
|
{ opacity: 1, filter: 'blur(0px)' },
|
||||||
|
],
|
||||||
|
{ duration: 280, delay: 60, easing: EASE_OUT, fill: 'backwards' },
|
||||||
|
);
|
||||||
|
const ends = Math.max(340, glides ? SMOOTH.duration : 0) + 40;
|
||||||
|
runs.set(el, { text: next, timer: window.setTimeout(() => finish(el), ends) });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
space(neu, at1);
|
||||||
|
space(old, at0);
|
||||||
|
|
||||||
|
// The letters both texts keep slide from where they stood to where they go, on the width's spring;
|
||||||
|
// the old ones' places in the overlay stay empty.
|
||||||
|
const was = [...old.children] as HTMLElement[];
|
||||||
|
const now = [...neu.children] as HTMLElement[];
|
||||||
|
const pairs = kept([...from], [...next]);
|
||||||
|
const stays = new Set(pairs.map(([i]) => i));
|
||||||
|
const comes = new Set(pairs.map(([, j]) => j));
|
||||||
|
pairs.forEach(([i, j]) => {
|
||||||
|
const a = was[i].getBoundingClientRect();
|
||||||
|
const b = now[j].getBoundingClientRect();
|
||||||
|
was[i].style.visibility = 'hidden';
|
||||||
|
if (Math.abs(a.left - b.left) > 0.5 || Math.abs(a.top - b.top) > 0.5)
|
||||||
|
play(now[j], [{ transform: `translate(${a.left - b.left}px, ${a.top - b.top}px)` }, { transform: 'none' }], {
|
||||||
|
duration: SMOOTH.duration,
|
||||||
|
easing: SMOOTH.easing,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const out = was.filter((_, i) => !stays.has(i));
|
||||||
|
const inn = now.filter((_, j) => !comes.has(j));
|
||||||
|
// 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: 1, filter: 'blur(0px)', 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' },
|
||||||
|
),
|
||||||
|
);
|
||||||
|
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) });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The keyed texts under `root` (`data-t`), before a repaint rebuilds them. */
|
||||||
|
export function textsOf(root: ParentNode): Map<string, string> {
|
||||||
|
return new Map([...root.querySelectorAll<HTMLElement>('[data-t]')].map((el) => [el.dataset.t!, textOf(el)]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** After the repaint: each keyed text that changed morphs from what it said. */
|
||||||
|
export function morphChanged(root: ParentNode, was: Map<string, string>) {
|
||||||
|
root.querySelectorAll<HTMLElement>('[data-t]').forEach((el) => {
|
||||||
|
const before = was.get(el.dataset.t!);
|
||||||
|
const now = el.textContent ?? '';
|
||||||
|
if (before !== undefined && before !== now) morphText(el, now, before);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What a box shows, piece by piece, keyed by where each sits (child indexes): its kind, its words, its drawing, its place. */
|
||||||
|
interface Piece {
|
||||||
|
kind: string;
|
||||||
|
text: string;
|
||||||
|
svg: string;
|
||||||
|
at: DOMRect | null;
|
||||||
|
/** Where its words stand (a morph under way: the words it is turning into). */
|
||||||
|
words: DOMRect | null;
|
||||||
|
node: Node;
|
||||||
|
}
|
||||||
|
/** Its tag and classes, less a morph's own (a piece still changing is the same piece). */
|
||||||
|
const kindOf = (el: Element) => `${el.tagName}.${[...el.classList].filter((c) => c !== 'mt' && c !== 'mt-ib').join(' ')}`;
|
||||||
|
/** A drawing as markup, less the ids each build makes up (a glass icon's gradients): the same icon twice is the same. */
|
||||||
|
const drawing = (el: Element) => el.outerHTML.replace(/\bgl\d+/g, 'gl');
|
||||||
|
function pieces(box: Element): Map<string, Piece> {
|
||||||
|
const out = new Map<string, Piece>();
|
||||||
|
const walk = (n: Node, path: string) =>
|
||||||
|
n.childNodes.forEach((c, i) => {
|
||||||
|
const p = `${path}/${i}`;
|
||||||
|
if (c.nodeType === Node.TEXT_NODE) {
|
||||||
|
if (c.textContent?.trim()) {
|
||||||
|
const r = document.createRange();
|
||||||
|
r.selectNodeContents(c);
|
||||||
|
const at = r.getBoundingClientRect();
|
||||||
|
out.set(p, { kind: '#text', text: c.textContent, svg: '', at, words: at, node: c });
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(c instanceof Element)) return;
|
||||||
|
const svg = c instanceof SVGElement ? drawing(c) : '';
|
||||||
|
const words = c instanceof HTMLElement && !svg ? wordsBox(c.querySelector<HTMLElement>(':scope > .mt-new') ?? c) : null;
|
||||||
|
out.set(p, { kind: kindOf(c), text: c instanceof HTMLElement ? textOf(c) : '', svg, at: c.getBoundingClientRect(), words, node: c });
|
||||||
|
if (!svg) walk(c, p);
|
||||||
|
});
|
||||||
|
walk(box, '');
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Something with nothing to change from comes in through a blur. */
|
||||||
|
const appear = (el: Element) =>
|
||||||
|
play(
|
||||||
|
el,
|
||||||
|
[
|
||||||
|
{ opacity: 0, filter: 'blur(4px)' },
|
||||||
|
{ opacity: 1, filter: 'blur(0px)' },
|
||||||
|
],
|
||||||
|
{ duration: 280, delay: 60, easing: EASE_OUT, fill: 'backwards' },
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `box` refilled with `kids` and nothing blinks: what is the same stays still;
|
||||||
|
* a piece in the same place with other words blurs from the old words into the
|
||||||
|
* new where it stands; a drawing that changed comes in through a blur; a piece
|
||||||
|
* that changed its kind or its height (another block, a list that wraps over
|
||||||
|
* more lines) crosses whole, the old one blurring out exactly where it stood as
|
||||||
|
* the new one blurs in, and so does what is gone. A piece that kept its kind
|
||||||
|
* and size but moved glides from where it stood. Places are taken against the
|
||||||
|
* box, which its sheet moves as a whole; an old piece fades inside its own
|
||||||
|
* parent's new self (the same kind, in the same place), so it keeps its look.
|
||||||
|
*/
|
||||||
|
export function morphInto(box: HTMLElement, kids: Kid) {
|
||||||
|
const was = pieces(box);
|
||||||
|
const box0 = box.getBoundingClientRect();
|
||||||
|
put(box, kids);
|
||||||
|
if (!was.size || calm()) return;
|
||||||
|
const box1 = box.getBoundingClientRect();
|
||||||
|
/** Where something that stood at `r` in the box's old place stands now, the pieces having glided back there. */
|
||||||
|
const here = (r: DOMRect | null) => r && new DOMRect(r.left - box0.left + box1.left, r.top - box0.top + box1.top, r.width, r.height);
|
||||||
|
const morphs: (() => void)[] = [];
|
||||||
|
/** An old piece, where it stood, the new parent it fades in and where that parent stood. */
|
||||||
|
const ghosts: [Element, DOMRect, Element, DOMRect][] = [];
|
||||||
|
const seen = new Set<string>();
|
||||||
|
const cross = (el: Element, w: Piece | undefined, path: string) => {
|
||||||
|
const host = el.parentElement;
|
||||||
|
const from = path ? was.get(path)?.at : box0;
|
||||||
|
if (w?.at && w.node instanceof Element) ghosts.push(host && from ? [w.node, w.at, host, from] : [w.node, w.at, box, box0]);
|
||||||
|
morphs.push(() => appear(el));
|
||||||
|
};
|
||||||
|
/** Moves `el` from where it stood (`at`, in the box's old place) to where it is, less what its parent already carries. */
|
||||||
|
const glideFrom = (el: Element, at: DOMRect, carried: [number, number]): [number, number] => {
|
||||||
|
const r = el.getBoundingClientRect();
|
||||||
|
const dx = at.left - box0.left - (r.left - box1.left);
|
||||||
|
const dy = at.top - box0.top - (r.top - box1.top);
|
||||||
|
const ox = dx - carried[0];
|
||||||
|
const oy = dy - carried[1];
|
||||||
|
if (Math.abs(ox) > 0.5 || Math.abs(oy) > 0.5)
|
||||||
|
play(el, [{ transform: `translate(${ox}px, ${oy}px)` }, { transform: 'none' }], { duration: SMOOTH.duration, easing: SMOOTH.easing });
|
||||||
|
return [dx, dy];
|
||||||
|
};
|
||||||
|
const walk = (n: Node, path: string, carried: [number, number]) =>
|
||||||
|
[...n.childNodes].forEach((c, i) => {
|
||||||
|
const p = `${path}/${i}`;
|
||||||
|
seen.add(p);
|
||||||
|
const w = was.get(p);
|
||||||
|
if (c.nodeType === Node.TEXT_NODE) {
|
||||||
|
const t = c.textContent ?? '';
|
||||||
|
if (!t.trim() || (w?.kind === '#text' && w.text === t)) return;
|
||||||
|
// A bare word among elements goes into a span of its own, so it can change (and glide from where its words were).
|
||||||
|
const s = h('span', {}, t);
|
||||||
|
c.replaceWith(s);
|
||||||
|
if (w?.at) glideFrom(s, w.at, carried);
|
||||||
|
morphs.push(() =>
|
||||||
|
w?.kind === '#text' && t.length <= 40 && w.text.length <= 40
|
||||||
|
? morphText(s, t, w.text, { whole: true, at: here(w.words) ?? undefined })
|
||||||
|
: appear(s),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(c instanceof Element)) return;
|
||||||
|
const r = c.getBoundingClientRect();
|
||||||
|
if (!w || w.kind !== kindOf(c) || (w.at && Math.abs(w.at.height - r.height) > 1 && !(c instanceof SVGElement)))
|
||||||
|
return cross(c, w, path);
|
||||||
|
// The same piece somewhere else in the box: it glides there (what it holds rides along, plus its own move).
|
||||||
|
const own = w.at ? glideFrom(c, w.at, carried) : carried;
|
||||||
|
if (c instanceof SVGElement) {
|
||||||
|
if (w.svg !== drawing(c)) morphs.push(() => appear(c));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!c.children.length && c instanceof HTMLElement) {
|
||||||
|
const t = c.textContent ?? '';
|
||||||
|
if (t !== w.text)
|
||||||
|
morphs.push(() =>
|
||||||
|
t.length <= 40 && w.text.length <= 40
|
||||||
|
? morphText(c, t, w.text, { whole: true, at: here(w.words) ?? undefined })
|
||||||
|
: cross(c, w, path),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
walk(c, p, own);
|
||||||
|
});
|
||||||
|
walk(box, '', [0, 0]);
|
||||||
|
// What the new box no longer has goes the same way.
|
||||||
|
for (const [p, w] of was)
|
||||||
|
if (!seen.has(p) && p.lastIndexOf('/') === 0 && w.at && w.node instanceof Element) ghosts.push([w.node, w.at, box, box0]);
|
||||||
|
morphs.forEach((m) => m());
|
||||||
|
// The old pieces that cross go from exactly where they stood in their parent (which glides from where it stood).
|
||||||
|
const hosts = new Map<Element, number>();
|
||||||
|
for (const [, , host] of ghosts) {
|
||||||
|
if (!hosts.has(host) && getComputedStyle(host).position === 'static') host.classList.add('mt');
|
||||||
|
hosts.set(host, (hosts.get(host) ?? 0) + 1);
|
||||||
|
}
|
||||||
|
for (const [g, at, host, from] of ghosts) {
|
||||||
|
const e = g as HTMLElement;
|
||||||
|
e.style.position = 'absolute';
|
||||||
|
e.style.margin = '0';
|
||||||
|
e.style.left = `${at.left - from.left - host.clientLeft}px`;
|
||||||
|
e.style.top = `${at.top - from.top - host.clientTop}px`;
|
||||||
|
e.style.width = `${at.width}px`;
|
||||||
|
e.style.pointerEvents = 'none';
|
||||||
|
e.setAttribute('aria-hidden', 'true');
|
||||||
|
host.appendChild(e);
|
||||||
|
play(
|
||||||
|
e,
|
||||||
|
[
|
||||||
|
{ opacity: 1, filter: 'blur(0px)' },
|
||||||
|
{ opacity: 0, filter: 'blur(4px)' },
|
||||||
|
],
|
||||||
|
{ duration: 180, easing: EASE_IN, fill: 'forwards' },
|
||||||
|
).onfinish = () => {
|
||||||
|
e.remove();
|
||||||
|
const n = hosts.get(host)! - 1;
|
||||||
|
hosts.set(host, n);
|
||||||
|
if (!n) host.classList.remove('mt');
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The Android robot's head; its eyes take the colour of what it sits on. */
|
||||||
|
const ANDROID =
|
||||||
|
'<svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M2.5 19a9.5 9.5 0 0 1 19 0z" fill="currentColor"/>' +
|
||||||
|
'<path d="M6.9 11.2 4.6 7.4M17.1 11.2l2.3-3.8" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>' +
|
||||||
|
'<circle class="eye" cx="8.3" cy="15" r="1.25"/><circle class="eye" cx="15.7" cy="15" r="1.25"/></svg>';
|
||||||
|
const marks = (): Element[] => [ic('apple'), markup(ANDROID)];
|
||||||
|
|
||||||
|
/** One step of a path, cut where iOS and Android word it differently: [what comes before, iOS word, Android word, what comes after]. */
|
||||||
|
type Step = [string, string, string, string];
|
||||||
|
function cut(ios: string, android: string): Step {
|
||||||
|
if (ios === android) return ['', ios, ios, ''];
|
||||||
|
const A = ios.split(' ');
|
||||||
|
const B = android.split(' ');
|
||||||
|
let p = 0;
|
||||||
|
while (p < A.length && p < B.length && A[p] === B[p]) p++;
|
||||||
|
let q = 0;
|
||||||
|
while (q < A.length - p && q < B.length - p && A[A.length - 1 - q] === B[B.length - 1 - q]) q++;
|
||||||
|
const pre = A.slice(0, p).join(' ');
|
||||||
|
const suf = A.slice(A.length - q).join(' ');
|
||||||
|
return [pre ? `${pre} ` : '', A.slice(p, A.length - q).join(' '), B.slice(p, B.length - q).join(' '), suf ? ` ${suf}` : ''];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MenuLine {
|
||||||
|
el: HTMLElement;
|
||||||
|
/** Another app's path in its place: each part morphs, the arrows stay, the system's mark comes or goes. */
|
||||||
|
set(ios: string, android: string): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A menu path ("+ → Create from QR code") for both phone systems in one line,
|
||||||
|
* its steps in bold with grey arrows between them. Where iOS and Android word a
|
||||||
|
* step differently, that word turns between the two every few seconds, the
|
||||||
|
* system's mark beside it.
|
||||||
|
*/
|
||||||
|
export function menuLine(ios: string, android: string): MenuLine {
|
||||||
|
const body = h('span', { 'aria-hidden': 'true' });
|
||||||
|
const el = h('b', { class: 'osm', role: 'text' }, body);
|
||||||
|
let steps: Step[] = [];
|
||||||
|
let parts: { pre: HTMLElement; word: HTMLElement; suf: HTMLElement }[] = [];
|
||||||
|
/** The step that differs (its mark stands before its word), or -1. */
|
||||||
|
let at = -1;
|
||||||
|
let icEl: HTMLElement | null = null;
|
||||||
|
/** Which system's wording shows: 0 iOS, 1 Android. */
|
||||||
|
let k = 0;
|
||||||
|
const wordOf = (s: Step) => (k ? s[2] : s[1]);
|
||||||
|
const part = (t: string) => h('span', { class: 'osm-p' }, t);
|
||||||
|
|
||||||
|
/** Drawn afresh, no motion (the first time, or a path with another number of steps). */
|
||||||
|
const draw = () => {
|
||||||
|
at = steps.findIndex((s) => s[1] !== s[2]);
|
||||||
|
if (at < 0) k = 0;
|
||||||
|
parts = steps.map((s) => ({ pre: part(s[0]), word: part(wordOf(s)), suf: part(s[3]) }));
|
||||||
|
icEl = at >= 0 ? h('span', { class: 'osm-ic' }, marks()[k]) : null;
|
||||||
|
body.replaceChildren(
|
||||||
|
...parts
|
||||||
|
.flatMap((p, i) => [i ? h('span', { class: 'arr' }, '›') : null, p.pre, i === at ? icEl : null, p.word, p.suf])
|
||||||
|
.filter((n): n is HTMLElement => !!n),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const MARK = { width: '1.05em', marginRight: '0.25em' };
|
||||||
|
const markOut = (m: HTMLElement) =>
|
||||||
|
(play(
|
||||||
|
m,
|
||||||
|
[
|
||||||
|
{ opacity: 1, filter: 'blur(0px)', ...MARK },
|
||||||
|
{ opacity: 0, filter: 'blur(3px)', width: '0px', marginRight: '0px' },
|
||||||
|
],
|
||||||
|
{ duration: 220, easing: EASE_IN, fill: 'forwards' },
|
||||||
|
).onfinish = () => m.remove());
|
||||||
|
const markIn = (m: HTMLElement) =>
|
||||||
|
play(
|
||||||
|
m,
|
||||||
|
[
|
||||||
|
{ opacity: 0, filter: 'blur(3px)', width: '0px', marginRight: '0px' },
|
||||||
|
{ opacity: 1, filter: 'blur(0px)', ...MARK },
|
||||||
|
],
|
||||||
|
{ duration: SMOOTH.duration, easing: SMOOTH.easing },
|
||||||
|
);
|
||||||
|
|
||||||
|
const set = (i: string, a: string) => {
|
||||||
|
el.setAttribute('aria-label', (i === a ? i : `${i} (Android: ${a.split(' → ').pop()})`).replace(/ → /g, ' › '));
|
||||||
|
const I = i.split(' → ');
|
||||||
|
const A = a.split(' → ');
|
||||||
|
const next = I.map((s, n) => cut(s, A[n] ?? s));
|
||||||
|
if (!parts.length || next.length !== steps.length) {
|
||||||
|
steps = next;
|
||||||
|
return draw();
|
||||||
|
}
|
||||||
|
const was = at;
|
||||||
|
steps = next;
|
||||||
|
at = steps.findIndex((s) => s[1] !== s[2]);
|
||||||
|
if (at < 0) k = 0;
|
||||||
|
// Another app's path: each part blurs from the old words into the new (the system's turn morphs, below).
|
||||||
|
steps.forEach((s, n) => {
|
||||||
|
morphText(parts[n].pre, s[0], undefined, { whole: true });
|
||||||
|
morphText(parts[n].word, wordOf(s), undefined, { whole: true });
|
||||||
|
morphText(parts[n].suf, s[3], undefined, { whole: true });
|
||||||
|
});
|
||||||
|
if (at === was) return;
|
||||||
|
if (icEl) markOut(icEl);
|
||||||
|
icEl = at >= 0 ? h('span', { class: 'osm-ic' }, marks()[k]) : null;
|
||||||
|
if (icEl) {
|
||||||
|
parts[at].word.before(icEl);
|
||||||
|
markIn(icEl);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
set(ios, android);
|
||||||
|
|
||||||
|
// The other system's wording, every few seconds: its word morphs, its mark turns in.
|
||||||
|
const turn = () => {
|
||||||
|
if (!el.isConnected) return clearInterval(timer);
|
||||||
|
// Not on screen (a folded row): wait for the next turn.
|
||||||
|
if (at < 0 || !icEl || !el.offsetParent) return;
|
||||||
|
k = 1 - k;
|
||||||
|
morphText(parts[at].word, wordOf(steps[at]));
|
||||||
|
const oi = icEl.firstElementChild as Element;
|
||||||
|
const ni = marks()[k];
|
||||||
|
if (calm()) {
|
||||||
|
oi.replaceWith(ni);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
icEl.appendChild(ni);
|
||||||
|
play(
|
||||||
|
oi,
|
||||||
|
[
|
||||||
|
{ opacity: 1, filter: 'blur(0px)', transform: 'none' },
|
||||||
|
{ opacity: 0, filter: 'blur(3px)', transform: 'scale(.5) rotate(-40deg)' },
|
||||||
|
],
|
||||||
|
{ duration: 200, easing: EASE_IN, fill: 'forwards' },
|
||||||
|
).onfinish = () => oi.remove();
|
||||||
|
play(
|
||||||
|
ni,
|
||||||
|
[
|
||||||
|
{ opacity: 0, filter: 'blur(3px)', transform: 'scale(.5) rotate(40deg)' },
|
||||||
|
{ opacity: 1, filter: 'blur(0px)', transform: 'none' },
|
||||||
|
],
|
||||||
|
{ duration: POP.duration, delay: 80, easing: POP.easing, fill: 'backwards' },
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const timer = window.setInterval(turn, 3000);
|
||||||
|
return { el, set };
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
// The icon picker (the apps): icons only, the picked one widens and shows its
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { EASE_OUT, LEAD, SMOOTH, calm, play } from '../motion';
|
||||||
|
|
||||||
|
export interface SegItem<T extends string> {
|
||||||
|
value: T;
|
||||||
|
label: string;
|
||||||
|
icon: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IconSeg<T extends string> {
|
||||||
|
el: HTMLElement;
|
||||||
|
/** Show this value without telling anyone (another copy of the picker changed it). */
|
||||||
|
sync(v: T): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function iconSeg<T extends string>(items: SegItem<T>[], value: T, onPick: (v: T) => void): IconSeg<T> {
|
||||||
|
const pill = h('span', { class: 'seg-pill' });
|
||||||
|
const el = h('div', { class: 'seg appseg', role: 'tablist' }, pill);
|
||||||
|
const btns = items.map((it) => {
|
||||||
|
const b = h(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'seg-b', role: 'tab', 'aria-label': it.label, title: it.label, onclick: () => pick(it.value) },
|
||||||
|
ic(it.icon),
|
||||||
|
h('span', { class: 'seg-l' }, it.label),
|
||||||
|
);
|
||||||
|
b.dataset.v = it.value;
|
||||||
|
el.appendChild(b);
|
||||||
|
return b;
|
||||||
|
});
|
||||||
|
const labelOf = (b: HTMLElement) => b.querySelector('.seg-l') as HTMLElement;
|
||||||
|
const mark = () =>
|
||||||
|
btns.forEach((b) => {
|
||||||
|
const on = b.dataset.v === value;
|
||||||
|
b.classList.toggle('on', on);
|
||||||
|
b.setAttribute('aria-selected', String(on));
|
||||||
|
});
|
||||||
|
const edges = (): [number, number] | null => {
|
||||||
|
const b = btns.find((x) => x.dataset.v === value);
|
||||||
|
return b && b.offsetWidth ? [b.offsetLeft, el.clientWidth - b.offsetLeft - b.offsetWidth] : null;
|
||||||
|
};
|
||||||
|
const placePill = () => {
|
||||||
|
const e = edges();
|
||||||
|
if (!e) return;
|
||||||
|
pill.style.left = `${e[0]}px`;
|
||||||
|
pill.style.right = `${e[1]}px`;
|
||||||
|
};
|
||||||
|
|
||||||
|
let raf = 0;
|
||||||
|
function pick(v: T) {
|
||||||
|
if (v === value) return;
|
||||||
|
const from = btns.findIndex((b) => b.dataset.v === value);
|
||||||
|
const to = btns.findIndex((b) => b.dataset.v === v);
|
||||||
|
const cs = getComputedStyle(pill);
|
||||||
|
const l0 = parseFloat(cs.left) || 0;
|
||||||
|
const r0 = parseFloat(cs.right) || 0;
|
||||||
|
const g0 = btns.map((b) => parseFloat(getComputedStyle(b).flexGrow) || 0);
|
||||||
|
const oldL = labelOf(btns[from]);
|
||||||
|
const oldW = oldL.getBoundingClientRect().width;
|
||||||
|
[...btns, ...btns.map(labelOf)].forEach((x) => x.getAnimations().forEach((a) => a.cancel()));
|
||||||
|
value = v;
|
||||||
|
mark();
|
||||||
|
btns.forEach((b, i) => {
|
||||||
|
const g1 = i === to ? 1 : 0;
|
||||||
|
if (g0[i] !== g1) play(b, [{ flexGrow: g0[i] }, { flexGrow: g1 }], { duration: SMOOTH.duration, easing: SMOOTH.easing });
|
||||||
|
});
|
||||||
|
play(
|
||||||
|
oldL,
|
||||||
|
[
|
||||||
|
{ opacity: 1, maxWidth: `${oldW}px`, marginLeft: '0px' },
|
||||||
|
{ opacity: 0, maxWidth: '0px', marginLeft: '-8px' },
|
||||||
|
],
|
||||||
|
{ duration: 220, easing: 'ease-out' },
|
||||||
|
);
|
||||||
|
play(
|
||||||
|
labelOf(btns[to]),
|
||||||
|
[
|
||||||
|
{ opacity: 0, filter: 'blur(4px)' },
|
||||||
|
{ opacity: 1, filter: 'none' },
|
||||||
|
],
|
||||||
|
{ duration: 280, delay: 70, easing: EASE_OUT, fill: 'backwards' },
|
||||||
|
);
|
||||||
|
// The stretch: the leading edge follows the quick spring, the trailing edge the smooth one.
|
||||||
|
const right = to > from;
|
||||||
|
const lead = calm() ? SMOOTH : LEAD;
|
||||||
|
const t0 = performance.now();
|
||||||
|
const end = Math.max(SMOOTH.duration, lead.duration);
|
||||||
|
const eL = right ? SMOOTH : lead;
|
||||||
|
const eR = right ? lead : SMOOTH;
|
||||||
|
cancelAnimationFrame(raf);
|
||||||
|
const step = () => {
|
||||||
|
const t = calm() ? end : performance.now() - t0;
|
||||||
|
const e = edges();
|
||||||
|
if (!e) {
|
||||||
|
raf = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pill.style.left = `${l0 + (e[0] - l0) * eL.at(t)}px`;
|
||||||
|
pill.style.right = `${r0 + (e[1] - r0) * eR.at(t)}px`;
|
||||||
|
raf = t < end ? requestAnimationFrame(step) : 0;
|
||||||
|
if (!raf) placePill();
|
||||||
|
};
|
||||||
|
raf = requestAnimationFrame(step);
|
||||||
|
onPick(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
mark();
|
||||||
|
new ResizeObserver(() => {
|
||||||
|
if (!raf) placePill();
|
||||||
|
}).observe(el);
|
||||||
|
return {
|
||||||
|
el,
|
||||||
|
sync(v) {
|
||||||
|
if (v === value) return;
|
||||||
|
value = v;
|
||||||
|
mark();
|
||||||
|
placePill();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,477 @@
|
|||||||
|
// The sheet: one drawer floating at the bottom of the screen, on phones and
|
||||||
|
// desktops alike. It holds a stack of views (go/back), glides to each view's
|
||||||
|
// height, widens on a desktop for a dense QR code until the code gets its
|
||||||
|
// pixels, pins a view's own buttons beside ×, and closes by ×, the scrim, a
|
||||||
|
// pull down on its header, Escape, or the phone's back button (it is a history
|
||||||
|
// entry). Views are built by the flows; this module only moves them.
|
||||||
|
|
||||||
|
import { h, ic } from '../dom';
|
||||||
|
import { BOUNCY, DRAWER, EASE_IN, EASE_OUT, SMOOTH, SOFT, dismisses, play, rubber } from '../motion';
|
||||||
|
import { closeMenu } from './menu';
|
||||||
|
|
||||||
|
/** A view: its root, and what the sheet reads from it. */
|
||||||
|
export interface View {
|
||||||
|
el: HTMLElement;
|
||||||
|
/** The sheet's accessible name while this view shows (its title). */
|
||||||
|
label: string;
|
||||||
|
/** A question (Remove, Reconnect): an alert dialog. */
|
||||||
|
asks?: boolean;
|
||||||
|
/** Its own buttons, pinned beside × while it shows. */
|
||||||
|
acts?: HTMLElement | null;
|
||||||
|
}
|
||||||
|
export type ViewFactory = () => View;
|
||||||
|
|
||||||
|
let root: HTMLElement;
|
||||||
|
let scrim: HTMLElement;
|
||||||
|
let sheetEl: HTMLElement;
|
||||||
|
let closeBtn: HTMLElement;
|
||||||
|
let actsEl: HTMLElement;
|
||||||
|
let scroller: HTMLElement;
|
||||||
|
let vp: HTMLElement;
|
||||||
|
|
||||||
|
let stack: ViewFactory[] = [];
|
||||||
|
let closed: (() => void) | null = null;
|
||||||
|
let left: (() => void) | null = null;
|
||||||
|
let ownsHistory = false;
|
||||||
|
let returnFocus: HTMLElement | null = null;
|
||||||
|
|
||||||
|
export const sheetOpen = () => !!root?.classList.contains('open');
|
||||||
|
|
||||||
|
/* ---------- width: a dense code scans from a screen at about 3 px a module ---------- */
|
||||||
|
|
||||||
|
const SHEET_W = 400;
|
||||||
|
const QR_PAD = 80;
|
||||||
|
// 3.2 px a module: 6–7 device pixels on a retina screen, still a sure read for a phone camera.
|
||||||
|
const PX_PER_MODULE = 3.2;
|
||||||
|
/** A computer, or a tablet held wide: the sheet is a dialog in the middle (sheet.css), and may widen for a dense code. */
|
||||||
|
const wide = () => matchMedia('(min-width: 760px)').matches;
|
||||||
|
let sheetW = SHEET_W;
|
||||||
|
let shownQr: HTMLElement | null = null;
|
||||||
|
|
||||||
|
export interface WidthPlan {
|
||||||
|
from: number;
|
||||||
|
want: number;
|
||||||
|
reveal: HTMLElement | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The width the sheet needs now, set at once so whatever measures the new
|
||||||
|
* layout (an accordion, the height glide) measures it at the final width; the
|
||||||
|
* plan then animates there on the same spring (`startWidth`), so nothing snaps.
|
||||||
|
*/
|
||||||
|
export function planWidth(): WidthPlan | null {
|
||||||
|
if (!root || !sheetOpen()) return null;
|
||||||
|
if (!wide()) {
|
||||||
|
if (sheetEl.style.maxWidth) sheetEl.style.maxWidth = '';
|
||||||
|
sheetW = SHEET_W;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const qr = [...vp.querySelectorAll<HTMLElement>('.qrbox.dense')].find((b) => {
|
||||||
|
const row = b.closest('.acc-row');
|
||||||
|
return b.offsetWidth && (!row || row.classList.contains('open')) && !b.closest('.leaving');
|
||||||
|
});
|
||||||
|
let want = SHEET_W;
|
||||||
|
if (qr) {
|
||||||
|
// The code itself fits the screen; the rest of the sheet may scroll around it.
|
||||||
|
const room = Math.min(innerWidth - 32 - QR_PAD, innerHeight - 120);
|
||||||
|
want = Math.max(SHEET_W, Math.round(Math.min(+(qr.dataset.mods ?? 0) * PX_PER_MODULE, room) + QR_PAD));
|
||||||
|
}
|
||||||
|
const reveal = qr && qr !== shownQr ? qr : null;
|
||||||
|
shownQr = qr ?? null;
|
||||||
|
if (Math.abs(want - sheetW) < 8) return reveal ? { from: want, want, reveal } : null;
|
||||||
|
const from = parseFloat(getComputedStyle(sheetEl).maxWidth) || sheetW;
|
||||||
|
sheetW = want;
|
||||||
|
sheetEl
|
||||||
|
.getAnimations()
|
||||||
|
.filter((a) => (a.effect as KeyframeEffect | null)?.getKeyframes().some((k) => 'maxWidth' in k))
|
||||||
|
.forEach((a) => a.cancel());
|
||||||
|
sheetEl.style.maxWidth = `${want}px`;
|
||||||
|
return { from, want, reveal };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function startWidth(p: WidthPlan | null) {
|
||||||
|
if (!p) return;
|
||||||
|
if (Math.abs(p.from - p.want) > 1)
|
||||||
|
play(sheetEl, [{ maxWidth: `${p.from}px` }, { maxWidth: `${p.want}px` }], { duration: SMOOTH.duration, easing: SMOOTH.easing });
|
||||||
|
// The code has to be on screen whole: scroll it into view once the sheet has its size.
|
||||||
|
const q = p.reveal;
|
||||||
|
if (q)
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!q.isConnected) return;
|
||||||
|
const a = scroller.getBoundingClientRect();
|
||||||
|
const b = q.getBoundingClientRect();
|
||||||
|
const d = b.bottom > a.bottom - 16 ? b.bottom - a.bottom + 16 : b.top < a.top + 16 ? b.top - a.top - 16 : 0;
|
||||||
|
if (d) scroller.scrollBy({ top: d, behavior: 'smooth' });
|
||||||
|
}, BOUNCY.duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- the drawer ---------- */
|
||||||
|
|
||||||
|
function build() {
|
||||||
|
closeBtn = h('button', { type: 'button', class: 'knob x', 'aria-label': 'Close', onclick: () => closeSheet() }, ic('x'));
|
||||||
|
actsEl = h('div', { class: 'sheet-acts' });
|
||||||
|
vp = h('div', { class: 'vp' });
|
||||||
|
scroller = h('div', { class: 'sheet-scroll' }, vp);
|
||||||
|
sheetEl = h('div', { class: 'sheet', role: 'dialog', 'aria-modal': 'true' }, closeBtn, actsEl, scroller);
|
||||||
|
scrim = h('div', { class: 'scrim', onclick: () => closeSheet() });
|
||||||
|
root = h('div', { class: 'sheet-root', 'aria-hidden': 'true' }, scrim, sheetEl);
|
||||||
|
document.body.appendChild(root);
|
||||||
|
new ResizeObserver(() => startWidth(planWidth())).observe(vp);
|
||||||
|
pullToClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
function label(v: View) {
|
||||||
|
sheetEl.setAttribute('aria-label', v.label);
|
||||||
|
sheetEl.setAttribute('role', v.asks ? 'alertdialog' : 'dialog');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The view being left (a new one, or the sheet closing) lets go of what it holds. */
|
||||||
|
function leave() {
|
||||||
|
const f = left;
|
||||||
|
left = null;
|
||||||
|
f?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What the current view holds and must stop (a poll): called when it is left. */
|
||||||
|
export function onLeave(fn: () => void) {
|
||||||
|
left = fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** After this sheet closes (once). */
|
||||||
|
export function onClosed(fn: () => void) {
|
||||||
|
closed = fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openSheet(factory: ViewFactory) {
|
||||||
|
if (!root) build();
|
||||||
|
closeMenu(true);
|
||||||
|
leave();
|
||||||
|
if (sheetOpen()) {
|
||||||
|
// Already open: the new flow takes the place of the old one, history and all.
|
||||||
|
stack = [factory];
|
||||||
|
swapView(factory());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||||
|
stack = [factory];
|
||||||
|
closed = null;
|
||||||
|
sheetW = SHEET_W;
|
||||||
|
shownQr = null;
|
||||||
|
sheetEl.style.maxWidth = '';
|
||||||
|
sheetEl.classList.remove('arrived');
|
||||||
|
const v = factory();
|
||||||
|
vp.replaceChildren(v.el);
|
||||||
|
setActs(v, false);
|
||||||
|
label(v);
|
||||||
|
root.classList.add('open');
|
||||||
|
root.setAttribute('aria-hidden', 'false');
|
||||||
|
document.body.classList.add('locked');
|
||||||
|
const p0 = planWidth();
|
||||||
|
if (p0) startWidth({ ...p0, from: p0.want });
|
||||||
|
sheetEl.getAnimations().forEach((a) => a.cancel());
|
||||||
|
scrim.getAnimations().forEach((a) => a.cancel());
|
||||||
|
sheetEl.style.transform = '';
|
||||||
|
// A dialog comes up from its centre the way a ⋯ menu pops (menu.ts), on a softer spring; the drawer rises from the bottom edge.
|
||||||
|
if (wide())
|
||||||
|
play(
|
||||||
|
sheetEl,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: 'scale(.9)', filter: 'blur(4px)' },
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
],
|
||||||
|
{ duration: SOFT.duration, easing: SOFT.easing },
|
||||||
|
);
|
||||||
|
else play(sheetEl, [{ transform: 'translateY(calc(100% + 40px))' }, { transform: 'none' }], { duration: 500, easing: DRAWER });
|
||||||
|
// The dim behind keeps time with the sheet: with the dialog's pop on a computer, with the drawer's rise on a phone.
|
||||||
|
play(
|
||||||
|
scrim,
|
||||||
|
[{ opacity: 0 }, { opacity: 1 }],
|
||||||
|
wide() ? { duration: SOFT.duration, easing: SOFT.easing } : { duration: 420, easing: 'ease-out' },
|
||||||
|
);
|
||||||
|
if (!ownsHistory) {
|
||||||
|
try {
|
||||||
|
history.pushState({ sheet: true }, '');
|
||||||
|
ownsHistory = true;
|
||||||
|
} catch {
|
||||||
|
/* no history */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** `now`: gone at once (Escape: what the keyboard does never animates). */
|
||||||
|
export function closeSheet(now = false) {
|
||||||
|
if (!sheetOpen() || root.dataset.closing) return;
|
||||||
|
leave();
|
||||||
|
if (ownsHistory) {
|
||||||
|
ownsHistory = false;
|
||||||
|
history.back();
|
||||||
|
}
|
||||||
|
document.body.classList.remove('locked');
|
||||||
|
const done = () => {
|
||||||
|
root.classList.remove('open');
|
||||||
|
root.setAttribute('aria-hidden', 'true');
|
||||||
|
delete root.dataset.closing;
|
||||||
|
sheetEl.style.transform = '';
|
||||||
|
scrim.style.opacity = '';
|
||||||
|
sheetEl.getAnimations().forEach((a) => a.cancel());
|
||||||
|
scrim.getAnimations().forEach((a) => a.cancel());
|
||||||
|
vp.getAnimations().forEach((a) => a.cancel());
|
||||||
|
vp.replaceChildren();
|
||||||
|
actsEl.replaceChildren();
|
||||||
|
sheetEl.classList.remove('arrived');
|
||||||
|
sheetEl.style.maxWidth = '';
|
||||||
|
sheetW = SHEET_W;
|
||||||
|
stack = [];
|
||||||
|
if (returnFocus?.isConnected) returnFocus.focus({ preventScroll: true });
|
||||||
|
returnFocus = null;
|
||||||
|
const f = closed;
|
||||||
|
closed = null;
|
||||||
|
f?.();
|
||||||
|
};
|
||||||
|
if (now) return done();
|
||||||
|
root.dataset.closing = '1';
|
||||||
|
const from = getComputedStyle(sheetEl).transform;
|
||||||
|
sheetEl.getAnimations().forEach((a) => a.cancel());
|
||||||
|
play(
|
||||||
|
scrim,
|
||||||
|
[{ opacity: getComputedStyle(scrim).opacity }, { opacity: 0 }],
|
||||||
|
wide() ? { duration: 120, easing: EASE_IN, fill: 'forwards' } : { duration: 320, easing: 'ease-out', fill: 'forwards' },
|
||||||
|
);
|
||||||
|
const at = from === 'none' ? 'none' : from;
|
||||||
|
// A dialog goes the way a ⋯ menu does, quick and soft into its centre; the drawer goes down past the edge.
|
||||||
|
play(
|
||||||
|
sheetEl,
|
||||||
|
wide()
|
||||||
|
? [
|
||||||
|
{ opacity: 1, transform: at, filter: 'blur(0px)' },
|
||||||
|
{ opacity: 0, transform: `${at === 'none' ? '' : at} scale(.96)`.trim(), filter: 'blur(3px)' },
|
||||||
|
]
|
||||||
|
: [{ transform: at }, { transform: 'translateY(calc(100% + 40px))' }],
|
||||||
|
wide() ? { duration: 120, easing: EASE_IN, fill: 'forwards' } : { duration: 420, easing: DRAWER, fill: 'forwards' },
|
||||||
|
).onfinish = done;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The phone's back button closes the sheet instead of leaving the page.
|
||||||
|
addEventListener('popstate', () => {
|
||||||
|
if (!sheetOpen()) return;
|
||||||
|
ownsHistory = false;
|
||||||
|
closeSheet();
|
||||||
|
});
|
||||||
|
|
||||||
|
/** A view's own buttons beside ×: pinned with it while the sheet scrolls, they come and go with the view. */
|
||||||
|
function setActs(v: View, anim = true) {
|
||||||
|
const neu = v.acts ?? null;
|
||||||
|
const old = actsEl.firstElementChild as HTMLElement | null;
|
||||||
|
if (neu === old) return;
|
||||||
|
// No motion asked, or the same buttons for a rebuilt view: swapped in place.
|
||||||
|
if (!anim || (old && neu && old.dataset.key === neu.dataset.key)) return actsEl.replaceChildren(...(neu ? [neu] : []));
|
||||||
|
if (old) {
|
||||||
|
Object.assign(old.style, { position: 'absolute', right: '0', top: '0', pointerEvents: 'none' });
|
||||||
|
play(
|
||||||
|
old,
|
||||||
|
[
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
{ opacity: 0, transform: 'scale(.9)', filter: 'blur(3px)' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: 180,
|
||||||
|
easing: 'cubic-bezier(.2,0,0,1)',
|
||||||
|
fill: 'forwards',
|
||||||
|
},
|
||||||
|
).onfinish = () => old.remove();
|
||||||
|
}
|
||||||
|
if (neu) {
|
||||||
|
actsEl.appendChild(neu);
|
||||||
|
play(
|
||||||
|
neu,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: 'scale(.9)', filter: 'blur(3px)' },
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: 260,
|
||||||
|
delay: 110,
|
||||||
|
easing: 'cubic-bezier(.2,0,0,1)',
|
||||||
|
fill: 'backwards',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Another view in the open sheet: the old one fades out over the new one, the sheet glides to its height. */
|
||||||
|
function swapView(v: View) {
|
||||||
|
label(v);
|
||||||
|
setActs(v);
|
||||||
|
sheetEl.classList.remove('arrived');
|
||||||
|
const old = [...vp.children] as HTMLElement[];
|
||||||
|
const h0 = vp.getBoundingClientRect().height;
|
||||||
|
vp.getAnimations().forEach((a) => a.cancel());
|
||||||
|
old.forEach((o) => {
|
||||||
|
o.classList.add('leaving');
|
||||||
|
Object.assign(o.style, { position: 'absolute', left: '0', right: '0', top: '0', pointerEvents: 'none' });
|
||||||
|
o.inert = true;
|
||||||
|
});
|
||||||
|
vp.appendChild(v.el);
|
||||||
|
// A tap that lands where the new view's button appears must not press it.
|
||||||
|
v.el.style.pointerEvents = 'none';
|
||||||
|
setTimeout(() => (v.el.style.pointerEvents = ''), 320);
|
||||||
|
scroller.scrollTop = 0;
|
||||||
|
const plan = planWidth();
|
||||||
|
const h1 = v.el.getBoundingClientRect().height;
|
||||||
|
play(vp, [{ height: `${h0}px` }, { height: `${h1}px` }], { duration: 360, easing: 'cubic-bezier(.25,1,.5,1)' });
|
||||||
|
startWidth(plan);
|
||||||
|
old.forEach(
|
||||||
|
(o) =>
|
||||||
|
(play(
|
||||||
|
o,
|
||||||
|
[
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
{ opacity: 0, transform: 'scale(.96)', filter: 'blur(2px)' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: 200,
|
||||||
|
easing: 'cubic-bezier(.2,0,0,1)',
|
||||||
|
fill: 'forwards',
|
||||||
|
},
|
||||||
|
).onfinish = () => o.remove()),
|
||||||
|
);
|
||||||
|
play(
|
||||||
|
v.el,
|
||||||
|
[
|
||||||
|
{ opacity: 0, transform: 'scale(.96)', filter: 'blur(4px)' },
|
||||||
|
{ opacity: 1, transform: 'none', filter: 'none' },
|
||||||
|
],
|
||||||
|
{
|
||||||
|
duration: 280,
|
||||||
|
delay: 110,
|
||||||
|
easing: 'cubic-bezier(.2,0,0,1)',
|
||||||
|
fill: 'backwards',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Further into a flow (Add → Open on the device). */
|
||||||
|
export function go(factory: ViewFactory) {
|
||||||
|
if (!sheetOpen()) return openSheet(factory);
|
||||||
|
leave();
|
||||||
|
stack.push(factory);
|
||||||
|
swapView(factory());
|
||||||
|
}
|
||||||
|
|
||||||
|
export function back() {
|
||||||
|
if (stack.length < 2) return;
|
||||||
|
leave();
|
||||||
|
stack.pop();
|
||||||
|
swapView(stack[stack.length - 1]());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content inside the open sheet changed: it glides to its new height, what
|
||||||
|
* stayed but moved (a block above it grew or shrank) glides to its new place,
|
||||||
|
* the changed blocks come into focus.
|
||||||
|
*/
|
||||||
|
export function glide(change: () => void, focus: (Element | null | undefined)[] = []) {
|
||||||
|
if (!sheetOpen()) return change();
|
||||||
|
const h0 = vp.getBoundingClientRect().height;
|
||||||
|
vp.getAnimations().forEach((a) => a.cancel());
|
||||||
|
const view = vp.lastElementChild;
|
||||||
|
const was = new Map<Element, DOMRect>();
|
||||||
|
view?.querySelectorAll('*').forEach((e) => {
|
||||||
|
if (!(e instanceof SVGElement) || e instanceof SVGSVGElement) was.set(e, e.getBoundingClientRect());
|
||||||
|
});
|
||||||
|
change();
|
||||||
|
const plan = planWidth();
|
||||||
|
const h1 = vp.getBoundingClientRect().height;
|
||||||
|
if (Math.abs(h1 - h0) > 1) play(vp, [{ height: `${h0}px` }, { height: `${h1}px` }], { duration: SMOOTH.duration, easing: SMOOTH.easing });
|
||||||
|
startWidth(plan);
|
||||||
|
// Measured with the sheet back at its old size (its glides have just started): only what moved inside it moves.
|
||||||
|
const moved = new Set<Element>();
|
||||||
|
for (const [e, r] of was) {
|
||||||
|
if (!e.isConnected || !r.width || !r.height) continue;
|
||||||
|
const n = e.getBoundingClientRect();
|
||||||
|
if (!n.width || !n.height) continue;
|
||||||
|
const dx = r.left - n.left;
|
||||||
|
const dy = r.top - n.top;
|
||||||
|
if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5) continue;
|
||||||
|
moved.add(e);
|
||||||
|
// Once, on the outermost that moved: what it holds moves with it.
|
||||||
|
let p = e.parentElement;
|
||||||
|
while (p && p !== view && !moved.has(p)) p = p.parentElement;
|
||||||
|
if (p && p !== view) continue;
|
||||||
|
play(e, [{ transform: `translate(${dx}px, ${dy}px)` }, { transform: 'none' }], { duration: SMOOTH.duration, easing: SMOOTH.easing });
|
||||||
|
}
|
||||||
|
for (const el of focus)
|
||||||
|
if (el)
|
||||||
|
play(
|
||||||
|
el,
|
||||||
|
[
|
||||||
|
{ opacity: 0, filter: 'blur(4px)' },
|
||||||
|
{ opacity: 1, filter: 'none' },
|
||||||
|
],
|
||||||
|
{ duration: 280, easing: EASE_OUT },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The view's job is done (a device connected): ×, and the view's own buttons, step away. */
|
||||||
|
export function settle() {
|
||||||
|
sheetEl?.classList.add('arrived');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The sheet scrolls back to the top (a device connected under a scrolled sheet). */
|
||||||
|
export const scrollTop = () => scroller?.scrollTo({ top: 0, behavior: 'smooth' });
|
||||||
|
|
||||||
|
/** Is this element in the sheet that shows now (not one being swapped out)? */
|
||||||
|
export const showing = (el: Element) => sheetOpen() && vp.contains(el) && !el.closest('.leaving');
|
||||||
|
|
||||||
|
/* ---------- pull down by the header to close ---------- */
|
||||||
|
|
||||||
|
function pullToClose() {
|
||||||
|
let drag: { y: number; t: number; dy: number; v: number } | null = null;
|
||||||
|
sheetEl.addEventListener('pointerdown', (e) => {
|
||||||
|
const t = e.target as Element;
|
||||||
|
if (!t.closest('.vhead') || t.closest('button, a, input')) return;
|
||||||
|
drag = { y: e.clientY, t: performance.now(), dy: 0, v: 0 };
|
||||||
|
sheetEl.setPointerCapture(e.pointerId);
|
||||||
|
});
|
||||||
|
sheetEl.addEventListener('pointermove', (e) => {
|
||||||
|
if (!drag) return;
|
||||||
|
const raw = e.clientY - drag.y;
|
||||||
|
const t = performance.now();
|
||||||
|
// Down follows the finger; up resists, more the further it goes.
|
||||||
|
const dy = raw > 0 ? raw : -rubber(-raw, sheetEl.offsetHeight);
|
||||||
|
drag.v = (dy - drag.dy) / Math.max(1, t - drag.t);
|
||||||
|
drag.dy = dy;
|
||||||
|
drag.t = t;
|
||||||
|
sheetEl.style.transform = `translateY(${dy}px)`;
|
||||||
|
scrim.style.opacity = String(Math.max(0, 1 - Math.max(0, dy) / 420));
|
||||||
|
});
|
||||||
|
const end = () => {
|
||||||
|
if (!drag) return;
|
||||||
|
const { dy, v } = drag;
|
||||||
|
drag = null;
|
||||||
|
if (dismisses(dy, v, sheetEl.offsetHeight)) return closeSheet();
|
||||||
|
const from = sheetEl.style.transform;
|
||||||
|
sheetEl.style.transform = '';
|
||||||
|
scrim.style.opacity = '';
|
||||||
|
if (dy !== 0) play(sheetEl, [{ transform: from }, { transform: 'none' }], { duration: SMOOTH.duration, easing: SMOOTH.easing });
|
||||||
|
};
|
||||||
|
sheetEl.addEventListener('pointerup', end);
|
||||||
|
sheetEl.addEventListener('pointercancel', end);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- the parts every view is made of ---------- */
|
||||||
|
|
||||||
|
/** A view's head: its title (and Back, inside a flow). */
|
||||||
|
export function head(title: string, o: { back?: boolean; acts?: boolean } = {}): HTMLElement {
|
||||||
|
return h(
|
||||||
|
'div',
|
||||||
|
{ class: `vhead${o.back ? ' center' : ''}${o.acts ? ' with-acts' : ''}` },
|
||||||
|
o.back ? h('button', { type: 'button', class: 'knob back', 'aria-label': 'Back', onclick: back }, ic('chevron')) : null,
|
||||||
|
h('h2', {}, title),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The line under a view's title. */
|
||||||
|
export const sub = (text: string) => h('p', { class: 'vsub' }, text);
|
||||||
|
/** A small line of help. */
|
||||||
|
export const hint = (...kids: (Node | string | null)[]) => h('p', { class: 'hint' }, ...kids);
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
// The set-up sheets' "waiting for the first connection" card: the way from
|
|
||||||
// the device (its icon; the sheet's title names it) to the home server, a light
|
|
||||||
// running along its dots while the page waits; the dots fill green when it connects.
|
|
||||||
// It only draws and switches its states; main.ts (watchFirstConnection)
|
|
||||||
// decides when, and what leaves around it. A live region: the changes are read out.
|
|
||||||
|
|
||||||
import type { Kind } from '../shared/types';
|
|
||||||
import { h, ic } from './dom';
|
|
||||||
import { grow, replay } from './motion';
|
|
||||||
|
|
||||||
export interface Way {
|
|
||||||
el: HTMLElement;
|
|
||||||
/** The first connection arrived. */
|
|
||||||
connected(): void;
|
|
||||||
/** The page stopped asking (ten minutes): say so instead of waiting on forever. */
|
|
||||||
gaveUp(): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function waitPath(kind: Kind): Way {
|
|
||||||
const title = h('span', { class: 'strong s' }, 'Waiting for the connection');
|
|
||||||
// Nothing to add while it waits: the line comes with "You're all set" or the give-up.
|
|
||||||
const sub = h('span', { class: 'faint s' });
|
|
||||||
// The router end: the server's icon, as on the admin's map.
|
|
||||||
const home = h('span', { class: 'way-end home' }, ic('server'));
|
|
||||||
const el = h(
|
|
||||||
'div',
|
|
||||||
{ class: 'way', role: 'status', 'aria-live': 'polite' },
|
|
||||||
h(
|
|
||||||
'div',
|
|
||||||
{ class: 'way-row' },
|
|
||||||
h('span', { class: 'way-end' }, ic(kind)),
|
|
||||||
h('span', { class: 'way-track' }, h('span', { class: 'way-glow' }, h('i')), h('span', { class: 'way-fill' })),
|
|
||||||
home,
|
|
||||||
),
|
|
||||||
h('div', { class: 'way-text' }, title, sub),
|
|
||||||
);
|
|
||||||
const say = (t: string, s: string) => {
|
|
||||||
if (title.textContent !== t) {
|
|
||||||
title.textContent = t;
|
|
||||||
replay(title, 'swap');
|
|
||||||
}
|
|
||||||
if (sub.textContent === s) return;
|
|
||||||
// The line under the title only appears now: it opens rather than pushing the card.
|
|
||||||
const opens = !sub.textContent;
|
|
||||||
sub.textContent = s;
|
|
||||||
if (opens) grow(sub);
|
|
||||||
else replay(sub, 'swap');
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
el,
|
|
||||||
connected: () => {
|
|
||||||
el.classList.add('done');
|
|
||||||
say('Connected', 'You’re all set.');
|
|
||||||
},
|
|
||||||
gaveUp: () => {
|
|
||||||
el.classList.add('stopped');
|
|
||||||
say('No connection yet', 'Close this and open it again to keep checking.');
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -4,15 +4,16 @@
|
|||||||
// no mark and level L: every step up in correction adds modules, and a dense
|
// no mark and level L: every step up in correction adds modules, and a dense
|
||||||
// code fails on the camera before it fails on damage.
|
// code fails on the camera before it fails on damage.
|
||||||
//
|
//
|
||||||
// Two looks. `plain`: black squares on white in one path (the admin's cards and
|
// Three looks. `plain`: black squares on white in one path (the admin's cards and
|
||||||
// the invite image). `night`: light dots on black with rounded finder eyes (the
|
// the invite image). `night`: light dots on black with rounded finder eyes (the
|
||||||
// portal). Light dots on dark lose a dense code to blur sooner, so a dense night
|
// portal on a dark theme). `day`: the same dots and eyes, dark on white (the
|
||||||
// code gets fuller dots: checked with a QR reader, r 0.42 lost a 1.5 KB key at
|
// portal on a light theme). Light dots on dark lose a dense code to blur sooner,
|
||||||
// 1.2 px of blur where r 0.48 read as well as the plain code.
|
// so a dense round code gets fuller dots: checked with a QR reader, r 0.42 lost
|
||||||
|
// a 1.5 KB key at 1.2 px of blur where r 0.48 read as well as the plain code.
|
||||||
|
|
||||||
import qrcode from 'qrcode-generator';
|
import qrcode from 'qrcode-generator';
|
||||||
|
|
||||||
export type QrLook = 'plain' | 'night';
|
export type QrLook = 'plain' | 'night' | 'day';
|
||||||
|
|
||||||
/** The icon's dome and bar (64×64 viewBox, see portal/icon.svg), in a colour. */
|
/** The icon's dome and bar (64×64 viewBox, see portal/icon.svg), in a colour. */
|
||||||
const mark = (fill: string) =>
|
const mark = (fill: string) =>
|
||||||
@@ -20,6 +21,8 @@ const mark = (fill: string) =>
|
|||||||
|
|
||||||
const NIGHT_BG = '#0a0a0a';
|
const NIGHT_BG = '#0a0a0a';
|
||||||
const NIGHT_FG = '#f2f2f2';
|
const NIGHT_FG = '#f2f2f2';
|
||||||
|
/** The round looks' card and dots: light on black at night, dark on white by day. */
|
||||||
|
const ROUND: Record<'night' | 'day', [bg: string, fg: string]> = { night: [NIGHT_BG, NIGHT_FG], day: ['#ffffff', NIGHT_BG] };
|
||||||
|
|
||||||
/** Long content: fewer modules matter more than the mark. */
|
/** Long content: fewer modules matter more than the mark. */
|
||||||
export const denseQr = (text: string): boolean => text.length > 300;
|
export const denseQr = (text: string): boolean => text.length > 300;
|
||||||
@@ -35,7 +38,9 @@ function rrect(x: number, y: number, w: number, h: number, r: number): string {
|
|||||||
|
|
||||||
export function qrSvg(text: string, margin = 3, logo = true, look: QrLook = 'plain'): string {
|
export function qrSvg(text: string, margin = 3, logo = true, look: QrLook = 'plain'): string {
|
||||||
const dense = denseQr(text);
|
const dense = denseQr(text);
|
||||||
const night = look === 'night';
|
// The night and day looks draw the same round dots and eyes; only their colours differ.
|
||||||
|
const round = look !== 'plain';
|
||||||
|
const [bg, fg] = round ? ROUND[look] : ['#fff', '#000'];
|
||||||
const qr = qrcode(0, dense ? 'L' : 'H');
|
const qr = qrcode(0, dense ? 'L' : 'H');
|
||||||
qr.addData(text, 'Byte');
|
qr.addData(text, 'Byte');
|
||||||
qr.make();
|
qr.make();
|
||||||
@@ -47,10 +52,10 @@ export function qrSvg(text: string, margin = 3, logo = true, look: QrLook = 'pla
|
|||||||
const h0 = (n - hole) / 2,
|
const h0 = (n - hole) / 2,
|
||||||
h1 = h0 + hole;
|
h1 = h0 + hole;
|
||||||
const inHole = (x: number, y: number) => hole > 0 && x >= h0 && x < h1 && y >= h0 && y < h1;
|
const inHole = (x: number, y: number) => hole > 0 && x >= h0 && x < h1 && y >= h0 && y < h1;
|
||||||
// The three finder patterns, drawn whole as eyes in the night look.
|
// The three finder patterns, drawn whole as eyes in the round looks.
|
||||||
const inEye = (x: number, y: number) => night && ((y < 7 && x < 7) || (y < 7 && x >= n - 7) || (y >= n - 7 && x < 7));
|
const inEye = (x: number, y: number) => round && ((y < 7 && x < 7) || (y < 7 && x >= n - 7) || (y >= n - 7 && x < 7));
|
||||||
let d = '';
|
let d = '';
|
||||||
if (night) {
|
if (round) {
|
||||||
const r = dense ? 0.48 : 0.42;
|
const r = dense ? 0.48 : 0.42;
|
||||||
for (let y = 0; y < n; y++)
|
for (let y = 0; y < n; y++)
|
||||||
for (let x = 0; x < n; x++)
|
for (let x = 0; x < n; x++)
|
||||||
@@ -72,7 +77,7 @@ export function qrSvg(text: string, margin = 3, logo = true, look: QrLook = 'pla
|
|||||||
}
|
}
|
||||||
// Each eye: a 7×7 ring around a gap and a 3×3 pupil, one even-odd path.
|
// Each eye: a 7×7 ring around a gap and a 3×3 pupil, one even-odd path.
|
||||||
let eyes = '';
|
let eyes = '';
|
||||||
if (night)
|
if (round)
|
||||||
for (const [x, y] of [
|
for (const [x, y] of [
|
||||||
[margin, margin],
|
[margin, margin],
|
||||||
[margin + n - 7, margin],
|
[margin + n - 7, margin],
|
||||||
@@ -85,12 +90,12 @@ export function qrSvg(text: string, margin = 3, logo = true, look: QrLook = 'pla
|
|||||||
s = hole - pad * 2,
|
s = hole - pad * 2,
|
||||||
o = h0 + margin + pad;
|
o = h0 + margin + pad;
|
||||||
logoTile =
|
logoTile =
|
||||||
`<rect x="${o}" y="${o}" width="${s}" height="${s}" rx="${s * (night ? 0.28 : 0.25)}" fill="${night ? NIGHT_FG : '#0a0a0a'}"/>` +
|
`<rect x="${o}" y="${o}" width="${s}" height="${s}" rx="${s * (round ? 0.28 : 0.25)}" fill="${round ? fg : '#0a0a0a'}"/>` +
|
||||||
`<g transform="translate(${o} ${o}) scale(${s / 64})">${mark(night ? NIGHT_BG : '#fff')}</g>`;
|
`<g transform="translate(${o} ${o}) scale(${s / 64})">${mark(round ? bg : '#fff')}</g>`;
|
||||||
}
|
}
|
||||||
const open = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" role="img" aria-label="QR code">`;
|
const open = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" role="img" aria-label="QR code">`;
|
||||||
return night
|
return round
|
||||||
? `${open}<rect width="${size}" height="${size}" fill="${NIGHT_BG}"/><path d="${d}" fill="${NIGHT_FG}"/>` +
|
? `${open}<rect width="${size}" height="${size}" fill="${bg}"/><path d="${d}" fill="${fg}"/>` +
|
||||||
`<path d="${eyes}" fill="${NIGHT_FG}" fill-rule="evenodd"/>${logoTile}</svg>`
|
`<path d="${eyes}" fill="${fg}" fill-rule="evenodd"/>${logoTile}</svg>`
|
||||||
: `${open}<rect width="${size}" height="${size}" fill="#fff"/><path d="${d}" fill="#000" shape-rendering="crispEdges"/>${logoTile}</svg>`;
|
: `${open}<rect width="${size}" height="${size}" fill="${bg}"/><path d="${d}" fill="${fg}" shape-rendering="crispEdges"/>${logoTile}</svg>`;
|
||||||
}
|
}
|
||||||
@@ -52,6 +52,8 @@ export interface Person {
|
|||||||
online: number;
|
online: number;
|
||||||
last_seen: number;
|
last_seen: number;
|
||||||
devices: Device[];
|
devices: Device[];
|
||||||
|
/** Daily totals (rx+tx) from the 1st of this month to today, oldest first; portal only. */
|
||||||
|
month_days?: number[];
|
||||||
/** Throughput, one point a minute (last 15): [ts, rx, tx] in bytes/s (rx = from devices); admin only. */
|
/** Throughput, one point a minute (last 15): [ts, rx, tx] in bytes/s (rx = from devices); admin only. */
|
||||||
rate?: [number, number, number][];
|
rate?: [number, number, number][];
|
||||||
// admin only (the personal link itself comes from person_links, not the status)
|
// admin only (the personal link itself comes from person_links, not the status)
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { calendar, clockOf, hoursFor, minuteAt, minuteOf, monthOf, stretches } from '../src/portal/days';
|
||||||
|
|
||||||
|
describe('days', () => {
|
||||||
|
it('lays the weeks to the end out Monday first, one cell a day', () => {
|
||||||
|
// Mon 19 Oct 2026 to Fri 23 Oct: one week.
|
||||||
|
const c = calendar('2026-10-19', '2026-10-23')!;
|
||||||
|
expect(c).toHaveLength(7);
|
||||||
|
expect(c.map((x) => x.kind)).toEqual(['today', 'left', 'left', 'left', 'end', 'after', 'after']);
|
||||||
|
// From a Wednesday: Monday and Tuesday are gone.
|
||||||
|
const w = calendar('2026-10-21', '2026-10-21')!;
|
||||||
|
expect(w.map((x) => x.kind).slice(0, 3)).toEqual(['past', 'past', 'today']);
|
||||||
|
expect(w[2].day).toBe('2026-10-21');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gives up on a calendar past ten weeks', () => {
|
||||||
|
expect(calendar('2026-10-19', '2026-12-27')).not.toBeNull();
|
||||||
|
expect(calendar('2026-10-19', '2027-03-01')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reads and writes clock times', () => {
|
||||||
|
expect(minuteOf('08:30')).toBe(510);
|
||||||
|
expect(minuteOf('8:05')).toBe(485);
|
||||||
|
expect(minuteOf('24:00')).toBeNull();
|
||||||
|
expect(clockOf(510)).toBe('08:30');
|
||||||
|
expect(clockOf(-30)).toBe('23:30');
|
||||||
|
expect(clockOf(1440 + 60)).toBe('01:00');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('moves the hours into the visitor’s time', () => {
|
||||||
|
// Router on UTC+3, visitor on UTC+1: two hours earlier.
|
||||||
|
expect(hoursFor('08:00-23:00', 180, 60)).toEqual({ from: 360, to: 1260, yours: true });
|
||||||
|
// Without the router's offset: its own time, as set.
|
||||||
|
expect(hoursFor('08:00-23:00', undefined, 60)).toEqual({ from: 480, to: 1380, yours: false });
|
||||||
|
expect(hoursFor('nonsense', 0, 0)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('splits a window over midnight into two stretches', () => {
|
||||||
|
expect(stretches({ from: 480, to: 1380, yours: true })).toEqual([[480, 1380]]);
|
||||||
|
expect(stretches({ from: 1320, to: 360, yours: true })).toEqual([
|
||||||
|
[1320, 1440],
|
||||||
|
[0, 360],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('finds the minute of the day and the days of the month', () => {
|
||||||
|
// 2026-10-19 12:00 UTC is 15:00 on UTC+3.
|
||||||
|
expect(minuteAt(Date.UTC(2026, 9, 19, 12) / 1000, 180)).toBe(900);
|
||||||
|
expect(monthOf('2026-10-19')).toEqual({ days: 31, day: 19 });
|
||||||
|
expect(monthOf('2028-02-03')).toEqual({ days: 29, day: 3 });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { kept } from '../src/portal/ui/morph';
|
||||||
|
|
||||||
|
/** The letters a morph keeps, as the new text shows them (the rest come in). */
|
||||||
|
const keeps = (from: string, to: string) =>
|
||||||
|
kept([...from], [...to])
|
||||||
|
.map(([, j]) => [...to][j])
|
||||||
|
.join('');
|
||||||
|
|
||||||
|
describe('kept letters', () => {
|
||||||
|
it('keeps what the two share at the end together', () => {
|
||||||
|
expect(kept([...'iPad'], [...'Kitchen iPad'])).toEqual([
|
||||||
|
[0, 8],
|
||||||
|
[1, 9],
|
||||||
|
[2, 10],
|
||||||
|
[3, 11],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps what they share at the start and at the end, and changes only the middle', () => {
|
||||||
|
expect(keeps('2 of 3', '3 of 3')).toBe(' of 3');
|
||||||
|
expect(keeps('Kitchen tablet', 'Kitchen iPad')).toBe('Kitchen a');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('finds the letters in common between two different words', () => {
|
||||||
|
expect(keeps('Scan', 'Create')).toBe('a');
|
||||||
|
expect(keeps('Last 7 days', 'Thu 15 Oct')).toContain(' ');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps nothing between texts with nothing in common, and everything between equal ones', () => {
|
||||||
|
expect(kept([...'abc'], [...'xyz'])).toEqual([]);
|
||||||
|
expect(keeps('Connected', 'Connected')).toBe('Connected');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('pairs indexes in order on both sides', () => {
|
||||||
|
const pairs = kept([...'Not set up yet'], [...'Connected']);
|
||||||
|
pairs.forEach(([i, j], n) => {
|
||||||
|
if (!n) return;
|
||||||
|
expect(i).toBeGreaterThan(pairs[n - 1][0]);
|
||||||
|
expect(j).toBeGreaterThan(pairs[n - 1][1]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import { dismisses, morphMs, rubber } from '../src/portal/motion';
|
import { BOUNCY, SMOOTH, dismisses, rubber, spring } from '../src/portal/motion';
|
||||||
|
|
||||||
describe('motion', () => {
|
describe('motion', () => {
|
||||||
it('pulls past an edge with growing resistance, never further than the box', () => {
|
it('pulls past an edge with growing resistance, never further than the box', () => {
|
||||||
@@ -21,9 +21,21 @@ describe('motion', () => {
|
|||||||
expect(dismisses(-40, 1, 500)).toBe(false);
|
expect(dismisses(-40, 1, 500)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('times a height change by its distance, inside 220–380 ms', () => {
|
it('samples springs into linear() that starts at 0 and ends at 1', () => {
|
||||||
expect(morphMs(0)).toBe(220);
|
for (const s of [BOUNCY, SMOOTH, spring(520, 24)]) {
|
||||||
expect(morphMs(200)).toBe(270);
|
expect(s.easing.startsWith('linear(0, ')).toBe(true);
|
||||||
expect(morphMs(2000)).toBe(380);
|
expect(s.easing.endsWith(', 1)')).toBe(true);
|
||||||
|
expect(s.at(0)).toBe(0);
|
||||||
|
expect(s.at(s.duration)).toBe(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gives the bouncy spring its overshoot and the smooth one none', () => {
|
||||||
|
const peak = (s: typeof BOUNCY) => Math.max(...Array.from({ length: 200 }, (_, i) => s.at((s.duration * i) / 200)));
|
||||||
|
// skiper103: about 11% past the end, settled well inside a second.
|
||||||
|
expect(peak(BOUNCY)).toBeGreaterThan(1.08);
|
||||||
|
expect(peak(BOUNCY)).toBeLessThan(1.15);
|
||||||
|
expect(BOUNCY.duration).toBeLessThan(900);
|
||||||
|
expect(peak(SMOOTH)).toBeLessThanOrEqual(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -79,7 +79,6 @@ import {
|
|||||||
portsHelp,
|
portsHelp,
|
||||||
quotaHelp,
|
quotaHelp,
|
||||||
timeHelp,
|
timeHelp,
|
||||||
titleHelp,
|
|
||||||
urlHelp,
|
urlHelp,
|
||||||
} from '../src/admin/netcheck';
|
} from '../src/admin/netcheck';
|
||||||
import { date, daysLeft } from '../src/shared/format';
|
import { date, daysLeft } from '../src/shared/format';
|
||||||
@@ -131,7 +130,6 @@ describe('field helps', () => {
|
|||||||
expect(portsHelp('70000').bad).toBe(true);
|
expect(portsHelp('70000').bad).toBe(true);
|
||||||
expect(urlHelp('vpn.example.com').bad).toBe(true);
|
expect(urlHelp('vpn.example.com').bad).toBe(true);
|
||||||
expect(urlHelp('https://example.com/x').bad).toBe(false);
|
expect(urlHelp('https://example.com/x').bad).toBe(false);
|
||||||
expect(titleHelp('x'.repeat(65)).bad).toBe(true);
|
|
||||||
expect(domainHelp('').bad).toBe(false);
|
expect(domainHelp('').bad).toBe(false);
|
||||||
expect(domainHelp('').text).toContain('phone.myata.lan');
|
expect(domainHelp('').text).toContain('phone.myata.lan');
|
||||||
expect(domainHelp('Home.LAN').text).toBe('Lowercase only.');
|
expect(domainHelp('Home.LAN').text).toBe('Lowercase only.');
|
||||||
|
|||||||
@@ -23,6 +23,16 @@ describe('qr', () => {
|
|||||||
expect(qrSvg(KEY, 3, true, 'night')).not.toContain('<g transform');
|
expect(qrSvg(KEY, 3, true, 'night')).not.toContain('<g transform');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('draws the day look with the night shapes, dark on white', () => {
|
||||||
|
const night = qrSvg(LINK, 3, true, 'night');
|
||||||
|
const day = qrSvg(LINK, 3, true, 'day');
|
||||||
|
expect(day).toMatch(/<rect width="(\d+)" height="\1" fill="#ffffff"\/>/);
|
||||||
|
expect(day).toContain('fill-rule="evenodd"');
|
||||||
|
expect(day).not.toContain('crispEdges');
|
||||||
|
// The same dots and eyes as at night, in the other colours; the mark's tile turns dark.
|
||||||
|
expect(day.replace(/#ffffff/g, 'BG').replace(/#0a0a0a/g, 'FG')).toBe(night.replace(/#0a0a0a/g, 'BG').replace(/#f2f2f2/g, 'FG'));
|
||||||
|
});
|
||||||
|
|
||||||
it('gives a dense night code fuller dots', () => {
|
it('gives a dense night code fuller dots', () => {
|
||||||
expect(qrSvg(LINK, 3, true, 'night')).toContain('a0.42 0.42');
|
expect(qrSvg(LINK, 3, true, 'night')).toContain('a0.42 0.42');
|
||||||
expect(qrSvg(KEY, 3, true, 'night')).toContain('a0.48 0.48');
|
expect(qrSvg(KEY, 3, true, 'night')).toContain('a0.48 0.48');
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import {
|
import {
|
||||||
|
addLink,
|
||||||
appsFor,
|
appsFor,
|
||||||
deviceNoun,
|
deviceNoun,
|
||||||
importPath,
|
importPath,
|
||||||
@@ -7,14 +8,13 @@ import {
|
|||||||
inWebview,
|
inWebview,
|
||||||
keyFileName,
|
keyFileName,
|
||||||
opensKeyLinks,
|
opensKeyLinks,
|
||||||
osGroup,
|
|
||||||
platformOf,
|
platformOf,
|
||||||
sameDevice,
|
sameDevice,
|
||||||
scanPath,
|
scanPath,
|
||||||
setupFromHash,
|
setupFromHash,
|
||||||
setupLink,
|
setupLink,
|
||||||
storeFor,
|
storeFor,
|
||||||
updateLine,
|
wantsAdd,
|
||||||
} from '../src/portal/setup';
|
} from '../src/portal/setup';
|
||||||
|
|
||||||
const IPHONE =
|
const IPHONE =
|
||||||
@@ -45,6 +45,14 @@ describe('setup', () => {
|
|||||||
expect(setupFromHash('#setup=../../api')).toBeNull();
|
expect(setupFromHash('#setup=../../api')).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('links to "Add a device" for the device itself, and reads only that back', () => {
|
||||||
|
const page = 'https://engage.example.eu:4500/abcdef-ghijkl-mnopqr';
|
||||||
|
expect(addLink(page)).toBe(`${page}#add`);
|
||||||
|
expect(wantsAdd('#add')).toBe(true);
|
||||||
|
expect(wantsAdd('#add=1')).toBe(false);
|
||||||
|
expect(wantsAdd('')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('names the device being set up by its kind, not its name', () => {
|
it('names the device being set up by its kind, not its name', () => {
|
||||||
expect(deviceNoun('phone')).toBe('phone');
|
expect(deviceNoun('phone')).toBe('phone');
|
||||||
expect(deviceNoun('computer')).toBe('computer');
|
expect(deviceNoun('computer')).toBe('computer');
|
||||||
@@ -60,20 +68,9 @@ describe('setup', () => {
|
|||||||
expect(sameDevice('phone', 'unknown')).toBe(false);
|
expect(sameDevice('phone', 'unknown')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lets the person pick the system of a computer or an "other" device', () => {
|
|
||||||
expect(osGroup('computer')).toEqual(['windows', 'mac', 'linux']);
|
|
||||||
expect(osGroup('other')).toEqual(['ios', 'android', 'windows', 'mac', 'linux']);
|
|
||||||
expect(osGroup('phone')).toEqual([]);
|
|
||||||
expect(osGroup('router')).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('lists the apps a disguise allows, AmneziaVPN first', () => {
|
it('lists the apps a disguise allows, AmneziaVPN first', () => {
|
||||||
expect(appsFor('max').map((a) => a.id)).toEqual(['vpn', 'awg']);
|
expect(appsFor('max').map((a) => a.id)).toEqual(['vpn', 'awg']);
|
||||||
expect(appsFor('off').map((a) => a.id)).toEqual(['vpn', 'awg', 'wg']);
|
expect(appsFor('off').map((a) => a.id)).toEqual(['vpn', 'awg', 'wg']);
|
||||||
expect(appsFor('balanced')[0].need).toBe('4.8.12');
|
|
||||||
expect(updateLine(appsFor('balanced')[0])).toContain('4.8.12 or newer');
|
|
||||||
expect(updateLine(appsFor('max')[0])).toContain('the current version');
|
|
||||||
expect(updateLine(appsFor('off')[0])).toBe('');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends people to the store first and to GitHub where no store has the app', () => {
|
it('sends people to the store first and to GitHub where no store has the app', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { defineConfig } from 'tsup';
|
import { defineConfig } from 'tsup';
|
||||||
import { transform, type Plugin } from 'esbuild';
|
import { build, transform, type Plugin } from 'esbuild';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
@@ -33,6 +33,21 @@ async function minifyCss(css: string): Promise<string> {
|
|||||||
return (await transform(css, { loader: 'css', minify: true, legalComments: 'none' })).code.trim();
|
return (await transform(css, { loader: 'css', minify: true, legalComments: 'none' })).code.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The portal's stylesheet: its parts (src/portal/styles, joined by @import) as one minified file. */
|
||||||
|
async function portalCss(): Promise<string> {
|
||||||
|
const r = await build({
|
||||||
|
entryPoints: ['src/portal/styles/index.css'],
|
||||||
|
bundle: true,
|
||||||
|
minify: true,
|
||||||
|
write: false,
|
||||||
|
legalComments: 'none',
|
||||||
|
// The fonts sit next to the stylesheet on the router: their URLs stay as written.
|
||||||
|
external: ['*.woff2'],
|
||||||
|
logLevel: 'silent',
|
||||||
|
});
|
||||||
|
return r.outputFiles[0].text.trim();
|
||||||
|
}
|
||||||
|
|
||||||
// The admin styles are plain .css files under src/admin/styles, imported as
|
// The admin styles are plain .css files under src/admin/styles, imported as
|
||||||
// text and joined in styles/index.ts (rendered inside each view): each is
|
// text and joined in styles/index.ts (rendered inside each view): each is
|
||||||
// minified here. They get a namespace (and a path not ending in .css) of
|
// minified here. They get a namespace (and a path not ending in .css) of
|
||||||
@@ -97,7 +112,7 @@ export default defineConfig([
|
|||||||
o.charset = 'utf8';
|
o.charset = 'utf8';
|
||||||
},
|
},
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
fs.writeFileSync(path.join(PORTAL_OUT, 'portal.css'), (await minifyCss(fs.readFileSync('src/portal/portal.css', 'utf8'))) + '\n');
|
fs.writeFileSync(path.join(PORTAL_OUT, 'portal.css'), (await portalCss()) + '\n');
|
||||||
fs.copyFileSync('src/portal/icon.svg', path.join(PORTAL_OUT, 'icon.svg'));
|
fs.copyFileSync('src/portal/icon.svg', path.join(PORTAL_OUT, 'icon.svg'));
|
||||||
for (const f of fs.readdirSync('src/portal/fonts')) fs.copyFileSync(path.join('src/portal/fonts', f), path.join(PORTAL_OUT, f));
|
for (const f of fs.readdirSync('src/portal/fonts')) fs.copyFileSync(path.join('src/portal/fonts', f), path.join(PORTAL_OUT, f));
|
||||||
},
|
},
|
||||||
|
|||||||