@wastech-mdlint/viewer 0.0.0-stage → 0.4.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/LICENSE +21 -0
- package/README.md +86 -2
- package/assets/favicon.ico +0 -0
- package/assets/viewer.css +4184 -0
- package/dist/asset-routes.d.ts +4 -0
- package/dist/asset-routes.js +107 -0
- package/dist/blame.d.ts +8 -0
- package/dist/blame.js +54 -0
- package/dist/branch-changes.d.ts +8 -0
- package/dist/branch-changes.js +49 -0
- package/dist/candidate-lint-worker.d.ts +1 -0
- package/dist/candidate-lint-worker.js +67 -0
- package/dist/candidate-lint.d.ts +39 -0
- package/dist/candidate-lint.js +115 -0
- package/dist/change-banner.d.ts +38 -0
- package/dist/change-banner.js +108 -0
- package/dist/change-diff.d.ts +23 -0
- package/dist/change-diff.js +140 -0
- package/dist/change-marks.d.ts +32 -0
- package/dist/change-marks.js +363 -0
- package/dist/changes-article.d.ts +15 -0
- package/dist/changes-article.js +244 -0
- package/dist/changes-routes.d.ts +12 -0
- package/dist/changes-routes.js +271 -0
- package/dist/changes.d.ts +113 -0
- package/dist/changes.js +324 -0
- package/dist/cli-args.d.ts +21 -0
- package/dist/cli-args.js +93 -0
- package/dist/client/banner-height.d.ts +1 -0
- package/dist/client/banner-height.js +33 -0
- package/dist/client/change-marks.d.ts +1 -0
- package/dist/client/change-marks.js +56 -0
- package/dist/client/changes.d.ts +1 -0
- package/dist/client/changes.js +183 -0
- package/dist/client/chart-option.d.ts +3 -0
- package/dist/client/chart-option.js +76 -0
- package/dist/client/charts.d.ts +1 -0
- package/dist/client/charts.js +54 -0
- package/dist/client/clipboard.d.ts +1 -0
- package/dist/client/clipboard.js +43 -0
- package/dist/client/code-copy.d.ts +1 -0
- package/dist/client/code-copy.js +29 -0
- package/dist/client/column-resize.d.ts +1 -0
- package/dist/client/column-resize.js +120 -0
- package/dist/client/config-dom.d.ts +13 -0
- package/dist/client/config-dom.js +47 -0
- package/dist/client/config-draft.d.ts +73 -0
- package/dist/client/config-draft.js +218 -0
- package/dist/client/config-editor.d.ts +3 -0
- package/dist/client/config-editor.js +677 -0
- package/dist/client/config-fields.d.ts +35 -0
- package/dist/client/config-fields.js +339 -0
- package/dist/client/config-json.d.ts +18 -0
- package/dist/client/config-json.js +96 -0
- package/dist/client/config-preview.d.ts +9 -0
- package/dist/client/config-preview.js +91 -0
- package/dist/client/config-rules.d.ts +14 -0
- package/dist/client/config-rules.js +202 -0
- package/dist/client/config-types.d.ts +91 -0
- package/dist/client/config-types.js +4 -0
- package/dist/client/copy-path.d.ts +1 -0
- package/dist/client/copy-path.js +32 -0
- package/dist/client/dashboard-requests.d.ts +11 -0
- package/dist/client/dashboard-requests.js +28 -0
- package/dist/client/dashboard.d.ts +1 -0
- package/dist/client/dashboard.js +119 -0
- package/dist/client/diagnostics.d.ts +1 -0
- package/dist/client/diagnostics.js +164 -0
- package/dist/client/diagrams.d.ts +1 -0
- package/dist/client/diagrams.js +81 -0
- package/dist/client/diff-expand.d.ts +1 -0
- package/dist/client/diff-expand.js +42 -0
- package/dist/client/display-settings-model.d.ts +74 -0
- package/dist/client/display-settings-model.js +229 -0
- package/dist/client/display-settings.d.ts +1 -0
- package/dist/client/display-settings.js +411 -0
- package/dist/client/echarts.d.ts +30 -0
- package/dist/client/echarts.js +14 -0
- package/dist/client/graph-layout.d.ts +88 -0
- package/dist/client/graph-layout.js +198 -0
- package/dist/client/graph.d.ts +2 -0
- package/dist/client/graph.js +566 -0
- package/dist/client/history.d.ts +21 -0
- package/dist/client/history.js +86 -0
- package/dist/client/live-reload-model.d.ts +28 -0
- package/dist/client/live-reload-model.js +52 -0
- package/dist/client/live-reload.d.ts +9 -0
- package/dist/client/live-reload.js +138 -0
- package/dist/client/menu.d.ts +14 -0
- package/dist/client/menu.js +176 -0
- package/dist/client/navigation-feedback.d.ts +1 -0
- package/dist/client/navigation-feedback.js +141 -0
- package/dist/client/open-config.d.ts +1 -0
- package/dist/client/open-config.js +48 -0
- package/dist/client/outline-spy.d.ts +1 -0
- package/dist/client/outline-spy.js +60 -0
- package/dist/client/prompts.d.ts +7 -0
- package/dist/client/prompts.js +65 -0
- package/dist/client/review.d.ts +1 -0
- package/dist/client/review.js +379 -0
- package/dist/client/search.d.ts +1 -0
- package/dist/client/search.js +199 -0
- package/dist/client/segmented.d.ts +13 -0
- package/dist/client/segmented.js +70 -0
- package/dist/client/source-lines.d.ts +16 -0
- package/dist/client/source-lines.js +47 -0
- package/dist/client/theme-toggle.d.ts +10 -0
- package/dist/client/theme-toggle.js +100 -0
- package/dist/client/theme.d.ts +0 -0
- package/dist/client/theme.js +50 -0
- package/dist/client/tree-marks.d.ts +31 -0
- package/dist/client/tree-marks.js +102 -0
- package/dist/client/tree-state.d.ts +0 -0
- package/dist/client/tree-state.js +179 -0
- package/dist/client/viewer.d.ts +1 -0
- package/dist/client/viewer.js +53 -0
- package/dist/config-editor.d.ts +166 -0
- package/dist/config-editor.js +378 -0
- package/dist/config-routes.d.ts +18 -0
- package/dist/config-routes.js +213 -0
- package/dist/context-view.d.ts +41 -0
- package/dist/context-view.js +295 -0
- package/dist/corpus-routes.d.ts +31 -0
- package/dist/corpus-routes.js +258 -0
- package/dist/corpus.d.ts +134 -0
- package/dist/corpus.js +653 -0
- package/dist/dashboard-article.d.ts +14 -0
- package/dist/dashboard-article.js +290 -0
- package/dist/dashboard.d.ts +94 -0
- package/dist/dashboard.js +468 -0
- package/dist/diagnostics.d.ts +23 -0
- package/dist/diagnostics.js +44 -0
- package/dist/document-routes.d.ts +39 -0
- package/dist/document-routes.js +396 -0
- package/dist/event-hub.d.ts +39 -0
- package/dist/event-hub.js +120 -0
- package/dist/findings-panel.d.ts +4 -0
- package/dist/findings-panel.js +74 -0
- package/dist/folder-page.d.ts +8 -0
- package/dist/folder-page.js +74 -0
- package/dist/graph-view.d.ts +66 -0
- package/dist/graph-view.js +236 -0
- package/dist/highlight.d.ts +24 -0
- package/dist/highlight.js +100 -0
- package/dist/http-send.d.ts +9 -0
- package/dist/http-send.js +53 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +72 -0
- package/dist/open-file.d.ts +36 -0
- package/dist/open-file.js +87 -0
- package/dist/page-tree.d.ts +3 -0
- package/dist/page-tree.js +105 -0
- package/dist/page.d.ts +73 -0
- package/dist/page.js +478 -0
- package/dist/prompts.d.ts +25 -0
- package/dist/prompts.js +82 -0
- package/dist/render-cache.d.ts +23 -0
- package/dist/render-cache.js +38 -0
- package/dist/render-document.d.ts +60 -0
- package/dist/render-document.js +440 -0
- package/dist/request-path.d.ts +17 -0
- package/dist/request-path.js +51 -0
- package/dist/review-context.d.ts +24 -0
- package/dist/review-context.js +109 -0
- package/dist/review-queries.d.ts +26 -0
- package/dist/review-queries.js +69 -0
- package/dist/review-state.d.ts +106 -0
- package/dist/review-state.js +251 -0
- package/dist/review-store.d.ts +145 -0
- package/dist/review-store.js +530 -0
- package/dist/router.d.ts +28 -0
- package/dist/router.js +294 -0
- package/dist/search.d.ts +22 -0
- package/dist/search.js +164 -0
- package/dist/security.d.ts +95 -0
- package/dist/security.js +196 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.js +224 -0
- package/dist/speculation-rules.d.ts +4 -0
- package/dist/speculation-rules.js +49 -0
- package/dist/state-dir.d.ts +6 -0
- package/dist/state-dir.js +31 -0
- package/dist/tree-marks.d.ts +49 -0
- package/dist/tree-marks.js +108 -0
- package/dist/viewer-context.d.ts +37 -0
- package/dist/viewer-context.js +74 -0
- package/dist/watch.d.ts +41 -0
- package/dist/watch.js +135 -0
- package/package.json +57 -4
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// Where the link graph's documents go: the forces ECharts' force layout is handed and the part of
|
|
2
|
+
// each node and link that steers it. Kept apart from the drawing, which needs the page, so the layout
|
|
3
|
+
// can be run to rest outside a browser and checked there.
|
|
4
|
+
// The page graph's label size; its labels shrink from it as the reader zooms out.
|
|
5
|
+
export const LABEL_FONT_SIZE = 11;
|
|
6
|
+
// Room above the page graph for the legend.
|
|
7
|
+
const LEGEND_HEIGHT = 40;
|
|
8
|
+
// Nodes are laid out this many average node widths apart. Measured on the six hundred documents of a
|
|
9
|
+
// real repository, running ECharts' layout to rest: at the spacing that merely fits the box, nine
|
|
10
|
+
// documents in ten touched a neighbor; at four widths, with every node repelling alike and links one
|
|
11
|
+
// to two spacings long, one in thirty did, mostly the large, much-linked ones. At six widths, with
|
|
12
|
+
// the repulsion and link lengths `layoutFor` derives from each document's size, none touch and one
|
|
13
|
+
// in thirty comes within half their widths again of another.
|
|
14
|
+
const SPACING_IN_NODE_WIDTHS = 6;
|
|
15
|
+
// The empty space a link leaves between the edges of the two documents it joins.
|
|
16
|
+
const LINK_GAP_IN_SPACINGS = 1;
|
|
17
|
+
// The local graph's neighbors sit on a ring this fraction of the box from the pinned document, or on
|
|
18
|
+
// a wider one the graph starts zoomed out of when that many neighbors would not fit round it this
|
|
19
|
+
// many average node widths apart. Less than the page graph's spacing: a ring has no crowded middle
|
|
20
|
+
// to keep documents out of, only room for each neighbor and the line of its name, and at the page
|
|
21
|
+
// graph's spacing a document with a dozen neighbors would already open zoomed out, every node small.
|
|
22
|
+
const LOCAL_RING = 0.4;
|
|
23
|
+
const LOCAL_ARC_IN_NODE_WIDTHS = 3;
|
|
24
|
+
// Fixed forces suit one size of graph only: tuned for six hundred documents, a ten-document folder
|
|
25
|
+
// huddles in the middle; tuned for ten, six hundred pile on one another. Measured on ECharts' layout,
|
|
26
|
+
// n nodes under gravity g and repulsion r settle into a square about 2.7·√(n·r/g) pixels wide, so r is
|
|
27
|
+
// solved for the square the layout needs: the box when the documents fit in it at their spacing, or
|
|
28
|
+
// a larger square that the graph then starts zoomed out of, so the whole graph shows and nothing
|
|
29
|
+
// overlaps. Nodes scale with the zoom, so the gaps between them stay as wide as the layout made them.
|
|
30
|
+
//
|
|
31
|
+
// One repulsion for every node would give a hub the same room as a leaf, though it is several times
|
|
32
|
+
// as wide and every one of its links pulls it toward the crowded middle; that is where documents
|
|
33
|
+
// still landed on each other. So each node repels in proportion to its area — scaled so the mean
|
|
34
|
+
// stays the repulsion solved for above — and a link is as long as the gap the layout keeps plus the
|
|
35
|
+
// radii of the two documents it joins, so two linked hubs end the same gap apart as two leaves.
|
|
36
|
+
//
|
|
37
|
+
// A local graph is a ring of neighbors around the pinned document instead, every link that shapes it
|
|
38
|
+
// the ring's radius long. ECharts moves a node by each other node's repulsion divided by their
|
|
39
|
+
// distance, and on a ring of n neighbors those pushes add up to (n + 1)·r / R straight outward —
|
|
40
|
+
// one r / R from each other neighbor, two from the pinned document — against gravity's g·R inward.
|
|
41
|
+
// So r = g·R² / (n + 1) is the one repulsion that holds the ring at its radius with no help from the
|
|
42
|
+
// links, and it then spreads the neighbors evenly round it. Measured on a fourteen-neighbor document:
|
|
43
|
+
// with the page graph's repulsion and every link pulling, they settled from 27 to 76 pixels out with
|
|
44
|
+
// gaps between them from 6 to 63 degrees; with these, all at the radius and every gap 26 degrees.
|
|
45
|
+
export function layoutFor(view, canvas, kind) {
|
|
46
|
+
const top = kind === "page" ? LEGEND_HEIGHT : 0;
|
|
47
|
+
const nodeScale = kind === "page" ? 1 : 0.75;
|
|
48
|
+
const box = 0.85 * Math.min(canvas.width, canvas.height - top);
|
|
49
|
+
const count = Math.max(view.nodes.length, 1);
|
|
50
|
+
const sizes = view.nodes.map((node) => drawnSize(node, view.focus, nodeScale));
|
|
51
|
+
const meanSize = sizes.reduce((sum, size) => sum + size, 0) / count;
|
|
52
|
+
// An empty view has no sizes; the one keeps the repulsion a number.
|
|
53
|
+
const meanArea = sizes.reduce((sum, size) => sum + size ** 2, 0) / count || 1;
|
|
54
|
+
const [smallest, largest] = extent(sizes);
|
|
55
|
+
const spacing = SPACING_IN_NODE_WIDTHS * meanSize;
|
|
56
|
+
const side = Math.max(box, spacing * Math.sqrt(count));
|
|
57
|
+
const gravity = 0.2;
|
|
58
|
+
const gap = LINK_GAP_IN_SPACINGS * spacing;
|
|
59
|
+
const neighbors = Math.max(count - 1, 1);
|
|
60
|
+
const ring = Math.max(LOCAL_RING * box, (neighbors * LOCAL_ARC_IN_NODE_WIDTHS * meanSize) / (2 * Math.PI));
|
|
61
|
+
const repulsion = kind === "page"
|
|
62
|
+
? gravity * (side / (2.7 * Math.sqrt(count))) ** 2
|
|
63
|
+
: (gravity * ring ** 2) / (neighbors + 1);
|
|
64
|
+
// On the ring every node must push alike for the balance above to hold; the pinned document's
|
|
65
|
+
// larger area would only push its neighbors out past the radius.
|
|
66
|
+
const [weakest, strongest] = kind === "page"
|
|
67
|
+
? [
|
|
68
|
+
(repulsion * smallest ** 2) / meanArea,
|
|
69
|
+
(repulsion * largest ** 2) / meanArea,
|
|
70
|
+
]
|
|
71
|
+
: [repulsion, repulsion];
|
|
72
|
+
const zoom = kind === "page" ? box / side : (LOCAL_RING * box) / ring;
|
|
73
|
+
const sizeOf = new Map(view.nodes.map((node, index) => [node.path, sizes[index] ?? 0]));
|
|
74
|
+
const [shortestLink, longestLink] = extent(view.edges.map((edge) => linkLength({ kind, gap, ring }, sizeOf.get(edge.from) ?? 0, sizeOf.get(edge.to) ?? 0)));
|
|
75
|
+
return {
|
|
76
|
+
kind,
|
|
77
|
+
nodeScale,
|
|
78
|
+
fontSize: kind === "page" ? LABEL_FONT_SIZE : 10,
|
|
79
|
+
top,
|
|
80
|
+
width: canvas.width,
|
|
81
|
+
height: canvas.height,
|
|
82
|
+
spacing,
|
|
83
|
+
gap,
|
|
84
|
+
ring,
|
|
85
|
+
force: {
|
|
86
|
+
gravity,
|
|
87
|
+
repulsion: [weakest, strongest],
|
|
88
|
+
// A link's `value` is its length, and ECharts maps the smallest value in the view onto the
|
|
89
|
+
// range's second end and the largest onto its first, linearly between them — so this range,
|
|
90
|
+
// written longest first, hands every link back exactly the length it asked for.
|
|
91
|
+
edgeLength: [longestLink, shortestLink],
|
|
92
|
+
},
|
|
93
|
+
zoom,
|
|
94
|
+
minZoom: zoom / 2,
|
|
95
|
+
maxZoom: 6,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Whether a link is the focused document's own: the graph lights those, and the local graph is laid
|
|
100
|
+
* out by them alone.
|
|
101
|
+
*/
|
|
102
|
+
export function isOwnLink(edge, focus) {
|
|
103
|
+
return focus !== null && (edge.from === focus.path || edge.to === focus.path);
|
|
104
|
+
}
|
|
105
|
+
// The most documents a local graph is laid out at once rather than step by step. ECharts runs about
|
|
106
|
+
// five hundred steps, each weighing every document against every other: for a few dozen that is a
|
|
107
|
+
// few milliseconds before the first frame, while a hub with hundreds of neighbors would hold the page
|
|
108
|
+
// up for a noticeable moment, and is drawn settling instead.
|
|
109
|
+
const LOCAL_LAID_OUT_AT_ONCE = 120;
|
|
110
|
+
/** Whether ECharts lays the graph out before drawing it, rather than drawing it as it settles. */
|
|
111
|
+
export function laidOutAtOnce(view, kind) {
|
|
112
|
+
return kind === "local" && view.nodes.length <= LOCAL_LAID_OUT_AT_ONCE;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Everything in the graph series that steers the layout, with nodes and links in the view's order. A
|
|
116
|
+
* node's value is its area, which ECharts maps onto the repulsion range, so a wide document keeps a
|
|
117
|
+
* wide berth; a link's value is the length the layout gives it. In the local graph a link between
|
|
118
|
+
* two neighbors is drawn but does not pull: it would drag the two off the ring toward each other,
|
|
119
|
+
* and a neighborhood whose neighbors link to one another then folds into a knot beside the pinned
|
|
120
|
+
* document.
|
|
121
|
+
*/
|
|
122
|
+
export function forceSeries(view, layout) {
|
|
123
|
+
const focus = view.focus;
|
|
124
|
+
const size = new Map(view.nodes.map((node) => [
|
|
125
|
+
node.path,
|
|
126
|
+
drawnSize(node, focus, layout.nodeScale),
|
|
127
|
+
]));
|
|
128
|
+
// The focused document is pinned in the middle, so its neighbors gather where the reader is
|
|
129
|
+
// looking; left to the layout it lands anywhere, often at an edge.
|
|
130
|
+
const middle = {
|
|
131
|
+
x: layout.width / 2,
|
|
132
|
+
y: layout.top + (layout.height - layout.top) / 2,
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
// The layout works in the box's own pixels only while the series fills the box below `top`;
|
|
136
|
+
// ECharts' default height is four fifths of it, which left the pinned document a tenth of the
|
|
137
|
+
// box above the middle and the bottom fifth always empty.
|
|
138
|
+
top: layout.top,
|
|
139
|
+
bottom: 0,
|
|
140
|
+
// The local graph is drawn where it comes to rest. Laid out step by step, its neighbors drifted
|
|
141
|
+
// onto their ring for the first seconds of every document page, still moving after the page had
|
|
142
|
+
// settled; the page graph is opened on purpose, and settling is part of reading it.
|
|
143
|
+
force: {
|
|
144
|
+
...layout.force,
|
|
145
|
+
friction: layout.friction,
|
|
146
|
+
layoutAnimation: !laidOutAtOnce(view, layout.kind),
|
|
147
|
+
},
|
|
148
|
+
data: view.nodes.map((node) => {
|
|
149
|
+
const symbolSize = size.get(node.path) ?? 0;
|
|
150
|
+
return {
|
|
151
|
+
id: node.path,
|
|
152
|
+
symbolSize,
|
|
153
|
+
value: symbolSize ** 2,
|
|
154
|
+
...(node.path === focus?.path ? { fixed: true, ...middle } : {}),
|
|
155
|
+
};
|
|
156
|
+
}),
|
|
157
|
+
links: view.edges.map((edge) => ({
|
|
158
|
+
source: edge.from,
|
|
159
|
+
target: edge.to,
|
|
160
|
+
value: linkLength(layout, size.get(edge.from) ?? 0, size.get(edge.to) ?? 0),
|
|
161
|
+
// A link the branch removed is drawn for the reader but is no link any more, so it must not
|
|
162
|
+
// pull its documents together and make the picture differ from the one without changes.
|
|
163
|
+
...((layout.kind === "local" && !isOwnLink(edge, focus)) ||
|
|
164
|
+
edge.change === "removed"
|
|
165
|
+
? { ignoreForceLayout: true }
|
|
166
|
+
: {}),
|
|
167
|
+
})),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// By area rather than radius, so a document with four times the inbound links looks twice as wide
|
|
171
|
+
// rather than four times; a few hubs would otherwise cover the rest.
|
|
172
|
+
function nodeSize(node) {
|
|
173
|
+
return Math.min(24, 5 + 2.2 * Math.sqrt(node.inDegree));
|
|
174
|
+
}
|
|
175
|
+
// The width a document is drawn at, which is also what the layout gives room to: the focused one is
|
|
176
|
+
// drawn large whatever its links.
|
|
177
|
+
function drawnSize(node, focus, nodeScale) {
|
|
178
|
+
return (node.path === focus?.path ? 26 : nodeSize(node)) * nodeScale;
|
|
179
|
+
}
|
|
180
|
+
// How long the layout makes a link between documents drawn at these two sizes. In the local graph
|
|
181
|
+
// the links that count are the pinned document's own, each a spoke of the ring; the others do not
|
|
182
|
+
// pull at all, so their length is never used.
|
|
183
|
+
function linkLength(layout, size, otherSize) {
|
|
184
|
+
return layout.kind === "local"
|
|
185
|
+
? layout.ring
|
|
186
|
+
: layout.gap + (size + otherSize) / 2;
|
|
187
|
+
}
|
|
188
|
+
// The smallest and largest of a list, without spreading it into `Math.min`, which runs out of stack
|
|
189
|
+
// on a large enough repository's links.
|
|
190
|
+
function extent(values) {
|
|
191
|
+
let low = Infinity;
|
|
192
|
+
let high = -Infinity;
|
|
193
|
+
for (const value of values) {
|
|
194
|
+
low = Math.min(low, value);
|
|
195
|
+
high = Math.max(high, value);
|
|
196
|
+
}
|
|
197
|
+
return values.length === 0 ? [0, 0] : [low, high];
|
|
198
|
+
}
|