@x-tech-laboratories/x-app 0.127.0 → 0.128.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/README.md +2 -3
- package/dist/site/build.js +4 -8
- package/dist/site/markdown.d.ts +0 -2
- package/dist/site/markdown.js +1 -20
- package/dist/web/react/site.d.ts +1 -3
- package/dist/web/react/site.js +5 -48
- package/dist/web/site/client.d.ts +1 -5
- package/dist/web/site/client.js +3 -3
- package/package.json +1 -5
- package/dist/web/site/mermaid.d.ts +0 -11
- package/dist/web/site/mermaid.js +0 -65
package/README.md
CHANGED
|
@@ -820,9 +820,8 @@ so it reads without JavaScript and its search, outline, menus and theme work wit
|
|
|
820
820
|
- **GitHub's own Markdown**: alerts such as `> [!TIP]` show as asides and raw HTML such as a table of pictures is
|
|
821
821
|
kept, so a page reads the same on GitHub and on the site; a page with no `title` takes its opening `# heading`, which
|
|
822
822
|
is then not drawn twice, so an MDX page can show a README with `import Readme from "../README.md"`; links that start at the root move under the base in Markdown and in a component's `href` or `src`.
|
|
823
|
-
- **Diagrams**:
|
|
824
|
-
|
|
825
|
-
JavaScript. The browser loads mermaid only on a site with a diagram, which adds `mermaid` to its own dependencies.
|
|
823
|
+
- **Diagrams**: images like any other. Draw them in [draw.io](https://www.drawio.com/), keep the `.drawio` source beside
|
|
824
|
+
its PNG export in `public/`, and show the PNG; a ```` ```mermaid ```` block is only code.
|
|
826
825
|
- **Pages beside a package**: the scan skips `node_modules`, `dist`, `public` and hidden folders, so a site can live in
|
|
827
826
|
an app's `docs/` folder with a `package.json` of its own.
|
|
828
827
|
|
package/dist/site/build.js
CHANGED
|
@@ -16,7 +16,7 @@ import { pathToFileURL } from "node:url";
|
|
|
16
16
|
import { build, createServer, preview } from "vite";
|
|
17
17
|
import { text_direction } from "../i18n.js";
|
|
18
18
|
import { read_content } from "./content.js";
|
|
19
|
-
import {
|
|
19
|
+
import { mdx_plugin } from "./markdown.js";
|
|
20
20
|
import { build_sidebar, extract_headings, neighbours, page_path, plan_routes, root_locale, site_locales, with_base, } from "./model.js";
|
|
21
21
|
import { messages_for } from "./ui_strings.js";
|
|
22
22
|
// ── The project ──────────────────────────────────────────────────────────────
|
|
@@ -106,8 +106,8 @@ export function page_data(project, plan, route, locale = route?.locale ?? root_l
|
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
// ── Vite ─────────────────────────────────────────────────────────────────────
|
|
109
|
-
// The entries Vite starts from: the page modules by content file, the browser's entry with the site's stylesheets
|
|
110
|
-
//
|
|
109
|
+
// The entries Vite starts from: the page modules by content file, the browser's entry with the site's stylesheets, and the
|
|
110
|
+
// server's; written only when they change, so the dev server does not
|
|
111
111
|
// reload for nothing.
|
|
112
112
|
export function write_entries(project, plan) {
|
|
113
113
|
mkdirSync(project.work_folder, { recursive: true });
|
|
@@ -117,13 +117,9 @@ export function write_entries(project, plan) {
|
|
|
117
117
|
};
|
|
118
118
|
const page_lines = plan.pages.map((page) => ` ${JSON.stringify(page.id)}: () => import(${JSON.stringify(from_work(join(project.content_folder, page.id)))}),`);
|
|
119
119
|
const css_lines = (project.config.css ?? []).map((sheet) => `import ${JSON.stringify(sheet.startsWith(".") ? from_work(resolve(project.root, sheet)) : sheet)};`);
|
|
120
|
-
const draws_diagrams = plan.pages.some((page) => has_mermaid(readFileSync(join(project.content_folder, page.id), "utf8")));
|
|
121
|
-
const start = draws_diagrams
|
|
122
|
-
? `import { mermaid_drawer } from "@x-tech-laboratories/x-app/web/site/mermaid";\nimport { pages } from "./pages.js";\n\nstart_site(pages, { draw_diagram: mermaid_drawer(() => import("mermaid")) });\n`
|
|
123
|
-
: `import { pages } from "./pages.js";\n\nstart_site(pages);\n`;
|
|
124
120
|
const files = {
|
|
125
121
|
"pages.js": `export const pages = {\n${page_lines.join("\n")}\n};\n`,
|
|
126
|
-
"client.js": `${css_lines.join("\n")}\nimport { start_site } from "@x-tech-laboratories/x-app/web/site/client";\
|
|
122
|
+
"client.js": `${css_lines.join("\n")}\nimport { start_site } from "@x-tech-laboratories/x-app/web/site/client";\nimport { pages } from "./pages.js";\n\nstart_site(pages);\n`,
|
|
127
123
|
"server.js": `export { load_content, render_content, render_page } from "@x-tech-laboratories/x-app/web/site/server";\nexport { pages } from "./pages.js";\n`,
|
|
128
124
|
".gitignore": "*\n",
|
|
129
125
|
};
|
package/dist/site/markdown.d.ts
CHANGED
|
@@ -4,6 +4,4 @@ import type { Plugin } from "vite";
|
|
|
4
4
|
export declare function rehype_base_links(base: string): (tree: Root) => void;
|
|
5
5
|
export declare function remark_github_alerts(): (tree: MarkdownRoot) => void;
|
|
6
6
|
export declare function remark_drop_title_heading(): (tree: MarkdownRoot) => void;
|
|
7
|
-
export declare function rehype_mermaid_blocks(): (tree: Root) => void;
|
|
8
|
-
export declare function has_mermaid(text: string): boolean;
|
|
9
7
|
export declare function mdx_plugin(base: string): Plugin;
|
package/dist/site/markdown.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// How a site's Markdown and MDX become pages, on MDX's own compiler: GitHub's tables, task lists, autolinks, alerts
|
|
2
2
|
// and raw HTML, frontmatter and a leading title heading kept out of the page, an id and an anchor link on every heading, code coloured by Shiki through Halon's
|
|
3
|
-
// tokens,
|
|
3
|
+
// tokens, and links within the site moved under its base.
|
|
4
4
|
import mdx from "@mdx-js/rollup";
|
|
5
5
|
import rehype_shiki from "@shikijs/rehype";
|
|
6
6
|
import rehype_autolink_headings from "rehype-autolink-headings";
|
|
@@ -76,24 +76,6 @@ export function remark_drop_title_heading() {
|
|
|
76
76
|
tree.children.splice(index, 1);
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
// A ```mermaid block kept as its source in a marked <pre>, which the page draws as a diagram and Shiki leaves alone.
|
|
80
|
-
export function rehype_mermaid_blocks() {
|
|
81
|
-
return (tree) => {
|
|
82
|
-
visit(tree, "element", (node) => {
|
|
83
|
-
const code = node.tagName === "pre" ? node.children.find((child) => child.type === "element" && child.tagName === "code") : undefined;
|
|
84
|
-
const classes = code?.properties.className;
|
|
85
|
-
if (!code || !Array.isArray(classes) || !classes.includes("language-mermaid"))
|
|
86
|
-
return;
|
|
87
|
-
const source = code.children.map((child) => (child.type === "text" ? child.value : "")).join("");
|
|
88
|
-
node.properties = { dataMermaid: "" };
|
|
89
|
-
node.children = [{ type: "text", value: source }];
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
// Whether a page's Markdown holds a ```mermaid block, so the site's browser entry loads mermaid.
|
|
94
|
-
export function has_mermaid(text) {
|
|
95
|
-
return /^[ \t]*(```|~~~)[ \t]*mermaid\b/m.test(text);
|
|
96
|
-
}
|
|
97
79
|
// MDX's own nodes, which raw HTML parsing must pass through untouched.
|
|
98
80
|
const mdx_node_types = ["mdxFlowExpression", "mdxJsxFlowElement", "mdxJsxTextElement", "mdxTextExpression", "mdxjsEsm"];
|
|
99
81
|
export function mdx_plugin(base) {
|
|
@@ -104,7 +86,6 @@ export function mdx_plugin(base) {
|
|
|
104
86
|
[rehype_raw, { passThrough: mdx_node_types }],
|
|
105
87
|
rehype_slug,
|
|
106
88
|
[rehype_autolink_headings, { behavior: "append", properties: { className: ["heading-anchor"], ariaHidden: "true", tabIndex: -1, dataPagefindIgnore: "" }, content: { type: "text", value: "#" } }],
|
|
107
|
-
rehype_mermaid_blocks,
|
|
108
89
|
[rehype_shiki, { theme: halon_code_theme, defaultLanguage: "text", fallbackLanguage: "text" }],
|
|
109
90
|
[rehype_base_links, base],
|
|
110
91
|
],
|
package/dist/web/react/site.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type ComponentType, type ReactNode } from "react";
|
|
2
2
|
import { type NavItem, type PageData } from "../../site/model.ts";
|
|
3
|
-
import type { DiagramDrawer } from "../site/mermaid.ts";
|
|
4
3
|
import { type SearchHit } from "./search_dialog.tsx";
|
|
5
4
|
export type { PageData } from "../../site/model.ts";
|
|
6
5
|
export declare function use_site_page(): PageData;
|
|
@@ -11,9 +10,8 @@ interface SitePageProps {
|
|
|
11
10
|
page: PageData;
|
|
12
11
|
Content: PageContent;
|
|
13
12
|
search?: (query: string) => Promise<SearchHit[]>;
|
|
14
|
-
draw_diagram?: DiagramDrawer;
|
|
15
13
|
}
|
|
16
|
-
export declare function SitePage({ page, Content, search
|
|
14
|
+
export declare function SitePage({ page, Content, search }: SitePageProps): import("react").JSX.Element;
|
|
17
15
|
export declare function SiteNav({ items, current }: {
|
|
18
16
|
items: NavItem[];
|
|
19
17
|
current: string;
|
package/dist/web/react/site.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
// A static site's page in the X-apps' frame: the Shell with the site's sidebar, search, links and language picker in
|
|
3
3
|
// the top bar, the page's outline beside it, and edit, date and previous and next links at its foot. The pieces a page's
|
|
4
4
|
// MDX can use, such as cards and asides, are here too.
|
|
5
|
-
import { createContext, useContext,
|
|
5
|
+
import { createContext, useContext, useMemo, useState } from "react";
|
|
6
6
|
import { with_base } from "../../site/model.js";
|
|
7
7
|
import { create_translator } from "../../i18n.js";
|
|
8
8
|
import { theme_choice } from "../theme.js";
|
|
@@ -19,50 +19,7 @@ export function use_site_page() {
|
|
|
19
19
|
throw new Error("Site content is drawn outside a SitePage.");
|
|
20
20
|
return page;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
const DiagramDrawing = createContext(null);
|
|
24
|
-
// Whether the page shows its dark scheme: the theme picked, else the system's, followed as either changes.
|
|
25
|
-
function use_dark_page() {
|
|
26
|
-
return useSyncExternalStore((changed) => {
|
|
27
|
-
const media = matchMedia("(prefers-color-scheme: dark)");
|
|
28
|
-
const observer = new MutationObserver(changed);
|
|
29
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
|
|
30
|
-
media.addEventListener("change", changed);
|
|
31
|
-
return () => {
|
|
32
|
-
observer.disconnect();
|
|
33
|
-
media.removeEventListener("change", changed);
|
|
34
|
-
};
|
|
35
|
-
}, () => {
|
|
36
|
-
const theme = document.documentElement.dataset.theme;
|
|
37
|
-
return theme === undefined ? matchMedia("(prefers-color-scheme: dark)").matches : theme === "dark";
|
|
38
|
-
}, () => false);
|
|
39
|
-
}
|
|
40
|
-
// A ```mermaid block: its source until the page has drawn it, then the diagram, drawn again when the scheme changes.
|
|
41
|
-
function Diagram({ source }) {
|
|
42
|
-
const draw = useContext(DiagramDrawing);
|
|
43
|
-
const dark = use_dark_page();
|
|
44
|
-
const [svg, set_svg] = useState(null);
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
if (draw === null)
|
|
47
|
-
return;
|
|
48
|
-
let shown = true;
|
|
49
|
-
draw(source, dark).then((drawn) => shown && set_svg(drawn), () => shown && set_svg(null));
|
|
50
|
-
return () => {
|
|
51
|
-
shown = false;
|
|
52
|
-
};
|
|
53
|
-
}, [draw, source, dark]);
|
|
54
|
-
if (svg === null)
|
|
55
|
-
return _jsx("pre", { className: "site-diagram-source", "data-pagefind-ignore": "", children: source });
|
|
56
|
-
return _jsx("div", { className: "site-diagram", "data-pagefind-ignore": "", dangerouslySetInnerHTML: { __html: svg } });
|
|
57
|
-
}
|
|
58
|
-
// A Markdown <pre>: a diagram when the build marked it as mermaid, else code as it is.
|
|
59
|
-
function SitePre({ "data-mermaid": mermaid, ...props }) {
|
|
60
|
-
if (mermaid === undefined)
|
|
61
|
-
return _jsx("pre", { ...props });
|
|
62
|
-
return _jsx(Diagram, { source: typeof props.children === "string" ? props.children : String(props.children ?? "") });
|
|
63
|
-
}
|
|
64
|
-
const content_components = { pre: SitePre };
|
|
65
|
-
export function SitePage({ page, Content, search, draw_diagram }) {
|
|
22
|
+
export function SitePage({ page, Content, search }) {
|
|
66
23
|
const t = create_translator(page.ui);
|
|
67
24
|
const theme = useMemo(() => theme_choice(page.site.theme_key), [page.site.theme_key]);
|
|
68
25
|
const [is_searching, set_searching] = useState(false);
|
|
@@ -77,7 +34,7 @@ export function SitePage({ page, Content, search, draw_diagram }) {
|
|
|
77
34
|
change_theme: t("change_theme"),
|
|
78
35
|
};
|
|
79
36
|
const tools = (_jsxs("div", { className: "site-tools", children: [search && page.site.search && _jsx(SearchButton, { label: t("search"), on_open: () => set_searching(true) }), _jsxs("div", { className: "site-tools-end", children: [_jsx(SocialLinks, { links: page.site.social }), _jsx(LanguagePicker, { page: page, label: t("language") })] })] }));
|
|
80
|
-
return (
|
|
37
|
+
return (_jsxs(SiteData.Provider, { value: page, children: [_jsx(Shell, { brand: page.site.title, brand_icon: page.site.logo_replaces_title ? undefined : page.site.logo, brand_logo: page.site.logo_replaces_title ? page.site.logo : undefined, brand_href: page.site.home, sidebar: _jsx(SiteNav, { items: page.nav, current: page.href }), theme: theme, tools: tools, labels: labels, view_key: page.href, children: page.template === "splash" ? _jsx(SplashLayout, { page: page, Content: Content, t: t }) : _jsx(DocLayout, { page: page, Content: Content, t: t }) }), is_searching && search && (_jsx(SearchDialog, { search: search, on_close: () => set_searching(false), labels: { title: t("search_title"), placeholder: t("search_placeholder"), no_results: t("search_no_results"), searching: t("search_searching") } }))] }));
|
|
81
38
|
}
|
|
82
39
|
// Search indexes only a page's own words, so the missing-page page and one shown in the default language for want of a
|
|
83
40
|
// translation are left out.
|
|
@@ -87,11 +44,11 @@ function search_body(page) {
|
|
|
87
44
|
function DocLayout({ page, Content, t }) {
|
|
88
45
|
const has_outline = page.toc && page.headings.length > 0;
|
|
89
46
|
const outline = [{ heading: t("on_this_page"), items: page.headings.map((heading) => ({ target: heading.id, label: heading.text, level: heading.level })) }];
|
|
90
|
-
return (_jsxs("div", { className: has_outline ? "site-page with-outline" : "site-page", children: [_jsxs("div", { className: "site-main", children: [has_outline && (_jsxs("details", { className: "site-outline-narrow", children: [_jsx("summary", { children: t("on_this_page") }), _jsx(Outline, { groups: [{ items: outline[0].items }], label: t("on_this_page"), update_hash: true })] })), _jsxs("article", { className: "site-article", ...search_body(page), children: [_jsx("h1", { className: "site-title", children: page.title }), page.description && _jsx("p", { className: "site-lead", children: page.description }), page.fallback_language && _jsx("p", { className: "banner site-notice", children: t("not_translated", { language: page.fallback_language }) }), _jsx("div", { className: "markdown site-content", children: _jsx(Content, {
|
|
47
|
+
return (_jsxs("div", { className: has_outline ? "site-page with-outline" : "site-page", children: [_jsxs("div", { className: "site-main", children: [has_outline && (_jsxs("details", { className: "site-outline-narrow", children: [_jsx("summary", { children: t("on_this_page") }), _jsx(Outline, { groups: [{ items: outline[0].items }], label: t("on_this_page"), update_hash: true })] })), _jsxs("article", { className: "site-article", ...search_body(page), children: [_jsx("h1", { className: "site-title", children: page.title }), page.description && _jsx("p", { className: "site-lead", children: page.description }), page.fallback_language && _jsx("p", { className: "banner site-notice", children: t("not_translated", { language: page.fallback_language }) }), _jsx("div", { className: "markdown site-content", children: _jsx(Content, {}) })] }), _jsx(PageFoot, { page: page, t: t })] }), has_outline && (_jsx("aside", { className: "site-outline", children: _jsx(Outline, { groups: outline, label: t("on_this_page"), update_hash: true }) }))] }));
|
|
91
48
|
}
|
|
92
49
|
function SplashLayout({ page, Content, t }) {
|
|
93
50
|
const hero = page.hero ?? {};
|
|
94
|
-
return (_jsx("div", { className: "site-page splash", children: _jsxs("div", { className: "site-main", children: [_jsxs("article", { className: "site-article", ...search_body(page), children: [_jsxs("header", { className: "site-hero", children: [_jsxs("div", { className: "site-hero-text", children: [_jsx("h1", { className: "site-title", children: hero.title ?? page.title }), (hero.tagline ?? page.description) && _jsx("p", { className: "site-hero-tagline", children: hero.tagline ?? page.description }), hero.actions && hero.actions.length > 0 && (_jsx("div", { className: "site-hero-actions", children: hero.actions.map((action) => (_jsx("a", { href: with_base(page.base, action.link), className: action_class(action.variant), children: action.text }, action.link))) }))] }), hero.image && _jsx("img", { className: "site-hero-image", src: hero.image, alt: "" })] }), page.fallback_language && _jsx("p", { className: "banner site-notice", children: t("not_translated", { language: page.fallback_language }) }), _jsx("div", { className: "markdown site-content", children: _jsx(Content, {
|
|
51
|
+
return (_jsx("div", { className: "site-page splash", children: _jsxs("div", { className: "site-main", children: [_jsxs("article", { className: "site-article", ...search_body(page), children: [_jsxs("header", { className: "site-hero", children: [_jsxs("div", { className: "site-hero-text", children: [_jsx("h1", { className: "site-title", children: hero.title ?? page.title }), (hero.tagline ?? page.description) && _jsx("p", { className: "site-hero-tagline", children: hero.tagline ?? page.description }), hero.actions && hero.actions.length > 0 && (_jsx("div", { className: "site-hero-actions", children: hero.actions.map((action) => (_jsx("a", { href: with_base(page.base, action.link), className: action_class(action.variant), children: action.text }, action.link))) }))] }), hero.image && _jsx("img", { className: "site-hero-image", src: hero.image, alt: "" })] }), page.fallback_language && _jsx("p", { className: "banner site-notice", children: t("not_translated", { language: page.fallback_language }) }), _jsx("div", { className: "markdown site-content", children: _jsx(Content, {}) })] }), _jsx(PageFoot, { page: page, t: t })] }) }));
|
|
95
52
|
}
|
|
96
53
|
function action_class(variant = "primary") {
|
|
97
54
|
return variant === "primary" ? "button accent solid" : variant === "secondary" ? "button" : "button minimal";
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import type { DiagramDrawer } from "./mermaid.ts";
|
|
2
1
|
import { type PageModules } from "./pages.ts";
|
|
3
|
-
export
|
|
4
|
-
draw_diagram?: DiagramDrawer;
|
|
5
|
-
}
|
|
6
|
-
export declare function start_site(pages: PageModules, options?: SiteOptions): Promise<void>;
|
|
2
|
+
export declare function start_site(pages: PageModules): Promise<void>;
|
package/dist/web/site/client.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
// Picks up a page the build drew, so its search, outline, menus
|
|
2
|
+
// Picks up a page the build drew, so its search, outline, menus and theme work in the browser.
|
|
3
3
|
import { hydrateRoot } from "react-dom/client";
|
|
4
4
|
import { NotFound, SitePage } from "../react/site.js";
|
|
5
5
|
import { pagefind_search } from "./pagefind.js";
|
|
6
6
|
import { load_content } from "./pages.js";
|
|
7
|
-
export async function start_site(pages
|
|
7
|
+
export async function start_site(pages) {
|
|
8
8
|
const page = JSON.parse(document.getElementById("x-site-page").textContent);
|
|
9
9
|
const Content = (await load_content(pages, page.source)) ?? NotFound;
|
|
10
|
-
hydrateRoot(document.getElementById("root"), _jsx(SitePage, { page: page, Content: Content, search: pagefind_search(page.base, page.ui.search_unavailable)
|
|
10
|
+
hydrateRoot(document.getElementById("root"), _jsx(SitePage, { page: page, Content: Content, search: pagefind_search(page.base, page.ui.search_unavailable) }));
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-tech-laboratories/x-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.128.0",
|
|
4
4
|
"description": "Code the X-apps share: agents and their long runs, passwords and sign-in, the Fastify server pieces, durations, and the web page's helpers and widgets",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -61,7 +61,6 @@
|
|
|
61
61
|
"electron-builder": "^26.18.0",
|
|
62
62
|
"electron-vite": "^6.0.0",
|
|
63
63
|
"fastify": "^5.12.7",
|
|
64
|
-
"mermaid": "^11.0.0",
|
|
65
64
|
"nodemailer": "^10.3.1",
|
|
66
65
|
"pagefind": "^1.6.0",
|
|
67
66
|
"react": "^19",
|
|
@@ -138,9 +137,6 @@
|
|
|
138
137
|
"fastify": {
|
|
139
138
|
"optional": true
|
|
140
139
|
},
|
|
141
|
-
"mermaid": {
|
|
142
|
-
"optional": true
|
|
143
|
-
},
|
|
144
140
|
"nodemailer": {
|
|
145
141
|
"optional": true
|
|
146
142
|
},
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface MermaidModule {
|
|
2
|
-
initialize(config: Record<string, unknown>): void;
|
|
3
|
-
render(id: string, text: string): Promise<{
|
|
4
|
-
svg: string;
|
|
5
|
-
}>;
|
|
6
|
-
}
|
|
7
|
-
export type DiagramDrawer = (source: string, dark: boolean) => Promise<string>;
|
|
8
|
-
export declare function mermaid_theme(read: (token: string) => string, dark: boolean): Record<string, unknown>;
|
|
9
|
-
export declare function mermaid_drawer(load: () => Promise<{
|
|
10
|
-
default: MermaidModule;
|
|
11
|
-
}>): DiagramDrawer;
|
package/dist/web/site/mermaid.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Draws a site's ```mermaid blocks with mermaid, coloured by Halon's tokens for the scheme the page shows. The site's
|
|
2
|
-
// browser entry hands in its own import of mermaid, so X-App never needs it and sites without diagrams never load it.
|
|
3
|
-
// ── Colours ──────────────────────────────────────────────────────────────────
|
|
4
|
-
// Mermaid's theme variables from the page's Halon tokens, as the current scheme sets them.
|
|
5
|
-
export function mermaid_theme(read, dark) {
|
|
6
|
-
const surface = read("--surface-default") || (dark ? "#16213a" : "#ffffff");
|
|
7
|
-
const panel = read("--surface-secondary") || (dark ? "#060b14" : "#f1f5f9");
|
|
8
|
-
const text = read("--text-body") || (dark ? "#e2e8f0" : "#1a1a2e");
|
|
9
|
-
const muted = read("--text-secondary") || (dark ? "#cbd5e1" : "#475569");
|
|
10
|
-
const border = read("--border-default") || (dark ? "#334155" : "#e2e8f0");
|
|
11
|
-
return {
|
|
12
|
-
darkMode: dark,
|
|
13
|
-
background: surface,
|
|
14
|
-
fontFamily: read("--font-family-interface") || "Noto Sans, sans-serif",
|
|
15
|
-
fontSize: "14px",
|
|
16
|
-
primaryColor: panel,
|
|
17
|
-
primaryTextColor: text,
|
|
18
|
-
primaryBorderColor: muted,
|
|
19
|
-
secondaryColor: surface,
|
|
20
|
-
tertiaryColor: panel,
|
|
21
|
-
lineColor: muted,
|
|
22
|
-
textColor: text,
|
|
23
|
-
mainBkg: panel,
|
|
24
|
-
nodeBorder: muted,
|
|
25
|
-
clusterBkg: surface,
|
|
26
|
-
clusterBorder: border,
|
|
27
|
-
edgeLabelBackground: surface,
|
|
28
|
-
noteBkgColor: panel,
|
|
29
|
-
noteTextColor: text,
|
|
30
|
-
noteBorderColor: border,
|
|
31
|
-
actorBkg: panel,
|
|
32
|
-
actorBorder: muted,
|
|
33
|
-
actorTextColor: text,
|
|
34
|
-
signalColor: text,
|
|
35
|
-
signalTextColor: text,
|
|
36
|
-
labelBoxBkgColor: panel,
|
|
37
|
-
labelTextColor: text,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
// ── Drawing ──────────────────────────────────────────────────────────────────
|
|
41
|
-
// A drawer that loads mermaid on its first diagram and sets its colours again whenever the scheme changes; diagrams
|
|
42
|
-
// are drawn one at a time, since mermaid's settings are shared by every diagram.
|
|
43
|
-
export function mermaid_drawer(load) {
|
|
44
|
-
let loading = null;
|
|
45
|
-
let scheme = null;
|
|
46
|
-
let count = 0;
|
|
47
|
-
let queue = Promise.resolve();
|
|
48
|
-
const draw = async (source, dark) => {
|
|
49
|
-
loading ??= load().then((module) => module.default);
|
|
50
|
-
const mermaid = await loading;
|
|
51
|
-
if (scheme !== dark) {
|
|
52
|
-
const styles = getComputedStyle(document.documentElement);
|
|
53
|
-
mermaid.initialize({ startOnLoad: false, securityLevel: "strict", theme: "base", themeVariables: mermaid_theme((token) => styles.getPropertyValue(token).trim(), dark) });
|
|
54
|
-
scheme = dark;
|
|
55
|
-
}
|
|
56
|
-
count += 1;
|
|
57
|
-
const { svg } = await mermaid.render(`site-diagram-${count}`, source);
|
|
58
|
-
return svg;
|
|
59
|
-
};
|
|
60
|
-
return (source, dark) => {
|
|
61
|
-
const next = queue.then(() => draw(source, dark));
|
|
62
|
-
queue = next.catch(() => { });
|
|
63
|
-
return next;
|
|
64
|
-
};
|
|
65
|
-
}
|