@action-state-group/capsule-viewer 0.13.0 → 0.16.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.
@@ -0,0 +1,1294 @@
1
+ "use strict";
2
+ var HistoryView = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/history-view.ts
22
+ var history_view_exports = {};
23
+ __export(history_view_exports, {
24
+ HISTORY_CHECK_IDS: () => HISTORY_CHECK_IDS,
25
+ HISTORY_VIEW: () => HISTORY_VIEW,
26
+ HISTORY_VIEW_WORDING: () => HISTORY_VIEW_WORDING,
27
+ HistoryViewRefused: () => HistoryViewRefused,
28
+ buildHistoryView: () => buildHistoryView,
29
+ historyElementToDom: () => historyElementToDom,
30
+ historyViewDocument: () => historyViewDocument,
31
+ historyViewHtml: () => historyViewHtml,
32
+ historyViewStyles: () => historyViewStyles,
33
+ renderHistoryView: () => renderHistoryView,
34
+ serializeHistoryElement: () => serializeHistoryElement
35
+ });
36
+
37
+ // src/wording/history-view.en.json
38
+ var history_view_en_default = {
39
+ wording_pack_version: "0",
40
+ id: "capsuleviewer.history-view.wording/v0",
41
+ locale: "en",
42
+ provenance: {
43
+ _comment: "Entries copied from actionstate-muse's packs name their source key; the snapshot test (test/history-view.test.ts) holds them to test/fixtures/history-view/muse-source.json. Once actionstate-muse deletes its history.page.* words, this pack is the source.",
44
+ muse_commit: "79cc01cfbae59536e690fd6c8e68192b6cf7a12a",
45
+ sources: {
46
+ "header.title.owner": "plugin.json history.page.title",
47
+ "badge.private": "plugin.json history.page.private",
48
+ "built.owner": "plugin.json history.page.built",
49
+ "hero.none.deals": "plugin.json history.page.none",
50
+ "hero.deals.one": "plugin.json history.page.count.one",
51
+ "hero.deals.other": "plugin.json history.page.count.other",
52
+ "row.opened": "plugin.json history.page.row.opened",
53
+ "row.last": "plugin.json history.page.row.last",
54
+ "stamp.recorded": "plugin.json history.page.stamp.recorded",
55
+ "stamp.timestamped": "plugin.json history.page.stamp.timestamped",
56
+ "slot.timestamped.none": "plugin.json history.page.stamp.timestamped.not",
57
+ "slot.part": "plugin.json history.page.stamp.timestamped.part",
58
+ "slot.unchecked": "plugin.json history.page.stamp.timestamped.unchecked",
59
+ "slot.failed": "plugin.json history.page.stamp.timestamped.failed",
60
+ "seal.deals": "receipt.json seal.text.unpostmarked",
61
+ "seal.directory": "plugin.json history.page.checked.directory"
62
+ }
63
+ },
64
+ entries: {
65
+ "header.title.node": "History \xB7 node {node}",
66
+ "header.title.stream": "History \xB7 node {node} \xB7 {stream} log",
67
+ "header.title.owner": "Your History",
68
+ "header.title.shared": "History \xB7 shared by {name}",
69
+ "header.title.person": "History \xB7 {name}",
70
+ "badge.private": "PRIVATE \xB7 for you only. Never send this page.",
71
+ "badge.shared": "SHARED COPY \xB7 for {who}",
72
+ "badge.anyone": "What this node gives anyone who asks",
73
+ "scope.period": "{from} to {to}",
74
+ "built.owner": "Built {at}. It is a snapshot from when you asked, not a page that updates itself.",
75
+ "built.recipient": "Built {at}. It is a snapshot from when it was built, not a page that updates itself.",
76
+ "hero.checkpoints.one": "1 checkpoint \xB7 {entries} \xB7 last cut {at} \xB7 {verdict}",
77
+ "hero.checkpoints.other": "{n} checkpoints \xB7 {entries} \xB7 last cut {at} \xB7 {verdict}",
78
+ "hero.entries.one": "1 entry",
79
+ "hero.entries.other": "{n} entries",
80
+ "verdict.pass": "every checkpoint signature checks",
81
+ "verdict.pass.all": "every signature checks, including the answer's own, by the node's published key",
82
+ "verdict.unchecked": "signatures not checked here",
83
+ "hero.failed": "This history didn't verify, so this page shows none of it.",
84
+ "hero.none.checkpoints": "No checkpoints yet.",
85
+ "hero.refused": "The node declined to answer.",
86
+ "hero.refused.reason": "Its reason, in its own words: \u201C{reason}\u201D",
87
+ "hero.unreadable": "This page could not read the answer, so it shows none of it.",
88
+ "hero.deals.one": "{n} deal, newest first",
89
+ "hero.deals.other": "{n} deals, newest first",
90
+ "hero.deals.picked.one": "1 deal {name} picked \xB7 steps recorded, not outcomes",
91
+ "hero.deals.picked.other": "{n} deals {name} picked \xB7 steps recorded, not outcomes",
92
+ "hero.none.deals": "There are no deals in this store yet.",
93
+ "chip.signatures.pass": "Checkpoint signatures check",
94
+ "chip.signatures.pass.all": "Every signature checks",
95
+ "chip.signatures.unchecked": "Signatures not checked here",
96
+ "chip.timestamped.all": "Time-stamped: all {n}",
97
+ "chip.timestamped.some": "Time-stamped: {k} of {n}",
98
+ "chip.timestamped.none": "Time-stamped: none yet",
99
+ "chip.timestamped.unchecked": "Time stamps not checked here",
100
+ "chip.timestamped.failed": "Time stamps didn't verify",
101
+ "chip.started": "Started {date}",
102
+ "chip.recorded": "Each step recorded as it happened",
103
+ "rows.heading.checkpoints": "Checkpoints",
104
+ "rows.heading.deals": "Deals",
105
+ "row.cut": "Cut {at}",
106
+ "row.entries.one": "1 entry in the log",
107
+ "row.entries.other": "{n} entries in the log",
108
+ "row.opened": "Opened {at}",
109
+ "row.last": "Last step {at}",
110
+ "proof.checkpoint": "\u{1F50F} checkpoint {id}\u2026",
111
+ "proof.node": "\u{1F50F} node key {id}\u2026",
112
+ "proof.record": "\u{1F50F} record {id}\u2026",
113
+ "stamp.recorded": "RECORDED",
114
+ "stamp.timestamped": "TIME-STAMPED",
115
+ "stamp.second": "SECOND SIGNATURE",
116
+ "stamp.signature.unchecked": "Signature not checked here",
117
+ "slot.timestamped.at": "{at}",
118
+ "slot.timestamped.by": "{at} \xB7 by {by}",
119
+ "slot.part": "through step {k} of {n}",
120
+ "slot.timestamped.none": "Not time-stamped yet",
121
+ "slot.second.by": "{by} signed this record too \xB7 {at}, by their clock",
122
+ "slot.second.none": "None yet",
123
+ "slot.unchecked": "Not checked here",
124
+ "slot.failed": "Didn't verify",
125
+ "periods.heading": "Service History: exchanges served in each closed week",
126
+ "periods.row": "{from} to {to}",
127
+ "periods.cell": "{what}: {value}",
128
+ "periods.cell.withheld": "{what}: fewer than 5",
129
+ "callout.heading": "What this does not show",
130
+ "callout.checkpoints": "These checkpoints show when this node's log was cut and how much it holds. They don't show what any exchange said or how it went, and this is not a judgment of the node.",
131
+ "callout.deals": "\u201CSteps recorded\u201D is this side's record of each deal, not a confirmed outcome.",
132
+ "callout.deals.picked": "{name} picked these; it isn't every deal. \u201CSteps recorded\u201D is {name}'s side's record, not a confirmed outcome.",
133
+ "shares.heading": "What this node shares",
134
+ "shares.summary": "With anyone who asks: a summary of its checkpoints, meaning how much it has recorded and when, and nothing about any exchange.",
135
+ "shares.standard.on": "With anyone: the Service History.",
136
+ "shares.standard.off": "The Service History: only the other side of an exchange gets it (off for anyone else on this node).",
137
+ "shares.segments.counterparties": "Only with the other side of an exchange, when they ask: that exchange's record.",
138
+ "shares.segments.peers": "With any node that signs its request: an exchange's record.",
139
+ "shares.segments.off": "The other side of an exchange can't ask for its record (off on this node).",
140
+ "shares.segments.off.sealed": "They still get the sealed record when it completes.",
141
+ "shares.corroboration.on": "With any node that asks by an exchange's id: whether this node holds its half (ids and digests only).",
142
+ "shares.completion.on": "Sent on its own: the sealed record when an exchange completes.",
143
+ "shares.completion.off": "The sealed record isn't sent when an exchange completes (off on this node).",
144
+ "shares.adjudications.on": "If this node judges an exchange, its verdict goes to the node judged.",
145
+ "shares.adjudications.off": "Verdicts this node reaches aren't sent to the nodes judged (off on this node).",
146
+ "shares.twins.on": "When two copies of a model answer differently, this node sends the question and both answers to a referee.",
147
+ "shares.twins.unstated": "Whether this node sends differing answers to a referee: this node's settings don't say.",
148
+ "shares.witnesses": "Signed checkpoints go to the witnesses named here: {witnesses}",
149
+ "shares.witnesses.none": "No witnesses named in this node's settings now. A row's time-stamp may come from an earlier setting.",
150
+ "shares.witnesses.unstated": "Which witnesses get its checkpoints: this node's settings don't say.",
151
+ "shares.standard.unstated": "Whether the Service History goes to anyone: this node's settings don't say.",
152
+ "shares.segments.unstated": "Whether the other side of an exchange can ask for its record: this node's settings don't say.",
153
+ "shares.corroboration.unstated": "Whether this node tells a node that asks by an exchange's id if it holds its half: this node's settings don't say.",
154
+ "shares.completion.unstated": "Whether the sealed record is sent when an exchange completes: this node's settings don't say.",
155
+ "shares.adjudications.unstated": "Whether verdicts this node reaches go to the nodes judged: this node's settings don't say.",
156
+ "shares.never.unstated": "Whether a record goes to someone who doesn't prove who they are: this node's settings don't say.",
157
+ "shares.never": "Never: a record to anyone who doesn't prove who they are.",
158
+ "shares.as_of": "As this node was set when this page was built, {at}.",
159
+ "seal.title": "Locked as it happened.",
160
+ "seal.checkpoints": "Each checkpoint is signed and extends the one before, so a change to what it covers shows.",
161
+ "seal.deals": "Each step was saved as it happened. Any change to a saved step shows.",
162
+ "seal.unchecked": "This page did not check how these records were locked.",
163
+ "seal.second.label": "Second signature",
164
+ "seal.second.rows": "See each row",
165
+ "seal.second.some_failed": "{k} of {n} didn't verify; see each row",
166
+ "seal.directory": "Signers are looked up at {directory} on every read, so that site can see each time you look.",
167
+ "checked.heading": "How this was checked",
168
+ "checked.where.page": "These checks ran in this browser when the page opened ({by}).",
169
+ "checked.where.builder": "These checks ran when the page was built, {at} ({by}).",
170
+ "check.line": "{status}: {name}",
171
+ "status.pass": "Checked",
172
+ "status.fail": "Didn't verify",
173
+ "status.not_run": "Not checked here",
174
+ "check.readable": "The answer can be read",
175
+ "check.refusal": "The refusal is signed by the key that answered",
176
+ "check.artifact_digest": "The answer's file is the bytes its digest names",
177
+ "check.card_digest": "The history card (history_card/1) matches its digest",
178
+ "check.checkpoint_signatures": "Every checkpoint is signed by the key that answered",
179
+ "check.checkpoint_chain": "Each checkpoint names the one before",
180
+ "check.consistency": "The log only grew between checkpoints: nothing removed or changed",
181
+ "check.anchor": "The last checkpoint is the one the answer names",
182
+ "check.period_counts": "The Service History's counts (service_history/1) match its checkpoints",
183
+ "check.envelope_signature": "The answer itself is signed by the key that answered",
184
+ "check.key_is_node": "The signing key is the node's published key",
185
+ "check.reply_bound": "The answer is bound to the request it answers",
186
+ "check.witness": "A witness time-stamped these records",
187
+ "check.second_signature": "A second party signed this record",
188
+ "check.deal_report": "Each deal was read with its own report, which writes nothing",
189
+ refused: "This page can't show this history: {reasons}"
190
+ }
191
+ };
192
+
193
+ // src/history-view.ts
194
+ var HISTORY_VIEW = "history-view/v0";
195
+ var HISTORY_CHECK_IDS = [
196
+ "readable",
197
+ "refusal",
198
+ "artifact_digest",
199
+ "card_digest",
200
+ "checkpoint_signatures",
201
+ "checkpoint_chain",
202
+ "consistency",
203
+ "anchor",
204
+ "period_counts",
205
+ "envelope_signature",
206
+ "key_is_node",
207
+ "reply_bound",
208
+ "witness",
209
+ "second_signature",
210
+ "deal_report"
211
+ ];
212
+ var SLOT_CHECKS = /* @__PURE__ */ new Set([
213
+ "witness",
214
+ "second_signature"
215
+ ]);
216
+ var BASE = history_view_en_default.entries;
217
+ var HISTORY_VIEW_WORDING = history_view_en_default;
218
+ var HistoryViewRefused = class extends Error {
219
+ reasons;
220
+ constructor(reasons) {
221
+ super(`history-view refused: ${reasons.join("; ")}`);
222
+ this.name = "HistoryViewRefused";
223
+ this.reasons = reasons;
224
+ }
225
+ };
226
+ var TOKEN = /^[a-z0-9 _.-]*$/u;
227
+ function el(tag, attrs, ...children) {
228
+ const pairs = Object.entries(attrs ?? {});
229
+ for (const [name, value] of pairs)
230
+ if (!TOKEN.test(name) || !TOKEN.test(value))
231
+ throw new Error(
232
+ `history-view: attribute ${name}=${value} is not a view token`
233
+ );
234
+ return {
235
+ tag,
236
+ attrs: pairs,
237
+ children: children.filter(
238
+ (c) => c !== null && c !== false
239
+ )
240
+ };
241
+ }
242
+ function escapeText(text) {
243
+ return text.replace(
244
+ /[&<> ]/gu,
245
+ (c) => c === "&" ? "&amp;" : c === "<" ? "&lt;" : c === ">" ? "&gt;" : "&nbsp;"
246
+ );
247
+ }
248
+ function serializeHistoryElement(node) {
249
+ if (typeof node === "string") return escapeText(node);
250
+ const attrs = node.attrs.map(([n, v]) => ` ${n}="${v}"`).join("");
251
+ return `<${node.tag}${attrs}>${node.children.map(serializeHistoryElement).join("")}</${node.tag}>`;
252
+ }
253
+ function historyElementToDom(node, doc) {
254
+ if (typeof node === "string") return doc.createTextNode(node);
255
+ const out = doc.createElement(node.tag);
256
+ for (const [n, v] of node.attrs) out.setAttribute(n, v);
257
+ for (const child of node.children)
258
+ out.appendChild(historyElementToDom(child, doc));
259
+ return out;
260
+ }
261
+ var Reader = class {
262
+ reasons = [];
263
+ refuse(path, why) {
264
+ this.reasons.push(`${path}: ${why}`);
265
+ }
266
+ object(v, path, allowed, required) {
267
+ if (typeof v !== "object" || v === null || Array.isArray(v)) {
268
+ this.refuse(path, "is not an object");
269
+ return null;
270
+ }
271
+ const o = v;
272
+ for (const k of Object.keys(o))
273
+ if (!allowed.includes(k))
274
+ this.refuse(`${path}.${k}`, "is not a member of history-view/v0");
275
+ for (const k of required)
276
+ if (!(k in o)) this.refuse(`${path}.${k}`, "is missing");
277
+ return o;
278
+ }
279
+ string(v, path, max = 2e3) {
280
+ if (typeof v !== "string" || v.length === 0 || v.length > max) {
281
+ this.refuse(path, `is not a string of 1 to ${max} characters`);
282
+ return void 0;
283
+ }
284
+ return v;
285
+ }
286
+ oneOf(v, path, values) {
287
+ if (typeof v !== "string" || !values.includes(v)) {
288
+ this.refuse(path, `is not one of ${values.join(", ")}`);
289
+ return void 0;
290
+ }
291
+ return v;
292
+ }
293
+ bool(v, path) {
294
+ if (typeof v !== "boolean") {
295
+ this.refuse(path, "is not true or false");
296
+ return void 0;
297
+ }
298
+ return v;
299
+ }
300
+ count(v, path) {
301
+ if (typeof v !== "number" || !Number.isSafeInteger(v) || v < 0) {
302
+ this.refuse(path, "is not a whole number of 0 or more");
303
+ return void 0;
304
+ }
305
+ return v;
306
+ }
307
+ time(v, path) {
308
+ const s = this.string(v, path, 64);
309
+ if (s === void 0) return void 0;
310
+ const t = parseInstant(s);
311
+ if (t === void 0) this.refuse(path, "is not an RFC 3339 time");
312
+ return t;
313
+ }
314
+ date(v, path) {
315
+ const s = this.string(v, path, 64);
316
+ if (s === void 0) return void 0;
317
+ const t = /^\d{4}-\d{2}-\d{2}$/u.test(s) ? parseInstant(`${s}T00:00:00Z`) : parseInstant(s);
318
+ if (t === void 0)
319
+ this.refuse(path, "is not a date (YYYY-MM-DD) or an RFC 3339 time");
320
+ return t;
321
+ }
322
+ };
323
+ function parseInstant(s) {
324
+ const m = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?([Zz]|[+-]\d{2}:\d{2})$/u.exec(
325
+ s
326
+ );
327
+ if (!m) return void 0;
328
+ const [, y, mo, d, h, mi, se, frac = "", zone = "Z"] = m;
329
+ const month = Number(mo);
330
+ const day = Number(d);
331
+ if (month < 1 || month > 12 || day < 1 || day > 31 || Number(h) > 23 || Number(mi) > 59 || Number(se) > 59)
332
+ return void 0;
333
+ let ms = Date.UTC(
334
+ Number(y),
335
+ month - 1,
336
+ day,
337
+ Number(h),
338
+ Number(mi),
339
+ Number(se)
340
+ );
341
+ if (new Date(ms).getUTCDate() !== day) return void 0;
342
+ if (zone !== "Z" && zone !== "z") {
343
+ const sign = zone.startsWith("-") ? -1 : 1;
344
+ ms -= sign * (Number(zone.slice(1, 3)) * 60 + Number(zone.slice(4, 6))) * 6e4;
345
+ }
346
+ return { ms, fraction: frac };
347
+ }
348
+ var MONTHS = [
349
+ "Jan",
350
+ "Feb",
351
+ "Mar",
352
+ "Apr",
353
+ "May",
354
+ "Jun",
355
+ "Jul",
356
+ "Aug",
357
+ "Sep",
358
+ "Oct",
359
+ "Nov",
360
+ "Dec"
361
+ ];
362
+ var two = (n) => String(n).padStart(2, "0");
363
+ function dateOf(t) {
364
+ const d = new Date(t.ms);
365
+ return `${MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}, ${d.getUTCFullYear()}`;
366
+ }
367
+ function minuteOf(t) {
368
+ const d = new Date(t.ms);
369
+ return `${dateOf(t)}, ${two(d.getUTCHours())}:${two(d.getUTCMinutes())} UTC`;
370
+ }
371
+ function shortMinuteOf(t) {
372
+ const d = new Date(t.ms);
373
+ return `${MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}, ${two(d.getUTCHours())}:${two(d.getUTCMinutes())} UTC`;
374
+ }
375
+ function secondOf(t, withFraction) {
376
+ const d = new Date(t.ms);
377
+ const frac = withFraction && t.fraction ? `.${t.fraction}` : "";
378
+ return `${dateOf(t)}, ${two(d.getUTCHours())}:${two(d.getUTCMinutes())}:${two(d.getUTCSeconds())}${frac} UTC`;
379
+ }
380
+ var PLACEHOLDER = /\{([a-z_]+)\}/gu;
381
+ function placeholders(text) {
382
+ return [...text.matchAll(PLACEHOLDER)].map((m) => m[1] ?? "").sort();
383
+ }
384
+ function readOverlay(r, v) {
385
+ const o = r.object(v, "overlay", ["id", "entries"], ["id", "entries"]);
386
+ if (!o) return {};
387
+ r.string(o["id"], "overlay.id", 200);
388
+ const e = r.object(o["entries"], "overlay.entries", Object.keys(BASE), []);
389
+ const out = {};
390
+ if (!e) return out;
391
+ for (const [k, text] of Object.entries(e)) {
392
+ const base = Object.hasOwn(BASE, k) ? BASE[k] : void 0;
393
+ const s = r.string(text, `overlay.entries.${k}`);
394
+ if (base === void 0 || s === void 0) continue;
395
+ if (placeholders(base).join(",") !== placeholders(s).join(","))
396
+ r.refuse(
397
+ `overlay.entries.${k}`,
398
+ `must use the placeholders ${JSON.stringify(placeholders(base))}`
399
+ );
400
+ else out[k] = s;
401
+ }
402
+ return out;
403
+ }
404
+ function readSlot(r, v, path, needBy) {
405
+ const o = r.object(v, path, ["state", "by", "at", "through"], ["state"]);
406
+ const state = o ? r.oneOf(o["state"], `${path}.state`, [
407
+ "passed",
408
+ "failed",
409
+ "none",
410
+ "not_checked"
411
+ ]) ?? "not_checked" : "not_checked";
412
+ const by = o && "by" in o ? r.string(o["by"], `${path}.by`, 200) : void 0;
413
+ const at = o && "at" in o ? r.time(o["at"], `${path}.at`) : void 0;
414
+ let through;
415
+ if (o && "through" in o) {
416
+ const t = r.object(o["through"], `${path}.through`, ["k", "n"], ["k", "n"]);
417
+ const k = t ? r.count(t["k"], `${path}.through.k`) : void 0;
418
+ const n = t ? r.count(t["n"], `${path}.through.n`) : void 0;
419
+ if (k !== void 0 && n !== void 0) {
420
+ if (k > n || n === 0)
421
+ r.refuse(`${path}.through`, "k must be at most n, and n more than 0");
422
+ else through = { k, n };
423
+ }
424
+ }
425
+ if (state === "passed") {
426
+ if (!o || !("at" in o)) r.refuse(path, "a passed slot needs at");
427
+ if (needBy && !(o && "by" in o))
428
+ r.refuse(path, "a passed second-signature slot needs by");
429
+ }
430
+ return { state, by, at, through };
431
+ }
432
+ var EPOCH = { ms: 0, fraction: "" };
433
+ function readRow(r, v, path, kind) {
434
+ if (kind === "checkpoint") {
435
+ const o2 = r.object(
436
+ v,
437
+ path,
438
+ [
439
+ "kind",
440
+ "cut_at",
441
+ "log_size",
442
+ "anchor",
443
+ "signature",
444
+ "witness",
445
+ "second_signature"
446
+ ],
447
+ [
448
+ "kind",
449
+ "cut_at",
450
+ "log_size",
451
+ "anchor",
452
+ "signature",
453
+ "witness",
454
+ "second_signature"
455
+ ]
456
+ );
457
+ if (!o2) return void 0;
458
+ if (o2["kind"] !== "checkpoint")
459
+ r.refuse(`${path}.kind`, "must be the page's kind, checkpoint");
460
+ return {
461
+ kind,
462
+ cut: r.time(o2["cut_at"], `${path}.cut_at`) ?? EPOCH,
463
+ logSize: r.count(o2["log_size"], `${path}.log_size`) ?? 0,
464
+ anchor: r.string(o2["anchor"], `${path}.anchor`, 200) ?? "",
465
+ signature: r.oneOf(o2["signature"], `${path}.signature`, [
466
+ "pass",
467
+ "fail",
468
+ "not_run"
469
+ ]) ?? "not_run",
470
+ witness: readSlot(r, o2["witness"], `${path}.witness`, false),
471
+ second: readSlot(
472
+ r,
473
+ o2["second_signature"],
474
+ `${path}.second_signature`,
475
+ true
476
+ )
477
+ };
478
+ }
479
+ const o = r.object(
480
+ v,
481
+ path,
482
+ [
483
+ "kind",
484
+ "asked",
485
+ "outcome",
486
+ "money",
487
+ "opened_at",
488
+ "last_at",
489
+ "record",
490
+ "witness",
491
+ "second_signature"
492
+ ],
493
+ [
494
+ "kind",
495
+ "asked",
496
+ "outcome",
497
+ "opened_at",
498
+ "last_at",
499
+ "record",
500
+ "witness",
501
+ "second_signature"
502
+ ]
503
+ );
504
+ if (!o) return void 0;
505
+ if (o["kind"] !== "deal")
506
+ r.refuse(`${path}.kind`, "must be the page's kind, deal");
507
+ return {
508
+ kind,
509
+ asked: r.string(o["asked"], `${path}.asked`) ?? "",
510
+ outcome: r.string(o["outcome"], `${path}.outcome`, 200) ?? "",
511
+ money: "money" in o ? r.string(o["money"], `${path}.money`, 200) : void 0,
512
+ opened: r.time(o["opened_at"], `${path}.opened_at`) ?? EPOCH,
513
+ last: r.time(o["last_at"], `${path}.last_at`) ?? EPOCH,
514
+ record: r.string(o["record"], `${path}.record`, 200) ?? "",
515
+ witness: readSlot(r, o["witness"], `${path}.witness`, false),
516
+ second: readSlot(
517
+ r,
518
+ o["second_signature"],
519
+ `${path}.second_signature`,
520
+ true
521
+ )
522
+ };
523
+ }
524
+ var TOP = [
525
+ "view",
526
+ "kind",
527
+ "surface",
528
+ "reader",
529
+ "holder",
530
+ "audience",
531
+ "built_at",
532
+ "checked",
533
+ "outcome",
534
+ "picked",
535
+ "rows",
536
+ "checks",
537
+ "periods",
538
+ "sharing",
539
+ "signer_directory",
540
+ "period"
541
+ ];
542
+ function buildHistoryView(input, overlay) {
543
+ const r = new Reader();
544
+ const o = r.object(input, "input", TOP, [
545
+ "view",
546
+ "kind",
547
+ "surface",
548
+ "reader",
549
+ "holder",
550
+ "audience",
551
+ "built_at",
552
+ "checked",
553
+ "rows",
554
+ "checks"
555
+ ]);
556
+ if (!o) return { ok: false, reasons: r.reasons };
557
+ if (o["view"] !== HISTORY_VIEW)
558
+ r.refuse("input.view", `is not ${HISTORY_VIEW}`);
559
+ const kind = r.oneOf(o["kind"], "input.kind", ["checkpoint", "deal"]) ?? "checkpoint";
560
+ const surface = r.oneOf(o["surface"], "input.surface", ["neutral", "product"]) ?? "neutral";
561
+ const reader = r.oneOf(o["reader"], "input.reader", ["owner", "recipient"]) ?? "recipient";
562
+ let words = {};
563
+ if (overlay !== void 0) {
564
+ if (surface !== "product")
565
+ r.refuse("overlay", "a neutral page takes no overlay");
566
+ else words = readOverlay(r, overlay);
567
+ }
568
+ const ho = r.object(
569
+ o["holder"],
570
+ "input.holder",
571
+ ["node", "name", "stream"],
572
+ []
573
+ );
574
+ const node = ho && "node" in ho ? r.string(ho["node"], "input.holder.node", 200) : void 0;
575
+ const name = ho && "name" in ho ? r.string(ho["name"], "input.holder.name", 200) : void 0;
576
+ const stream = ho && "stream" in ho ? r.string(ho["stream"], "input.holder.stream", 200) : void 0;
577
+ if (kind === "checkpoint" && node === void 0 && ho)
578
+ r.refuse(
579
+ "input.holder.node",
580
+ "is missing (a checkpoint page names its node)"
581
+ );
582
+ const au = r.object(
583
+ o["audience"],
584
+ "input.audience",
585
+ ["kind", "for"],
586
+ ["kind"]
587
+ );
588
+ const audienceKind = au ? r.oneOf(au["kind"], "input.audience.kind", [
589
+ "private",
590
+ "shared",
591
+ "anyone"
592
+ ]) ?? "anyone" : "anyone";
593
+ const audienceFor = audienceKind === "shared" && au ? r.string(au["for"], "input.audience.for", 200) : void 0;
594
+ if (audienceKind !== "shared" && au && "for" in au)
595
+ r.refuse("input.audience.for", "is only for a shared audience");
596
+ const built = r.time(o["built_at"], "input.built_at") ?? EPOCH;
597
+ const ck = r.object(
598
+ o["checked"],
599
+ "input.checked",
600
+ ["where", "by"],
601
+ ["where", "by"]
602
+ );
603
+ const where = ck ? r.oneOf(ck["where"], "input.checked.where", [
604
+ "page",
605
+ "builder"
606
+ ]) ?? "builder" : "builder";
607
+ const checkedBy = ck ? r.string(ck["by"], "input.checked.by", 200) ?? "" : "";
608
+ let outcome = "answered";
609
+ let refusedReason;
610
+ if ("outcome" in o) {
611
+ if (kind !== "checkpoint")
612
+ r.refuse("input.outcome", "is only for a checkpoint page");
613
+ const oc = r.object(
614
+ o["outcome"],
615
+ "input.outcome",
616
+ ["kind", "reason"],
617
+ ["kind"]
618
+ );
619
+ if (oc) {
620
+ outcome = r.oneOf(oc["kind"], "input.outcome.kind", [
621
+ "answered",
622
+ "refused",
623
+ "unreadable"
624
+ ]) ?? "answered";
625
+ if (outcome === "refused")
626
+ refusedReason = r.string(oc["reason"], "input.outcome.reason", 200);
627
+ else if ("reason" in oc)
628
+ r.refuse("input.outcome.reason", "is only for a refused answer");
629
+ }
630
+ }
631
+ const picked = "picked" in o ? r.bool(o["picked"], "input.picked") === true : false;
632
+ if (picked && kind !== "deal")
633
+ r.refuse("input.picked", "is only for a deal page");
634
+ if (kind === "deal" && reader === "recipient" && name === void 0)
635
+ r.refuse(
636
+ "input.holder.name",
637
+ "is missing (a deal page shown to someone else names whose it is)"
638
+ );
639
+ else if (picked && name === void 0)
640
+ r.refuse(
641
+ "input.holder.name",
642
+ "is missing (a picked selection names who picked it)"
643
+ );
644
+ const rows = [];
645
+ if (Array.isArray(o["rows"])) {
646
+ if (o["rows"].length > 1e4)
647
+ r.refuse("input.rows", "has more than 10000 rows");
648
+ o["rows"].forEach((row, i) => {
649
+ const read = readRow(r, row, `input.rows[${i}]`, kind);
650
+ if (read) rows.push(read);
651
+ });
652
+ if (outcome !== "answered" && o["rows"].length > 0)
653
+ r.refuse("input.rows", "must be empty unless the node answered");
654
+ } else r.refuse("input.rows", "is not a list");
655
+ const checks = [];
656
+ if (Array.isArray(o["checks"])) {
657
+ o["checks"].forEach((c, i) => {
658
+ const path = `input.checks[${i}]`;
659
+ const co = r.object(
660
+ c,
661
+ path,
662
+ ["id", "status", "values"],
663
+ ["id", "status"]
664
+ );
665
+ if (!co) return;
666
+ const id = r.oneOf(co["id"], `${path}.id`, HISTORY_CHECK_IDS);
667
+ const status = r.oneOf(co["status"], `${path}.status`, [
668
+ "pass",
669
+ "fail",
670
+ "not_run"
671
+ ]);
672
+ if ("values" in co) {
673
+ const vo = r.object(co["values"], `${path}.values`, [], []);
674
+ if (vo && Object.keys(vo).length > 0)
675
+ r.refuse(
676
+ `${path}.values`,
677
+ "names a placeholder the check's words do not have"
678
+ );
679
+ }
680
+ if (id && checks.some((x) => x.id === id))
681
+ r.refuse(`${path}.id`, "is listed twice");
682
+ if (id && status) checks.push({ id, status });
683
+ });
684
+ } else r.refuse("input.checks", "is not a list");
685
+ const periods = [];
686
+ if ("periods" in o) {
687
+ if (kind !== "checkpoint")
688
+ r.refuse("input.periods", "is only for a checkpoint page");
689
+ if (Array.isArray(o["periods"]))
690
+ o["periods"].forEach((p, i) => {
691
+ const path = `input.periods[${i}]`;
692
+ const po = r.object(
693
+ p,
694
+ path,
695
+ ["from", "to", "cells"],
696
+ ["from", "to", "cells"]
697
+ );
698
+ if (!po) return;
699
+ const from = r.date(po["from"], `${path}.from`);
700
+ const to = r.date(po["to"], `${path}.to`);
701
+ const cells = [];
702
+ if (Array.isArray(po["cells"]))
703
+ po["cells"].forEach((c, j) => {
704
+ const co = r.object(
705
+ c,
706
+ `${path}.cells[${j}]`,
707
+ ["what", "value", "withheld"],
708
+ ["what"]
709
+ );
710
+ const what = co ? r.string(co["what"], `${path}.cells[${j}].what`, 200) : void 0;
711
+ const withheld = co !== null && "withheld" in co;
712
+ if (withheld && co["withheld"] !== true)
713
+ r.refuse(`${path}.cells[${j}].withheld`, "is not true");
714
+ if (co && withheld === "value" in co)
715
+ r.refuse(
716
+ `${path}.cells[${j}]`,
717
+ "carries either a value or withheld: true"
718
+ );
719
+ const value = co && "value" in co ? r.string(co["value"], `${path}.cells[${j}].value`, 40) : void 0;
720
+ if (what !== void 0) cells.push({ what, value });
721
+ });
722
+ else r.refuse(`${path}.cells`, "is not a list");
723
+ if (from && to) periods.push({ from, to, cells });
724
+ });
725
+ else r.refuse("input.periods", "is not a list");
726
+ }
727
+ let sharing;
728
+ if (kind === "checkpoint" && !("sharing" in o))
729
+ r.refuse(
730
+ "input.sharing",
731
+ "is missing (a checkpoint page says what its node shares)"
732
+ );
733
+ if ("sharing" in o) {
734
+ if (kind !== "checkpoint")
735
+ r.refuse("input.sharing", "is only for a checkpoint page");
736
+ const keys = [
737
+ "standard_history",
738
+ "history_segments",
739
+ "record_at_completion",
740
+ "adjudications",
741
+ "exchange_corroboration",
742
+ "adjudicate_differing_twins",
743
+ "witnesses"
744
+ ];
745
+ const so = r.object(o["sharing"], "input.sharing", keys, []);
746
+ if (so) {
747
+ let witnesses;
748
+ if ("witnesses" in so) {
749
+ witnesses = [];
750
+ if (Array.isArray(so["witnesses"]))
751
+ for (const [i, w] of so["witnesses"].entries()) {
752
+ const s = r.string(w, `input.sharing.witnesses[${i}]`, 300);
753
+ if (s !== void 0) witnesses.push(s);
754
+ }
755
+ else r.refuse("input.sharing.witnesses", "is not a list");
756
+ }
757
+ const stated = {};
758
+ let wrong = false;
759
+ const take = (k, parse) => {
760
+ if (!(k in so)) return;
761
+ const v = parse();
762
+ if (v === void 0) wrong = true;
763
+ else stated[k] = v;
764
+ };
765
+ const on = (k) => take(k, () => r.bool(so[k], `input.sharing.${k}`));
766
+ const one = (k, values) => take(k, () => r.oneOf(so[k], `input.sharing.${k}`, values));
767
+ on("standard_history");
768
+ one("history_segments", ["off", "counterparties", "peers"]);
769
+ one("record_at_completion", ["counterparty", "off"]);
770
+ one("adjudications", ["deliver_to_subjects", "off"]);
771
+ on("exchange_corroboration");
772
+ on("adjudicate_differing_twins");
773
+ if (!wrong)
774
+ sharing = {
775
+ ...stated,
776
+ ...witnesses !== void 0 ? { witnesses } : {}
777
+ };
778
+ }
779
+ }
780
+ let directory;
781
+ if ("signer_directory" in o) {
782
+ if (kind !== "deal")
783
+ r.refuse("input.signer_directory", "is only for a deal page");
784
+ directory = r.string(o["signer_directory"], "input.signer_directory", 300);
785
+ if (directory !== void 0 && !directory.startsWith("https://"))
786
+ r.refuse("input.signer_directory", "is not an https:// address");
787
+ }
788
+ let period;
789
+ if ("period" in o) {
790
+ const po = r.object(
791
+ o["period"],
792
+ "input.period",
793
+ ["from", "to"],
794
+ ["from", "to"]
795
+ );
796
+ const from = po ? r.date(po["from"], "input.period.from") : void 0;
797
+ const to = po ? r.date(po["to"], "input.period.to") : void 0;
798
+ if (from && to) period = { from, to };
799
+ }
800
+ if (r.reasons.length > 0) return { ok: false, reasons: r.reasons };
801
+ const say = (key, values = {}) => {
802
+ const text = words[key] ?? BASE[key];
803
+ if (text === void 0)
804
+ throw new Error(`history-view: no words for ${key}`);
805
+ return text.replace(PLACEHOLDER, (_, p) => {
806
+ const v = values[p];
807
+ if (v === void 0) throw new Error(`history-view: ${key} needs {${p}}`);
808
+ return v;
809
+ });
810
+ };
811
+ const plural = (key, n, values = {}) => say(`${key}.${n === 1 ? "one" : "other"}`, { n: String(n), ...values });
812
+ const short = (id) => id.length > 12 ? id.slice(0, 12) : id;
813
+ const failedCheck = checks.some(
814
+ (c) => c.status === "fail" && !SLOT_CHECKS.has(c.id)
815
+ );
816
+ const failedRow = rows.some(
817
+ (x) => x.kind === "checkpoint" && x.signature === "fail"
818
+ );
819
+ const failed = failedCheck || failedRow;
820
+ const allPass = rows.length > 0 && rows.every((x) => x.kind !== "checkpoint" || x.signature === "pass") && checks.filter((c) => !SLOT_CHECKS.has(c.id) && c.status !== "not_run").every((c) => c.status === "pass") && (kind === "deal" || checks.some(
821
+ (c) => c.id === "checkpoint_signatures" && c.status === "pass"
822
+ ));
823
+ const passed = (id) => checks.some((c) => c.id === id && c.status === "pass");
824
+ const everySignature = allPass && passed("envelope_signature") && passed("key_is_node");
825
+ const verdictKey = everySignature ? "verdict.pass.all" : "verdict.pass";
826
+ const chipKey = everySignature ? "chip.signatures.pass.all" : "chip.signatures.pass";
827
+ const statusOf = (id) => checks.find((c) => c.id === id)?.status;
828
+ const dealRecorded = statusOf("deal_report") === "pass";
829
+ const witnessFailed = statusOf("witness") === "fail";
830
+ const secondFailed = statusOf("second_signature") === "fail";
831
+ const lockChecked = kind === "checkpoint" ? statusOf("checkpoint_signatures") === "pass" && statusOf("checkpoint_chain") === "pass" && statusOf("consistency") === "pass" : dealRecorded;
832
+ let title;
833
+ if (kind === "checkpoint")
834
+ title = stream !== void 0 ? say("header.title.stream", { node: short(node ?? ""), stream }) : say("header.title.node", { node: short(node ?? "") });
835
+ else if (reader === "owner") title = say("header.title.owner");
836
+ else
837
+ title = audienceKind === "shared" ? say("header.title.shared", { name: name ?? "" }) : say("header.title.person", { name: name ?? "" });
838
+ const badge = audienceKind === "private" ? say("badge.private") : audienceKind === "shared" ? say("badge.shared", { who: audienceFor ?? "" }) : say("badge.anyone");
839
+ const header = el(
840
+ "header",
841
+ { class: "cvh-header", "data-history": "header" },
842
+ el("h1", { class: "cvh-title" }, title),
843
+ node !== void 0 ? el(
844
+ "details",
845
+ { class: "cvh-proof" },
846
+ el("summary", null, say("proof.node", { id: short(node) })),
847
+ el("code", null, node)
848
+ ) : null,
849
+ period ? el(
850
+ "p",
851
+ { class: "cvh-scope" },
852
+ say("scope.period", {
853
+ from: dateOf(period.from),
854
+ to: dateOf(period.to)
855
+ })
856
+ ) : null,
857
+ el("p", { class: "cvh-badge", "data-audience": audienceKind }, badge),
858
+ el(
859
+ "p",
860
+ { class: "cvh-built" },
861
+ say(reader === "owner" ? "built.owner" : "built.recipient", {
862
+ at: minuteOf(built)
863
+ })
864
+ )
865
+ );
866
+ const heroLines = [];
867
+ let drawRows = false;
868
+ if (outcome === "refused") {
869
+ heroLines.push(say("hero.refused"));
870
+ if (refusedReason !== void 0)
871
+ heroLines.push(say("hero.refused.reason", { reason: refusedReason }));
872
+ } else if (outcome === "unreadable") heroLines.push(say("hero.unreadable"));
873
+ else if (failed) heroLines.push(say("hero.failed"));
874
+ else if (rows.length === 0)
875
+ heroLines.push(
876
+ say(kind === "checkpoint" ? "hero.none.checkpoints" : "hero.none.deals")
877
+ );
878
+ else {
879
+ drawRows = true;
880
+ if (kind === "checkpoint") {
881
+ const cps = rows;
882
+ const last = cps.reduce((a, b) => b.cut.ms > a.cut.ms ? b : a);
883
+ const entries = Math.max(...cps.map((c) => c.logSize));
884
+ heroLines.push(
885
+ plural("hero.checkpoints", cps.length, {
886
+ entries: plural("hero.entries", entries),
887
+ at: shortMinuteOf(last.cut),
888
+ verdict: say(allPass ? verdictKey : "verdict.unchecked")
889
+ })
890
+ );
891
+ } else
892
+ heroLines.push(
893
+ picked ? plural("hero.deals.picked", rows.length, { name: name ?? "" }) : plural("hero.deals", rows.length)
894
+ );
895
+ }
896
+ const hero = el(
897
+ "section",
898
+ { class: "cvh-hero", "data-history": "hero" },
899
+ ...heroLines.map(
900
+ (line, i) => el("p", { class: i === 0 ? "cvh-hero-line" : "cvh-hero-note" }, line)
901
+ )
902
+ );
903
+ let chips = null;
904
+ if (drawRows) {
905
+ const stamped = rows.filter((x) => x.witness.state === "passed").length;
906
+ const stampChip = witnessFailed ? say("chip.timestamped.failed") : stamped === 0 && rows.some((x) => x.witness.state === "not_checked") ? say("chip.timestamped.unchecked") : stamped === 0 ? say("chip.timestamped.none") : stamped === rows.length ? say("chip.timestamped.all", { n: String(rows.length) }) : say("chip.timestamped.some", {
907
+ k: String(stamped),
908
+ n: String(rows.length)
909
+ });
910
+ const items = [];
911
+ if (kind === "checkpoint") {
912
+ items.push(
913
+ say(allPass ? chipKey : "chip.signatures.unchecked"),
914
+ stampChip
915
+ );
916
+ const first = rows.reduce(
917
+ (a, b) => b.cut.ms < a.cut.ms ? b : a
918
+ );
919
+ items.push(say("chip.started", { date: dateOf(first.cut) }));
920
+ } else {
921
+ if (dealRecorded) items.push(say("chip.recorded"));
922
+ items.push(stampChip);
923
+ }
924
+ chips = el(
925
+ "ul",
926
+ { class: "cvh-chips", "data-history": "chips" },
927
+ ...items.map((t) => el("li", { class: "cvh-chip" }, t))
928
+ );
929
+ }
930
+ const slotLine = (s, second) => {
931
+ if (s.state === "passed") {
932
+ const at = s.at ? minuteOf(s.at) : "";
933
+ let line = second ? say("slot.second.by", { by: s.by ?? "", at }) : s.by !== void 0 ? say("slot.timestamped.by", { at, by: s.by }) : say("slot.timestamped.at", { at });
934
+ if (s.through && s.through.k < s.through.n)
935
+ line += ` \xB7 ${say("slot.part", { k: String(s.through.k), n: String(s.through.n) })}`;
936
+ return line;
937
+ }
938
+ if (s.state === "failed") return say("slot.failed");
939
+ if (s.state === "none")
940
+ return say(second ? "slot.second.none" : "slot.timestamped.none");
941
+ return say("slot.unchecked");
942
+ };
943
+ const stamp = (nameKey, filled, state, line) => el(
944
+ "li",
945
+ {
946
+ class: "cvh-stamp",
947
+ "data-filled": filled ? "yes" : "no",
948
+ "data-state": state
949
+ },
950
+ el("span", { class: "cvh-stamp-name" }, say(nameKey)),
951
+ line !== null ? el("span", { class: "cvh-stamp-line" }, line) : null
952
+ );
953
+ const slotStamps = (row) => [
954
+ stamp(
955
+ "stamp.timestamped",
956
+ row.witness.state === "passed",
957
+ row.witness.state,
958
+ slotLine(row.witness, false)
959
+ ),
960
+ stamp(
961
+ "stamp.second",
962
+ row.second.state === "passed",
963
+ row.second.state,
964
+ slotLine(row.second, true)
965
+ )
966
+ ];
967
+ const proof = (key, id) => el(
968
+ "details",
969
+ { class: "cvh-proof" },
970
+ el("summary", null, say(key, { id: short(id) })),
971
+ el("code", null, id)
972
+ );
973
+ let rowList = null;
974
+ if (drawRows) {
975
+ const seconds = /* @__PURE__ */ new Map();
976
+ if (kind === "checkpoint")
977
+ for (const x of rows)
978
+ seconds.set(
979
+ Math.floor(x.cut.ms / 1e3),
980
+ (seconds.get(Math.floor(x.cut.ms / 1e3)) ?? 0) + 1
981
+ );
982
+ const items = rows.map((x) => {
983
+ if (x.kind === "checkpoint") {
984
+ const tie = (seconds.get(Math.floor(x.cut.ms / 1e3)) ?? 0) > 1;
985
+ return el(
986
+ "li",
987
+ { class: "cvh-row", "data-history": "row" },
988
+ el(
989
+ "p",
990
+ { class: "cvh-row-title" },
991
+ say("row.cut", { at: secondOf(x.cut, tie) })
992
+ ),
993
+ el(
994
+ "p",
995
+ { class: "cvh-row-detail" },
996
+ plural("row.entries", x.logSize)
997
+ ),
998
+ proof("proof.checkpoint", x.anchor),
999
+ el(
1000
+ "ul",
1001
+ { class: "cvh-stamps" },
1002
+ stamp(
1003
+ "stamp.recorded",
1004
+ x.signature === "pass",
1005
+ x.signature,
1006
+ x.signature === "pass" ? null : say("stamp.signature.unchecked")
1007
+ ),
1008
+ ...slotStamps(x)
1009
+ )
1010
+ );
1011
+ }
1012
+ const detail = [
1013
+ x.outcome,
1014
+ ...x.money !== void 0 ? [x.money] : [],
1015
+ say("row.opened", { at: minuteOf(x.opened) }),
1016
+ say("row.last", { at: minuteOf(x.last) })
1017
+ ].join(" \xB7 ");
1018
+ return el(
1019
+ "li",
1020
+ { class: "cvh-row", "data-history": "row" },
1021
+ el("p", { class: "cvh-row-title" }, x.asked),
1022
+ el("p", { class: "cvh-row-detail" }, detail),
1023
+ proof("proof.record", x.record),
1024
+ el(
1025
+ "ul",
1026
+ { class: "cvh-stamps" },
1027
+ dealRecorded ? stamp("stamp.recorded", true, "passed", null) : stamp(
1028
+ "stamp.recorded",
1029
+ false,
1030
+ "not_checked",
1031
+ say("slot.unchecked")
1032
+ ),
1033
+ ...slotStamps(x)
1034
+ )
1035
+ );
1036
+ });
1037
+ rowList = el(
1038
+ "section",
1039
+ { class: "cvh-rows-block" },
1040
+ el(
1041
+ "h2",
1042
+ null,
1043
+ say(
1044
+ kind === "checkpoint" ? "rows.heading.checkpoints" : "rows.heading.deals"
1045
+ )
1046
+ ),
1047
+ el("ol", { class: "cvh-rows", "data-history": "rows" }, ...items)
1048
+ );
1049
+ }
1050
+ const periodBlock = drawRows && periods.length > 0 ? el(
1051
+ "section",
1052
+ { class: "cvh-periods", "data-history": "periods" },
1053
+ el("h2", null, say("periods.heading")),
1054
+ el(
1055
+ "ul",
1056
+ null,
1057
+ ...periods.map(
1058
+ (p) => el(
1059
+ "li",
1060
+ null,
1061
+ el(
1062
+ "p",
1063
+ null,
1064
+ say("periods.row", {
1065
+ from: dateOf(p.from),
1066
+ to: dateOf(p.to)
1067
+ })
1068
+ ),
1069
+ el(
1070
+ "ul",
1071
+ null,
1072
+ ...p.cells.map(
1073
+ (c) => el(
1074
+ "li",
1075
+ null,
1076
+ c.value === void 0 ? say("periods.cell.withheld", { what: c.what }) : say("periods.cell", { what: c.what, value: c.value })
1077
+ )
1078
+ )
1079
+ )
1080
+ )
1081
+ )
1082
+ )
1083
+ ) : null;
1084
+ const callout = outcome === "answered" && !failed ? el(
1085
+ "aside",
1086
+ { class: "cvh-callout", "data-history": "does-not-show" },
1087
+ el("h2", null, say("callout.heading")),
1088
+ el(
1089
+ "p",
1090
+ null,
1091
+ kind === "checkpoint" ? say("callout.checkpoints") : picked ? say("callout.deals.picked", { name: name ?? "" }) : say("callout.deals")
1092
+ )
1093
+ ) : null;
1094
+ let shares = null;
1095
+ if (sharing) {
1096
+ const lines = [say("shares.summary")];
1097
+ if (sharing.standard_history === void 0)
1098
+ lines.push(say("shares.standard.unstated"));
1099
+ else
1100
+ lines.push(
1101
+ say(
1102
+ sharing.standard_history ? "shares.standard.on" : "shares.standard.off"
1103
+ )
1104
+ );
1105
+ if (sharing.history_segments === "counterparties")
1106
+ lines.push(say("shares.segments.counterparties"));
1107
+ else if (sharing.history_segments === "peers")
1108
+ lines.push(say("shares.segments.peers"));
1109
+ else if (sharing.history_segments === "off")
1110
+ lines.push(
1111
+ sharing.record_at_completion === "counterparty" ? `${say("shares.segments.off")} ${say("shares.segments.off.sealed")}` : say("shares.segments.off")
1112
+ );
1113
+ else lines.push(say("shares.segments.unstated"));
1114
+ if (sharing.exchange_corroboration === void 0)
1115
+ lines.push(say("shares.corroboration.unstated"));
1116
+ else if (sharing.exchange_corroboration)
1117
+ lines.push(say("shares.corroboration.on"));
1118
+ if (sharing.record_at_completion === void 0)
1119
+ lines.push(say("shares.completion.unstated"));
1120
+ else
1121
+ lines.push(
1122
+ say(
1123
+ sharing.record_at_completion === "counterparty" ? "shares.completion.on" : "shares.completion.off"
1124
+ )
1125
+ );
1126
+ if (sharing.adjudications === void 0)
1127
+ lines.push(say("shares.adjudications.unstated"));
1128
+ else
1129
+ lines.push(
1130
+ say(
1131
+ sharing.adjudications === "deliver_to_subjects" ? "shares.adjudications.on" : "shares.adjudications.off"
1132
+ )
1133
+ );
1134
+ if (sharing.adjudicate_differing_twins === void 0)
1135
+ lines.push(say("shares.twins.unstated"));
1136
+ else if (sharing.adjudicate_differing_twins)
1137
+ lines.push(say("shares.twins.on"));
1138
+ if (sharing.witnesses === void 0)
1139
+ lines.push(say("shares.witnesses.unstated"));
1140
+ else
1141
+ lines.push(
1142
+ sharing.witnesses.length > 0 ? say("shares.witnesses", { witnesses: sharing.witnesses.join(", ") }) : say("shares.witnesses.none")
1143
+ );
1144
+ lines.push(
1145
+ say(
1146
+ sharing.history_segments === void 0 ? "shares.never.unstated" : "shares.never"
1147
+ )
1148
+ );
1149
+ shares = el(
1150
+ "section",
1151
+ { class: "cvh-shares", "data-history": "shares" },
1152
+ el("h2", null, say("shares.heading")),
1153
+ el("ul", null, ...lines.map((l) => el("li", null, l))),
1154
+ el(
1155
+ "p",
1156
+ { class: "cvh-note" },
1157
+ say("shares.as_of", { at: minuteOf(built) })
1158
+ )
1159
+ );
1160
+ }
1161
+ let seal = null;
1162
+ {
1163
+ const states = drawRows ? rows.map((x) => x.second.state) : [];
1164
+ const sealState = secondFailed || states.some((s) => s === "failed") ? "failed" : states.length === 0 || states.some((s) => s === "not_checked") ? "not_checked" : states.every((s) => s === "none") ? "none" : "mixed";
1165
+ const failedRows = states.filter((s) => s === "failed").length;
1166
+ const signedRows = states.filter(
1167
+ (s) => s === "failed" || s === "passed"
1168
+ ).length;
1169
+ const sealLine = sealState === "failed" ? failedRows > 0 && failedRows < signedRows ? say("seal.second.some_failed", {
1170
+ k: String(failedRows),
1171
+ n: String(signedRows)
1172
+ }) : say("slot.failed") : sealState === "none" ? say("slot.second.none") : sealState === "not_checked" ? say("slot.unchecked") : say("seal.second.rows");
1173
+ seal = el(
1174
+ "section",
1175
+ { class: "cvh-seal", "data-history": "seal" },
1176
+ drawRows && lockChecked ? el("p", { class: "cvh-seal-title" }, say("seal.title")) : null,
1177
+ drawRows && lockChecked ? el(
1178
+ "p",
1179
+ null,
1180
+ say(kind === "checkpoint" ? "seal.checkpoints" : "seal.deals")
1181
+ ) : drawRows ? el("p", null, say("seal.unchecked")) : null,
1182
+ el(
1183
+ "p",
1184
+ {
1185
+ class: "cvh-seal-slot",
1186
+ "data-filled": "no",
1187
+ "data-state": sealState
1188
+ },
1189
+ el("span", { class: "cvh-stamp-name" }, say("seal.second.label")),
1190
+ el("span", { class: "cvh-stamp-line" }, sealLine)
1191
+ ),
1192
+ directory !== void 0 ? el(
1193
+ "p",
1194
+ { class: "cvh-note", "data-history": "directory" },
1195
+ say("seal.directory", { directory })
1196
+ ) : null
1197
+ );
1198
+ }
1199
+ const checkedAttrs = {
1200
+ class: "cvh-checked",
1201
+ "data-history": "checked"
1202
+ };
1203
+ if (failed || outcome !== "answered") checkedAttrs["open"] = "";
1204
+ const panel = el(
1205
+ "details",
1206
+ checkedAttrs,
1207
+ el("summary", null, say("checked.heading")),
1208
+ el(
1209
+ "ul",
1210
+ null,
1211
+ ...checks.map(
1212
+ (c) => el(
1213
+ "li",
1214
+ { class: "cvh-check", "data-status": c.status },
1215
+ say("check.line", {
1216
+ status: say(`status.${c.status}`),
1217
+ name: say(`check.${c.id}`)
1218
+ })
1219
+ )
1220
+ )
1221
+ ),
1222
+ el(
1223
+ "p",
1224
+ { class: "cvh-note" },
1225
+ where === "page" ? say("checked.where.page", { by: checkedBy }) : say("checked.where.builder", { at: minuteOf(built), by: checkedBy })
1226
+ )
1227
+ );
1228
+ const tree = el(
1229
+ "section",
1230
+ {
1231
+ class: "cv-history",
1232
+ "data-history": "view",
1233
+ "data-kind": kind,
1234
+ "data-surface": surface,
1235
+ "data-verdict": failed ? "failed" : allPass ? "pass" : "unchecked"
1236
+ },
1237
+ header,
1238
+ el("div", { class: "cvh-main" }, hero, chips, rowList, periodBlock),
1239
+ el("div", { class: "cvh-side" }, callout, shares, seal, panel)
1240
+ );
1241
+ return { ok: true, tree };
1242
+ }
1243
+ function historyViewHtml(input, overlay) {
1244
+ const built = buildHistoryView(input, overlay);
1245
+ if (!built.ok) throw new HistoryViewRefused(built.reasons);
1246
+ return serializeHistoryElement(built.tree);
1247
+ }
1248
+ function renderHistoryView(input, container, overlay) {
1249
+ const doc = container.ownerDocument;
1250
+ const built = buildHistoryView(input, overlay);
1251
+ const node = built.ok ? historyElementToDom(built.tree, doc) : historyElementToDom(
1252
+ el(
1253
+ "p",
1254
+ { class: "cvh-refused", "data-history": "refused" },
1255
+ (BASE["refused"] ?? "").replace(
1256
+ "{reasons}",
1257
+ () => built.reasons.join("; ")
1258
+ )
1259
+ ),
1260
+ doc
1261
+ );
1262
+ container.replaceChildren(node);
1263
+ return built.ok;
1264
+ }
1265
+ var historyViewStyles = `.cv-history{--cvh-ink:#1f2733;--cvh-slate:#6b7482;--cvh-line:#e3ded3;--cvh-cream:#f6f2ea;--cvh-navy:#232f42;--cvh-ok:#2e7d5b;--cvh-bad:#b5462f;font:16px/1.45 system-ui,sans-serif;color:var(--cvh-ink);max-width:1120px;margin:0 auto;padding:16px;display:grid;gap:16px}
1266
+ .cv-history h1{font-size:22px;margin:0}.cv-history h2{font-size:15px;margin:0 0 8px;color:var(--cvh-navy)}
1267
+ .cvh-header p{margin:4px 0}.cvh-badge{display:inline-block;border:1px solid var(--cvh-line);border-radius:6px;padding:2px 8px;font-size:12px;font-weight:700;letter-spacing:.02em}
1268
+ .cvh-badge[data-audience=private]{background:#fbefd9;border-color:#e8a33d}.cvh-built,.cvh-note{color:var(--cvh-slate);font-size:13px}
1269
+ .cvh-hero-line{font-size:20px;font-weight:700;margin:0}.cvh-hero-note{margin:6px 0 0;color:var(--cvh-slate)}
1270
+ .cvh-chips{list-style:none;padding:0;margin:0;display:flex;flex-wrap:wrap;gap:8px}.cvh-chip{background:var(--cvh-cream);border-radius:999px;padding:3px 10px;font-size:13px}
1271
+ .cvh-rows{list-style:none;padding:0;margin:0}.cvh-row{border:1px solid var(--cvh-line);border-radius:10px;padding:10px 12px;margin:0 0 10px}
1272
+ .cvh-row p{margin:0 0 4px}.cvh-row-title{font-weight:700}.cvh-row-detail{color:var(--cvh-slate);font-size:14px}
1273
+ .cvh-proof summary{cursor:pointer;font-size:13px;color:var(--cvh-slate)}.cvh-proof code{font-size:12px;word-break:break-all}
1274
+ .cvh-stamps{list-style:none;padding:0;margin:8px 0 0;display:flex;flex-wrap:wrap;gap:8px}
1275
+ .cvh-stamp,.cvh-seal-slot{border:2px solid var(--cvh-navy);border-radius:999px;padding:2px 10px;font-size:12px;color:var(--cvh-navy)}
1276
+ .cvh-stamp[data-filled=no],.cvh-seal-slot[data-filled=no]{border-style:dotted;border-color:#9aa1ab;color:var(--cvh-slate)}
1277
+ .cvh-stamp[data-state=failed]{border-color:var(--cvh-bad);color:var(--cvh-bad)}
1278
+ .cvh-stamp-name{font-weight:800}.cvh-stamp-line{margin-left:6px}
1279
+ .cvh-callout,.cvh-shares,.cvh-seal,.cvh-periods{border:1px solid var(--cvh-line);border-radius:10px;padding:12px}
1280
+ .cvh-callout{background:var(--cvh-cream)}.cvh-callout p,.cvh-seal p{margin:0 0 6px}.cvh-shares ul,.cvh-periods ul{margin:0;padding-left:18px}
1281
+ .cvh-seal-title{font-weight:700}.cvh-checked summary{cursor:pointer;font-weight:700;color:var(--cvh-navy)}
1282
+ .cvh-check[data-status=fail]{color:var(--cvh-bad)}.cvh-check[data-status=pass]{color:var(--cvh-ok)}
1283
+ .cvh-main,.cvh-side{display:grid;gap:16px;align-content:start}.cvh-refused{border:1px solid var(--cvh-bad);color:var(--cvh-bad);padding:8px 12px;border-radius:8px}
1284
+ @media (min-width:900px){.cv-history{grid-template-columns:minmax(0,3fr) minmax(0,2fr)}.cvh-header{grid-column:1/-1}}
1285
+ @media print{.cv-history{max-width:none;grid-template-columns:1fr}.cvh-proof code{display:block}}
1286
+ `;
1287
+ function historyViewDocument(input, overlay, title = "History") {
1288
+ const body = historyViewHtml(input, overlay);
1289
+ return `<!doctype html>
1290
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escapeText(title)}</title><style>${historyViewStyles}</style></head><body>${body}</body></html>
1291
+ `;
1292
+ }
1293
+ return __toCommonJS(history_view_exports);
1294
+ })();