signalk-chiplog 2.7.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +74 -1
  2. package/README.md +152 -45
  3. package/docs/screenshots/05-stats.png +0 -0
  4. package/docs/screenshots/06-3d-animation.png +0 -0
  5. package/index.js +241 -4
  6. package/lib/api.js +123 -2
  7. package/lib/cloud-pairing.js +172 -0
  8. package/lib/cloud-restore.js +416 -0
  9. package/lib/cloud-sync.js +455 -0
  10. package/lib/database.js +50 -1
  11. package/lib/detection.js +4 -0
  12. package/lib/events.js +84 -20
  13. package/lib/export.js +1 -1
  14. package/lib/mail.js +162 -0
  15. package/lib/passage-map.js +342 -0
  16. package/lib/passage-summary.js +169 -0
  17. package/lib/places.js +6 -0
  18. package/lib/png.js +295 -0
  19. package/lib/qr.js +266 -0
  20. package/lib/smtp.js +242 -0
  21. package/lib/summary-mailer.js +286 -0
  22. package/package.json +2 -1
  23. package/public/app.css +94 -0
  24. package/public/entry/entry.css +94 -1
  25. package/public/entry/icons/apple-touch-icon.png +0 -0
  26. package/public/entry/icons/icon-192.png +0 -0
  27. package/public/entry/icons/icon-512.png +0 -0
  28. package/public/entry/index.html +2 -2
  29. package/public/entry/js/components/Dialogs.mjs +82 -16
  30. package/public/entry/js/components/Icons.mjs +33 -0
  31. package/public/entry/js/components/NotePanel.mjs +21 -3
  32. package/public/entry/js/components/RecentList.mjs +2 -3
  33. package/public/entry/js/journal.mjs +24 -7
  34. package/public/entry/js/main.mjs +27 -18
  35. package/public/entry/manifest.webmanifest +1 -1
  36. package/public/entry/sw.js +2 -0
  37. package/public/icon-small.svg +37 -0
  38. package/public/icon.svg +82 -6
  39. package/public/index.html +1 -1
  40. package/public/js/components/CloudBackup.mjs +298 -0
  41. package/public/js/components/ExportView.mjs +3 -0
  42. package/public/js/components/LogView.mjs +63 -6
  43. package/public/js/components/PassageView.mjs +4 -3
  44. package/public/js/components/Timeline.mjs +40 -14
  45. package/public/js/context.mjs +22 -3
  46. package/public/js/format.mjs +34 -0
  47. package/public/js/i18n.mjs +107 -2
  48. package/public/js/log-lines.mjs +5 -0
  49. package/public/js/main.mjs +1 -1
  50. package/public/js/view-memory.mjs +39 -0
