@dooc-dev/dooc 0.0.20 → 0.0.22
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/edit.global.js +4 -4
- package/dist/engine/core/html.js +2 -2
- package/dist/frontend/document-application.js +31 -21
- package/dist/frontend/document-links.js +31 -21
- package/dist/frontend/locales/eng.json +2 -1
- package/dist/frontend/locales/jpn.json +2 -1
- package/dist/frontend/locales/zho.json +2 -1
- package/dist/frontend/section-fold.d.ts +2 -0
- package/dist/frontend/section-fold.js +80 -0
- package/dist/frontend/toc-ui.js +45 -37
- package/dist/plugins.global.js +3 -3
- package/dist/subformats.global.js +34 -34
- package/dist/ui.global.js +55 -55
- package/dist/workspace-mcp-worker.global.js +39 -30
- package/dist/workspace-reader-mcp-worker.global.js +39 -30
- package/dist/workspace-reader-worker.global.js +39 -30
- package/dist/workspace-worker.global.js +39 -30
- package/package.json +1 -1
package/dist/engine/core/html.js
CHANGED
|
@@ -390,7 +390,7 @@ const blockContentHtml = (b, ctx, seg) => {
|
|
|
390
390
|
}
|
|
391
391
|
case "h":
|
|
392
392
|
// id = slug (a single-doc page, so no namespace is needed).
|
|
393
|
-
return `<h${b.level} id="${escapeHtml(b.slug)}">${segmentsHtml(b.text, ctx, seg)}${ctx.sectionUrl === undefined ? "" : `<button class="section-copy" type="button" data-section-url="${escapeHtml(ctx.sectionUrl)}#${encodeURIComponent(b.slug)}" title="Copy section URL" aria-label="Copy section URL" data-i18n-title="Copy section URL" data-i18n-aria-label="Copy section URL"><svg viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><path d="m8 12 4-4m-5 2-2 2a3 3 0 0 0 4 4l2-2m-2-8 2-2a3 3 0 0 1 4 4l-2 2"/></svg>${CHECK_ICON}</button>`}</h${b.level}>`;
|
|
393
|
+
return `<h${b.level} id="${escapeHtml(b.slug)}">${segmentsHtml(b.text, ctx, seg)}${ctx.sectionUrl === undefined ? "" : `<button class="section-fold" type="button" aria-expanded="true" title="Collapse section" aria-label="Collapse section" data-i18n-title="Collapse section" data-i18n-aria-label="Collapse section"><svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4 6 4 4 4-4"/></svg></button><button class="section-copy" type="button" data-section-url="${escapeHtml(ctx.sectionUrl)}#${encodeURIComponent(b.slug)}" title="Copy section URL" aria-label="Copy section URL" data-i18n-title="Copy section URL" data-i18n-aria-label="Copy section URL"><svg viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><path d="m8 12 4-4m-5 2-2 2a3 3 0 0 0 4 4l2-2m-2-8 2-2a3 3 0 0 1 4 4l-2 2"/></svg>${CHECK_ICON}</button>`}</h${b.level}>`;
|
|
394
394
|
case "p":
|
|
395
395
|
return `<p>${segmentsHtml(b.text, ctx, seg)}</p>`;
|
|
396
396
|
case "quote":
|
|
@@ -488,6 +488,6 @@ export const docHtml = (_fm, blocks, errors, ctx = emptyCtx, toc = []) => {
|
|
|
488
488
|
? `<div class="errors">${errors.map((e) => `<div>${escapeHtml(e)}</div>`).join("")}</div>`
|
|
489
489
|
: "";
|
|
490
490
|
const lang = ctx.lang ? ` lang="${escapeHtml(ctx.lang)}"` : "";
|
|
491
|
-
const controls = `${ctx.pageDownload ? resourceDownloadHtml(ctx.pageDownload.file, ctx.pageDownload.href) : ""}
|
|
491
|
+
const controls = `${inPageTocHtml(toc, ctx.tocTitle)}${ctx.pageDownload ? resourceDownloadHtml(ctx.pageDownload.file, ctx.pageDownload.href) : ""}`;
|
|
492
492
|
return `<article${lang}>${errBox}${controls ? `<header class="doc-title">${controls}</header>` : ""}${blocksHtml(blocks, ctx)}</article>`;
|
|
493
493
|
};
|
|
@@ -53,6 +53,7 @@ import { mountPanelResize } from "./resize.js";
|
|
|
53
53
|
import { mountDownloadBlock, mountResourceDownloads, mountResourceExpand, } from "./resource-download.js";
|
|
54
54
|
import { libraryPageHtml, resourceIndex, resourceLibraryHtml, resourceTabs, } from "./resource-library.js";
|
|
55
55
|
import { mountSearch, SEARCH_LABELS, searchIndex, searchSections } from "./search.js";
|
|
56
|
+
import { mountSectionFolds } from "./section-fold.js";
|
|
56
57
|
import { mountTables } from "./table-ui.js";
|
|
57
58
|
import { mountTerms } from "./terms-ui.js";
|
|
58
59
|
import { DARK_C, initializeThemes, LIGHT_C, mountThemePickers } from "./theme-picker.js";
|
|
@@ -540,7 +541,10 @@ main { --doc-mono: var(--reader-font, ${MONO_FONT}); }
|
|
|
540
541
|
gap: 2px; height: 36px; padding: 0 24px; pointer-events: none; z-index: 5; }
|
|
541
542
|
:is(.page-actions, .pane-actions) > .pbtn { pointer-events: auto; background: var(--c-bg0); }
|
|
542
543
|
.pane-actions > .pbtn { background: inherit; }
|
|
543
|
-
.page-actions { top: 0; margin: -20px -24px -
|
|
544
|
+
.page-actions { top: 0; margin: -20px -24px 16px; background: var(--c-bg0); }
|
|
545
|
+
.page-controls { display: flex; align-items: center; flex: 1; min-width: 0; gap: 4px; margin-right: auto; pointer-events: auto; }
|
|
546
|
+
.page-controls > .in-toc { min-width: 0; }
|
|
547
|
+
.page-controls .toc-current { width: 100%; }
|
|
544
548
|
.pbtn { flex: none; display: flex; align-items: center; justify-content: center; width: 28px; height: 28px;
|
|
545
549
|
padding: 0; color: var(--c-fg-faint); background: none; border: none; border-radius: 5px; cursor: pointer;
|
|
546
550
|
transition: color 120ms ease, background 120ms ease; }
|
|
@@ -866,7 +870,6 @@ article { max-width: 860px; margin: 0 auto; font-family: var(--reader-font, syst
|
|
|
866
870
|
.downloadable-resource:hover > .resource-download-tools, .resource-download-tools:focus-within { opacity: 1; }
|
|
867
871
|
.codeblk-head .resource-download { width: 16px; height: 16px; border-radius: 6px; color: var(--doc-fg-3); }
|
|
868
872
|
.codeblk-head .resource-download svg { width: 14px; height: 14px; }
|
|
869
|
-
.doc-title > .resource-download { align-self: center; }
|
|
870
873
|
.resource-download { display: inline-flex; flex: none; align-items: center; justify-content: center; box-sizing: border-box; width: 24px; height: 24px; border-radius: 4px; color: var(--doc-fg-2); text-decoration: none; }
|
|
871
874
|
.resource-download:hover { background: var(--doc-panel); color: var(--doc-accent); }
|
|
872
875
|
.resource-download:focus-visible { outline: 2px solid var(--doc-accent); outline-offset: 2px; }
|
|
@@ -942,21 +945,26 @@ ${PLUGIN_BLOCK_CSS}
|
|
|
942
945
|
article, article * { font-weight: 400; }
|
|
943
946
|
h1, h2, h3, h4, h5, h6 { font-weight: 400; }
|
|
944
947
|
article h1 { font-size: 26px; margin: 0 0 2px; }
|
|
945
|
-
article
|
|
946
|
-
|
|
948
|
+
article h1[id] { margin: 40px 0 12px; border-left: 3px solid var(--doc-accent); padding-left: 12px; }
|
|
949
|
+
article :is(h1, h2, h3, h4, h5, h6):has(> .section-copy) { position: relative; padding-right: 64px; }
|
|
950
|
+
.section-copy, .section-fold { position: absolute; right: 0; top: 0; display: flex; align-items: center; justify-content: center;
|
|
947
951
|
width: 28px; height: 28px; padding: 0; border: 0; border-radius: 4px; background: transparent;
|
|
948
952
|
color: var(--c-fg-faint); cursor: pointer; }
|
|
949
|
-
.section-copy:hover, .section-copy:focus-visible { background: var(--c-raised); color: var(--c-fg); }
|
|
950
|
-
.section-copy svg { flex: none; width: 16px; height: 16px; }
|
|
953
|
+
.section-copy:hover, .section-copy:focus-visible, .section-fold:hover, .section-fold:focus-visible { background: var(--c-raised); color: var(--c-fg); }
|
|
954
|
+
.section-copy svg, .section-fold svg { flex: none; width: 16px; height: 16px; }
|
|
955
|
+
.section-fold { right: 32px; }
|
|
956
|
+
.section-fold[aria-expanded="false"] svg { transform: rotate(-90deg); }
|
|
957
|
+
[data-section-hidden] { display: none !important; }
|
|
951
958
|
.section-copy .ic-ok, .section-copy.ok svg:not(.ic-ok), .section-copy.error svg { display: none; }
|
|
952
959
|
.section-copy.ok .ic-ok { display: block; color: var(--doc-ok); }
|
|
953
960
|
.section-copy.error::after { content: "!"; color: var(--c-danger); }
|
|
954
|
-
article h2 { font-size: 20px; margin-top:
|
|
961
|
+
article h2 { font-size: 20px; margin-top: 32px; margin-bottom: 8px; border-bottom: 1px solid
|
|
955
962
|
color-mix(in srgb, currentColor 20%, transparent); padding-bottom: 3px; }
|
|
956
|
-
article h3 { font-size: 16px; margin-top:
|
|
957
|
-
article h4 { font-size: 15px; margin-top:
|
|
958
|
-
article h5 { font-size: 14px; margin-top:
|
|
963
|
+
article h3 { font-size: 16px; margin-top: 24px; margin-bottom: 4px; }
|
|
964
|
+
article h4 { font-size: 15px; margin-top: 20px; margin-bottom: 4px; }
|
|
965
|
+
article h5 { font-size: 14px; margin-top: 16px; margin-bottom: 4px; }
|
|
959
966
|
article h6 { font-size: 13px; margin-top: 12px; margin-bottom: 4px; color: var(--doc-fg-2); }
|
|
967
|
+
article > :is(h1, h2, h3, h4, h5, h6)[id]:first-child, .doc-title + :is(h1, h2, h3, h4, h5, h6)[id] { margin-top: 0; }
|
|
960
968
|
:is(h2, h3, h4, h5, h6)[id] { scroll-margin-top: 12px; }
|
|
961
969
|
p { margin: 8px 0; }
|
|
962
970
|
ul, ol { margin: 4px 0; }
|
|
@@ -1092,7 +1100,8 @@ article a { color: var(--doc-accent); }
|
|
|
1092
1100
|
.callout-body > :last-child { margin-bottom: 0; }
|
|
1093
1101
|
.errors { border: 1px solid var(--doc-danger); border-radius: 8px; padding: 10px 16px;
|
|
1094
1102
|
margin-bottom: 16px; color: var(--doc-danger); font-size: 13px; }
|
|
1095
|
-
.doc-title { display: flex; align-items:
|
|
1103
|
+
.doc-title { display: flex; align-items: center; gap: 4px; margin-bottom: 16px; }
|
|
1104
|
+
.doc-title:empty { display: none; }
|
|
1096
1105
|
.in-toc { min-width: 28px; max-width: 100%; }
|
|
1097
1106
|
.toc-current { position: relative; display: block; max-width: min(240px, 100%); padding: 4px 20px 4px 6px;
|
|
1098
1107
|
overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border: 0; border-radius: 4px;
|
|
@@ -1111,11 +1120,6 @@ article a { color: var(--doc-accent); }
|
|
|
1111
1120
|
.in-toc .lvl5 a { padding-left: 50px; }
|
|
1112
1121
|
.in-toc .lvl6 a { padding-left: 60px; }
|
|
1113
1122
|
.in-toc a:hover, .in-toc a[aria-current] { color: var(--doc-accent); background: color-mix(in srgb, var(--doc-accent) 8%, transparent); }
|
|
1114
|
-
.doc-title:has(.toc-card) { display: block; max-width: none; }
|
|
1115
|
-
.toc-card { margin: 10px 0 14px; padding: 10px; border: 1px solid var(--doc-border); border-radius: 6px; }
|
|
1116
|
-
.toc-card::before { content: attr(aria-label); display: block; margin: 0 10px 6px; color: var(--doc-fg-3); font: 12px/1.5 var(--font-sans); }
|
|
1117
|
-
.toc-card .toc-current { display: none; }
|
|
1118
|
-
.toc-card .toc-options { position: static; padding: 0; border: 0; background: transparent; box-shadow: none; }
|
|
1119
1123
|
main :is(h1, h2, h3, h4, h5, h6)[id] { scroll-margin-top: 52px; }
|
|
1120
1124
|
article strong { font-weight: 700; }
|
|
1121
1125
|
article em { font-style: italic; }
|
|
@@ -1132,9 +1136,12 @@ ul.idx a > .nav-icon { width: 18px; height: 18px; }
|
|
|
1132
1136
|
#sidebar:has(.nav-root[data-document-link]) .site-title,
|
|
1133
1137
|
ul.idx a[data-document-link] .document-card-label {
|
|
1134
1138
|
color: color-mix(in srgb, var(--doc-accent-2) 85%, var(--doc-fg)); text-decoration: underline; text-underline-offset: 2px; }
|
|
1135
|
-
.document-web
|
|
1136
|
-
.document-web
|
|
1137
|
-
.document-web
|
|
1139
|
+
main:has(> article > .document-web) { position: relative; padding: 0; overflow: hidden; }
|
|
1140
|
+
main:has(> article > .document-web) > .page-actions { display: none; }
|
|
1141
|
+
.document-web { position: absolute; inset: 0; }
|
|
1142
|
+
.document-web-notice { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; background: var(--doc-bg); text-align: center; }
|
|
1143
|
+
.document-web-notice[hidden] { display: none; }
|
|
1144
|
+
.document-web-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
|
|
1138
1145
|
details summary { cursor: pointer; opacity: .8; }
|
|
1139
1146
|
/* Figure and term file links show previews on hover. */
|
|
1140
1147
|
.figref, .dictref { color: var(--doc-accent-2); text-decoration: none;
|
|
@@ -1871,7 +1878,7 @@ body.edit #nav-groups { --nav-rail: 22px; --nav-icon-half: 9px; }
|
|
|
1871
1878
|
main.editor-workspace { padding: 0; height: 100vh; display: flex; flex-direction: column; position: sticky; top: 0; }
|
|
1872
1879
|
#split-preview[aria-pressed="true"] { color: var(--c-accent); background: var(--c-raised); }
|
|
1873
1880
|
.resources-pane .pane-actions { display: none; }
|
|
1874
|
-
.pane-actions {
|
|
1881
|
+
.pane-actions { top: -20px; margin: -20px -24px 16px; padding: 4px 12px; min-height: 38px; background: inherit; }
|
|
1875
1882
|
.pane-resource { min-width: 0; }
|
|
1876
1883
|
#preview-panes { display: flex; flex: 1; min-height: 0; }
|
|
1877
1884
|
#preview-panes[hidden] { display: none; }
|
|
@@ -1884,6 +1891,8 @@ main.editor-workspace { padding: 0; height: 100vh; display: flex; flex-direction
|
|
|
1884
1891
|
#preview-panes.split .pane-actions { top: -16px; margin: -16px -16px 16px; padding-inline: 10px; }
|
|
1885
1892
|
#preview-panes.split .preview-pane + .preview-pane { border-left: 1px solid var(--c-line); }
|
|
1886
1893
|
#preview-panes.split .preview-pane.active { border-top-color: var(--c-accent); }
|
|
1894
|
+
#preview-panes .preview-pane:has(> .pane-resource .document-web, > .preview-content:not([hidden]) .document-web) { position: relative; padding: 0; border: 0; overflow: hidden; }
|
|
1895
|
+
.preview-pane:has(> .preview-content:not([hidden]) .document-web) > .pane-actions { display: none; }
|
|
1887
1896
|
.preview-pane:focus-visible { outline: 2px solid var(--c-accent); outline-offset: -2px; }
|
|
1888
1897
|
@media (max-width: 820px) {
|
|
1889
1898
|
body.edit:has(#panel) { display: grid; grid-template-columns: 52px minmax(0, 1fr); grid-template-rows: 50dvh 50dvh; height: 100dvh; min-height: 0; overflow: hidden; }
|
|
@@ -2582,6 +2591,7 @@ const localeFetch = (url, init = {}) => (${workspaceFetch.toString()})(url, { ..
|
|
|
2582
2591
|
(${mountTerms.toString()})(document);
|
|
2583
2592
|
(${mountTables.toString()})(document);
|
|
2584
2593
|
(${mountToc.toString()})(document);
|
|
2594
|
+
(${mountSectionFolds.toString()})(document);
|
|
2585
2595
|
(${mountVideos.toString()})(document);
|
|
2586
2596
|
${opts.publish ? "" : `(${mountFigurePreviews.toString()})(${workspaceFetch.toString()});`}
|
|
2587
2597
|
void (${mountFontPickers.toString()})(${createFontSettings.toString()}, ${JSON.stringify(site.fonts ?? []).replace(/</g, "\\u003c")});
|
|
@@ -3313,7 +3323,7 @@ ${opts.publish ? `${opts.publish.pages}<script>${publishRouterScript(opts.publis
|
|
|
3313
3323
|
const entryMain = (site, e) => {
|
|
3314
3324
|
if (e.url && /^https?:\/\//i.test(e.url)) {
|
|
3315
3325
|
const title = docDisplayName(e.frontmatter, e.id);
|
|
3316
|
-
return `<article><section class="document-web" data-web-url="${escapeHtml(e.url)}" data-title="${escapeHtml(title)}"><div class="document-web-
|
|
3326
|
+
return `<article><section class="document-web" data-web-url="${escapeHtml(e.url)}" data-title="${escapeHtml(title)}"><div class="document-web-notice"><p data-web-status role="status" data-i18n="Loading website…">Loading website…</p><a href="${escapeHtml(e.url)}" data-web-open data-i18n="Open externally" hidden>Open externally</a></div></section></article>`;
|
|
3317
3327
|
}
|
|
3318
3328
|
if (e.url && pageUrlKind(e.url) === "file")
|
|
3319
3329
|
return (linkedFilePage(site, e.url)?.main ??
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** Self-contained so live readers and standalone HTML use the same click behavior. */
|
|
2
2
|
export const mountDocumentLinks = (dialog, network = true, request) => {
|
|
3
3
|
const t = (text) => window.__docsTranslate?.(text) ?? text;
|
|
4
|
-
const mobile = () => matchMedia("(max-width: 600px), (hover: none) and (pointer: coarse)").matches;
|
|
5
4
|
const webUrl = (value) => {
|
|
6
5
|
if (!value)
|
|
7
6
|
return;
|
|
@@ -45,7 +44,7 @@ export const mountDocumentLinks = (dialog, network = true, request) => {
|
|
|
45
44
|
event.preventDefault();
|
|
46
45
|
window.open(url, "_blank", "noopener,noreferrer");
|
|
47
46
|
}
|
|
48
|
-
else if (link.hasAttribute("data-web-open") ||
|
|
47
|
+
else if (link.hasAttribute("data-web-open") || !network) {
|
|
49
48
|
event.preventDefault();
|
|
50
49
|
void confirm(url);
|
|
51
50
|
}
|
|
@@ -55,16 +54,19 @@ export const mountDocumentLinks = (dialog, network = true, request) => {
|
|
|
55
54
|
const mounted = new WeakSet();
|
|
56
55
|
const mount = () => {
|
|
57
56
|
for (const host of document.querySelectorAll(".document-web[data-web-url]")) {
|
|
58
|
-
if (mounted.has(host))
|
|
57
|
+
if (mounted.has(host) || host.querySelector(".document-web-frame"))
|
|
59
58
|
continue;
|
|
60
59
|
mounted.add(host);
|
|
61
60
|
const url = webUrl(host.dataset.webUrl);
|
|
61
|
+
const notice = host.querySelector(".document-web-notice");
|
|
62
62
|
const status = host.querySelector("[data-web-status]");
|
|
63
|
-
|
|
63
|
+
const external = host.querySelector("[data-web-open]");
|
|
64
|
+
if (!url || !notice || !status || !external)
|
|
64
65
|
continue;
|
|
65
|
-
if (
|
|
66
|
+
if (!network) {
|
|
66
67
|
status.dataset.i18n = "Open this website externally to view it.";
|
|
67
68
|
status.textContent = t(status.dataset.i18n);
|
|
69
|
+
external.hidden = false;
|
|
68
70
|
void confirm(url);
|
|
69
71
|
continue;
|
|
70
72
|
}
|
|
@@ -73,32 +75,40 @@ export const mountDocumentLinks = (dialog, network = true, request) => {
|
|
|
73
75
|
frame.title = host.dataset.title || url;
|
|
74
76
|
frame.referrerPolicy = "no-referrer";
|
|
75
77
|
frame.sandbox.add("allow-scripts", "allow-forms", "allow-popups");
|
|
76
|
-
let
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
78
|
+
let blocked = false;
|
|
79
|
+
const showStatus = (message) => {
|
|
80
|
+
if (blocked || !host.isConnected)
|
|
79
81
|
return;
|
|
80
|
-
|
|
81
|
-
clearTimeout(timer);
|
|
82
|
-
document.removeEventListener("securitypolicyviolation", violation);
|
|
83
|
-
if (!host.isConnected)
|
|
84
|
-
return;
|
|
85
|
-
status.hidden = false;
|
|
82
|
+
notice.hidden = false;
|
|
86
83
|
status.dataset.i18n = message;
|
|
87
84
|
status.textContent = t(message);
|
|
85
|
+
};
|
|
86
|
+
const denied = () => {
|
|
87
|
+
if (blocked || !host.isConnected)
|
|
88
|
+
return;
|
|
89
|
+
const message = "This website could not be displayed here. Open it externally?";
|
|
90
|
+
showStatus(message);
|
|
91
|
+
blocked = true;
|
|
92
|
+
clearTimeout(timer);
|
|
93
|
+
document.removeEventListener("securitypolicyviolation", violation);
|
|
94
|
+
external.hidden = false;
|
|
88
95
|
void confirm(url, message);
|
|
89
96
|
};
|
|
90
|
-
const timer = setTimeout(() =>
|
|
91
|
-
frame.onerror = () =>
|
|
97
|
+
const timer = setTimeout(() => showStatus("This website has not loaded."), 12000);
|
|
98
|
+
frame.onerror = () => {
|
|
99
|
+
clearTimeout(timer);
|
|
100
|
+
showStatus("This website could not be loaded.");
|
|
101
|
+
};
|
|
92
102
|
frame.onload = () => {
|
|
93
103
|
clearTimeout(timer);
|
|
94
104
|
document.removeEventListener("securitypolicyviolation", violation);
|
|
95
|
-
if (!
|
|
96
|
-
|
|
105
|
+
if (!blocked)
|
|
106
|
+
notice.hidden = true;
|
|
97
107
|
};
|
|
98
|
-
// shortcut: Browsers hide some cross-origin frame denials; retain
|
|
108
|
+
// shortcut: Browsers hide some cross-origin frame denials; retain new-tab navigation as a fallback.
|
|
99
109
|
const violation = (event) => {
|
|
100
110
|
if (event.effectiveDirective === "frame-src" && event.blockedURI === url)
|
|
101
|
-
|
|
111
|
+
denied();
|
|
102
112
|
};
|
|
103
113
|
document.addEventListener("securitypolicyviolation", violation);
|
|
104
114
|
frame.src = url;
|
|
@@ -107,7 +117,7 @@ export const mountDocumentLinks = (dialog, network = true, request) => {
|
|
|
107
117
|
void request(`/api/frame-policy?url=${encodeURIComponent(host.dataset.webUrl ?? url)}&parent=${encodeURIComponent(location.origin)}`)
|
|
108
118
|
.then(async (response) => {
|
|
109
119
|
if (response.ok && (await response.json()).blocked === true)
|
|
110
|
-
|
|
120
|
+
denied();
|
|
111
121
|
})
|
|
112
122
|
.catch(() => { });
|
|
113
123
|
}
|
|
@@ -448,6 +448,7 @@
|
|
|
448
448
|
"Open this website in a new tab?": "Open this website in a new tab?",
|
|
449
449
|
"Open this website externally to view it.": "Open this website externally to view it.",
|
|
450
450
|
"This website could not be displayed here. Open it externally?": "This website could not be displayed here. Open it externally?",
|
|
451
|
-
"This website has not loaded.
|
|
451
|
+
"This website has not loaded.": "This website has not loaded.",
|
|
452
|
+
"This website could not be loaded.": "This website could not be loaded.",
|
|
452
453
|
"Loading website…": "Loading website…"
|
|
453
454
|
}
|
|
@@ -448,6 +448,7 @@
|
|
|
448
448
|
"Open this website in a new tab?": "このWebサイトを新しいタブで開きますか?",
|
|
449
449
|
"Open this website externally to view it.": "このWebサイトは外部で開いて表示できます。",
|
|
450
450
|
"This website could not be displayed here. Open it externally?": "ここではWebサイトを表示できませんでした。外部で開きますか?",
|
|
451
|
-
"This website has not loaded.
|
|
451
|
+
"This website has not loaded.": "Webサイトの読み込みが完了していません。",
|
|
452
|
+
"This website could not be loaded.": "Webサイトを読み込めませんでした。",
|
|
452
453
|
"Loading website…": "Webサイトを読み込み中…"
|
|
453
454
|
}
|
|
@@ -448,6 +448,7 @@
|
|
|
448
448
|
"Open this website in a new tab?": "在新标签页中打开此网站?",
|
|
449
449
|
"Open this website externally to view it.": "请在外部打开此网站。",
|
|
450
450
|
"This website could not be displayed here. Open it externally?": "无法在此显示该网站。在外部打开?",
|
|
451
|
-
"This website has not loaded.
|
|
451
|
+
"This website has not loaded.": "此网站尚未加载。",
|
|
452
|
+
"This website could not be loaded.": "无法加载此网站。",
|
|
452
453
|
"Loading website…": "正在加载网站…"
|
|
453
454
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Self-contained so editor previews and standalone readers share section folding. */
|
|
2
|
+
export function mountSectionFolds(doc) {
|
|
3
|
+
const content = (heading) => {
|
|
4
|
+
const result = [];
|
|
5
|
+
const level = Number(heading.tagName[1]);
|
|
6
|
+
for (let node = heading.nextElementSibling; node; node = node.nextElementSibling) {
|
|
7
|
+
if (/^H[1-6]$/.test(node.tagName) && Number(node.tagName[1]) <= level)
|
|
8
|
+
break;
|
|
9
|
+
result.push(node);
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
const collapsed = () => doc.querySelectorAll('.section-fold[aria-expanded="false"]');
|
|
14
|
+
const expanded = (button, value) => {
|
|
15
|
+
button.setAttribute("aria-expanded", String(value));
|
|
16
|
+
const label = value ? "Collapse section" : "Expand section";
|
|
17
|
+
button.dataset.i18nTitle = button.dataset.i18nAriaLabel = label;
|
|
18
|
+
button.title =
|
|
19
|
+
window.__docsTranslate?.(label) ?? label;
|
|
20
|
+
button.setAttribute("aria-label", button.title);
|
|
21
|
+
};
|
|
22
|
+
const apply = () => {
|
|
23
|
+
for (const node of doc.querySelectorAll("[data-section-hidden]"))
|
|
24
|
+
node.removeAttribute("data-section-hidden");
|
|
25
|
+
for (const button of collapsed())
|
|
26
|
+
if (button.parentElement)
|
|
27
|
+
for (const node of content(button.parentElement))
|
|
28
|
+
node.setAttribute("data-section-hidden", "");
|
|
29
|
+
};
|
|
30
|
+
const reveal = (target) => {
|
|
31
|
+
for (const button of collapsed()) {
|
|
32
|
+
const heading = button.parentElement;
|
|
33
|
+
if (heading &&
|
|
34
|
+
(heading === target || content(heading).some((node) => node.contains(target))))
|
|
35
|
+
expanded(button, true);
|
|
36
|
+
}
|
|
37
|
+
apply();
|
|
38
|
+
};
|
|
39
|
+
const revealHash = (hash, scope) => {
|
|
40
|
+
if (!hash)
|
|
41
|
+
return null;
|
|
42
|
+
try {
|
|
43
|
+
const id = decodeURIComponent(hash.slice(hash.lastIndexOf("#") + 1));
|
|
44
|
+
const target = scope.querySelector(`#${CSS.escape(id)}`);
|
|
45
|
+
if (target)
|
|
46
|
+
reveal(target);
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
doc.addEventListener("click", (event) => {
|
|
54
|
+
if (!(event.target instanceof Element))
|
|
55
|
+
return;
|
|
56
|
+
const button = event.target.closest(".section-fold");
|
|
57
|
+
if (button) {
|
|
58
|
+
expanded(button, button.getAttribute("aria-expanded") !== "true");
|
|
59
|
+
apply();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const link = event.target.closest("a[href]");
|
|
63
|
+
if (link?.origin === location.origin && link.pathname === location.pathname)
|
|
64
|
+
revealHash(link.hash, link.closest(".preview-pane") ?? doc);
|
|
65
|
+
}, true);
|
|
66
|
+
doc.addEventListener("docs:reveal-section", (event) => {
|
|
67
|
+
if (event.target instanceof Element)
|
|
68
|
+
reveal(event.target);
|
|
69
|
+
});
|
|
70
|
+
window.addEventListener("hashchange", () => {
|
|
71
|
+
revealHash(location.hash, doc.querySelector(".preview-pane.active") ?? doc)?.scrollIntoView({
|
|
72
|
+
block: "start",
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
new MutationObserver(apply).observe(doc.querySelector("main") ?? doc.body, {
|
|
76
|
+
childList: true,
|
|
77
|
+
subtree: true,
|
|
78
|
+
});
|
|
79
|
+
apply();
|
|
80
|
+
}
|
package/dist/frontend/toc-ui.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Self-contained so live previews and standalone HTML share the same navigation. */
|
|
2
2
|
export function mountToc(doc) {
|
|
3
|
+
const owner = doc;
|
|
4
|
+
owner.__docsTocDispose?.();
|
|
3
5
|
const controller = new AbortController();
|
|
4
6
|
const mounted = new Map();
|
|
5
7
|
let sequence = 0;
|
|
@@ -15,28 +17,47 @@ export function mountToc(doc) {
|
|
|
15
17
|
};
|
|
16
18
|
const resize = new ResizeObserver(schedule);
|
|
17
19
|
const initialize = () => {
|
|
18
|
-
for (const [
|
|
19
|
-
if (!
|
|
20
|
+
for (const [toolbar, { article, dispose }] of mounted)
|
|
21
|
+
if (!toolbar.isConnected || !article.isConnected) {
|
|
20
22
|
dispose();
|
|
21
23
|
resize.unobserve(article);
|
|
22
|
-
mounted.delete(
|
|
23
|
-
nav.remove();
|
|
24
|
+
mounted.delete(toolbar);
|
|
24
25
|
}
|
|
25
|
-
for (const
|
|
26
|
-
if (mounted.has(
|
|
26
|
+
for (const toolbar of doc.querySelectorAll("article > .doc-title")) {
|
|
27
|
+
if (mounted.has(toolbar))
|
|
27
28
|
continue;
|
|
28
|
-
const article =
|
|
29
|
-
|
|
30
|
-
const list = nav.querySelector("ul");
|
|
31
|
-
if (!article || !button || !list)
|
|
32
|
-
continue;
|
|
33
|
-
const pane = nav.closest(".preview-pane");
|
|
34
|
-
const scroller = pane ?? nav.closest("main") ?? doc.scrollingElement;
|
|
35
|
-
if (!scroller)
|
|
29
|
+
const article = toolbar.closest("article");
|
|
30
|
+
if (!article)
|
|
36
31
|
continue;
|
|
32
|
+
const pane = toolbar.closest(".preview-pane");
|
|
33
|
+
const scroller = pane ?? toolbar.closest("main") ?? doc.scrollingElement;
|
|
37
34
|
const header = (pane ?? article.parentElement)?.querySelector(":scope > .pane-actions, :scope > .page-actions");
|
|
38
35
|
const listeners = new AbortController();
|
|
39
36
|
const options = { signal: listeners.signal };
|
|
37
|
+
const controls = header ? doc.createElement("div") : toolbar;
|
|
38
|
+
if (header) {
|
|
39
|
+
controls.className = "page-controls";
|
|
40
|
+
controls.append(...toolbar.childNodes);
|
|
41
|
+
header.prepend(controls);
|
|
42
|
+
}
|
|
43
|
+
// The empty toolbar stays with the article so live updates can retire its controls.
|
|
44
|
+
const state = {
|
|
45
|
+
article,
|
|
46
|
+
update: () => { },
|
|
47
|
+
dispose: () => {
|
|
48
|
+
listeners.abort();
|
|
49
|
+
if (controls !== toolbar) {
|
|
50
|
+
toolbar.append(...controls.childNodes);
|
|
51
|
+
controls.remove();
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
mounted.set(toolbar, state);
|
|
56
|
+
const nav = controls.querySelector(".in-toc");
|
|
57
|
+
const button = nav?.querySelector(".toc-current");
|
|
58
|
+
const list = nav?.querySelector("ul");
|
|
59
|
+
if (!nav || !button || !list || !scroller)
|
|
60
|
+
continue;
|
|
40
61
|
list.id = `toc-options-${++sequence}`;
|
|
41
62
|
button.setAttribute("aria-controls", list.id);
|
|
42
63
|
const sections = [...nav.querySelectorAll("[data-toc-target]")]
|
|
@@ -46,30 +67,18 @@ export function mountToc(doc) {
|
|
|
46
67
|
}))
|
|
47
68
|
.filter((section) => section.heading !== null);
|
|
48
69
|
let active;
|
|
49
|
-
let card = false;
|
|
50
70
|
const update = () => {
|
|
51
|
-
const narrow = article.clientWidth < 520;
|
|
52
|
-
if (card !== narrow) {
|
|
53
|
-
card = narrow;
|
|
54
|
-
const focused = nav.contains(doc.activeElement);
|
|
55
|
-
list.popover = card ? null : "auto";
|
|
56
|
-
list.removeAttribute("style");
|
|
57
|
-
nav.classList.toggle("toc-card", card);
|
|
58
|
-
if (focused)
|
|
59
|
-
(card ? (active ?? sections[0]?.link) : button)?.focus({
|
|
60
|
-
preventScroll: true,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
71
|
const top = (header?.getBoundingClientRect().bottom ??
|
|
64
72
|
pane?.getBoundingClientRect().top ??
|
|
65
73
|
0) + 20;
|
|
66
74
|
let current = sections[0];
|
|
67
75
|
for (const section of sections)
|
|
68
|
-
if (
|
|
76
|
+
if (!section.heading?.closest("[data-section-hidden]") &&
|
|
77
|
+
(section.heading?.getBoundingClientRect().top ?? Infinity) <= top)
|
|
69
78
|
current = section;
|
|
70
79
|
if (scroller.scrollTop > 0 &&
|
|
71
80
|
scroller.scrollTop >= scroller.scrollHeight - scroller.clientHeight - 1)
|
|
72
|
-
current = sections.
|
|
81
|
+
current = sections.findLast((section) => !section.heading?.closest("[data-section-hidden]"));
|
|
73
82
|
if (current?.link === active)
|
|
74
83
|
return;
|
|
75
84
|
active?.removeAttribute("aria-current");
|
|
@@ -97,8 +106,6 @@ export function mountToc(doc) {
|
|
|
97
106
|
button.setAttribute("aria-expanded", String(list.matches(":popover-open")));
|
|
98
107
|
}, options);
|
|
99
108
|
list.addEventListener("keydown", (event) => {
|
|
100
|
-
if (card)
|
|
101
|
-
return;
|
|
102
109
|
const index = sections.findIndex(({ link }) => link === doc.activeElement);
|
|
103
110
|
if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) {
|
|
104
111
|
event.preventDefault();
|
|
@@ -125,17 +132,16 @@ export function mountToc(doc) {
|
|
|
125
132
|
const heading = sections.find((section) => section.link === link)?.heading;
|
|
126
133
|
if (!heading)
|
|
127
134
|
return;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
135
|
+
list.hidePopover();
|
|
136
|
+
button.focus({ preventScroll: true });
|
|
137
|
+
heading.dispatchEvent(new Event("docs:reveal-section", { bubbles: true }));
|
|
132
138
|
if (pane) {
|
|
133
139
|
// Pane activation is asynchronous, so resolve the clicked pane directly.
|
|
134
140
|
event.preventDefault();
|
|
135
141
|
heading.scrollIntoView({ block: "start" });
|
|
136
142
|
}
|
|
137
143
|
}, options);
|
|
138
|
-
|
|
144
|
+
state.update = update;
|
|
139
145
|
resize.observe(article);
|
|
140
146
|
}
|
|
141
147
|
schedule();
|
|
@@ -151,7 +157,7 @@ export function mountToc(doc) {
|
|
|
151
157
|
doc.addEventListener("docs:font-change", schedule, { signal: controller.signal });
|
|
152
158
|
window.addEventListener("resize", schedule, { signal: controller.signal });
|
|
153
159
|
initialize();
|
|
154
|
-
|
|
160
|
+
const dispose = () => {
|
|
155
161
|
controller.abort();
|
|
156
162
|
observer.disconnect();
|
|
157
163
|
resize.disconnect();
|
|
@@ -160,4 +166,6 @@ export function mountToc(doc) {
|
|
|
160
166
|
dispose();
|
|
161
167
|
mounted.clear();
|
|
162
168
|
};
|
|
169
|
+
owner.__docsTocDispose = dispose;
|
|
170
|
+
return dispose;
|
|
163
171
|
}
|