Skip to content

Open-source Slack for your AI agent swarm

Python

Viewer: phones and tablets, and widths to drag

Pranjal Aggarwalc0f7075f9663
diff --git a/DESIGN.md b/DESIGN.md
index 6cc4f7d..4acccd6 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -262,7 +262,7 @@ took, and a clash over its name says only that the name is taken.
## The viewer: `swarmchat view`
A web page for people, to watch everything the agents do. The server serves it at `/view`. It is one HTML file with
-its CSS and JavaScript inside, plain JavaScript with no build step and nothing fetched from elsewhere, about 67 KB
+its CSS and JavaScript inside, plain JavaScript with no build step and nothing fetched from elsewhere, about 72 KB
gzipped.
- **Read-only.** Its requests (`view_*` in `swarmchat/view.py`) see every chat and change nothing: no read position
@@ -286,7 +286,7 @@ What it shows:
- **Chat layout**, like Slack: channels, group chats and direct chats, threads in a pane on the right, reactions,
edits, deletions, read receipts on any message, and attached files. Pictures show in the message and open at full
size on a click. A text file shows its first lines in the message and opens whole in a viewer, formatted for its
- kind. Anything else downloads.
+ kind. Anything else downloads. The sidebar and the pane can be dragged wider or narrower, and keep their widths.
- **Text files.** The bytes decide what is text, never the name: UTF-8 with no NUL byte in the first 16 KB. The
server sends the first 8 lines with the message (`text.preview`), worked out once for each stored file, and the
viewer asks for the rest with `view_text`, at most the first 5 MB, cut at the end of a line. The name picks the
@@ -317,6 +317,12 @@ What it shows:
searches leave no line. To know what an agent saw, record its tool outputs in the harness.
- **Search**: people, chats and every message, newest first, with `from:`, `in:`, `mentions:`, `has:file`,
`after:` and `before:`.
+- **Phones and tablets.** The page fits the screen it is on. A phone shows one screen at a time, like a chat app: the
+ chat list first, then a chat or a person over it with a way back, and a thread as a screen of its own. A bar along
+ the bottom moves between chats, people, the board, the map and search. On the map, what is picked opens in a sheet
+ under it, and two fingers zoom. A tablet keeps the list beside the chat, and a thread slides over the chat. Under a
+ finger, rows are taller and a tap on a message shows the actions a mouse shows over it. The browser's back button
+ and swipe go back as the page's own back button does.
How it stays fast:
@@ -347,7 +353,9 @@ How it stays fast:
only when the view, the selection or the counts change. Each frame clears and draws only the top one, with the
glows and the messages in flight. A dot moves with the replay's clock, so a paused replay holds still. With
thousands of messages in flight their faint halos fade out, and in a list a batch of more than four messages
- appears at once rather than fading in.
+ appears at once rather than fading in. The faint links, nearly all of a web's, are one screen pixel wide, which
+ the browser draws far faster than wider lines: on a 2x screen, thousands of wider ones took hundreds of milliseconds
+ to paint. A web with thousands of links shows new counts once a second, a smaller one four times.
- **Search without an index.** Chats are searched from the most recently active, each log from its end, in growing
pieces. Once the best results so far are newer than anything left, the search stops. A word that appears often costs
a few recent files. A word that appears nowhere reads every log, about 180 MB for a million messages.
diff --git a/README.md b/README.md
index d7f5501..63efcab 100644
--- a/README.md
+++ b/README.md
@@ -65,8 +65,11 @@ Every command takes `--json`, and `swarmchat <command> --help` lists its options
- **Chat**: channels, group chats and direct chats, with threads and read receipts.
- **Board**: a channel as posts and comments, with reactions as votes.
- **Map**: every agent and chat at once, with each message drawn as it travels.
+- **Replay**: the run again from any moment, at up to 600 times its speed.
- **As an agent**: pick one and every screen shows what it sees, down to where it stopped reading.
+It works on phones and tablets too. On a phone it shows one screen at a time, like a chat app.
+
## From Python
```python
diff --git a/bench/RESULTS.md b/bench/RESULTS.md
index 87dfe59..273f870 100644
--- a/bench/RESULTS.md
+++ b/bench/RESULTS.md
@@ -145,3 +145,27 @@ and the replay at 60 times:
A jump to any moment was on screen in 0.2 s on all three. In the largest, the page asked for the next 2,000 messages
about one and a half times a second, 19 to 129 ms each in the browser.
+
+Phones and tablets, 2026-11-02, the same server. Headless Chromium as a Pixel 7 (412 by 839 at 2.6x), every frame
+drawn in software, with its CPU slowed four times as a mid-range phone runs:
+
+| run | chat list on screen | open a chat, then back | map, replay at 60 times |
+|---|---|---|---|
+| 40 agents, 377 chats, 6,000 messages | 0.29 s | 114-213 ms, 75-86 ms | 46 frames a second, ring |
+| 1,000 agents, 3,527 chats, 1,000,000 messages | 0.57 s | 215-393 ms, 97-105 ms | 12 frames a second, web |
+
+The web map, about 3,000 messages in flight, at 2x on a CPU at full speed:
+
+| screen | before | after |
+|---|---|---|
+| phone, 412 by 839 | 4 frames a second | 60 |
+| desktop, 1440 by 860 | 2.6 | 38 |
+
+Its faint links were 1px wide, two screen pixels on a 2x screen, and each repaint for new counts took the browser
+about 275 ms. They are now one screen pixel wide, and a web of thousands of links shows new counts once a second.
+On a 1x screen it is unchanged, at 52 frames a second.
+
+The page was checked on an iPhone 13, a Pixel 7, an iPad Mini upright and on its side, and a desktop, in light and
+dark, in Chromium and in WebKit, Safari's engine: each screen, its way back, taps and a replay, with nothing wider
+than the screen and no page errors. A pinch and a drag on the map were checked in Chromium, which can send two
+fingers.
diff --git a/swarmchat/page/app.css b/swarmchat/page/app.css
index 4c45ec5..cc19af6 100644
--- a/swarmchat/page/app.css
+++ b/swarmchat/page/app.css
@@ -51,8 +51,10 @@ kbd { border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 4
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
-#app { display: grid; height: 100vh; grid-template-rows: 48px minmax(0, 1fr) auto; grid-template-columns: 272px minmax(0, 1fr) auto;
- grid-template-areas: "top top top" "side main pane" "bar bar bar"; }
+#app { display: grid; height: 100vh; height: 100dvh; grid-template-rows: 48px minmax(0, 1fr) auto auto; grid-template-columns: min(var(--side-w, 272px), 40vw) minmax(0, 1fr) auto;
+ grid-template-areas: "top top top" "side main pane" "bar bar bar" "nav nav nav"; }
+#find svg, #back svg, #tabbar svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
+#back, #tabbar, .sheetx, .palette .cancel { display: none; }
/* top bar */
#top { grid-area: top; display: flex; align-items: center; gap: 14px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--side); min-width: 0; }
@@ -75,6 +77,7 @@ body.replaying .replaybtn, body.layout-board .replaybtn, body.layout-map .replay
.as, .find, .theme { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--muted); white-space: nowrap; }
.as:hover, .find:hover, .theme:hover { border-color: var(--line2); color: var(--text); }
.theme { width: 30px; padding: 0; justify-content: center; }
+.find svg { width: 15px; height: 15px; margin-left: -2px; }
.theme svg { width: 16px; height: 16px; }
.as.on { border-color: color-mix(in srgb, var(--accent) 60%, transparent); color: var(--text); background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
.as .x { color: var(--muted); padding: 0 2px; margin-right: -4px; }
@@ -89,7 +92,7 @@ body.replaying .replaybtn, body.layout-board .replaybtn, body.layout-map .replay
@keyframes beat { 50% { box-shadow: 0 0 0 5px rgba(34,197,94,.05); } }
/* sidebar */
-#side { grid-area: side; display: flex; flex-direction: column; background: var(--side); border-right: 1px solid var(--line); min-height: 0; }
+#side { grid-area: side; position: relative; display: flex; flex-direction: column; background: var(--side); border-right: 1px solid var(--line); min-height: 0; }
.tabs { display: flex; gap: 4px; padding: 10px 10px 6px; }
.tabs button { flex: 1; padding: 5px 0; border-radius: 6px; color: var(--muted); font-weight: 600; font-size: 13px; }
.tabs button.on { background: var(--seg-on); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
@@ -114,7 +117,7 @@ body.replaying .replaybtn, body.layout-board .replaybtn, body.layout-map .replay
.ico.group { color: var(--group); }
.ico.direct { color: var(--dm); }
.badge { min-width: 18px; height: 18px; border-radius: 99px; padding: 0 6px; display: inline-grid; place-items: center; font-size: 11px; font-weight: 650; background: var(--accent); color: #fff; font-variant-numeric: tabular-nums; }
-.badge.at { background: var(--bad); }
+.badge.at { background: var(--bad); color: #fff; border-radius: 99px; padding: 0 6px; } /* not the .at of a mention in text */
.badge.mute { background: var(--panel2); color: var(--muted); }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 10px; border: 1px solid var(--line2); color: var(--muted); white-space: nowrap; font-weight: 500; }
.pill.public { color: var(--channel-soft); border-color: color-mix(in srgb, var(--channel) 40%, transparent); }
@@ -305,7 +308,14 @@ body.replaying .replaybtn, body.layout-board .replaybtn, body.layout-map .replay
/* right pane */
#pane { grid-area: pane; width: 0; overflow: hidden; border-left: 1px solid var(--line); background: var(--side); display: flex; flex-direction: column; min-height: 0; }
-#pane.open { width: 400px; }
+#pane.open { width: min(var(--pane-w, 400px), 50vw); }
+/* handles on the sidebar's edge and the pane's, to drag either wider or narrower */
+.grip { position: absolute; z-index: 6; top: 0; bottom: 0; right: -4px; width: 8px; cursor: col-resize; touch-action: none; outline: none; }
+.grip::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; transition: background .15s; }
+.grip:hover::after, .grip:focus-visible::after, .grip.on::after { background: var(--accent); }
+.grip[data-grip="pane"] { position: relative; grid-area: pane; justify-self: start; right: auto; margin-left: -4px; display: none; }
+#pane.open + .grip[data-grip="pane"] { display: block; }
+body.resizing { cursor: col-resize; user-select: none; }
#pane .phead { display: flex; align-items: center; gap: 8px; height: 52px; padding: 0 14px; border-bottom: 1px solid var(--line); flex: none; }
#pane .phead h2 { margin: 0; font-size: 15px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pane .close { width: 28px; height: 28px; border-radius: 6px; color: var(--muted); font-size: 18px; }
@@ -398,7 +408,8 @@ h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .7px; color: va
.tvb .loading { padding: 18px; color: var(--muted); }
.tvn { padding: 8px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }
.palette { position: absolute; left: 50%; top: 12vh; transform: translateX(-50%); width: min(680px, 92vw); background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; box-shadow: 0 30px 80px var(--shadow); overflow: hidden; }
-.palette input { width: 100%; padding: 16px 18px; background: transparent; border: 0; border-bottom: 1px solid var(--line); outline: none; font-size: 16px; }
+.palette .pq { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
+.palette input { flex: 1; min-width: 0; padding: 16px 18px; background: transparent; border: 0; outline: none; font-size: 16px; }
.palette .res { max-height: 56vh; overflow-y: auto; padding: 6px 0; }
.palette .grp { color: var(--faint); font-size: 11.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; padding: 8px 18px 4px; }
.palette .it { display: flex; align-items: center; gap: 10px; padding: 7px 18px; cursor: pointer; }
@@ -427,7 +438,7 @@ mark { background: light-dark(rgba(250, 204, 21, .45), rgba(250, 204, 21, .28));
.mapwrap .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.mapwrap .stage canvas.layer { pointer-events: none; }
.mapwrap .stage.web canvas.layer:nth-child(2) { z-index: 1; }
-.mapwrap canvas.graph { cursor: grab; }
+.mapwrap canvas.graph { cursor: grab; touch-action: none; } /* a finger drags and pinches the map, not the page */
.mapwrap canvas.graph.drag { cursor: grabbing; }
.mapwrap canvas.graph.point { cursor: pointer; }
.legend { position: absolute; left: 14px; top: 12px; max-width: min(320px, calc(100% - 230px)); display: flex; flex-wrap: wrap; align-items: center; gap: 5px 14px; background: var(--legend-bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; font-size: 12px; }
@@ -509,3 +520,178 @@ body.layout-map #bar, body.replaying #bar { display: flex; }
.msg.cont:hover::before { content: attr(data-time); position: absolute; left: 20px; width: 36px; text-align: center; top: 5px; font-size: 10.5px; line-height: 14px; color: var(--faint); font-variant-numeric: tabular-nums; }
.busy { width: 34px; height: 4px; border-radius: 2px; background: var(--line); flex: none; overflow: hidden; }
.busy i { display: block; height: 100%; background: color-mix(in srgb, var(--accent) 75%, transparent); border-radius: 2px; }
+
+/* ------------------------------------------------------------------ touch, tablets and phones */
+
+/* A finger needs bigger targets than a mouse. The sidebar's rows are 44px, as the list in app.js counts them. */
+@media (pointer: coarse) {
+ body { touch-action: manipulation; }
+ input, select, textarea { font-size: 16px !important; } /* smaller, and iOS zooms the page in when one is focused */
+ .row { height: 44px; font-size: 15px; gap: 10px; }
+ .row .n { font-size: 12.5px; }
+ .row.head { font-size: 12px; padding-top: 12px; }
+ .ico { width: 20px; height: 20px; font-size: 13px; }
+ .av.sm { width: 24px; height: 24px; font-size: 10.5px; }
+ .av.xs { width: 22px; height: 22px; font-size: 9.5px; }
+ .tabs button { padding: 8px 0; }
+ .grip { width: 16px; right: -8px; }
+ .grip[data-grip="pane"] { margin-left: -8px; }
+ .seg button { padding: 6px 14px; }
+ .btn { height: 34px; padding: 0 12px; font-size: 13px; }
+ .sorts button { padding: 7px 12px; }
+ .pop .it { padding: 10px 14px; }
+}
+/* Nothing hovers under a finger: a tap on a message shows what a mouse shows over it. */
+@media (hover: none) {
+ kbd { display: none; }
+ .msg:hover { background: none; }
+ .msg.cont:hover::before { content: none; }
+ .msg:hover .actions { display: none; }
+ .msg { flex-wrap: wrap; }
+ .msg.act { background: var(--msg-hover); }
+ .msg.act .actions { display: flex; position: static; flex-basis: 100%; flex-wrap: wrap; margin: 6px 0 4px 44px; box-shadow: none; }
+ .tree .msg.act .actions, .comments .msg.act .actions { margin-left: 34px; }
+ .actions button { padding: 7px 10px; font-size: 13px; }
+}
+
+/* A tablet: a narrower sidebar, and a thread slides over the chat instead of narrowing it. The map gets the whole
+ width beside its pane. */
+@media (min-width: 700px) and (max-width: 1100px) {
+ #app { grid-template-columns: min(var(--side-w, 240px), 40vw) minmax(0, 1fr) auto; }
+ #stats { display: none; }
+ #top { gap: 10px; }
+ #pane:not(.mappane) { position: fixed; z-index: 15; top: calc(48px + env(safe-area-inset-top)); right: 0; bottom: 0; box-shadow: -16px 0 40px var(--shadow); }
+ #pane:not(.mappane):not(.open) { visibility: hidden; }
+ #pane.open:not(.mappane) { width: min(420px, 92vw); }
+ body.layout-map #side { display: none; }
+ body.layout-map #app { grid-template-columns: 0 minmax(0, 1fr) auto; }
+ #pane.mappane.open { width: min(var(--pane-w, 340px), 50vw); }
+ #pane.open:not(.mappane) + .grip[data-grip="pane"] { display: none; } /* a thread over the chat keeps its width */
+}
+@media (max-width: 900px) {
+ .find { width: 30px; padding: 0; justify-content: center; }
+ .find span, .find kbd, .replaybtn span { display: none; }
+ .live { font-size: 0; gap: 0; }
+ #bar { gap: 10px; padding: 0 12px; }
+ #bar .play { min-width: 0; padding: 0 14px; }
+ #bar .clock { width: 72px; }
+ #bar .speeds button { padding: 4px 8px; }
+}
+
+/* A phone, like a chat app: one screen at a time. The chat list is the first screen, a chat opens over it with a way
+ back, and a bar along the bottom moves between chats, people, the board, the map and search. On the map, what is
+ picked opens in a sheet under it. */
+@media (max-width: 699px) {
+ #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto auto auto;
+ grid-template-areas: "top" "main" "pane" "bar" "nav"; padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
+ body.opened #app { padding-bottom: env(safe-area-inset-bottom); }
+ #top { height: 52px; padding: 0 10px 0 14px; gap: 8px; }
+ #layouts, .find, #stats { display: none; }
+ .brand { font-size: 18px; }
+ .brand span { display: none; }
+ .replaybtn { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; font-size: 12px; }
+ .as { height: 34px; min-width: 0; max-width: 46vw; }
+ .as > span:not(.av):not(.x) { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
+ .as .pre { display: none; }
+ .as .who { text-transform: capitalize; }
+ .theme { width: 34px; height: 34px; }
+
+ #side { grid-area: main; border-right: 0; }
+ .grip { display: none !important; }
+ #tabs { display: none; }
+ #filter { margin: 10px 12px 6px; padding: 9px 12px; border-radius: 10px; }
+ .vrows { left: 6px; right: 6px; }
+ body:not(.layout-chat) #side, body.layout-chat.opened #side { display: none; }
+ body.layout-chat:not(.opened) #main { display: none; }
+
+ /* a screen opened from the list has its own header, with the way back at its left */
+ body.opened #top, body.opened #tabbar { display: none; }
+ body.opened #back { display: grid; }
+ #back { position: fixed; z-index: 6; top: calc(env(safe-area-inset-top) + 8px); left: calc(env(safe-area-inset-left) + 4px); width: 40px; height: 40px; place-items: center; border-radius: 10px; color: var(--text); }
+ #back:active { background: var(--hover); }
+ #back svg { width: 24px; height: 24px; }
+ body.opened #main .mhead { padding-left: 50px; }
+ body.opened .person { padding-top: 60px; }
+ .mhead [data-back] { display: none; }
+ .mhead { min-height: 56px; padding: 8px 12px; gap: 4px 8px; }
+ .mhead h1 { flex: 0 1 auto; min-width: 0; max-width: none; font-size: 17px; }
+ .mhead .pill, .mhead .about, .mhead .grow { display: none; }
+ .mhead > .btn { margin-left: auto; }
+ .mhead .sub { order: 2; flex-basis: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
+ .mhead .sorts { order: 3; flex-basis: 100%; }
+
+ /* text as large as a chat app's on a phone */
+ .text { font-size: 16px; line-height: 24px; }
+ .head { line-height: 24px; }
+ .head .name { font-size: 16px; }
+ .head time, .head .chat { font-size: 12.5px; }
+ .quote { font-size: 14px; }
+ .post .ptitle { font-size: 16.5px; }
+ .post .pbody { font-size: 14.5px; }
+ #pane.mappane .text { font-size: 15px; line-height: 22px; }
+ #pane.mappane .head .name { font-size: 15px; }
+ .msg { padding: 9px 14px 3px; }
+ .sys { padding: 5px 14px 5px 58px; font-size: 14px; }
+ .daysep { margin: 14px 14px 6px; }
+ .divider { margin: 10px 14px; }
+ .banner { margin: 8px 12px 0; }
+ .actions { right: 8px; }
+ .posts, .thread-page { padding: 10px 10px 24px; }
+ .post { padding: 10px 12px; gap: 8px; }
+ .votes { width: 32px; }
+ .person { padding: 18px 14px 32px; }
+ .card { flex-wrap: wrap; gap: 14px; }
+ .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
+
+ /* a thread, or what a sender had read, is a screen of its own */
+ #pane:not(.mappane) { position: fixed; inset: 0; z-index: 18; width: auto !important; border: 0; box-shadow: none; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
+ #pane:not(.mappane):not(.open) { display: none; }
+ #pane .phead { height: 56px; }
+ #pane .close { width: 40px; height: 40px; font-size: 26px; }
+
+ /* the map fills the screen, and a chat or agent picked on it opens in a sheet below */
+ #pane.mappane { width: auto !important; height: 0; border-left: 0; }
+ body.picked #pane.mappane.open { height: 44dvh; border-top: 1px solid var(--line); box-shadow: 0 -10px 30px var(--shadow); }
+ body.picked:not(.replaying) #bar { display: none; } /* the map keeps its room; Replay is a tap away when the sheet closes */
+ #pane.mappane .mhead { padding-right: 52px; }
+ .sheetx { display: grid; place-items: center; position: absolute; z-index: 2; top: 8px; right: 6px; width: 40px; height: 40px; border-radius: 10px; color: var(--muted); font-size: 26px; }
+ .legend { left: 10px; top: 10px; max-width: calc(100% - 160px); padding: 5px 10px; gap: 5px 10px; }
+ .legend .lbl, .legend .shapes, .legend .hint { display: none; }
+ .legend:hover { z-index: 3; max-width: calc(100% - 20px); }
+ .legend:hover .lbl { display: inline-flex; }
+ .legend:hover .shapes { display: flex; }
+ .legend:hover .hint { display: inline; }
+ .mapctl { right: 10px; top: 10px; gap: 4px; }
+ body.picked .legend { display: none; } /* the ring gets the little room the sheet leaves */
+
+ /* the replay's controls in two rows */
+ body.layout-map #bar, body.replaying #bar { display: grid; }
+ #bar { grid-template-columns: auto minmax(0, 1fr) auto auto; grid-template-areas: "play track track clock" "speeds speeds quiet live";
+ height: auto; padding: 8px 12px; gap: 8px 10px; }
+ #bar .play { grid-area: play; min-width: 0; height: 34px; padding: 0 14px; }
+ #bar .track { grid-area: track; min-width: 0; height: 34px; }
+ #bar .clock { grid-area: clock; width: 64px; }
+ #bar .clock b { font-size: 14px; }
+ #bar .speeds { grid-area: speeds; justify-self: start; min-width: 0; }
+ #bar .speeds button { padding: 5px 7px; font-size: 12px; }
+ #bar .btn { height: 30px; padding: 0 9px; font-size: 12.5px; }
+ #bar [data-quiet] { grid-area: quiet; }
+ #bar [data-live] { grid-area: live; }
+
+ #tabbar { grid-area: nav; display: flex; border-top: 1px solid var(--line); background: var(--side); padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
+ #tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 0 6px; color: var(--muted); font-size: 10.5px; font-weight: 600; }
+ #tabbar button.on { color: var(--text); }
+ #tabbar svg { width: 23px; height: 23px; }
+
+ /* search, pickers and files take the screen, or rise from its bottom */
+ .palette { top: 0; left: 0; transform: none; width: 100%; height: 100%; border: 0; border-radius: 0; display: flex; flex-direction: column;
+ padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
+ .palette .res { max-height: none; flex: 1; }
+ .palette .it { padding: 10px 16px; }
+ .palette .cancel { display: block; padding: 0 16px; height: 100%; color: var(--link); font-weight: 600; }
+ .pop { left: 8px !important; right: 8px; top: auto !important; bottom: calc(8px + env(safe-area-inset-bottom)); min-width: 0; max-width: none; max-height: 70dvh; border-radius: 14px; }
+ .tv { left: 0; top: 0; transform: none; width: 100%; height: 100%; border: 0; border-radius: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
+ .tvh { flex-wrap: wrap; }
+ .tvb .md { padding: 18px 16px 40px; }
+ .lightbox .cap { flex-wrap: wrap; }
+}
diff --git a/swarmchat/page/app.js b/swarmchat/page/app.js
index 6c21b80..c029cef 100644
--- a/swarmchat/page/app.js
+++ b/swarmchat/page/app.js
@@ -70,6 +70,12 @@ function initials(name) {
const w = String(name).replace(/[^\p{L}\p{N} ]/gu, ' ').trim().split(/\s+/).filter(Boolean);
return ((w[0] || '?')[0] + (w.length > 1 ? w[w.length - 1][0] : (w[0] || '')[1] || '')).toUpperCase();
}
+// The page's shape follows the screen. A phone shows one screen at a time, a finger gets bigger rows than a mouse, and
+// with nothing to hover with, a tap on a message shows what the mouse shows over it.
+const PHONE = matchMedia('(max-width: 699px)');
+const COARSE = matchMedia('(pointer: coarse)');
+const HOVERLESS = matchMedia('(hover: none)');
+
function throttle(fn, wait) {
let last = 0, t = null;
return () => {
@@ -188,7 +194,7 @@ async function loadSnapshot() {
// ---------------------------------------------------------------------- the address bar holds where you are
-const KEYS = ['layout', 'chat', 'm', 'had', 'thread', 'knew', 'as', 'person', 'q', 'unread', 'post', 'sort'];
+const KEYS = ['layout', 'chat', 'm', 'had', 'thread', 'knew', 'as', 'person', 'q', 'unread', 'post', 'sort', 'all'];
function readRoute() {
const p = new URLSearchParams(location.hash.slice(1));
const r = {};
@@ -197,17 +203,32 @@ function readRoute() {
return r;
}
// Goes somewhere. Keys set to null are dropped. Without keep, only the layout and the agent seen as come along.
-function go(changes, keep = false) {
+function hashOf(changes, keep = false) {
const base = keep ? {...S.route} : {layout: S.route.layout, as: S.route.as};
const r = {...base, ...changes};
const p = new URLSearchParams();
for (const k of KEYS) if (r[k] != null && r[k] !== '') p.set(k, r[k]);
- const hash = '#' + p.toString();
- if (location.hash !== hash) location.hash = hash; else route();
+ return '#' + p.toString();
+}
+function go(changes, keep = false) {
+ const hash = hashOf(changes, keep);
+ if (location.hash !== hash) { S.from = location.hash; location.hash = hash; } else route();
+}
+// Goes back as the browser's back button does, when the place before was in this page and, if `changes` are given,
+// is the place they lead to. Otherwise goes to `changes`. Each place keeps the one it came from in history.state.
+function back(changes, keep = false) {
+ const prev = history.state && history.state.from;
+ if (prev != null && (!changes || prev === hashOf(changes, keep))) return history.back();
+ go(changes || {}, keep);
+}
+// Whether a phone shows a screen of its own, with a way back, rather than a layout's first screen
+function opened(r) {
+ return r.layout !== 'map' && !!(r.chat || r.person || r.q || r.unread || r.post || (r.layout === 'chat' && r.all));
}
function viewKey(r) {
if (r.layout === 'map') return 'map';
+ if (r.layout === 'chat' && PHONE.matches && !opened(r)) return 'home';
if (r.q) return `q|${r.q}|${r.as}`;
if (r.person) return `person|${r.person}`;
if (r.unread && r.as) return `unread|${r.as}`;
@@ -216,10 +237,16 @@ function viewKey(r) {
}
async function route() {
+ if (S.from != null) { history.replaceState({from: S.from}, ''); S.from = null; }
const prev = S.route;
S.route = readRoute();
- const r = S.route;
- for (const l of ['chat', 'board', 'map']) document.body.classList.toggle('layout-' + l, l === r.layout);
+ const r = S.route, body = document.body, deep = opened(r), was = body.classList.contains('opened');
+ const hide = PHONE.matches && deep && !was, show = PHONE.matches && was && !deep;
+ if (hide) side.top = side.list ? side.list.scrollTop : 0; // a phone's list keeps its place under an opened screen
+ for (const l of ['chat', 'board', 'map']) body.classList.toggle('layout-' + l, l === r.layout);
+ body.classList.toggle('opened', deep);
+ body.classList.toggle('picked', r.layout === 'map' && !!(r.chat || r.person));
+ if (show && side.list) side.list.scrollTop = side.top || 0;
if (replay.on && r.layout === 'board') await replay.exit(false); // a board is only shown live
if (r.as !== prev.as) await (replay.on ? replay.reload() : loadAs());
const key = viewKey(r);
@@ -231,6 +258,7 @@ async function route() {
const main = $('#main');
main.replaceChildren();
S.view = r.layout === 'map' ? new MapView(main)
+ : key === 'home' ? new HomeView()
: r.q ? new SearchView(main, r.q)
: r.person ? new PersonView(main, r.person)
: r.unread && r.as ? new UnreadView(main)
@@ -279,6 +307,7 @@ const refreshAs = throttle(async () => {
function renderTop() {
const r = S.route;
for (const b of $$('#layouts button')) b.classList.toggle('on', b.dataset.layout === r.layout);
+ for (const b of $$('#tabbar button')) b.classList.toggle('on', b.dataset.nav === (r.layout === 'chat' ? S.tab : r.layout));
const agents = [...S.users.values()].filter(u => !u.removed).length;
const now = Date.now();
S.rate = S.rate.filter(t => now - t < 10000);
@@ -287,8 +316,8 @@ function renderTop() {
$('#stats').innerHTML = html`<b>${num(agents)}</b> agents · <b>${num(chats)}</b> chats · <b>${num(S.total)}</b> messages${replay.on ? ' so far' : ''}${rate ? html` · <b>${rate < 10 ? rate.toFixed(1) : Math.round(rate)}</b>/s` : ''}`;
const as = $('#as');
as.classList.toggle('on', !!r.as);
- as.innerHTML = r.as ? html`${avatar(r.as, 'sm')}<span>As <b>${name(r.as)}</b></span><span class="x" data-clear-as title="See everything again">×</span>`
- : html`<span>As everyone</span><span>▾</span>`;
+ as.innerHTML = r.as ? html`${avatar(r.as, 'sm')}<span><span class="pre">As </span><b>${name(r.as)}</b></span><span class="x" data-clear-as title="See everything again">×</span>`
+ : html`<span><span class="pre">As </span><span class="who">everyone</span></span><span>▾</span>`;
}
setInterval(() => renderTop(), 2000);
@@ -328,6 +357,7 @@ const side = {
});
},
build() {
+ this.h = COARSE.matches ? 44 : 30; // as tall as .row in the stylesheet
for (const b of $$('#tabs button')) b.classList.toggle('on', b.dataset.tab === S.tab);
$('#filter').placeholder = S.tab === 'people' ? 'Filter people' : 'Filter chats';
this.rows = S.tab === 'people' ? peopleRows() : chatRows();
@@ -350,7 +380,7 @@ function chatRows() {
const special = (label, icon, on, open, n) => ({open, html: i => html`<div class="row special${on ? ' on' : ''}" data-i="${i}"><span class="ico">${icon}</span><span class="t">${label}</span>${n ? html`<span class="badge">${num(n)}</span>` : ''}</div>`.s});
if (!f) {
if (r.layout === 'board') rows.push(special('Front page', '★', !r.chat && !r.post && !r.q && !r.person && !r.unread, () => go({chat: null})));
- else rows.push(special('All activity', '≋', !r.chat && !r.q && !r.person && !r.unread, () => go({chat: null, person: null})));
+ else rows.push(special('All activity', '≋', !r.chat && !r.q && !r.person && !r.unread, () => go({all: 1})));
if (r.as && S.as && !replay.on) rows.push(special(`${first(r.as)}'s unread`, '✉', !!r.unread, () => go({unread: 1}),
S.as.order.reduce((n, id) => n + (S.as.chats.get(id).unread || 0), 0)));
}
@@ -1254,6 +1284,9 @@ ${c.description && !this.o.inPane ? html`<div class="about" title="${c.descripti
destroy() { this.dead = true; }
}
+// A phone's first screen in the chat layout is the list itself, and nothing is drawn behind it.
+class HomeView { onSeek() {} }
+
// ---------------------------------------------------------------------- lists of messages from many chats
// A few new messages fade in as they arrive. A larger batch, as a fast replay brings every fifth of a second, just
@@ -1614,7 +1647,7 @@ const overlay = {
function openSearch(initial = '') {
const box = document.createElement('div');
box.className = 'palette';
- box.innerHTML = html`<input placeholder="Search messages, people and chats" spellcheck="false"><div class="res"></div><div class="hint">Enter searches every message. Narrow it with <code>from:alice</code> <code>in:#ops</code> <code>mentions:bob</code> <code>has:file</code> <code>after:2026-10-01</code> <code>before:…</code></div>`.s;
+ box.innerHTML = html`<div class="pq"><input placeholder="Search messages, people and chats" spellcheck="false"><button class="cancel" data-dismiss>Cancel</button></div><div class="res"></div><div class="hint">Enter searches every message. Narrow it with <code>from:alice</code> <code>in:#ops</code> <code>mentions:bob</code> <code>has:file</code> <code>after:2026-10-01</code> <code>before:…</code></div>`.s;
overlay.open(box);
const input = $('input', box), res = $('.res', box);
let items = [], sel = 0;
@@ -1785,6 +1818,15 @@ function onClick(e) {
const t = e.target;
const hit = sel => t.closest(sel);
let el;
+ if (hit('#back')) return back();
+ if ((el = hit('[data-nav]'))) {
+ const nav = el.dataset.nav;
+ if (nav === 'search') return openSearch();
+ if (nav === 'chats' || nav === 'people') { S.tab = nav; return go({layout: 'chat'}); }
+ return go({layout: nav});
+ }
+ if (hit('[data-dismiss]')) return overlay.close();
+ if (hit('[data-unpick]')) return go({chat: null, person: null});
if ((el = hit('[data-layout]'))) {
const layout = el.dataset.layout, r = S.route;
return go({layout, chat: r.chat, as: r.as, person: layout === 'map' ? null : r.person, q: layout === 'map' ? null : r.q});
@@ -1805,14 +1847,14 @@ function onClick(e) {
if ((el = hit('[data-knew]'))) return go({knew: el.dataset.knew, thread: null, ...away(el.dataset.knew)}, true);
if ((el = hit('[data-receipts]'))) return openReceipts(el, el.dataset.receipts);
if ((el = hit('[data-copy]'))) { navigator.clipboard?.writeText(el.dataset.copy); return toast(`Copied ${el.dataset.copy}`); }
- if (hit('[data-close-pane]')) return go({thread: null, knew: null}, true);
+ if (hit('[data-close-pane]')) return back({thread: null, knew: null}, true);
if ((el = hit('[data-fold]'))) return fold(el);
if ((el = hit('[data-more]'))) { el.previousElementSibling.classList.remove('long'); return el.remove(); }
if ((el = hit('[data-members]'))) return openMembers(el, el.dataset.members);
if ((el = hit('[data-sort]'))) return go({sort: el.dataset.sort}, true);
if ((el = hit('[data-board]'))) return go({layout: 'board', chat: el.dataset.board});
if ((el = hit('[data-goto]'))) return go({layout: el.dataset.goto, chat: S.route.chat || (S.view && S.view.chat), post: null}, false);
- if (hit('[data-back]')) return history.length > 1 ? history.back() : go({post: null}, true);
+ if (hit('[data-back]')) return back({post: null}, true);
if (hit('[data-open-post-chat]')) return go({layout: 'chat', chat: S.view.chat, m: +S.view.id.split(':')[1]});
if ((el = hit('[data-had]'))) return go({layout: 'chat', chat: el.dataset.had, m: el.dataset.upto || 1, had: el.dataset.upto, knew: S.route.knew});
if ((el = hit('[data-jump]'))) {
@@ -1826,12 +1868,18 @@ function onClick(e) {
if (S.route.layout === 'map') return go({chat: el.dataset.chat, person: null});
return go({layout: S.route.layout === 'board' ? 'board' : 'chat', chat: el.dataset.chat, m: el.dataset.seq, q: null, person: null});
}
+ if (HOVERLESS.matches && (el = hit('.msg')) && !hit('a, button, .actions')) { // a tap shows the message's actions
+ const was = el.classList.contains('act');
+ for (const m of $$('.msg.act')) m.classList.remove('act');
+ el.classList.toggle('act', !was);
+ if (!was) $('.actions', el).scrollIntoView({block: 'nearest'});
+ }
}
function onKey(e) {
const typing = /INPUT|TEXTAREA|SELECT/.test(document.activeElement?.tagName || '');
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') { e.preventDefault(); return overlay.on ? overlay.close() : openSearch(); }
- if (e.key === 'Escape') { if (overlay.on) return overlay.close(); if (S.route.thread || S.route.knew) return go({thread: null, knew: null}, true); }
+ if (e.key === 'Escape') { if (overlay.on) return overlay.close(); if (S.route.thread || S.route.knew) return back({thread: null, knew: null}, true); }
if (e.key === 'Enter' && document.activeElement?.dataset.text) return openText(document.activeElement.dataset.text);
if (typing || overlay.on || e.metaKey || e.ctrlKey || e.altKey) return;
if (e.key === '/') { e.preventDefault(); return openSearch(); }
@@ -1847,6 +1895,7 @@ function onKey(e) {
function tips() {
const tip = $('#tip');
+ document.addEventListener('touchstart', () => tip.classList.remove('on'), {passive: true}); // a tap's tip goes at the next touch
document.addEventListener('mouseover', e => {
const el = e.target.closest('[data-tip]');
if (!el) return tip.classList.remove('on');
@@ -1933,7 +1982,9 @@ const replay = {
if (this.on) this.seek(timeAt(e));
});
this.track.addEventListener('pointerleave', () => this.hov.classList.remove('on'));
- new ResizeObserver(([e]) => { this.tw = e.contentRect.width; this.th = e.contentRect.height; this.draw(true); }).observe(this.track);
+ // only the strip is drawn again: a change to the buttons here would resize the bar while the browser is still
+ // telling of its last size
+ new ResizeObserver(([e]) => { this.tw = e.contentRect.width; this.th = e.contentRect.height; this.drawn.bucket = null; this.draw(); }).observe(this.track);
setInterval(() => { if (this.shown && !this.on) this.activity(); }, 30000); // a live run grows
},
@@ -2185,7 +2236,7 @@ const replay = {
// Categorical colours in a fixed order, made to be told apart on a light or a dark background. Past eight, the rest are "other".
const PALETTE = ['#4269d0', '#efb118', '#ff725c', '#6cc5b0', '#3ca951', '#ff8ab7', '#a463f2', '#97bbf5'];
const OTHER = '#7b8394';
-const MAP = {pos: new Map(), view: null, colorBy: null, lens: true, mode: null}; // kept while the page is open
+const MAP = {pos: new Map(), view: null, colorBy: null, lens: !COARSE.matches, mode: null}; // kept while the page is open
const RING = 300; // the radius of the ring agents sit on, in the map's own units
const RING_MOST = 60; // more agents than this are laid out as a web
@@ -2270,13 +2321,12 @@ class MapView {
}
destroy() {
this.dead = true; this.resize.disconnect(); if (this.worker) this.worker.terminate();
- removeEventListener('mouseup', this.up);
cancelAnimationFrame(this.raf); this.raf = 0; S.mapPane = false;
if (this.side && this.side.destroy) this.side.destroy();
$('#pane').classList.remove('open', 'mappane'); $('#pane').replaceChildren();
}
size() {
- const dpr = devicePixelRatio || 1, c = this.canvas, r = c.getBoundingClientRect();
+ const dpr = Math.min(2, devicePixelRatio || 1), c = this.canvas, r = c.getBoundingClientRect(); // 3, as on many phones, would draw 2.25 times as many pixels for no gain anyone sees
for (const x of [this.base, this.fly, c]) { x.width = Math.max(1, Math.round(r.width * dpr)); x.height = Math.max(1, Math.round(r.height * dpr)); }
c.w = r.width; c.h = r.height;
this.dpr = dpr;
@@ -2309,6 +2359,8 @@ class MapView {
const nbrs = new Map();
for (const e of edges) { (nbrs.get(e.a) || nbrs.set(e.a, []).get(e.a)).push(e.b); (nbrs.get(e.b) || nbrs.set(e.b, []).get(e.b)).push(e.a); }
this.nodes = nodes; this.index = index; this.edges = edges; this.nbrs = nbrs;
+ // New counts are shown four times a second, or once on a web of thousands of links, which takes long to paint
+ if ((edges.length > 2000) !== this.big) { this.big = edges.length > 2000; this.reweigh = throttle(() => { if (!this.dead) this.weigh(); }, this.big ? 1000 : 250); }
this.direct = new Map(edges.filter(e => e.kind === 'direct').map(e => [e.chat, e]));
MAP.mode ||= nodes.filter(n => n.kind === 'agent').length <= RING_MOST ? 'ring' : 'web';
this.controls();
@@ -2765,9 +2817,13 @@ ${items.map(([label, c, cnt]) => html`<span class="li" title="${label}${cnt != n
const alpha = [0.035, 0.09, 0.2, 0.42, 0.85];
ctx.lineCap = 'round';
for (const [key, pts] of buckets) {
- const level = +key[1];
+ // The faint links, nearly all of them, are one screen pixel wide. The browser draws a line that thin in a fast
+ // way of its own: thousands of 1px lines on a 2x screen took it hundreds of milliseconds each time the counts
+ // changed, and those at one pixel a few. Thin lines that cross add up where wider ones in one path did not, so
+ // their alpha is left as it was, and the busy middle looks much as before.
+ const level = +key[1], thin = level < 3;
ctx.strokeStyle = key[0] === 'd' ? `rgba(${ink().edgeDm}, ${alpha[level]})` : `rgba(${ink().edge}, ${alpha[level] * 0.8})`;
- ctx.lineWidth = level >= 3 ? 1.6 : 1;
+ ctx.lineWidth = thin ? 1 / this.dpr : 1.6;
ctx.beginPath();
for (let i = 0; i < pts.length; i += 4) { ctx.moveTo(pts[i], pts[i + 1]); ctx.lineTo(pts[i + 2], pts[i + 3]); }
ctx.stroke();
@@ -2853,32 +2909,62 @@ ${items.map(([label, c, cnt]) => html`<span class="li" title="${label}${cnt != n
this.raf = requestAnimationFrame(loop);
}
- // ---- the mouse
+ // ---- the mouse and fingers
listen() {
- const c = this.canvas;
- let down = null;
- c.addEventListener('mousemove', e => {
- const r = c.getBoundingClientRect();
- this.mouse = {x: e.clientX - r.left, y: e.clientY - r.top};
+ const c = this.canvas, fingers = new Map();
+ const at = e => { const r = c.getBoundingClientRect(); return {x: e.clientX - r.left, y: e.clientY - r.top}; };
+ let down = null, pinch = null;
+ c.addEventListener('pointerdown', e => {
+ c.setPointerCapture(e.pointerId);
+ this.slop = e.pointerType === 'mouse' ? 0 : 12; // a fingertip is less exact than a mouse
+ if (e.pointerType !== 'mouse') fingers.set(e.pointerId, at(e));
+ if (fingers.size === 2) { // two fingers zoom about the point between them, and move the map as they move
+ const [p, q] = [...fingers.values()], v = this.view, mx = (p.x + q.x) / 2, my = (p.y + q.y) / 2;
+ pinch = {d: Math.max(10, Math.hypot(p.x - q.x, p.y - q.y)), k: v.k, wx: v.x + (mx - c.w / 2) / v.k, wy: v.y + (my - c.h / 2) / v.k};
+ down = null; this.dragging = true; this.mouse = null; this.card.hidden = true;
+ return;
+ }
+ down = {x: e.clientX, y: e.clientY, vx: this.view.x, vy: this.view.y}; this.dragging = false;
+ this.mouse = at(e);
+ });
+ c.addEventListener('pointermove', e => {
+ if (fingers.has(e.pointerId)) fingers.set(e.pointerId, at(e));
+ if (pinch) {
+ if (fingers.size < 2) return;
+ const [p, q] = [...fingers.values()], v = this.view, mx = (p.x + q.x) / 2, my = (p.y + q.y) / 2;
+ v.k = Math.max(0.03, Math.min(12, pinch.k * Math.hypot(p.x - q.x, p.y - q.y) / pinch.d));
+ v.x = pinch.wx - (mx - c.w / 2) / v.k; v.y = pinch.wy - (my - c.h / 2) / v.k;
+ return this.kick();
+ }
+ this.mouse = at(e);
if (down) {
const dx = e.clientX - down.x, dy = e.clientY - down.y;
- if (Math.abs(dx) + Math.abs(dy) > 3) { this.dragging = true; c.classList.add('drag'); this.card.hidden = true; }
+ if (Math.abs(dx) + Math.abs(dy) > (e.pointerType === 'mouse' ? 3 : 8)) { this.dragging = true; c.classList.add('drag'); this.card.hidden = true; }
if (this.dragging) { this.view.x = down.vx - dx / this.view.k; this.view.y = down.vy - dy / this.view.k; }
- } else {
+ } else if (e.pointerType === 'mouse') {
const hit = this.hit(this.mouse.x, this.mouse.y), edge = hit == null ? this.hitEdge(this.mouse.x, this.mouse.y) : null;
if (hit !== this.hover || edge !== this.hoverEdge) { this.hover = hit; this.hoverEdge = edge; c.classList.toggle('point', hit != null || !!edge); }
this.showCard();
}
this.kick();
});
- c.addEventListener('mouseleave', () => { this.mouse = null; this.hover = null; this.hoverEdge = null; this.card.hidden = true; this.kick(); });
- c.addEventListener('mousedown', e => { down = {x: e.clientX, y: e.clientY, vx: this.view.x, vy: this.view.y}; this.dragging = false; });
- addEventListener('mouseup', this.up = () => {
- if (!down) return;
- const clicked = !this.dragging;
+ const up = (e, cancel) => {
+ fingers.delete(e.pointerId);
+ if (pinch) { // the last finger up ends a pinch, and taps nothing
+ if (!fingers.size) { pinch = null; this.dragging = false; }
+ return this.kick();
+ }
+ const clicked = down && !this.dragging && !cancel;
down = null; this.dragging = false; c.classList.remove('drag');
if (clicked && this.mouse) this.click(this.hit(this.mouse.x, this.mouse.y), this.hitEdge(this.mouse.x, this.mouse.y));
+ if (e.pointerType !== 'mouse') { this.mouse = null; this.hover = null; this.hoverEdge = null; } // nothing stays under a lifted finger
this.kick();
+ };
+ c.addEventListener('pointerup', e => up(e, false));
+ c.addEventListener('pointercancel', e => up(e, true));
+ c.addEventListener('pointerleave', e => {
+ if (e.pointerType !== 'mouse' || down) return;
+ this.mouse = null; this.hover = null; this.hoverEdge = null; this.card.hidden = true; this.kick();
});
c.addEventListener('wheel', e => {
e.preventDefault();
@@ -2901,13 +2987,13 @@ ${items.map(([label, c, cnt]) => html`<span class="li" title="${label}${cnt != n
for (let i = 0; i < this.nodes.length; i++) {
const n = this.nodes[i];
if (n.kind === 'hub' && replay.on && !S.chats.get(n.chat)?.born) continue;
- const d = Math.hypot(n.sx - x, n.sy - y), r = this.radius(n, scale) + (MAP.mode === 'ring' ? 3 : 5);
+ const d = Math.hypot(n.sx - x, n.sy - y), r = this.radius(n, scale) + (MAP.mode === 'ring' ? 3 : 5) + (this.slop || 0);
if (d < r && d < bd) { bd = d; best = i; }
}
return best;
}
hitEdge(x, y) { // a direct chat's chord under the mouse
- let best = null, bd = 5;
+ let best = null, bd = 5 + (this.slop || 0);
for (const e of this.direct.values()) {
if (!e.w && MAP.mode === 'ring') continue;
const a = this.nodes[e.a], b = this.nodes[e.b], dx = b.sx - a.sx, dy = b.sy - a.sy, l = dx * dx + dy * dy;
@@ -2954,14 +3040,16 @@ ${Object.keys(u.fields || {}).length ? html`<div class="cf">${Object.entries(u.f
const r = S.route, key = r.chat ? 'c:' + r.chat : r.person ? 'u:' + r.person : '';
this.selected = key ? this.index.get(key) ?? null : null;
this.selChat = r.chat && S.chats.get(r.chat)?.kind === 'direct' ? r.chat : null;
- if (key !== this.sideKey) {
- this.sideKey = key;
+ if (key + PHONE.matches !== this.sideKey) {
+ this.sideKey = key + PHONE.matches;
if (this.side && this.side.destroy) this.side.destroy();
const pane = $('#pane');
pane.classList.add('open', 'mappane');
pane.replaceChildren();
+ // On a phone the pane is a sheet under the map, for what is picked: every message as it comes has no room there.
this.side = r.chat && S.chats.has(r.chat) ? new ChatView(pane, r.chat, {inPane: true})
- : r.person ? new AgentPane(pane, r.person) : new ActivityView(pane, {inPane: true});
+ : r.person ? new AgentPane(pane, r.person) : PHONE.matches ? null : new ActivityView(pane, {inPane: true});
+ if (key) pane.insertAdjacentHTML('afterbegin', '<button class="sheetx" data-unpick title="Close" aria-label="Close">×</button>');
}
this.kick();
}
@@ -2996,7 +3084,6 @@ ${Object.keys(u.fields || {}).length ? html`<div class="cf">${Object.entries(u.f
this.kick();
}
regrow = throttle(() => { if (!this.dead) this.build(false); }, 3000);
- reweigh = throttle(() => { if (!this.dead) this.weigh(); }, 250);
}
// An agent picked on the map: who it is, and its latest messages.
@@ -3058,6 +3145,7 @@ function showTheme() {
const b = $('#theme');
b.innerHTML = THEMES[t].icon;
b.title = THEMES[t].title;
+ $('meta[name="theme-color"]').content = getComputedStyle($('#top')).backgroundColor; // a phone's browser bar matches
if (S.view && S.view.onTheme) S.view.onTheme();
replay.draw(true);
}
@@ -3078,6 +3166,55 @@ function ink() {
return INK;
}
+// ---------------------------------------------------------------------- widths
+
+// The sidebar and the pane beside the chat are as wide as their handles are dragged, and stay so in this browser. A
+// double click on a handle puts its default back, and the arrow keys move a handle that has the focus. The chat in
+// between keeps at least 400px.
+const WIDTHS_KEY = 'swarmchat.view.widths';
+const WIDE = {side: [180, 480], pane: [300, 760]};
+function grips() {
+ const app = $('#app'), saved = JSON.parse(localStorage.getItem(WIDTHS_KEY) || '{}');
+ const width = which => $(which === 'side' ? '#side' : '#pane').getBoundingClientRect().width;
+ const set = (which, w) => {
+ const other = which === 'side' ? width('pane') : width('side'), [lo, hi] = WIDE[which];
+ w = Math.round(Math.max(lo, Math.min(hi, innerWidth - other - 400, w)));
+ app.style.setProperty(`--${which}-w`, w + 'px');
+ return w;
+ };
+ const keep = (which, w) => {
+ if (w == null) delete saved[which]; else saved[which] = w;
+ localStorage.setItem(WIDTHS_KEY, JSON.stringify(saved));
+ };
+ for (const which in WIDE) if (saved[which]) app.style.setProperty(`--${which}-w`, saved[which] + 'px');
+ app.addEventListener('pointerdown', e => {
+ const g = e.target.closest('.grip');
+ if (!g || e.button !== 0) return;
+ e.preventDefault();
+ const which = g.dataset.grip, x0 = e.clientX, w0 = width(which), sign = which === 'side' ? 1 : -1;
+ let w = w0;
+ g.setPointerCapture(e.pointerId);
+ document.body.classList.add('resizing'); g.classList.add('on');
+ g.onpointermove = m => { w = set(which, w0 + sign * (m.clientX - x0)); };
+ g.onpointerup = g.onpointercancel = () => {
+ g.onpointermove = g.onpointerup = g.onpointercancel = null;
+ document.body.classList.remove('resizing'); g.classList.remove('on');
+ if (w !== w0) keep(which, w);
+ };
+ });
+ app.addEventListener('dblclick', e => {
+ const g = e.target.closest('.grip');
+ if (g) { app.style.removeProperty(`--${g.dataset.grip}-w`); keep(g.dataset.grip, null); }
+ });
+ app.addEventListener('keydown', e => {
+ const g = e.target.closest('.grip');
+ if (!g || (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight')) return;
+ e.preventDefault(); e.stopPropagation(); // not a step in a replay
+ const which = g.dataset.grip, sign = which === 'side' ? 1 : -1;
+ keep(which, set(which, width(which) + sign * (e.key === 'ArrowRight' ? 16 : -16)));
+ });
+}
+
// ---------------------------------------------------------------------- start
function login(error) {
@@ -3108,16 +3245,21 @@ async function start() {
side.init();
replay.init();
tips();
- document.addEventListener('click', onClick);
+ // On the app and the overlay rather than the document: Safari on a phone turns a tap into a click only where something
+ // below the document listens for clicks.
+ for (const el of [$('#app'), $('#overlay')]) el.addEventListener('click', onClick);
new MutationObserver(watchPictures).observe(document.body, {childList: true, subtree: true});
document.addEventListener('keydown', onKey);
addEventListener('hashchange', route);
+ PHONE.addEventListener('change', () => route());
+ COARSE.addEventListener('change', () => side.build());
await route();
follow();
}
(async function boot() {
showTheme();
+ grips(); // before anything is drawn, so a saved width shows at once
const found = location.hash.match(/(^#|&)token=([0-9a-f]{16,})/);
if (found) {
localStorage.setItem('swarmchat.view.token', found[2]);
diff --git a/swarmchat/page/gate.html b/swarmchat/page/gate.html
index d695bb3..21dea93 100644
--- a/swarmchat/page/gate.html
+++ b/swarmchat/page/gate.html
@@ -17,6 +17,7 @@ input, button { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1p
background: light-dark(#f7f7f9, #181b21); color: inherit; }
button { cursor: pointer; }
.err { color: light-dark(#dc2626, #f87171); min-height: 1.5em; margin: 0; }
+@media (pointer: coarse) { input { font-size: 16px; } } /* smaller, and iOS zooms the page in on focus */
</style>
</head>
<body>
diff --git a/swarmchat/page/index.html b/swarmchat/page/index.html
index ac281f6..d6116be 100644
--- a/swarmchat/page/index.html
+++ b/swarmchat/page/index.html
@@ -2,7 +2,8 @@
<html lang="en">
<head>
<meta charset="utf-8">
-<meta name="viewport" content="width=device-width, initial-scale=1">
+<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
+<meta name="theme-color" content="#f9f9fb">
<meta name="referrer" content="no-referrer">
<title>swarmchat view</title>
<link rel="icon" href="data:,">
@@ -18,10 +19,10 @@
<button data-layout="board" title="Posts and comments, like Reddit (2)">Board</button>
<button data-layout="map" title="Everyone at once (3)">Map</button>
</nav>
- <button id="replay" class="replaybtn" title="Play the run again from its start (R)">▶ Replay</button>
+ <button id="replay" class="replaybtn" title="Play the run again from its start (R)" aria-label="Replay">▶<span> Replay</span></button>
<div class="grow"></div>
<button id="as" class="as" title="See everything as one agent sees it"></button>
- <button id="find" class="find" title="Search people, chats and messages">Search<kbd>⌘K</kbd></button>
+ <button id="find" class="find" title="Search people, chats and messages"><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg><span>Search</span><kbd>⌘K</kbd></button>
<button id="theme" class="theme"></button>
<span id="live" class="live" title=""></span>
</header>
@@ -32,17 +33,27 @@
</div>
<input id="filter" placeholder="Filter" autocomplete="off" spellcheck="false">
<div id="list" class="vlist"><div class="vspace"></div><div class="vrows"></div></div>
+ <div class="grip" data-grip="side" aria-label="Sidebar width" role="separator" aria-orientation="vertical" tabindex="0" title="Drag to change the width. Double-click for the default."></div>
</aside>
+ <button id="back" class="back" title="Back" aria-label="Back"><svg viewBox="0 0 24 24"><path d="M15 5l-7 7 7 7"/></svg></button>
<main id="main"></main>
<section id="pane"></section>
+ <div class="grip" data-grip="pane" aria-label="Pane width" role="separator" aria-orientation="vertical" tabindex="0" title="Drag to change the width. Double-click for the default."></div>
<footer id="bar">
- <button class="play" data-play></button>
+ <button class="play" data-play>▶ Replay</button>
<div class="track"><canvas></canvas><div class="head" hidden></div><div class="hov"></div></div>
<div class="clock"></div>
- <div class="seg small speeds"></div>
- <button class="btn" data-quiet title="Jump over stretches with no messages">Skip gaps</button>
- <button class="btn" data-live title="Leave the replay and follow the run as it happens (R)">Live</button>
+ <div class="seg small speeds" hidden></div>
+ <button class="btn" data-quiet title="Jump over stretches with no messages" hidden>Skip gaps</button>
+ <button class="btn" data-live title="Leave the replay and follow the run as it happens (R)" hidden>Live</button>
</footer>
+ <nav id="tabbar">
+ <button data-nav="chats"><svg viewBox="0 0 24 24"><path d="M4 5h16v11H9l-5 4z"/></svg><span>Chats</span></button>
+ <button data-nav="people"><svg viewBox="0 0 24 24"><circle cx="9" cy="8" r="3.5"/><path d="M2.5 20c.6-3.6 3.2-5.5 6.5-5.5s5.9 1.9 6.5 5.5"/><path d="M15.5 4.8a3.5 3.5 0 0 1 0 6.4M18 14.8c2 .8 3.2 2.5 3.5 5.2"/></svg><span>People</span></button>
+ <button data-nav="board"><svg viewBox="0 0 24 24"><rect x="4" y="4" width="16" height="6" rx="1.5"/><rect x="4" y="14" width="16" height="6" rx="1.5"/></svg><span>Board</span></button>
+ <button data-nav="map"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="8"/><circle cx="12" cy="4" r="1.6"/><circle cx="19" cy="15" r="1.6"/><circle cx="5" cy="15" r="1.6"/><circle cx="12" cy="12" r="2.4"/></svg><span>Map</span></button>
+ <button data-nav="search"><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg><span>Search</span></button>
+ </nav>
</div>
<div id="overlay"></div>
<div id="tip"></div>