@dooc-dev/dooc 0.0.4 → 0.0.5
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/dist/cli.js +41 -3
- package/dist/compiler/asset-references.d.ts +4 -0
- package/dist/compiler/asset-references.js +117 -0
- package/dist/compiler/bundle-urls.d.ts +1 -1
- package/dist/compiler/bundle-urls.js +15 -5
- package/dist/compiler/check.js +8 -5
- package/dist/compiler/code-languages.js +7 -2
- package/dist/compiler/compile.d.ts +5 -0
- package/dist/compiler/compile.js +105 -10
- package/dist/compiler/config.js +2 -1
- package/dist/compiler/export.d.ts +4 -0
- package/dist/compiler/export.js +140 -0
- package/dist/compiler/figures.js +4 -0
- package/dist/compiler/files.js +80 -41
- package/dist/compiler/fonts.js +4 -1
- package/dist/compiler/icons.d.ts +1 -1
- package/dist/compiler/icons.js +11 -2
- package/dist/compiler/ignored-files.d.ts +3 -0
- package/dist/compiler/ignored-files.js +68 -0
- package/dist/compiler/locales.js +13 -8
- package/dist/compiler/ops.d.ts +6 -0
- package/dist/compiler/ops.js +98 -7
- package/dist/compiler/subformats.d.ts +24 -0
- package/dist/compiler/subformats.js +299 -0
- package/dist/compiler/textfile.js +3 -0
- package/dist/compiler/theme-variants.js +5 -2
- package/dist/core/content-metadata.d.ts +15 -6
- package/dist/core/content-metadata.js +278 -17
- package/dist/core/content-types.d.ts +3 -1
- package/dist/core/figure-frame.js +19 -1
- package/dist/core/files.d.ts +2 -1
- package/dist/core/files.js +6 -8
- package/dist/core/flow-base-css.generated.js +1 -1
- package/dist/core/html.js +3 -3
- package/dist/core/icons.d.ts +3 -0
- package/dist/core/icons.js +3 -0
- package/dist/core/json-tools.d.ts +1 -0
- package/dist/core/json-tools.js +12 -0
- package/dist/core/routing.d.ts +5 -2
- package/dist/core/routing.js +17 -5
- package/dist/core/subformat-record.d.ts +3 -0
- package/dist/core/subformat-record.js +131 -0
- package/dist/core/subformats.d.ts +43 -0
- package/dist/core/subformats.js +81 -0
- package/dist/core/toc-ui.js +25 -23
- package/dist/edit.global.js +322 -95
- package/dist/mcp.js +50 -9
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/transport.d.ts +22 -0
- package/dist/plugins/transport.js +1 -0
- package/dist/plugins.global.js +128 -0
- package/dist/subformats.global.js +127 -0
- package/dist/ui.global.js +91 -38
- package/dist/viewer/build-plugins.d.ts +7 -0
- package/dist/viewer/build-plugins.js +70 -0
- package/dist/viewer/build.d.ts +9 -0
- package/dist/viewer/build.js +32 -5
- package/dist/viewer/editor-tools.d.ts +7 -7
- package/dist/viewer/editor-tools.js +36 -5
- package/dist/viewer/font-picker.js +5 -1
- package/dist/viewer/git-diff.d.ts +3 -0
- package/dist/viewer/git-diff.js +47 -0
- package/dist/viewer/hmr.js +4 -1
- package/dist/viewer/i18n.js +7 -5
- package/dist/viewer/language-picker.d.ts +2 -2
- package/dist/viewer/language-picker.js +26 -9
- package/dist/viewer/lazy-graph.d.ts +2 -0
- package/dist/viewer/lazy-graph.js +30 -0
- package/dist/viewer/locales/eng.json +72 -10
- package/dist/viewer/locales/jpn.json +73 -11
- package/dist/viewer/locales/zho.json +73 -11
- package/dist/viewer/nav-focus.js +8 -1
- package/dist/viewer/nav-update.d.ts +2 -0
- package/dist/viewer/nav-update.js +117 -0
- package/dist/viewer/plugin-style.d.ts +1 -0
- package/dist/viewer/plugin-style.js +82 -0
- package/dist/viewer/resize.d.ts +0 -2
- package/dist/viewer/resize.js +2 -98
- package/dist/viewer/resource-library.d.ts +10 -8
- package/dist/viewer/resource-library.js +179 -30
- package/dist/viewer/search.d.ts +4 -2
- package/dist/viewer/search.js +252 -53
- package/dist/viewer/serve.d.ts +10 -5
- package/dist/viewer/serve.js +789 -278
- package/dist/viewer/site-icon.js +13 -6
- package/dist/viewer/site-title.js +15 -2
- package/dist/viewer/textfile.d.ts +3 -0
- package/dist/viewer/textfile.js +19 -2
- package/dist/viewer/theme-picker.d.ts +2 -0
- package/dist/viewer/theme-picker.js +24 -8
- package/dist/viewer/workspace.d.ts +2 -0
- package/dist/viewer/workspace.js +46 -1
- package/package.json +24 -9
- package/dist/compiler/bundle.d.ts +0 -2
- package/dist/compiler/bundle.js +0 -100
package/dist/viewer/search.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { inlineSegmenter } from "../core/inline.js";
|
|
2
2
|
import { docPath } from "../core/routing.js";
|
|
3
3
|
import { docDisplayName } from "../core/taxonomy.js";
|
|
4
|
-
|
|
4
|
+
/** `files` are workspace files that open at /_files/file/<path> (edit mode only). */
|
|
5
|
+
export const searchIndex = (site, files = []) => {
|
|
5
6
|
const parents = new Set(site.entries.map((entry) => entry.parent));
|
|
6
7
|
const segments = inlineSegmenter({ terms: site.ctx.terms });
|
|
7
8
|
const plain = (text) => segments(text)
|
|
@@ -55,23 +56,22 @@ export const searchIndex = (site) => {
|
|
|
55
56
|
.join(" ");
|
|
56
57
|
}
|
|
57
58
|
};
|
|
58
|
-
|
|
59
|
+
const docs = site.entries.flatMap((entry) => {
|
|
59
60
|
const base = {
|
|
60
61
|
path: docPath(site.entries, entry.id),
|
|
61
|
-
file: entry.file,
|
|
62
|
-
folder: parents.has(entry.id),
|
|
62
|
+
file: entry.sourceFile ?? entry.file,
|
|
63
63
|
title: docDisplayName(entry.frontmatter, entry.id),
|
|
64
|
-
};
|
|
65
|
-
let section = {
|
|
66
|
-
...base,
|
|
67
64
|
heading: "",
|
|
68
65
|
anchor: "",
|
|
69
66
|
text: "",
|
|
70
67
|
};
|
|
71
|
-
|
|
68
|
+
let section = { ...base, kind: "text" };
|
|
69
|
+
const sections = [section, { ...base, kind: "file" }];
|
|
70
|
+
if (parents.has(entry.id))
|
|
71
|
+
sections.push({ ...base, kind: "folder", file: `${base.path}/` });
|
|
72
72
|
for (const block of entry.blocks) {
|
|
73
73
|
if (block.type === "h") {
|
|
74
|
-
section = { ...base, heading: plain(block.text), anchor: block.slug
|
|
74
|
+
section = { ...base, kind: "text", heading: plain(block.text), anchor: block.slug };
|
|
75
75
|
sections.push(section);
|
|
76
76
|
}
|
|
77
77
|
else
|
|
@@ -79,6 +79,21 @@ export const searchIndex = (site) => {
|
|
|
79
79
|
}
|
|
80
80
|
return sections.map((item) => ({ ...item, text: item.text.replace(/\s+/g, " ").trim() }));
|
|
81
81
|
});
|
|
82
|
+
const sources = new Set(docs.map((section) => section.file));
|
|
83
|
+
return [
|
|
84
|
+
...docs,
|
|
85
|
+
...files
|
|
86
|
+
.filter((file) => !sources.has(file))
|
|
87
|
+
.map((file) => ({
|
|
88
|
+
kind: "file",
|
|
89
|
+
path: `/_files/file/${encodeURIComponent(file)}`,
|
|
90
|
+
file,
|
|
91
|
+
title: file.split("/").pop() ?? file,
|
|
92
|
+
heading: "",
|
|
93
|
+
anchor: "",
|
|
94
|
+
text: "",
|
|
95
|
+
})),
|
|
96
|
+
];
|
|
82
97
|
};
|
|
83
98
|
// Self-contained: the viewer embeds this function in offline HTML as well.
|
|
84
99
|
export const searchSections = (index, query, currentPath = "") => {
|
|
@@ -89,21 +104,27 @@ export const searchSections = (index, query, currentPath = "") => {
|
|
|
89
104
|
const seen = new Set();
|
|
90
105
|
return index
|
|
91
106
|
.flatMap((section) => {
|
|
107
|
+
if (section.kind !== "text") {
|
|
108
|
+
// File names match on the basename, so "md" or ".md" finds extensions.
|
|
109
|
+
const name = normalize(section.kind === "file" ? (section.file.split("/").pop() ?? "") : section.file);
|
|
110
|
+
if (!words.every((word) => name.includes(word)))
|
|
111
|
+
return [];
|
|
112
|
+
// A folder document also matches as its own file; prefer showing it as a folder.
|
|
113
|
+
const score = (section.kind === "folder" ? 25 : 20) * words.length +
|
|
114
|
+
(name === words.join(" ") ? 100 : 0);
|
|
115
|
+
return [{ ...section, snippet: "", score }];
|
|
116
|
+
}
|
|
92
117
|
const title = normalize(section.title);
|
|
93
118
|
const heading = normalize(section.heading);
|
|
94
119
|
const text = section.text.normalize("NFKC");
|
|
95
120
|
const body = text.toLowerCase();
|
|
96
|
-
const
|
|
97
|
-
const all = `${title} ${heading} ${body} ${name}`;
|
|
121
|
+
const all = `${title} ${heading} ${body}`;
|
|
98
122
|
if (!words.every((word) => all.includes(word)))
|
|
99
123
|
return [];
|
|
100
124
|
if (section.anchor && !words.some((word) => `${heading} ${body}`.includes(word)))
|
|
101
125
|
return [];
|
|
102
126
|
const score = (title === words.join(" ") ? 100 : 0) +
|
|
103
|
-
words.reduce((sum, word) => sum +
|
|
104
|
-
(title.includes(word) ? 10 : 0) +
|
|
105
|
-
(name.includes(word) ? 10 : 0) +
|
|
106
|
-
(heading.includes(word) ? 5 : 0), 0);
|
|
127
|
+
words.reduce((sum, word) => sum + (title.includes(word) ? 10 : 0) + (heading.includes(word) ? 5 : 0), 0);
|
|
107
128
|
const matches = words.map((word) => body.indexOf(word)).filter((at) => at >= 0);
|
|
108
129
|
const start = Math.max(0, (matches.length ? Math.min(...matches) : 0) - 45);
|
|
109
130
|
const snippet = `${start ? "…" : ""}${text.slice(start, start + 180)}${text.length > start + 180 ? "…" : ""}`;
|
|
@@ -127,17 +148,31 @@ export const SEARCH_LABELS = [
|
|
|
127
148
|
"Could not load search. Press Ctrl+F to retry.",
|
|
128
149
|
"{count} results",
|
|
129
150
|
"Showing {shown} of {count} results",
|
|
130
|
-
"
|
|
151
|
+
"Matches text",
|
|
152
|
+
"Matches file name",
|
|
153
|
+
"Matches folder name",
|
|
131
154
|
"Move search",
|
|
132
155
|
"Resize search",
|
|
156
|
+
"Close search",
|
|
157
|
+
"Move search to sidebar",
|
|
158
|
+
"Float search",
|
|
159
|
+
"Copy path",
|
|
160
|
+
"Copied",
|
|
161
|
+
"Copy failed",
|
|
133
162
|
];
|
|
134
163
|
// Embedded by page(); keep browser behavior independent of the editor bundle.
|
|
135
164
|
export const mountSearch = (initial, search, labels, published) => {
|
|
165
|
+
const svg = (d, size = 14) => `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`;
|
|
166
|
+
const kinds = {
|
|
167
|
+
text: { icon: svg("M5 6h14M5 11h14M5 16h9"), label: "Matches text" },
|
|
168
|
+
file: { icon: svg("M6 3h8l4 4v14H6zM14 3v4h4"), label: "Matches file name" },
|
|
169
|
+
folder: { icon: svg("M3 6h6l2 2h10v11H3z"), label: "Matches folder name" },
|
|
170
|
+
};
|
|
136
171
|
const dialog = document.createElement("dialog");
|
|
137
172
|
dialog.id = "doc-search";
|
|
138
173
|
dialog.setAttribute("aria-label", labels["Search documents"] ?? "Search documents");
|
|
139
|
-
dialog.innerHTML = `<div class="search-
|
|
140
|
-
document.body.
|
|
174
|
+
dialog.innerHTML = `<div class="search-grip" role="button" tabindex="0" data-label="Move search"></div><div class="search-head">${svg("M10.5 4a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13zM16 16l4 4", 18)}<input id="doc-search-input" type="search" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="doc-search-results" autocomplete="off" spellcheck="false"><button type="button" class="search-dock"></button><button type="button" class="search-close" data-label="Close search">${svg("M6 6l12 12M18 6 6 18")}</button></div><div class="search-status" role="status" aria-live="polite"></div><div id="doc-search-results" role="listbox"></div><div class="search-resize search-resize-x" role="button" tabindex="0" data-axis="x" data-label="Resize search"></div><div class="search-resize search-resize-y" role="button" tabindex="0" data-axis="y" data-label="Resize search"></div><div class="search-resize search-resize-xy" data-axis="xy" aria-hidden="true"></div><div class="search-resize search-resize-w" role="button" tabindex="0" data-axis="w" data-label="Resize search"></div>`;
|
|
175
|
+
document.body.insertBefore(dialog, document.getElementById("panel"));
|
|
141
176
|
const input = dialog.querySelector("input");
|
|
142
177
|
const results = dialog.querySelector("#doc-search-results");
|
|
143
178
|
const status = dialog.querySelector(".search-status");
|
|
@@ -155,6 +190,37 @@ export const mountSearch = (initial, search, labels, published) => {
|
|
|
155
190
|
const currentPath = () => published
|
|
156
191
|
? location.hash.slice(1).split(/[?#]/)[0] || initial[0]?.path || ""
|
|
157
192
|
: location.pathname;
|
|
193
|
+
// Wrap query words in <mark>, comparing each character the way searchSections() does.
|
|
194
|
+
const highlight = (target, text, words) => {
|
|
195
|
+
let folded = "";
|
|
196
|
+
const source = [];
|
|
197
|
+
for (let i = 0; i < text.length; i++) {
|
|
198
|
+
const part = (text[i] ?? "").normalize("NFKC").toLowerCase();
|
|
199
|
+
folded += part;
|
|
200
|
+
for (let j = 0; j < part.length; j++)
|
|
201
|
+
source.push(i);
|
|
202
|
+
}
|
|
203
|
+
const marked = [];
|
|
204
|
+
for (const word of words)
|
|
205
|
+
for (let at = folded.indexOf(word); at >= 0; at = folded.indexOf(word, at + 1))
|
|
206
|
+
for (let i = source[at] ?? 0; i <= (source[at + word.length - 1] ?? -1); i++)
|
|
207
|
+
marked[i] = true;
|
|
208
|
+
let start = 0;
|
|
209
|
+
for (let i = 1; i <= text.length; i++) {
|
|
210
|
+
if (i < text.length && !!marked[i] === !!marked[start])
|
|
211
|
+
continue;
|
|
212
|
+
const run = text.slice(start, i);
|
|
213
|
+
if (marked[start]) {
|
|
214
|
+
const mark = document.createElement("mark");
|
|
215
|
+
mark.textContent = run;
|
|
216
|
+
target.append(mark);
|
|
217
|
+
}
|
|
218
|
+
else
|
|
219
|
+
target.append(run);
|
|
220
|
+
start = i;
|
|
221
|
+
}
|
|
222
|
+
return target;
|
|
223
|
+
};
|
|
158
224
|
const select = (position) => {
|
|
159
225
|
const items = [...results.querySelectorAll("a")];
|
|
160
226
|
selected = items.length ? (position + items.length) % items.length : 0;
|
|
@@ -169,8 +235,57 @@ export const mountSearch = (initial, search, labels, published) => {
|
|
|
169
235
|
else
|
|
170
236
|
input.removeAttribute("aria-activedescendant");
|
|
171
237
|
};
|
|
238
|
+
const copyButton = (text) => {
|
|
239
|
+
const button = document.createElement("button");
|
|
240
|
+
button.type = "button";
|
|
241
|
+
button.className = "search-copy";
|
|
242
|
+
const show = (icon, label) => {
|
|
243
|
+
button.innerHTML = icon;
|
|
244
|
+
button.title = t(label);
|
|
245
|
+
button.setAttribute("aria-label", button.title);
|
|
246
|
+
};
|
|
247
|
+
const reset = () => show(svg("M9 9h11v11H9zM5 15H4V4h11v1"), "Copy path");
|
|
248
|
+
reset();
|
|
249
|
+
button.addEventListener("click", () => {
|
|
250
|
+
Promise.resolve()
|
|
251
|
+
.then(() => navigator.clipboard.writeText(text))
|
|
252
|
+
.then(() => show(svg("M5 12l5 5 9-10"), "Copied"), () => show(svg("M6 6l12 12M18 6 6 18"), "Copy failed"))
|
|
253
|
+
.finally(() => setTimeout(reset, 1500));
|
|
254
|
+
});
|
|
255
|
+
return button;
|
|
256
|
+
};
|
|
257
|
+
// Highlight where a clicked result leads, once navigation has shown it.
|
|
258
|
+
let pending;
|
|
259
|
+
let flashing;
|
|
260
|
+
const flash = (target) => {
|
|
261
|
+
pending = target;
|
|
262
|
+
clearInterval(flashing);
|
|
263
|
+
let tries = 0;
|
|
264
|
+
flashing = window.setInterval(() => {
|
|
265
|
+
const element = currentPath() !== target.path
|
|
266
|
+
? null
|
|
267
|
+
: target.anchor
|
|
268
|
+
? document.getElementById(target.anchor)
|
|
269
|
+
: (document.querySelector(".resources-pane article") ??
|
|
270
|
+
document.querySelector(".preview-pane.active article") ??
|
|
271
|
+
document.querySelector("main article"));
|
|
272
|
+
if (!element && ++tries < 50)
|
|
273
|
+
return;
|
|
274
|
+
clearInterval(flashing);
|
|
275
|
+
pending = undefined;
|
|
276
|
+
if (!element)
|
|
277
|
+
return;
|
|
278
|
+
element.classList.remove("search-flash");
|
|
279
|
+
void element.offsetWidth; // Restart the animation on repeated jumps.
|
|
280
|
+
element.classList.add("search-flash");
|
|
281
|
+
setTimeout(() => element.classList.remove("search-flash"), 2600);
|
|
282
|
+
}, 100);
|
|
283
|
+
};
|
|
172
284
|
const render = () => {
|
|
173
285
|
const hits = search(index, input.value, currentPath());
|
|
286
|
+
const words = [
|
|
287
|
+
...new Set(input.value.normalize("NFKC").toLowerCase().trim().split(/\s+/)),
|
|
288
|
+
].filter(Boolean);
|
|
174
289
|
results.replaceChildren();
|
|
175
290
|
dialog.classList.toggle("search-filled", input.value.length > 0);
|
|
176
291
|
for (const [i, hit] of hits.slice(0, 60).entries()) {
|
|
@@ -178,32 +293,51 @@ export const mountSearch = (initial, search, labels, published) => {
|
|
|
178
293
|
link.id = `doc-search-result-${i}`;
|
|
179
294
|
link.setAttribute("role", "option");
|
|
180
295
|
link.tabIndex = -1;
|
|
296
|
+
link.dataset.path = hit.path;
|
|
297
|
+
link.dataset.anchor = hit.anchor;
|
|
181
298
|
link.href = `${published ? "#" : ""}${hit.path}${!published && language ? `?lang=${encodeURIComponent(language)}` : ""}${hit.anchor ? `#${encodeURIComponent(hit.anchor)}` : ""}`;
|
|
182
299
|
const meta = document.createElement("div");
|
|
183
300
|
meta.className = "search-meta";
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
301
|
+
const kind = document.createElement("span");
|
|
302
|
+
kind.className = "search-kind";
|
|
303
|
+
kind.innerHTML = kinds[hit.kind].icon;
|
|
304
|
+
kind.title = t(kinds[hit.kind].label);
|
|
305
|
+
kind.setAttribute("role", "img");
|
|
306
|
+
kind.setAttribute("aria-label", kind.title);
|
|
189
307
|
const path = document.createElement("small");
|
|
190
308
|
path.className = "search-path";
|
|
191
|
-
path.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
309
|
+
path.title = hit.file;
|
|
310
|
+
// File hits match only the basename, so leave the folder part unmarked.
|
|
311
|
+
const cut = hit.kind === "file" ? hit.file.lastIndexOf("/") + 1 : 0;
|
|
312
|
+
path.append(hit.file.slice(0, cut));
|
|
313
|
+
meta.append(kind, highlight(path, hit.file.slice(cut), words));
|
|
314
|
+
link.append(meta);
|
|
315
|
+
// Name-only hits list just the path; their content has nothing to do with the match.
|
|
316
|
+
const named = hit.kind !== "text";
|
|
317
|
+
if (!named) {
|
|
318
|
+
const title = document.createElement("strong");
|
|
319
|
+
link.append(highlight(title, `${hit.title}${hit.heading ? ` › ${hit.heading}` : ""}`, words));
|
|
320
|
+
}
|
|
321
|
+
if (!named && hit.snippet) {
|
|
322
|
+
const snippet = document.createElement("span");
|
|
323
|
+
snippet.className = "search-snippet";
|
|
324
|
+
link.append(highlight(snippet, hit.snippet, words));
|
|
325
|
+
}
|
|
326
|
+
// The copy button sits beside the option, since buttons cannot nest inside links.
|
|
327
|
+
const item = document.createElement("div");
|
|
328
|
+
item.className = named ? "search-hit search-name" : "search-hit";
|
|
329
|
+
item.setAttribute("role", "none");
|
|
330
|
+
item.append(link);
|
|
331
|
+
if (named)
|
|
332
|
+
item.append(copyButton(hit.file));
|
|
333
|
+
results.append(item);
|
|
200
334
|
}
|
|
201
|
-
status.textContent =
|
|
202
|
-
?
|
|
203
|
-
:
|
|
204
|
-
? t("
|
|
205
|
-
:
|
|
206
|
-
? ""
|
|
335
|
+
status.textContent = !input.value.trim()
|
|
336
|
+
? ""
|
|
337
|
+
: loading
|
|
338
|
+
? t("Searching…")
|
|
339
|
+
: failed
|
|
340
|
+
? t("Could not load search. Press Ctrl+F to retry.")
|
|
207
341
|
: !hits.length
|
|
208
342
|
? t("No results")
|
|
209
343
|
: hits.length > 60
|
|
@@ -216,16 +350,42 @@ export const mountSearch = (initial, search, labels, published) => {
|
|
|
216
350
|
const localize = () => {
|
|
217
351
|
dialog.setAttribute("aria-label", t("Search documents"));
|
|
218
352
|
input.setAttribute("aria-label", t("Search documents"));
|
|
219
|
-
for (const
|
|
220
|
-
|
|
221
|
-
|
|
353
|
+
for (const control of dialog.querySelectorAll("[data-label]")) {
|
|
354
|
+
control.title = t(control.dataset.label ?? "");
|
|
355
|
+
control.setAttribute("aria-label", control.title);
|
|
222
356
|
}
|
|
223
357
|
render();
|
|
224
358
|
};
|
|
359
|
+
const minHeight = 44;
|
|
360
|
+
// Dock between the document and editor; each mode keeps its own inline geometry.
|
|
361
|
+
let docked = false;
|
|
362
|
+
let other = "";
|
|
363
|
+
const dockButton = dialog.querySelector(".search-dock");
|
|
364
|
+
const dock = (value) => {
|
|
365
|
+
if (value !== docked)
|
|
366
|
+
[dialog.style.cssText, other] = [other, dialog.style.cssText];
|
|
367
|
+
docked = value;
|
|
368
|
+
dialog.classList.toggle("search-docked", value);
|
|
369
|
+
dockButton.innerHTML = svg(value ? "M14 4h6v6M20 4l-9 9M18 14v6H4V6h6" : "M4 5h16v14H4zM15 5v14");
|
|
370
|
+
dockButton.dataset.label = value ? "Float search" : "Move search to sidebar";
|
|
371
|
+
dockButton.title = t(dockButton.dataset.label);
|
|
372
|
+
dockButton.setAttribute("aria-label", dockButton.title);
|
|
373
|
+
};
|
|
374
|
+
dock(false);
|
|
375
|
+
dockButton.addEventListener("click", () => {
|
|
376
|
+
dock(!docked);
|
|
377
|
+
input.focus();
|
|
378
|
+
});
|
|
225
379
|
const position = (rect, dx, dy, resize = false) => {
|
|
226
380
|
const clamp = (value, min, max) => Math.max(Math.min(min, max), Math.min(value, max));
|
|
381
|
+
if (docked) {
|
|
382
|
+
// As a sidebar only the left edge resizes the panel.
|
|
383
|
+
if (resize && dx)
|
|
384
|
+
dialog.style.width = `${clamp(rect.width + dx, 240, innerWidth - 320)}px`;
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
227
387
|
const width = clamp(rect.width + (resize ? dx : 0), 280, innerWidth - 16);
|
|
228
|
-
const height = clamp(rect.height + (resize ? dy : 0),
|
|
388
|
+
const height = clamp(rect.height + (resize ? dy : 0), minHeight, innerHeight - 16);
|
|
229
389
|
const left = clamp(rect.left + (resize ? 0 : dx), 8, innerWidth - width - 8);
|
|
230
390
|
const top = clamp(rect.top + (resize ? 0 : dy), 8, innerHeight - height - 8);
|
|
231
391
|
Object.assign(dialog.style, {
|
|
@@ -236,17 +396,21 @@ export const mountSearch = (initial, search, labels, published) => {
|
|
|
236
396
|
width: `${width}px`,
|
|
237
397
|
maxHeight: `${innerHeight - top - 8}px`,
|
|
238
398
|
});
|
|
239
|
-
|
|
399
|
+
// Width-only resizing keeps the height following the results.
|
|
400
|
+
if ((resize && dy) || dialog.style.height)
|
|
240
401
|
dialog.style.height = `${height}px`;
|
|
241
402
|
};
|
|
242
403
|
for (const handle of dialog.querySelectorAll(".search-grip, .search-resize")) {
|
|
243
|
-
const
|
|
404
|
+
const axis = handle.dataset.axis ?? "";
|
|
405
|
+
const resize = axis !== "";
|
|
406
|
+
// The left edge ("w") grows the docked panel while moving left.
|
|
407
|
+
const fx = axis === "w" ? -1 : !resize || axis.includes("x") ? 1 : 0;
|
|
408
|
+
const fy = !resize || axis.includes("y") ? 1 : 0;
|
|
244
409
|
let drag;
|
|
245
410
|
handle.addEventListener("pointerdown", (event) => {
|
|
246
411
|
if (event.button !== 0 || drag)
|
|
247
412
|
return;
|
|
248
413
|
event.preventDefault();
|
|
249
|
-
handle.focus();
|
|
250
414
|
drag = {
|
|
251
415
|
id: event.pointerId,
|
|
252
416
|
x: event.clientX,
|
|
@@ -257,7 +421,7 @@ export const mountSearch = (initial, search, labels, published) => {
|
|
|
257
421
|
});
|
|
258
422
|
handle.addEventListener("pointermove", (event) => {
|
|
259
423
|
if (drag?.id === event.pointerId)
|
|
260
|
-
position(drag.rect, event.clientX - drag.x, event.clientY - drag.y, resize);
|
|
424
|
+
position(drag.rect, fx * (event.clientX - drag.x), fy * (event.clientY - drag.y), resize);
|
|
261
425
|
});
|
|
262
426
|
const stop = () => {
|
|
263
427
|
drag = undefined;
|
|
@@ -271,7 +435,7 @@ export const mountSearch = (initial, search, labels, published) => {
|
|
|
271
435
|
event.preventDefault();
|
|
272
436
|
event.stopPropagation();
|
|
273
437
|
const step = event.shiftKey ? 40 : 10;
|
|
274
|
-
position(dialog.getBoundingClientRect(), event.key === "ArrowRight" ? step : event.key === "ArrowLeft" ? -step : 0, event.key === "ArrowDown" ? step : event.key === "ArrowUp" ? -step : 0, resize);
|
|
438
|
+
position(dialog.getBoundingClientRect(), fx * (event.key === "ArrowRight" ? step : event.key === "ArrowLeft" ? -step : 0), fy * (event.key === "ArrowDown" ? step : event.key === "ArrowUp" ? -step : 0), resize);
|
|
275
439
|
});
|
|
276
440
|
}
|
|
277
441
|
window.addEventListener("resize", () => {
|
|
@@ -340,19 +504,54 @@ export const mountSearch = (initial, search, labels, published) => {
|
|
|
340
504
|
}
|
|
341
505
|
});
|
|
342
506
|
results.addEventListener("click", (event) => {
|
|
343
|
-
|
|
344
|
-
|
|
507
|
+
const link = event.target.closest("a");
|
|
508
|
+
if (!link || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey)
|
|
509
|
+
return;
|
|
510
|
+
flash({ path: link.dataset.path ?? "", anchor: link.dataset.anchor ?? "" });
|
|
345
511
|
});
|
|
512
|
+
// The window stays open across navigation and outside clicks; only these close it.
|
|
513
|
+
dialog.querySelector(".search-close")?.addEventListener("click", () => dialog.close());
|
|
346
514
|
dialog.addEventListener("keydown", (event) => {
|
|
347
515
|
if (event.key === "Escape" && !event.isComposing) {
|
|
348
516
|
event.preventDefault();
|
|
349
517
|
dialog.close();
|
|
350
518
|
}
|
|
351
519
|
});
|
|
352
|
-
document.addEventListener("pointerdown", (event) => {
|
|
353
|
-
if (dialog.open && !dialog.contains(event.target))
|
|
354
|
-
dialog.close();
|
|
355
|
-
});
|
|
356
520
|
document.addEventListener("docs:ui-language", localize);
|
|
357
521
|
localize();
|
|
522
|
+
// Full page loads (preview links, reloads) restore the open window for this browser tab.
|
|
523
|
+
const key = "docs:search";
|
|
524
|
+
let saved = null;
|
|
525
|
+
try {
|
|
526
|
+
saved = JSON.parse(sessionStorage.getItem(key) ?? "null");
|
|
527
|
+
}
|
|
528
|
+
catch {
|
|
529
|
+
/* Persistence is optional. */
|
|
530
|
+
}
|
|
531
|
+
window.addEventListener("pagehide", () => {
|
|
532
|
+
try {
|
|
533
|
+
if (dialog.open)
|
|
534
|
+
sessionStorage.setItem(key, JSON.stringify({
|
|
535
|
+
query: input.value,
|
|
536
|
+
style: dialog.style.cssText,
|
|
537
|
+
docked,
|
|
538
|
+
pending,
|
|
539
|
+
}));
|
|
540
|
+
else
|
|
541
|
+
sessionStorage.removeItem(key);
|
|
542
|
+
}
|
|
543
|
+
catch {
|
|
544
|
+
/* Persistence is optional. */
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
if (saved?.query == null)
|
|
548
|
+
return;
|
|
549
|
+
if (saved.docked)
|
|
550
|
+
dock(true);
|
|
551
|
+
if (saved.style)
|
|
552
|
+
dialog.style.cssText = saved.style;
|
|
553
|
+
input.value = saved.query;
|
|
554
|
+
void open();
|
|
555
|
+
if (saved.pending)
|
|
556
|
+
flash(saved.pending);
|
|
358
557
|
};
|
package/dist/viewer/serve.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { LanguageRegistration } from "shiki/core";
|
|
|
3
3
|
import { type Compiled } from "../compiler/compile.js";
|
|
4
4
|
import { assembleDoc } from "../compiler/ops.js";
|
|
5
5
|
import { type Block, type TocEntry } from "../core/blocks.js";
|
|
6
|
-
import type { TermEntry } from "../core/content-types.js";
|
|
6
|
+
import type { CompiledDoc, TermEntry } from "../core/content-types.js";
|
|
7
7
|
import { type RenderCtx } from "../core/html.js";
|
|
8
8
|
import { type LanguageAdapter } from "../core/language.js";
|
|
9
9
|
import { type PreviewSettings } from "../core/previewers.js";
|
|
@@ -20,6 +20,7 @@ export type ServeMode = "preview" | "edit";
|
|
|
20
20
|
*/
|
|
21
21
|
export interface Entry {
|
|
22
22
|
id: string;
|
|
23
|
+
subformat?: CompiledDoc["subformat"];
|
|
23
24
|
translatedLanguages?: string[];
|
|
24
25
|
/** Parent doc id (omitted = top level). */
|
|
25
26
|
parent?: string;
|
|
@@ -51,14 +52,18 @@ export interface Entry {
|
|
|
51
52
|
figureRefs?: string[];
|
|
52
53
|
termRefs?: string[];
|
|
53
54
|
terms?: TermEntry[];
|
|
55
|
+
referencedFiles?: string[];
|
|
54
56
|
}
|
|
55
57
|
export interface Site {
|
|
58
|
+
sourceBase?: string;
|
|
59
|
+
subformats?: Compiled["subformats"];
|
|
56
60
|
fonts?: readonly ProjectFont[];
|
|
57
61
|
workspace?: WorkspaceSource;
|
|
58
62
|
filePaths?: readonly string[];
|
|
59
63
|
previews?: PreviewSettings;
|
|
60
64
|
title?: string;
|
|
61
65
|
icon?: string;
|
|
66
|
+
iconVariants?: Record<string, string>;
|
|
62
67
|
codeLanguages?: string[];
|
|
63
68
|
codeGrammars?: LanguageRegistration[];
|
|
64
69
|
contentLanguage?: string;
|
|
@@ -76,7 +81,7 @@ export interface Site {
|
|
|
76
81
|
themes?: readonly ("light" | "dark")[];
|
|
77
82
|
}
|
|
78
83
|
/** Compile result → viewer Site (shared by the server's per-request path and one-off publish). */
|
|
79
|
-
export declare const siteFrom: ({ title, icon, docs, terms, figures, sources, siteErrors, defaultLang, previews, contentLanguages, themes, }: Compiled, languages?: readonly LanguageAdapter[]) => Site;
|
|
84
|
+
export declare const siteFrom: ({ title, icon, iconVariants, docs, terms, figures, sources, siteErrors, defaultLang, previews, contentLanguages, themes, subformats, }: Compiled, languages?: readonly LanguageAdapter[]) => Site;
|
|
80
85
|
export declare const filePreviewResults: (entry: Entry, site: Site) => FilePreviewResults;
|
|
81
86
|
/** Renders only the requested doc, not every doc in site.entries. */
|
|
82
87
|
export declare const renderEntryHtml: (site: Site, entry: Entry) => {
|
|
@@ -134,7 +139,7 @@ export declare const resourcesMain: (site: Site, rest: string) => {
|
|
|
134
139
|
* down to figures / terms / schema graph JS). Each doc is held in a
|
|
135
140
|
* <template> and switched via hash routes.
|
|
136
141
|
*/
|
|
137
|
-
export declare const publishHtml: (site: Site, graphJs: string, title?: string, codeJs?: string, mode?: "static" | "network") => string;
|
|
142
|
+
export declare const publishHtml: (site: Site, graphJs: string, title?: string, codeJs?: string, mode?: "static" | "network" | "live", pluginJs?: string, subformatJs?: string) => string;
|
|
138
143
|
/**
|
|
139
144
|
* Boot data for the client (edit-client.ts) — the same shape is passed for the initial render and
|
|
140
145
|
* on doc switch. Insertion happens via the client's in-editor autocomplete (`/` palette), so the
|
|
@@ -201,8 +206,8 @@ export interface BundleCache {
|
|
|
201
206
|
clear: () => void;
|
|
202
207
|
}
|
|
203
208
|
export declare const createBundleCache: () => BundleCache;
|
|
204
|
-
/**
|
|
205
|
-
export declare const bundleClient: (entry: string
|
|
209
|
+
/** Minified client bundle shared by local viewing and published HTML. */
|
|
210
|
+
export declare const bundleClient: (entry: string) => Promise<string>;
|
|
206
211
|
export declare const startServer: (mode: ServeMode, port?: number, pluginModule?: string, startup?: {
|
|
207
212
|
file?: string;
|
|
208
213
|
data?: string;
|