diffdesk 0.1.0__py3-none-any.whl
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.
- diffdesk/__init__.py +3 -0
- diffdesk/agent.py +414 -0
- diffdesk/agent_guide.md +112 -0
- diffdesk/cli.py +329 -0
- diffdesk/config.py +130 -0
- diffdesk/gitio.py +391 -0
- diffdesk/index.py +635 -0
- diffdesk/mcp.py +472 -0
- diffdesk/server.py +750 -0
- diffdesk/static/app.js +402 -0
- diffdesk/static/index.html +129 -0
- diffdesk/static/js/api.js +58 -0
- diffdesk/static/js/boot.js +12 -0
- diffdesk/static/js/diffview.js +359 -0
- diffdesk/static/js/dom.js +82 -0
- diffdesk/static/js/editor-cm.js +225 -0
- diffdesk/static/js/editor-monaco.js +116 -0
- diffdesk/static/js/flow.js +227 -0
- diffdesk/static/js/hunks.js +40 -0
- diffdesk/static/js/markdown.js +102 -0
- diffdesk/static/js/settings.js +228 -0
- diffdesk/static/js/subject.js +127 -0
- diffdesk/static/js/tree.js +492 -0
- diffdesk/static/js/treemap.js +217 -0
- diffdesk/static/style.css +508 -0
- diffdesk/static/vendor/LICENSES.txt +603 -0
- diffdesk/static/vendor/codemirror.js +24 -0
- diffdesk/static/vendor/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Main-Bold.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Main-Italic.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Main-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Math-Italic.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Script-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/OFL.txt +102 -0
- diffdesk/static/vendor/katex.css +2 -0
- diffdesk/static/vendor/katex.js +258 -0
- diffdesk/static/vendor/marked.js +72 -0
- diffdesk/subject.schema.json +59 -0
- diffdesk-0.1.0.dist-info/METADATA +520 -0
- diffdesk-0.1.0.dist-info/RECORD +59 -0
- diffdesk-0.1.0.dist-info/WHEEL +4 -0
- diffdesk-0.1.0.dist-info/entry_points.txt +2 -0
- diffdesk-0.1.0.dist-info/licenses/LICENSE +21 -0
- diffdesk-0.1.0.dist-info/licenses/src/diffdesk/static/vendor/LICENSES.txt +603 -0
- diffdesk-0.1.0.dist-info/licenses/src/diffdesk/static/vendor/fonts/OFL.txt +102 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Monaco diff editor, loaded from the CDN only when the user chooses it.
|
|
2
|
+
const MONACO_BASE = 'https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min';
|
|
3
|
+
// The server's language names are used as Monaco language IDs. Monaco has no TOML mode, and it
|
|
4
|
+
// shows an unknown ID as plain text.
|
|
5
|
+
const LANGUAGE = { toml: 'ini' };
|
|
6
|
+
const THEME = { light: 'vs', dark: 'vs-dark', contrast: 'hc-black' };
|
|
7
|
+
|
|
8
|
+
let loading = null;
|
|
9
|
+
|
|
10
|
+
/** Load Monaco from the CDN (first call only). `Editor` needs it. */
|
|
11
|
+
export function ready() {
|
|
12
|
+
if (window.monaco?.editor) return Promise.resolve(window.monaco);
|
|
13
|
+
loading ||= new Promise((resolve, reject) => {
|
|
14
|
+
const fail = () => {
|
|
15
|
+
loading = null;
|
|
16
|
+
reject(new Error('Monaco did not load from cdn.jsdelivr.net. Check the network connection, or use CodeMirror.'));
|
|
17
|
+
};
|
|
18
|
+
const script = document.createElement('script');
|
|
19
|
+
script.src = `${MONACO_BASE}/vs/loader.js`;
|
|
20
|
+
script.onerror = () => {
|
|
21
|
+
script.remove();
|
|
22
|
+
fail();
|
|
23
|
+
};
|
|
24
|
+
script.onload = () => {
|
|
25
|
+
const worker = `self.MonacoEnvironment = { baseUrl: '${MONACO_BASE}/' };`
|
|
26
|
+
+ `importScripts('${MONACO_BASE}/vs/base/worker/workerMain.js');`;
|
|
27
|
+
window.MonacoEnvironment = {
|
|
28
|
+
getWorkerUrl: () => `data:text/javascript;charset=utf-8,${encodeURIComponent(worker)}`,
|
|
29
|
+
};
|
|
30
|
+
window.require.config({ paths: { vs: `${MONACO_BASE}/vs` } });
|
|
31
|
+
window.require(['vs/editor/editor.main'], () => resolve(window.monaco), fail);
|
|
32
|
+
};
|
|
33
|
+
document.head.append(script);
|
|
34
|
+
});
|
|
35
|
+
return loading;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class Editor {
|
|
39
|
+
constructor(host, hooks) {
|
|
40
|
+
this.monaco = window.monaco;
|
|
41
|
+
this.host = host;
|
|
42
|
+
this.hooks = hooks;
|
|
43
|
+
this.editor = null;
|
|
44
|
+
this.models = null;
|
|
45
|
+
this.listener = null;
|
|
46
|
+
this.doc = null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
editorOptions(o) {
|
|
50
|
+
return {
|
|
51
|
+
renderSideBySide: o.layout !== 'inline',
|
|
52
|
+
useInlineViewWhenSpaceIsLimited: false,
|
|
53
|
+
ignoreTrimWhitespace: o.ignoreWhitespace,
|
|
54
|
+
wordWrap: o.wrap ? 'on' : 'off',
|
|
55
|
+
diffWordWrap: o.wrap ? 'on' : 'off',
|
|
56
|
+
fontFamily: o.fontFamily,
|
|
57
|
+
fontSize: o.fontSize,
|
|
58
|
+
hideUnchangedRegions: { enabled: o.collapse, contextLineCount: o.context },
|
|
59
|
+
smoothScrolling: !o.reducedMotion,
|
|
60
|
+
originalEditable: false,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
show(doc, options) {
|
|
65
|
+
const m = this.monaco;
|
|
66
|
+
this.doc = doc;
|
|
67
|
+
if (!this.editor) {
|
|
68
|
+
this.editor = m.editor.createDiffEditor(this.host, {
|
|
69
|
+
automaticLayout: true,
|
|
70
|
+
minimap: { enabled: false },
|
|
71
|
+
scrollBeyondLastLine: false,
|
|
72
|
+
theme: THEME[options.theme] || 'vs',
|
|
73
|
+
...this.editorOptions(options),
|
|
74
|
+
});
|
|
75
|
+
this.editor.getModifiedEditor().addCommand(m.KeyMod.CtrlCmd | m.KeyCode.KeyS, () => this.hooks.onSave());
|
|
76
|
+
} else {
|
|
77
|
+
this.update(options);
|
|
78
|
+
}
|
|
79
|
+
const language = LANGUAGE[doc.language] ?? doc.language ?? 'plaintext';
|
|
80
|
+
const old = this.models;
|
|
81
|
+
this.models = {
|
|
82
|
+
original: m.editor.createModel(doc.original, language),
|
|
83
|
+
modified: m.editor.createModel(doc.modified, language),
|
|
84
|
+
};
|
|
85
|
+
this.editor.setModel(this.models);
|
|
86
|
+
this.listener?.dispose();
|
|
87
|
+
this.listener = this.models.modified.onDidChangeContent(() => this.hooks.onChange());
|
|
88
|
+
const numbers = (list) => ({ lineNumbers: list ? (n) => list[n - 1] ?? '' : 'on' });
|
|
89
|
+
this.editor.getOriginalEditor().updateOptions(numbers(doc.numbersA));
|
|
90
|
+
this.editor.getModifiedEditor().updateOptions({ ...numbers(doc.numbersB), readOnly: Boolean(doc.readOnly) });
|
|
91
|
+
if (old) {
|
|
92
|
+
old.original.dispose();
|
|
93
|
+
old.modified.dispose();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
value() {
|
|
98
|
+
return this.models ? this.models.modified.getValue() : (this.doc?.modified ?? '');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
update(options) {
|
|
102
|
+
if (!this.editor) return;
|
|
103
|
+
this.editor.updateOptions(this.editorOptions(options));
|
|
104
|
+
this.monaco.editor.setTheme(THEME[options.theme] || 'vs');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
destroy() {
|
|
108
|
+
this.listener?.dispose();
|
|
109
|
+
this.editor?.dispose();
|
|
110
|
+
this.models?.original.dispose();
|
|
111
|
+
this.models?.modified.dispose();
|
|
112
|
+
this.editor = null;
|
|
113
|
+
this.models = null;
|
|
114
|
+
this.listener = null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Flow view: packages in dependency order as SVG. Dependencies are drawn above the packages
|
|
2
|
+
// that depend on them. Layered layout by longest path.
|
|
3
|
+
import { api } from './api.js';
|
|
4
|
+
import { reviewedOf, STATUS_ORDER, STATUS_LABEL } from './dom.js';
|
|
5
|
+
|
|
6
|
+
const NS = 'http://www.w3.org/2000/svg';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Layer of every node: 0 without dependencies, else 1 + the largest layer of its dependencies.
|
|
10
|
+
*
|
|
11
|
+
* A dependency that closes a cycle cannot satisfy that rule. Such edges are found by a
|
|
12
|
+
* depth-first search in input order and returned in `cut`; the layers use the other edges.
|
|
13
|
+
*
|
|
14
|
+
* @param {string[]} nodes
|
|
15
|
+
* @param {[string, string][]} deps `[node, dependency]` pairs. Self-edges are ignored.
|
|
16
|
+
* @returns {{layer: Map<string, number>, cut: [string, string][]}}
|
|
17
|
+
*/
|
|
18
|
+
export function longestPathLayers(nodes, deps) {
|
|
19
|
+
const out = new Map(nodes.map((n) => [n, []]));
|
|
20
|
+
for (const [a, b] of deps) {
|
|
21
|
+
if (a === b) continue;
|
|
22
|
+
if (!out.has(a)) out.set(a, []);
|
|
23
|
+
if (!out.has(b)) out.set(b, []);
|
|
24
|
+
out.get(a).push(b);
|
|
25
|
+
}
|
|
26
|
+
const ON_PATH = 1;
|
|
27
|
+
const DONE = 2;
|
|
28
|
+
const mark = new Map();
|
|
29
|
+
const kept = new Map([...out.keys()].map((n) => [n, []]));
|
|
30
|
+
const cut = [];
|
|
31
|
+
for (const root of out.keys()) {
|
|
32
|
+
if (mark.has(root)) continue;
|
|
33
|
+
mark.set(root, ON_PATH);
|
|
34
|
+
const stack = [[root, 0]];
|
|
35
|
+
while (stack.length) {
|
|
36
|
+
const top = stack[stack.length - 1];
|
|
37
|
+
const next = out.get(top[0])[top[1]++];
|
|
38
|
+
if (next === undefined) {
|
|
39
|
+
mark.set(top[0], DONE);
|
|
40
|
+
stack.pop();
|
|
41
|
+
} else if (mark.get(next) === ON_PATH) {
|
|
42
|
+
cut.push([top[0], next]);
|
|
43
|
+
} else {
|
|
44
|
+
kept.get(top[0]).push(next);
|
|
45
|
+
if (!mark.has(next)) {
|
|
46
|
+
mark.set(next, ON_PATH);
|
|
47
|
+
stack.push([next, 0]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const layer = new Map();
|
|
53
|
+
for (const root of kept.keys()) {
|
|
54
|
+
if (layer.has(root)) continue;
|
|
55
|
+
const stack = [[root, 0]];
|
|
56
|
+
while (stack.length) {
|
|
57
|
+
const top = stack[stack.length - 1];
|
|
58
|
+
const next = kept.get(top[0])[top[1]++];
|
|
59
|
+
if (next === undefined) {
|
|
60
|
+
stack.pop();
|
|
61
|
+
let l = 0;
|
|
62
|
+
for (const d of kept.get(top[0])) l = Math.max(l, layer.get(d) + 1);
|
|
63
|
+
layer.set(top[0], l);
|
|
64
|
+
} else if (!layer.has(next)) {
|
|
65
|
+
stack.push([next, 0]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { layer, cut };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Group nodes by layer. Inside a layer, nodes are sorted by the mean position of their
|
|
74
|
+
* dependencies in the layers above (one barycenter pass, top to bottom), then by input order.
|
|
75
|
+
*/
|
|
76
|
+
export function orderLayers(nodes, deps, layer) {
|
|
77
|
+
const rows = [];
|
|
78
|
+
for (const n of nodes) (rows[layer.get(n)] ||= []).push(n);
|
|
79
|
+
const position = new Map();
|
|
80
|
+
const depsOf = new Map(nodes.map((n) => [n, []]));
|
|
81
|
+
for (const [a, b] of deps) if (a !== b && depsOf.has(a)) depsOf.get(a).push(b);
|
|
82
|
+
rows.forEach((row, r) => {
|
|
83
|
+
if (r > 0) {
|
|
84
|
+
const key = new Map(row.map((n, i) => {
|
|
85
|
+
const p = depsOf.get(n).filter((d) => position.has(d)).map((d) => position.get(d));
|
|
86
|
+
return [n, p.length ? p.reduce((s, x) => s + x, 0) / p.length : i];
|
|
87
|
+
}));
|
|
88
|
+
row.sort((a, b) => key.get(a) - key.get(b));
|
|
89
|
+
}
|
|
90
|
+
row.forEach((n, i) => position.set(n, (i + 0.5) / row.length));
|
|
91
|
+
});
|
|
92
|
+
return rows.filter(Boolean);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function svg(tag, attrs = {}, ...children) {
|
|
96
|
+
const node = document.createElementNS(NS, tag);
|
|
97
|
+
for (const [k, v] of Object.entries(attrs)) if (v != null) node.setAttribute(k, String(v));
|
|
98
|
+
node.append(...children);
|
|
99
|
+
return node;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export class FlowView {
|
|
103
|
+
constructor(el, { onSelect }) {
|
|
104
|
+
this.el = el;
|
|
105
|
+
this.onSelect = onSelect;
|
|
106
|
+
this.selected = null;
|
|
107
|
+
this.data = null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async refresh(selected = this.selected) {
|
|
111
|
+
this.selected = selected;
|
|
112
|
+
this.data = await api.flow();
|
|
113
|
+
this.render();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
setSelected(pkg) {
|
|
117
|
+
this.selected = pkg;
|
|
118
|
+
for (const g of this.el.querySelectorAll('.node')) g.classList.toggle('selected', g.dataset.pkg === pkg);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
render() {
|
|
122
|
+
const { nodes, edges } = this.data;
|
|
123
|
+
const names = nodes.map((n) => n.package);
|
|
124
|
+
const byName = new Map(nodes.map((n) => [n.package, n]));
|
|
125
|
+
const { layer, cut } = longestPathLayers(names, edges);
|
|
126
|
+
const rows = orderLayers(names, edges, layer);
|
|
127
|
+
const cutSet = new Set(cut.map(([a, b]) => `${a}\u0001${b}`));
|
|
128
|
+
|
|
129
|
+
const fontSize = parseFloat(getComputedStyle(this.el).fontSize) || 13;
|
|
130
|
+
const padX = fontSize * 0.8;
|
|
131
|
+
const lineH = fontSize * 1.35;
|
|
132
|
+
const boxH = lineH * 2 + fontSize * 1.1;
|
|
133
|
+
const gapX = fontSize * 1.2;
|
|
134
|
+
const gapY = fontSize * 2.6;
|
|
135
|
+
|
|
136
|
+
const root = svg('svg', { role: 'img', 'aria-label': 'Packages in dependency order' });
|
|
137
|
+
root.append(svg('defs', {}, svg('marker', {
|
|
138
|
+
id: 'flow-arrow', viewBox: '0 0 10 10', refX: 10, refY: 5, markerWidth: 7, markerHeight: 7, orient: 'auto-start-reverse',
|
|
139
|
+
}, svg('path', { d: 'M0,0 L10,5 L0,10 z', class: 'arrow' }))));
|
|
140
|
+
const edgeLayer = svg('g');
|
|
141
|
+
const nodeLayer = svg('g');
|
|
142
|
+
root.append(edgeLayer, nodeLayer);
|
|
143
|
+
this.el.replaceChildren(root);
|
|
144
|
+
if (!edges.length) {
|
|
145
|
+
this.el.append(Object.assign(document.createElement('p'), {
|
|
146
|
+
className: 'view-note',
|
|
147
|
+
textContent: 'No dependencies are set. Add depends_on to the packages in diffdesk.toml.',
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Build nodes first, then measure all text in one pass, then place.
|
|
152
|
+
const groups = new Map();
|
|
153
|
+
for (const name of names) {
|
|
154
|
+
const n = byName.get(name);
|
|
155
|
+
const reviewed = reviewedOf(n);
|
|
156
|
+
const title = svg('text', { 'font-weight': 600 }, name);
|
|
157
|
+
const sub = svg('text', { class: 'sub' }, `${reviewed} of ${n.total} reviewed`);
|
|
158
|
+
const g = svg('g', {
|
|
159
|
+
class: `node${name === this.selected ? ' selected' : ''}`, tabindex: 0, role: 'button',
|
|
160
|
+
'aria-label': `${name}: ${reviewed} of ${n.total} reviewed. Show only this package in the tree.`,
|
|
161
|
+
}, svg('title', {}, `${name}\n${STATUS_ORDER.map((s) => `${STATUS_LABEL[s]}: ${n.by_status?.[s] || 0}`).join('\n')}`), title, sub);
|
|
162
|
+
g.dataset.pkg = name;
|
|
163
|
+
g.addEventListener('click', () => this.onSelect(name));
|
|
164
|
+
g.addEventListener('keydown', (e) => {
|
|
165
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
this.onSelect(name);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
nodeLayer.append(g);
|
|
171
|
+
groups.set(name, { g, title, sub, n });
|
|
172
|
+
}
|
|
173
|
+
const widths = new Map([...groups].map(([name, x]) => [name, Math.max(x.title.getComputedTextLength(), x.sub.getComputedTextLength()) + 2 * padX]));
|
|
174
|
+
const boxW = Math.max(...widths.values(), fontSize * 6);
|
|
175
|
+
|
|
176
|
+
const place = new Map();
|
|
177
|
+
let width = 0;
|
|
178
|
+
for (const row of rows) width = Math.max(width, row.length * boxW + (row.length - 1) * gapX);
|
|
179
|
+
rows.forEach((row, r) => {
|
|
180
|
+
const rowW = row.length * boxW + (row.length - 1) * gapX;
|
|
181
|
+
const x0 = (width - rowW) / 2;
|
|
182
|
+
row.forEach((name, i) => place.set(name, { x: x0 + i * (boxW + gapX), y: r * (boxH + gapY) }));
|
|
183
|
+
});
|
|
184
|
+
const height = rows.length * boxH + (rows.length - 1) * gapY;
|
|
185
|
+
const pad = 2;
|
|
186
|
+
root.setAttribute('viewBox', `${-pad} ${-pad} ${width + 2 * pad} ${height + 2 * pad}`);
|
|
187
|
+
root.setAttribute('width', '100%');
|
|
188
|
+
root.style.maxWidth = `${width + 2 * pad}px`;
|
|
189
|
+
|
|
190
|
+
for (const [name, { g, title, sub, n }] of groups) {
|
|
191
|
+
const { x, y } = place.get(name);
|
|
192
|
+
g.prepend(svg('rect', { class: 'box', x, y, width: boxW, height: boxH, rx: 5 }));
|
|
193
|
+
title.setAttribute('x', x + padX);
|
|
194
|
+
title.setAttribute('y', y + lineH);
|
|
195
|
+
sub.setAttribute('x', x + padX);
|
|
196
|
+
sub.setAttribute('y', y + 2 * lineH);
|
|
197
|
+
const barY = y + boxH - fontSize * 0.75;
|
|
198
|
+
const barW = boxW - 2 * padX;
|
|
199
|
+
let bx = x + padX;
|
|
200
|
+
for (const s of STATUS_ORDER) {
|
|
201
|
+
const count = n.by_status?.[s] || 0;
|
|
202
|
+
if (!count || !n.total) continue;
|
|
203
|
+
const w = (barW * count) / n.total;
|
|
204
|
+
g.append(svg('rect', { class: `seg-${s}`, x: bx, y: barY, width: w, height: fontSize * 0.4 }));
|
|
205
|
+
bx += w;
|
|
206
|
+
}
|
|
207
|
+
if (!n.total) g.append(svg('rect', { class: 'seg-pending', x: bx, y: barY, width: barW, height: fontSize * 0.4 }));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
for (const [from, to] of edges) {
|
|
211
|
+
if (from === to || !place.has(from) || !place.has(to)) continue;
|
|
212
|
+
// `from` depends on `to`: the arrow runs from the dependency to the package.
|
|
213
|
+
const a = place.get(to);
|
|
214
|
+
const b = place.get(from);
|
|
215
|
+
const reversed = cutSet.has(`${from}\u0001${to}`);
|
|
216
|
+
const x1 = a.x + boxW / 2;
|
|
217
|
+
const y1 = a.y + boxH;
|
|
218
|
+
const x2 = b.x + boxW / 2;
|
|
219
|
+
const y2 = b.y;
|
|
220
|
+
const dy = (y2 - y1) / 2;
|
|
221
|
+
edgeLayer.append(svg('path', {
|
|
222
|
+
class: 'edge', d: `M${x1},${y1} C${x1},${y1 + dy} ${x2},${y2 - dy} ${x2},${y2}`,
|
|
223
|
+
'marker-end': 'url(#flow-arrow)', 'stroke-dasharray': reversed ? '4 3' : null,
|
|
224
|
+
}, svg('title', {}, reversed ? `${from} depends on ${to} (this closes a cycle)` : `${from} depends on ${to}`)));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn `git diff` hunks into two read-only excerpts that a diff editor can show side by side.
|
|
3
|
+
*
|
|
4
|
+
* Each hunk starts with its `@@ -a,b +c,d @@` header on both sides, so the headers align.
|
|
5
|
+
* `numbersA[k]` / `numbersB[k]` is the real line number of excerpt line `k + 1` ('' for headers).
|
|
6
|
+
*
|
|
7
|
+
* @param {{old_start: number, old_lines: number, new_start: number, new_lines: number, lines: string[]}[]} hunks
|
|
8
|
+
*/
|
|
9
|
+
export function hunkExcerpt(hunks) {
|
|
10
|
+
const a = [];
|
|
11
|
+
const b = [];
|
|
12
|
+
const numbersA = [];
|
|
13
|
+
const numbersB = [];
|
|
14
|
+
for (const hunk of hunks) {
|
|
15
|
+
const header = `@@ -${hunk.old_start},${hunk.old_lines} +${hunk.new_start},${hunk.new_lines} @@`;
|
|
16
|
+
a.push(header);
|
|
17
|
+
b.push(header);
|
|
18
|
+
numbersA.push('');
|
|
19
|
+
numbersB.push('');
|
|
20
|
+
let lineA = hunk.old_start;
|
|
21
|
+
let lineB = hunk.new_start;
|
|
22
|
+
for (const line of hunk.lines) {
|
|
23
|
+
const kind = line[0];
|
|
24
|
+
const text = line.slice(1);
|
|
25
|
+
if (kind === ' ') {
|
|
26
|
+
a.push(text);
|
|
27
|
+
b.push(text);
|
|
28
|
+
numbersA.push(String(lineA++));
|
|
29
|
+
numbersB.push(String(lineB++));
|
|
30
|
+
} else if (kind === '-') {
|
|
31
|
+
a.push(text);
|
|
32
|
+
numbersA.push(String(lineA++));
|
|
33
|
+
} else if (kind === '+') {
|
|
34
|
+
b.push(text);
|
|
35
|
+
numbersB.push(String(lineB++));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return { original: a.join('\n'), modified: b.join('\n'), numbersA, numbersB };
|
|
40
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Markdown with $...$ and $$...$$ math. marked loads on first use, KaTeX only when math is present.
|
|
2
|
+
import { escapeHtml } from './dom.js';
|
|
3
|
+
|
|
4
|
+
let markedReady = null;
|
|
5
|
+
let katexReady = null;
|
|
6
|
+
|
|
7
|
+
function loadMarked() {
|
|
8
|
+
markedReady ||= import('../vendor/marked.js').then(({ marked }) => {
|
|
9
|
+
marked.use({
|
|
10
|
+
gfm: true,
|
|
11
|
+
renderer: {
|
|
12
|
+
// Raw HTML in the source is shown as text, never run.
|
|
13
|
+
html: (token) => escapeHtml(token.text),
|
|
14
|
+
},
|
|
15
|
+
walkTokens(token) {
|
|
16
|
+
if ((token.type === 'link' || token.type === 'image') && /^\s*(javascript|vbscript|data):/i.test(token.href)) {
|
|
17
|
+
token.href = '#';
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
return marked;
|
|
22
|
+
});
|
|
23
|
+
return markedReady;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function loadKatex() {
|
|
27
|
+
katexReady ||= new Promise((resolve, reject) => {
|
|
28
|
+
const link = document.createElement('link');
|
|
29
|
+
link.rel = 'stylesheet';
|
|
30
|
+
link.href = 'vendor/katex.css';
|
|
31
|
+
link.onload = resolve;
|
|
32
|
+
link.onerror = () => reject(new Error('Cannot load vendor/katex.css'));
|
|
33
|
+
document.head.append(link);
|
|
34
|
+
}).then(() => import('../vendor/katex.js')).then((m) => m.default);
|
|
35
|
+
return katexReady;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Inline code spans are matched first so that a `$` inside them is not math.
|
|
39
|
+
const INLINE_TOKEN = new RegExp([
|
|
40
|
+
'(`+)[\\s\\S]*?\\1(?!`)',
|
|
41
|
+
'\\\\\\$',
|
|
42
|
+
'\\$\\$[\\s\\S]+?\\$\\$',
|
|
43
|
+
'\\$(?![\\s$])(?:\\\\.|[^\\\\$\\n]|\\n(?!\\n))*?(?<![\\s\\\\])\\$(?!\\d)',
|
|
44
|
+
].join('|'), 'g');
|
|
45
|
+
|
|
46
|
+
function protectInline(text, store) {
|
|
47
|
+
return text.replace(INLINE_TOKEN, (match) => {
|
|
48
|
+
if (match[0] !== '$') return match;
|
|
49
|
+
store.push(match);
|
|
50
|
+
return `MATHPLACEHOLDER${store.length - 1}END`;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Replace math outside fenced code blocks with placeholders; push the math source to `store`. */
|
|
55
|
+
function protectMath(src, store) {
|
|
56
|
+
const out = [];
|
|
57
|
+
let buffer = [];
|
|
58
|
+
let fence = null;
|
|
59
|
+
const flush = () => {
|
|
60
|
+
if (buffer.length) out.push(protectInline(buffer.join('\n'), store));
|
|
61
|
+
buffer = [];
|
|
62
|
+
};
|
|
63
|
+
for (const line of src.split('\n')) {
|
|
64
|
+
const open = /^ {0,3}(`{3,}|~{3,})/.exec(line);
|
|
65
|
+
if (fence === null && open) {
|
|
66
|
+
flush();
|
|
67
|
+
fence = open[1];
|
|
68
|
+
out.push(line);
|
|
69
|
+
} else if (fence !== null) {
|
|
70
|
+
out.push(line);
|
|
71
|
+
const close = /^ {0,3}(`{3,}|~{3,})\s*$/.exec(line);
|
|
72
|
+
if (close && close[1][0] === fence[0] && close[1].length >= fence.length) fence = null;
|
|
73
|
+
} else {
|
|
74
|
+
buffer.push(line);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
flush();
|
|
78
|
+
return out.join('\n');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Render Markdown `src` into `target`. */
|
|
82
|
+
export async function renderMarkdown(src, target) {
|
|
83
|
+
const marked = await loadMarked();
|
|
84
|
+
const store = [];
|
|
85
|
+
const html = marked.parse(protectMath(src, store)).replace(/MATHPLACEHOLDER(\d+)END/g, (_, i) => (
|
|
86
|
+
`<span class="math-src" data-i="${i}">${escapeHtml(store[Number(i)])}</span>`
|
|
87
|
+
));
|
|
88
|
+
target.innerHTML = html;
|
|
89
|
+
if (!store.length) return;
|
|
90
|
+
let katex;
|
|
91
|
+
try {
|
|
92
|
+
katex = await loadKatex();
|
|
93
|
+
} catch {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
for (const span of target.querySelectorAll('.math-src')) {
|
|
97
|
+
const raw = store[Number(span.dataset.i)];
|
|
98
|
+
const display = raw.startsWith('$$');
|
|
99
|
+
const tex = display ? raw.slice(2, -2) : raw.slice(1, -1);
|
|
100
|
+
katex.render(tex, span, { displayMode: display, throwOnError: false });
|
|
101
|
+
}
|
|
102
|
+
}
|