hdoc-tools 0.52.1 → 0.54.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/hdoc-build.js +83 -12
- package/hdoc-content-routes.js +343 -0
- package/hdoc-edit.js +5 -0
- package/hdoc-serve.js +11 -0
- package/npm-shrinkwrap.json +66 -2
- package/package.json +3 -1
- package/ui/js/doc.hornbill.js +99 -0
- package/ui/js/mermaid.min.js +3435 -0
package/ui/js/doc.hornbill.js
CHANGED
|
@@ -7,6 +7,102 @@ let jqDocumentHeader = null;
|
|
|
7
7
|
let jqLeftNav = null;
|
|
8
8
|
const global = { stateParams: {}, lastLayoutClass: "" };
|
|
9
9
|
|
|
10
|
+
//-- Mermaid client-side rendering config — mirrors templates/mermaid-theme.yaml.
|
|
11
|
+
//-- (PDFs are still rendered to SVG server-side by hdoc build; this is HTML-only.)
|
|
12
|
+
const HB_MERMAID_CONFIG = {
|
|
13
|
+
startOnLoad: false,
|
|
14
|
+
theme: "base",
|
|
15
|
+
themeVariables: {
|
|
16
|
+
background: "transparent",
|
|
17
|
+
fontSize: "14px",
|
|
18
|
+
primaryColor: "#85D2FF",
|
|
19
|
+
primaryColorLight: "#85D2FF",
|
|
20
|
+
primaryColorDark: "#0065CB",
|
|
21
|
+
secondaryColor: "#219BFF",
|
|
22
|
+
secondaryColorLight: "#85D2FF",
|
|
23
|
+
secondaryColorDark: "#0C4C8C",
|
|
24
|
+
tertiaryColor: "#219BFF",
|
|
25
|
+
tertiaryColorLight: "#85D2FF",
|
|
26
|
+
tertiaryColorDark: "#0C4C8C",
|
|
27
|
+
lineColor: "#808080",
|
|
28
|
+
border1: "#606060",
|
|
29
|
+
textColor: "#A0A0A0",
|
|
30
|
+
titleColor: "#A0A0A0",
|
|
31
|
+
labelColor: "#404040",
|
|
32
|
+
loopTextColor: "#A0A0A0",
|
|
33
|
+
nodeTextColor: "#404040",
|
|
34
|
+
labelTextColor: "#404040",
|
|
35
|
+
pieSectionTextColor: "#404040",
|
|
36
|
+
nodeBorder: "#219BFF",
|
|
37
|
+
nodeBg: "transparent",
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//-- Lazy-load the Mermaid bundle (~3MB) only when a page actually contains a
|
|
42
|
+
//-- diagram. Resolves to window.mermaid, initialised once.
|
|
43
|
+
let hbMermaidLoadPromise = null;
|
|
44
|
+
function hbLoadMermaid() {
|
|
45
|
+
if (window.mermaid) return Promise.resolve(window.mermaid);
|
|
46
|
+
if (hbMermaidLoadPromise) return hbMermaidLoadPromise;
|
|
47
|
+
hbMermaidLoadPromise = new Promise((resolve, reject) => {
|
|
48
|
+
const el = document.createElement("script");
|
|
49
|
+
el.src = "js/mermaid.min.js"; //-- resolves against <base href> (site root)
|
|
50
|
+
el.onload = () => {
|
|
51
|
+
try {
|
|
52
|
+
window.mermaid.initialize(HB_MERMAID_CONFIG);
|
|
53
|
+
resolve(window.mermaid);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
reject(e);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
el.onerror = () => reject(new Error("failed to load js/mermaid.min.js"));
|
|
59
|
+
document.head.appendChild(el);
|
|
60
|
+
});
|
|
61
|
+
return hbMermaidLoadPromise;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//-- Inject the spinner styles once. While a <pre class="mermaid"> has no
|
|
65
|
+
//-- data-processed attr (set by mermaid.run() once rendered) we collapse its raw
|
|
66
|
+
//-- source text and show a spinner in its place.
|
|
67
|
+
function hbEnsureMermaidStyles() {
|
|
68
|
+
if (document.getElementById("hb-mermaid-style")) return;
|
|
69
|
+
const style = document.createElement("style");
|
|
70
|
+
style.id = "hb-mermaid-style";
|
|
71
|
+
style.textContent =
|
|
72
|
+
"pre.mermaid:not([data-processed]){font-size:0!important;line-height:0!important;min-height:140px;display:flex;align-items:center;justify-content:center;background:none!important;border:none!important;}" +
|
|
73
|
+
'pre.mermaid:not([data-processed])::after{content:"";width:32px;height:32px;border:3px solid rgba(33,155,255,.25);border-top-color:#219BFF;border-radius:50%;animation:hbMermaidSpin .8s linear infinite;}' +
|
|
74
|
+
"@keyframes hbMermaidSpin{to{transform:rotate(360deg);}}";
|
|
75
|
+
document.head.appendChild(style);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//-- Render any not-yet-processed <pre class="mermaid"> blocks in the current doc.
|
|
79
|
+
//-- mermaid.run() tags each node with data-processed, so re-running after a
|
|
80
|
+
//-- navigation only renders freshly-injected diagrams.
|
|
81
|
+
function hbRenderMermaidDiagrams() {
|
|
82
|
+
hbEnsureMermaidStyles();
|
|
83
|
+
const nodes = document.querySelectorAll(
|
|
84
|
+
"#DocContent pre.mermaid:not([data-processed])",
|
|
85
|
+
);
|
|
86
|
+
if (!nodes.length) return;
|
|
87
|
+
//-- On any failure, mark nodes processed so the spinner stops (reveals source
|
|
88
|
+
//-- rather than spinning forever).
|
|
89
|
+
const reveal = (err) => {
|
|
90
|
+
hslDocLog.log("Mermaid render failed", err);
|
|
91
|
+
for (const n of nodes) n.setAttribute("data-processed", "true");
|
|
92
|
+
};
|
|
93
|
+
hbLoadMermaid()
|
|
94
|
+
.then((mermaid) => mermaid.run({ nodes }))
|
|
95
|
+
.catch(reveal);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//-- Warm the Mermaid bundle (~4.5MB) immediately on first script run so it's
|
|
99
|
+
//-- downloading/parsing in the background regardless of whether THIS page has a
|
|
100
|
+
//-- diagram. By the time the user reaches a diagram page it's ready and the swap
|
|
101
|
+
//-- is instant. The bundle is served with a long cache header, so it downloads
|
|
102
|
+
//-- once per browser, not once per page.
|
|
103
|
+
hbEnsureMermaidStyles();
|
|
104
|
+
hbLoadMermaid().catch(() => {});
|
|
105
|
+
|
|
10
106
|
const docAppMethods = {
|
|
11
107
|
setSessionInfo: function (info) {
|
|
12
108
|
this.docApp.userSession = info;
|
|
@@ -383,6 +479,9 @@ function loadContentUrl(
|
|
|
383
479
|
);
|
|
384
480
|
}
|
|
385
481
|
|
|
482
|
+
//-- render any Mermaid diagrams client-side (lazy-loads the bundle)
|
|
483
|
+
hbRenderMermaidDiagrams();
|
|
484
|
+
|
|
386
485
|
//-- show copy button by any code blocks
|
|
387
486
|
const options = {
|
|
388
487
|
contentSelector: ".injected-document-content",
|