@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.
Files changed (189) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -2
  3. package/assets/favicon.ico +0 -0
  4. package/assets/viewer.css +4184 -0
  5. package/dist/asset-routes.d.ts +4 -0
  6. package/dist/asset-routes.js +107 -0
  7. package/dist/blame.d.ts +8 -0
  8. package/dist/blame.js +54 -0
  9. package/dist/branch-changes.d.ts +8 -0
  10. package/dist/branch-changes.js +49 -0
  11. package/dist/candidate-lint-worker.d.ts +1 -0
  12. package/dist/candidate-lint-worker.js +67 -0
  13. package/dist/candidate-lint.d.ts +39 -0
  14. package/dist/candidate-lint.js +115 -0
  15. package/dist/change-banner.d.ts +38 -0
  16. package/dist/change-banner.js +108 -0
  17. package/dist/change-diff.d.ts +23 -0
  18. package/dist/change-diff.js +140 -0
  19. package/dist/change-marks.d.ts +32 -0
  20. package/dist/change-marks.js +363 -0
  21. package/dist/changes-article.d.ts +15 -0
  22. package/dist/changes-article.js +244 -0
  23. package/dist/changes-routes.d.ts +12 -0
  24. package/dist/changes-routes.js +271 -0
  25. package/dist/changes.d.ts +113 -0
  26. package/dist/changes.js +324 -0
  27. package/dist/cli-args.d.ts +21 -0
  28. package/dist/cli-args.js +93 -0
  29. package/dist/client/banner-height.d.ts +1 -0
  30. package/dist/client/banner-height.js +33 -0
  31. package/dist/client/change-marks.d.ts +1 -0
  32. package/dist/client/change-marks.js +56 -0
  33. package/dist/client/changes.d.ts +1 -0
  34. package/dist/client/changes.js +183 -0
  35. package/dist/client/chart-option.d.ts +3 -0
  36. package/dist/client/chart-option.js +76 -0
  37. package/dist/client/charts.d.ts +1 -0
  38. package/dist/client/charts.js +54 -0
  39. package/dist/client/clipboard.d.ts +1 -0
  40. package/dist/client/clipboard.js +43 -0
  41. package/dist/client/code-copy.d.ts +1 -0
  42. package/dist/client/code-copy.js +29 -0
  43. package/dist/client/column-resize.d.ts +1 -0
  44. package/dist/client/column-resize.js +120 -0
  45. package/dist/client/config-dom.d.ts +13 -0
  46. package/dist/client/config-dom.js +47 -0
  47. package/dist/client/config-draft.d.ts +73 -0
  48. package/dist/client/config-draft.js +218 -0
  49. package/dist/client/config-editor.d.ts +3 -0
  50. package/dist/client/config-editor.js +677 -0
  51. package/dist/client/config-fields.d.ts +35 -0
  52. package/dist/client/config-fields.js +339 -0
  53. package/dist/client/config-json.d.ts +18 -0
  54. package/dist/client/config-json.js +96 -0
  55. package/dist/client/config-preview.d.ts +9 -0
  56. package/dist/client/config-preview.js +91 -0
  57. package/dist/client/config-rules.d.ts +14 -0
  58. package/dist/client/config-rules.js +202 -0
  59. package/dist/client/config-types.d.ts +91 -0
  60. package/dist/client/config-types.js +4 -0
  61. package/dist/client/copy-path.d.ts +1 -0
  62. package/dist/client/copy-path.js +32 -0
  63. package/dist/client/dashboard-requests.d.ts +11 -0
  64. package/dist/client/dashboard-requests.js +28 -0
  65. package/dist/client/dashboard.d.ts +1 -0
  66. package/dist/client/dashboard.js +119 -0
  67. package/dist/client/diagnostics.d.ts +1 -0
  68. package/dist/client/diagnostics.js +164 -0
  69. package/dist/client/diagrams.d.ts +1 -0
  70. package/dist/client/diagrams.js +81 -0
  71. package/dist/client/diff-expand.d.ts +1 -0
  72. package/dist/client/diff-expand.js +42 -0
  73. package/dist/client/display-settings-model.d.ts +74 -0
  74. package/dist/client/display-settings-model.js +229 -0
  75. package/dist/client/display-settings.d.ts +1 -0
  76. package/dist/client/display-settings.js +411 -0
  77. package/dist/client/echarts.d.ts +30 -0
  78. package/dist/client/echarts.js +14 -0
  79. package/dist/client/graph-layout.d.ts +88 -0
  80. package/dist/client/graph-layout.js +198 -0
  81. package/dist/client/graph.d.ts +2 -0
  82. package/dist/client/graph.js +566 -0
  83. package/dist/client/history.d.ts +21 -0
  84. package/dist/client/history.js +86 -0
  85. package/dist/client/live-reload-model.d.ts +28 -0
  86. package/dist/client/live-reload-model.js +52 -0
  87. package/dist/client/live-reload.d.ts +9 -0
  88. package/dist/client/live-reload.js +138 -0
  89. package/dist/client/menu.d.ts +14 -0
  90. package/dist/client/menu.js +176 -0
  91. package/dist/client/navigation-feedback.d.ts +1 -0
  92. package/dist/client/navigation-feedback.js +141 -0
  93. package/dist/client/open-config.d.ts +1 -0
  94. package/dist/client/open-config.js +48 -0
  95. package/dist/client/outline-spy.d.ts +1 -0
  96. package/dist/client/outline-spy.js +60 -0
  97. package/dist/client/prompts.d.ts +7 -0
  98. package/dist/client/prompts.js +65 -0
  99. package/dist/client/review.d.ts +1 -0
  100. package/dist/client/review.js +379 -0
  101. package/dist/client/search.d.ts +1 -0
  102. package/dist/client/search.js +199 -0
  103. package/dist/client/segmented.d.ts +13 -0
  104. package/dist/client/segmented.js +70 -0
  105. package/dist/client/source-lines.d.ts +16 -0
  106. package/dist/client/source-lines.js +47 -0
  107. package/dist/client/theme-toggle.d.ts +10 -0
  108. package/dist/client/theme-toggle.js +100 -0
  109. package/dist/client/theme.d.ts +0 -0
  110. package/dist/client/theme.js +50 -0
  111. package/dist/client/tree-marks.d.ts +31 -0
  112. package/dist/client/tree-marks.js +102 -0
  113. package/dist/client/tree-state.d.ts +0 -0
  114. package/dist/client/tree-state.js +179 -0
  115. package/dist/client/viewer.d.ts +1 -0
  116. package/dist/client/viewer.js +53 -0
  117. package/dist/config-editor.d.ts +166 -0
  118. package/dist/config-editor.js +378 -0
  119. package/dist/config-routes.d.ts +18 -0
  120. package/dist/config-routes.js +213 -0
  121. package/dist/context-view.d.ts +41 -0
  122. package/dist/context-view.js +295 -0
  123. package/dist/corpus-routes.d.ts +31 -0
  124. package/dist/corpus-routes.js +258 -0
  125. package/dist/corpus.d.ts +134 -0
  126. package/dist/corpus.js +653 -0
  127. package/dist/dashboard-article.d.ts +14 -0
  128. package/dist/dashboard-article.js +290 -0
  129. package/dist/dashboard.d.ts +94 -0
  130. package/dist/dashboard.js +468 -0
  131. package/dist/diagnostics.d.ts +23 -0
  132. package/dist/diagnostics.js +44 -0
  133. package/dist/document-routes.d.ts +39 -0
  134. package/dist/document-routes.js +396 -0
  135. package/dist/event-hub.d.ts +39 -0
  136. package/dist/event-hub.js +120 -0
  137. package/dist/findings-panel.d.ts +4 -0
  138. package/dist/findings-panel.js +74 -0
  139. package/dist/folder-page.d.ts +8 -0
  140. package/dist/folder-page.js +74 -0
  141. package/dist/graph-view.d.ts +66 -0
  142. package/dist/graph-view.js +236 -0
  143. package/dist/highlight.d.ts +24 -0
  144. package/dist/highlight.js +100 -0
  145. package/dist/http-send.d.ts +9 -0
  146. package/dist/http-send.js +53 -0
  147. package/dist/index.d.ts +2 -0
  148. package/dist/index.js +72 -0
  149. package/dist/open-file.d.ts +36 -0
  150. package/dist/open-file.js +87 -0
  151. package/dist/page-tree.d.ts +3 -0
  152. package/dist/page-tree.js +105 -0
  153. package/dist/page.d.ts +73 -0
  154. package/dist/page.js +478 -0
  155. package/dist/prompts.d.ts +25 -0
  156. package/dist/prompts.js +82 -0
  157. package/dist/render-cache.d.ts +23 -0
  158. package/dist/render-cache.js +38 -0
  159. package/dist/render-document.d.ts +60 -0
  160. package/dist/render-document.js +440 -0
  161. package/dist/request-path.d.ts +17 -0
  162. package/dist/request-path.js +51 -0
  163. package/dist/review-context.d.ts +24 -0
  164. package/dist/review-context.js +109 -0
  165. package/dist/review-queries.d.ts +26 -0
  166. package/dist/review-queries.js +69 -0
  167. package/dist/review-state.d.ts +106 -0
  168. package/dist/review-state.js +251 -0
  169. package/dist/review-store.d.ts +145 -0
  170. package/dist/review-store.js +530 -0
  171. package/dist/router.d.ts +28 -0
  172. package/dist/router.js +294 -0
  173. package/dist/search.d.ts +22 -0
  174. package/dist/search.js +164 -0
  175. package/dist/security.d.ts +95 -0
  176. package/dist/security.js +196 -0
  177. package/dist/server.d.ts +21 -0
  178. package/dist/server.js +224 -0
  179. package/dist/speculation-rules.d.ts +4 -0
  180. package/dist/speculation-rules.js +49 -0
  181. package/dist/state-dir.d.ts +6 -0
  182. package/dist/state-dir.js +31 -0
  183. package/dist/tree-marks.d.ts +49 -0
  184. package/dist/tree-marks.js +108 -0
  185. package/dist/viewer-context.d.ts +37 -0
  186. package/dist/viewer-context.js +74 -0
  187. package/dist/watch.d.ts +41 -0
  188. package/dist/watch.js +135 -0
  189. 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
+ }
@@ -0,0 +1,2 @@
1
+ export declare function initGraph(): void;
2
+ export declare function initLocalGraph(): void;