@nervur.org/installer-node 0.0.0-stage → 0.37.1
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.
- package/LICENSE +105 -0
- package/README.md +158 -2
- package/SECURITY.md +8 -0
- package/bin/nervur.js +5 -0
- package/cargo/emscripten-module.wasm +0 -0
- package/cargo/manifest.json +1 -0
- package/cargo/sqlite3.wasm +0 -0
- package/cargo/table-i-i.wasm +0 -0
- package/cargo/table-i-ii.wasm +0 -0
- package/cargo/table-i-iii.wasm +0 -0
- package/cargo/table-i-iiii.wasm +0 -0
- package/cargo/table-i-iiiii.wasm +0 -0
- package/cargo/table-i-iiij.wasm +0 -0
- package/cargo/table-i-ij.wasm +0 -0
- package/cargo/table-v-ii.wasm +0 -0
- package/cargo/table-v-iii.wasm +0 -0
- package/cargo/worker.js +30756 -0
- package/organs/console/node/guard.d.ts +10 -0
- package/organs/console/node/guard.js +52 -0
- package/organs/console/node/index.d.ts +4 -0
- package/organs/console/node/index.js +5 -0
- package/organs/console/node/line.d.ts +16 -0
- package/organs/console/node/line.js +150 -0
- package/organs/console/node/main.js +51 -0
- package/organs/console/node/program.d.ts +1 -0
- package/organs/console/node/program.js +5 -0
- package/organs/console/node/proof.d.ts +15 -0
- package/organs/console/node/proof.js +84 -0
- package/organs/console/node/socket.d.ts +15 -0
- package/organs/console/node/socket.js +99 -0
- package/organs/disk/index.d.ts +1 -0
- package/organs/disk/index.js +2 -0
- package/organs/disk/node/files.js +162 -0
- package/organs/disk/node/main.js +20 -0
- package/organs/disk/node/program.d.ts +1 -0
- package/organs/disk/node/program.js +5 -0
- package/organs/disk/organ.d.ts +5 -0
- package/organs/disk/organ.js +69 -0
- package/organs/network/node/fill.d.ts +21 -0
- package/organs/network/node/fill.js +195 -0
- package/organs/network/node/flows.js +66 -0
- package/organs/network/node/half.js +260 -0
- package/organs/network/node/lines.d.ts +29 -0
- package/organs/network/node/lines.js +236 -0
- package/organs/network/node/link.d.ts +24 -0
- package/organs/network/node/link.js +215 -0
- package/organs/network/node/main.js +41 -0
- package/organs/network/node/moved.d.ts +2 -0
- package/organs/network/node/moved.js +20 -0
- package/organs/network/node/near.d.ts +63 -0
- package/organs/network/node/near.js +263 -0
- package/organs/network/node/program.d.ts +1 -0
- package/organs/network/node/program.js +5 -0
- package/organs/network/node/schemes.d.ts +1 -0
- package/organs/network/node/schemes.js +2 -0
- package/organs/network/node/sent.d.ts +13 -0
- package/organs/network/node/sent.js +101 -0
- package/organs/network/node/served.d.ts +19 -0
- package/organs/network/node/served.js +237 -0
- package/organs/screen/node/client.js +3 -0
- package/organs/screen/node/follow.js +266 -0
- package/organs/screen/node/frames.js +26 -0
- package/organs/screen/node/held.js +27 -0
- package/organs/screen/node/http.js +179 -0
- package/organs/screen/node/lay.js +116 -0
- package/organs/screen/node/leave.js +27 -0
- package/organs/screen/node/linked.js +69 -0
- package/organs/screen/node/listen.js +61 -0
- package/organs/screen/node/look.js +121 -0
- package/organs/screen/node/loop.js +154 -0
- package/organs/screen/node/main.js +74 -0
- package/organs/screen/node/mirror.js +112 -0
- package/organs/screen/node/notice.js +44 -0
- package/organs/screen/node/presser.js +11 -0
- package/organs/screen/node/presses.js +108 -0
- package/organs/screen/node/program.d.ts +1 -0
- package/organs/screen/node/program.js +5 -0
- package/organs/screen/node/shown.js +205 -0
- package/organs/screen/node/standing.js +29 -0
- package/organs/screen/node/state.js +80 -0
- package/organs/screen/node/tell.js +47 -0
- package/organs/screen/node/uid.js +65 -0
- package/organs/screen/node/worn.js +23 -0
- package/organs/shell/index.d.ts +1 -0
- package/organs/shell/index.js +2 -0
- package/organs/shell/node/main.js +26 -0
- package/organs/shell/node/output.js +70 -0
- package/organs/shell/node/pressure.js +14 -0
- package/organs/shell/node/program.d.ts +1 -0
- package/organs/shell/node/program.js +5 -0
- package/organs/shell/node/runs.js +220 -0
- package/organs/shell/node/told.js +70 -0
- package/organs/shell/organ.d.ts +5 -0
- package/organs/shell/organ.js +59 -0
- package/package.json +43 -4
- package/src/command/act.d.ts +31 -0
- package/src/command/act.js +256 -0
- package/src/command/answers.d.ts +3 -0
- package/src/command/answers.js +232 -0
- package/src/command/args.d.ts +14 -0
- package/src/command/args.js +220 -0
- package/src/command/arrive.d.ts +2 -0
- package/src/command/arrive.js +21 -0
- package/src/command/asked.d.ts +18 -0
- package/src/command/asked.js +49 -0
- package/src/command/backup.d.ts +18 -0
- package/src/command/backup.js +261 -0
- package/src/command/before.d.ts +41 -0
- package/src/command/before.js +237 -0
- package/src/command/born.d.ts +27 -0
- package/src/command/born.js +103 -0
- package/src/command/bridge.d.ts +19 -0
- package/src/command/bridge.js +152 -0
- package/src/command/chain.d.ts +9 -0
- package/src/command/chain.js +48 -0
- package/src/command/channel.d.ts +29 -0
- package/src/command/channel.js +263 -0
- package/src/command/choices.d.ts +35 -0
- package/src/command/choices.js +173 -0
- package/src/command/claim.d.ts +12 -0
- package/src/command/claim.js +46 -0
- package/src/command/commands.d.ts +16 -0
- package/src/command/commands.js +257 -0
- package/src/command/ends.d.ts +16 -0
- package/src/command/ends.js +78 -0
- package/src/command/follow.d.ts +12 -0
- package/src/command/follow.js +66 -0
- package/src/command/given.d.ts +39 -0
- package/src/command/given.js +53 -0
- package/src/command/held.d.ts +15 -0
- package/src/command/held.js +56 -0
- package/src/command/index.d.ts +1 -0
- package/src/command/index.js +203 -0
- package/src/command/jailer.d.ts +28 -0
- package/src/command/jailer.js +135 -0
- package/src/command/laid.d.ts +6 -0
- package/src/command/laid.js +31 -0
- package/src/command/left.d.ts +9 -0
- package/src/command/left.js +34 -0
- package/src/command/line.d.ts +7 -0
- package/src/command/line.js +39 -0
- package/src/command/link.d.ts +30 -0
- package/src/command/link.js +123 -0
- package/src/command/lobes.d.ts +1 -0
- package/src/command/lobes.js +10 -0
- package/src/command/locks.d.ts +17 -0
- package/src/command/locks.js +76 -0
- package/src/command/mcp/calls.d.ts +27 -0
- package/src/command/mcp/calls.js +155 -0
- package/src/command/mcp/notices.d.ts +22 -0
- package/src/command/mcp/notices.js +203 -0
- package/src/command/mcp/resources.d.ts +31 -0
- package/src/command/mcp/resources.js +108 -0
- package/src/command/mcp/server.d.ts +19 -0
- package/src/command/mcp/server.js +149 -0
- package/src/command/mcp/tools.d.ts +39 -0
- package/src/command/mcp/tools.js +131 -0
- package/src/command/mcp.d.ts +8 -0
- package/src/command/mcp.js +39 -0
- package/src/command/noticed.d.ts +11 -0
- package/src/command/noticed.js +55 -0
- package/src/command/older.d.ts +11 -0
- package/src/command/older.js +45 -0
- package/src/command/open.d.ts +24 -0
- package/src/command/open.js +107 -0
- package/src/command/passphrase.d.ts +6 -0
- package/src/command/passphrase.js +82 -0
- package/src/command/reclaim.d.ts +7 -0
- package/src/command/reclaim.js +47 -0
- package/src/command/refused.d.ts +4 -0
- package/src/command/refused.js +27 -0
- package/src/command/release.d.ts +27 -0
- package/src/command/release.js +153 -0
- package/src/command/repo.d.ts +31 -0
- package/src/command/repo.js +133 -0
- package/src/command/rewrap.d.ts +16 -0
- package/src/command/rewrap.js +175 -0
- package/src/command/runtime.d.ts +25 -0
- package/src/command/runtime.js +175 -0
- package/src/command/salvage.d.ts +4 -0
- package/src/command/salvage.js +42 -0
- package/src/command/screen.d.ts +14 -0
- package/src/command/screen.js +62 -0
- package/src/command/spawn.d.ts +23 -0
- package/src/command/spawn.js +213 -0
- package/src/command/start.d.ts +34 -0
- package/src/command/start.js +246 -0
- package/src/command/state.d.ts +5 -0
- package/src/command/state.js +39 -0
- package/src/command/token.d.ts +1 -0
- package/src/command/token.js +9 -0
- package/src/command/trial.d.ts +17 -0
- package/src/command/trial.js +92 -0
- package/src/command/vouch.d.ts +1 -0
- package/src/command/vouch.js +15 -0
- package/src/command/windows-processes.d.ts +2 -0
- package/src/command/windows-processes.js +22 -0
- package/src/command/wipe.d.ts +9 -0
- package/src/command/wipe.js +105 -0
- package/src/command/words.d.ts +5 -0
- package/src/command/words.js +53 -0
- package/src/door/claim.d.ts +5 -0
- package/src/door/claim.js +21 -0
- package/src/door/claimed.d.ts +7 -0
- package/src/door/claimed.js +110 -0
- package/src/door/configuration.d.ts +40 -0
- package/src/door/configuration.js +206 -0
- package/src/door/design.d.ts +13 -0
- package/src/door/design.js +71 -0
- package/src/door/digests.d.ts +7 -0
- package/src/door/digests.js +36 -0
- package/src/door/distribution.d.ts +25 -0
- package/src/door/distribution.js +88 -0
- package/src/door/door.d.ts +41 -0
- package/src/door/door.js +219 -0
- package/src/door/dressed.d.ts +34 -0
- package/src/door/dressed.js +182 -0
- package/src/door/faculties.d.ts +29 -0
- package/src/door/faculties.js +88 -0
- package/src/door/longest.d.ts +6 -0
- package/src/door/longest.js +25 -0
- package/src/fills/account-only.d.ts +3 -0
- package/src/fills/account-only.js +24 -0
- package/src/fills/boot-key.d.ts +21 -0
- package/src/fills/boot-key.js +70 -0
- package/src/fills/boot-move.d.ts +25 -0
- package/src/fills/boot-move.js +86 -0
- package/src/fills/bridge.d.ts +13 -0
- package/src/fills/bridge.js +86 -0
- package/src/fills/chance.d.ts +2 -0
- package/src/fills/chance.js +7 -0
- package/src/fills/crypto.d.ts +2 -0
- package/src/fills/crypto.js +94 -0
- package/src/fills/flushed.d.ts +9 -0
- package/src/fills/flushed.js +80 -0
- package/src/fills/hardware.d.ts +18 -0
- package/src/fills/hardware.js +70 -0
- package/src/fills/held.d.ts +31 -0
- package/src/fills/held.js +171 -0
- package/src/fills/keepers.d.ts +23 -0
- package/src/fills/keepers.js +151 -0
- package/src/fills/keyring.d.ts +19 -0
- package/src/fills/keyring.js +131 -0
- package/src/fills/pages.d.ts +3 -0
- package/src/fills/pages.js +260 -0
- package/src/fills/reserve.d.ts +11 -0
- package/src/fills/reserve.js +72 -0
- package/src/fills/time.d.ts +2 -0
- package/src/fills/time.js +29 -0
- package/src/fills/unlocker.d.ts +6 -0
- package/src/fills/unlocker.js +26 -0
- package/src/fills/vitals.d.ts +8 -0
- package/src/fills/vitals.js +100 -0
- package/src/fills/windows-start.d.ts +2 -0
- package/src/fills/windows-start.js +21 -0
- package/src/halves/build.d.ts +10 -0
- package/src/halves/build.js +219 -0
- package/src/halves/end.d.ts +17 -0
- package/src/halves/end.js +157 -0
- package/src/halves/genome.d.ts +3 -0
- package/src/halves/genome.js +21 -0
- package/src/halves/handler.d.ts +8 -0
- package/src/halves/handler.js +40 -0
- package/src/halves/index.d.ts +5 -0
- package/src/halves/index.js +6 -0
- package/src/halves/laid.d.ts +12 -0
- package/src/halves/laid.js +103 -0
- package/src/halves/lent.d.ts +6 -0
- package/src/halves/lent.js +147 -0
- package/src/halves/native.d.ts +12 -0
- package/src/halves/native.js +53 -0
- package/src/halves/statements.d.ts +23 -0
- package/src/halves/statements.js +165 -0
- package/src/halves/tokens.d.ts +22 -0
- package/src/halves/tokens.js +135 -0
- package/src/link/link.d.ts +4 -0
- package/src/link/link.js +4 -0
- package/src/link/placeholder.d.ts +1 -0
- package/src/link/placeholder.js +21 -0
- package/src/link/steps.d.ts +52 -0
- package/src/link/steps.js +118 -0
- package/src/lobes/calls.d.ts +76 -0
- package/src/lobes/calls.js +61 -0
- package/src/lobes/channel.d.ts +76 -0
- package/src/lobes/channel.js +202 -0
- package/src/lobes/index.d.ts +1 -0
- package/src/lobes/index.js +2 -0
- package/src/lobes/lobes.d.ts +15 -0
- package/src/lobes/lobes.js +244 -0
- package/src/lobes/main.js +107 -0
- package/src/lobes/thread.d.ts +22 -0
- package/src/lobes/thread.js +270 -0
- package/src/organism/act.d.ts +8 -0
- package/src/organism/act.js +63 -0
- package/src/organism/beat.d.ts +5 -0
- package/src/organism/beat.js +45 -0
- package/src/organism/compiled.d.ts +2 -0
- package/src/organism/compiled.js +24 -0
- package/src/organism/folder.d.ts +88 -0
- package/src/organism/folder.js +259 -0
- package/src/organism/main.d.ts +1 -0
- package/src/organism/main.js +11 -0
- package/src/organism/organism.d.ts +1 -0
- package/src/organism/organism.js +219 -0
- package/src/organism/said.d.ts +12 -0
- package/src/organism/said.js +30 -0
- package/src/organism/told.d.ts +5 -0
- package/src/organism/told.js +110 -0
- package/src/organism/unlock.d.ts +8 -0
- package/src/organism/unlock.js +95 -0
- package/src/organism/upgrade.d.ts +24 -0
- package/src/organism/upgrade.js +145 -0
- package/src/organism/via.d.ts +7 -0
- package/src/organism/via.js +20 -0
- package/src/service/body.d.ts +8 -0
- package/src/service/body.js +34 -0
- package/src/service/handler.d.ts +20 -0
- package/src/service/handler.js +128 -0
- package/src/service/index.d.ts +4 -0
- package/src/service/index.js +16 -0
- package/src/service/manager.d.ts +18 -0
- package/src/service/manager.js +185 -0
- package/src/service/service.d.ts +24 -0
- package/src/service/service.js +200 -0
- package/src/service/swap.d.ts +12 -0
- package/src/service/swap.js +74 -0
- package/src/service/watchdog.d.ts +6 -0
- package/src/service/watchdog.js +31 -0
- package/src/tcp/crowd.d.ts +18 -0
- package/src/tcp/crowd.js +85 -0
- package/src/tcp/dial.d.ts +23 -0
- package/src/tcp/dial.js +102 -0
- package/src/tcp/frame.d.ts +23 -0
- package/src/tcp/frame.js +159 -0
- package/src/tcp/listen.d.ts +50 -0
- package/src/tcp/listen.js +207 -0
- package/src/tcp/source.d.ts +2 -0
- package/src/tcp/source.js +26 -0
- package/src/version/index.d.ts +1 -0
- package/src/version/index.js +2 -0
- package/src/version/version.d.ts +1 -0
- package/src/version/version.js +2 -0
- package/src/work/first.d.ts +11 -0
- package/src/work/first.js +91 -0
- package/src/work/index.d.ts +2 -0
- package/src/work/index.js +15 -0
- package/src/work/work.d.ts +20 -0
- package/src/work/work.js +136 -0
- package/src/ws/dial.d.ts +7 -0
- package/src/ws/dial.js +252 -0
- package/src/ws/dialing.d.ts +50 -0
- package/src/ws/dialing.js +72 -0
- package/src/ws/frame.d.ts +32 -0
- package/src/ws/frame.js +124 -0
- package/src/ws/handshake.d.ts +4 -0
- package/src/ws/handshake.js +27 -0
- package/src/ws/line.d.ts +45 -0
- package/src/ws/line.js +250 -0
- package/src/ws/listen.d.ts +42 -0
- package/src/ws/listen.js +272 -0
- package/src/ws/rfc6455.d.ts +18 -0
- package/src/ws/rfc6455.js +187 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import {
|
|
3
|
+
NO_REST,
|
|
4
|
+
watchedFrom,
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
} from '@nervur.org/genome/seams';
|
|
11
|
+
|
|
12
|
+
import { ringPast } from '../../../src/door/longest.js';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const METHOD = /^[A-Z]+$/;
|
|
17
|
+
const URL_OF_THE_WEB = /^https?:\/\//;
|
|
18
|
+
|
|
19
|
+
export const after = (ms, ring) => {
|
|
20
|
+
const timer = setTimeout(ring, ms);
|
|
21
|
+
timer.unref();
|
|
22
|
+
return () => clearTimeout(timer);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const bodyFor = (first , rest , moved ) => {
|
|
26
|
+
if (!first.more) return first.bytes.length === 0 ? null : first.bytes;
|
|
27
|
+
let given = false;
|
|
28
|
+
return new ReadableStream ({
|
|
29
|
+
pull: async (controller) => {
|
|
30
|
+
if (!given) {
|
|
31
|
+
given = true;
|
|
32
|
+
return controller.enqueue(first.bytes);
|
|
33
|
+
}
|
|
34
|
+
const piece = await rest();
|
|
35
|
+
moved();
|
|
36
|
+
if ('why' in piece) return controller.error(new Error(piece.why));
|
|
37
|
+
if (piece.bytes.length > 0) controller.enqueue(piece.bytes);
|
|
38
|
+
if (!piece.more) controller.close();
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const stillOf = (wait , lapse ) => {
|
|
44
|
+
let stop = ringPast(wait, lapse);
|
|
45
|
+
return {
|
|
46
|
+
moved: () => {
|
|
47
|
+
if (stop === null) return;
|
|
48
|
+
stop();
|
|
49
|
+
stop = ringPast(wait, lapse);
|
|
50
|
+
},
|
|
51
|
+
end: () => {
|
|
52
|
+
stop?.();
|
|
53
|
+
stop = null;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const requested = async (
|
|
59
|
+
request ,
|
|
60
|
+
rest ,
|
|
61
|
+
wait ,
|
|
62
|
+
fill ,
|
|
63
|
+
) => {
|
|
64
|
+
if (!METHOD.test(request.method)) return { why: 'a method is uppercase letters, as GET' };
|
|
65
|
+
if (!URL_OF_THE_WEB.test(request.url)) return { why: 'a URL opens with http:// or https://' };
|
|
66
|
+
const aborting = new AbortController();
|
|
67
|
+
const still = stillOf(wait, () => aborting.abort(new Error(`${request.url} answered nothing within ${wait} ms`)));
|
|
68
|
+
try {
|
|
69
|
+
const body = bodyFor(request.body, rest, still.moved);
|
|
70
|
+
const response = await fetch(request.url, {
|
|
71
|
+
method: request.method,
|
|
72
|
+
headers: request.headers,
|
|
73
|
+
redirect: 'manual',
|
|
74
|
+
signal: aborting.signal,
|
|
75
|
+
...(body === null ? {} : { body, duplex: 'half' }),
|
|
76
|
+
});
|
|
77
|
+
still.end();
|
|
78
|
+
const head = { status: response.status, headers: Object.fromEntries(response.headers) };
|
|
79
|
+
const reader = response.body?.getReader();
|
|
80
|
+
if (reader === undefined)
|
|
81
|
+
return {
|
|
82
|
+
response: { ...head, body: { bytes: new Uint8Array(0), more: false } },
|
|
83
|
+
rest: NO_REST,
|
|
84
|
+
};
|
|
85
|
+
const read = watchedFrom(
|
|
86
|
+
async () => reader.read(),
|
|
87
|
+
wait,
|
|
88
|
+
() => aborting.abort(new Error(`${request.url} stood still for ${wait} ms`)),
|
|
89
|
+
after,
|
|
90
|
+
fill,
|
|
91
|
+
);
|
|
92
|
+
const first = await read.soon();
|
|
93
|
+
return 'why' in first ? first : { response: { ...head, body: first }, rest: read };
|
|
94
|
+
} catch (thrown) {
|
|
95
|
+
still.end();
|
|
96
|
+
if (aborting.signal.aborted) return { why: `${request.url} answered nothing within ${wait} ms` };
|
|
97
|
+
return {
|
|
98
|
+
why: `${request.url}: ${thrown instanceof Error ? thrown.message : String(thrown)}`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Exchange, type WebArrival, type WebRequest, type WebResponse, type WebRest } from '@nervur.org/genome/seams';
|
|
2
|
+
import { type Data } from '@nervur.org/genome/standard';
|
|
3
|
+
import { type Why } from './sent.js';
|
|
4
|
+
export type Web = {
|
|
5
|
+
readonly request: (request: WebRequest, rest: WebRest, wait: number) => Promise<{
|
|
6
|
+
readonly response: WebResponse;
|
|
7
|
+
readonly rest: WebRest;
|
|
8
|
+
} | Why>;
|
|
9
|
+
readonly serve: (endpoint: string, arrived: (exchange: Exchange, request: WebArrival, rest: WebRest) => void) => Promise<{
|
|
10
|
+
readonly origin: string;
|
|
11
|
+
} | Why>;
|
|
12
|
+
readonly respond: (exchange: Exchange, response: WebResponse, rest: WebRest) => void;
|
|
13
|
+
readonly bound: (words: {
|
|
14
|
+
readonly [name: string]: number;
|
|
15
|
+
}) => void;
|
|
16
|
+
readonly close: () => void;
|
|
17
|
+
};
|
|
18
|
+
export declare const textsIn: (data: Data | undefined) => Readonly<Record<string, string>> | null;
|
|
19
|
+
export declare const webOf: (announced: string | null, most?: number) => Web;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { createServer, } from 'node:http';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
piecesFrom,
|
|
7
|
+
WEB_FILL,
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
} from '@nervur.org/genome/seams';
|
|
15
|
+
import { isFields, } from '@nervur.org/genome/standard';
|
|
16
|
+
import { admitted, carried, crowdOf, left } from '../../../src/tcp/crowd.js';
|
|
17
|
+
import { BOUNDS, LONGEST_SPAN, shareOf } from '../../../src/tcp/listen.js';
|
|
18
|
+
import { SOURCE_V6, sourceOf } from '../../../src/tcp/source.js';
|
|
19
|
+
import { after, requested, } from './sent.js';
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
const HELD = 60_000;
|
|
38
|
+
|
|
39
|
+
const ENDPOINT = /^http:\/\/(\[[0-9A-Fa-f:.]+\]|[^\s/?#@[\]:]+):(\d{1,5})$/;
|
|
40
|
+
|
|
41
|
+
export const textsIn = (data ) => {
|
|
42
|
+
if (!isFields(data)) return null;
|
|
43
|
+
const entries = Object.entries(data);
|
|
44
|
+
return entries.every(([, value]) => typeof value === 'string')
|
|
45
|
+
? Object.fromEntries(
|
|
46
|
+
entries.flatMap(([name, value]) => (typeof value === 'string' ? [[name.toLowerCase(), value]] : [])),
|
|
47
|
+
)
|
|
48
|
+
: null;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const plain = (response , status , body ) => {
|
|
52
|
+
if (response.headersSent || response.writableEnded || response.destroyed) return;
|
|
53
|
+
response.writeHead(status, { 'content-type': 'text/plain; charset=utf-8' });
|
|
54
|
+
response.end(body);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const written = (stream , bytes ) =>
|
|
58
|
+
new Promise((done) => {
|
|
59
|
+
if (stream.write(bytes)) return done(null);
|
|
60
|
+
const drained = () => {
|
|
61
|
+
stream.off('close', closed);
|
|
62
|
+
done(null);
|
|
63
|
+
};
|
|
64
|
+
const closed = () => {
|
|
65
|
+
stream.off('drain', drained);
|
|
66
|
+
done({ why: 'the stream closed' });
|
|
67
|
+
};
|
|
68
|
+
stream.once('drain', drained);
|
|
69
|
+
stream.once('close', closed);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const headersOf = (request ) =>
|
|
73
|
+
Object.fromEntries(
|
|
74
|
+
Object.entries(request.headers).flatMap(([name, value]) =>
|
|
75
|
+
value === undefined ? [] : [[name, Array.isArray(value) ? value.join(', ') : value]],
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const pathOf = (url ) => {
|
|
80
|
+
try {
|
|
81
|
+
return decodeURIComponent(url.pathname);
|
|
82
|
+
} catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const dropped = async (request , chunks , wait ) => {
|
|
88
|
+
const still = () => setTimeout(() => request.destroy(), wait);
|
|
89
|
+
for (let timer = still(); ; timer = still()) {
|
|
90
|
+
const next = await chunks.next().catch(() => ({ done: true }));
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
if (next.done === true) return;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
const arrivalsTo =
|
|
104
|
+
(held , arrived ) =>
|
|
105
|
+
(request , response ) => {
|
|
106
|
+
const url = new URL(request.url ?? '/', 'http://organism');
|
|
107
|
+
const path = pathOf(url);
|
|
108
|
+
if (path === null) return plain(response, 400, 'the path is no text');
|
|
109
|
+
const chunks = request[Symbol.asyncIterator]();
|
|
110
|
+
const read = piecesFrom(async () => chunks.next(), after, held.fill);
|
|
111
|
+
response.once('finish', () => request.complete || void dropped(request, chunks, held.wait));
|
|
112
|
+
void read().then((first) => {
|
|
113
|
+
if ('why' in first) return plain(response, 400, first.why);
|
|
114
|
+
const exchange = held.next++;
|
|
115
|
+
held.waiting.set(exchange, response);
|
|
116
|
+
let timer ;
|
|
117
|
+
const waited = () => {
|
|
118
|
+
clearTimeout(timer);
|
|
119
|
+
timer = setTimeout(() => {
|
|
120
|
+
held.waiting.delete(exchange);
|
|
121
|
+
plain(response, 504, 'the organism answered nothing in time');
|
|
122
|
+
}, held.wait);
|
|
123
|
+
};
|
|
124
|
+
waited();
|
|
125
|
+
response.on('close', () => {
|
|
126
|
+
clearTimeout(timer);
|
|
127
|
+
held.waiting.delete(exchange);
|
|
128
|
+
});
|
|
129
|
+
const rest = async () => {
|
|
130
|
+
waited();
|
|
131
|
+
return read();
|
|
132
|
+
};
|
|
133
|
+
const query = url.search.startsWith('?') ? url.search.slice(1) : url.search;
|
|
134
|
+
arrived(
|
|
135
|
+
exchange,
|
|
136
|
+
{
|
|
137
|
+
method: request.method ?? 'GET',
|
|
138
|
+
path,
|
|
139
|
+
query,
|
|
140
|
+
headers: headersOf(request),
|
|
141
|
+
body: first,
|
|
142
|
+
},
|
|
143
|
+
rest,
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const boundOn = (
|
|
149
|
+
server ,
|
|
150
|
+
endpoint ,
|
|
151
|
+
announced ,
|
|
152
|
+
) => {
|
|
153
|
+
const found = ENDPOINT.exec(endpoint);
|
|
154
|
+
if (found?.[1] === undefined || found[2] === undefined || Number(found[2]) > 65_535)
|
|
155
|
+
return Promise.resolve({
|
|
156
|
+
why: `${endpoint} is no web endpoint, http://host:port`,
|
|
157
|
+
});
|
|
158
|
+
const host = found[1].replace(/^\[|\]$/g, '');
|
|
159
|
+
return new Promise((done) => {
|
|
160
|
+
server.once('error', (failed) => done({ why: failed.message }));
|
|
161
|
+
server.listen(Number(found[2]), host, () => {
|
|
162
|
+
const address = server.address();
|
|
163
|
+
const port = typeof address === 'object' && address !== null ? address.port : 0;
|
|
164
|
+
const named = announced ?? host;
|
|
165
|
+
done({
|
|
166
|
+
origin: `http://${named.includes(':') ? `[${named}]` : named}:${port}`,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const respondOn = async (held , exchange , given , rest ) => {
|
|
173
|
+
const response = held.waiting.get(exchange);
|
|
174
|
+
if (response === undefined) return;
|
|
175
|
+
held.waiting.delete(exchange);
|
|
176
|
+
try {
|
|
177
|
+
response.writeHead(given.status, given.headers);
|
|
178
|
+
let piece = given.body;
|
|
179
|
+
for (;;) {
|
|
180
|
+
if ('why' in piece) return void response.destroy();
|
|
181
|
+
const why = await written(response, piece.bytes);
|
|
182
|
+
if (why !== null || !piece.more) break;
|
|
183
|
+
piece = await rest();
|
|
184
|
+
}
|
|
185
|
+
response.end();
|
|
186
|
+
} catch (thrown) {
|
|
187
|
+
plain(response, 502, thrown instanceof Error ? thrown.message : String(thrown));
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export const webOf = (announced , most = BOUNDS.connections) => {
|
|
192
|
+
const held = { waiting: new Map(), next: 1, wait: HELD, fill: WEB_FILL };
|
|
193
|
+
let connections = most;
|
|
194
|
+
let share = shareOf(most);
|
|
195
|
+
let prefix = SOURCE_V6;
|
|
196
|
+
const servers = new Map ();
|
|
197
|
+
const bound = [];
|
|
198
|
+
return {
|
|
199
|
+
request: (request, rest, wait) => requested(request, rest, wait, held.fill),
|
|
200
|
+
serve: (endpoint, arrived) => {
|
|
201
|
+
const kept = servers.get(endpoint);
|
|
202
|
+
if (kept !== undefined) return kept;
|
|
203
|
+
const server = createServer(arrivalsTo(held, arrived));
|
|
204
|
+
const crowd = crowdOf ((socket) => socket.destroy());
|
|
205
|
+
let taken = 0;
|
|
206
|
+
server.on('connection', (socket) => {
|
|
207
|
+
taken += 1;
|
|
208
|
+
if (!admitted(crowd, socket, sourceOf(socket.remoteAddress, taken, prefix), connections, share)) {
|
|
209
|
+
socket.destroy();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
socket.once('close', () => left(crowd, socket));
|
|
213
|
+
});
|
|
214
|
+
server.on('request', (request) => carried(crowd, request.socket));
|
|
215
|
+
const serving = boundOn(server, endpoint, announced).then((found) => {
|
|
216
|
+
if ('why' in found) servers.delete(endpoint);
|
|
217
|
+
else bound.push(server);
|
|
218
|
+
return found;
|
|
219
|
+
});
|
|
220
|
+
servers.set(endpoint, serving);
|
|
221
|
+
return serving;
|
|
222
|
+
},
|
|
223
|
+
respond: (exchange, response, rest) => void respondOn(held, exchange, response, rest),
|
|
224
|
+
bound: (words) => {
|
|
225
|
+
connections = words['connections'] ?? most;
|
|
226
|
+
share = words['connections.share'] ?? shareOf(connections);
|
|
227
|
+
prefix = words['source.v6'] ?? SOURCE_V6;
|
|
228
|
+
held.wait = Math.min(words['wait'] ?? HELD, LONGEST_SPAN);
|
|
229
|
+
held.fill = words['fill'] ?? WEB_FILL;
|
|
230
|
+
},
|
|
231
|
+
close: () => {
|
|
232
|
+
for (const server of bound) server.close();
|
|
233
|
+
for (const response of held.waiting.values()) response.destroy();
|
|
234
|
+
held.waiting.clear();
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
export const SURFACE_TEXT =
|
|
3
|
+
" \n\nexport const SHEET_PATH = '/.nervur/skin/';\n\nexport const WAY_HOST = 'nervur-way-out';\nexport const SAID_HOST = 'nervur-said';\nexport const ASKED_HOST = 'nervur-asked';\nexport const LINK_HOST = 'nervur-link';\n\nexport const lineEdge = (side , px ) => `calc(${px}px + env(safe-area-inset-${side}, 0px))`;\n\nexport const deviceScheme = (host ) => {\n host.style?.setProperty('color-scheme', 'light dark');\n};\n\nexport const LINE_MARGIN = 8;\n\n \n\nexport const madeOf = async (root , href ) => {\n const Sheet = Reflect.get(globalThis, 'CSSStyleSheet');\n const fetching = Reflect.get(globalThis, 'fetch');\n if (typeof Sheet !== 'function' || typeof fetching !== 'function' || !Array.isArray(root.adoptedStyleSheets))\n return undefined;\n try {\n const answer = await Reflect.apply(fetching, globalThis, [href]);\n if (typeof answer !== 'object' || answer === null || Reflect.get(answer, 'ok') !== true) return undefined;\n const text = await Reflect.apply(Reflect.get(answer, 'text'), answer, []);\n const made = Reflect.construct(Sheet, []);\n if (typeof text !== 'string' || typeof made !== 'object' || made === null) return undefined;\n Reflect.apply(Reflect.get(made, 'replaceSync'), made, [text]);\n return made;\n } catch {\n return undefined;\n }\n};\n\nexport const sheetKept = (read , digest , root , href ) => {\n if (read.has(digest)) return;\n void madeOf(root, href).then((made) => {\n if (made !== undefined && !read.has(digest)) read.set(digest, made);\n });\n};\n\n \n\nexport const makeDress = (doc ) => {\n let worn = [];\n const roots = new Map ();\n const told = [];\n const read = new Map ();\n const dressed = (root , one ) => {\n for (const old of one.links.splice(0)) root.removeChild(old);\n const made = worn.flatMap((digest) => read.get(digest) ?? []);\n if (worn.length > 0 && made.length === worn.length) {\n root.adoptedStyleSheets = made;\n for (const [name] of one.bare) one.host.style?.removeProperty(name);\n one.host.style?.removeProperty('visibility');\n for (const tell of told) tell();\n return;\n }\n if (Array.isArray(root.adoptedStyleSheets)) root.adoptedStyleSheets = [];\n for (const [name, value] of one.bare) one.host.style?.setProperty(name, value);\n const first = root.childNodes[0] ?? null;\n let waited = worn.length;\n if (waited > 0) one.host.style?.setProperty('visibility', 'hidden');\n for (const digest of worn) {\n const link = doc.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', `${SHEET_PATH}${digest}.css`);\n link.addEventListener('load', () => {\n sheetKept(read, digest, root, `${SHEET_PATH}${digest}.css`);\n waited -= 1;\n if (waited !== 0 || !one.links.includes(link)) return;\n for (const [name] of one.bare) one.host.style?.removeProperty(name);\n one.host.style?.removeProperty('visibility');\n for (const tell of told) tell();\n });\n link.addEventListener('error', () => {\n if (one.links.includes(link)) one.host.style?.removeProperty('visibility');\n });\n one.links.push(link);\n root.insertBefore(link, first);\n }\n };\n return {\n wear: (sheets ) => {\n if (sheets.join() === worn.join()) return;\n worn = [...sheets];\n for (const [root, one] of roots) dressed(root, one);\n },\n loaded: (tell ) => void told.push(tell),\n on: (root , host , bare = []) => {\n const one = { host, bare, links: [] };\n roots.set(root, one);\n dressed(root, one);\n return () => void roots.delete(root);\n },\n };\n};\n\n \n\n \n \n\nconst ASSET_PATH = '/.nervur/asset/';\nconst KEY_ATTR = 'data-key';\nconst SVG_NS = 'http://www.w3.org/2000/svg';\nexport const PRESSABLE = new Set(['button', 'input', 'select', 'textarea', 'summary']);\nconst CLICKED = new Set(['button', 'summary']);\n\nexport const routeHref = (href ) => {\n if (href === null || !href.startsWith('/') || href.startsWith('//') || href.startsWith('/\\\\')) return null;\n if (href.startsWith('/.nervur/')) return null;\n return href.split(/[?#]/u)[0] ?? null;\n};\n\nexport const isWorld = (href ) =>\n href !== null && (href.startsWith('https://') || href.startsWith('mailto:'));\n\nexport const withinHref = (href ) =>\n href !== null && href.startsWith('#') && href.length > 1 ? href.slice(1) : null;\n\nconst plain = (event ) =>\n (event.button ?? 0) === 0 &&\n event.metaKey !== true &&\n event.ctrlKey !== true &&\n event.shiftKey !== true &&\n event.altKey !== true;\nconst REFUSED = /^(on|style$|srcdoc$)/i;\n\nconst attrText = (value ) => {\n if (value === false) return null;\n if (value === true) return '';\n if (typeof value === 'object') return `${ASSET_PATH}${value.asset}.${value.ext}`;\n return String(value);\n};\n\nexport const attrsOf = (node ) => {\n const attrs = new Map ();\n for (const [name, value] of Object.entries(node.a)) {\n const text = attrText(value);\n if (text !== null) attrs.set(name, text);\n }\n if (node.k !== undefined) attrs.set(KEY_ATTR, node.k);\n return attrs;\n};\n\nconst NAMED_FIELDS = 'input[name], select[name], textarea[name]';\nconst FORM = 'fieldset';\nconst fieldsAround = (el ) => {\n const form = el.closest(FORM);\n if (form !== null) return Array.from(form.querySelectorAll(NAMED_FIELDS));\n return Array.from(el.getRootNode().querySelectorAll(NAMED_FIELDS)).filter((one) => one.closest(FORM) === null);\n};\n\nconst valuesAround = (el ) => {\n const values = {};\n for (const one of fieldsAround(el)) {\n const name = one.getAttribute('name');\n if (name === null || one.type === 'file') continue;\n if (one.type === 'checkbox') values[name] = one.checked === true;\n else if (one.type !== 'radio' || one.checked === true) values[name] = one.value ?? '';\n }\n return values;\n};\n\nconst filesAround = (el ) =>\n fieldsAround(el).flatMap((one) => {\n const name = one.getAttribute('name');\n const chosen = one.type === 'file' ? one.files?.[0] : undefined;\n return name === null || chosen === undefined ? [] : [[name, chosen] ];\n });\nconst sha256Of = async (bytes ) =>\n [...new Uint8Array(await crypto.subtle.digest('SHA-256', bytes))]\n .map((byte) => byte.toString(16).padStart(2, '0'))\n .join('');\nconst factsOf = async (chosen ) => {\n const bytes = new Uint8Array(await chosen.arrayBuffer());\n return { facts: { name: chosen.name, type: chosen.type, size: bytes.length, sha256: await sha256Of(bytes) }, bytes };\n};\n\nconst typedField = (press ) => {\n if (typeof press !== 'object' || press === null || !('method' in press) || press.method !== 'local') return null;\n const args = 'args' in press && typeof press.args === 'object' && press.args !== null ? press.args : null;\n return args !== null && 'field' in args && typeof args.field === 'string' ? args.field : null;\n};\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\nconst held = (node ) => [\n ...(node.shadowRoot === undefined || node.shadowRoot === null ? [] : [node.shadowRoot]),\n ...Array.from(node.childNodes),\n];\n\nconst released = (state , node ) => {\n const id = state.idOf.get(node);\n if (id !== undefined) {\n state.byId.delete(id);\n state.idOf.delete(node);\n state.presses.delete(id);\n if (state.flying.get(id)?.el === node) state.flying.delete(id);\n }\n for (const one of held(node)) released(state, one);\n};\n\nconst attr = (el , name , value ) => {\n if (REFUSED.test(name)) return;\n if (value === null) el.removeAttribute(name);\n else el.setAttribute(name, value);\n};\n\nconst flown = async (state , id , el , press ) => {\n if (state.flying.has(id)) return;\n const flight = { el, own: el.getAttribute('aria-busy') };\n state.flying.set(id, flight);\n el.setAttribute('aria-busy', 'true');\n try {\n await press();\n } finally {\n if (state.flying.get(id) === flight) {\n state.flying.delete(id);\n attr(el, 'aria-busy', flight.own);\n }\n }\n};\n\nconst commit = async (state , id , el ) => {\n const field = typedField(state.presses.get(id));\n if (field !== null) return state.send({ node: id, values: { [field]: el.value ?? '' } });\n if (!state.presses.has(id)) return;\n return flown(state, id, el, async () => {\n const values = valuesAround(el);\n const files = filesAround(el);\n if (files.length === 0) return state.send({ node: id, values });\n const read = await Promise.all(files.map(async ([name, one]) => [name, await factsOf(one)] ));\n return state.send({\n node: id,\n values: { ...values, ...Object.fromEntries(read.map(([name, one]) => [name, one.facts])) },\n files: read.map(([, one]) => one.bytes),\n });\n });\n};\n\nconst register = (state , id , node ) => {\n state.byId.set(id, node);\n state.idOf.set(node, id);\n};\n\nconst SHEET_AT = /\\/\\.nervur\\/skin\\/([0-9a-f]{64})\\.css$/u;\n\nconst harvested = (state , node ) => {\n if (node.localName === 'link') {\n const digest = SHEET_AT.exec(node.getAttribute('href') ?? '')?.[1];\n const root = node.getRootNode();\n if (digest !== undefined) sheetKept(state.read, digest, root, `${SHEET_PATH}${digest}.css`);\n }\n for (const one of held(node)) harvested(state, one);\n};\n\nconst faces = () => {\n const document = Reflect.get(globalThis, 'document');\n const fonts = typeof document === 'object' && document !== null ? Reflect.get(document, 'fonts') : undefined;\n const ready = typeof fonts === 'object' && fonts !== null ? Reflect.get(fonts, 'ready') : undefined;\n return ready instanceof Promise ? ready : undefined;\n};\n\nconst reached = (state , again = true) => {\n const opening = state.opening;\n if (opening === null) return;\n for (const node of state.byId.values())\n if (typeof node.getAttribute === 'function' && node.getAttribute('opens') !== null) {\n node.scrollIntoView?.({ block: 'nearest' });\n break;\n }\n if (again) void faces()?.then(() => (state.opening === opening ? reached(state, false) : undefined));\n};\n\nconst linked = (state , host , root , sheets ) => {\n let waited = sheets.length;\n if (waited === 0) return;\n host.style?.setProperty('visibility', 'hidden');\n const settled = () => {\n waited -= 1;\n if (waited === 0) host.style?.removeProperty('visibility');\n if (state.idOf.has(root)) reached(state);\n };\n for (const digest of sheets) {\n const link = state.doc.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', `${SHEET_PATH}${digest}.css`);\n link.addEventListener('load', () => {\n sheetKept(state.read, digest, root, `${SHEET_PATH}${digest}.css`);\n settled();\n });\n link.addEventListener('error', settled);\n root.insertBefore(link, null);\n }\n};\n\nconst rooted = (state , el , node , at ) => {\n const content = node.s;\n if (content === undefined) return;\n const rootId = at.next;\n at.next += 1;\n const root = el.attachShadow({ mode: 'open' });\n register(state, rootId, root);\n const sheets = node.sheets ?? [];\n const made = sheets.flatMap((digest) => state.read.get(digest) ?? []);\n if (sheets.length > 0 && made.length === sheets.length) root.adoptedStyleSheets = made;\n else linked(state, el, root, sheets);\n root.insertBefore(build(state, content, at), null);\n};\n\nconst namedOf = (el , id ) => {\n if (id === null) return null;\n for (const one of Array.from(el.getRootNode().querySelectorAll('[id]')))\n if (one.getAttribute('id') === id) return one;\n return null;\n};\n\nconst build = (state , node , at , drawn = false) => {\n const id = at.next;\n at.next += 1;\n if (typeof node === 'string') {\n const text = state.doc.createTextNode(node);\n register(state, id, text);\n return text;\n }\n const inSvg = drawn || node.t === 'svg';\n const el = inSvg ? state.doc.createElementNS(SVG_NS, node.t) : state.doc.createElement(node.t);\n register(state, id, el);\n for (const [name, value] of attrsOf(node)) attr(el, name, value);\n if (node.press !== undefined) state.presses.set(id, node.press);\n if (PRESSABLE.has(node.t)) {\n el.addEventListener(CLICKED.has(node.t) ? 'click' : 'change', () => void commit(state, id, el));\n if (!CLICKED.has(node.t))\n el.addEventListener('input', () => {\n const field = typedField(state.presses.get(id));\n if (field !== null) void state.send({ node: id, values: { [field]: el.value ?? '' } });\n });\n }\n if (node.t === 'input')\n el.addEventListener('keydown', (event) => {\n if (event.key !== 'Enter' || event.isComposing === true) return;\n const button = namedOf(el, el.getAttribute('enter'));\n const numbered = button === null ? undefined : state.idOf.get(button);\n if (button === null || numbered === undefined) return;\n event.preventDefault();\n if (button.getAttribute('disabled') === null) void commit(state, numbered, button);\n });\n if (node.t === 'button')\n el.addEventListener('click', () => {\n const copied = namedOf(el, el.getAttribute('copies'));\n if (copied === null) return;\n const field = copied.localName === 'input' || copied.localName === 'textarea';\n state.copy(field ? (copied.value ?? '') : (copied.textContent ?? ''));\n });\n if (node.t === 'a')\n el.addEventListener('click', (event) => {\n const href = el.getAttribute('href');\n if (isWorld(href)) {\n event.preventDefault();\n state.world(href);\n return;\n }\n const within = withinHref(href);\n if (within !== null) {\n event.preventDefault();\n for (const one of Array.from(el.getRootNode().querySelectorAll('[id]')))\n if (one.getAttribute('id') === within) {\n one.scrollIntoView?.();\n break;\n }\n return;\n }\n const path = routeHref(href);\n if (path === null || !plain(event)) return;\n event.preventDefault();\n state.go(path);\n });\n rooted(state, el, node, at);\n for (const child of node.c) el.insertBefore(build(state, child, at, inSvg), null);\n return el;\n};\n\nconst place = (state , parent , node , before ) =>\n void state.byId.get(parent)?.insertBefore(node, before === null ? null : (state.byId.get(before) ?? null));\n\nconst detached = (node ) => void node.parentNode?.removeChild(node);\n\nconst applied = (state , op ) => {\n const at = (id ) => state.byId.get(id);\n switch (op[0]) {\n case 'make':\n place(state, op[1], build(state, op[3], { next: op[4] }, at(op[1])?.namespaceURI === SVG_NS), op[2]);\n return;\n case 'drop':\n case 'forget': {\n const node = at(op[1]);\n if (node === undefined) return;\n detached(node);\n released(state, node);\n return;\n }\n case 'move':\n case 'revive': {\n const node = at(op[2]);\n if (node !== undefined) place(state, op[1], node, op[3]);\n return;\n }\n case 'park': {\n const node = at(op[1]);\n if (node !== undefined) detached(node);\n return;\n }\n case 'attr': {\n const node = at(op[1]);\n const flight = state.flying.get(op[1]);\n if (flight !== undefined && flight.el === node && op[2] === 'aria-busy') flight.own = op[3];\n else if (node !== undefined) attr(node, op[2], op[3]);\n return;\n }\n case 'text': {\n const node = at(op[1]);\n if (node !== undefined) node.data = op[2];\n return;\n }\n case 'press':\n if (op[2] === null) state.presses.delete(op[1]);\n else state.presses.set(op[1], op[2]);\n }\n};\n\nexport const makeSurface = (\n doc ,\n send ,\n go ,\n world ,\n copy = () => undefined,\n) => {\n let fontLink = null;\n const state = {\n doc,\n send,\n go,\n world,\n copy,\n byId: new Map([[0, doc.body]]),\n idOf: new Map([[doc.body, 0]]),\n presses: new Map(),\n flying: new Map(),\n opening: null,\n read: new Map(),\n };\n for (const type of ['wheel', 'touchstart', 'pointerdown', 'keydown'])\n doc.body.addEventListener(type, () => void (state.opening = null), { passive: true });\n return {\n apply: (ops , opens = false) => {\n for (const op of ops) applied(state, op);\n if (!opens) return;\n state.opening = {};\n reached(state);\n },\n reset: () => {\n for (const node of held(doc.body)) {\n harvested(state, node);\n detached(node);\n released(state, node);\n }\n state.presses.clear();\n state.flying.clear();\n },\n fonts: (digest ) => {\n if (digest === undefined) {\n if (fontLink !== null) detached(fontLink);\n fontLink = null;\n return;\n }\n if (fontLink === null) {\n fontLink = doc.createElement('link');\n fontLink.setAttribute('rel', 'stylesheet');\n for (const type of ['load', 'error']) fontLink.addEventListener(type, () => reached(state));\n doc.head.insertBefore(fontLink, null);\n }\n fontLink.setAttribute('href', `${SHEET_PATH}${digest}.css`);\n },\n pressAt: (id ) => state.presses.get(id),\n press: async (control ) => {\n const id = state.idOf.get(control);\n if (id !== undefined && control.getAttribute('disabled') === null) await commit(state, id, control);\n },\n morphs: () => {\n const named = new Map ();\n for (const node of state.byId.values()) {\n const name = typeof node.getAttribute === 'function' ? node.getAttribute('morph') : null;\n if (name !== null) named.set(name, node);\n }\n return named;\n },\n deadlines: () => {\n const counted = new Map ();\n for (const node of state.byId.values()) {\n const deadline = node.localName === 'time' ? node.getAttribute('deadline') : null;\n if (deadline !== null) counted.set(node, deadline);\n }\n return counted;\n },\n instants: () => {\n const asked = new Map ();\n for (const node of state.byId.values()) {\n const datetime =\n node.localName === 'time' && node.getAttribute('deadline') === null ? node.getAttribute('datetime') : null;\n if (datetime !== null) asked.set(node, { datetime, shows: node.getAttribute('shows') });\n }\n return asked;\n },\n nodeAt: (id ) => state.byId.get(id),\n };\n};\n\nconst UNDRESSED = () => undefined;\n\nconst CORNERS = Object.fromEntries(\n (['top', 'bottom'] ).flatMap((high) =>\n (['start', 'end'] ).map((side) => {\n const across = side === 'start' ? 'left' : 'right';\n return [\n `${high}-${side}`,\n [\n [high, lineEdge(high, LINE_MARGIN)],\n [across, lineEdge(across, LINE_MARGIN)],\n ],\n ] ;\n }),\n ),\n);\n\nexport const makeWay = (\n doc ,\n leave ,\n press ,\n dress ,\n) => {\n let leavingFlies = false;\n let host = null;\n let seat = null;\n const controls = [null, null];\n let leaving ;\n let bared = UNDRESSED;\n const root = doc.documentElement ?? doc.body;\n const button = (at , words , click ) => {\n if (seat === null) return;\n let control = controls[at] ?? null;\n if (words === undefined) {\n if (control !== null) seat.removeChild(control);\n controls[at] = null;\n return;\n }\n if (control === null) {\n control = doc.createElement('button');\n control.setAttribute('type', 'button');\n control.addEventListener('click', (event) => {\n event.preventDefault();\n click();\n });\n const after = at === 0 ? Array.from(seat.childNodes).find((one) => one.localName !== 'link') : undefined;\n seat.insertBefore(control, after ?? null);\n controls[at] = control;\n }\n while (control.childNodes.length > 0) {\n const first = control.childNodes[0];\n if (first !== undefined) control.removeChild(first);\n }\n control.insertBefore(doc.createTextNode(words), null);\n };\n const lay = (way ) => {\n if (way === null) {\n if (host !== null) root.removeChild(host);\n bared();\n host = null;\n seat = null;\n controls[0] = null;\n controls[1] = null;\n leaving = undefined;\n return;\n }\n if (host === null || seat === null) {\n host = doc.createElement(WAY_HOST);\n host.setAttribute('popover', 'manual');\n deviceScheme(host);\n seat = host.attachShadow({ mode: 'open' });\n bared = dress.on(seat, host);\n root.insertBefore(host, null);\n host.showPopover?.();\n }\n leaving = way.leave;\n button(0, way.say, leave);\n button(1, way.leave?.say, () => {\n const control = controls[1];\n if (leaving === undefined || control === null || leavingFlies) return;\n leavingFlies = true;\n control.setAttribute('aria-busy', 'true');\n void Promise.resolve(press({ way: leaving.press, values: {} })).finally(() => {\n leavingFlies = false;\n control.removeAttribute('aria-busy');\n });\n });\n const style = host.style;\n for (const name of ['top', 'right', 'bottom', 'left']) style?.setProperty(name, 'auto');\n style?.setProperty('position', 'fixed');\n style?.setProperty('margin', '0');\n style?.setProperty('padding', '0');\n style?.setProperty('border', '0');\n style?.setProperty('background', 'transparent');\n for (const [name, value] of CORNERS[way.at] ?? []) style?.setProperty(name, value);\n };\n return { lay };\n};\n\n \n\nexport const makeAsked = (\n doc ,\n dress ,\n) => {\n let host = null;\n let bared = UNDRESSED;\n const root = doc.documentElement ?? doc.body;\n const close = () => {\n if (host !== null) root.removeChild(host);\n bared();\n host = null;\n };\n return (asking, yes) => {\n close();\n host = doc.createElement(ASKED_HOST);\n host.setAttribute('popover', 'manual');\n deviceScheme(host);\n const box = doc.createElement('div');\n box.setAttribute('role', 'alertdialog');\n box.setAttribute('aria-modal', 'true');\n const said = doc.createElement('p');\n said.insertBefore(doc.createTextNode(asking.say), null);\n box.insertBefore(said, null);\n const button = (words , run ) => {\n const made = doc.createElement('button');\n made.setAttribute('type', 'button');\n made.insertBefore(doc.createTextNode(words), null);\n made.addEventListener('click', (event) => {\n event.preventDefault();\n close();\n run();\n });\n box.insertBefore(made, null);\n return made;\n };\n const no = button(asking.no, () => undefined);\n button(asking.yes, yes);\n box.addEventListener('keydown', (event) => {\n if (event.key !== 'Escape') return;\n event.preventDefault();\n close();\n });\n const seat = host.attachShadow({ mode: 'open' });\n seat.insertBefore(box, null);\n bared = dress.on(seat, host);\n root.insertBefore(host, null);\n host.showPopover?.();\n no.focus?.();\n };\n};\n\nexport const makeSaid = (\n doc ,\n dress ,\n) => {\n let host = null;\n let bared = UNDRESSED;\n const root = doc.documentElement ?? doc.body;\n return (words) => {\n if (host !== null) root.removeChild(host);\n bared();\n host = null;\n if (words === null) return;\n host = doc.createElement(SAID_HOST);\n host.setAttribute('popover', 'manual');\n deviceScheme(host);\n const said = doc.createElement('p');\n said.setAttribute('role', 'alert');\n said.insertBefore(doc.createTextNode(words), null);\n const seat = host.attachShadow({ mode: 'open' });\n seat.insertBefore(said, null);\n bared = dress.on(seat, host);\n root.insertBefore(host, null);\n host.showPopover?.();\n };\n};\n\n \n\n \n\nconst SECOND = 1000;\nconst two = (count ) => String(count).padStart(2, '0');\n\nexport const leftOf = (deadline , now ) => {\n const left = Math.max(0, Math.ceil((deadline - now) / SECOND));\n const [hours, minutes, seconds] = [Math.floor(left / 3600), Math.floor(left / 60) % 60, left % 60];\n return hours > 0 ? `${hours}:${two(minutes)}:${two(seconds)}` : `${minutes}:${two(seconds)}`;\n};\n\nexport const makeCountdown = (doc , deadlines , clock ) => {\n const shown = new Map ();\n let asked = 0;\n const count = () => {\n const now = clock.now();\n const standing = deadlines();\n let next = Infinity;\n for (const [el, text] of shown)\n if (!standing.has(el)) {\n if (text.parentNode === el) el.removeChild(text);\n shown.delete(el);\n }\n for (const [el, deadline] of standing) {\n const at = Date.parse(deadline);\n const words = Number.isFinite(at) ? leftOf(at, now) : '';\n let text = shown.get(el);\n if (text === undefined || text.parentNode !== el) {\n text = doc.createTextNode(words);\n el.insertBefore(text, el.childNodes[0] ?? null);\n shown.set(el, text);\n } else if (text.data !== words) text.data = words;\n if (at > now) next = Math.min(next, (at - now) % SECOND || SECOND);\n }\n asked += 1;\n const mine = asked;\n if (next !== Infinity)\n clock.later(() => {\n if (mine === asked) count();\n }, next);\n };\n return { count };\n};\n\n \n\n \n\nconst RFC3339 = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:\\d{2})$/iu;\n\nexport const instantWords = (\n datetime ,\n shows ,\n language ,\n zone ,\n) => {\n const at = RFC3339.test(datetime) ? Date.parse(datetime) : Number.NaN;\n if (!Number.isFinite(at)) return null;\n const parts =\n shows === 'day'\n ? { dateStyle: 'medium' }\n : shows === 'time'\n ? { hour: 'numeric', minute: '2-digit' }\n : { dateStyle: 'medium', timeStyle: 'short' };\n try {\n return new Intl.DateTimeFormat(language, { ...parts, ...(zone === undefined ? {} : { timeZone: zone }) }).format(\n at,\n );\n } catch {\n return null;\n }\n};\n\nexport const makeInstants = (\n doc ,\n instants ,\n language ,\n zone ,\n) => {\n const shown = new Map ();\n const drop = (el ) => {\n const text = shown.get(el);\n if (text?.parentNode === el) el.removeChild(text);\n shown.delete(el);\n };\n const write = () => {\n const standing = instants();\n for (const el of shown.keys()) if (!standing.has(el)) drop(el);\n for (const [el, { datetime, shows }] of standing) {\n const own = shown.get(el);\n const lobes = Array.from(el.childNodes).filter((one) => one !== own);\n const words = lobes.length > 0 ? null : instantWords(datetime, shows, language(), zone);\n if (words === null) {\n drop(el);\n continue;\n }\n if (own === undefined || own.parentNode !== el) {\n const text = doc.createTextNode(words);\n el.insertBefore(text, el.childNodes[0] ?? null);\n shown.set(el, text);\n } else if (own.data !== words) own.data = words;\n }\n };\n return { write };\n};\n\n \n\nconst DIGEST = /^[0-9a-f]{64}$/u;\nconst KINDS = new Set(['enter', 'leave', 'move', 'change']);\n\nconst movingOf = (read ) => {\n if (!Array.isArray(read)) return null;\n const found = [];\n for (const one of read) {\n if (!Array.isArray(one) || one.length !== 4) return null;\n const [node, kind, duration, easing] = one;\n if (typeof node !== 'number' || !KINDS.has(kind) || typeof duration !== 'number' || typeof easing !== 'string')\n return null;\n found.push([node, kind, duration, easing]);\n }\n return found;\n};\n\nconst SHAPES = new Map(\n Object.entries({\n make: 'nixn',\n drop: 'n',\n move: 'nni',\n park: 'n',\n revive: 'nni',\n forget: 'n',\n attr: 'nst',\n text: 'ns',\n press: 'nx',\n }),\n);\nconst OF_KIND = {\n n: (field) => typeof field === 'number',\n i: (field) => field === null || typeof field === 'number',\n s: (field) => typeof field === 'string',\n t: (field) => field === null || typeof field === 'string',\n x: (field) => field !== undefined,\n};\n\nconst isOp = (op ) => {\n const shape = Array.isArray(op) && typeof op[0] === 'string' ? SHAPES.get(op[0]) : undefined;\n return (\n shape !== undefined &&\n Array.isArray(op) &&\n op.length === shape.length + 1 &&\n Array.from(shape).every((kind, at) => OF_KIND[kind]?.(op[at + 1]) === true)\n );\n};\n\nconst homeOf = (read ) => {\n const home = 'home' in read ? read.home : undefined;\n if (!Array.isArray(home)) return undefined;\n const digests = home.filter((one) => typeof one === 'string' && DIGEST.test(one));\n return digests.length === home.length ? digests : undefined;\n};\n\nconst leaveOf = (read ) => {\n if (typeof read !== 'object' || read === null || !('press' in read) || !('say' in read)) return undefined;\n const { press, say } = read;\n if (typeof press !== 'object' || press === null || Array.isArray(press)) return undefined;\n if (typeof say !== 'string' || say === '') return undefined;\n return { press: Object.fromEntries(Object.entries(press)), say };\n};\n\nconst wayOf = (read ) => {\n if (!('way' in read)) return undefined;\n const way = read.way;\n if (typeof way !== 'object' || way === null || !('at' in way && typeof way.at === 'string')) return null;\n const say = 'say' in way ? way.say : undefined;\n if (say !== undefined && typeof say !== 'string') return null;\n const leave = 'leave' in way ? leaveOf(way.leave) : undefined;\n if (say === undefined && leave === undefined) return null;\n return {\n at: way.at,\n ...(say === undefined ? {} : { say }),\n ...(leave === undefined ? {} : { leave }),\n };\n};\n\nconst worldWordsOf = (read ) => {\n if (!('world' in read)) return undefined;\n const world = read.world;\n if (typeof world !== 'object' || world === null) return null;\n const [say, yes, no] = ['say', 'yes', 'no'].map((name) => (name in world ? Reflect.get(world, name) : undefined));\n if (typeof say !== 'string' || typeof yes !== 'string' || typeof no !== 'string') return null;\n return say.includes('{href}') && yes !== '' && no !== '' ? { say, yes, no } : null;\n};\n\nexport const messageOf = (text ) => {\n let read ;\n try {\n read = JSON.parse(text);\n } catch {\n return null;\n }\n if (typeof read !== 'object' || read === null || !('ops' in read) || !Array.isArray(read.ops)) return null;\n const ops = [];\n for (const op of read.ops) {\n if (!isOp(op)) return null;\n ops.push(op);\n }\n const way = wayOf(read);\n const world = worldWordsOf(read);\n const home = homeOf(read);\n const motion = 'motion' in read ? movingOf(read.motion) : [];\n const fonts = 'fonts' in read && typeof read.fonts === 'string' && DIGEST.test(read.fonts) ? read.fonts : undefined;\n return motion === null\n ? null\n : {\n whole: 'whole' in read && read.whole === true,\n opens: 'opens' in read && read.opens === true,\n ops,\n motion,\n ...(fonts === undefined ? {} : { fonts }),\n ...(way === undefined ? {} : { way }),\n ...(world === undefined ? {} : { world }),\n ...(home === undefined ? {} : { home }),\n };\n};\n\n \n\n \n\nconst elementOf = (node ) =>\n node === undefined || typeof node.animate === 'function'\n ? node\n : node.parentNode?.animate === undefined\n ? undefined\n : node.parentNode;\n\nconst FADES = {\n enter: [{ opacity: 0 }, { opacity: 1 }],\n change: [{ opacity: 0.4 }, { opacity: 1 }],\n leave: [{ opacity: 1 }, { opacity: 0 }],\n} ;\n\nexport const makeMotion = (nodeAt , morphs ) => ({\n before: async (motion ) => {\n const rects = new Map ();\n if (motion.length > 0)\n for (const [name, el] of morphs()) {\n const at = el.getBoundingClientRect?.();\n if (at !== undefined)\n rects.set(name, { left: at.left, top: at.top, width: at.width ?? 1, height: at.height ?? 1, el });\n }\n const fading = [];\n for (const [id, kind, duration, easing] of motion) {\n const target = elementOf(nodeAt(id));\n if (target === undefined) continue;\n if (kind === 'leave')\n fading.push(\n target.animate?.(FADES.leave, { duration, easing, fill: 'forwards' }).finished ?? Promise.resolve(),\n );\n const at = kind === 'move' ? target.getBoundingClientRect?.() : undefined;\n if (at !== undefined) rects.set(id, { left: at.left, top: at.top });\n }\n await Promise.all(fading.map((one) => one.catch(() => undefined)));\n return rects;\n },\n after: (motion , rects ) => {\n const flown = new Set ();\n if (motion.length > 0) {\n const flight = motion.reduce((most, one) => (one[2] > most[2] ? one : most));\n for (const [name, el] of morphs()) {\n const was = rects.get(name);\n const now = el.getBoundingClientRect?.();\n if (was === undefined || was.el === el || now === undefined) continue;\n flown.add(el);\n const scale = `scale(${(was.width ?? 1) / (now.width ?? 1)}, ${(was.height ?? 1) / (now.height ?? 1)})`;\n el.animate?.(\n [\n {\n transformOrigin: 'top left',\n transform: `translate(${was.left - now.left}px, ${was.top - now.top}px) ${scale}`,\n },\n { transformOrigin: 'top left', transform: 'none' },\n ],\n { duration: flight[2], easing: flight[3] },\n );\n }\n }\n for (const [id, kind, duration, easing] of motion) {\n const target = elementOf(nodeAt(id));\n if (target === undefined || kind === 'leave' || flown.has(target)) continue;\n const was = rects.get(id);\n const now = kind === 'move' ? target.getBoundingClientRect?.() : undefined;\n if (kind !== 'move') target.animate?.(FADES[kind], { duration, easing });\n else if (was !== undefined && now !== undefined && (was.left !== now.left || was.top !== now.top))\n target.animate?.(\n [{ transform: `translate(${was.left - now.left}px, ${was.top - now.top}px)` }, { transform: 'none' }],\n { duration, easing },\n );\n }\n },\n});\n\n \n\nconst HOLD = 500;\nconst BEGUN = 10;\nconst SWIPED = 64;\nconst SETTLE = { duration: 200, easing: 'ease-out' };\n\nconst FIELDS = new Set(['input', 'select', 'textarea']);\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n\nconst named = (one , name ) =>\n typeof one.getAttribute === 'function' ? one.getAttribute(name) : null;\n\nconst control = (el , id ) =>\n id === null\n ? undefined\n : named(el, 'id') === id\n ? el\n : Array.from(el.querySelectorAll('[id]')).find((one) => named(one, 'id') === id);\n\nconst gestured = (one ) =>\n ['swipe-left', 'swipe-right', 'swipe-up', 'swipe-down', 'hold', 'drag'].some((name) => named(one, name) !== null);\n\nconst atTop = (path ) => path.every((one) => (one.scrollTop ?? 0) <= 0);\n\nconst dropAt = (el , select , x , y ) => {\n const offered = new Set(Array.from(select.querySelectorAll('option')).map((one) => one.value));\n let found = null;\n for (const one of Array.from(el.getRootNode().querySelectorAll('[drop]'))) {\n const value = named(one, 'drop');\n if (value === null || !offered.has(value)) continue;\n let inside = false;\n for (let up = one; up !== null && !inside; up = up.parentNode) inside = up === el;\n const at = one.getBoundingClientRect?.();\n if (\n !inside &&\n at !== undefined &&\n x >= at.left &&\n x <= (at.right ?? at.left) &&\n y >= at.top &&\n y <= (at.bottom ?? at.top)\n )\n found = value;\n }\n return found;\n};\n\nexport const makeGestures = (hands ) => {\n const { body, reduced, later, press } = hands;\n const root = body.getRootNode();\n let hand = null;\n let swallow = false;\n const ended = () => {\n swallow = true;\n later(() => {\n swallow = false;\n }, 0);\n };\n const moved = (el , x , y ) => {\n if (!reduced()) el.style?.setProperty('transform', `translate(${x}px, ${y}px)`);\n };\n const settled = (el , x , y ) => {\n if (reduced()) return;\n el.style?.setProperty('transform', 'none');\n el.animate?.([{ transform: `translate(${x}px, ${y}px)` }, { transform: 'none' }], SETTLE);\n };\n const begin = (one , x , y , path ) => {\n const horizontal = Math.abs(x) > Math.abs(y);\n const direction = horizontal ? (x < 0 ? 'left' : 'right') : y < 0 ? 'up' : 'down';\n const swiped = control(one.el, named(one.el, `swipe-${direction}`));\n if (swiped !== undefined && (direction !== 'down' || atTop(path))) {\n one.moving = { kind: 'swipe', control: swiped };\n } else {\n const dragged = control(one.el, named(one.el, 'drag'));\n if (dragged === undefined) {\n hand = null;\n return;\n }\n one.moving = { kind: 'drag', control: dragged };\n }\n one.waiting = false;\n };\n body.addEventListener('pointerdown', (event) => {\n swallow = false;\n hand = null;\n if ((event.button ?? 0) !== 0 || event.isPrimary === false) return;\n const path = event.composedPath?.() ?? [];\n for (const one of path) {\n if (FIELDS.has(one.localName ?? '')) return;\n if (!gestured(one)) continue;\n const taken = {\n el: one,\n x: event.clientX ?? 0,\n y: event.clientY ?? 0,\n moving: null,\n waiting: named(one, 'hold') !== null,\n };\n hand = taken;\n if (taken.waiting)\n later(() => {\n if (hand !== taken || !taken.waiting) return;\n const held = control(taken.el, named(taken.el, 'hold'));\n hand = null;\n ended();\n if (held !== undefined) press(held);\n }, HOLD);\n return;\n }\n });\n root.addEventListener('pointermove', (event) => {\n if (hand === null) return;\n const x = (event.clientX ?? 0) - hand.x;\n const y = (event.clientY ?? 0) - hand.y;\n if (hand.moving === null) {\n if (Math.hypot(x, y) < BEGUN) return;\n hand.waiting = false;\n begin(hand, x, y, event.composedPath?.() ?? []);\n }\n if (hand?.moving === null || hand === null) return;\n const across = Math.abs(x) > Math.abs(y);\n moved(hand.el, hand.moving.kind === 'drag' || across ? x : 0, hand.moving.kind === 'drag' || !across ? y : 0);\n });\n root.addEventListener('pointerup', (event) => {\n const one = hand;\n hand = null;\n if (one === null || one.moving === null) return;\n const x = (event.clientX ?? 0) - one.x;\n const y = (event.clientY ?? 0) - one.y;\n ended();\n if (one.moving.kind === 'swipe') {\n if (Math.hypot(x, y) >= SWIPED) press(one.moving.control);\n } else {\n const dropped = dropAt(one.el, one.moving.control, event.clientX ?? 0, event.clientY ?? 0);\n if (dropped !== null) {\n one.moving.control.value = dropped;\n press(one.moving.control);\n }\n }\n settled(one.el, x, y);\n });\n root.addEventListener('pointercancel', () => {\n if (hand?.moving !== null && hand !== null) settled(hand.el, 0, 0);\n hand = null;\n });\n const held = (event ) => {\n if (hand !== null) event.preventDefault();\n };\n body.addEventListener(\n 'touchmove',\n (event) => {\n if (hand?.moving !== null && hand !== null) event.preventDefault();\n },\n { passive: false },\n );\n body.addEventListener('contextmenu', held);\n body.addEventListener('dragstart', held);\n body.addEventListener(\n 'click',\n (event) => {\n if (!swallow) return;\n swallow = false;\n event.preventDefault();\n event.stopPropagation?.();\n },\n true,\n );\n};\n\n \n \n \n\nexport const whyOf = (answer ) => ('error' in answer ? answer.error.message : null);\n\n \nexport const fieldsOf = (value ) =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n ? Object.fromEntries(Object.entries(value))\n : null;\n\nexport const answerOf = (value ) => {\n const fields = fieldsOf(value);\n if (fields === null) return null;\n if ('result' in fields) return { result: fields['result'] };\n const failure = fieldsOf(fields['error']);\n return failure !== null && typeof failure['code'] === 'string' && typeof failure['message'] === 'string'\n ? { error: { code: failure['code'], message: failure['message'] } }\n : null;\n};\n\n \n\nexport const SKIN_SHEETS = '/.nervur/skin/';\n\nexport const LOBE = 'nervur-lobe';\n\nexport const made = (doc , tag , text , attrs = {}) => {\n const one = doc.createElement(tag);\n for (const [name, value] of Object.entries(attrs)) one.setAttribute(name, value);\n if (text !== null) one.insertBefore(doc.createTextNode(text), null);\n return one;\n};\n\nexport const emptied = (target ) => {\n while (target.childNodes.length > 0) {\n const first = target.childNodes[0];\n if (first === undefined) break;\n target.removeChild(first);\n }\n};\n\n \n\nexport const mark = (target , state , why ) => {\n target.setAttribute('data-quo', state);\n if (why === undefined) target.removeAttribute('data-quo-why');\n else target.setAttribute('data-quo-why', why);\n};\n\n \n\n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\nexport const ENGLISH = {\n reading: 'Reading your invitation…',\n invited: '{domain} has invited you',\n invitedNamed: 'A place that says it is at \"{named}\" has invited you',\n invitedUnnamed: 'A place no website stands for has invited you',\n vouched: '{domain} says this place is its own. If you accept, it is added beside you, and you can leave it later.',\n named:\n 'That is its own word: no website stands for it, so accept only if you trust whoever sent you the link. Its key begins {key}. If you accept, it is added beside you, and you can leave it later.',\n unnamed:\n 'It names no website and no address, so accept only if you trust whoever sent you the link. Its key begins {key}. If you accept, it is added beside you, and you can leave it later.',\n accept: 'Accept',\n decline: 'Not now',\n tryAgain: 'Try again',\n close: 'Close',\n untaken: 'The invitation could not be taken: your organism did not answer. You can try again.',\n unread: 'The invitation could not be read.',\n storeMayGo:\n 'This browser may clear what your organism holds, when its space runs short or after a long time unvisited. You can keep it by moving it to an app of your own.',\n unkept:\n 'This browser keeps nothing for this site in this window, as a private window does, so your organism cannot wake here. Open the page in a window that is not private, or allow this site to keep its data, and come back.',\n says: 'It says, in its own words, which nothing here proves:',\n saysMore: 'It says more than is shown here.',\n waits: 'This invitation stands for {span} more.',\n lives: 'If you accept, it stays beside you for {span}.',\n unreached:\n 'The place this link names did not answer just now, so what it offers cannot be read. You can still accept: if it is still not reached, nothing is added and you are told.',\n days: { '1': 'a day', other: '{count} days' },\n hours: { '1': 'an hour', other: '{count} hours' },\n minutes: { '1': 'a minute', other: '{count} minutes' },\n underMinute: 'less than a minute',\n leaves: 'This link leaves the screen and leads to {href}.',\n openLink: 'Open it',\n stay: 'Stay here',\n};\n\nexport const filled = (word , values ) =>\n word.replaceAll(/\\{([a-z]+)\\}/gu, (found, name ) =>\n Object.hasOwn(values, name) ? (values[name] ?? found) : found,\n );\n\nexport const askingOf = (href , world ) => ({\n say: filled(world?.say ?? ENGLISH.leaves, { href }),\n yes: world?.yes ?? ENGLISH.openLink,\n no: world?.no ?? ENGLISH.stay,\n});\n\nexport const counted = (word , count ) =>\n filled((Object.hasOwn(word, String(count)) ? word[String(count)] : undefined) ?? word.other, {\n count: String(count),\n });\n\nconst MINUTE = 60_000;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\n\nexport const spanSaid = (ms , words ) => {\n if (ms >= DAY) return counted(words.days, Math.floor(ms / DAY));\n if (ms >= HOUR) return counted(words.hours, Math.floor(ms / HOUR));\n return ms >= MINUTE ? counted(words.minutes, Math.floor(ms / MINUTE)) : words.underMinute;\n};\n\n \n \n\nconst SAID_LINES = 8;\nconst SAID_LONGEST = 200;\n\n \n\nexport const cutTo = (text , most ) => {\n const points = Array.from(text);\n return points.length <= most ? { text, cut: false } : { text: points.slice(0, most).join(''), cut: true };\n};\n\nexport const saidLines = (says ) => {\n const raw =\n typeof says === 'string'\n ? says.split(/\\r\\n|\\r|\\n/u)\n : typeof says === 'number'\n ? [String(says)]\n : typeof says === 'object' && says !== null && !Array.isArray(says) && !(says instanceof Uint8Array)\n ? Object.entries(says).flatMap(([name, value]) =>\n typeof value === 'string' || typeof value === 'number' ? [`${name}: ${String(value)}`] : [],\n )\n : [];\n const plain = raw.map((one) => one.replaceAll(/\\s+/gu, ' ').trim()).filter((one) => one !== '');\n const lines = plain.slice(0, SAID_LINES).map((one) => {\n const kept = cutTo(one, SAID_LONGEST);\n return kept.cut ? `${kept.text}…` : kept.text;\n });\n return { lines, more: plain.length > SAID_LINES };\n};\n\nconst offerDrawn = (doc , words , offer ) => {\n const parts = [];\n const { lines, more } = saidLines(offer.says);\n if (lines.length > 0) {\n const list = made(doc, 'ul', null, { 'data-quo-offer': 'says' });\n for (const line of lines) list.insertBefore(made(doc, 'li', line), null);\n if (more) list.insertBefore(made(doc, 'li', words.saysMore, { 'data-quo-offer': 'more' }), null);\n parts.push(made(doc, 'p', words.says, { 'data-quo-offer': 'intro' }), list);\n }\n for (const [mark, span, word] of [\n ['waits', offer.waits, words.waits],\n ['lives', offer.lives, words.lives],\n ] )\n if (span !== null)\n parts.push(made(doc, 'p', filled(word, { span: spanSaid(span, words) }), { 'data-quo-offer': mark }));\n return parts;\n};\n\nexport const offerSaid = (doc , words , offer ) =>\n offer === null\n ? []\n : 'reached' in offer\n ? [made(doc, 'p', words.unreached, { 'data-quo-offer': 'unreached', role: 'status' })]\n : offerDrawn(doc, words, offer);\n\n \n \n\n \n\nconst WARD_SHOWN = 8;\n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n\nexport const wordsOf = (inviter , words ) => {\n const values = {\n domain: inviter.domain ?? '',\n named: inviter.named ?? '',\n key: inviter.ward.slice(0, WARD_SHOWN),\n };\n const [title, body] =\n inviter.domain !== null\n ? [words.invited, words.vouched]\n : inviter.named === null\n ? [words.invitedUnnamed, words.unnamed]\n : [words.invitedNamed, words.named];\n return { title: filled(title, values), body: filled(body, values) };\n};\n\nconst sheetLinks = (doc , digests ) =>\n digests.map((digest) => made(doc, 'link', null, { rel: 'stylesheet', href: `${SKIN_SHEETS}${digest}.css` }));\n\nconst hosted = (\n room ,\n content ,\n) => {\n const lobe = made(room.doc, LOBE, null);\n const root = lobe.attachShadow({ mode: 'open' });\n const linked = room.wear === undefined ? sheetLinks(room.doc, room.sheets) : [];\n for (const link of linked) root.insertBefore(link, null);\n root.insertBefore(content, null);\n emptied(room.container);\n room.container.insertBefore(lobe, null);\n return {\n dress: (now) => {\n if (room.wear !== undefined) return;\n for (const old of linked.splice(0)) root.removeChild(old);\n for (const link of sheetLinks(room.doc, now)) {\n linked.push(link);\n root.insertBefore(link, content);\n }\n },\n off: room.wear?.(root, lobe) ?? (() => undefined),\n };\n};\n\nconst formed = (\n doc ,\n card ,\n yesIs ,\n noIs ,\n) => {\n const form = made(doc, 'form', null, { 'data-quo-card': card.kind });\n for (const child of card.children) form.insertBefore(child, null);\n form.insertBefore(made(doc, 'button', card.yes, { type: 'submit' }), null);\n if (card.no !== null) {\n const refuse = made(doc, 'button', card.no, { type: 'button' });\n refuse.addEventListener('click', noIs);\n form.insertBefore(refuse, null);\n }\n form.addEventListener('submit', (event) => {\n event.preventDefault();\n yesIs();\n });\n return form;\n};\n\nconst consentParts = (\n room ,\n words ,\n { inviter, offer } ,\n) => {\n const { title, body } = wordsOf(inviter, words);\n return [made(room.doc, 'h1', title), made(room.doc, 'p', body), ...offerSaid(room.doc, words, offer)];\n};\n\nexport const makeVoice = (room , words ) => {\n const { doc } = room;\n const element = (tag , text , attrs = {}) =>\n made(doc, tag, text, attrs);\n const none = { dress: (_sheets ) => undefined, off: () => undefined };\n let dressing = none;\n room.onSheets?.((now) => dressing.dress(now));\n const host = (content ) => {\n dressing.off();\n dressing = hosted(room, content);\n };\n const card = (\n kind ,\n children ,\n yes ,\n no ,\n yesIs ,\n noIs ,\n ) =>\n new Promise((resolve) =>\n host(\n formed(\n doc,\n { kind, children, yes, no },\n () => resolve(yesIs()),\n () => resolve(noIs),\n ),\n ),\n );\n return {\n loading: () =>\n host(element('p', words.reading, { 'data-quo-card': 'reading', role: 'status', 'aria-busy': 'true' })),\n consent: (inviter, offer) =>\n card('consent', consentParts(room, words, { inviter, offer }), words.accept, words.decline, () => true, false),\n again: (said) => card('again', [element('p', said)], words.tryAgain, words.close, () => true, false),\n say: (said, label) => card ('said', [element('p', said)], label, null, () => undefined, undefined),\n none: () => {\n dressing.off();\n dressing = none;\n emptied(room.container);\n },\n };\n};\n\n \n \n \n\n \n\n \n \n \n \n \n \n\nconst REFERENCE = /^[a-z2-7]{26}$/u;\nconst HANDED = /^web\\+quo:/iu;\nconst ON_DOMAIN = /^https:\\/\\/([a-z0-9]+(?:[.-][a-z0-9]+)*(?::[0-9]{1,5})?)\\/[^#]*#[a-z2-7]{26}$/u;\n\nexport const decoded = (text ) => {\n try {\n return decodeURIComponent(text);\n } catch {\n return null;\n }\n};\n\n \n\nexport const linkOf = (where , links ) => {\n if (!where.hash.startsWith('#')) return null;\n const text = where.hash.slice(1);\n if (REFERENCE.test(text))\n return links === null ? null : { text: `https://${where.host}${links}#${text}`, domain: where.host };\n for (const whole of [text, decoded(text)]) {\n if (whole === null) continue;\n if (HANDED.test(whole)) return { text: whole, domain: null };\n const on = ON_DOMAIN.exec(whole);\n if (on !== null) return { text: whole, domain: on[1] ?? null };\n }\n return null;\n};\n\n \n \n \n \n\n \n\nconst tried = async (\n client ,\n voice ,\n words ,\n body ,\n live ,\n) => {\n for (;;) {\n const answer = await client.request(body);\n if (!live()) return null;\n if (!('error' in answer) || answer.error.code !== 'timeout') return answer;\n if (!(await voice.again(words.untaken))) return null;\n }\n};\n\nconst takenOf = (taken ) => {\n const read = 'result' in taken ? fieldsOf(taken.result) : null;\n const { domain, ward, invitation } = read ?? {};\n if ((typeof domain !== 'string' && domain !== null) || typeof ward !== 'string' || typeof invitation !== 'string')\n return null;\n return { domain, ward, invitation };\n};\n\nconst textOrNull = (value ) =>\n typeof value === 'string' || value === null ? value : undefined;\n\nconst spanIn = (value ) =>\n value === null || (typeof value === 'number' && Number.isSafeInteger(value) && value >= 0) ? value : undefined;\n\nconst offerIn = (value ) => {\n const offer = fieldsOf(value);\n if (offer === null) return null;\n if (offer['reached'] === false && Object.keys(offer).length === 1) return { reached: false };\n const [waits, lives] = [spanIn(offer['waits']), spanIn(offer['lives'])];\n return waits === undefined || lives === undefined ? null : { says: offer['says'] ?? null, waits, lives };\n};\n\nconst lookedOf = (answer ) => {\n const looked = 'result' in answer ? fieldsOf(answer.result) : null;\n const ward = looked?.['ward'];\n const [domain, named] = [textOrNull(looked?.['domain']), textOrNull(looked?.['named'])];\n if (domain === undefined || named === undefined || typeof ward !== 'string') return null;\n return { inviter: { domain, ward, named }, offer: offerIn(looked?.['offer']) };\n};\n\n \n \n \n \n \n \n \n \n\nconst redeemedHere = async ({ client, voice, words, live, rest, leave } , link ) => {\n const taken = await tried(client, voice, words, { link: { text: link.text } }, live);\n if (taken === null) return rest();\n const refused = whyOf(taken);\n if (refused !== null) return leave(refused);\n const redeemed = takenOf(taken);\n if (redeemed === null) return leave(words.unread);\n const accepted = await tried(\n client,\n voice,\n words,\n { accept: { invitation: redeemed.invitation, domain: redeemed.domain } },\n live,\n );\n if (accepted === null) return rest();\n const joined = whyOf(accepted);\n if (joined !== null) return leave(joined);\n return rest();\n};\n\nconst steps = async (\n client ,\n voice ,\n words ,\n link ,\n live ,\n rest ,\n) => {\n const leave = async (said ) => {\n await voice.say(said, words.close);\n rest();\n };\n const looked = await tried(client, voice, words, { link: { text: link.text, look: true } }, live);\n if (looked === null) return rest();\n const unseen = whyOf(looked);\n if (unseen !== null) return leave(unseen);\n const seen = lookedOf(looked);\n if (seen === null) return leave(words.unread);\n const yes = await voice.consent(seen.inviter, seen.offer);\n if (!yes) return rest();\n voice.loading();\n return redeemedHere({ client, voice, words, live, rest, leave }, link);\n};\n\nexport const makeLanding = (env , client , stage ) => {\n const rooms = new WeakMap ();\n const turns = new WeakMap ();\n return async (element , links ) => {\n const link = linkOf(env.where, links);\n if (link === null) return turns.has(element) ? undefined : mark(element, 'none');\n const turn = (turns.get(element) ?? 0) + 1;\n turns.set(element, turn);\n const live = () => turns.get(element) === turn;\n mark(element, 'waking');\n const staged = rooms.get(element) ?? stage(element);\n rooms.set(element, staged);\n const room = await staged;\n if (!live()) return;\n if ('why' in room) return mark(element, 'failed', room.why);\n const words = ENGLISH;\n const voice = makeVoice(room, words);\n voice.loading();\n mark(element, 'drawn');\n const rest = () => {\n if (!live()) return;\n voice.none();\n mark(element, 'none');\n env.replace(env.where.pathname + env.where.search);\n };\n await steps(client, voice, words, link, live, rest);\n };\n};\n\n \n \n\nexport const LINK_ROAD = '/.nervur/link';\n\nconst NO_LINKS = null;\n\nconst answered = (reply ) => {\n if (reply === null) return { error: { code: 'timeout', message: 'The organism did not answer.' } };\n let read = null;\n try {\n read = JSON.parse(reply.text);\n } catch {\n read = null;\n }\n return answerOf(read) ?? { error: { code: 'refused', message: reply.text.trim() } };\n};\n\nconst textsOf = (value ) =>\n Array.isArray(value) ? value.filter((one) => typeof one === 'string') : [];\n\nconst CARD_BARE = [\n ['background', 'Canvas'],\n ['color', 'CanvasText'],\n];\n\nconst raised = (env ) => {\n const element = env.doc.createElement(LINK_HOST);\n element.setAttribute('popover', 'manual');\n deviceScheme(element);\n for (const [name, value] of [\n ['position', 'fixed'],\n ['inset', '0'],\n ['width', '100%'],\n ['height', '100%'],\n ['margin', '0'],\n ['padding', '0'],\n ['border', '0'],\n ['display', 'grid'],\n ['overflow', 'auto'],\n ] )\n element.style?.setProperty(name, value);\n (env.doc.documentElement ?? env.doc.body).insertBefore(element, null);\n element.showPopover?.();\n return element;\n};\n\nconst LOBE_PLACE = [\n ['margin', 'auto'],\n ['max-width', '100%'],\n ['box-sizing', 'border-box'],\n];\n\nexport const makeHanded = (env , walked , dress ) => {\n const where = {\n get pathname() {\n return env.path();\n },\n search: '',\n get hash() {\n return env.hash();\n },\n host: '',\n };\n const request = async (body ) => answered(await env.post(LINK_ROAD, body));\n const client = {\n request: async (body) => {\n const answer = await request(body);\n const route = 'accept' in body && 'result' in answer ? fieldsOf(answer.result)?.['text'] : undefined;\n if (typeof route === 'string' && route.startsWith('/') && !route.startsWith('//')) walked(route);\n return answer;\n },\n };\n const stage = async (container ) => {\n const answer = await request({ room: true });\n const read = 'result' in answer ? fieldsOf(answer.result) : null;\n if (read?.['sheets'] !== undefined) dress.wear(textsOf(read['sheets']));\n return {\n doc: env.doc,\n container,\n sheets: [],\n wear: (root, host) => {\n for (const [name, value] of LOBE_PLACE) host.style?.setProperty(name, value);\n return dress.on(root, host, CARD_BARE);\n },\n };\n };\n const take = makeLanding({ where, replace: env.replace }, client, stage);\n const root = env.doc.documentElement ?? env.doc.body;\n let standing = null;\n return () => {\n if (standing === null && linkOf(where, NO_LINKS) === null) return;\n const element = standing ?? raised(env);\n standing = element;\n void take(element, NO_LINKS).then(() => {\n if (standing !== element || element.getAttribute('data-quo') !== 'none') return;\n root.removeChild(element);\n standing = null;\n });\n };\n};\n\n \n\nconst RETRY = 1000;\n\nconst walkedOf = (text ) => {\n try {\n const read = JSON.parse(text);\n const walked = typeof read === 'object' && read !== null && 'walked' in read ? read.walked : null;\n return typeof walked === 'string' && walked.startsWith('/') && !walked.startsWith('//') ? walked : null;\n } catch {\n return null;\n }\n};\n\nconst refusalOf = (text ) => {\n let read ;\n try {\n read = JSON.parse(text);\n } catch {\n const plain = text.trim();\n return plain === '' ? null : plain;\n }\n const error = typeof read === 'object' && read !== null && 'error' in read ? read.error : null;\n const message = typeof error === 'object' && error !== null && 'message' in error ? error.message : null;\n return typeof message === 'string' && message.trim() !== '' ? message : null;\n};\n\nexport const run = (env ) => {\n env.doc.documentElement?.style?.setProperty('color-scheme', 'light dark');\n let route = env.path();\n let stream = null;\n const held = () => {\n if (stream === null) return false;\n stream.close();\n stream = null;\n env.doc.body.setAttribute('inert', '');\n env.doc.body.setAttribute('aria-busy', 'true');\n env.doc.body.style?.setProperty('opacity', '0.5');\n return true;\n };\n const hold = () => {\n if (held()) env.later(open, RETRY);\n };\n const renew = () => {\n if (held()) open();\n };\n const dress = makeDress(env.doc);\n const say = makeSaid(env.doc, dress);\n const refused = (answer ) => {\n if (answer.status < 400) return false;\n const refusal = refusalOf(answer.text);\n if (refusal === null) hold();\n else say(refusal);\n return true;\n };\n const free = () => {\n env.doc.body.removeAttribute('inert');\n env.doc.body.removeAttribute('aria-busy');\n env.doc.body.style?.setProperty('opacity', '');\n };\n const tell = (more ) =>\n void env.post('/.nervur/tell', more).then((answer) => {\n if (answer === null) hold();\n else refused(answer);\n });\n const go = (path ) => {\n say(null);\n env.push(path);\n route = path;\n tell({ route });\n };\n const asked = makeAsked(env.doc, dress);\n let worded = null;\n const world = (href ) => asked(askingOf(href, worded), () => env.open(href));\n const pressed = async (sent ) => {\n const { files = [], ...body } = 'files' in sent ? sent : { ...sent, files: [] };\n if (stream === null) return;\n say(null);\n for (const bytes of files) if (!(await env.give(bytes))) return hold();\n const answer = await env.post('/.nervur/press', body);\n if (answer === null) return hold();\n if (answer.status === 409) return renew();\n if (refused(answer)) return;\n const walked = walkedOf(answer.text);\n if (walked === null) return;\n env.push(walked);\n route = walked;\n };\n const surface = makeSurface(env.doc, pressed, go, world, env.copy);\n const way = makeWay(\n env.doc,\n () => {\n say(null);\n env.push('/');\n route = '/';\n tell({ route });\n },\n pressed,\n dress,\n );\n const motion = makeMotion(surface.nodeAt, surface.morphs);\n const countdown = makeCountdown(env.doc, surface.deadlines, env);\n const instants = makeInstants(env.doc, surface.instants, env.language);\n makeGestures({ body: env.doc.body, reduced: env.reduced, later: env.later, press: surface.press });\n let queue = Promise.resolve();\n const play = async (text ) => {\n const message = messageOf(text);\n if (message === null) return;\n if (message.home !== undefined) dress.wear(message.home);\n if (message.way !== undefined) way.lay(message.way);\n if (message.world !== undefined) worded = message.world;\n if (message.whole) surface.reset();\n if (message.whole || message.fonts !== undefined) surface.fonts(message.fonts);\n const rects = await motion.before(message.motion);\n surface.apply(message.ops, message.opens);\n countdown.count();\n instants.write();\n motion.after(message.motion, rects);\n };\n const moments = () =>\n `route=${encodeURIComponent(route)}&width=${env.width()}&language=${encodeURIComponent(env.language())}&reduced=${env.reduced() ? 1 : 0}&theme=${env.dark() ? 'dark' : 'light'}`;\n const open = () => {\n const opened = env.stream(`/.nervur/stream?${moments()}`);\n stream = opened;\n let first = true;\n opened.onMessage((text) => {\n if (first) queue = queue.then(free);\n first = false;\n queue = queue.then(() => play(text)).catch(() => undefined);\n });\n opened.onError(() => {\n if (stream === opened) hold();\n });\n };\n env.onPop(() => {\n say(null);\n route = env.path();\n tell({ route });\n });\n env.onChange(() => tell({ width: env.width(), reduced: env.reduced(), theme: env.dark() ? 'dark' : 'light' }));\n open();\n const handed = makeHanded(\n env,\n (walked) => {\n say(null);\n env.replace(walked);\n route = walked;\n },\n dress,\n );\n env.onHash(handed);\n handed();\n};\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\nif (typeof document !== 'undefined' && document !== undefined) {\n const reduced = matchMedia('(prefers-reduced-motion: reduce)');\n const scheme = matchMedia('(prefers-color-scheme: dark)');\n run({\n doc: document,\n path: () => location.pathname,\n hash: () => location.hash,\n push: (path) => history.pushState(null, '', path),\n replace: (path) => history.replaceState(null, '', path),\n stream: (url) => {\n const source = new EventSource(url);\n return {\n onMessage: (handle) => source.addEventListener('message', (event) => handle(event.data)),\n onError: (handle) => source.addEventListener('error', handle),\n close: () => source.close(),\n };\n },\n post: (url, body) =>\n fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n })\n .then(async (answer) => ({ status: answer.status, text: await answer.text() }))\n .catch(() => null),\n give: (bytes) =>\n fetch('/.nervur/file', {\n method: 'POST',\n headers: { 'content-type': 'application/octet-stream' },\n body: bytes,\n }).then(\n () => true,\n () => false,\n ),\n onPop: (handle) => addEventListener('popstate', handle),\n onHash: (handle) => addEventListener('hashchange', handle),\n width: () => innerWidth,\n language: () => navigator.language,\n reduced: () => reduced.matches,\n dark: () => scheme.matches,\n onChange: (handle) => {\n for (const query of ['(min-width: 600px)', '(min-width: 1000px)'])\n matchMedia(query).addEventListener('change', handle);\n reduced.addEventListener('change', handle);\n scheme.addEventListener('change', handle);\n },\n later: (handle, ms) => void setTimeout(handle, ms),\n now: () => Date.now(),\n open: (href) => void open(href, '_blank', 'noopener,noreferrer'),\n copy: (text) => void navigator.clipboard?.writeText(text).catch(() => undefined),\n });\n}\n";
|