package/lib/smtp.js ADDED
@@ -0,0 +1,242 @@
1
+ const net = require('node:net');
2
+ const os = require('node:os');
3
+ const tls = require('node:tls');
4
+
5
+ // A small SMTP client: EHLO, optional STARTTLS, optional AUTH, one message.
6
+ // Enough to hand a passage summary to the boat's mail relay (SPEC §4.16), and
7
+ // no more -- the same reason the PDF writer and the PNG codec are hand-rolled
8
+ // rather than pulled in as dependencies (SPEC §2).
9
+
10
+ const CONNECT_TIMEOUT_MS = 20 * 1000;
11
+ const COMMAND_TIMEOUT_MS = 60 * 1000;
12
+ // RFC 5321 §4.5.3.1: no line of a command or of the data may exceed this.
13
+ const MAX_LINE = 998;
14
+
15
+ const SECURITIES = ['starttls', 'tls', 'none'];
16
+
17
+ class SmtpError extends Error {
18
+ constructor(message, { code = null, permanent = false } = {}) {
19
+ super(message);
20
+ this.name = 'SmtpError';
21
+ this.code = code;
22
+ // 5xx is the server saying "not like this, ever": retrying the same
23
+ // message would only repeat it.
24
+ this.permanent = permanent;
25
+ }
26
+ }
27
+
28
+ // Reads the CRLF-delimited replies of one connection. A reply is one or more
29
+ // lines sharing a code, all but the last written `250-like this`.
30
+ //
31
+ // The bytes are kept as a Buffer rather than read through `setEncoding`: after
32
+ // STARTTLS the same socket carries TLS records, which must reach the TLS layer
33
+ // untouched.
34
+ function createReader(socket) {
35
+ let buffer = Buffer.alloc(0);
36
+ let failure = null;
37
+ let waiting = null;
38
+
39
+ const settle = () => {
40
+ if (!waiting) {
41
+ return;
42
+ }
43
+ if (failure) {
44
+ const { reject } = waiting;
45
+ waiting = null;
46
+ reject(failure);
47
+ return;
48
+ }
49
+ const lines = [];
50
+ for (;;) {
51
+ const end = buffer.indexOf('\r\n');
52
+ if (end === -1) {
53
+ return;
54
+ }
55
+ const line = buffer.toString('utf8', 0, end);
56
+ buffer = buffer.subarray(end + 2);
57
+ lines.push(line);
58
+ if (line.length < 4 || line[3] !== '-') {
59
+ const { resolve } = waiting;
60
+ waiting = null;
61
+ resolve({
62
+ code: Number.parseInt(lines[0].slice(0, 3), 10),
63
+ text: lines.map((item) => item.slice(4)).join('\n'),
64
+ lines
65
+ });
66
+ return;
67
+ }
68
+ }
69
+ };
70
+
71
+ const onData = (chunk) => {
72
+ buffer = Buffer.concat([buffer, chunk]);
73
+ settle();
74
+ };
75
+ const onError = (err) => {
76
+ failure ??= new SmtpError(`SMTP connection failed: ${err.message}`);
77
+ settle();
78
+ };
79
+ const onClose = () => {
80
+ failure ??= new SmtpError('The SMTP server closed the connection');
81
+ settle();
82
+ };
83
+
84
+ socket.on('data', onData);
85
+ socket.on('error', onError);
86
+ socket.on('close', onClose);
87
+
88
+ return {
89
+ read() {
90
+ return new Promise((resolve, reject) => {
91
+ waiting = { resolve, reject };
92
+ settle();
93
+ });
94
+ },
95
+ // Lets go of the socket, so STARTTLS can hand it to the TLS layer with
96
+ // nobody else reading it.
97
+ detach() {
98
+ socket.off('data', onData);
99
+ socket.off('error', onError);
100
+ socket.off('close', onClose);
101
+ socket.pause();
102
+ }
103
+ };
104
+ }
105
+
106
+ function withTimeout(promise, ms, what) {
107
+ let timer;
108
+ return Promise.race([
109
+ promise.finally(() => clearTimeout(timer)),
110
+ new Promise((_, reject) => {
111
+ timer = setTimeout(() => reject(new SmtpError(`The SMTP server did not answer ${what}`)), ms);
112
+ })
113
+ ]);
114
+ }
115
+
116
+ // `secure` is implicit TLS, the submission-over-TLS port (465); STARTTLS
117
+ // starts in the clear and upgrades below.
118
+ function openSocket({ host, port, secure }) {
119
+ return new Promise((resolve, reject) => {
120
+ const socket = secure ? tls.connect({ host, port, servername: host }) : net.connect(port, host);
121
+ const ready = secure ? 'secureConnect' : 'connect';
122
+ socket.setTimeout(CONNECT_TIMEOUT_MS, () =>
123
+ socket.destroy(new Error(`no answer from ${host}:${port}`))
124
+ );
125
+ socket.once(ready, () => {
126
+ socket.setTimeout(0);
127
+ resolve(socket);
128
+ });
129
+ socket.once('error', reject);
130
+ });
131
+ }
132
+
133
+ function upgrade(socket, host) {
134
+ return new Promise((resolve, reject) => {
135
+ const secure = tls.connect({ socket, servername: host });
136
+ secure.once('secureConnect', () => resolve(secure));
137
+ secure.once('error', reject);
138
+ });
139
+ }
140
+
141
+ // `connect(options)` returns a connected duplex stream; injected so a test can
142
+ // speak to a socket of its own.
143
+ function createSmtpClient({
144
+ host,
145
+ port,
146
+ security = 'starttls',
147
+ username = null,
148
+ password = null,
149
+ clientName = os.hostname(),
150
+ connect = openSocket
151
+ } = {}) {
152
+ if (!SECURITIES.includes(security)) {
153
+ throw new Error(`Unknown SMTP security "${security}"`);
154
+ }
155
+
156
+ async function send({ from, to, message }) {
157
+ const recipients = Array.isArray(to) ? to : [to];
158
+ if (recipients.length === 0) {
159
+ throw new SmtpError('No recipient for the message', { permanent: true });
160
+ }
161
+ for (const line of message.split('\r\n')) {
162
+ if (line.length > MAX_LINE) {
163
+ throw new SmtpError('A line of the message is too long for SMTP', { permanent: true });
164
+ }
165
+ }
166
+
167
+ let socket = await connect({ host, port, secure: security === 'tls' });
168
+ let reader = createReader(socket);
169
+ let closed = false;
170
+
171
+ const say = async (command, what, expected) => {
172
+ socket.write(`${command}\r\n`);
173
+ return expect(what, expected);
174
+ };
175
+
176
+ const expect = async (what, expected) => {
177
+ const reply = await withTimeout(reader.read(), COMMAND_TIMEOUT_MS, what);
178
+ if (!expected.includes(Math.floor(reply.code / 100))) {
179
+ throw new SmtpError(`SMTP ${what} refused: ${reply.code} ${reply.text}`, {
180
+ code: reply.code,
181
+ permanent: reply.code >= 500
182
+ });
183
+ }
184
+ return reply;
185
+ };
186
+
187
+ try {
188
+ await expect('the greeting', [2]);
189
+ let hello = await say(`EHLO ${clientName}`, 'EHLO', [2]);
190
+ const supports = (keyword) =>
191
+ hello.lines.some((line) => line.slice(4).toUpperCase().startsWith(keyword));
192
+
193
+ if (security === 'starttls') {
194
+ if (!supports('STARTTLS')) {
195
+ throw new SmtpError(`${host} does not offer STARTTLS`, { permanent: true });
196
+ }
197
+ await say('STARTTLS', 'STARTTLS', [2]);
198
+ reader.detach();
199
+ socket = await upgrade(socket, host);
200
+ reader = createReader(socket);
201
+ hello = await say(`EHLO ${clientName}`, 'EHLO', [2]);
202
+ }
203
+
204
+ if (username) {
205
+ if (supports('AUTH') && hello.lines.some((line) => /\bPLAIN\b/i.test(line))) {
206
+ const credentials = Buffer.from(`\0${username}\0${password ?? ''}`).toString('base64');
207
+ await say(`AUTH PLAIN ${credentials}`, 'authentication', [2]);
208
+ } else {
209
+ await say('AUTH LOGIN', 'authentication', [3]);
210
+ await say(Buffer.from(username).toString('base64'), 'the user name', [3]);
211
+ await say(Buffer.from(password ?? '').toString('base64'), 'the password', [2]);
212
+ }
213
+ }
214
+
215
+ await say(`MAIL FROM:<${from}>`, 'the sender', [2]);
216
+ for (const recipient of recipients) {
217
+ await say(`RCPT TO:<${recipient}>`, `the recipient ${recipient}`, [2]);
218
+ }
219
+ await say('DATA', 'DATA', [3]);
220
+ // Dot-stuffing: a line of the message that starts with one would
221
+ // otherwise end it.
222
+ socket.write(`${message.replace(/\r\n\./g, '\r\n..')}\r\n.\r\n`);
223
+ await expect('the message', [2]);
224
+ // The message is accepted; waiting for the goodbye only makes sure the
225
+ // relay has it before the connection goes, and a server that hangs up on
226
+ // QUIT instead of answering has done nothing wrong.
227
+ socket.write('QUIT\r\n');
228
+ await withTimeout(reader.read(), COMMAND_TIMEOUT_MS, 'QUIT').catch(() => {});
229
+ closed = true;
230
+ socket.end();
231
+ return { recipients };
232
+ } finally {
233
+ if (!closed) {
234
+ socket.destroy();
235
+ }
236
+ }
237
+ }
238
+
239
+ return { send };
240
+ }
241
+
242
+ module.exports = { createSmtpClient, SmtpError, SECURITIES, MAX_LINE };
@@ -0,0 +1,286 @@
1
+ const { withTransaction } = require('./database');
2
+ const { getEntry } = require('./entries');
3
+ const { buildMessage, parseAddress, parseAddressList } = require('./mail');
4
+ const { renderPassageMap } = require('./passage-map');
5
+ const { MAP_CID, renderPassageSummary } = require('./passage-summary');
6
+ const { createSmtpClient, SmtpError } = require('./smtp');
7
+ const { allTrackPoints } = require('./track');
8
+
9
+ // Emails a summary of each passage once it is definitively closed (SPEC
10
+ // §4.16): a passage closes the moment the vessel stops, but a departure within
11
+ // `stopClosureMinutes` reopens it (SPEC §4.2), so the summary waits out that
12
+ // window and goes out only once the arrival is final.
13
+ //
14
+ // Shaped like the forecasters: a `resolveNext()` run by its own
15
+ // `background-schedule` chain, dealing with one passage at a time and saying
16
+ // when the next run is due.
17
+
18
+ const SUMMARY_MAIL_DEFAULTS = {
19
+ summaryMailEnabled: false,
20
+ summaryMailTileUrl: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
21
+ smtpPort: 587,
22
+ smtpSecurity: 'starttls'
23
+ };
24
+
25
+ const IDLE_MS = 60 * 1000;
26
+ // Offline is the normal state at sea; retry patiently rather than hammering.
27
+ const FIRST_RETRY_MS = 5 * 60 * 1000;
28
+ const MAX_RETRY_MS = 60 * 60 * 1000;
29
+ // Past this, a summary is no longer news and the passage is written off rather
30
+ // than retried forever -- the same giving-up as the departure forecasts.
31
+ const MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
32
+
33
+ const iso = (ms) => new Date(ms).toISOString();
34
+
35
+ // The oldest passage definitively closed and not dealt with, so a backlog
36
+ // built up offline goes out in the order it was sailed.
37
+ function nextPending(db, { now, closureMs }) {
38
+ return db
39
+ .prepare(
40
+ `SELECT id FROM log_entries
41
+ WHERE state = 'closed' AND end_time IS NOT NULL
42
+ AND end_time <= ? AND end_time >= ?
43
+ AND id NOT IN (SELECT entry_id FROM passage_summary_mails)
44
+ ORDER BY end_time, id LIMIT 1`
45
+ )
46
+ .get(iso(now - closureMs), iso(now - MAX_AGE_MS))?.id;
47
+ }
48
+
49
+ function record(db, entryId, now, { recipients = null, error = null }) {
50
+ withTransaction(db, () => {
51
+ db.prepare(
52
+ `INSERT INTO passage_summary_mails (entry_id, sent_at, recipients, error, created_at)
53
+ VALUES (?, ?, ?, ?, ?)
54
+ ON CONFLICT (entry_id) DO UPDATE
55
+ SET sent_at = excluded.sent_at, recipients = excluded.recipients, error = excluded.error`
56
+ ).run(entryId, error ? null : iso(now), recipients?.join(', ') ?? null, error, iso(now));
57
+ });
58
+ }
59
+
60
+ // Writes off every passage already too old to be worth a summary, so a boat
61
+ // back from a month offline is not mailed its whole cruise one passage at a
62
+ // time -- and so `nextPending` does not keep stepping over them.
63
+ function writeOffStale(db, now) {
64
+ const where = `state = 'closed' AND end_time IS NOT NULL AND end_time < ?
65
+ AND id NOT IN (SELECT entry_id FROM passage_summary_mails)`;
66
+ // A read first: this runs every minute, and most minutes has nothing to do.
67
+ const stale = db
68
+ .prepare(`SELECT EXISTS (SELECT 1 FROM log_entries WHERE ${where}) AS any`)
69
+ .get(iso(now - MAX_AGE_MS)).any;
70
+ if (!stale) {
71
+ return;
72
+ }
73
+ withTransaction(db, () => {
74
+ db.prepare(
75
+ `INSERT INTO passage_summary_mails (entry_id, error, created_at)
76
+ SELECT id, 'closed too long ago for a summary to be worth sending', ?
77
+ FROM log_entries WHERE ${where}`
78
+ ).run(iso(now), iso(now - MAX_AGE_MS));
79
+ });
80
+ }
81
+
82
+ function configurationProblem(settings) {
83
+ if (!settings.smtpHost) {
84
+ return 'no SMTP server is configured';
85
+ }
86
+ if (parseAddressList(settings.summaryMailTo).length === 0) {
87
+ return 'no recipient is configured';
88
+ }
89
+ if (!parseAddress(settings.summaryMailFrom ?? '')?.address?.includes('@')) {
90
+ return 'no sender address is configured';
91
+ }
92
+ return null;
93
+ }
94
+
95
+ function createSummaryMailer({
96
+ db,
97
+ settings,
98
+ userAgent = 'signalk-chiplog',
99
+ vesselName = () => null,
100
+ clock = Date.now,
101
+ // Injected whole in tests: neither the tile servers nor an SMTP relay is
102
+ // reachable from them.
103
+ fetchImpl = globalThis.fetch,
104
+ createClient = createSmtpClient,
105
+ log = () => {}
106
+ }) {
107
+ let stopped = false;
108
+ let failures = 0;
109
+ let failingEntryId = null;
110
+ let lastSuccess = null;
111
+ let lastError = null;
112
+
113
+ async function compose(entryId) {
114
+ const entry = getEntry(db, entryId);
115
+ const trackPoints = allTrackPoints(db, entryId);
116
+ const vessel = vesselName();
117
+
118
+ // The map is the point of the mail, but a missing one is no reason to
119
+ // withhold the figures: the summary goes out with the track left out.
120
+ let map = null;
121
+ try {
122
+ map = await renderPassageMap(trackPoints, {
123
+ tileUrlTemplate: settings.summaryMailTileUrl || null,
124
+ fetchImpl,
125
+ userAgent,
126
+ log
127
+ });
128
+ } catch (err) {
129
+ log('error', `Passage ${entryId} map could not be drawn: ${err.message}`);
130
+ }
131
+
132
+ const { subject, text, html } = await renderPassageSummary(
133
+ { entry, trackPoints },
134
+ {
135
+ language: settings.logbookLanguage,
136
+ timeZone: settings.logbookTimeZone ?? undefined,
137
+ vesselName: vessel,
138
+ mapAvailable: map !== null
139
+ }
140
+ );
141
+
142
+ const to = parseAddressList(settings.summaryMailTo);
143
+ const configured = parseAddress(settings.summaryMailFrom);
144
+ // A sender given as a bare address is shown under the vessel's name, so an
145
+ // inbox full of these says which boat they came from.
146
+ const from = configured.name
147
+ ? configured
148
+ : { name: vessel ?? 'Chiplog', address: configured.address };
149
+ return {
150
+ to,
151
+ from,
152
+ message: buildMessage({
153
+ from,
154
+ to,
155
+ subject,
156
+ text,
157
+ html,
158
+ date: new Date(clock()),
159
+ inlineImages: map
160
+ ? [
161
+ {
162
+ cid: MAP_CID,
163
+ filename: `passage-${entryId}.png`,
164
+ contentType: 'image/png',
165
+ content: map.png
166
+ }
167
+ ]
168
+ : []
169
+ })
170
+ };
171
+ }
172
+
173
+ async function sendSummary(entryId) {
174
+ const { from, to, message } = await compose(entryId);
175
+ const client = createClient({
176
+ host: settings.smtpHost,
177
+ port: settings.smtpPort,
178
+ security: settings.smtpSecurity,
179
+ username: settings.smtpUsername || null,
180
+ password: settings.smtpPassword || null
181
+ });
182
+ await client.send({
183
+ from: from.address,
184
+ to: to.map((address) => address.address),
185
+ message
186
+ });
187
+ return to.map((address) => address.address);
188
+ }
189
+
190
+ return {
191
+ // Sends the summary of one passage now, whatever its state and whether or
192
+ // not one has already gone out: what the configuration is tested with.
193
+ async send(entryId) {
194
+ const problem = configurationProblem(settings);
195
+ if (problem) {
196
+ throw new SmtpError(`Cannot send the passage summary: ${problem}`, { permanent: true });
197
+ }
198
+ const recipients = await sendSummary(entryId);
199
+ const now = clock();
200
+ record(db, entryId, now, { recipients });
201
+ lastSuccess = { at: iso(now), entryId, recipients };
202
+ lastError = null;
203
+ return { entryId, recipients };
204
+ },
205
+
206
+ async resolveNext() {
207
+ if (!settings.summaryMailEnabled) {
208
+ return { outcome: 'disabled', retryInMs: IDLE_MS };
209
+ }
210
+ const problem = configurationProblem(settings);
211
+ if (problem) {
212
+ return { outcome: 'disabled', retryInMs: IDLE_MS };
213
+ }
214
+
215
+ const now = clock();
216
+ writeOffStale(db, now);
217
+ const entryId = nextPending(db, {
218
+ now,
219
+ closureMs: settings.stopClosureMinutes * 60 * 1000
220
+ });
221
+ if (entryId === undefined) {
222
+ failures = 0;
223
+ return { outcome: 'idle', retryInMs: IDLE_MS };
224
+ }
225
+ if (entryId !== failingEntryId) {
226
+ failures = 0;
227
+ failingEntryId = entryId;
228
+ }
229
+
230
+ let recipients;
231
+ try {
232
+ recipients = await sendSummary(entryId);
233
+ } catch (error) {
234
+ if (stopped) {
235
+ return { outcome: 'stopped' };
236
+ }
237
+ // A refusal the relay will repeat -- an address it will not take, a
238
+ // password it will not accept -- is recorded against the passage and
239
+ // left there; retrying it every few minutes for a week would only
240
+ // annoy the relay, and the reason is in the row and in the log.
241
+ if (error instanceof SmtpError && error.permanent) {
242
+ record(db, entryId, clock(), { error: error.message });
243
+ lastError = { at: iso(clock()), entryId, message: error.message };
244
+ log('error', `Passage ${entryId} summary refused for good: ${error.message}`);
245
+ return { outcome: 'refused', retryInMs: 0 };
246
+ }
247
+ failures += 1;
248
+ lastError = { at: iso(clock()), entryId, message: error.message };
249
+ return {
250
+ outcome: 'failed',
251
+ error,
252
+ retryInMs: Math.min(FIRST_RETRY_MS * 2 ** (failures - 1), MAX_RETRY_MS)
253
+ };
254
+ }
255
+ if (stopped) {
256
+ return { outcome: 'stopped' };
257
+ }
258
+
259
+ failures = 0;
260
+ const sentAt = clock();
261
+ record(db, entryId, sentAt, { recipients });
262
+ lastSuccess = { at: iso(sentAt), entryId, recipients };
263
+ lastError = null;
264
+ log('info', `Passage ${entryId} summary sent to ${recipients.join(', ')}`);
265
+ // Straight on to the next: a backlog goes out in one go.
266
+ return { outcome: 'sent', retryInMs: 0 };
267
+ },
268
+
269
+ status() {
270
+ return {
271
+ enabled: Boolean(settings.summaryMailEnabled),
272
+ configured: configurationProblem(settings) === null,
273
+ problem: configurationProblem(settings),
274
+ recipients: parseAddressList(settings.summaryMailTo).map((address) => address.address),
275
+ lastSuccess,
276
+ lastError
277
+ };
278
+ },
279
+
280
+ stop() {
281
+ stopped = true;
282
+ }
283
+ };
284
+ }
285
+
286
+ module.exports = { createSummaryMailer, SUMMARY_MAIL_DEFAULTS, MAX_AGE_MS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-chiplog",
3
- "version": "2.7.0",
3
+ "version": "2.9.0",
4
4
  "description": "Nautical logbook for Signal K: automatic entries, handwritten notes",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -75,6 +75,7 @@
75
75
  "globals": "^17.12.0",
76
76
  "htm": "^3.1.1",
77
77
  "husky": "^9.1.7",
78
+ "jsqr": "^1.4.0",
78
79
  "leaflet": "^1.9.4",
79
80
  "lint-staged": "^17.5.1",
80
81
  "mediabunny": "1.58.0",
package/public/app.css CHANGED
@@ -374,6 +374,28 @@ main {
374
374
  margin: 1.5rem auto;
375
375
  }
376
376
 
377
+ /* The logbook runs to hundreds of passages once older pages are loaded, and a
378
+ reader who has scrolled down to last spring should not have to scroll back. */
379
+ .to-top {
380
+ position: fixed;
381
+ right: 1rem;
382
+ bottom: 1rem;
383
+ z-index: 20;
384
+ display: flex;
385
+ align-items: center;
386
+ justify-content: center;
387
+ width: 2.75rem;
388
+ height: 2.75rem;
389
+ padding: 0;
390
+ border-radius: 50%;
391
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
392
+ }
393
+
394
+ .to-top svg {
395
+ width: 1.25rem;
396
+ height: 1.25rem;
397
+ }
398
+
377
399
  /* Passage */
378
400
 
379
401
  .back {
@@ -628,6 +650,26 @@ main {
628
650
  resize: vertical;
629
651
  }
630
652
 
653
+ .timeline-comment-form textarea,
654
+ .timeline-time-field input {
655
+ font: inherit;
656
+ padding: 0.4rem 0.6rem;
657
+ border-radius: 8px;
658
+ border: 1px solid var(--border);
659
+ background: var(--surface);
660
+ color: var(--text);
661
+ }
662
+
663
+ .timeline-time-field {
664
+ display: flex;
665
+ flex-direction: column;
666
+ gap: 0.2rem;
667
+ }
668
+
669
+ .timeline-time-field small {
670
+ font-size: 0.8em;
671
+ }
672
+
631
673
  /* Tide */
632
674
 
633
675
  .tide-place {
@@ -1058,6 +1100,58 @@ button.preset-on {
1058
1100
  padding: 0;
1059
1101
  }
1060
1102
 
1103
+ .pairing-form {
1104
+ display: flex;
1105
+ flex-wrap: wrap;
1106
+ align-items: end;
1107
+ gap: 0.6rem;
1108
+ margin-bottom: 1rem;
1109
+ }
1110
+
1111
+ .pairing-form label {
1112
+ display: grid;
1113
+ gap: 0.25rem;
1114
+ flex: 1 1 16rem;
1115
+ }
1116
+
1117
+ .pairing-code .code {
1118
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
1119
+ font-size: 2rem;
1120
+ font-weight: 600;
1121
+ letter-spacing: 0.12em;
1122
+ margin: 0.25rem 0;
1123
+ }
1124
+
1125
+ .costly-link {
1126
+ display: flex;
1127
+ align-items: center;
1128
+ gap: 0.5rem;
1129
+ margin-top: 1rem;
1130
+ }
1131
+
1132
+ .qr-code {
1133
+ display: block;
1134
+ width: 11rem;
1135
+ max-width: 100%;
1136
+ height: auto;
1137
+ margin: 0.75rem 0 0.25rem;
1138
+ /* Sharp squares at any size: a blurred edge is a module misread. */
1139
+ shape-rendering: crispEdges;
1140
+ }
1141
+
1142
+ .restore-offer ul {
1143
+ list-style: none;
1144
+ padding: 0;
1145
+ }
1146
+
1147
+ .restore-offer li {
1148
+ display: flex;
1149
+ flex-wrap: wrap;
1150
+ align-items: center;
1151
+ gap: 0.5rem 1rem;
1152
+ margin: 0.5rem 0;
1153
+ }
1154
+
1061
1155
  /* Retrospective analysis */
1062
1156
 
1063
1157
  .replay-actions {