@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,411 @@
|
|
|
1
|
+
import { ACCENTS, DEFAULT_SETTINGS, accentColor, NUMBER_RANGES, STORAGE_KEY, VARIABLE_NAME, changedVariables, parseSettings, storedDisplay, } from "./display-settings-model.js";
|
|
2
|
+
import { segmentedControl } from "./segmented.js";
|
|
3
|
+
export function initDisplaySettings() {
|
|
4
|
+
const button = document.querySelector(".settings-toggle");
|
|
5
|
+
if (button === null) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
// Rendered hidden by the server: without this script the button could do nothing.
|
|
9
|
+
button.hidden = false;
|
|
10
|
+
let settings = readStored();
|
|
11
|
+
const panel = buildPanel();
|
|
12
|
+
document.body.append(panel.element);
|
|
13
|
+
button.setAttribute("aria-controls", panel.element.id);
|
|
14
|
+
button.setAttribute("aria-expanded", "false");
|
|
15
|
+
const isOpen = () => panel.element.classList.contains("is-open");
|
|
16
|
+
const open = () => {
|
|
17
|
+
panel.render(settings);
|
|
18
|
+
panel.element.classList.add("is-open");
|
|
19
|
+
panel.element.removeAttribute("inert");
|
|
20
|
+
button.setAttribute("aria-expanded", "true");
|
|
21
|
+
panel.focusFirst();
|
|
22
|
+
};
|
|
23
|
+
const close = (returnFocus) => {
|
|
24
|
+
if (!isOpen()) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
panel.element.classList.remove("is-open");
|
|
28
|
+
// Out of the tab order and the accessibility tree while it is off screen.
|
|
29
|
+
panel.element.setAttribute("inert", "");
|
|
30
|
+
button.setAttribute("aria-expanded", "false");
|
|
31
|
+
if (returnFocus) {
|
|
32
|
+
button.focus();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
button.addEventListener("click", () => {
|
|
36
|
+
if (isOpen()) {
|
|
37
|
+
close(true);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
open();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
panel.closeButton.addEventListener("click", () => {
|
|
44
|
+
close(true);
|
|
45
|
+
});
|
|
46
|
+
document.addEventListener("keydown", (event) => {
|
|
47
|
+
if (event.key === "Escape" && isOpen()) {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
close(true);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
// A click anywhere else puts the panel away, as a menu would; the article stays readable beside it
|
|
53
|
+
// until then, so a change can be judged on the text it changes.
|
|
54
|
+
document.addEventListener("pointerdown", (event) => {
|
|
55
|
+
const target = event.target;
|
|
56
|
+
if (isOpen() &&
|
|
57
|
+
target !== null &&
|
|
58
|
+
!panel.element.contains(target) &&
|
|
59
|
+
!button.contains(target)) {
|
|
60
|
+
close(false);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
panel.onChange((next) => {
|
|
64
|
+
settings = next;
|
|
65
|
+
apply(settings);
|
|
66
|
+
writeStored(settings);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Set exactly the properties the settings change, and clear every other one. */
|
|
70
|
+
function apply(settings) {
|
|
71
|
+
const style = document.documentElement.style;
|
|
72
|
+
for (const name of [...style]) {
|
|
73
|
+
if (VARIABLE_NAME.test(name)) {
|
|
74
|
+
style.removeProperty(name);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const [name, value] of Object.entries(changedVariables(settings))) {
|
|
78
|
+
style.setProperty(name, value);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Storage can be unavailable (private windows, blocked site data); the settings then hold for this
|
|
82
|
+
// page only, and the next one opens with the defaults.
|
|
83
|
+
function readStored() {
|
|
84
|
+
try {
|
|
85
|
+
const raw = localStorage.getItem(STORAGE_KEY);
|
|
86
|
+
return parseSettings(raw === null
|
|
87
|
+
? undefined
|
|
88
|
+
: JSON.parse(raw).settings);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return { ...DEFAULT_SETTINGS };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function writeStored(settings) {
|
|
95
|
+
try {
|
|
96
|
+
if (Object.keys(changedVariables(settings)).length === 0) {
|
|
97
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(storedDisplay(settings)));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Applied to this page, not remembered.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function buildPanel() {
|
|
108
|
+
const element = document.createElement("aside");
|
|
109
|
+
element.className = "settings-panel";
|
|
110
|
+
element.id = "display-settings";
|
|
111
|
+
element.setAttribute("aria-label", "Display settings");
|
|
112
|
+
element.setAttribute("inert", "");
|
|
113
|
+
const { head, closeButton } = panelHead();
|
|
114
|
+
const form = document.createElement("form");
|
|
115
|
+
form.className = "settings-form";
|
|
116
|
+
// Nothing is submitted: every control applies itself.
|
|
117
|
+
form.addEventListener("submit", (event) => {
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
});
|
|
120
|
+
const controls = new PanelControls();
|
|
121
|
+
form.append(...panelSections(controls));
|
|
122
|
+
element.append(head, form);
|
|
123
|
+
return {
|
|
124
|
+
element,
|
|
125
|
+
closeButton,
|
|
126
|
+
render(settings) {
|
|
127
|
+
controls.render(settings);
|
|
128
|
+
},
|
|
129
|
+
focusFirst() {
|
|
130
|
+
form.querySelector("select, input")?.focus();
|
|
131
|
+
},
|
|
132
|
+
onChange(listener) {
|
|
133
|
+
controls.listeners.push(listener);
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function panelHead() {
|
|
138
|
+
const head = document.createElement("div");
|
|
139
|
+
head.className = "settings-head";
|
|
140
|
+
const title = document.createElement("h2");
|
|
141
|
+
title.textContent = "Display";
|
|
142
|
+
const closeButton = document.createElement("button");
|
|
143
|
+
closeButton.type = "button";
|
|
144
|
+
closeButton.className = "settings-close";
|
|
145
|
+
// An × drawn as two strokes rather than the character, which sits off center in most fonts.
|
|
146
|
+
const cross = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
147
|
+
cross.setAttribute("viewBox", "0 0 16 16");
|
|
148
|
+
cross.setAttribute("width", "12");
|
|
149
|
+
cross.setAttribute("height", "12");
|
|
150
|
+
cross.setAttribute("aria-hidden", "true");
|
|
151
|
+
const strokes = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
152
|
+
strokes.setAttribute("d", "M3.5 3.5l9 9M12.5 3.5l-9 9");
|
|
153
|
+
strokes.setAttribute("stroke", "currentColor");
|
|
154
|
+
strokes.setAttribute("stroke-width", "2");
|
|
155
|
+
strokes.setAttribute("stroke-linecap", "round");
|
|
156
|
+
cross.append(strokes);
|
|
157
|
+
closeButton.append(cross);
|
|
158
|
+
closeButton.setAttribute("aria-label", "Close display settings");
|
|
159
|
+
head.append(title, closeButton);
|
|
160
|
+
return { head, closeButton };
|
|
161
|
+
}
|
|
162
|
+
// The panel's groups, in the order they are shown. The text-width slider and the margins are built
|
|
163
|
+
// first, as their own variables, because the slider gets a second renderer and the margins a class.
|
|
164
|
+
function panelSections(controls) {
|
|
165
|
+
const width = controls.range("textWidth", "Text width", "px");
|
|
166
|
+
controls.renderers.push(() => {
|
|
167
|
+
const slider = width.querySelector("input");
|
|
168
|
+
if (slider !== null) {
|
|
169
|
+
// A fixed width means nothing while the article fills the column.
|
|
170
|
+
slider.disabled = controls.current.fullWidth;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const margins = group("Margins", [
|
|
174
|
+
controls.number("paddingTop", "Top"),
|
|
175
|
+
controls.number("paddingRight", "Right"),
|
|
176
|
+
controls.number("paddingBottom", "Bottom"),
|
|
177
|
+
controls.number("paddingLeft", "Left"),
|
|
178
|
+
]);
|
|
179
|
+
margins.classList.add("settings-margins");
|
|
180
|
+
const reset = document.createElement("button");
|
|
181
|
+
reset.type = "button";
|
|
182
|
+
reset.className = "settings-reset";
|
|
183
|
+
reset.textContent = "Reset to defaults";
|
|
184
|
+
reset.addEventListener("click", () => {
|
|
185
|
+
controls.change({ ...DEFAULT_SETTINGS });
|
|
186
|
+
});
|
|
187
|
+
return [
|
|
188
|
+
group("Whole site", [
|
|
189
|
+
controls.accent("Accent color"),
|
|
190
|
+
controls.select("siteFont", "Font", [
|
|
191
|
+
["system", "System"],
|
|
192
|
+
["serif", "Serif"],
|
|
193
|
+
["wide", "Wide sans"],
|
|
194
|
+
["mono", "Monospace"],
|
|
195
|
+
["custom", "Other…"],
|
|
196
|
+
]),
|
|
197
|
+
controls.fontName("customSiteFont", "siteFont", "Font name"),
|
|
198
|
+
controls.select("siteCodeFont", "Monospace font", [
|
|
199
|
+
["system", "System monospace"],
|
|
200
|
+
["custom", "Other…"],
|
|
201
|
+
]),
|
|
202
|
+
controls.fontName("customSiteCodeFont", "siteCodeFont", "Font name"),
|
|
203
|
+
]),
|
|
204
|
+
group("Text", [
|
|
205
|
+
controls.select("textFont", "Font", [
|
|
206
|
+
["system", "Same as the site"],
|
|
207
|
+
["serif", "Serif"],
|
|
208
|
+
["wide", "Wide sans"],
|
|
209
|
+
["mono", "Monospace"],
|
|
210
|
+
["custom", "Other…"],
|
|
211
|
+
]),
|
|
212
|
+
controls.fontName("customTextFont", "textFont", "Font name"),
|
|
213
|
+
controls.range("fontSize", "Size", "px"),
|
|
214
|
+
controls.range("lineHeight", "Line height", "×"),
|
|
215
|
+
controls.range("letterSpacing", "Letter spacing", "em"),
|
|
216
|
+
controls.range("blockSpacing", "Space between blocks", "em"),
|
|
217
|
+
controls.segmented("align", "Alignment", [
|
|
218
|
+
["start", "Left"],
|
|
219
|
+
["justify", "Justified"],
|
|
220
|
+
]),
|
|
221
|
+
]),
|
|
222
|
+
group("Layout", [
|
|
223
|
+
width,
|
|
224
|
+
controls.checkbox("fullWidth", "Fill the column"),
|
|
225
|
+
controls.checkbox("sourceLines", "Source line numbers"),
|
|
226
|
+
]),
|
|
227
|
+
margins,
|
|
228
|
+
group("Code", [
|
|
229
|
+
controls.select("codeFont", "Font", [
|
|
230
|
+
["system", "Same as the site"],
|
|
231
|
+
["custom", "Other…"],
|
|
232
|
+
]),
|
|
233
|
+
controls.fontName("customCodeFont", "codeFont", "Font name"),
|
|
234
|
+
controls.range("codeScale", "Size", "×"),
|
|
235
|
+
]),
|
|
236
|
+
reset,
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The panel's controls and the settings they show. Each control reads its value out of `current`
|
|
241
|
+
* when drawn and writes it back on input; every change redraws all of them, since one setting can
|
|
242
|
+
* hide or disable another's control.
|
|
243
|
+
*/
|
|
244
|
+
class PanelControls {
|
|
245
|
+
current = { ...DEFAULT_SETTINGS };
|
|
246
|
+
renderers = [];
|
|
247
|
+
listeners = [];
|
|
248
|
+
render(settings) {
|
|
249
|
+
this.current = settings;
|
|
250
|
+
for (const render of this.renderers) {
|
|
251
|
+
render();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
change(patch) {
|
|
255
|
+
this.render(parseSettings({ ...this.current, ...patch }));
|
|
256
|
+
for (const listener of this.listeners) {
|
|
257
|
+
listener(this.current);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
select(key, label, options) {
|
|
261
|
+
const control = document.createElement("select");
|
|
262
|
+
for (const [value, text] of options) {
|
|
263
|
+
control.append(new Option(text, value));
|
|
264
|
+
}
|
|
265
|
+
control.addEventListener("change", () => {
|
|
266
|
+
this.change({ [key]: control.value });
|
|
267
|
+
});
|
|
268
|
+
this.renderers.push(() => (control.value = this.current[key]));
|
|
269
|
+
return field(label, control, "select");
|
|
270
|
+
}
|
|
271
|
+
// A choice of two or three short words, shown all at once rather than behind a select.
|
|
272
|
+
segmented(key, label, options) {
|
|
273
|
+
const control = segmentedControl(label, options, (value) => {
|
|
274
|
+
this.change({ [key]: value });
|
|
275
|
+
});
|
|
276
|
+
this.renderers.push(() => {
|
|
277
|
+
control.render(this.current[key]);
|
|
278
|
+
});
|
|
279
|
+
const row = document.createElement("div");
|
|
280
|
+
row.className = "settings-field is-segmented";
|
|
281
|
+
const text = document.createElement("span");
|
|
282
|
+
text.className = "settings-label";
|
|
283
|
+
text.textContent = label;
|
|
284
|
+
row.append(text, control.element);
|
|
285
|
+
return row;
|
|
286
|
+
}
|
|
287
|
+
// The accent as a row of color dots: a color is chosen by seeing it, which a list of names would
|
|
288
|
+
// not let the reader do. Still a radio group to the keyboard and a screen reader, each dot named
|
|
289
|
+
// by its caption, since a dot alone says nothing to someone who cannot see it.
|
|
290
|
+
accent(label) {
|
|
291
|
+
const control = segmentedControl(label, ACCENTS.map(([value, caption]) => [value, caption]), (value) => {
|
|
292
|
+
this.change({ accent: value });
|
|
293
|
+
}, "accent-swatches");
|
|
294
|
+
control.element.querySelectorAll("button").forEach((button, at) => {
|
|
295
|
+
const [value, caption] = ACCENTS[at];
|
|
296
|
+
button.className = "accent-swatch";
|
|
297
|
+
button.textContent = "";
|
|
298
|
+
button.title = caption;
|
|
299
|
+
button.setAttribute("aria-label", caption);
|
|
300
|
+
button.style.setProperty("--swatch", accentColor(value));
|
|
301
|
+
});
|
|
302
|
+
this.renderers.push(() => {
|
|
303
|
+
control.render(this.current.accent);
|
|
304
|
+
});
|
|
305
|
+
const row = document.createElement("div");
|
|
306
|
+
row.className = "settings-field is-swatches";
|
|
307
|
+
const text = document.createElement("span");
|
|
308
|
+
text.className = "settings-label";
|
|
309
|
+
text.textContent = label;
|
|
310
|
+
row.append(text, control.element);
|
|
311
|
+
return row;
|
|
312
|
+
}
|
|
313
|
+
fontName(key, chooser, label) {
|
|
314
|
+
const control = document.createElement("input");
|
|
315
|
+
control.type = "text";
|
|
316
|
+
control.placeholder = "An installed font, e.g. Inter";
|
|
317
|
+
control.spellcheck = false;
|
|
318
|
+
control.autocomplete = "off";
|
|
319
|
+
// Applied as typed, but the typed text is left alone while the field has focus: rewriting it
|
|
320
|
+
// with the cleaned name would move the caret under the reader's fingers.
|
|
321
|
+
control.addEventListener("input", () => {
|
|
322
|
+
this.change({ [key]: control.value });
|
|
323
|
+
});
|
|
324
|
+
const row = field(label, control, "text");
|
|
325
|
+
this.renderers.push(() => {
|
|
326
|
+
row.hidden = this.current[chooser] !== "custom";
|
|
327
|
+
if (document.activeElement !== control) {
|
|
328
|
+
control.value = this.current[key];
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
return row;
|
|
332
|
+
}
|
|
333
|
+
range(key, label, unit) {
|
|
334
|
+
const { min, max, step } = NUMBER_RANGES[key];
|
|
335
|
+
const control = document.createElement("input");
|
|
336
|
+
control.type = "range";
|
|
337
|
+
control.min = String(min);
|
|
338
|
+
control.max = String(max);
|
|
339
|
+
control.step = String(step);
|
|
340
|
+
const output = document.createElement("output");
|
|
341
|
+
control.addEventListener("input", () => {
|
|
342
|
+
this.change({ [key]: Number(control.value) });
|
|
343
|
+
});
|
|
344
|
+
this.renderers.push(() => {
|
|
345
|
+
const value = this.current[key];
|
|
346
|
+
control.value = String(value);
|
|
347
|
+
output.textContent = `${value}${unit}`;
|
|
348
|
+
// How far along the track the value is, for the stylesheet to fill the track up to the thumb.
|
|
349
|
+
control.style.setProperty("--range-pct", `${((value - min) / (max - min)) * 100}%`);
|
|
350
|
+
});
|
|
351
|
+
const row = field(label, control, "range");
|
|
352
|
+
row.querySelector(".settings-label")?.append(output);
|
|
353
|
+
return row;
|
|
354
|
+
}
|
|
355
|
+
number(key, label) {
|
|
356
|
+
const { min, max, step } = NUMBER_RANGES[key];
|
|
357
|
+
const control = document.createElement("input");
|
|
358
|
+
control.type = "number";
|
|
359
|
+
control.min = String(min);
|
|
360
|
+
control.max = String(max);
|
|
361
|
+
control.step = String(step);
|
|
362
|
+
control.inputMode = "numeric";
|
|
363
|
+
control.addEventListener("change", () => {
|
|
364
|
+
const value = Number(control.value);
|
|
365
|
+
this.change({
|
|
366
|
+
[key]: Number.isFinite(value) ? value : DEFAULT_SETTINGS[key],
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
this.renderers.push(() => (control.value = String(this.current[key])));
|
|
370
|
+
return field(label, control, "number");
|
|
371
|
+
}
|
|
372
|
+
checkbox(key, label) {
|
|
373
|
+
const control = document.createElement("input");
|
|
374
|
+
control.type = "checkbox";
|
|
375
|
+
control.className = "switch";
|
|
376
|
+
// An on/off setting that applies at once is a switch, not a box to tick and then submit.
|
|
377
|
+
control.setAttribute("role", "switch");
|
|
378
|
+
control.addEventListener("change", () => {
|
|
379
|
+
this.change({ [key]: control.checked });
|
|
380
|
+
});
|
|
381
|
+
this.renderers.push(() => (control.checked = this.current[key]));
|
|
382
|
+
const row = document.createElement("label");
|
|
383
|
+
row.className = "settings-switch switch-row";
|
|
384
|
+
const text = document.createElement("span");
|
|
385
|
+
text.textContent = label;
|
|
386
|
+
row.append(text, control);
|
|
387
|
+
return row;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
// One row of a group's card. Its kind decides the layout: a select or a font name sits at the row's
|
|
391
|
+
// right end, a slider takes the full width under its label, a margin is one of four small columns.
|
|
392
|
+
function field(label, control, kind) {
|
|
393
|
+
const row = document.createElement("label");
|
|
394
|
+
row.className = `settings-field is-${kind}`;
|
|
395
|
+
const text = document.createElement("span");
|
|
396
|
+
text.className = "settings-label";
|
|
397
|
+
text.textContent = label;
|
|
398
|
+
row.append(text, control);
|
|
399
|
+
return row;
|
|
400
|
+
}
|
|
401
|
+
// A titled group of rows: the title above, the rows on a rounded card, as Settings groups its own.
|
|
402
|
+
function group(legend, children) {
|
|
403
|
+
const fieldset = document.createElement("fieldset");
|
|
404
|
+
const title = document.createElement("legend");
|
|
405
|
+
title.textContent = legend;
|
|
406
|
+
const card = document.createElement("div");
|
|
407
|
+
card.className = "settings-card";
|
|
408
|
+
card.append(...children);
|
|
409
|
+
fieldset.append(title, card);
|
|
410
|
+
return fieldset;
|
|
411
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Theme } from "./theme-toggle.js";
|
|
2
|
+
export type ECharts = {
|
|
3
|
+
setOption(option: object, opts?: {
|
|
4
|
+
notMerge?: boolean;
|
|
5
|
+
}): void;
|
|
6
|
+
setTheme(theme: string): void;
|
|
7
|
+
resize(): void;
|
|
8
|
+
on(event: "click", handler: (params: {
|
|
9
|
+
dataType?: string;
|
|
10
|
+
dataIndex: number;
|
|
11
|
+
}) => void): void;
|
|
12
|
+
on(event: "finished", handler: () => void): void;
|
|
13
|
+
on(event: "graphroam", handler: (params: {
|
|
14
|
+
zoom?: number;
|
|
15
|
+
}) => void): void;
|
|
16
|
+
dispatchAction(payload: object): void;
|
|
17
|
+
getZr(): {
|
|
18
|
+
on(event: "mouseup", handler: () => void): void;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
type EChartsModule = {
|
|
22
|
+
init(element: HTMLElement, theme?: string): ECharts;
|
|
23
|
+
};
|
|
24
|
+
export declare function loadECharts(): Promise<EChartsModule>;
|
|
25
|
+
/**
|
|
26
|
+
* The ECharts theme for the page's theme. ECharts registers `dark` itself, and `default` is the name
|
|
27
|
+
* `setTheme` takes to switch back; neither needs a theme file from the viewer.
|
|
28
|
+
*/
|
|
29
|
+
export declare function echartsTheme(theme: Theme): string;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let echarts;
|
|
2
|
+
export function loadECharts() {
|
|
3
|
+
// A variable, not a literal, so TypeScript does not try to resolve a URL as a module.
|
|
4
|
+
const url = "/vendor/echarts/echarts.esm.min.mjs";
|
|
5
|
+
echarts ??= import(url);
|
|
6
|
+
return echarts;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The ECharts theme for the page's theme. ECharts registers `dark` itself, and `default` is the name
|
|
10
|
+
* `setTheme` takes to switch back; neither needs a theme file from the viewer.
|
|
11
|
+
*/
|
|
12
|
+
export function echartsTheme(theme) {
|
|
13
|
+
return theme === "dark" ? "dark" : "default";
|
|
14
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type GraphNode = {
|
|
2
|
+
path: string;
|
|
3
|
+
title: string;
|
|
4
|
+
href: string;
|
|
5
|
+
group: string;
|
|
6
|
+
inDegree: number;
|
|
7
|
+
outDegree: number;
|
|
8
|
+
change?: "A" | "M" | "D" | "R" | "affected";
|
|
9
|
+
};
|
|
10
|
+
export type GraphView = {
|
|
11
|
+
folder: string;
|
|
12
|
+
nodes: GraphNode[];
|
|
13
|
+
edges: {
|
|
14
|
+
from: string;
|
|
15
|
+
to: string;
|
|
16
|
+
change?: "added" | "removed";
|
|
17
|
+
}[];
|
|
18
|
+
focus: {
|
|
19
|
+
path: string;
|
|
20
|
+
neighbors: string[];
|
|
21
|
+
} | null;
|
|
22
|
+
};
|
|
23
|
+
export type GraphKind = "page" | "local";
|
|
24
|
+
export declare const LABEL_FONT_SIZE = 11;
|
|
25
|
+
export type Layout = {
|
|
26
|
+
kind: GraphKind;
|
|
27
|
+
nodeScale: number;
|
|
28
|
+
fontSize: number;
|
|
29
|
+
top: number;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
spacing: number;
|
|
33
|
+
gap: number;
|
|
34
|
+
ring: number;
|
|
35
|
+
force: {
|
|
36
|
+
gravity: number;
|
|
37
|
+
repulsion: [number, number];
|
|
38
|
+
edgeLength: [number, number];
|
|
39
|
+
};
|
|
40
|
+
zoom?: number;
|
|
41
|
+
minZoom: number;
|
|
42
|
+
maxZoom: number;
|
|
43
|
+
friction?: number;
|
|
44
|
+
};
|
|
45
|
+
export declare function layoutFor(view: GraphView, canvas: {
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
}, kind: GraphKind): Layout;
|
|
49
|
+
export type ForceNode = {
|
|
50
|
+
id: string;
|
|
51
|
+
symbolSize: number;
|
|
52
|
+
value: number;
|
|
53
|
+
fixed?: true;
|
|
54
|
+
x?: number;
|
|
55
|
+
y?: number;
|
|
56
|
+
};
|
|
57
|
+
export type ForceLink = {
|
|
58
|
+
source: string;
|
|
59
|
+
target: string;
|
|
60
|
+
value: number;
|
|
61
|
+
ignoreForceLayout?: true;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Whether a link is the focused document's own: the graph lights those, and the local graph is laid
|
|
65
|
+
* out by them alone.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isOwnLink(edge: GraphView["edges"][number], focus: GraphView["focus"]): boolean;
|
|
68
|
+
export type ForceSeries = {
|
|
69
|
+
top: number;
|
|
70
|
+
bottom: number;
|
|
71
|
+
force: Layout["force"] & {
|
|
72
|
+
friction?: number;
|
|
73
|
+
layoutAnimation: boolean;
|
|
74
|
+
};
|
|
75
|
+
data: ForceNode[];
|
|
76
|
+
links: ForceLink[];
|
|
77
|
+
};
|
|
78
|
+
/** Whether ECharts lays the graph out before drawing it, rather than drawing it as it settles. */
|
|
79
|
+
export declare function laidOutAtOnce(view: GraphView, kind: GraphKind): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Everything in the graph series that steers the layout, with nodes and links in the view's order. A
|
|
82
|
+
* node's value is its area, which ECharts maps onto the repulsion range, so a wide document keeps a
|
|
83
|
+
* wide berth; a link's value is the length the layout gives it. In the local graph a link between
|
|
84
|
+
* two neighbors is drawn but does not pull: it would drag the two off the ring toward each other,
|
|
85
|
+
* and a neighborhood whose neighbors link to one another then folds into a knot beside the pinned
|
|
86
|
+
* document.
|
|
87
|
+
*/
|
|
88
|
+
export declare function forceSeries(view: GraphView, layout: Layout): ForceSeries;
|