@tuprolog/arg2p-ui 0.0.0-stage → 0.1.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 +48 -2
- package/dist/components/arg2p-editor.d.ts +73 -0
- package/dist/components/arg2p-editor.js +244 -0
- package/dist/components/arg2p-editor.js.map +1 -0
- package/dist/components/arg2p-flags.d.ts +58 -0
- package/dist/components/arg2p-flags.js +358 -0
- package/dist/components/arg2p-flags.js.map +1 -0
- package/dist/components/arg2p-framework.d.ts +102 -0
- package/dist/components/arg2p-framework.js +513 -0
- package/dist/components/arg2p-framework.js.map +1 -0
- package/dist/components/arg2p-graph.d.ts +112 -0
- package/dist/components/arg2p-graph.js +577 -0
- package/dist/components/arg2p-graph.js.map +1 -0
- package/dist/components/arg2p-solutions.d.ts +75 -0
- package/dist/components/arg2p-solutions.js +391 -0
- package/dist/components/arg2p-solutions.js.map +1 -0
- package/dist/data.d.ts +9 -0
- package/dist/data.js +11 -0
- package/dist/data.js.map +1 -0
- package/dist/editor/language.d.ts +9 -0
- package/dist/editor/language.js +78 -0
- package/dist/editor/language.js.map +1 -0
- package/dist/engine.d.ts +94 -0
- package/dist/engine.js +2 -0
- package/dist/engine.js.map +1 -0
- package/dist/flags/schema.d.ts +50 -0
- package/dist/flags/schema.js +195 -0
- package/dist/flags/schema.js.map +1 -0
- package/dist/flags/text.d.ts +18 -0
- package/dist/flags/text.js +85 -0
- package/dist/flags/text.js.map +1 -0
- package/dist/formats/declarations.d.ts +9 -0
- package/dist/formats/declarations.js +193 -0
- package/dist/formats/declarations.js.map +1 -0
- package/dist/formats/frameworks.d.ts +23 -0
- package/dist/formats/frameworks.js +130 -0
- package/dist/formats/frameworks.js.map +1 -0
- package/dist/graph/canvas.d.ts +21 -0
- package/dist/graph/canvas.js +76 -0
- package/dist/graph/canvas.js.map +1 -0
- package/dist/graph/drawing.d.ts +24 -0
- package/dist/graph/drawing.js +64 -0
- package/dist/graph/drawing.js.map +1 -0
- package/dist/graph/layout.d.ts +28 -0
- package/dist/graph/layout.js +167 -0
- package/dist/graph/layout.js.map +1 -0
- package/dist/graph/levels.d.ts +6 -0
- package/dist/graph/levels.js +25 -0
- package/dist/graph/levels.js.map +1 -0
- package/dist/graph/positions.d.ts +24 -0
- package/dist/graph/positions.js +43 -0
- package/dist/graph/positions.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/js/engine.d.ts +35 -0
- package/dist/js/engine.js +110 -0
- package/dist/js/engine.js.map +1 -0
- package/dist/js/host.d.ts +75 -0
- package/dist/js/host.js +237 -0
- package/dist/js/host.js.map +1 -0
- package/dist/js/index.d.ts +2 -0
- package/dist/js/index.js +4 -0
- package/dist/js/index.js.map +1 -0
- package/dist/js/worker.d.ts +1 -0
- package/dist/js/worker.js +7 -0
- package/dist/js/worker.js.map +1 -0
- package/dist/theme.d.ts +5 -0
- package/dist/theme.js +48 -0
- package/dist/theme.js.map +1 -0
- package/package.json +65 -4
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// A compact layered drawing of an argument graph: every argument on the row of its level (facts at the bottom), each
|
|
2
|
+
// close to the arguments it is linked to, and never closer than `spacing` to its neighbours on the row.
|
|
3
|
+
//
|
|
4
|
+
// `levels` maps every id to its row, `links` are the supports (from a sub-argument to the argument built on it) and
|
|
5
|
+
// `attacks` the attacks. Supports decide the rows and pull hardest; attacks pull too, more lightly, so that attackers
|
|
6
|
+
// sit near what they attack.
|
|
7
|
+
const SWEEPS = 4;
|
|
8
|
+
const ATTACK_WEIGHT = 0.4;
|
|
9
|
+
const STAGGER_SQUEEZE = 0.55;
|
|
10
|
+
const STAGGER_DROP = 0.4;
|
|
11
|
+
const MAX_STRETCH = 2.4;
|
|
12
|
+
// the free room above and below a row, for the edges
|
|
13
|
+
const ROW_GAP = 40;
|
|
14
|
+
/** The position of every argument of [levels] */
|
|
15
|
+
export function layeredLayout(levels, links, options = {}) {
|
|
16
|
+
const { spacing = 110, levelSeparation = 110, attacks = [], aspect = null, staggerFrom = 8, sizes = null, gap = 18 } = options;
|
|
17
|
+
const size = (id) => sizes?.get(id) ?? { width: 0, height: 0 };
|
|
18
|
+
const metrics = { spacing, levelSeparation, staggerFrom, size, sized: sizes !== null, gap };
|
|
19
|
+
// The separate parts of the graph are laid out on their own and then put side by side, largest first, so that
|
|
20
|
+
// none of them drifts away from the others
|
|
21
|
+
const positions = new Map();
|
|
22
|
+
let offset = 0;
|
|
23
|
+
components(levels, [...links, ...attacks]).forEach(ids => {
|
|
24
|
+
const part = layoutComponent(ids, levels, links, attacks, metrics);
|
|
25
|
+
const left = Math.min(...ids.map(id => part.get(id).x - size(id).width / 2));
|
|
26
|
+
const right = Math.max(...ids.map(id => part.get(id).x + size(id).width / 2));
|
|
27
|
+
part.forEach((point, id) => positions.set(id, { x: point.x - left + offset, y: point.y }));
|
|
28
|
+
offset += right - left + (sizes ? gap * 2 : spacing);
|
|
29
|
+
});
|
|
30
|
+
if (aspect !== null && positions.size > 1)
|
|
31
|
+
stretchRows(positions, aspect);
|
|
32
|
+
return positions;
|
|
33
|
+
}
|
|
34
|
+
function layoutComponent(ids, levels, links, attacks, metrics) {
|
|
35
|
+
const { spacing, levelSeparation, staggerFrom, size, sized, gap } = metrics;
|
|
36
|
+
const inside = new Set(ids);
|
|
37
|
+
const rows = [];
|
|
38
|
+
ids.forEach(id => {
|
|
39
|
+
const level = levels.get(id);
|
|
40
|
+
(rows[level] = rows[level] ?? []).push(id);
|
|
41
|
+
});
|
|
42
|
+
for (let i = 0; i < rows.length; i++)
|
|
43
|
+
rows[i] = (rows[i] ?? []).sort(byNumber);
|
|
44
|
+
const staggered = rows.map(row => row.length > staggerFrom);
|
|
45
|
+
// The least distance between the centres of two neighbours on a row: by their widths when known. On a zig-zag
|
|
46
|
+
// row, next neighbours sit at different heights and may come closer; the ones after them may not.
|
|
47
|
+
const apart = (a, b) => (sized ? (size(a).width + size(b).width) / 2 + gap : spacing);
|
|
48
|
+
const rowDistances = rows.map((_, level) => staggered[level] ? { next: (a, b) => apart(a, b) * STAGGER_SQUEEZE, second: apart } : { next: apart, second: null });
|
|
49
|
+
const own = (list) => list.filter(it => inside.has(it.from) && inside.has(it.to));
|
|
50
|
+
const supportsBelow = neighbours(own(links), 'to', 'from');
|
|
51
|
+
const supportsAbove = neighbours(own(links), 'from', 'to');
|
|
52
|
+
// attacks pull both ways, whatever row their ends are on
|
|
53
|
+
const attacked = new Map();
|
|
54
|
+
[...neighbours(own(attacks), 'from', 'to'), ...neighbours(own(attacks), 'to', 'from')].forEach(([id, list]) => attacked.set(id, [...(attacked.get(id) ?? []), ...list]));
|
|
55
|
+
// Evenly spaced rows to start with, then every row placed by the one below (its sub-arguments) and by the one
|
|
56
|
+
// above (what it supports), in turn
|
|
57
|
+
const x = new Map();
|
|
58
|
+
rows.forEach(row => row.forEach((id, i) => x.set(id, i * spacing)));
|
|
59
|
+
for (let sweep = 0; sweep < SWEEPS; sweep++) {
|
|
60
|
+
for (let level = 1; level < rows.length; level++)
|
|
61
|
+
placeRow(rows[level], supportsBelow, attacked, x, rowDistances[level]);
|
|
62
|
+
for (let level = rows.length - 2; level >= 0; level--)
|
|
63
|
+
placeRow(rows[level], supportsAbove, attacked, x, rowDistances[level]);
|
|
64
|
+
}
|
|
65
|
+
for (let level = 1; level < rows.length; level++)
|
|
66
|
+
placeRow(rows[level], supportsBelow, attacked, x, rowDistances[level]);
|
|
67
|
+
// The rows from the bottom up: a zig-zag row drops every other node by enough for the two halves not to overlap,
|
|
68
|
+
// and rows are kept apart by their heights (and at least levelSeparation)
|
|
69
|
+
const tallest = (row) => Math.max(0, ...row.map(id => size(id).height));
|
|
70
|
+
const drops = rows.map((row, level) => staggered[level] ? Math.max(levelSeparation * STAGGER_DROP, sized ? tallest(row) + gap / 2 : 0) : 0);
|
|
71
|
+
const positions = new Map();
|
|
72
|
+
let y = 0;
|
|
73
|
+
rows.forEach((row, level) => {
|
|
74
|
+
if (level > 0) {
|
|
75
|
+
const below = tallest(rows[level - 1]) / 2 + drops[level - 1];
|
|
76
|
+
const above = tallest(row) / 2;
|
|
77
|
+
y -= Math.max(levelSeparation, below + above + (sized ? ROW_GAP : 0) + drops[level]);
|
|
78
|
+
}
|
|
79
|
+
row
|
|
80
|
+
.slice()
|
|
81
|
+
.sort((a, b) => x.get(a) - x.get(b))
|
|
82
|
+
.forEach((id, i) => positions.set(id, { x: x.get(id), y: y + (staggered[level] && i % 2 === 1 ? drops[level] : 0) }));
|
|
83
|
+
});
|
|
84
|
+
return positions;
|
|
85
|
+
}
|
|
86
|
+
// The rows moved apart (never closer) until the drawing has the proportions of the area it is shown in, up to
|
|
87
|
+
// MAX_STRETCH times the normal separation
|
|
88
|
+
function stretchRows(positions, aspect) {
|
|
89
|
+
const xs = [...positions.values()].map(it => it.x);
|
|
90
|
+
const ys = [...positions.values()].map(it => it.y);
|
|
91
|
+
const width = Math.max(...xs) - Math.min(...xs);
|
|
92
|
+
const height = Math.max(...ys) - Math.min(...ys);
|
|
93
|
+
if (height === 0 || width === 0)
|
|
94
|
+
return;
|
|
95
|
+
const stretch = Math.min(MAX_STRETCH, Math.max(1, (aspect * width) / height));
|
|
96
|
+
positions.forEach(point => {
|
|
97
|
+
point.y *= stretch;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// The connected parts of the graph, largest first (ties: the lowest argument first)
|
|
101
|
+
function components(levels, edges) {
|
|
102
|
+
const parent = new Map([...levels.keys()].map(id => [id, id]));
|
|
103
|
+
const find = (id) => {
|
|
104
|
+
const up = parent.get(id);
|
|
105
|
+
if (up === id)
|
|
106
|
+
return id;
|
|
107
|
+
const root = find(up);
|
|
108
|
+
parent.set(id, root);
|
|
109
|
+
return root;
|
|
110
|
+
};
|
|
111
|
+
edges.forEach(it => {
|
|
112
|
+
if (parent.has(it.from) && parent.has(it.to))
|
|
113
|
+
parent.set(find(it.from), find(it.to));
|
|
114
|
+
});
|
|
115
|
+
const groups = new Map();
|
|
116
|
+
[...levels.keys()].sort(byNumber).forEach(id => {
|
|
117
|
+
const root = find(id);
|
|
118
|
+
if (!groups.has(root))
|
|
119
|
+
groups.set(root, []);
|
|
120
|
+
groups.get(root).push(id);
|
|
121
|
+
});
|
|
122
|
+
return [...groups.values()].sort((a, b) => b.length - a.length || byNumber(a[0], b[0]));
|
|
123
|
+
}
|
|
124
|
+
function neighbours(links, key, value) {
|
|
125
|
+
const map = new Map();
|
|
126
|
+
links.forEach(link => {
|
|
127
|
+
if (!map.has(link[key]))
|
|
128
|
+
map.set(link[key], []);
|
|
129
|
+
map.get(link[key]).push(link[value]);
|
|
130
|
+
});
|
|
131
|
+
return map;
|
|
132
|
+
}
|
|
133
|
+
// A row ordered by where its nodes would like to be (the weighted mean x of the nodes they are linked to, or where
|
|
134
|
+
// they are when they have none), then placed left to right no closer than [distances] allow, and shifted back so that,
|
|
135
|
+
// on average, the nodes are where they wanted to be
|
|
136
|
+
function placeRow(row, supports, attacks, x, distances) {
|
|
137
|
+
if (row.length === 0)
|
|
138
|
+
return;
|
|
139
|
+
const wanted = new Map(row.map(id => {
|
|
140
|
+
const pulls = [
|
|
141
|
+
...(supports.get(id) ?? []).filter(it => x.has(it)).map((it) => [x.get(it), 1]),
|
|
142
|
+
...(attacks.get(id) ?? []).filter(it => x.has(it)).map((it) => [x.get(it), ATTACK_WEIGHT]),
|
|
143
|
+
];
|
|
144
|
+
const weight = pulls.reduce((sum, [, w]) => sum + w, 0);
|
|
145
|
+
return [id, weight > 0 ? pulls.reduce((sum, [at, w]) => sum + at * w, 0) / weight : x.get(id)];
|
|
146
|
+
}));
|
|
147
|
+
row.sort((a, b) => wanted.get(a) - wanted.get(b) || byNumber(a, b));
|
|
148
|
+
const placed = [];
|
|
149
|
+
row.forEach((id, i) => {
|
|
150
|
+
let at = wanted.get(id);
|
|
151
|
+
if (i > 0)
|
|
152
|
+
at = Math.max(at, placed[i - 1] + distances.next(row[i - 1], id));
|
|
153
|
+
if (i > 1 && distances.second)
|
|
154
|
+
at = Math.max(at, placed[i - 2] + distances.second(row[i - 2], id));
|
|
155
|
+
placed.push(at);
|
|
156
|
+
});
|
|
157
|
+
const shift = mean(row.map((id, i) => wanted.get(id) - placed[i]));
|
|
158
|
+
row.forEach((id, i) => x.set(id, placed[i] + shift));
|
|
159
|
+
}
|
|
160
|
+
function mean(values) {
|
|
161
|
+
return values.reduce((sum, it) => sum + it, 0) / values.length;
|
|
162
|
+
}
|
|
163
|
+
// A2 before A10
|
|
164
|
+
function byNumber(a, b) {
|
|
165
|
+
return parseInt(a.substring(1)) - parseInt(b.substring(1)) || a.localeCompare(b);
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/graph/layout.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,wGAAwG;AACxG,EAAE;AACF,oHAAoH;AACpH,sHAAsH;AACtH,6BAA6B;AAgC7B,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,qDAAqD;AACrD,MAAM,OAAO,GAAG,EAAE,CAAC;AAgBnB,iDAAiD;AACjD,MAAM,UAAU,aAAa,CAAC,MAAmC,EAAE,KAAsB,EAAE,OAAO,GAAkB,EAAE;IAClH,MAAM,EAAE,OAAO,GAAG,GAAG,EAAE,eAAe,GAAG,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,MAAM,GAAG,IAAI,EAAE,WAAW,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAC/H,MAAM,IAAI,GAAG,CAAC,EAAU,EAAQ,EAAE,CAAC,KAAK,EAAE,GAA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AAE,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;AACnE,CAAC;AAED,gBAAgB;AAChB,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS;IAClC,OAAO,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ArgumentData } from '../engine.js';
|
|
2
|
+
import type { Link } from './layout.js';
|
|
3
|
+
/** The supports between the arguments of a graph: every argument from each of those it is built on */
|
|
4
|
+
export declare function supportsOf(argumentList: readonly ArgumentData[]): Link[];
|
|
5
|
+
/** The row of every argument in a layered drawing: facts on row 0, an argument one row above the highest it is built on */
|
|
6
|
+
export declare function levelsOf(argumentList: readonly ArgumentData[]): Map<string, number>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The supports between the arguments of a graph: every argument from each of those it is built on */
|
|
2
|
+
export function supportsOf(argumentList) {
|
|
3
|
+
const ids = new Set(argumentList.map(it => it.id));
|
|
4
|
+
return argumentList.flatMap(it => it.supports.filter(sub => ids.has(sub)).map(sub => ({ from: sub, to: it.id })));
|
|
5
|
+
}
|
|
6
|
+
/** The row of every argument in a layered drawing: facts on row 0, an argument one row above the highest it is built on */
|
|
7
|
+
export function levelsOf(argumentList) {
|
|
8
|
+
const supports = new Map(argumentList.map(it => [it.id, it.supports]));
|
|
9
|
+
const levels = new Map();
|
|
10
|
+
const levelOf = (id, visiting) => {
|
|
11
|
+
if (levels.has(id))
|
|
12
|
+
return levels.get(id);
|
|
13
|
+
// sub-arguments missing from the graph, or (defensively) a cycle, do not raise the level
|
|
14
|
+
if (!supports.has(id) || visiting.has(id))
|
|
15
|
+
return -1;
|
|
16
|
+
visiting.add(id);
|
|
17
|
+
const level = 1 + Math.max(-1, ...supports.get(id).map(sub => levelOf(sub, visiting)));
|
|
18
|
+
visiting.delete(id);
|
|
19
|
+
levels.set(id, level);
|
|
20
|
+
return level;
|
|
21
|
+
};
|
|
22
|
+
argumentList.forEach(it => levelOf(it.id, new Set()));
|
|
23
|
+
return levels;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=levels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"levels.js","sourceRoot":"","sources":["../../src/graph/levels.ts"],"names":[],"mappings":"AAGA,sGAAsG;AACtG,MAAM,UAAU,UAAU,CAAC,YAAqC;IAC5D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACnD,OAAO,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACtH,CAAC;AAED,2HAA2H;AAC3H,MAAM,UAAU,QAAQ,CAAC,YAAqC;IAC1D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,MAAM,OAAO,GAAG,CAAC,EAAU,EAAE,QAAqB,EAAU,EAAE;QAC1D,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO,MAAM,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;QAC3C,yFAAyF;QACzF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO,CAAC,CAAC,CAAC;QACrD,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACjB,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QACxF,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACpB,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACtB,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;IACF,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;IACtD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Core, NodeSingular } from 'cytoscape';
|
|
2
|
+
/** Where each argument is, by its name */
|
|
3
|
+
export type Positions = Readonly<Record<string, {
|
|
4
|
+
readonly x: number;
|
|
5
|
+
readonly y: number;
|
|
6
|
+
}>>;
|
|
7
|
+
/**
|
|
8
|
+
* The nodes of [cy] placed where [positions] has them (by [nameOf]), the others laid out around them by forces (all of
|
|
9
|
+
* them anew when none is known). Whether any had to be laid out.
|
|
10
|
+
*/
|
|
11
|
+
export declare function placeByName(cy: Core, nameOf: (node: NodeSingular) => string, positions: Positions | null): boolean;
|
|
12
|
+
/** Where the nodes of [cy] are, by [nameOf] */
|
|
13
|
+
export declare function positionsOf(cy: Core, nameOf: (node: NodeSingular) => string): Positions;
|
|
14
|
+
/** The edges of [cy] whose reverse is there too, as mutual attacks: they bend apart, so that both show */
|
|
15
|
+
export declare function markMutual(cy: Core): void;
|
|
16
|
+
/** The style of mutual attacks: each bends to its own side, so that they do not overlap */
|
|
17
|
+
export declare const MUTUAL_STYLE: {
|
|
18
|
+
readonly selector: 'edge.mutual';
|
|
19
|
+
readonly style: {
|
|
20
|
+
readonly 'curve-style': 'unbundled-bezier';
|
|
21
|
+
readonly 'control-point-distances': 32;
|
|
22
|
+
readonly 'control-point-weights': 0.5;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The nodes of [cy] placed where [positions] has them (by [nameOf]), the others laid out around them by forces (all of
|
|
3
|
+
* them anew when none is known). Whether any had to be laid out.
|
|
4
|
+
*/
|
|
5
|
+
export function placeByName(cy, nameOf, positions) {
|
|
6
|
+
const nodes = cy.nodes();
|
|
7
|
+
const known = nodes.filter(it => positions?.[nameOf(it)] !== undefined);
|
|
8
|
+
const unknown = nodes.not(known);
|
|
9
|
+
cy.batch(() => known.forEach(it => void it.position({ ...positions[nameOf(it)] })));
|
|
10
|
+
if (unknown.empty())
|
|
11
|
+
return false;
|
|
12
|
+
if (known.empty()) {
|
|
13
|
+
cy.layout({ name: 'cose', animate: false, randomize: true, fit: false }).run();
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
// the new ones start next to the arguments they are linked to, and only they move
|
|
17
|
+
unknown.forEach(node => {
|
|
18
|
+
const around = node.neighborhood('node').intersection(known);
|
|
19
|
+
const centre = around.nonempty() ? around.boundingBox() : known.boundingBox();
|
|
20
|
+
node.position({ x: (centre.x1 + centre.x2) / 2 + (Math.random() - 0.5) * 60, y: (centre.y1 + centre.y2) / 2 + (Math.random() - 0.5) * 60 });
|
|
21
|
+
});
|
|
22
|
+
known.lock();
|
|
23
|
+
cy.layout({ name: 'cose', animate: false, randomize: false, fit: false }).run();
|
|
24
|
+
known.unlock();
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
/** Where the nodes of [cy] are, by [nameOf] */
|
|
28
|
+
export function positionsOf(cy, nameOf) {
|
|
29
|
+
return Object.fromEntries(cy.nodes().map(it => [nameOf(it), { ...it.position() }]));
|
|
30
|
+
}
|
|
31
|
+
/** The edges of [cy] whose reverse is there too, as mutual attacks: they bend apart, so that both show */
|
|
32
|
+
export function markMutual(cy) {
|
|
33
|
+
cy.batch(() => cy.edges().forEach(edge => {
|
|
34
|
+
const reverse = cy.getElementById(`${edge.data('target')}->${edge.data('source')}`);
|
|
35
|
+
edge.toggleClass('mutual', reverse.nonempty() && !edge.hasClass('support'));
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
/** The style of mutual attacks: each bends to its own side, so that they do not overlap */
|
|
39
|
+
export const MUTUAL_STYLE = {
|
|
40
|
+
selector: 'edge.mutual',
|
|
41
|
+
style: { 'curve-style': 'unbundled-bezier', 'control-point-distances': 32, 'control-point-weights': 0.5 },
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=positions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positions.js","sourceRoot":"","sources":["../../src/graph/positions.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,EAAQ,EAAE,MAAsC,EAAE,SAA2B;IACrG,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACxE,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjC,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE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arg2pGraph, type Stages } from './components/arg2p-graph.js';
|
|
4
|
+
export { Arg2pFramework } from './components/arg2p-framework.js';
|
|
5
|
+
export { Arg2pSolutions, listItems } from './components/arg2p-solutions.js';
|
|
6
|
+
export { Arg2pEditor, rangeOf, type EditorKind } from './components/arg2p-editor.js';
|
|
7
|
+
export { Arg2pFlags, type Source } from './components/arg2p-flags.js';
|
|
8
|
+
export { arg2p, arg2pLanguage } from './editor/language.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The components of Arg2P, defined as they are imported, and what they are built on (also apart, with no component:
|
|
2
|
+
// @tuprolog/arg2p-ui/data). The engine of the browser is apart (@tuprolog/arg2p-ui/js), as it brings the solver with it.
|
|
3
|
+
export * from './data.js';
|
|
4
|
+
export { tokens, labelColor } from './theme.js';
|
|
5
|
+
export { Arg2pGraph } from './components/arg2p-graph.js';
|
|
6
|
+
export { Arg2pFramework } from './components/arg2p-framework.js';
|
|
7
|
+
export { Arg2pSolutions, listItems } from './components/arg2p-solutions.js';
|
|
8
|
+
export { Arg2pEditor, rangeOf } from './components/arg2p-editor.js';
|
|
9
|
+
export { Arg2pFlags } from './components/arg2p-flags.js';
|
|
10
|
+
export { arg2p, arg2pLanguage } from './editor/language.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,yHAAyH;AACzH,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,UAAU,EAAe,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,OAAO,EAAmB,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,UAAU,EAAe,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Engine, Run, SolveRequest, SyntaxProblem } from '../engine.js';
|
|
2
|
+
import type { Settings } from '../flags/schema.js';
|
|
3
|
+
import type { Answer, Request } from './host.js';
|
|
4
|
+
/** What [JsEngine] runs the solver on: a Worker, or anything that answers as one (a host of the same thread, for tests) */
|
|
5
|
+
export interface Channel {
|
|
6
|
+
postMessage(request: Request): void;
|
|
7
|
+
onmessage: ((event: {
|
|
8
|
+
data: Answer;
|
|
9
|
+
}) => void) | null;
|
|
10
|
+
terminate(): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The engine of the browser: the solver of @tuprolog/arg2p in a worker (see host for the messages), so that the page
|
|
14
|
+
* stays responsive while it works. Stopping an evaluation ends the worker (the only way to interrupt it) and starts a
|
|
15
|
+
* fresh one, which warms itself up in the background.
|
|
16
|
+
*/
|
|
17
|
+
export declare class JsEngine implements Engine {
|
|
18
|
+
private readonly spawn;
|
|
19
|
+
private channel;
|
|
20
|
+
private sequence;
|
|
21
|
+
private readonly pending;
|
|
22
|
+
private readonly outputs;
|
|
23
|
+
constructor(spawn?: () => Channel);
|
|
24
|
+
/** Starts the worker, and its warm-up, ahead of the first evaluation */
|
|
25
|
+
start(): void;
|
|
26
|
+
solve(request: SolveRequest, output?: (text: string) => void): Promise<Run>;
|
|
27
|
+
check(text: string, kind: 'theory' | 'query'): Promise<SyntaxProblem | null>;
|
|
28
|
+
settings(theory: string, flags: string): Promise<Settings>;
|
|
29
|
+
stop(): void;
|
|
30
|
+
private open;
|
|
31
|
+
private restart;
|
|
32
|
+
private receive;
|
|
33
|
+
private request;
|
|
34
|
+
private failAll;
|
|
35
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// The worker of this module, as bundlers (Vite, webpack) find it
|
|
2
|
+
const spawnWorker = () => new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });
|
|
3
|
+
/**
|
|
4
|
+
* The engine of the browser: the solver of @tuprolog/arg2p in a worker (see host for the messages), so that the page
|
|
5
|
+
* stays responsive while it works. Stopping an evaluation ends the worker (the only way to interrupt it) and starts a
|
|
6
|
+
* fresh one, which warms itself up in the background.
|
|
7
|
+
*/
|
|
8
|
+
export class JsEngine {
|
|
9
|
+
constructor(spawn = spawnWorker) {
|
|
10
|
+
this.spawn = spawn;
|
|
11
|
+
this.channel = null;
|
|
12
|
+
this.sequence = 0;
|
|
13
|
+
// the answers waited for, by kind and id
|
|
14
|
+
this.pending = new Map();
|
|
15
|
+
// where the output of each query goes
|
|
16
|
+
this.outputs = new Map();
|
|
17
|
+
}
|
|
18
|
+
/** Starts the worker, and its warm-up, ahead of the first evaluation */
|
|
19
|
+
start() {
|
|
20
|
+
if (this.channel === null)
|
|
21
|
+
this.open();
|
|
22
|
+
}
|
|
23
|
+
solve(request, output = () => { }) {
|
|
24
|
+
const id = ++this.sequence;
|
|
25
|
+
this.outputs.clear();
|
|
26
|
+
this.outputs.set(id, output);
|
|
27
|
+
return this.request({ type: 'solve', id, ...request }, `start:${id}`).then(started => {
|
|
28
|
+
// every query has a first answer: yes, no or an error
|
|
29
|
+
let hasNext = true;
|
|
30
|
+
return {
|
|
31
|
+
query: started.query,
|
|
32
|
+
hasNext: () => hasNext,
|
|
33
|
+
next: () => this.request({ type: 'next', id }, `next:${id}`).then(answer => {
|
|
34
|
+
const solution = answer;
|
|
35
|
+
hasNext = solution.hasNext;
|
|
36
|
+
return solution.solution;
|
|
37
|
+
}),
|
|
38
|
+
graphAt: (branch) => {
|
|
39
|
+
const reqId = ++this.sequence;
|
|
40
|
+
return this.request({ type: 'graphAt', id, branch, reqId }, `graph:${reqId}`).then(answer => answer.graph);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
check(text, kind) {
|
|
46
|
+
const reqId = ++this.sequence;
|
|
47
|
+
return this.request({ type: 'check', reqId, text, kind }, `check:${reqId}`).then(answer => answer.problem);
|
|
48
|
+
}
|
|
49
|
+
settings(theory, flags) {
|
|
50
|
+
const reqId = ++this.sequence;
|
|
51
|
+
return this.request({ type: 'settings', reqId, theory, flags }, `settings:${reqId}`).then(answer => answer.settings);
|
|
52
|
+
}
|
|
53
|
+
stop() {
|
|
54
|
+
this.failAll({ name: 'Stopped', message: 'The query was stopped.', syntax: null, stopped: true });
|
|
55
|
+
this.restart();
|
|
56
|
+
}
|
|
57
|
+
open() {
|
|
58
|
+
const channel = this.spawn();
|
|
59
|
+
channel.onmessage = event => this.receive(event.data);
|
|
60
|
+
if ('onerror' in channel) {
|
|
61
|
+
channel.onerror = event => {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
this.failAll({ name: 'Solver error', message: event.message || 'The solver stopped working.', syntax: null });
|
|
64
|
+
this.restart();
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
this.channel = channel;
|
|
68
|
+
channel.postMessage({ type: 'warmUp' });
|
|
69
|
+
}
|
|
70
|
+
restart() {
|
|
71
|
+
this.channel?.terminate();
|
|
72
|
+
this.channel = null;
|
|
73
|
+
this.open();
|
|
74
|
+
}
|
|
75
|
+
receive(answer) {
|
|
76
|
+
if (answer.type === 'output') {
|
|
77
|
+
this.outputs.get(answer.id)?.(answer.text);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const key = answer.type === 'graph' ? `graph:${answer.reqId}`
|
|
81
|
+
: answer.type === 'checked' ? `check:${answer.reqId}`
|
|
82
|
+
: answer.type === 'settings' ? `settings:${answer.reqId}`
|
|
83
|
+
: answer.type === 'solution' ? `next:${answer.id}`
|
|
84
|
+
: answer.type === 'started' ? `start:${answer.id}`
|
|
85
|
+
: answer.type === 'failed' ? [`start:${answer.id}`, `next:${answer.id}`].find(it => this.pending.has(it))
|
|
86
|
+
: undefined;
|
|
87
|
+
const waiting = key === undefined ? undefined : this.pending.get(key);
|
|
88
|
+
if (key === undefined || waiting === undefined)
|
|
89
|
+
return;
|
|
90
|
+
this.pending.delete(key);
|
|
91
|
+
if (answer.type === 'failed')
|
|
92
|
+
waiting.reject(answer.error);
|
|
93
|
+
else
|
|
94
|
+
waiting.resolve(answer);
|
|
95
|
+
}
|
|
96
|
+
request(request, key) {
|
|
97
|
+
if (this.channel === null)
|
|
98
|
+
this.open();
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
this.pending.set(key, { resolve, reject });
|
|
101
|
+
this.channel.postMessage(request);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
failAll(error) {
|
|
105
|
+
const waiting = [...this.pending.values()];
|
|
106
|
+
this.pending.clear();
|
|
107
|
+
waiting.forEach(it => it.reject(error));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/js/engine.ts"],"names":[],"mappings":"AAWA,iEAAiE;AACjE,MAAM,WAAW,GAAG,GAAY,EAAE,CAC9B,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,aAAa,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAuB,CAAC;AAElG;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IAQjB,YAA6B,KAAK,GAAkB,WAAW;QAAlC,UAAK,GAAL,KAAK,CAA6B;QAPvD,YAAO,GAAmB,IAAI,CAAC;QAC/B,aAAQ,GAAG,CAAC,CAAC;QACrB,yCAAyC;QACxB,YAAO,GAAG,IAAI,GAAG,EAA+E,CAAC;QAClH,sCAAsC;QACrB,YAAO,GAAG,IAAI,GAAG,EAAkC,CAAC;IAEH,CAAC;IAEnE,wEAAwE;IACxE,KAAK;QACD,IAAI,IAAI,CA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AAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5C,CAAC;CACJ"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type Graph } from '@tuprolog/arg2p';
|
|
2
|
+
import { type EngineError, type GraphData, type SolutionData, type SyntaxProblem } from '../engine.js';
|
|
3
|
+
import { type Settings } from '../flags/schema.js';
|
|
4
|
+
export type Request = {
|
|
5
|
+
type: 'warmUp';
|
|
6
|
+
} | {
|
|
7
|
+
type: 'solve';
|
|
8
|
+
id: number;
|
|
9
|
+
theory: string;
|
|
10
|
+
query: string;
|
|
11
|
+
flags: string;
|
|
12
|
+
} | {
|
|
13
|
+
type: 'next';
|
|
14
|
+
id: number;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'graphAt';
|
|
17
|
+
id: number;
|
|
18
|
+
branch: number;
|
|
19
|
+
reqId: number;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'check';
|
|
22
|
+
reqId: number;
|
|
23
|
+
text: string;
|
|
24
|
+
kind: 'theory' | 'query';
|
|
25
|
+
} | {
|
|
26
|
+
type: 'settings';
|
|
27
|
+
reqId: number;
|
|
28
|
+
theory: string;
|
|
29
|
+
flags: string;
|
|
30
|
+
};
|
|
31
|
+
export type Answer = {
|
|
32
|
+
type: 'warm';
|
|
33
|
+
} | {
|
|
34
|
+
type: 'started';
|
|
35
|
+
id: number;
|
|
36
|
+
query: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'failed';
|
|
39
|
+
id: number;
|
|
40
|
+
error: EngineError;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'output';
|
|
43
|
+
id: number;
|
|
44
|
+
text: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'solution';
|
|
47
|
+
id: number;
|
|
48
|
+
solution: SolutionData;
|
|
49
|
+
hasNext: boolean;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'graph';
|
|
52
|
+
reqId: number;
|
|
53
|
+
graph: GraphData;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'checked';
|
|
56
|
+
reqId: number;
|
|
57
|
+
problem: SyntaxProblem | null;
|
|
58
|
+
} | {
|
|
59
|
+
type: 'settings';
|
|
60
|
+
reqId: number;
|
|
61
|
+
settings: Settings;
|
|
62
|
+
};
|
|
63
|
+
export declare function createHost(post: (answer: Answer) => void): {
|
|
64
|
+
handle(request: Request): void;
|
|
65
|
+
};
|
|
66
|
+
/** A graph of the API as plain data, read in [profile] */
|
|
67
|
+
export declare function graphData(graph: Graph, profile?: string): GraphData;
|
|
68
|
+
/** Where [text], a theory (or flags) or a query, does not parse; null if it does */
|
|
69
|
+
export declare function check(text: string, kind: 'theory' | 'query'): SyntaxProblem | null;
|
|
70
|
+
/**
|
|
71
|
+
* The values of the flags in effect for [theory] solved with [flags], as the solver checks them (setting/1 for a
|
|
72
|
+
* switch, setting/2 for the values of a flag): the flags alone when the theory does not parse, none when they do not
|
|
73
|
+
* (until the API gives them)
|
|
74
|
+
*/
|
|
75
|
+
export declare function settings(theory: string, flags: string): Settings;
|