@brett_lamy/docstream 1.2.4 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -14
- package/dist/assets.d.ts +3 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +20 -0
- package/dist/assets.js.map +1 -0
- package/dist/demo/DemoViewer.d.ts +64 -0
- package/dist/demo/DemoViewer.d.ts.map +1 -0
- package/dist/demo/DemoViewer.js +426 -0
- package/dist/demo/DemoViewer.js.map +1 -0
- package/dist/demo/context.d.ts +14 -0
- package/dist/demo/context.d.ts.map +1 -0
- package/dist/demo/context.js +25 -0
- package/dist/demo/context.js.map +1 -0
- package/dist/demo/glob.d.ts +60 -0
- package/dist/demo/glob.d.ts.map +1 -0
- package/dist/demo/glob.js +158 -0
- package/dist/demo/glob.js.map +1 -0
- package/dist/demo/index.d.ts +10 -0
- package/dist/demo/index.d.ts.map +1 -0
- package/dist/demo/index.js +6 -0
- package/dist/demo/index.js.map +1 -0
- package/dist/demo/markdown.d.ts +60 -0
- package/dist/demo/markdown.d.ts.map +1 -0
- package/dist/demo/markdown.js +181 -0
- package/dist/demo/markdown.js.map +1 -0
- package/dist/demo/surface.d.ts +11 -0
- package/dist/demo/surface.d.ts.map +1 -0
- package/dist/demo/surface.js +69 -0
- package/dist/demo/surface.js.map +1 -0
- package/dist/demo/types.d.ts +91 -0
- package/dist/demo/types.d.ts.map +1 -0
- package/dist/demo/types.js +2 -0
- package/dist/demo/types.js.map +1 -0
- package/dist/docs/CollapsibleCode.d.ts +14 -0
- package/dist/docs/CollapsibleCode.d.ts.map +1 -0
- package/dist/docs/CollapsibleCode.js +19 -0
- package/dist/docs/CollapsibleCode.js.map +1 -0
- package/dist/docs/DocsRenderer.d.ts +49 -0
- package/dist/docs/DocsRenderer.d.ts.map +1 -0
- package/dist/docs/DocsRenderer.js +277 -0
- package/dist/docs/DocsRenderer.js.map +1 -0
- package/dist/docs/HighlightedCode.d.ts +6 -0
- package/dist/docs/HighlightedCode.d.ts.map +1 -0
- package/dist/docs/HighlightedCode.js +40 -0
- package/dist/docs/HighlightedCode.js.map +1 -0
- package/dist/docs/Mermaid.d.ts +7 -0
- package/dist/docs/Mermaid.d.ts.map +1 -0
- package/dist/docs/Mermaid.js +39 -0
- package/dist/docs/Mermaid.js.map +1 -0
- package/dist/docs/PageActions.d.ts +33 -0
- package/dist/docs/PageActions.d.ts.map +1 -0
- package/dist/docs/PageActions.js +115 -0
- package/dist/docs/PageActions.js.map +1 -0
- package/dist/docs/controls.d.ts +29 -0
- package/dist/docs/controls.d.ts.map +1 -0
- package/dist/docs/controls.js +46 -0
- package/dist/docs/controls.js.map +1 -0
- package/dist/docs/copy.d.ts +24 -0
- package/dist/docs/copy.d.ts.map +1 -0
- package/dist/docs/copy.js +62 -0
- package/dist/docs/copy.js.map +1 -0
- package/dist/docs/math.d.ts +3 -0
- package/dist/docs/math.d.ts.map +1 -0
- package/dist/docs/math.js +12 -0
- package/dist/docs/math.js.map +1 -0
- package/dist/docs/reference.d.ts +27 -0
- package/dist/docs/reference.d.ts.map +1 -0
- package/dist/docs/reference.js +73 -0
- package/dist/docs/reference.js.map +1 -0
- package/dist/docs/tabs-sync.d.ts +5 -0
- package/dist/docs/tabs-sync.d.ts.map +1 -0
- package/dist/docs/tabs-sync.js +58 -0
- package/dist/docs/tabs-sync.js.map +1 -0
- package/dist/gitbook/ast.d.ts +506 -0
- package/dist/gitbook/ast.d.ts.map +1 -0
- package/dist/gitbook/ast.js +8 -0
- package/dist/gitbook/ast.js.map +1 -0
- package/dist/gitbook/attrs.d.ts +14 -0
- package/dist/gitbook/attrs.d.ts.map +1 -0
- package/dist/gitbook/attrs.js +36 -0
- package/dist/gitbook/attrs.js.map +1 -0
- package/dist/gitbook/flatten.d.ts +14 -0
- package/dist/gitbook/flatten.d.ts.map +1 -0
- package/dist/gitbook/flatten.js +45 -0
- package/dist/gitbook/flatten.js.map +1 -0
- package/dist/gitbook/index.d.ts +10 -0
- package/dist/gitbook/index.d.ts.map +1 -0
- package/dist/gitbook/index.js +8 -0
- package/dist/gitbook/index.js.map +1 -0
- package/dist/gitbook/inline.d.ts +28 -0
- package/dist/gitbook/inline.d.ts.map +1 -0
- package/dist/gitbook/inline.js +956 -0
- package/dist/gitbook/inline.js.map +1 -0
- package/dist/gitbook/outline.d.ts +16 -0
- package/dist/gitbook/outline.d.ts.map +1 -0
- package/dist/gitbook/outline.js +44 -0
- package/dist/gitbook/outline.js.map +1 -0
- package/dist/gitbook/package-managers.d.ts +12 -0
- package/dist/gitbook/package-managers.d.ts.map +1 -0
- package/dist/gitbook/package-managers.js +93 -0
- package/dist/gitbook/package-managers.js.map +1 -0
- package/dist/gitbook/parse.d.ts +44 -0
- package/dist/gitbook/parse.d.ts.map +1 -0
- package/dist/gitbook/parse.js +1113 -0
- package/dist/gitbook/parse.js.map +1 -0
- package/dist/gitbook/serialize.d.ts +23 -0
- package/dist/gitbook/serialize.d.ts.map +1 -0
- package/dist/gitbook/serialize.js +498 -0
- package/dist/gitbook/serialize.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi/OpenApiOperation.d.ts +6 -0
- package/dist/openapi/OpenApiOperation.d.ts.map +1 -0
- package/dist/openapi/OpenApiOperation.js +112 -0
- package/dist/openapi/OpenApiOperation.js.map +1 -0
- package/dist/playground/InlineDemoPreview.d.ts +24 -0
- package/dist/playground/InlineDemoPreview.d.ts.map +1 -0
- package/dist/playground/InlineDemoPreview.js +48 -0
- package/dist/playground/InlineDemoPreview.js.map +1 -0
- package/dist/playground/PlaygroundStreamdown.d.ts +16 -0
- package/dist/playground/PlaygroundStreamdown.d.ts.map +1 -0
- package/dist/playground/PlaygroundStreamdown.js +22 -0
- package/dist/playground/PlaygroundStreamdown.js.map +1 -0
- package/dist/playground/ReactCodePreview.d.ts +64 -0
- package/dist/playground/ReactCodePreview.d.ts.map +1 -0
- package/dist/playground/ReactCodePreview.js +108 -0
- package/dist/playground/ReactCodePreview.js.map +1 -0
- package/dist/playground/filesystem.d.ts +27 -0
- package/dist/playground/filesystem.d.ts.map +1 -0
- package/dist/playground/filesystem.js +65 -0
- package/dist/playground/filesystem.js.map +1 -0
- package/dist/playground/index.d.ts +9 -0
- package/dist/playground/index.d.ts.map +1 -0
- package/dist/playground/index.js +7 -0
- package/dist/playground/index.js.map +1 -0
- package/dist/playground/project.d.ts +57 -0
- package/dist/playground/project.d.ts.map +1 -0
- package/dist/playground/project.js +137 -0
- package/dist/playground/project.js.map +1 -0
- package/dist/replay/NativeReplay.d.ts +9 -0
- package/dist/replay/NativeReplay.d.ts.map +1 -0
- package/dist/replay/NativeReplay.js +173 -0
- package/dist/replay/NativeReplay.js.map +1 -0
- package/dist/replay/ReplayPreview.d.ts +33 -0
- package/dist/replay/ReplayPreview.d.ts.map +1 -0
- package/dist/replay/ReplayPreview.js +91 -0
- package/dist/replay/ReplayPreview.js.map +1 -0
- package/dist/replay/index.d.ts +5 -0
- package/dist/replay/index.d.ts.map +1 -0
- package/dist/replay/index.js +4 -0
- package/dist/replay/index.js.map +1 -0
- package/dist/replay/sanitize.d.ts +4 -0
- package/dist/replay/sanitize.d.ts.map +1 -0
- package/dist/replay/sanitize.js +86 -0
- package/dist/replay/sanitize.js.map +1 -0
- package/dist/replay/url.d.ts +8 -0
- package/dist/replay/url.d.ts.map +1 -0
- package/dist/replay/url.js +41 -0
- package/dist/replay/url.js.map +1 -0
- package/dist/source/SourcePreview.d.ts +13 -0
- package/dist/source/SourcePreview.d.ts.map +1 -0
- package/dist/source/SourcePreview.js +47 -0
- package/dist/source/SourcePreview.js.map +1 -0
- package/dist/source/client.d.ts +7 -0
- package/dist/source/client.d.ts.map +1 -0
- package/dist/source/client.js +52 -0
- package/dist/source/client.js.map +1 -0
- package/dist/source/index.d.ts +6 -0
- package/dist/source/index.d.ts.map +1 -0
- package/dist/source/index.js +3 -0
- package/dist/source/index.js.map +1 -0
- package/dist/source/types.d.ts +33 -0
- package/dist/source/types.d.ts.map +1 -0
- package/dist/source/types.js +2 -0
- package/dist/source/types.js.map +1 -0
- package/dist/streamdown.d.ts +19 -0
- package/dist/streamdown.d.ts.map +1 -0
- package/dist/streamdown.js +15 -0
- package/dist/streamdown.js.map +1 -0
- package/dist/styles.css +2441 -0
- package/dist/video/VideoEmbed.d.ts +17 -0
- package/dist/video/VideoEmbed.d.ts.map +1 -0
- package/dist/video/VideoEmbed.js +12 -0
- package/dist/video/VideoEmbed.js.map +1 -0
- package/dist/video/index.d.ts +3 -0
- package/dist/video/index.d.ts.map +1 -0
- package/dist/video/index.js +2 -0
- package/dist/video/index.js.map +1 -0
- package/dist/vite/index.d.ts +21 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +137 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/viz/VizEmbed.d.ts +18 -0
- package/dist/viz/VizEmbed.d.ts.map +1 -0
- package/dist/viz/VizEmbed.js +12 -0
- package/dist/viz/VizEmbed.js.map +1 -0
- package/dist/viz/index.d.ts +4 -0
- package/dist/viz/index.d.ts.map +1 -0
- package/dist/viz/index.js +3 -0
- package/dist/viz/index.js.map +1 -0
- package/package.json +70 -34
- package/src/demo/types.ts +2 -2
- package/src/docs/DocsRenderer.tsx +31 -7
- package/src/docs/Mermaid.tsx +5 -3
- package/src/docs/math.ts +3 -0
- package/src/index.ts +10 -28
- package/src/playground/PlaygroundStreamdown.tsx +28 -61
- package/src/playground/filesystem.ts +10 -190
- package/src/playground/index.ts +4 -0
- package/src/playground/project.ts +194 -0
- package/src/replay/NativeReplay.tsx +236 -0
- package/src/replay/ReplayPreview.tsx +7 -226
- package/src/styles.css +91 -1
- package/src/replay/styles.css +0 -87
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
export interface VideoEmbedProps {
|
|
3
|
+
/** A direct media asset or a public player URL. */
|
|
4
|
+
src: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
/** CSS aspect-ratio for iframe embeds. Defaults to 16 / 9. */
|
|
8
|
+
aspectRatio?: CSSProperties["aspectRatio"];
|
|
9
|
+
controls?: boolean;
|
|
10
|
+
autoplay?: boolean;
|
|
11
|
+
loop?: boolean;
|
|
12
|
+
muted?: boolean;
|
|
13
|
+
poster?: string;
|
|
14
|
+
allowFullScreen?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function VideoEmbed({ src, title, className, aspectRatio, controls, autoplay, loop, muted, poster, allowFullScreen, }: VideoEmbedProps): import("react").JSX.Element;
|
|
17
|
+
//# sourceMappingURL=VideoEmbed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VideoEmbed.d.ts","sourceRoot":"","sources":["../../src/video/VideoEmbed.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,8DAA8D;IAC9D,WAAW,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;IAC1C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAMD,wBAAgB,UAAU,CAAC,EACzB,GAAG,EACH,KAAe,EACf,SAAS,EACT,WAAsB,EACtB,QAAe,EACf,QAAgB,EAChB,IAAY,EACZ,KAAa,EACb,MAAM,EACN,eAAsB,GACvB,EAAE,eAAe,+BA6BjB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
function isDirectVideo(src) {
|
|
3
|
+
return /\.(?:mp4|webm|ogg)(?:[?#]|$)/i.test(src);
|
|
4
|
+
}
|
|
5
|
+
export function VideoEmbed({ src, title = "Video", className, aspectRatio = "16 / 9", controls = true, autoplay = false, loop = false, muted = false, poster, allowFullScreen = true, }) {
|
|
6
|
+
const mediaClass = `video-embed__media ${className ?? ""}`.trim();
|
|
7
|
+
if (isDirectVideo(src)) {
|
|
8
|
+
return (_jsx("video", { className: mediaClass, src: src, title: title, controls: controls, autoPlay: autoplay, loop: loop, muted: muted, poster: poster, playsInline: true }));
|
|
9
|
+
}
|
|
10
|
+
return (_jsx("iframe", { className: mediaClass, src: src, title: title, loading: "lazy", allow: "autoplay; fullscreen", allowFullScreen: allowFullScreen, style: { aspectRatio }, referrerPolicy: "strict-origin-when-cross-origin" }));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=VideoEmbed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VideoEmbed.js","sourceRoot":"","sources":["../../src/video/VideoEmbed.tsx"],"names":[],"mappings":";AAiBA,SAAS,aAAa,CAAC,GAAW;IAChC,OAAO,+BAA+B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAClD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,EACzB,GAAG,EACH,KAAK,GAAG,OAAO,EACf,SAAS,EACT,WAAW,GAAG,QAAQ,EACtB,QAAQ,GAAG,IAAI,EACf,QAAQ,GAAG,KAAK,EAChB,IAAI,GAAG,KAAK,EACZ,KAAK,GAAG,KAAK,EACb,MAAM,EACN,eAAe,GAAG,IAAI,GACN;IAChB,MAAM,UAAU,GAAG,sBAAsB,SAAS,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAA;IACjE,IAAI,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,CACL,gBACE,SAAS,EAAE,UAAU,EACrB,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,WAAW,SACX,CACH,CAAA;IACH,CAAC;IACD,OAAO,CACL,iBACE,SAAS,EAAE,UAAU,EACrB,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,OAAO,EAAC,MAAM,EACd,KAAK,EAAC,sBAAsB,EAC5B,eAAe,EAAE,eAAe,EAChC,KAAK,EAAE,EAAE,WAAW,EAAE,EACtB,cAAc,EAAC,iCAAiC,GAChD,CACH,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/video/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/video/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export interface DocstreamSourceMount {
|
|
3
|
+
/** Stable name used by Markdown source references. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Real source directory. Relative paths are resolved from the Vite root. */
|
|
6
|
+
root: string;
|
|
7
|
+
/** Allow PUT requests to edit files in this mount. Defaults to true. */
|
|
8
|
+
writable?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface DocstreamSourcesOptions {
|
|
11
|
+
mounts: readonly DocstreamSourceMount[];
|
|
12
|
+
/** HTTP endpoint prefix. Defaults to `/@docstream`. */
|
|
13
|
+
apiBase?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Mount real source directories behind safe Vite dev-server endpoints.
|
|
17
|
+
* Markdown references import live modules from these files, and editor writes
|
|
18
|
+
* go back to disk so Vite's normal watcher/HMR pipeline remains authoritative.
|
|
19
|
+
*/
|
|
20
|
+
export declare function docstreamSources(options: DocstreamSourcesOptions): Plugin;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAA;AAEjD,MAAM,WAAW,oBAAoB;IACnC,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAA;IACZ,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAA;IACZ,wEAAwE;IACxE,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,SAAS,oBAAoB,EAAE,CAAA;IACvC,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AA6GD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAgCzE"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const VIRTUAL_ID = "virtual:docstream-sources";
|
|
4
|
+
const RESOLVED_VIRTUAL_ID = "\0virtual:docstream-sources";
|
|
5
|
+
function send(response, status, body, type = "application/json; charset=utf-8") {
|
|
6
|
+
response.statusCode = status;
|
|
7
|
+
response.setHeader("content-type", type);
|
|
8
|
+
response.setHeader("cache-control", "no-store");
|
|
9
|
+
response.end(body);
|
|
10
|
+
}
|
|
11
|
+
function requestUrl(request) {
|
|
12
|
+
return new URL(request.url ?? "/", "http://docstream.local");
|
|
13
|
+
}
|
|
14
|
+
async function requestBody(request) {
|
|
15
|
+
const chunks = [];
|
|
16
|
+
for await (const chunk of request)
|
|
17
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
18
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
19
|
+
}
|
|
20
|
+
function normalizeRelativePath(value) {
|
|
21
|
+
const source = value.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
22
|
+
if (!source || source.startsWith("/") || source.split("/").some((part) => part === ".." || part === "")) {
|
|
23
|
+
throw new Error(`Invalid mounted source path: ${value}`);
|
|
24
|
+
}
|
|
25
|
+
return source;
|
|
26
|
+
}
|
|
27
|
+
function sourcePath(mount, requestedPath) {
|
|
28
|
+
const relativePath = normalizeRelativePath(requestedPath);
|
|
29
|
+
const absolutePath = path.resolve(mount.root, relativePath);
|
|
30
|
+
const prefix = mount.root.endsWith(path.sep) ? mount.root : `${mount.root}${path.sep}`;
|
|
31
|
+
if (!absolutePath.startsWith(prefix))
|
|
32
|
+
throw new Error(`Source path escapes mount ${mount.name}: ${requestedPath}`);
|
|
33
|
+
return { relativePath, absolutePath };
|
|
34
|
+
}
|
|
35
|
+
function provenance(url, mount, relativePath, absolutePath, mtimeMs) {
|
|
36
|
+
return {
|
|
37
|
+
mount: mount.name,
|
|
38
|
+
path: relativePath,
|
|
39
|
+
exportName: url.searchParams.get("export") || "default",
|
|
40
|
+
kind: url.searchParams.get("kind") === "story" ? "story" : "component",
|
|
41
|
+
absolutePath,
|
|
42
|
+
mtimeMs,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function findMount(url, mounts) {
|
|
46
|
+
const name = url.searchParams.get("mount") ?? "";
|
|
47
|
+
const mount = mounts.find((candidate) => candidate.name === name);
|
|
48
|
+
if (!mount)
|
|
49
|
+
throw new Error(`Unknown Docstream source mount: ${name}`);
|
|
50
|
+
return mount;
|
|
51
|
+
}
|
|
52
|
+
function errorMessage(error) {
|
|
53
|
+
return error instanceof Error ? error.message : String(error);
|
|
54
|
+
}
|
|
55
|
+
function installMiddleware(server, apiBase, viteBase, mounts) {
|
|
56
|
+
server.middlewares.use(async (request, response, next) => {
|
|
57
|
+
const url = requestUrl(request);
|
|
58
|
+
if (url.pathname !== `${apiBase}/source` && url.pathname !== `${apiBase}/module`)
|
|
59
|
+
return next();
|
|
60
|
+
try {
|
|
61
|
+
const mount = findMount(url, mounts);
|
|
62
|
+
const requestedPath = url.searchParams.get("path") ?? "";
|
|
63
|
+
const { relativePath, absolutePath } = sourcePath(mount, requestedPath);
|
|
64
|
+
if (url.pathname === `${apiBase}/module`) {
|
|
65
|
+
if (request.method !== "GET")
|
|
66
|
+
return send(response, 405, "Method not allowed", "text/plain; charset=utf-8");
|
|
67
|
+
await fs.access(absolutePath);
|
|
68
|
+
const sourceUrl = `${viteBase.replace(/\/$/, "")}/@fs/${absolutePath.replaceAll(path.sep, "/")}?docstream=${Date.now()}`;
|
|
69
|
+
const module = `import * as source from ${JSON.stringify(sourceUrl)};\nexport default source;\n`;
|
|
70
|
+
return send(response, 200, module, "text/javascript; charset=utf-8");
|
|
71
|
+
}
|
|
72
|
+
if (request.method === "GET") {
|
|
73
|
+
const [content, stat] = await Promise.all([fs.readFile(absolutePath, "utf8"), fs.stat(absolutePath)]);
|
|
74
|
+
return send(response, 200, JSON.stringify({ content, provenance: provenance(url, mount, relativePath, absolutePath, stat.mtimeMs) }));
|
|
75
|
+
}
|
|
76
|
+
if (request.method === "PUT") {
|
|
77
|
+
if (!mount.writable)
|
|
78
|
+
return send(response, 403, `Source mount ${mount.name} is read-only`, "text/plain; charset=utf-8");
|
|
79
|
+
await fs.access(absolutePath);
|
|
80
|
+
const parsed = JSON.parse(await requestBody(request));
|
|
81
|
+
if (typeof parsed.content !== "string")
|
|
82
|
+
return send(response, 400, "Expected a JSON string field named content", "text/plain; charset=utf-8");
|
|
83
|
+
await fs.writeFile(absolutePath, parsed.content, "utf8");
|
|
84
|
+
const stat = await fs.stat(absolutePath);
|
|
85
|
+
server.watcher.add(absolutePath);
|
|
86
|
+
server.ws.send({ type: "full-reload", path: "*" });
|
|
87
|
+
return send(response, 200, JSON.stringify({ content: parsed.content, provenance: provenance(url, mount, relativePath, absolutePath, stat.mtimeMs) }));
|
|
88
|
+
}
|
|
89
|
+
return send(response, 405, "Method not allowed", "text/plain; charset=utf-8");
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
const status = error && typeof error === "object" && "code" in error && error.code === "ENOENT" ? 404 : 400;
|
|
93
|
+
return send(response, status, errorMessage(error), "text/plain; charset=utf-8");
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Mount real source directories behind safe Vite dev-server endpoints.
|
|
99
|
+
* Markdown references import live modules from these files, and editor writes
|
|
100
|
+
* go back to disk so Vite's normal watcher/HMR pipeline remains authoritative.
|
|
101
|
+
*/
|
|
102
|
+
export function docstreamSources(options) {
|
|
103
|
+
const apiBase = `/${(options.apiBase ?? "/@docstream").replace(/^\/+|\/+$/g, "")}`;
|
|
104
|
+
let mounts = [];
|
|
105
|
+
let viteBase = "/";
|
|
106
|
+
return {
|
|
107
|
+
name: "docstream-sources",
|
|
108
|
+
enforce: "pre",
|
|
109
|
+
configResolved(config) {
|
|
110
|
+
viteBase = config.base || "/";
|
|
111
|
+
const names = new Set();
|
|
112
|
+
mounts = options.mounts.map((mount) => {
|
|
113
|
+
if (!mount.name || names.has(mount.name))
|
|
114
|
+
throw new Error(`Docstream source mount names must be unique: ${mount.name}`);
|
|
115
|
+
names.add(mount.name);
|
|
116
|
+
return {
|
|
117
|
+
name: mount.name,
|
|
118
|
+
root: path.resolve(config.root, mount.root),
|
|
119
|
+
writable: mount.writable !== false,
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
configureServer(server) {
|
|
124
|
+
installMiddleware(server, apiBase, viteBase, mounts);
|
|
125
|
+
},
|
|
126
|
+
resolveId(id) {
|
|
127
|
+
if (id === VIRTUAL_ID)
|
|
128
|
+
return RESOLVED_VIRTUAL_ID;
|
|
129
|
+
},
|
|
130
|
+
load(id) {
|
|
131
|
+
if (id !== RESOLVED_VIRTUAL_ID)
|
|
132
|
+
return;
|
|
133
|
+
return `export const apiBase = ${JSON.stringify(apiBase)};\nexport const mounts = ${JSON.stringify(options.mounts.map(({ name, writable = true }) => ({ name, writable })))};\n`;
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,IAAI,MAAM,WAAW,CAAA;AAyB5B,MAAM,UAAU,GAAG,2BAA2B,CAAA;AAC9C,MAAM,mBAAmB,GAAG,6BAA6B,CAAA;AAEzD,SAAS,IAAI,CAAC,QAAwB,EAAE,MAAc,EAAE,IAAY,EAAE,IAAI,GAAG,iCAAiC;IAC5G,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAA;IAC5B,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;IACxC,QAAQ,CAAC,SAAS,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;IAC/C,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AACpB,CAAC;AAED,SAAS,UAAU,CAAC,OAAwB;IAC1C,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAC9D,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,OAAwB;IACjD,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO;QAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,Q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A;gBACvH,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBACrB,OAAO;oBACL,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC;oBAC3C,QAAQ,EAAE,KAAK,CAAC,QAAQ,KAAK,KAAK;iBACnC,CAAA;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;QACD,eAAe,CAAC,MAAM;YACpB,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;QACtD,CAAC;QACD,SAAS,CAAC,EAAE;YACV,IAAI,EAAE,KAAK,UAAU;gBAAE,OAAO,mBAAmB,CAAA;QACnD,CAAC;QACD,IAAI,CAAC,EAAE;YACL,IAAI,EAAE,KAAK,mBAAmB;gBAAE,OAAM;YACtC,OAAO,0BAA0B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,4BAA4B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAA;QAClL,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PlayerAudio, VideoScene } from "@brett_lamy/viz-engine";
|
|
2
|
+
export interface VizEmbedProps {
|
|
3
|
+
scene: VideoScene;
|
|
4
|
+
audio?: PlayerAudio;
|
|
5
|
+
title?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
autoplay?: boolean;
|
|
8
|
+
loop?: boolean;
|
|
9
|
+
showCaptions?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Mount a deterministic VizEngine scene inside a Docstream document. This is
|
|
13
|
+
* intentionally a component API rather than a markdown escape hatch: callers
|
|
14
|
+
* choose the scene and its evidence, while Docstream supplies document chrome
|
|
15
|
+
* and accessible figure semantics.
|
|
16
|
+
*/
|
|
17
|
+
export declare function VizEmbed({ scene, audio, title, className, autoplay, loop, showCaptions, }: VizEmbedProps): import("react").JSX.Element;
|
|
18
|
+
//# sourceMappingURL=VizEmbed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VizEmbed.d.ts","sourceRoot":"","sources":["../../src/viz/VizEmbed.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAGrE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,UAAU,CAAA;IACjB,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,QAAe,EACf,IAAW,EACX,YAAoB,GACrB,EAAE,aAAa,+BAcf"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { VizPlayer } from "@brett_lamy/viz-engine";
|
|
3
|
+
/**
|
|
4
|
+
* Mount a deterministic VizEngine scene inside a Docstream document. This is
|
|
5
|
+
* intentionally a component API rather than a markdown escape hatch: callers
|
|
6
|
+
* choose the scene and its evidence, while Docstream supplies document chrome
|
|
7
|
+
* and accessible figure semantics.
|
|
8
|
+
*/
|
|
9
|
+
export function VizEmbed({ scene, audio, title, className, autoplay = true, loop = true, showCaptions = false, }) {
|
|
10
|
+
return (_jsxs("figure", { className: `docstream-viz ${className ?? ""}`.trim(), children: [_jsx(VizPlayer, { scene: scene, ...(audio === undefined ? {} : { audio }), autoplay: autoplay, loop: loop, showCaptions: showCaptions, className: "docstream-viz__player" }), title && _jsx("figcaption", { children: title })] }));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=VizEmbed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VizEmbed.js","sourceRoot":"","sources":["../../src/viz/VizEmbed.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAYlD;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,EACvB,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,QAAQ,GAAG,IAAI,EACf,IAAI,GAAG,IAAI,EACX,YAAY,GAAG,KAAK,GACN;IACd,OAAO,CACL,kBAAQ,SAAS,EAAE,iBAAiB,SAAS,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,aAC1D,KAAC,SAAS,IACR,KAAK,EAAE,KAAK,KACR,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAC1C,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAC,uBAAuB,GACjC,EACD,KAAK,IAAI,+BAAa,KAAK,GAAc,IACnC,CACV,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/viz/index.ts"],"names":[],"mappings":"AAAA,OAAO,mCAAmC,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/viz/index.ts"],"names":[],"mappings":"AAAA,OAAO,mCAAmC,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brett_lamy/docstream",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "GitBook-aware readonly markdown and AI stream renderer.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
|
+
"build": "node scripts/build.mjs",
|
|
10
11
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
11
|
-
"test": "vitest run"
|
|
12
|
+
"test": "npm run build && vitest run",
|
|
13
|
+
"prepack": "npm run build"
|
|
12
14
|
},
|
|
13
|
-
"main": "./
|
|
14
|
-
"types": "./
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
15
17
|
"files": [
|
|
18
|
+
"dist",
|
|
16
19
|
"src",
|
|
17
20
|
"!src/**/*.test.ts",
|
|
18
21
|
"!src/**/*.test.tsx",
|
|
@@ -24,77 +27,108 @@
|
|
|
24
27
|
],
|
|
25
28
|
"exports": {
|
|
26
29
|
".": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
30
|
+
"source": "./src/index.ts",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"default": "./dist/index.js"
|
|
29
34
|
},
|
|
30
35
|
"./gitbook": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
36
|
+
"source": "./src/gitbook/index.ts",
|
|
37
|
+
"types": "./dist/gitbook/index.d.ts",
|
|
38
|
+
"import": "./dist/gitbook/index.js",
|
|
39
|
+
"default": "./dist/gitbook/index.js"
|
|
33
40
|
},
|
|
34
41
|
"./streamdown": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
42
|
+
"source": "./src/streamdown.tsx",
|
|
43
|
+
"types": "./dist/streamdown.d.ts",
|
|
44
|
+
"import": "./dist/streamdown.js",
|
|
45
|
+
"default": "./dist/streamdown.js"
|
|
37
46
|
},
|
|
38
47
|
"./reference": {
|
|
39
|
-
"
|
|
40
|
-
"
|
|
48
|
+
"source": "./src/docs/reference.tsx",
|
|
49
|
+
"types": "./dist/docs/reference.d.ts",
|
|
50
|
+
"import": "./dist/docs/reference.js",
|
|
51
|
+
"default": "./dist/docs/reference.js"
|
|
41
52
|
},
|
|
42
53
|
"./assets": {
|
|
43
|
-
"
|
|
44
|
-
"
|
|
54
|
+
"source": "./src/assets.ts",
|
|
55
|
+
"types": "./dist/assets.d.ts",
|
|
56
|
+
"import": "./dist/assets.js",
|
|
57
|
+
"default": "./dist/assets.js"
|
|
45
58
|
},
|
|
46
59
|
"./openapi": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
60
|
+
"source": "./src/openapi/OpenApiOperation.tsx",
|
|
61
|
+
"types": "./dist/openapi/OpenApiOperation.d.ts",
|
|
62
|
+
"import": "./dist/openapi/OpenApiOperation.js",
|
|
63
|
+
"default": "./dist/openapi/OpenApiOperation.js"
|
|
49
64
|
},
|
|
50
65
|
"./replay": {
|
|
51
|
-
"
|
|
52
|
-
"
|
|
66
|
+
"source": "./src/replay/index.ts",
|
|
67
|
+
"types": "./dist/replay/index.d.ts",
|
|
68
|
+
"import": "./dist/replay/index.js",
|
|
69
|
+
"default": "./dist/replay/index.js"
|
|
53
70
|
},
|
|
54
71
|
"./video": {
|
|
55
|
-
"
|
|
56
|
-
"
|
|
72
|
+
"source": "./src/video/index.ts",
|
|
73
|
+
"types": "./dist/video/index.d.ts",
|
|
74
|
+
"import": "./dist/video/index.js",
|
|
75
|
+
"default": "./dist/video/index.js"
|
|
57
76
|
},
|
|
58
77
|
"./viz": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
78
|
+
"source": "./src/viz/index.ts",
|
|
79
|
+
"types": "./dist/viz/index.d.ts",
|
|
80
|
+
"import": "./dist/viz/index.js",
|
|
81
|
+
"default": "./dist/viz/index.js"
|
|
61
82
|
},
|
|
62
83
|
"./playground": {
|
|
63
|
-
"
|
|
64
|
-
"
|
|
84
|
+
"source": "./src/playground/index.ts",
|
|
85
|
+
"types": "./dist/playground/index.d.ts",
|
|
86
|
+
"import": "./dist/playground/index.js",
|
|
87
|
+
"default": "./dist/playground/index.js"
|
|
65
88
|
},
|
|
66
89
|
"./source": {
|
|
67
|
-
"
|
|
68
|
-
"
|
|
90
|
+
"source": "./src/source/index.ts",
|
|
91
|
+
"types": "./dist/source/index.d.ts",
|
|
92
|
+
"import": "./dist/source/index.js",
|
|
93
|
+
"default": "./dist/source/index.js"
|
|
69
94
|
},
|
|
70
95
|
"./demo": {
|
|
71
|
-
"
|
|
72
|
-
"
|
|
96
|
+
"source": "./src/demo/index.ts",
|
|
97
|
+
"types": "./dist/demo/index.d.ts",
|
|
98
|
+
"import": "./dist/demo/index.js",
|
|
99
|
+
"default": "./dist/demo/index.js"
|
|
73
100
|
},
|
|
74
101
|
"./vite": {
|
|
75
|
-
"
|
|
76
|
-
"
|
|
102
|
+
"source": "./src/vite/index.ts",
|
|
103
|
+
"types": "./dist/vite/index.d.ts",
|
|
104
|
+
"import": "./dist/vite/index.js",
|
|
105
|
+
"default": "./dist/vite/index.js"
|
|
77
106
|
},
|
|
78
|
-
"./styles.css": "./
|
|
107
|
+
"./styles.css": "./dist/styles.css"
|
|
79
108
|
},
|
|
80
109
|
"dependencies": {
|
|
81
|
-
"@brett_lamy/viz-engine": ">=0.2.0",
|
|
82
110
|
"framer-motion": "^13.1.1",
|
|
83
111
|
"gpu-lexer": "^0.0.2",
|
|
84
112
|
"katex": "^0.18.5",
|
|
85
113
|
"lucide-react": "^1.17.0",
|
|
86
114
|
"mermaid": "^11.15.0",
|
|
87
115
|
"rrweb": "2.0.0-alpha.20",
|
|
88
|
-
"streamdown": "^2.5.0",
|
|
89
116
|
"yaml": "^2.9.0"
|
|
90
117
|
},
|
|
91
118
|
"peerDependencies": {
|
|
92
119
|
"@agent-wasm/core": ">=0.4.0",
|
|
93
120
|
"@brett_lamy/viz-engine": ">=0.2.0",
|
|
94
121
|
"react": ">=18",
|
|
122
|
+
"react-dom": ">=18",
|
|
95
123
|
"vite": ">=5"
|
|
96
124
|
},
|
|
97
125
|
"peerDependenciesMeta": {
|
|
126
|
+
"@agent-wasm/core": {
|
|
127
|
+
"optional": true
|
|
128
|
+
},
|
|
129
|
+
"@brett_lamy/viz-engine": {
|
|
130
|
+
"optional": true
|
|
131
|
+
},
|
|
98
132
|
"vite": {
|
|
99
133
|
"optional": true
|
|
100
134
|
}
|
|
@@ -105,10 +139,12 @@
|
|
|
105
139
|
},
|
|
106
140
|
"devDependencies": {
|
|
107
141
|
"@agent-wasm/core": "^0.4.0",
|
|
142
|
+
"@brett_lamy/viz-engine": "^0.2.1",
|
|
108
143
|
"@types/node": "^24.0.0",
|
|
109
144
|
"@types/react": "^18.3.3",
|
|
110
145
|
"typescript": "^5.5.4",
|
|
111
146
|
"vite": "^7.0.0",
|
|
112
147
|
"vitest": "^3.2.4"
|
|
113
|
-
}
|
|
148
|
+
},
|
|
149
|
+
"module": "./dist/index.js"
|
|
114
150
|
}
|
package/src/demo/types.ts
CHANGED
|
@@ -85,8 +85,8 @@ export interface InlineDemoRuntimeProps {
|
|
|
85
85
|
/**
|
|
86
86
|
* Renders the Preview of a `{% demo %}` block that carries its files inline and has
|
|
87
87
|
* no resolver behind it. `@brett_lamy/docstream/playground` provides an almost-node
|
|
88
|
-
* implementation (`createAlmostNodeDemoRuntime`), which `PlaygroundStreamdown`
|
|
89
|
-
* package root
|
|
88
|
+
* implementation (`createAlmostNodeDemoRuntime`), which that entry's `PlaygroundStreamdown`
|
|
89
|
+
* wires in by default. The package root never loads a runtime on its own.
|
|
90
90
|
*/
|
|
91
91
|
export type InlineDemoRuntime = (props: InlineDemoRuntimeProps) => ReactNode
|
|
92
92
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useContext, useId, useMemo, useState, type ReactNode } from "react"
|
|
1
|
+
import { useContext, useEffect, useId, useMemo, useState, type ReactNode } from "react"
|
|
2
2
|
import { motion, useReducedMotion } from "framer-motion"
|
|
3
|
-
import "katex/dist/katex.min.css"
|
|
4
3
|
import {
|
|
5
4
|
AlertTriangle,
|
|
6
5
|
CheckCircle2,
|
|
@@ -24,16 +23,41 @@ import { CopyButton } from "./copy"
|
|
|
24
23
|
import { PillTabs, rovingKeyDown } from "./controls"
|
|
25
24
|
import { DocPageActions, type DocPageActionsOptions } from "./PageActions"
|
|
26
25
|
import { useSyncedTab } from "./tabs-sync"
|
|
27
|
-
import { ReplayPreview
|
|
26
|
+
import { ReplayPreview } from "../replay/ReplayPreview"
|
|
27
|
+
import { isReplayQaUrl } from "../replay/url"
|
|
28
28
|
import { VideoEmbed } from "../video"
|
|
29
29
|
import { OpenApiOperation } from "../openapi/OpenApiOperation"
|
|
30
30
|
import { Mermaid } from "./Mermaid"
|
|
31
31
|
import { HighlightedCode } from "./HighlightedCode"
|
|
32
32
|
import { CitationSources, InlineReference } from "./reference"
|
|
33
|
-
import { renderMathToHtml } from "./math"
|
|
34
33
|
|
|
34
|
+
type MathRenderer = (formula: string) => string
|
|
35
|
+
let mathRenderer: MathRenderer | null = null
|
|
36
|
+
let mathLoad: Promise<MathRenderer> | null = null
|
|
37
|
+
function loadMathRenderer(): Promise<MathRenderer> {
|
|
38
|
+
mathLoad ??= import("./math").then((m) => (mathRenderer = m.renderMathToHtml))
|
|
39
|
+
return mathLoad
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// KaTeX loads on first use; until then the TeX source shows in place.
|
|
35
43
|
function MathBlock({ formula }: { formula: string }) {
|
|
36
|
-
|
|
44
|
+
const [render, setRender] = useState<MathRenderer | null>(() => mathRenderer)
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (render) return
|
|
47
|
+
let live = true
|
|
48
|
+
loadMathRenderer().then((fn) => live && setRender(() => fn), () => {})
|
|
49
|
+
return () => {
|
|
50
|
+
live = false
|
|
51
|
+
}
|
|
52
|
+
}, [render])
|
|
53
|
+
if (!render) {
|
|
54
|
+
return (
|
|
55
|
+
<div className="docs-math" data-pending="">
|
|
56
|
+
<code>{formula}</code>
|
|
57
|
+
</div>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
return <div className="docs-math" dangerouslySetInnerHTML={{ __html: render(formula) }} />
|
|
37
61
|
}
|
|
38
62
|
|
|
39
63
|
export interface LivePreviewProps {
|
|
@@ -561,8 +585,8 @@ export interface DocRenderOptions {
|
|
|
561
585
|
demoResolver?: DemoResolver
|
|
562
586
|
/**
|
|
563
587
|
* Runs the Preview of `{% demo %}` blocks that carry their files inline and have no
|
|
564
|
-
* resolver behind them.
|
|
565
|
-
*
|
|
588
|
+
* resolver behind them. Nothing is supplied by default: pass `createAlmostNodeDemoRuntime()`
|
|
589
|
+
* from `@brett_lamy/docstream/playground` (or use its `PlaygroundStreamdown`) to run them.
|
|
566
590
|
* Without one, such demos show their code with a short note.
|
|
567
591
|
*/
|
|
568
592
|
demoRuntime?: InlineDemoRuntime
|
package/src/docs/Mermaid.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useId,
|
|
1
|
+
import { useEffect, useId, useState, type CSSProperties } from "react"
|
|
2
2
|
import { HighlightedCode } from "./HighlightedCode"
|
|
3
3
|
|
|
4
4
|
let seq = 0
|
|
@@ -17,7 +17,6 @@ export function Mermaid({ code, collapsedCodeLines = 3, expandedCodeLines = 30 }
|
|
|
17
17
|
const [svg, setSvg] = useState<string | null>(null)
|
|
18
18
|
const [error, setError] = useState<string | null>(null)
|
|
19
19
|
const [codeExpanded, setCodeExpanded] = useState(false)
|
|
20
|
-
const idRef = useRef(`mermaid-${++seq}`)
|
|
21
20
|
const codePanelId = useId()
|
|
22
21
|
const collapsedLines = positiveLineCount(collapsedCodeLines, 3)
|
|
23
22
|
const expandedLines = Math.max(collapsedLines, positiveLineCount(expandedCodeLines, 30))
|
|
@@ -27,7 +26,10 @@ export function Mermaid({ code, collapsedCodeLines = 3, expandedCodeLines = 30 }
|
|
|
27
26
|
import("mermaid")
|
|
28
27
|
.then(async ({ default: mermaid }) => {
|
|
29
28
|
mermaid.initialize({ startOnLoad: false, securityLevel: "strict" })
|
|
30
|
-
|
|
29
|
+
// A fresh id per render: mermaid.render removes any element with the id it is given,
|
|
30
|
+
// so reusing one (StrictMode's double effect, a code change) deleted the diagram an
|
|
31
|
+
// earlier render had already mounted.
|
|
32
|
+
const { svg } = await mermaid.render(`mermaid-${++seq}`, code)
|
|
31
33
|
if (!cancelled) setSvg(svg)
|
|
32
34
|
})
|
|
33
35
|
.catch((e) => {
|
package/src/docs/math.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
/* KaTeX lives behind this module, which DocsRenderer loads with a dynamic import the
|
|
2
|
+
first time a page has a math block — pages without math never download KaTeX. */
|
|
1
3
|
import katex from "katex"
|
|
4
|
+
import "katex/dist/katex.min.css"
|
|
2
5
|
|
|
3
6
|
export function renderMathToHtml(formula: string): string {
|
|
4
7
|
return katex.renderToString(formula, {
|