@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,36 @@
1
+ export type OpenAction = "reveal" | "open";
2
+ /**
3
+ * Why opening a file is refused for a viewer bound to `host`, or `undefined` when it is allowed.
4
+ *
5
+ * Opening starts a program on the machine running the viewer. A reader on another machine, reaching
6
+ * a viewer bound with `--host`, would make a window appear on a desktop that is not theirs — so,
7
+ * like saving the config, it is an action for a loopback binding only.
8
+ */
9
+ export declare function openRefusal(host: string): string | undefined;
10
+ export type LaunchCommand = {
11
+ command: string;
12
+ args: string[];
13
+ windowsVerbatimArguments?: boolean;
14
+ };
15
+ /**
16
+ * The program and arguments that reveal or open `absolutePath` on `platform`, or `undefined` for a
17
+ * path that cannot be passed safely.
18
+ *
19
+ * - Windows: Explorer — `/select,` opens the folder with the file selected; a bare path opens the
20
+ * file with its associated application, as a double click would. Quoted by hand for the verbatim
21
+ * command line, which is safe because a Windows path cannot contain a double quote; one that
22
+ * somehow does is refused rather than allowed to end the quoting early.
23
+ * - macOS: `open -R` reveals in Finder, `open` uses the default application.
24
+ * - Elsewhere: `xdg-open`, the freedesktop launcher. It has no portable way to select a file in a
25
+ * file manager, so revealing opens the folder that holds it.
26
+ */
27
+ export declare function openCommand(platform: NodeJS.Platform, action: OpenAction, absolutePath: string): LaunchCommand | undefined;
28
+ /** Starts a command and resolves once it is running; rejects if it could not be started at all. */
29
+ export type Launcher = (command: LaunchCommand) => Promise<void>;
30
+ /**
31
+ * Start the program detached and stop tracking it: the file manager or editor it opens is the
32
+ * reader's to close, and the viewer must neither wait for it nor take it down when it exits. Only a
33
+ * failure to start (no such program) is reported. What the program does after that is not: Explorer
34
+ * exits with status 1 even when it succeeds, so an exit status says nothing either way.
35
+ */
36
+ export declare const launchDetached: Launcher;
@@ -0,0 +1,87 @@
1
+ import { spawn } from "node:child_process";
2
+ import path from "node:path";
3
+ import { findExecutable } from "@wastech-mdlint/core";
4
+ import { isLoopbackHost } from "./security.js";
5
+ /**
6
+ * Why opening a file is refused for a viewer bound to `host`, or `undefined` when it is allowed.
7
+ *
8
+ * Opening starts a program on the machine running the viewer. A reader on another machine, reaching
9
+ * a viewer bound with `--host`, would make a window appear on a desktop that is not theirs — so,
10
+ * like saving the config, it is an action for a loopback binding only.
11
+ */
12
+ export function openRefusal(host) {
13
+ return isLoopbackHost(host)
14
+ ? undefined
15
+ : "Opening the config is off: the viewer is reachable from other machines (--host), and would start a program on this one for them.";
16
+ }
17
+ /**
18
+ * The program and arguments that reveal or open `absolutePath` on `platform`, or `undefined` for a
19
+ * path that cannot be passed safely.
20
+ *
21
+ * - Windows: Explorer — `/select,` opens the folder with the file selected; a bare path opens the
22
+ * file with its associated application, as a double click would. Quoted by hand for the verbatim
23
+ * command line, which is safe because a Windows path cannot contain a double quote; one that
24
+ * somehow does is refused rather than allowed to end the quoting early.
25
+ * - macOS: `open -R` reveals in Finder, `open` uses the default application.
26
+ * - Elsewhere: `xdg-open`, the freedesktop launcher. It has no portable way to select a file in a
27
+ * file manager, so revealing opens the folder that holds it.
28
+ */
29
+ export function openCommand(platform, action, absolutePath) {
30
+ if (platform === "win32") {
31
+ if (absolutePath.includes('"')) {
32
+ return undefined;
33
+ }
34
+ return {
35
+ command: "explorer",
36
+ args: [
37
+ action === "reveal" ? `/select,"${absolutePath}"` : `"${absolutePath}"`,
38
+ ],
39
+ windowsVerbatimArguments: true,
40
+ };
41
+ }
42
+ if (platform === "darwin") {
43
+ return {
44
+ command: "open",
45
+ args: action === "reveal" ? ["-R", absolutePath] : [absolutePath],
46
+ };
47
+ }
48
+ return {
49
+ command: "xdg-open",
50
+ args: [
51
+ action === "reveal" ? path.posix.dirname(absolutePath) : absolutePath,
52
+ ],
53
+ };
54
+ }
55
+ /**
56
+ * Start the program detached and stop tracking it: the file manager or editor it opens is the
57
+ * reader's to close, and the viewer must neither wait for it nor take it down when it exits. Only a
58
+ * failure to start (no such program) is reported. What the program does after that is not: Explorer
59
+ * exits with status 1 even when it succeeds, so an exit status says nothing either way.
60
+ */
61
+ export const launchDetached = async (command) => {
62
+ // Never by bare name: on Windows that searches the viewer's working directory — usually the
63
+ // repository it serves — before `PATH`, so an `explorer.exe` committed to it would be what a click
64
+ // on "Show in folder" runs. An absolute `command` is the caller's own choice and is used as given.
65
+ const executable = path.isAbsolute(command.command)
66
+ ? command.command
67
+ : await findExecutable(command.command, process.env);
68
+ if (executable === undefined) {
69
+ throw new Error("the program was not found on PATH");
70
+ }
71
+ await new Promise((resolve, reject) => {
72
+ const child = spawn(executable, command.args, {
73
+ detached: true,
74
+ stdio: "ignore",
75
+ shell: false,
76
+ windowsVerbatimArguments: command.windowsVerbatimArguments,
77
+ });
78
+ // Node's own message names the absolute path it tried, which a page must not show.
79
+ child.once("error", (error) => {
80
+ reject(new Error(error.code ?? "it could not be started"));
81
+ });
82
+ child.once("spawn", () => {
83
+ child.unref();
84
+ resolve();
85
+ });
86
+ });
87
+ };
@@ -0,0 +1,3 @@
1
+ import type { Element } from "hast";
2
+ import { type TreeMarks } from "./tree-marks.js";
3
+ export declare function renderTree(paths: readonly string[], currentPath: string | undefined, marks: TreeMarks | undefined): Element;
@@ -0,0 +1,105 @@
1
+ import { h } from "hastscript";
2
+ import { compareStrings } from "@wastech-mdlint/core";
3
+ import { documentHref } from "./render-document.js";
4
+ import { changeLetter, findingsBadge, reviewDot, } from "./tree-marks.js";
5
+ export function renderTree(paths, currentPath, marks) {
6
+ const root = {
7
+ name: "",
8
+ path: "",
9
+ directories: new Map(),
10
+ files: [],
11
+ };
12
+ for (const relPath of paths) {
13
+ let directory = root;
14
+ for (const segment of relPath.split("/").slice(0, -1)) {
15
+ directory = childDirectory(directory, segment);
16
+ }
17
+ directory.files.push(relPath);
18
+ }
19
+ const changes = [...(marks?.changes?.files ?? [])];
20
+ return renderDirectory(root, {
21
+ currentPath,
22
+ marks,
23
+ findings: withFolders(Object.keys(marks?.findings ?? {})),
24
+ changed: withFolders(changes.map(([relPath]) => relPath)),
25
+ unreviewed: withFolders(changes.flatMap(([relPath, file]) => file.review === "unreviewed" || file.review === "changed"
26
+ ? [relPath]
27
+ : [])),
28
+ });
29
+ }
30
+ function childDirectory(directory, segment) {
31
+ let child = directory.directories.get(segment);
32
+ if (child === undefined) {
33
+ child = {
34
+ name: segment,
35
+ path: directory.path === "" ? segment : `${directory.path}/${segment}`,
36
+ directories: new Map(),
37
+ files: [],
38
+ };
39
+ directory.directories.set(segment, child);
40
+ }
41
+ return child;
42
+ }
43
+ // The paths and every folder that holds one of them.
44
+ function withFolders(paths) {
45
+ const all = new Set();
46
+ for (const relPath of paths) {
47
+ all.add(relPath);
48
+ const segments = relPath.split("/");
49
+ for (let end = 1; end < segments.length; end += 1) {
50
+ all.add(segments.slice(0, end).join("/"));
51
+ }
52
+ }
53
+ return all;
54
+ }
55
+ // The same attributes the page script sets when it redraws the marks.
56
+ function flagsOf(relPath, tree) {
57
+ return {
58
+ dataFindings: tree.findings.has(relPath) ? "" : undefined,
59
+ dataChanged: tree.changed.has(relPath) ? "" : undefined,
60
+ dataUnreviewed: tree.unreviewed.has(relPath) ? "" : undefined,
61
+ };
62
+ }
63
+ // Folders before files, each in code-point order, the way an editor's file tree reads. Only the
64
+ // folders on the way to the current document start open: a few hundred documents fully expanded
65
+ // bury the one being read.
66
+ function renderDirectory(directory, tree) {
67
+ const directories = [...directory.directories.values()].sort((a, b) => compareStrings(a.name, b.name));
68
+ const files = [...directory.files].sort(compareStrings);
69
+ return h("ul.tree", [
70
+ ...directories.map((child) => h("li", flagsOf(child.path, tree), [
71
+ h("details", {
72
+ open: tree.currentPath?.startsWith(`${child.path}/`) === true,
73
+ // The name the tree-state script keeps an open folder under from page to page.
74
+ dataFolder: child.path,
75
+ }, [
76
+ // Names longer than the tree is wide end in an ellipsis; the full path is the tooltip.
77
+ h("summary", { title: child.path }, [
78
+ h("span.tree-name", child.name),
79
+ ]),
80
+ renderDirectory(child, tree),
81
+ ]),
82
+ ])),
83
+ ...files.map((file) => h("li", flagsOf(file, tree), [fileLink(file, tree)])),
84
+ ]);
85
+ }
86
+ // A file's row: its name, then the branch's letter and the review dot, then its findings, in the
87
+ // order the page script puts them in when it redraws them.
88
+ function fileLink(file, tree) {
89
+ const changed = tree.marks?.changes?.files.get(file);
90
+ const findings = tree.marks?.findings;
91
+ // Own keys only: the counts are a plain object keyed by path.
92
+ const counts = findings !== undefined && Object.hasOwn(findings, file)
93
+ ? findings[file]
94
+ : undefined;
95
+ return h("a", {
96
+ href: documentHref(file),
97
+ title: file,
98
+ ariaCurrent: file === tree.currentPath ? "page" : undefined,
99
+ }, [
100
+ h("span.tree-name", file.split("/").pop() ?? file),
101
+ changed === undefined ? undefined : changeLetter(changed),
102
+ changed === undefined ? undefined : reviewDot(changed.review),
103
+ counts === undefined ? undefined : findingsBadge(counts),
104
+ ]);
105
+ }
package/dist/page.d.ts ADDED
@@ -0,0 +1,73 @@
1
+ import type { Element, ElementContent } from "hast";
2
+ import type { ParsedFrontmatter, ParsedHeading } from "@wastech-mdlint/core";
3
+ import type { BlockChange } from "./change-marks.js";
4
+ import type { SectionMark } from "./review-state.js";
5
+ import { type TreeMarks } from "./tree-marks.js";
6
+ export type PageParams = {
7
+ title: string;
8
+ siteName: string;
9
+ documentPaths: readonly string[];
10
+ displayPath?: string;
11
+ absolutePath?: string;
12
+ documentPath?: string;
13
+ article: ElementContent[];
14
+ changeBanner?: Element;
15
+ historyLine?: Element;
16
+ headings?: readonly ParsedHeading[];
17
+ changedSections?: ReadonlySet<string>;
18
+ sectionMarks?: {
19
+ path: string;
20
+ marks: ReadonlyMap<string, SectionMark>;
21
+ };
22
+ introduction?: {
23
+ changed: boolean;
24
+ };
25
+ backlinks?: readonly string[];
26
+ neighborCount?: number;
27
+ localGraphChanges?: boolean;
28
+ frontmatter?: ParsedFrontmatter | null;
29
+ frontmatterChange?: BlockChange;
30
+ query?: string;
31
+ blameToggle?: {
32
+ href: string;
33
+ on: boolean;
34
+ };
35
+ changeToken?: string;
36
+ section?: Section;
37
+ showChanges?: boolean;
38
+ showReview?: boolean;
39
+ marks?: TreeMarks;
40
+ eventSequence?: string;
41
+ findingsPanel?: Element;
42
+ firstScreen?: boolean;
43
+ scriptFirst?: boolean;
44
+ };
45
+ export type Section = "graph" | "dashboard" | "changes" | "config";
46
+ /**
47
+ * The id of the page's main column, the skip link's target and where a finding about the whole file
48
+ * jumps to.
49
+ *
50
+ * Every id the viewer gives its own elements contains a `.`: author headings get core's slugs as ids,
51
+ * verbatim so the anchors REF-002 accepts exist on the page, and a slug never contains a `.`. An id a
52
+ * heading could also have — `content` for a heading "Content" — would send that heading's outline
53
+ * entry to the first element with it, the viewer's own.
54
+ */
55
+ export declare const CONTENT_ID = "viewer.content";
56
+ /**
57
+ * The id a long page gives the first element below its first screen, so the page is drawn once
58
+ * everything above it has been read rather than all of it (`firstScreen`). The Changes page and the
59
+ * dashboard are several hundred kilobytes, most of it far below the first screen, and waiting for all
60
+ * of it held them back by a fifth of a second; what arrives after the first frame is out of sight.
61
+ */
62
+ export declare const FIRST_SCREEN_ID = "viewer.first-screen";
63
+ /** An empty element to place where a long page's first screen ends, when nothing there can carry the id. */
64
+ export declare function firstScreenMarker(): Element;
65
+ export declare function renderPage(params: PageParams): string;
66
+ /**
67
+ * The button that copies a file's path, relative or absolute, through a menu the page script adds.
68
+ * Hidden without script, which the copying needs. `absolutePath` is left off unless the viewer is
69
+ * bound to a loopback address; the menu then says why that choice is missing.
70
+ */
71
+ export declare function copyPathButton(relativePath: string, absolutePath: string | undefined): Element;
72
+ /** Article content for an already-sanitized HTML string. */
73
+ export declare function rawHtml(html: string): ElementContent[];