visualproof 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -7
- package/dist/assets/latex/visualproof.sty +19 -9
- package/dist/assets/tips/tour-agent.webp +0 -0
- package/dist/assets/tips/tour-arrange.webp +0 -0
- package/dist/assets/tips/tour-artwork.webp +0 -0
- package/dist/assets/tips/tour-checks.webp +0 -0
- package/dist/assets/tips/tour-keys.webp +0 -0
- package/dist/assets/tips/tour-library.webp +0 -0
- package/dist/assets/tips/tour-project.webp +0 -0
- package/dist/assets/tips/tour-review.webp +0 -0
- package/dist/assets/tips/tour-share.webp +0 -0
- package/dist/assets/tips/tour-source.webp +0 -0
- package/dist/assets/tips/tour-target.webp +0 -0
- package/dist/assets/tips/tour-view.webp +0 -0
- package/dist/assets/tips/tour.json +117 -112
- package/dist/assets/tips/tour.webp +0 -0
- package/dist/mcp/visualproof-mcp.mjs +7 -3
- package/dist/server/access.js +37 -1
- package/dist/server/accesspage.js +130 -0
- package/dist/server/agent.js +11 -5
- package/dist/server/agentlibrary.js +1 -1
- package/dist/server/agentviews.js +1 -1
- package/dist/server/artcmd.js +1 -1
- package/dist/server/askfollow.js +1 -4
- package/dist/server/buildwatch.js +133 -0
- package/dist/server/deploy.js +844 -0
- package/dist/server/doctor.js +15 -3
- package/dist/server/events.js +20 -5
- package/dist/server/export.js +17 -4
- package/dist/server/fetchurl.js +30 -13
- package/dist/server/film.js +1 -1
- package/dist/server/history.js +3 -1
- package/dist/server/historyapi.js +100 -50
- package/dist/server/historythread.js +206 -0
- package/dist/server/hover.js +8 -0
- package/dist/server/identity.js +25 -1
- package/dist/server/library.js +10 -3
- package/dist/server/live.js +206 -28
- package/dist/server/lostfound.js +3 -2
- package/dist/server/main.js +361 -50
- package/dist/server/poppler.js +48 -10
- package/dist/server/renames.js +10 -5
- package/dist/server/review.js +32 -2
- package/dist/server/reviewapi.js +1 -1
- package/dist/server/status.js +144 -50
- package/dist/server/talk.js +7 -2
- package/dist/server/usage.js +51 -0
- package/dist/server/views.js +21 -7
- package/dist/shared/board.js +2 -1
- package/dist/shared/collab.js +14 -8
- package/dist/shared/deploy.js +35 -0
- package/dist/shared/doc/latex.js +5 -3
- package/dist/shared/doc/outline.js +6 -3
- package/dist/shared/layout.js +297 -70
- package/dist/shared/libm.js +366 -0
- package/dist/shared/library.js +11 -6
- package/dist/shared/palette.js +1 -1
- package/dist/shared/review.js +7 -5
- package/dist/shared/search.js +7 -3
- package/dist/shared/separate.js +556 -32
- package/dist/shared/views.js +8 -1
- package/dist/web/bundle/app.js +3595 -1520
- package/dist/web/bundle/edges.js +44 -16
- package/dist/web/bundle/layout.js +1026 -80
- package/dist/web/index.html +2 -2
- package/dist/web/src/artwork.js +25 -4
- package/dist/web/src/axiomring.js +42 -0
- package/dist/web/src/bundles.js +52 -16
- package/dist/web/src/canvas.js +109 -54
- package/dist/web/src/overview.js +4 -1
- package/dist/web/src/past.js +28 -0
- package/dist/web/src/scene.js +13 -12
- package/dist/web/src/selection.js +47 -4
- package/dist/web/src/status.js +32 -2
- package/dist/web/src/theme.js +108 -0
- package/dist/web/style.css +181 -45
- package/docs/agent-api/following.md +1 -1
- package/docs/agent-api/history.md +3 -0
- package/docs/agent-api/library.md +1 -1
- package/docs/agent-api/requests.md +4 -1
- package/docs/agent-api/views.md +1 -1
- package/package.json +1 -1
package/dist/web/src/past.js
CHANGED
|
@@ -173,6 +173,20 @@ export function latestOf(snaps) {
|
|
|
173
173
|
best = s;
|
|
174
174
|
return best;
|
|
175
175
|
}
|
|
176
|
+
/** Where a reader in the Time Machine goes once the server has read a new build (the owner's decision
|
|
177
|
+
* of 2026-10-18, HistorySpec decision 18): one at the latest build goes on to the new latest, so
|
|
178
|
+
* that a new build is never left behind as a past one; one at a build they chose stays there, and so
|
|
179
|
+
* does one on a view kept at the build they are at (it stays kept), and one following someone,
|
|
180
|
+
* whose build presence brings. `at` is the build aimed at, `before` and `now` the latest builds
|
|
181
|
+
* before and after the list was read again, `kept` the build the view on show is kept at. The build
|
|
182
|
+
* to go to, or null to stay. */
|
|
183
|
+
export function onNewBuild(at, before, now, o) {
|
|
184
|
+
if (at === null || now === null || before === now || at !== before)
|
|
185
|
+
return null;
|
|
186
|
+
if (o.following || o.kept === at)
|
|
187
|
+
return null;
|
|
188
|
+
return now;
|
|
189
|
+
}
|
|
176
190
|
// ------------------------------------------------------------------------------------ the graph
|
|
177
191
|
/** The memory a past board is laid out from where it has none of its own (shared/layout.ts,
|
|
178
192
|
* stabilize): the layout of the board of now, so that what both have stays where it is; a
|
|
@@ -209,6 +223,20 @@ export function markWords(marks, now) {
|
|
|
209
223
|
out.push("changed since");
|
|
210
224
|
return out;
|
|
211
225
|
}
|
|
226
|
+
/** What the bar says of a build that could not read some of the project's files (its snapshot's
|
|
227
|
+
* `missing`: a failed file, what imports one): what they held is on none of its boards and counts as
|
|
228
|
+
* no change against now (HistorySpec decision 6), so that it is not taken for gone. Null for a build
|
|
229
|
+
* that read them all. */
|
|
230
|
+
export function unreadWords(missing) {
|
|
231
|
+
const n = missing.length;
|
|
232
|
+
if (!n)
|
|
233
|
+
return null;
|
|
234
|
+
const which = missing.slice(0, 8).join(", ") + (n > 8 ? `, and ${n - 8} more` : "");
|
|
235
|
+
return {
|
|
236
|
+
label: `${n} file${n === 1 ? "" : "s"} unread`,
|
|
237
|
+
tip: `${n === 1 ? "A file" : `${n} files`} could not be read at this build (a failed file, or what imports one): ${which}. What ${n === 1 ? "it" : "they"} held is on none of its boards, and is not counted as changed.`,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
212
240
|
/** The marks of the declarations of a board (`toFull`: board → past graph), in the board's
|
|
213
241
|
* numbering, and the names now of those renamed. */
|
|
214
242
|
export function boardMarks(p, n, toFull) {
|
package/dist/web/src/scene.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// The scene may hold room for what is not the board's: the discs the reader's visitors and their
|
|
17
17
|
// temporary clusters take (ViewSpec decision 27; web/src/visits.ts). What they cover makes way, as
|
|
18
18
|
// from a drop; they are never pins, and when they go everything is where it was.
|
|
19
|
+
import { hypot } from "../../shared/libm.js";
|
|
19
20
|
import { Separator } from "../../shared/separate.js";
|
|
20
21
|
/** collision radius of a declaration, as the server packs them */
|
|
21
22
|
export const LEAF_R = 5;
|
|
@@ -423,7 +424,7 @@ export class Scene {
|
|
|
423
424
|
if (p < 0)
|
|
424
425
|
return [lx, ly];
|
|
425
426
|
const room = Math.max(0, this.homeR[p] - this.padOf(p) - r);
|
|
426
|
-
const d =
|
|
427
|
+
const d = hypot(lx, ly);
|
|
427
428
|
return d > room ? [(lx * room) / d, (ly * room) / d] : [lx, ly];
|
|
428
429
|
}
|
|
429
430
|
/** Room between a cluster's contents and its circle, for its label. */
|
|
@@ -520,9 +521,9 @@ export class Scene {
|
|
|
520
521
|
const DENSITY = 0.72;
|
|
521
522
|
let area = 0;
|
|
522
523
|
for (const it of (shrunk ? items : []).filter((x) => !x.pinned).sort((a, b) => a.hx * a.hx + a.hy * a.hy - (b.hx * b.hx + b.hy * b.hy))) {
|
|
523
|
-
const len =
|
|
524
|
+
const len = hypot(it.hx, it.hy);
|
|
524
525
|
const ux = len > 1e-6 ? it.hx / len : 1, uy = len > 1e-6 ? it.hy / len : 0;
|
|
525
|
-
area += (Math.PI * (it.r + GAP / 2)
|
|
526
|
+
area += (Math.PI * ((it.r + GAP / 2) * (it.r + GAP / 2))) / DENSITY;
|
|
526
527
|
const d = Math.min(len, Math.max(0, Math.sqrt(area / Math.PI) - it.r));
|
|
527
528
|
it.x = ux * d;
|
|
528
529
|
it.y = uy * d;
|
|
@@ -545,7 +546,7 @@ export class Scene {
|
|
|
545
546
|
const inward = shrunk && !grown && !pinned;
|
|
546
547
|
const room = self >= 0 ? homeR - this.padOf(self) : Infinity;
|
|
547
548
|
const limit = Float64Array.from(items, (it) => {
|
|
548
|
-
const len =
|
|
549
|
+
const len = hypot(it.hx, it.hy);
|
|
549
550
|
return inward ? len : Math.max(len, room - it.r);
|
|
550
551
|
});
|
|
551
552
|
const sep = this.separator;
|
|
@@ -585,7 +586,7 @@ export class Scene {
|
|
|
585
586
|
});
|
|
586
587
|
let extent = 0;
|
|
587
588
|
for (const it of items) {
|
|
588
|
-
extent = Math.max(extent,
|
|
589
|
+
extent = Math.max(extent, hypot(it.x, it.y) + it.r);
|
|
589
590
|
if (it.c >= 0) {
|
|
590
591
|
this.ancCX[it.c] = it.x;
|
|
591
592
|
this.ancCY[it.c] = it.y;
|
|
@@ -629,17 +630,17 @@ export class Scene {
|
|
|
629
630
|
const idx = Array.from({ length: n }, (_, j) => j);
|
|
630
631
|
const B = { n, x, y, r, pinned, seq, big: Int32Array.from(idx.filter((j) => r[j] > LEAF_R + 0.1)), small: Int32Array.from(idx.filter((j) => r[j] <= LEAF_R + 0.1)) };
|
|
631
632
|
const room = self >= 0 ? homeR - this.padOf(self) : Infinity;
|
|
632
|
-
const limit = Float64Array.from(idx, (j) => Math.max(
|
|
633
|
+
const limit = Float64Array.from(idx, (j) => Math.max(hypot(x[j], y[j]), room - r[j]));
|
|
633
634
|
// how far the children reach before they make way: the circle grows by what they are pushed out
|
|
634
635
|
let reach = 0;
|
|
635
636
|
for (let j = 0; j < nk; j++)
|
|
636
|
-
reach = Math.max(reach,
|
|
637
|
+
reach = Math.max(reach, hypot(x[j], y[j]) + r[j]);
|
|
637
638
|
// only what a held disc covers makes way: overlaps the board's own arrangement has are its own
|
|
638
639
|
// (a layout may hold some), and stay as they are where the held discs cover nothing
|
|
639
640
|
let covers = false;
|
|
640
641
|
for (let h = nk; h < n && !covers; h++)
|
|
641
642
|
for (let j = 0; j < n && !covers; j++)
|
|
642
|
-
if (j !== h &&
|
|
643
|
+
if (j !== h && hypot(x[j] - x[h], y[j] - y[h]) < r[j] + r[h] - 0.5)
|
|
643
644
|
covers = true;
|
|
644
645
|
const sep = this.separator;
|
|
645
646
|
if (covers) {
|
|
@@ -665,7 +666,7 @@ export class Scene {
|
|
|
665
666
|
return 0;
|
|
666
667
|
let pushed = 0, own = 0;
|
|
667
668
|
for (let j = 0; j < n; j++) {
|
|
668
|
-
const d =
|
|
669
|
+
const d = hypot(x[j], y[j]) + r[j];
|
|
669
670
|
if (j < nk)
|
|
670
671
|
pushed = Math.max(pushed, d);
|
|
671
672
|
else
|
|
@@ -783,17 +784,17 @@ export class Scene {
|
|
|
783
784
|
let reach = 0;
|
|
784
785
|
const x = this.cwx[c], y = this.cwy[c];
|
|
785
786
|
for (const k of this.kidsC[c])
|
|
786
|
-
reach = Math.max(reach,
|
|
787
|
+
reach = Math.max(reach, hypot(this.cwx[k] - x, this.cwy[k] - y) + this.drawnR[k]);
|
|
787
788
|
for (const i of this.kidsN[c]) {
|
|
788
789
|
if (this.nodeRep[i] >= 0)
|
|
789
790
|
continue;
|
|
790
|
-
reach = Math.max(reach,
|
|
791
|
+
reach = Math.max(reach, hypot(this.nwx[i] - x, this.nwy[i] - y) + LEAF_R);
|
|
791
792
|
}
|
|
792
793
|
// what is held in it is inside it too: a visitor's temporary clusters (setHeld)
|
|
793
794
|
const held = this.held.get(c), at = this.heldAt.get(c);
|
|
794
795
|
if (held && at)
|
|
795
796
|
for (let j = 0; j < held.length; j++)
|
|
796
|
-
reach = Math.max(reach, (
|
|
797
|
+
reach = Math.max(reach, (hypot(at[2 * j], at[2 * j + 1]) + held[j].r) * this.scale[c]);
|
|
797
798
|
this.drawnR[c] = Math.max(this.curR[c], reach > 0 ? reach + MARGIN : 0);
|
|
798
799
|
}
|
|
799
800
|
}
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
// it says in words, reading picks back from a query (an address, a reader followed, an agent), what
|
|
18
18
|
// a click or a shift-click does to the list, and how key 2 steps through Rests on. main.ts keeps the
|
|
19
19
|
// list and the thing the panel tells of; web/src/selbar.ts shows the list.
|
|
20
|
+
import { renameInQuery } from "../../shared/moves.js";
|
|
20
21
|
import { describe, keysQuery, parseQuery, printQuery, readKeys } from "../../shared/query.js";
|
|
21
22
|
/** Every tool, as the address and presence name them (web/src/state.ts). */
|
|
22
23
|
export const TOOLS = ["plain", "deps", "tcb", "keys", "refs", "apps"];
|
|
@@ -117,19 +118,25 @@ function short(name) {
|
|
|
117
118
|
const tail = parts[parts.length - 1];
|
|
118
119
|
return /^\d+$/.test(tail) || tail.length <= 2 ? parts.slice(-2).join(".") : tail;
|
|
119
120
|
}
|
|
120
|
-
/** A pick in a few words, as its chip says it: "Minimal", "TCB of not_fermat_42", "ns Fermat42".
|
|
121
|
-
|
|
121
|
+
/** A pick in a few words, as its chip says it: "Minimal", "TCB of not_fermat_42", "ns Fermat42".
|
|
122
|
+
* With `names` (shared/titles.ts, the graph on show's), a name is said as a view's title says it:
|
|
123
|
+
* with the parents that tell it apart from the project's others of its kind ("what
|
|
124
|
+
* Dim24.MainTheorem uses" beside Dim8's; ViewSpec decision 25). */
|
|
125
|
+
export function pickWords(p, names) {
|
|
122
126
|
const r = p.root;
|
|
123
127
|
let what;
|
|
124
128
|
if (!r)
|
|
125
129
|
return describe(p.q);
|
|
126
130
|
if ("decl" in r)
|
|
127
|
-
what = short(r.decl);
|
|
131
|
+
what = names?.decl(r.decl) ?? short(r.decl);
|
|
128
132
|
else if (r.cluster === EXT)
|
|
129
133
|
what = "the outside world";
|
|
130
134
|
else {
|
|
131
135
|
const ext = r.cluster.startsWith(EXT + ".");
|
|
132
|
-
|
|
136
|
+
const by = r.by === "module" ? "file" : "ns";
|
|
137
|
+
// the outside world's namespaces and folders are not the project's: said by their last part
|
|
138
|
+
const told = ext || !names ? short(ext ? r.cluster.slice(EXT.length + 1) : r.cluster) : names[by](r.cluster);
|
|
139
|
+
what = `${by} ${told}${ext ? " (outside)" : ""}`;
|
|
133
140
|
}
|
|
134
141
|
if (p.tool === "keys")
|
|
135
142
|
return `keys ${what} rests on`;
|
|
@@ -204,6 +211,42 @@ export function retool(picks, shown, tool, keys = () => null) {
|
|
|
204
211
|
const next = withTool(last, tool, keys);
|
|
205
212
|
return next ? { picks: [next], shown: shownOf(next) } : { picks, shown };
|
|
206
213
|
}
|
|
214
|
+
/** The selection once a build renamed what it is on (HistorySpec decision 10; the manual's "Live": a
|
|
215
|
+
* new graph keeps the selection): a declaration picked, or told of in the panel, that the graph no
|
|
216
|
+
* longer has, and that the renames in force lead on to one it has, is that one. `renamed` maps each
|
|
217
|
+
* name to the one before it (ReviewData.renamed, shared/moves.ts); `has` says what the graph has.
|
|
218
|
+
* The same array and object where nothing it names was renamed. */
|
|
219
|
+
export function followRenames(picks, shown, renamed, has) {
|
|
220
|
+
if (!renamed)
|
|
221
|
+
return { picks, shown };
|
|
222
|
+
const ahead = new Map();
|
|
223
|
+
for (const [to, from] of Object.entries(renamed))
|
|
224
|
+
ahead.set(from, to);
|
|
225
|
+
/** its name now, where it is gone and a rename leads on to one the graph has; else null */
|
|
226
|
+
const now = (name) => {
|
|
227
|
+
if (has(name))
|
|
228
|
+
return null;
|
|
229
|
+
let n = name;
|
|
230
|
+
// a chain is as long as the renames of one declaration; a loop (a log edited by hand) is cut short
|
|
231
|
+
for (let k = 0; k < 1000 && ahead.has(n); k++) {
|
|
232
|
+
n = ahead.get(n);
|
|
233
|
+
if (has(n))
|
|
234
|
+
return n;
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
};
|
|
238
|
+
let changed = false;
|
|
239
|
+
const next = picks.map((p) => {
|
|
240
|
+
const from = p.root && "decl" in p.root ? p.root.decl : null;
|
|
241
|
+
const to = from === null ? null : now(from);
|
|
242
|
+
if (to === null)
|
|
243
|
+
return p;
|
|
244
|
+
changed = true;
|
|
245
|
+
return { ...p, root: { decl: to }, q: renameInQuery(p.q, from, to) };
|
|
246
|
+
});
|
|
247
|
+
const to = shown && "decl" in shown ? now(shown.decl) : null;
|
|
248
|
+
return { picks: changed ? next : picks, shown: to === null ? shown : { decl: to } };
|
|
249
|
+
}
|
|
207
250
|
/** The edges a selection draws (canvas.ts, MODE_SITES): a TCB's statement and body edges when every
|
|
208
251
|
* pick is a TCB, else every edge between what is lit. (While the tool is Keys the canvas draws the
|
|
209
252
|
* key graph's edges instead: shared/keys.ts, litKeyEdges.) */
|
package/dist/web/src/status.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// review at all (not yet reviewed, trusted). A file being compiled shows so while it lasts. What
|
|
6
6
|
// agents advise is not among the states: advice is never counted, and the panel shows it apart
|
|
7
7
|
// (AgentSpec decision 2).
|
|
8
|
-
import { statusOf
|
|
8
|
+
import { statusOf } from "../../shared/review.js";
|
|
9
|
+
import { needsReview } from "../../shared/reviewqueue.js";
|
|
9
10
|
/** The states, most urgent first; a declaration's code is its index here. The legend lists them in
|
|
10
11
|
* this order, and the CSS colours are `--status-<state>`. */
|
|
11
12
|
export const STATUSES = ["failed", "building", "sorry", "commented", "stale", "approved", "unreviewed", "trusted"];
|
|
@@ -53,7 +54,8 @@ export function statusState(d, g, i, file, sorryAx) {
|
|
|
53
54
|
return ST_STALE;
|
|
54
55
|
if (s === "approved")
|
|
55
56
|
return ST_APPROVED;
|
|
56
|
-
|
|
57
|
+
// a non-standard axiom needs review whatever trusts it (ReviewSpec decision 3)
|
|
58
|
+
return needsReview(g, d, i) ? ST_UNREVIEWED : ST_TRUSTED;
|
|
57
59
|
}
|
|
58
60
|
/** Every declaration of `g`'s state, as codes (indices into STATUSES). `files` holds the build
|
|
59
61
|
* status of the project's files, by module; empty in a snapshot or before the first report. */
|
|
@@ -78,3 +80,31 @@ export function statusCounts(codes, counted = () => true) {
|
|
|
78
80
|
n[codes[i]]++;
|
|
79
81
|
return n;
|
|
80
82
|
}
|
|
83
|
+
/** A file cluster's own build trouble, as a Status code (failed, building, sorry), or -1: what its
|
|
84
|
+
* outline shows in the Status scheme. Trouble inherited from below (blocked, out of date because
|
|
85
|
+
* something under it changed) is left out, so that one failure does not ring every file above it. */
|
|
86
|
+
export function fileTrouble(f) {
|
|
87
|
+
switch (f?.state) {
|
|
88
|
+
case "failed":
|
|
89
|
+
case "unbuilt":
|
|
90
|
+
return ST_FAILED;
|
|
91
|
+
case "building":
|
|
92
|
+
return ST_BUILDING;
|
|
93
|
+
case "sorry":
|
|
94
|
+
return ST_SORRY;
|
|
95
|
+
default:
|
|
96
|
+
return -1;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** Each cluster's outline in the Status scheme (CanvasSpec, "Files and clusters"): its file's own
|
|
100
|
+
* trouble (fileTrouble) where the clusters are files, -1 (none, the plain outline) for every other
|
|
101
|
+
* cluster. Under namespaces a cluster's key is a namespace, which can read like a module's name
|
|
102
|
+
* without being its file: none has an outline there. -1, not 0, is "none": 0 is failed's code, and
|
|
103
|
+
* an array left at zeros ringed every namespace in failed's colour (the owner's report of
|
|
104
|
+
* 2026-10-18). */
|
|
105
|
+
export function clusterTroubles(clusters, clustering, files) {
|
|
106
|
+
const out = new Int8Array(clusters.length).fill(-1);
|
|
107
|
+
if (clustering === "module")
|
|
108
|
+
clusters.forEach((c, k) => (out[k] = fileTrouble(files.get(c.key))));
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Light, dark, or as the system is: the reader's choice, kept for every project in this browser;
|
|
2
|
+
// light unless they chose otherwise, on every platform (the owner's decision of 2026-10-14). The
|
|
3
|
+
// page's colours follow `data-theme` on <html> (style.css); a script in index.html's <head> sets it
|
|
4
|
+
// before the first paint, from the same stored choice, so a dark page never flashes light.
|
|
5
|
+
//
|
|
6
|
+
// What draws in the theme's colours itself — the board's canvas, the linear form — reads them from
|
|
7
|
+
// the page's custom properties as it draws, and keeps what it drew: it draws again when the theme on
|
|
8
|
+
// show changes (onThemeChange), whoever changed it, in either direction.
|
|
9
|
+
//
|
|
10
|
+
// The system's other preference the page follows is reduced motion (reducedMotion): nothing on the
|
|
11
|
+
// page glides then — style.css's one rule for its transitions and animations, and here for what
|
|
12
|
+
// moves by itself (the board's camera, the linear form coming and going).
|
|
13
|
+
const KEY = "visualproof:theme";
|
|
14
|
+
// none without a browser: the artwork command reads the board's module, which reads this one
|
|
15
|
+
const dark = typeof matchMedia === "function" ? matchMedia("(prefers-color-scheme: dark)") : null;
|
|
16
|
+
/** the theme something holds on show over the reader's choice (holdTheme), or none */
|
|
17
|
+
let held = null;
|
|
18
|
+
/** Whether the system asks for reduced motion: what would glide is where it goes at once (GuideSpec
|
|
19
|
+
* decision 4; the camera, web/src/canvas.ts animate; the linear form, web/src/linear.ts). Read as
|
|
20
|
+
* it is asked, so that a change of the setting holds from the next motion. */
|
|
21
|
+
export const reducedMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
22
|
+
export function themeChoice() {
|
|
23
|
+
try {
|
|
24
|
+
const v = localStorage.getItem(KEY);
|
|
25
|
+
if (v === "dark" || v === "system")
|
|
26
|
+
return v;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// storage blocked: the default
|
|
30
|
+
}
|
|
31
|
+
return "light";
|
|
32
|
+
}
|
|
33
|
+
/** Put the choice in force: what <html> says, now and (for "system") whenever the system changes;
|
|
34
|
+
* while a theme is held (holdTheme), that one. */
|
|
35
|
+
export function applyTheme(choice = themeChoice()) {
|
|
36
|
+
const t = held ?? (choice === "system" ? (dark?.matches ? "dark" : "light") : choice);
|
|
37
|
+
if (document.documentElement.dataset.theme !== t)
|
|
38
|
+
document.documentElement.dataset.theme = t;
|
|
39
|
+
}
|
|
40
|
+
/** Show `t` whatever the reader chose, until it is let go (null): the artwork mode's theme (web/src/
|
|
41
|
+
* main.ts, drawLook), which a change of the system's, followed by "As the system", must not undo
|
|
42
|
+
* while the mode is on. Let go, the reader's choice is in force again. */
|
|
43
|
+
export function holdTheme(t) {
|
|
44
|
+
held = t;
|
|
45
|
+
applyTheme();
|
|
46
|
+
}
|
|
47
|
+
const followers = [];
|
|
48
|
+
let watching = null;
|
|
49
|
+
let shown;
|
|
50
|
+
/** Call `f` whenever the theme on show changes, light to dark or back: by the reader's choice, the
|
|
51
|
+
* system's while it is followed, an artwork's look. It is read from <html> itself, so that no way of
|
|
52
|
+
* changing it is missed; setting it to what it is already is no change. */
|
|
53
|
+
export function onThemeChange(f) {
|
|
54
|
+
followers.push(f);
|
|
55
|
+
if (watching || typeof MutationObserver === "undefined")
|
|
56
|
+
return;
|
|
57
|
+
shown = document.documentElement.dataset.theme;
|
|
58
|
+
watching = new MutationObserver(() => {
|
|
59
|
+
const now = document.documentElement.dataset.theme;
|
|
60
|
+
if (now === shown)
|
|
61
|
+
return;
|
|
62
|
+
shown = now;
|
|
63
|
+
for (const g of followers)
|
|
64
|
+
g();
|
|
65
|
+
});
|
|
66
|
+
watching.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
|
|
67
|
+
}
|
|
68
|
+
export function setTheme(choice) {
|
|
69
|
+
try {
|
|
70
|
+
// the default is kept as nothing, so that a later change of the default reaches whoever never chose
|
|
71
|
+
if (choice === "light")
|
|
72
|
+
localStorage.removeItem(KEY);
|
|
73
|
+
else
|
|
74
|
+
localStorage.setItem(KEY, choice);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// not kept: in force for this page only
|
|
78
|
+
}
|
|
79
|
+
applyTheme(choice);
|
|
80
|
+
}
|
|
81
|
+
dark?.addEventListener("change", () => {
|
|
82
|
+
if (themeChoice() === "system")
|
|
83
|
+
applyTheme("system");
|
|
84
|
+
});
|
|
85
|
+
const ICONS = {
|
|
86
|
+
light: `<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><circle cx="8" cy="8" r="3"/><path d="M8 1.5v1.5M8 13v1.5M1.5 8H3M13 8h1.5M3.4 3.4l1 1M11.6 11.6l1 1M3.4 12.6l1-1M11.6 4.4l1-1"/></svg>`,
|
|
87
|
+
dark: `<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M13 9.5A5.5 5.5 0 0 1 6.5 3a5.5 5.5 0 1 0 6.5 6.5Z"/></svg>`,
|
|
88
|
+
system: `<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><rect x="2" y="3" width="12" height="8.5" rx="1.5"/><path d="M6 14h4M8 11.5V14"/></svg>`,
|
|
89
|
+
};
|
|
90
|
+
const LABELS = { light: "Light", dark: "Dark", system: "As the system" };
|
|
91
|
+
/** The theme's three choices side by side, in the eyes' ⋯ menu at the bottom right (since
|
|
92
|
+
* 2026-10-08; a switch of its own under the zoom buttons before). */
|
|
93
|
+
export function themeChoices(el) {
|
|
94
|
+
const render = () => {
|
|
95
|
+
const c = themeChoice();
|
|
96
|
+
el.innerHTML = ["light", "dark", "system"]
|
|
97
|
+
.map((k) => `<button data-theme-choice="${k}" class="${k === c ? "on" : ""}" role="radio" aria-checked="${k === c}" title="${LABELS[k]}" aria-label="${LABELS[k]}">${ICONS[k]}</button>`)
|
|
98
|
+
.join("");
|
|
99
|
+
};
|
|
100
|
+
render();
|
|
101
|
+
el.addEventListener("click", (e) => {
|
|
102
|
+
const b = e.target.closest("[data-theme-choice]");
|
|
103
|
+
if (!b)
|
|
104
|
+
return;
|
|
105
|
+
setTheme(b.dataset.themeChoice);
|
|
106
|
+
render();
|
|
107
|
+
});
|
|
108
|
+
}
|