@enspirit/opspicy 0.3.2 → 0.6.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 +56 -34
- package/bin/help.js +8 -2
- package/dist/configuration.d.ts +8 -2
- package/dist/explorer/api.js +162 -12
- package/dist/explorer/asking.js +51 -0
- package/dist/explorer/dependencies.js +117 -0
- package/dist/explorer/depending.js +139 -0
- package/dist/explorer/diagrams.js +176 -0
- package/dist/explorer/document.js +1 -0
- package/dist/explorer/elo-refs.js +6 -3
- package/dist/explorer/elo.js +18 -0
- package/dist/explorer/index.js +1 -2
- package/dist/explorer/operation.js +2 -4
- package/dist/explorer/pages.js +14 -16
- package/dist/explorer/script/depending.js +41 -0
- package/dist/explorer/script/main.js +1 -0
- package/dist/explorer/script/ranking.js +2 -2
- package/dist/explorer/script/review.js +1 -1
- package/dist/explorer/script/run.js +4 -1
- package/dist/explorer/script/runner.js +420 -0
- package/dist/explorer/script/running.js +111 -0
- package/dist/explorer/script/sending.js +1 -1
- package/dist/explorer/script/served.js +4 -2
- package/dist/explorer/serve.js +1 -1
- package/dist/explorer/server.js +28 -6
- package/dist/explorer/site.js +1 -1
- package/dist/explorer/style.css +91 -1
- package/dist/explorer/telling.js +2 -0
- package/dist/explorer/tests.js +51 -18
- package/dist/explorer/wiki.js +5 -3
- package/dist/files.js +27 -16
- package/dist/judging.js +2 -34
- package/dist/main.js +1 -1
- package/dist/meaning.js +2 -2
- package/dist/modelling.js +99 -25
- package/dist/naming.js +44 -15
- package/dist/notation.js +18 -3
- package/dist/observing.js +112 -0
- package/dist/planning.js +3 -3
- package/dist/reach.js +244 -140
- package/dist/reading.js +14 -18
- package/dist/running.js +18 -8
- package/dist/starting.js +4 -3
- package/dist/suite.js +8 -1
- package/dist/upgrade.js +3 -9
- package/dist/upgrading-state.js +197 -0
- package/dist/upgrading.js +13 -2
- package/dist/variables.js +62 -0
- package/dist/world.js +8 -39
- package/package.json +3 -2
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// The page of what the areas depend on: two drawings (diagrams.ts), and under each the same as a
|
|
2
|
+
// table, where every name leads to its citizen. What is shown is derived (depending.ts): no file
|
|
3
|
+
// of a suite says it. Pure: the wiki is given, markup is what comes out.
|
|
4
|
+
import { aroundOf } from './depending.js';
|
|
5
|
+
import { areasDrawn, detailDrawn, namesDrawn } from './diagrams.js';
|
|
6
|
+
import { esc, link, plural, table } from './html.js';
|
|
7
|
+
import { areaTitle } from './operation.js';
|
|
8
|
+
import { idOf } from './wiki.js';
|
|
9
|
+
const LEAD = 'What each area says in the words of another, and reads of what another holds. Nothing here is written in the specification: it is read from the formaldefs, and from where each citizen is at home.';
|
|
10
|
+
const HOW = 'An area depends on another when one of its formaldefs names a predicate or a function at home there, when one of its operations says a condition or exchanges a type of it, or when it reads a state the other holds, with no name in between. A state is held by the area whose predicates and functions read it.';
|
|
11
|
+
const areaLink = (name) => link(`#${idOf('area', name)}`, areaTitle(name));
|
|
12
|
+
const none = '<span class="m">none</span>';
|
|
13
|
+
/** A citizen, where a dependency names it: its name leads to it; a condition is told by its sentence. */
|
|
14
|
+
const cited = (one) => (one.kind === 'condition' ? link(`#${one.anchor}`, one.name) : `<a class="mono" href="#${esc(one.anchor)}">${esc(one.name)}</a>`);
|
|
15
|
+
const each = (all) => [...new Map(all.map((one) => [one.anchor, one])).values()].map(cited).join(', ');
|
|
16
|
+
const count = (uses) => new Set(uses.map((one) => one.from.anchor)).size;
|
|
17
|
+
/** A verb, as one citizen or several do it. */
|
|
18
|
+
const does = (uses, verb) => (count(uses) === 1 ? `${verb}s` : verb);
|
|
19
|
+
/** What a dependency goes through, a line for each way: who of the one depends, and on what of the other. */
|
|
20
|
+
function throughOf({ uses }) {
|
|
21
|
+
const of = (through) => uses.filter((one) => one.through === through);
|
|
22
|
+
const told = (through, says) => (of(through).length ? [says(of(through))] : []);
|
|
23
|
+
return [
|
|
24
|
+
...told('name', (all) => `${esc(plural(count(all), 'citizen'))} ${does(all, 'name')} ${each(all.map((one) => one.to))}`),
|
|
25
|
+
...told('condition', (all) => `${esc(plural(count(all), 'operation'))} ${does(all, 'say')} ${each(all.map((one) => one.to))}`),
|
|
26
|
+
...told('type', (all) => `<span class="m">as types:</span> ${each(all.map((one) => one.to))}`),
|
|
27
|
+
...told('state', (all) => `${esc(plural(count(all), 'citizen'))} ${does(all, 'read')} ${each(all.map((one) => one.to))} <span class="m">with no name in between</span>`),
|
|
28
|
+
].join('<br>');
|
|
29
|
+
}
|
|
30
|
+
/** What is listed under a drawing: a heading that says how many, then a row each. A row is no citizen: it lists those that are, each leading to its own. */
|
|
31
|
+
const listed = (title, note, columns, rows, widths, level = 'h3') => `<${level} class="group"><span>${esc(title)}</span><span class="m s">${esc(note)}</span></${level}>${rows.length ? table(columns, rows, widths) : '<p class="sub">None.</p>'}`;
|
|
32
|
+
const LEGEND_AREAS = '<p class="legend dep-legend"><span><i class="dep-key"></i> depends on, from the one above</span><span><i class="dep-key state"></i> by reading its state alone</span><span><i class="dep-key against"></i> against the order: a cycle</span><span><b>7</b> citizens that depend</span></p>';
|
|
33
|
+
/** How a drawing names what it shows: an area by its title, a predicate or a function with what it is given. */
|
|
34
|
+
function namingOf(wiki) {
|
|
35
|
+
const definitions = new Map(wiki.areas.flatMap((area) => [...area.predicates, ...area.functions]).map((one) => [idOf(one.kind, one.name), one]));
|
|
36
|
+
const written = (anchor) => {
|
|
37
|
+
const one = definitions.get(anchor);
|
|
38
|
+
return one ? `${one.name}${one.parameters.length ? `(${one.parameters.join(', ')})` : ''}` : anchor;
|
|
39
|
+
};
|
|
40
|
+
return { title: areaTitle, written };
|
|
41
|
+
}
|
|
42
|
+
/** The one switch of the drawing of an area: off, the areas; on, every citizen that depends. It needs no script, and with it the choice is that of every area, and is remembered. */
|
|
43
|
+
const SWITCH = '<label class="dep-switch"><input type="checkbox" role="switch" class="dep-detail-on"><span class="dep-knob" aria-hidden="true"></span>In detail</label>';
|
|
44
|
+
const LEGEND_DETAIL = '<p class="legend dep-legend"><span><i class="dep-key"></i> names it, says it, or is made of it, from the one above</span><span><i class="dep-key state"></i> reads the state, with no name in between</span><span><i class="dep-key against"></i> against the order: a cycle</span><span><b>7</b> citizens that depend on it</span></p>';
|
|
45
|
+
/** The areas, as the drawing shows each: its title, how many operations it has, and the states it holds. */
|
|
46
|
+
const areasOf = (wiki) => wiki.areas.map((area) => ({ name: area.name, title: areaTitle(area.name), operations: area.operations.length, holds: wiki.state.filter((one) => wiki.dependencies.holders.get(one.name) === area.name).map((one) => one.name) }));
|
|
47
|
+
/**
|
|
48
|
+
* What is around one area, for its own page: the drawing of the areas, of this one and of those it
|
|
49
|
+
* is joined to alone, in the order all of them are in; and, at one switch, the same in detail:
|
|
50
|
+
* every citizen that depends, joined to what it depends on.
|
|
51
|
+
*/
|
|
52
|
+
export function aroundShown(wiki, area) {
|
|
53
|
+
const around = aroundOf(wiki.dependencies, area);
|
|
54
|
+
const all = link('#dependencies', 'Dependencies');
|
|
55
|
+
if (!around.between.length)
|
|
56
|
+
return `<p class="sub">It depends on no other area, and none depends on it: ${all}.</p>`;
|
|
57
|
+
const [on, by] = [around.between.filter((one) => one.from === area).length, around.between.filter((one) => one.to === area).length];
|
|
58
|
+
const note = `depends on ${plural(on, 'area')}, ${by} ${by === 1 ? 'depends' : 'depend'} on it`;
|
|
59
|
+
return `<h2 class="group"><span>Dependencies</span><span class="m s">${esc(note)}</span></h2>
|
|
60
|
+
<p class="sub">This area, those that depend on it above it, and those it depends on under it; in detail, every citizen that depends, joined to what it depends on. The same is told for every area on ${all}.</p>
|
|
61
|
+
<div class="dep-mode">${SWITCH}
|
|
62
|
+
<div class="dep-plain"><div class="scroll dep-scroll">${areasDrawn(areasOf(wiki), around, area)}</div>${LEGEND_AREAS}</div>
|
|
63
|
+
<div class="dep-detailed"><div class="scroll dep-scroll">${detailDrawn(around, namingOf(wiki), area)}</div>${LEGEND_DETAIL}</div>
|
|
64
|
+
</div>`;
|
|
65
|
+
}
|
|
66
|
+
function betweenShown(wiki) {
|
|
67
|
+
const { dependencies } = wiki;
|
|
68
|
+
const at = (name) => dependencies.order.indexOf(name);
|
|
69
|
+
const rows = [...dependencies.between]
|
|
70
|
+
.sort((a, b) => at(a.from) - at(b.from) || at(a.to) - at(b.to))
|
|
71
|
+
.map((one) => [areaLink(one.from), `${areaLink(one.to)}${dependencies.against.has(`${one.from}>${one.to}`) ? '<br><span class="res ko">closes a cycle</span>' : ''}`, throughOf(one)]);
|
|
72
|
+
const cycles = dependencies.against.size ? `${plural(dependencies.against.size, 'dependency')} against the order` : 'no cycle';
|
|
73
|
+
return `<h2 class="group"><span>Between areas</span><span class="m s">${esc(`${plural(dependencies.between.length, 'dependency')}, ${cycles}`)}</span></h2>
|
|
74
|
+
<p class="sub">The areas, those that depend on others first. An arc goes from an area down to one it depends on; one that would go up closes a cycle, and is drawn at the left.</p>
|
|
75
|
+
<div class="scroll dep-scroll">${areasDrawn(areasOf(wiki), dependencies)}</div>${LEGEND_AREAS}
|
|
76
|
+
${listed('Each dependency', plural(rows.length, 'dependency'), ['Area', 'Depends on', 'Through'], rows, ['14%', '16%', '70%'])}`;
|
|
77
|
+
}
|
|
78
|
+
/** The names said beyond their area: each with the operations whose own formaldefs say it, and those that reach it through a condition. */
|
|
79
|
+
function namesShown(wiki) {
|
|
80
|
+
const { uses, reaches } = wiki.dependencies;
|
|
81
|
+
const { written } = namingOf(wiki);
|
|
82
|
+
const said = uses.filter((one) => one.through === 'name');
|
|
83
|
+
const names = [...new Map([...said.map((one) => one.to), ...reaches.map((one) => one.to)].map((one) => [one.anchor, one])).values()].sort((a, b) => a.area.localeCompare(b.area) || a.name.localeCompare(b.name));
|
|
84
|
+
const rows = names.map((one) => {
|
|
85
|
+
const by = said.filter((use) => use.to.anchor === one.anchor).map((use) => use.from);
|
|
86
|
+
const through = reaches.filter((reach) => reach.to.anchor === one.anchor);
|
|
87
|
+
const conditions = each(through.map((reach) => reach.by));
|
|
88
|
+
return [`<a class="mono" href="#${esc(one.anchor)}">${esc(written(one.anchor))}</a>`, areaLink(one.area), by.length ? each(by) : none, through.length ? `${esc(plural(new Set(through.map((reach) => reach.from.anchor)).size, 'operation'))}, <span class="m">saying</span> ${conditions}` : none];
|
|
89
|
+
});
|
|
90
|
+
const drawing = namesDrawn(wiki.dependencies, namingOf(wiki));
|
|
91
|
+
return `<h2 class="group"><span>By name</span><span class="m s">${esc(plural(names.length, 'name'))} said beyond its area</span></h2>
|
|
92
|
+
<p class="sub">The operations whose own formaldefs name a predicate or a function of another area, each joined to that name. What an operation reaches only through a condition it says is in the table, and not drawn: the condition names it.</p>
|
|
93
|
+
${drawing ? `<div class="scroll dep-scroll">${drawing}</div>` : ''}
|
|
94
|
+
${listed('Each name', plural(rows.length, 'name'), ['Name', 'Area', 'Named by', 'Reached through a condition by'], rows, ['22%', '10%', '38%', '30%'])}`;
|
|
95
|
+
}
|
|
96
|
+
/** Who holds each state, and what reads it from elsewhere with no name in between. */
|
|
97
|
+
function statesShown(wiki) {
|
|
98
|
+
const { holders, readers, uses } = wiki.dependencies;
|
|
99
|
+
const rows = wiki.state.map((one) => {
|
|
100
|
+
const holder = holders.get(one.name);
|
|
101
|
+
const read = readers.get(one.name) ?? [];
|
|
102
|
+
const held = holder ? areaLink(holder) : `<span class="m">no area: ${read.length ? `read by ${read.map(areaTitle).map(esc).join(' and ')}` : 'nothing reads it'}</span>`;
|
|
103
|
+
const outside = uses.filter((use) => use.through === 'state' && use.to.name === one.name).map((use) => use.from);
|
|
104
|
+
return [`<a class="mono" href="#${esc(idOf('state', one.name))}">${esc(one.name)}</a>`, held, outside.length ? each(outside) : none];
|
|
105
|
+
});
|
|
106
|
+
return listed('Who holds a state', plural(rows.length, 'state'), ['State', 'Held by', 'Read from another area, with no name in between, by'], rows, ['14%', '16%', '70%'], 'h2');
|
|
107
|
+
}
|
|
108
|
+
/** The page of what the areas depend on. */
|
|
109
|
+
export function dependenciesPage(wiki) {
|
|
110
|
+
const body = `<h1>Dependencies</h1>
|
|
111
|
+
<p class="lead">${esc(LEAD)}</p>
|
|
112
|
+
<p class="sub how">${esc(HOW)}</p>
|
|
113
|
+
${betweenShown(wiki)}
|
|
114
|
+
${namesShown(wiki)}
|
|
115
|
+
${statesShown(wiki)}`;
|
|
116
|
+
return { id: 'dependencies', kind: 'Dependencies', title: 'Dependencies', said: LEAD, body };
|
|
117
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// What an area depends on: the citizens of another area that its own name, and the states another
|
|
2
|
+
// holds that its formaldefs read. Derived from what the suite says, and from nothing else
|
|
3
|
+
// (doc/derived.md): no file says who depends on whom, nor who holds a state. Pure.
|
|
4
|
+
//
|
|
5
|
+
// a name a formaldef names a predicate or a function at home in another area
|
|
6
|
+
// a condition an operation says a sentence that a condition of another area decides
|
|
7
|
+
// a type an operation exchanges, or a type is made of, a type another area declares
|
|
8
|
+
// a state a formaldef reads a state another area holds, with no name in between
|
|
9
|
+
//
|
|
10
|
+
// An operation that says a condition also reaches what the formaldef of that condition names. That
|
|
11
|
+
// is told apart, as what it reaches through the condition: the condition depends on it, and the
|
|
12
|
+
// operation on the condition.
|
|
13
|
+
import { sameSentence } from '../suite.js';
|
|
14
|
+
import { namedIn } from './elo.js';
|
|
15
|
+
import { idOf } from './wiki.js';
|
|
16
|
+
const once = (all, key) => [...new Map(all.map((one) => [key(one), one])).values()];
|
|
17
|
+
/** The formaldefs an operation says itself: those of its clauses and of what its examples also show, where no condition gives them, and the inputs a case computes. */
|
|
18
|
+
function ownOf(operation) {
|
|
19
|
+
const clauses = [...operation.clauses, ...operation.cases.flatMap((kase) => kase.and)];
|
|
20
|
+
const computed = operation.cases.flatMap((kase) => (typeof kase.input === 'string' ? [kase.input] : []));
|
|
21
|
+
return [...clauses.filter((clause) => clause.formaldef && clause.from !== 'shared').map((clause) => clause.formaldef ?? ''), ...computed];
|
|
22
|
+
}
|
|
23
|
+
/** The conditions an operation says: those that give one of its clauses its formaldef. */
|
|
24
|
+
function saidBy(operation, conditions) {
|
|
25
|
+
const clauses = [...operation.clauses, ...operation.cases.flatMap((kase) => kase.and)];
|
|
26
|
+
const found = clauses.filter((clause) => clause.from === 'shared').flatMap((clause) => conditions.filter((one) => sameSentence(one.description, clause.description)));
|
|
27
|
+
return once(found, (one) => one.name);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Who holds each state. The area whose predicates and functions read it by its name, when those
|
|
31
|
+
* of one area alone do; where no predicate or function reads it, the area whose operations and
|
|
32
|
+
* conditions do, when one alone does. Otherwise nobody: the suite does not decide.
|
|
33
|
+
*/
|
|
34
|
+
function holdersOf(model, words, others, named) {
|
|
35
|
+
const reading = (all, state) => [...new Set(all.filter((one) => named(one).includes(idOf('state', state))).map((one) => one.who.area))];
|
|
36
|
+
const readers = new Map(model.state.map((one) => [one.name, [reading(words, one.name), reading(others, one.name)].find((areas) => areas.length) ?? []]));
|
|
37
|
+
const holders = new Map(model.state.map((one) => [one.name, readers.get(one.name)?.length === 1 ? (readers.get(one.name)?.[0] ?? null) : null]));
|
|
38
|
+
return { holders, readers };
|
|
39
|
+
}
|
|
40
|
+
/** Every way to put a few things in a row. */
|
|
41
|
+
const rows = (all) => (all.length < 2 ? [all] : all.flatMap((one, at) => rows([...all.slice(0, at), ...all.slice(at + 1)]).map((rest) => [one, ...rest])));
|
|
42
|
+
/**
|
|
43
|
+
* The areas in a row, those that depend on others first. Areas that depend on each other, in a
|
|
44
|
+
* circle, are kept together, in the order that leaves the fewest citizens depending against it.
|
|
45
|
+
*/
|
|
46
|
+
function orderOf(areas, between) {
|
|
47
|
+
const on = (area) => between.filter((one) => one.from === area).map((one) => one.to);
|
|
48
|
+
const reached = new Map(areas.map((area) => [area, new Set()]));
|
|
49
|
+
const reach = (from, area) => {
|
|
50
|
+
for (const next of on(area))
|
|
51
|
+
if (!reached.get(from)?.has(next))
|
|
52
|
+
(reached.get(from)?.add(next), reach(from, next));
|
|
53
|
+
};
|
|
54
|
+
for (const area of areas)
|
|
55
|
+
reach(area, area);
|
|
56
|
+
const circles = once(areas.map((area) => areas.filter((other) => other === area || (reached.get(area)?.has(other) && reached.get(other)?.has(area)))), (circle) => circle.join(' '));
|
|
57
|
+
// A circle is as far from the ground as the longest way down from it.
|
|
58
|
+
const height = new Map();
|
|
59
|
+
const heightOf = (circle) => {
|
|
60
|
+
const key = circle.join(' ');
|
|
61
|
+
if (!height.has(key)) {
|
|
62
|
+
height.set(key, 0);
|
|
63
|
+
const under = circles.filter((other) => other !== circle && circle.some((area) => other.some((below) => on(area).includes(below))));
|
|
64
|
+
height.set(key, under.length ? 1 + Math.max(...under.map(heightOf)) : 0);
|
|
65
|
+
}
|
|
66
|
+
return height.get(key) ?? 0;
|
|
67
|
+
};
|
|
68
|
+
const weights = new Map(between.map((one) => [`${one.from}>${one.to}`, new Set(one.uses.map((use) => use.from.anchor)).size]));
|
|
69
|
+
const weight = (from, to) => weights.get(`${from}>${to}`) ?? 0;
|
|
70
|
+
const againstIn = (row) => row.reduce((sum, area, at) => sum + row.slice(0, at).reduce((more, above) => more + weight(area, above), 0), 0);
|
|
71
|
+
const better = (best, row) => (againstIn(row) < againstIn(best) ? row : best);
|
|
72
|
+
// A few areas are tried in every order. More are put where most depends the right way, then each is moved wherever that leaves less against the order, until no move does.
|
|
73
|
+
const moved = (row) => row.flatMap((area, from) => row.map((_other, to) => [...row.slice(0, from), ...row.slice(from + 1)].toSpliced(to, 0, area))).reduce(better, row);
|
|
74
|
+
const improved = (row) => (againstIn(moved(row)) < againstIn(row) ? improved(moved(row)) : row);
|
|
75
|
+
const leaning = (area, circle) => circle.reduce((sum, other) => sum + weight(area, other) - weight(other, area), 0);
|
|
76
|
+
const settled = (circle) => (circle.length > 7 ? improved([...circle].sort((a, b) => leaning(b, circle) - leaning(a, circle) || a.localeCompare(b))) : rows(circle).reduce(better));
|
|
77
|
+
return [...circles].sort((a, b) => heightOf(b) - heightOf(a) || (a[0] ?? '').localeCompare(b[0] ?? '')).flatMap(settled);
|
|
78
|
+
}
|
|
79
|
+
/** What the areas of a suite depend on, each other. */
|
|
80
|
+
export function dependenciesOf(model, operations, refs) {
|
|
81
|
+
const operation = (one) => ({ anchor: idOf('op', one.name), kind: 'operation', name: one.name, area: one.area });
|
|
82
|
+
const citizens = [
|
|
83
|
+
...model.definitions.map((one) => ({ anchor: idOf(one.kind, one.name), kind: one.kind, name: one.name, area: one.area })),
|
|
84
|
+
...model.conditions.map((one) => ({ anchor: idOf('condition', one.name), kind: 'condition', name: one.description, area: one.area })),
|
|
85
|
+
...model.types.map((one) => ({ anchor: idOf('type', one.name), kind: 'type', name: one.name, area: one.area })),
|
|
86
|
+
];
|
|
87
|
+
const at = new Map(citizens.map((one) => [one.anchor, one]));
|
|
88
|
+
const citizen = (anchor) => at.get(anchor) ?? { anchor, kind: 'type', name: anchor, area: '' };
|
|
89
|
+
const asked = new Map();
|
|
90
|
+
const named = ({ who, formaldef, given }) => {
|
|
91
|
+
const key = `${who.anchor}\n${formaldef}`;
|
|
92
|
+
if (!asked.has(key))
|
|
93
|
+
asked.set(key, namedIn(formaldef, refs, { self: who.anchor, given }));
|
|
94
|
+
return asked.get(key) ?? [];
|
|
95
|
+
};
|
|
96
|
+
const words = model.definitions.map((one) => ({ who: citizen(idOf(one.kind, one.name)), formaldef: one.formaldef, given: one.parameters }));
|
|
97
|
+
const conditions = model.conditions.map((one) => ({ who: citizen(idOf('condition', one.name)), formaldef: one.formaldef }));
|
|
98
|
+
const own = operations.flatMap((one) => ownOf(one).map((formaldef) => ({ who: operation(one), formaldef })));
|
|
99
|
+
const types = model.types.map((one) => ({ who: citizen(idOf('type', one.name)), formaldef: `${one.name} = ${one.formaldef}` }));
|
|
100
|
+
const { holders, readers } = holdersOf(model, words, [...conditions, ...own], named);
|
|
101
|
+
const state = new Map(model.state.map((one) => [idOf('state', one.name), one.name]));
|
|
102
|
+
/** What a formaldef names of another area: a predicate, a function or a type at home there, or a state held there. */
|
|
103
|
+
const usedBy = (one) => named(one).flatMap((anchor) => {
|
|
104
|
+
const held = state.get(anchor);
|
|
105
|
+
if (held !== undefined)
|
|
106
|
+
return holders.get(held) ? [{ from: one.who, to: { anchor, kind: 'state', name: held, area: holders.get(held) ?? '' }, through: 'state' }] : [];
|
|
107
|
+
const to = at.get(anchor);
|
|
108
|
+
return to ? [{ from: one.who, to, through: to.kind === 'type' ? 'type' : 'name' }] : [];
|
|
109
|
+
});
|
|
110
|
+
const exchanged = operations.flatMap((one) => [one.input, one.output].flatMap((type) => (type && at.has(idOf('type', type)) ? [{ from: operation(one), to: citizen(idOf('type', type)), through: 'type' }] : [])));
|
|
111
|
+
const said = operations.flatMap((one) => saidBy(one, model.conditions).map((condition) => ({ from: operation(one), to: citizen(idOf('condition', condition.name)), through: 'condition' })));
|
|
112
|
+
// A state is told as a type: the area that holds it depends on the one that declares the type.
|
|
113
|
+
const told = model.state.flatMap((one) => [one.web?.type, one.web?.one?.type].flatMap((type) => (type && at.has(idOf('type', type)) && holders.get(one.name) ? [{ from: { anchor: idOf('state', one.name), kind: 'state', name: one.name, area: holders.get(one.name) ?? '' }, to: citizen(idOf('type', type)), through: 'type' }] : [])));
|
|
114
|
+
const elsewhere = (one) => one.from.area !== one.to.area;
|
|
115
|
+
const uses = once([...[...words, ...conditions, ...own, ...types].flatMap(usedBy), ...exchanged, ...said, ...told].filter(elsewhere), (one) => `${one.from.anchor} ${one.to.anchor} ${one.through}`);
|
|
116
|
+
const through = operations.flatMap((one) => saidBy(one, model.conditions).flatMap((condition) => {
|
|
117
|
+
const by = citizen(idOf('condition', condition.name));
|
|
118
|
+
return usedBy({ who: by, formaldef: condition.formaldef }).filter((use) => use.through === 'name').map((use) => ({ from: operation(one), to: use.to, by }));
|
|
119
|
+
}));
|
|
120
|
+
const direct = new Set(uses.map((one) => `${one.from.anchor} ${one.to.anchor}`));
|
|
121
|
+
const reaches = once(through.filter(elsewhere).filter((one) => !direct.has(`${one.from.anchor} ${one.to.anchor}`)), (one) => `${one.from.anchor} ${one.to.anchor}`);
|
|
122
|
+
const pairs = once(uses, (one) => `${one.from.area}>${one.to.area}`).map((one) => [one.from.area, one.to.area]);
|
|
123
|
+
const between = pairs.map(([from, to]) => ({ from, to, uses: uses.filter((one) => one.from.area === from && one.to.area === to) }));
|
|
124
|
+
const areas = [...new Set([...model.areas.map((one) => one.name), ...citizens.map((one) => one.area), ...operations.map((one) => one.area)])].filter(Boolean);
|
|
125
|
+
const order = orderOf(areas, between);
|
|
126
|
+
const against = new Set(between.filter((one) => order.indexOf(one.from) > order.indexOf(one.to)).map((one) => `${one.from}>${one.to}`));
|
|
127
|
+
return { holders, readers, uses, reaches, between, order, against };
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* What is around one area: the dependencies it is an end of, and the areas at their other end, in
|
|
131
|
+
* the order all of them are in. What goes against that order still does: a part is drawn as the whole is.
|
|
132
|
+
*/
|
|
133
|
+
export function aroundOf(all, area) {
|
|
134
|
+
const between = all.between.filter((one) => one.from === area || one.to === area);
|
|
135
|
+
const near = new Set([area, ...between.flatMap((one) => [one.from, one.to])]);
|
|
136
|
+
const joined = new Set(between.map((one) => `${one.from}>${one.to}`));
|
|
137
|
+
const ofIt = (one) => one.from.area === area || one.to.area === area;
|
|
138
|
+
return { ...all, between, uses: all.uses.filter(ofIt), reaches: all.reaches.filter(ofIt), order: all.order.filter((one) => near.has(one)), against: new Set([...all.against].filter((one) => joined.has(one))) };
|
|
139
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { esc, plural } from './html.js';
|
|
2
|
+
import { idOf } from './wiki.js';
|
|
3
|
+
const fixed = (value) => String(Math.round(value * 10) / 10);
|
|
4
|
+
const ROW = 58;
|
|
5
|
+
const BOX = { width: 270, height: 42 };
|
|
6
|
+
/** How far an arc goes out, by how many rows it spans: each span has a width of its own. */
|
|
7
|
+
const outBy = (span) => 22 + 24 * span;
|
|
8
|
+
/** How many of the citizens of an area depend on another. */
|
|
9
|
+
const countOf = (uses) => new Set(uses.map((one) => one.from.anchor)).size;
|
|
10
|
+
/**
|
|
11
|
+
* The areas and what each depends on: an arc from the one that depends to the one it depends on.
|
|
12
|
+
* Given one area, the drawing is of what is around it (`aroundOf`), and says which it is.
|
|
13
|
+
*/
|
|
14
|
+
export function areasDrawn(areas, { between, order, against }, here) {
|
|
15
|
+
const drawn = order.map((name) => areas.find((one) => one.name === name)).filter((one) => one !== undefined);
|
|
16
|
+
const at = new Map(drawn.map((one, row) => [one.name, row]));
|
|
17
|
+
const arcs = between.filter((one) => at.has(one.from) && at.has(one.to));
|
|
18
|
+
const span = (one) => Math.abs((at.get(one.to) ?? 0) - (at.get(one.from) ?? 0));
|
|
19
|
+
const widest = (up) => Math.max(0, ...arcs.filter((one) => against.has(`${one.from}>${one.to}`) === up).map((one) => outBy(span(one)))) + 28;
|
|
20
|
+
const [left, right] = [widest(true), widest(false)];
|
|
21
|
+
const width = left + BOX.width + right;
|
|
22
|
+
const height = drawn.length * ROW + 6;
|
|
23
|
+
const middle = (name) => (at.get(name) ?? 0) * ROW + ROW / 2;
|
|
24
|
+
// Where the count of an arc is written: half way along it, or further along where another count is already there.
|
|
25
|
+
const written = [];
|
|
26
|
+
const along = (x, from, to, out) => {
|
|
27
|
+
const at = (t) => ({ x: x + 3 * out * t * (1 - t), y: from + (to - from) * t * t * (3 - 2 * t) });
|
|
28
|
+
const free = [0.5, 0.36, 0.64, 0.24, 0.76].map(at).find((place) => written.every((other) => Math.abs(other.x - place.x) > 18 || Math.abs(other.y - place.y) > 13)) ?? at(0.5);
|
|
29
|
+
written.push(free);
|
|
30
|
+
return free;
|
|
31
|
+
};
|
|
32
|
+
const arc = (one) => {
|
|
33
|
+
const up = against.has(`${one.from}>${one.to}`);
|
|
34
|
+
const [side, x] = up ? [-1, left] : [1, left + BOX.width];
|
|
35
|
+
// It leaves under the middle of what depends, and arrives above the middle of what is depended on; the other way round where it goes up.
|
|
36
|
+
const [from, to] = [middle(one.from) + (up ? -8 : 8), middle(one.to) + (up ? 8 : -8)];
|
|
37
|
+
const out = outBy(span(one)) * side;
|
|
38
|
+
const state = one.uses.every((use) => use.through === 'state');
|
|
39
|
+
const path = `M${fixed(x)},${fixed(from)} C${fixed(x + out)},${fixed(from)} ${fixed(x + out)},${fixed(to)} ${fixed(x + 7 * side)},${fixed(to)}`;
|
|
40
|
+
const tip = `M${fixed(x)},${fixed(to)} l${7 * side},-3.5 v7 z`;
|
|
41
|
+
const count = along(x, from, to, out);
|
|
42
|
+
const said = `${one.from} depends on ${one.to}: ${plural(countOf(one.uses), 'citizen')}${state ? ', by reading its state alone' : ''}${up ? ', against the order: a cycle' : ''}`;
|
|
43
|
+
return `<g class="dep-arc${state ? ' state' : ''}${up ? ' against' : ''}" data-from="${esc(one.from)}" data-to="${esc(one.to)}"><title>${esc(said)}</title><path class="wire" d="${path}"/><path class="tip" d="${tip}"/><text class="dep-n" x="${fixed(count.x)}" y="${fixed(count.y + 4)}" text-anchor="middle">${countOf(one.uses)}</text></g>`;
|
|
44
|
+
};
|
|
45
|
+
const box = (one) => {
|
|
46
|
+
const y = middle(one.name) - BOX.height / 2;
|
|
47
|
+
const held = one.holds.length ? ` · holds ${one.holds.slice(0, 3).join(', ')}${one.holds.length > 3 ? `, +${one.holds.length - 3}` : ''}` : '';
|
|
48
|
+
return `<a class="dep-node${one.name === here ? ' here' : ''}" href="#${esc(idOf('area', one.name))}" data-area="${esc(one.name)}"${one.name === here ? ' aria-current="page"' : ''}><rect class="dep-box" x="${left}" y="${fixed(y)}" width="${BOX.width}" height="${BOX.height}" rx="8"/><text class="dep-name" x="${left + 14}" y="${fixed(y + 18)}">${esc(one.title)}</text><text class="dep-sub" x="${left + 14}" y="${fixed(y + 33)}">${esc(`${plural(one.operations, 'operation')}${held}`)}</text></a>`;
|
|
49
|
+
};
|
|
50
|
+
const subject = here === undefined ? 'The areas' : `${areas.find((one) => one.name === here)?.title ?? here} and the areas it is joined to`;
|
|
51
|
+
const label = `${subject}, those that depend on others first: ${arcs.length ? `${plural(arcs.length, 'dependency')}, ${against.size ? `${against.size} against the order` : 'none against the order'}` : 'none depends on another'}.`;
|
|
52
|
+
return `<svg class="dep dep-areas" viewBox="0 0 ${fixed(width)} ${height}" width="${fixed(width)}" role="img" aria-label="${esc(label)}">${[...arcs].sort((a, b) => span(a) - span(b)).map(arc).join('')}${drawn.map(box).join('')}</svg>`;
|
|
53
|
+
}
|
|
54
|
+
const LINE = 21;
|
|
55
|
+
const HEAD = 32;
|
|
56
|
+
const GAP = 14;
|
|
57
|
+
/** What a part takes over its rows: its line, and its name under it. */
|
|
58
|
+
const PART = 24;
|
|
59
|
+
/**
|
|
60
|
+
* The parts of a box, as an object diagram has them, one under the other with a line between: what
|
|
61
|
+
* the area holds, what it says of it, what it says with it, and what it does.
|
|
62
|
+
*/
|
|
63
|
+
const PARTS = [
|
|
64
|
+
['state', 'State'],
|
|
65
|
+
['predicate', 'Predicates'],
|
|
66
|
+
['function', 'Functions'],
|
|
67
|
+
['condition', 'Conditions'],
|
|
68
|
+
['type', 'Types'],
|
|
69
|
+
['operation', 'Operations'],
|
|
70
|
+
];
|
|
71
|
+
/** How wide a box of citizens is. */
|
|
72
|
+
const WIDE = 320;
|
|
73
|
+
/** How many characters a row has room for: a sentence that is longer is cut, and told whole to who points at it. */
|
|
74
|
+
const ROOM = 36;
|
|
75
|
+
/** The boxes of one side, one under the other, and where each of their rows is. */
|
|
76
|
+
function placed(boxes, rows) {
|
|
77
|
+
let y = 4;
|
|
78
|
+
for (const box of boxes) {
|
|
79
|
+
box.y = y;
|
|
80
|
+
let at = y + HEAD;
|
|
81
|
+
// A part is there when the box has a row of its kind, and the rows of a part keep the order they were given.
|
|
82
|
+
box.parts = PARTS.map(([kind, title]) => ({ title, of: box.rows.filter((row) => row.kind === kind) }))
|
|
83
|
+
.filter((part) => part.of.length)
|
|
84
|
+
.map((part) => {
|
|
85
|
+
const top = at;
|
|
86
|
+
part.of.forEach((row, n) => rows.set(row.anchor, top + PART + n * LINE + LINE / 2));
|
|
87
|
+
at += PART + part.of.length * LINE;
|
|
88
|
+
return { title: part.title, y: top };
|
|
89
|
+
});
|
|
90
|
+
box.height = at + 7 - y;
|
|
91
|
+
y += box.height + GAP;
|
|
92
|
+
}
|
|
93
|
+
return y - GAP;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The citizens that depend and those they depend on, each area in one box and each citizen in one
|
|
97
|
+
* row of it, whatever depends on it and whatever it depends on. The boxes are one under the other
|
|
98
|
+
* in the order of the areas, so a wire goes down, at the right of the boxes, from the row of what
|
|
99
|
+
* depends to the row of what it depends on; one that goes against the order goes up, at the left.
|
|
100
|
+
*
|
|
101
|
+
* A box is in parts, as that of an object diagram: the states, the predicates, the functions, the
|
|
102
|
+
* conditions, the types and the operations, each under a line and its name. A row goes where what
|
|
103
|
+
* it is joined to is, as far as its part lets it. A wire is as wide as it is long, so that two of
|
|
104
|
+
* different lengths never lie on each other.
|
|
105
|
+
*/
|
|
106
|
+
function joinedDrawn(wires, order, { title, written }, { cls, label, here }) {
|
|
107
|
+
if (!wires.length)
|
|
108
|
+
return '';
|
|
109
|
+
const said = (one) => {
|
|
110
|
+
const text = one.kind === 'predicate' || one.kind === 'function' ? written(one.anchor) : one.name;
|
|
111
|
+
return text.length > ROOM ? { label: `${text.slice(0, ROOM - 1).trimEnd()}…`, whole: text } : { label: text };
|
|
112
|
+
};
|
|
113
|
+
const ends = wires.flatMap((one) => [one.from, one.to]);
|
|
114
|
+
const depending = (anchor) => wires.filter((wire) => wire.to.anchor === anchor).length;
|
|
115
|
+
const boxes = order
|
|
116
|
+
.map((area) => {
|
|
117
|
+
const all = [...new Map(ends.filter((one) => one.area === area).map((one) => [one.anchor, one])).values()];
|
|
118
|
+
const rows = all.map((one) => ({ anchor: one.anchor, kind: one.kind, ...said(one), ...(depending(one.anchor) ? { count: depending(one.anchor) } : {}) }));
|
|
119
|
+
return { area, title: title(area), rows, y: 0, height: 0, parts: [] };
|
|
120
|
+
})
|
|
121
|
+
.filter((box) => box.rows.length);
|
|
122
|
+
const y = new Map();
|
|
123
|
+
let height = placed(boxes, y);
|
|
124
|
+
// A row goes where what it is joined to is, on average: a few turns are enough to untangle most.
|
|
125
|
+
const mean = (values) => values.reduce((sum, value) => sum + value, 0) / Math.max(1, values.length);
|
|
126
|
+
const towards = (anchor) => mean(wires.flatMap((one) => (one.from.anchor === anchor ? [y.get(one.to.anchor) ?? 0] : one.to.anchor === anchor ? [y.get(one.from.anchor) ?? 0] : [])));
|
|
127
|
+
for (let turn = 0; turn < 6; turn++) {
|
|
128
|
+
for (const box of boxes)
|
|
129
|
+
box.rows.sort((a, b) => towards(a.anchor) - towards(b.anchor));
|
|
130
|
+
height = placed(boxes, y);
|
|
131
|
+
}
|
|
132
|
+
const at = new Map(boxes.map((box, row) => [box.area, row]));
|
|
133
|
+
const up = (one) => (at.get(one.from.area) ?? 0) > (at.get(one.to.area) ?? 0);
|
|
134
|
+
const outOf = (one) => 14 + 8 * Math.sqrt(Math.abs((y.get(one.to.anchor) ?? 0) - (y.get(one.from.anchor) ?? 0)));
|
|
135
|
+
const widest = (side) => Math.max(0, ...wires.filter((one) => up(one) === side).map(outOf)) + 12;
|
|
136
|
+
const [left, right] = [widest(true), widest(false)];
|
|
137
|
+
const width = left + WIDE + right;
|
|
138
|
+
const wire = (one) => {
|
|
139
|
+
const [from, to] = [y.get(one.from.anchor) ?? 0, y.get(one.to.anchor) ?? 0];
|
|
140
|
+
const [side, x] = up(one) ? [-1, left] : [1, left + WIDE];
|
|
141
|
+
const out = outOf(one) * side;
|
|
142
|
+
return `<g class="dep-wire${one.through === 'state' ? ' state' : ''}${up(one) ? ' against' : ''}" data-from="${esc(one.from.anchor)}" data-to="${esc(one.to.anchor)}"><path class="wire" d="M${fixed(x)},${fixed(from)} C${fixed(x + out)},${fixed(from)} ${fixed(x + out)},${fixed(to)} ${fixed(x + 7 * side)},${fixed(to)}"/><path class="tip" d="M${fixed(x)},${fixed(to)} l${7 * side},-3.5 v7 z"/></g>`;
|
|
143
|
+
};
|
|
144
|
+
const box = (one) => {
|
|
145
|
+
const x = left;
|
|
146
|
+
const rows = one.rows
|
|
147
|
+
.map((row) => {
|
|
148
|
+
const middle = y.get(row.anchor) ?? 0;
|
|
149
|
+
const count = row.count === undefined ? '' : `<text class="dep-count" x="${fixed(x + WIDE - 12)}" y="${fixed(middle + 4)}" text-anchor="end">${row.count}</text>`;
|
|
150
|
+
return `<a class="dep-row" href="#${esc(row.anchor)}" data-dep="${esc(row.anchor)}">${row.whole ? `<title>${esc(row.whole)}</title>` : ''}<rect class="dep-hit" x="${fixed(x + 2)}" y="${fixed(middle - LINE / 2)}" width="${WIDE - 4}" height="${LINE}" rx="4"/><text class="dep-word ${row.kind}" x="${fixed(x + 12)}" y="${fixed(middle + 4)}">${esc(row.label)}</text>${count}</a>`;
|
|
151
|
+
})
|
|
152
|
+
.join('');
|
|
153
|
+
const parts = one.parts.map((part) => `<line class="dep-rule" x1="${fixed(x)}" y1="${fixed(part.y)}" x2="${fixed(x + WIDE)}" y2="${fixed(part.y)}"/><text class="dep-part" x="${fixed(x + 12)}" y="${fixed(part.y + 15)}">${esc(part.title)}</text>`).join('');
|
|
154
|
+
return `<rect class="dep-box${one.area === here ? ' here' : ''}" x="${fixed(x)}" y="${fixed(one.y)}" width="${WIDE}" height="${fixed(one.height)}" rx="8"/>${parts}<a href="#${esc(idOf('area', one.area))}"><text class="dep-name" x="${fixed(x + 12)}" y="${fixed(one.y + 22)}">${esc(one.title)}</text></a>${rows}`;
|
|
155
|
+
};
|
|
156
|
+
return `<svg class="dep ${cls}" viewBox="0 0 ${fixed(width)} ${fixed(height + 4)}" width="${fixed(width)}" role="img" aria-label="${esc(label)}">${wires.map(wire).join('')}${boxes.map(box).join('')}</svg>`;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The operations that name a predicate or a function of another area in a formaldef of their own,
|
|
160
|
+
* each joined to that name. What an operation reaches through a condition is not drawn: it is the
|
|
161
|
+
* condition that names it.
|
|
162
|
+
*/
|
|
163
|
+
export function namesDrawn({ uses, order }, naming) {
|
|
164
|
+
const wires = uses.filter((one) => one.from.kind === 'operation' && one.through === 'name');
|
|
165
|
+
const label = `${plural(new Set(wires.map((one) => one.from.anchor)).size, 'operation')} joined to the ${plural(new Set(wires.map((one) => one.to.anchor)).size, 'name')} of another area that their formaldefs say.`;
|
|
166
|
+
return joinedDrawn(wires, order, naming, { cls: 'dep-names', label });
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* What is around one area, in detail (`aroundOf`): every citizen that depends, joined to what it
|
|
170
|
+
* depends on, whatever it goes through: a name, a condition, a type, or a state, which is dashed.
|
|
171
|
+
* Each arc of the drawing of the areas is here as many wires as it has reasons.
|
|
172
|
+
*/
|
|
173
|
+
export function detailDrawn({ uses, order }, naming, here) {
|
|
174
|
+
const label = `${naming.title(here)} in detail: ${plural(new Set(uses.map((one) => one.from.anchor)).size, 'citizen')} joined to the ${plural(new Set(uses.map((one) => one.to.anchor)).size, 'citizen')} of another area they depend on.`;
|
|
175
|
+
return joinedDrawn(uses, order, naming, { cls: 'dep-detail', label, here });
|
|
176
|
+
}
|
|
@@ -33,6 +33,7 @@ const navOf = (wiki, about) => `<nav class="side" aria-label="Explorer">
|
|
|
33
33
|
<div class="nav">
|
|
34
34
|
${link('#definitions', 'Formal definitions')}
|
|
35
35
|
${link('#types', 'Types')}
|
|
36
|
+
${link('#dependencies', 'Dependencies')}
|
|
36
37
|
</div>
|
|
37
38
|
<p class="chap">Testing</p>
|
|
38
39
|
<div class="nav">
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The names of a formaldef that lead to a citizen of the suite, as Elo's parser reads them. Pure.
|
|
2
2
|
//
|
|
3
3
|
// Elo's parser says where each expression stands (`parse(source, { locations: true })`), so a
|
|
4
|
-
// name is resolved from the tree: a free name, a member of `old`, of `seenBy.<actor>` or of `db
|
|
4
|
+
// name is resolved from the tree: a free name, a member of `old`, of `seenBy.<actor>` or of `db`
|
|
5
|
+
// (a state or the item of one, as that mechanism shows it),
|
|
5
6
|
// a type a value is given to. What the expression binds (a lambda's parameters, a `let`'s names)
|
|
6
7
|
// is not the citizen of the same name, inside that scope only. A member and a record key are never
|
|
7
8
|
// a citizen. A type of a declaration has no position in the tree: it is found among the words of
|
|
@@ -10,13 +11,15 @@ import { parse, splitProgramHeader } from '@enspirit/elo';
|
|
|
10
11
|
import { RESERVED } from '../naming.js';
|
|
11
12
|
import { idOf } from './wiki.js';
|
|
12
13
|
/** The anchors of the citizens a formaldef may name, from what a suite says. */
|
|
14
|
+
/** An item leads to the state it is one of. */
|
|
15
|
+
const items = (state) => state.flatMap((one) => (one.item ? [[one.item.name, idOf('state', one.name)]] : []));
|
|
13
16
|
export function refsOf(model) {
|
|
14
17
|
const by = (kind, names) => names.map((name) => [name, idOf(kind, name)]);
|
|
15
18
|
const definitions = model.definitions.map((one) => [one.name, idOf(one.kind, one.name)]);
|
|
16
19
|
return {
|
|
17
|
-
names: new Map([...by('state', model.state.map((one) => one.name)), ...definitions]),
|
|
20
|
+
names: new Map([...by('state', model.state.map((one) => one.name)), ...items(model.state.filter((one) => one.web)), ...definitions]),
|
|
18
21
|
types: new Map(by('type', model.types.map((one) => one.name))),
|
|
19
|
-
relations: new Map(by('
|
|
22
|
+
relations: new Map([...by('state', model.state.filter((one) => one.db).map((one) => one.name)), ...items(model.state.filter((one) => one.db))]),
|
|
20
23
|
actors: new Map(by('actor', model.actors.map((one) => one.name))),
|
|
21
24
|
};
|
|
22
25
|
}
|
package/dist/explorer/elo.js
CHANGED
|
@@ -93,3 +93,21 @@ export function eloHtml(text, refs, about = {}) {
|
|
|
93
93
|
})
|
|
94
94
|
.join('');
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* The citizens a text of Elo names, by their anchors, each once: what `eloHtml` would make a link
|
|
98
|
+
* of, and nothing else. A function of Elo's own, called, names no citizen.
|
|
99
|
+
*/
|
|
100
|
+
export function namedIn(text, refs, about = {}) {
|
|
101
|
+
const tokens = tokensOf(text);
|
|
102
|
+
const links = refsIn(text, wordsOf(tokens), refs, about);
|
|
103
|
+
const found = new Set();
|
|
104
|
+
let at = 0;
|
|
105
|
+
for (const token of tokens) {
|
|
106
|
+
const end = at + token.text.length;
|
|
107
|
+
for (const ref of token.kind === 'fn' ? links.filter((one) => !one.called) : links)
|
|
108
|
+
if (ref.at >= at && ref.at + ref.length <= end)
|
|
109
|
+
found.add(ref.anchor);
|
|
110
|
+
at = end;
|
|
111
|
+
}
|
|
112
|
+
return [...found];
|
|
113
|
+
}
|
package/dist/explorer/index.js
CHANGED
|
@@ -54,8 +54,7 @@ export function indexOf(wiki, pages) {
|
|
|
54
54
|
...pages.map((page) => ({ h: page.id, k: page.kind, n: page.title, x: page.said ?? '', c: '', ctx: '', ...(page.area ? { a: page.area } : {}), ...(page.quote ? { q: page.quote } : {}) })),
|
|
55
55
|
...wiki.areas.flatMap(wordsOf),
|
|
56
56
|
...wiki.operations.flatMap((operation) => [...operation.clauses.map((one) => clause(operation, one)), ...operation.cases.flatMap((one) => [kase(operation, one), ...also(operation, one)])]),
|
|
57
|
-
...wiki.state.map((one) => plain('state', 'State', STATE, one, `GET ${one.path}`)),
|
|
58
|
-
...wiki.relations.map((one) => ({ h: idOf('relation', one.name), k: 'Relation', n: `db.${one.name}`, x: told(one.description, one.table, one.attributes.join(', ')), c: '', ctx: STATE, q: one.description })),
|
|
57
|
+
...wiki.state.map((one) => plain('state', 'State', STATE, one, told(one.item ? `${one.item.name}(${one.item.key.join(', ')})` : '', one.web ? `GET ${one.web.path}` : '', one.web?.one ? `GET ${one.web.one.path}` : '', one.db ? told(one.db.table, one.db.attributes.join(', ')) : ''))),
|
|
59
58
|
...wiki.backgrounds.map((one) => plain('background', 'Background', BACKGROUNDS, one)),
|
|
60
59
|
...wiki.actors.map((one) => plain('actor', 'Actor', WORLD, one, one.is)),
|
|
61
60
|
];
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// its counterexamples. What the suite says, and nothing of a run: that is in tests.ts.
|
|
3
3
|
// Pure: the wiki is given, markup is what comes out.
|
|
4
4
|
import { PRE, SAID, isForType, sameSentence } from '../suite.js';
|
|
5
|
+
import { shown } from '../variables.js';
|
|
5
6
|
import { requestOf } from './calls.js';
|
|
6
7
|
import { eloHtml } from './elo.js';
|
|
7
8
|
import { jsonHtml } from './json.js';
|
|
@@ -19,8 +20,6 @@ const GROUP = {
|
|
|
19
20
|
export const crumbs = (...parts) => `<p class="crumb">${parts.join('<span aria-hidden="true">›</span>')}</p>`;
|
|
20
21
|
export const areaTitle = (name) => (name === '_shared' ? 'Shared' : name.charAt(0).toUpperCase() + name.slice(1));
|
|
21
22
|
const row = (label, value) => `<dt>${esc(label)}</dt><dd>${value}</dd>`;
|
|
22
|
-
/** States, each leading to its row of the State page; a list its file does not say is derived, and says so. */
|
|
23
|
-
const statesOf = (names, said) => `${names.map((name) => link(`#${idOf('state', name)}`, name)).join(', ') || '<span class="m">none</span>'}${said ? '' : ' <span class="m s" title="Not said by its file: derived from its formaldefs">· derived</span>'}`;
|
|
24
23
|
const typeLink = (name) => (name ? link(`#${idOf('type', name)}`, name) : '<span class="m">nothing</span>');
|
|
25
24
|
/** Who calls, and from which Background: a name for a table cell, each leading to who and what it is. */
|
|
26
25
|
export const callerOf = (kase) => {
|
|
@@ -82,8 +81,7 @@ function typeSide(label, name, { types, refs }) {
|
|
|
82
81
|
export function operationPage(operation, around) {
|
|
83
82
|
const gaps = operation.gaps.length ? fold('Gaps', `<p class="sub">The transition the operation does not say, what no case shows, or no counterexample violates.</p>${list(operation.gaps.map((gap) => `<span class="m">· ${esc(gap)}</span>`))}`) : '';
|
|
84
83
|
const kind = operation.observes ? 'Observation: it only reads, so it is checked to change nothing' : 'Operation';
|
|
85
|
-
const {
|
|
86
|
-
const meta = [row('Performed by', link(`#${idOf('agent', operation.agent)}`, operation.agent)), row('Route', mono(`${operation.entry.method} ${operation.entry.path}`)), row('Kind', esc(kind)), row('Input', typeLink(operation.input)), row('Output', typeLink(operation.output)), row('Monitors', statesOf(reach.monitors, reach.said.monitors)), row('Controls', statesOf(reach.controls, reach.said.controls)), row('Specification', mono(operation.file)), row('Tests', link(`#${idOf('test', operation.name)}`, 'Results of the last run'))];
|
|
84
|
+
const meta = [row('Performed by', link(`#${idOf('agent', operation.agent)}`, operation.agent)), row('Route', mono(`${operation.entry.method} ${operation.entry.path}`)), row('Kind', esc(kind)), row('Input', typeLink(operation.input)), row('Output', typeLink(operation.output)), row('Specification', mono(operation.file)), row('Tests', link(`#${idOf('test', operation.name)}`, 'Results of the last run'))];
|
|
87
85
|
const io = `<div class="io">${typeSide('Input', operation.input, around)}<span class="arrow" aria-hidden="true">→</span>${typeSide('Output', operation.output, around)}</div>`;
|
|
88
86
|
const body = `<div class="page-top">${crumbs(link('#home', 'Specification'), link(`#${idOf('area', operation.area)}`, areaTitle(operation.area)))}<button type="button" class="fold-all" aria-expanded="true">Collapse all</button></div>
|
|
89
87
|
<h1 class="code">${esc(operation.name)}</h1>
|