@markgrafhq/docusaurus-plugin-markgraf 0.0.42

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark Eibes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # @markgrafhq/docusaurus-plugin-markgraf
2
+
3
+ Docusaurus plugin + component for embedding [markgraf](https://github.com/markgrafhq) animations.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @markgrafhq/docusaurus-plugin-markgraf @markgrafhq/markgraf-react
9
+ ```
10
+
11
+ ## Configure
12
+
13
+ ```js
14
+ // docusaurus.config.js
15
+ import remarkMarkgraf from "@markgrafhq/docusaurus-plugin-markgraf/remark";
16
+
17
+ export default {
18
+ presets: [
19
+ [
20
+ "classic",
21
+ {
22
+ docs: { remarkPlugins: [remarkMarkgraf] },
23
+ blog: { remarkPlugins: [remarkMarkgraf] },
24
+ },
25
+ ],
26
+ ],
27
+ plugins: ["@markgrafhq/docusaurus-plugin-markgraf"],
28
+ };
29
+ ```
30
+
31
+ Then add the CSS in your custom CSS entry:
32
+
33
+ ```css
34
+ @import "@markgrafhq/docusaurus-plugin-markgraf/css";
35
+ ```
36
+
37
+ ## Use
38
+
39
+ Fenced code blocks with the `markgraf` language render as live players:
40
+
41
+ ````markdown
42
+ ```markgraf
43
+ seed 1
44
+ scene v1 {
45
+ + client: Client
46
+ + api: API
47
+ + client -> api
48
+ client ~> api: GET /user/42
49
+ }
50
+ ```
51
+ ````
52
+
53
+ Or use the component directly in MDX:
54
+
55
+ ```mdx
56
+ import { Markgraf } from "@markgrafhq/docusaurus-plugin-markgraf";
57
+
58
+ <Markgraf src={`seed 1\nscene v1 { + a: A }`} />
59
+ ```
60
+
61
+ Players include the floating play, scrub, time, and speed controls by default.
62
+ Hide them with `controls={false}`, or replace them with a render function that
63
+ receives the underlying `MarkgrafApi`:
64
+
65
+ ```mdx
66
+ <Markgraf
67
+ src={source}
68
+ controls={(api) => <MyDiagramControls api={api} />}
69
+ />
70
+ ```
@@ -0,0 +1,16 @@
1
+ import React, { type ReactNode } from "react";
2
+ import { type MarkgrafApi } from "@markgrafhq/markgraf-react";
3
+ type Renderer = "canvas" | "svg";
4
+ export type MarkgrafControls = boolean | ((api: MarkgrafApi<Element>) => ReactNode);
5
+ export interface MarkgrafProps {
6
+ src: string;
7
+ renderer?: Renderer;
8
+ className?: string;
9
+ /**
10
+ * Shows the transport bar by default. Pass `false` to hide it, or a render
11
+ * function to replace it with controls driven by the same player API.
12
+ */
13
+ controls?: MarkgrafControls;
14
+ }
15
+ export default function Markgraf(props: MarkgrafProps): React.JSX.Element;
16
+ export {};
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { useMarkgraf } from "@markgrafhq/markgraf-react";
4
+ const playIcon = (_jsx("svg", { viewBox: "0 0 15 15", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M3.24 2.05a.5.5 0 0 1 .52.02l8.5 5a.5.5 0 0 1 0 .86l-8.5 5A.5.5 0 0 1 3 12.5v-10a.5.5 0 0 1 .24-.45Z" }) }));
5
+ const pauseIcon = (_jsx("svg", { viewBox: "0 0 15 15", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M3.5 2.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 .5.5v10a.5.5 0 0 1-.5.5H4a.5.5 0 0 1-.5-.5v-10Zm5 0A.5.5 0 0 1 9 2h2a.5.5 0 0 1 .5.5v10a.5.5 0 0 1-.5.5H9a.5.5 0 0 1-.5-.5v-10Z" }) }));
6
+ const speedIcon = (_jsx("svg", { className: "markgraf-doc-speed-icon", viewBox: "0 0 15 15", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M3.14 5.64a.5.5 0 0 1 .71 0L7.5 9.29l3.65-3.65a.5.5 0 0 1 .7.71l-4 4a.5.5 0 0 1-.7 0l-4-4a.5.5 0 0 1 0-.71Z" }) }));
7
+ const useDocumentTheme = () => {
8
+ const [theme, setTheme] = useState("light");
9
+ useEffect(() => {
10
+ const root = document.documentElement;
11
+ const update = () => setTheme(root.dataset.theme === "dark" ? "dark" : "light");
12
+ update();
13
+ const observer = new MutationObserver(update);
14
+ observer.observe(root, {
15
+ attributes: true,
16
+ attributeFilter: ["data-theme"],
17
+ });
18
+ return () => observer.disconnect();
19
+ }, []);
20
+ return theme;
21
+ };
22
+ const formatTime = (seconds) => {
23
+ const safe = Number.isFinite(seconds) ? Math.max(0, seconds) : 0;
24
+ const minutes = Math.floor(safe / 60);
25
+ const remainder = safe - minutes * 60;
26
+ return `${minutes}:${remainder.toFixed(1).padStart(4, "0")}`;
27
+ };
28
+ const DefaultControls = ({ api, speed, setSpeed, }) => {
29
+ const duration = Number.isFinite(api.duration)
30
+ ? Math.max(0, api.duration)
31
+ : 0;
32
+ const time = Number.isFinite(api.time)
33
+ ? Math.max(0, Math.min(api.time, duration))
34
+ : 0;
35
+ return (_jsxs("div", { className: "markgraf-doc-controls", "aria-label": "Diagram playback controls", children: [_jsx("button", { className: "markgraf-doc-play", type: "button", "aria-label": api.playing ? "Pause diagram" : "Play diagram", "aria-pressed": api.playing, disabled: !api.ready, onClick: api.toggle, children: api.playing ? pauseIcon : playIcon }), _jsx("input", { className: "markgraf-doc-scrub", type: "range", "aria-label": "Diagram time", min: "0", max: Math.max(duration, 0.001), step: "0.01", value: time, disabled: !api.ready, onChange: (event) => api.seek(event.currentTarget.valueAsNumber) }), _jsxs("output", { className: "markgraf-doc-time", "aria-live": "off", children: [formatTime(time), " / ", formatTime(duration)] }), _jsxs("div", { className: "markgraf-doc-speed-control", children: [_jsxs("select", { className: "markgraf-doc-speed", "aria-label": "Playback speed", value: speed, disabled: !api.ready, onChange: (event) => setSpeed(Number(event.currentTarget.value)), children: [_jsx("option", { value: "0.5", children: "0.5\u00D7" }), _jsx("option", { value: "1", children: "1\u00D7" }), _jsx("option", { value: "1.5", children: "1.5\u00D7" }), _jsx("option", { value: "2", children: "2\u00D7" })] }), speedIcon] })] }));
36
+ };
37
+ const Controls = ({ api, controls, }) => {
38
+ const [speed, setSpeed] = useState(1);
39
+ useEffect(() => {
40
+ if (controls === true && api.ready)
41
+ api.setSpeed(speed);
42
+ }, [api.ready, controls, speed]);
43
+ if (typeof controls === "function")
44
+ return controls(api);
45
+ if (!controls)
46
+ return null;
47
+ return _jsx(DefaultControls, { api: api, speed: speed, setSpeed: setSpeed });
48
+ };
49
+ const CanvasPlayer = ({ src, theme, className, controls, }) => {
50
+ const api = useMarkgraf(src, { renderer: "canvas", theme });
51
+ return (_jsxs("div", { className: `markgraf-doc-player ${className ?? ""}`, "data-markgraf-theme": theme, children: [_jsx("canvas", { className: "markgraf-player markgraf-doc-stage", ref: api.elementRef, onClick: api.toggle, "aria-label": "Animated Markgraf diagram" }), _jsx(Controls, { api: api, controls: controls })] }));
52
+ };
53
+ const SvgPlayer = ({ src, theme, className, controls, }) => {
54
+ const api = useMarkgraf(src, { renderer: "svg", theme });
55
+ return (_jsxs("div", { className: `markgraf-doc-player ${className ?? ""}`, "data-markgraf-theme": theme, children: [_jsx("svg", { className: "markgraf-player markgraf-doc-stage", ref: api.elementRef, onClick: api.toggle, "aria-label": "Animated Markgraf diagram" }), _jsx(Controls, { api: api, controls: controls })] }));
56
+ };
57
+ const MountedPlayer = (props) => {
58
+ const theme = useDocumentTheme();
59
+ return props.renderer === "svg" ? (_jsx(SvgPlayer, { ...props, renderer: "svg", theme: theme, controls: props.controls ?? true })) : (_jsx(CanvasPlayer, { ...props, renderer: "canvas", theme: theme, controls: props.controls ?? true }));
60
+ };
61
+ export default function Markgraf(props) {
62
+ const [mounted, setMounted] = useState(false);
63
+ useEffect(() => setMounted(true), []);
64
+ if (!mounted) {
65
+ return (_jsx("div", { className: `markgraf-doc-player ${props.className ?? ""}`, "data-markgraf-placeholder": "" }));
66
+ }
67
+ return _jsx(MountedPlayer, { ...props });
68
+ }
@@ -0,0 +1,13 @@
1
+ import remarkMarkgraf from "./remark-markgraf.mjs";
2
+ export { default as Markgraf, type MarkgrafControls, type MarkgrafProps, } from "./Markgraf.js";
3
+ export default function pluginMarkgraf(): {
4
+ name: string;
5
+ configureWebpack(): {
6
+ resolve: {
7
+ extensionAlias: {
8
+ ".js": string[];
9
+ };
10
+ };
11
+ };
12
+ };
13
+ export { remarkMarkgraf };
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import remarkMarkgraf from "./remark-markgraf.mjs";
2
+ export { default as Markgraf, } from "./Markgraf.js";
3
+ export default function pluginMarkgraf() {
4
+ return {
5
+ name: "markgraf-docusaurus",
6
+ configureWebpack() {
7
+ return { resolve: { extensionAlias: { ".js": [".js", ".ts", ".tsx"] } } };
8
+ },
9
+ };
10
+ }
11
+ export { remarkMarkgraf };
@@ -0,0 +1,154 @@
1
+ @import "@markgrafhq/markgraf-react/css";
2
+
3
+ .markgraf-doc-player {
4
+ position: relative;
5
+ display: flex;
6
+ flex-direction: column;
7
+ width: 100%;
8
+ min-width: 0;
9
+ min-height: 11.25rem;
10
+ aspect-ratio: 16 / 9;
11
+ overflow: hidden;
12
+ border: 1px solid color-mix(in srgb, currentColor 14%, transparent);
13
+ border-radius: 0.875rem;
14
+ background: #ffffff;
15
+ box-shadow: 0 1rem 3rem rgb(0 0 0 / 10%);
16
+ }
17
+
18
+ .markgraf-doc-player[data-markgraf-theme="dark"] {
19
+ background: #101827;
20
+ }
21
+
22
+ .markgraf-doc-stage {
23
+ display: block;
24
+ width: 100%;
25
+ height: 100%;
26
+ min-height: 11.25rem;
27
+ cursor: pointer;
28
+ }
29
+
30
+ .markgraf-doc-controls {
31
+ position: absolute;
32
+ z-index: 2;
33
+ right: 50%;
34
+ bottom: 0.75rem;
35
+ display: grid;
36
+ grid-template-columns: 1.75rem minmax(7rem, 1fr) auto auto;
37
+ align-items: center;
38
+ gap: 0.5rem;
39
+ width: min(35rem, calc(100% - 2rem));
40
+ padding: 0.375rem 0.5rem;
41
+ border: 1px solid rgb(255 255 255 / 14%);
42
+ border-radius: 999px;
43
+ color: #ffffff;
44
+ background: rgb(8 13 22 / 58%);
45
+ box-shadow: 0 0.875rem 2.75rem rgb(0 0 0 / 28%);
46
+ opacity: 0.78;
47
+ transform: translateX(50%);
48
+ transition:
49
+ opacity 140ms ease,
50
+ background 140ms ease;
51
+ backdrop-filter: blur(18px);
52
+ }
53
+
54
+ .markgraf-doc-player:hover .markgraf-doc-controls,
55
+ .markgraf-doc-controls:focus-within {
56
+ background: rgb(8 13 22 / 78%);
57
+ opacity: 0.98;
58
+ }
59
+
60
+ .markgraf-doc-play {
61
+ display: grid;
62
+ width: 1.75rem;
63
+ height: 1.75rem;
64
+ padding: 0;
65
+ border: 0;
66
+ border-radius: 999px;
67
+ place-items: center;
68
+ color: inherit;
69
+ background: rgb(255 255 255 / 10%);
70
+ cursor: pointer;
71
+ }
72
+
73
+ .markgraf-doc-play:hover,
74
+ .markgraf-doc-play:focus-visible {
75
+ background: rgb(255 255 255 / 20%);
76
+ }
77
+
78
+ .markgraf-doc-play svg {
79
+ width: 0.875rem;
80
+ height: 0.875rem;
81
+ }
82
+
83
+ .markgraf-doc-scrub {
84
+ min-width: 0;
85
+ height: 0.875rem;
86
+ margin: 0;
87
+ accent-color: #ffffff;
88
+ cursor: pointer;
89
+ }
90
+
91
+ .markgraf-doc-time {
92
+ color: rgb(255 255 255 / 76%);
93
+ font-family: var(
94
+ --sl-font-mono,
95
+ var(--ifm-font-family-monospace, ui-monospace, monospace)
96
+ );
97
+ font-size: 0.625rem;
98
+ line-height: 1;
99
+ font-variant-numeric: tabular-nums;
100
+ white-space: nowrap;
101
+ }
102
+
103
+ .markgraf-doc-speed-control {
104
+ position: relative;
105
+ display: flex;
106
+ align-items: center;
107
+ }
108
+
109
+ .markgraf-doc-speed {
110
+ appearance: none;
111
+ width: 100%;
112
+ padding: 0.1875rem 1.375rem 0.1875rem 0.5rem;
113
+ border: 0;
114
+ border-radius: 999px;
115
+ color: #ffffff;
116
+ background: rgb(255 255 255 / 10%);
117
+ font-size: 0.625rem;
118
+ cursor: pointer;
119
+ }
120
+
121
+ .markgraf-doc-speed-icon {
122
+ position: absolute;
123
+ right: 0.4375rem;
124
+ width: 0.75rem;
125
+ height: 0.75rem;
126
+ color: rgb(255 255 255 / 72%);
127
+ pointer-events: none;
128
+ }
129
+
130
+ .markgraf-doc-speed option {
131
+ color: #111827;
132
+ background: #ffffff;
133
+ }
134
+
135
+ .markgraf-doc-controls :disabled {
136
+ cursor: wait;
137
+ opacity: 0.5;
138
+ }
139
+
140
+ @media (max-width: 32rem) {
141
+ .markgraf-doc-controls {
142
+ grid-template-columns: 1.75rem minmax(5rem, 1fr) auto;
143
+ }
144
+
145
+ .markgraf-doc-time {
146
+ display: none;
147
+ }
148
+ }
149
+
150
+ @media (prefers-reduced-motion: reduce) {
151
+ .markgraf-doc-controls {
152
+ transition: none;
153
+ }
154
+ }
@@ -0,0 +1,56 @@
1
+ import { visit } from "unist-util-visit";
2
+
3
+ const importNode = {
4
+ type: "mdxjsEsm",
5
+ value: 'import Markgraf from "@markgrafhq/docusaurus-plugin-markgraf/dist/Markgraf.js";',
6
+ data: {
7
+ estree: {
8
+ type: "Program",
9
+ sourceType: "module",
10
+ body: [
11
+ {
12
+ type: "ImportDeclaration",
13
+ specifiers: [
14
+ {
15
+ type: "ImportDefaultSpecifier",
16
+ local: { type: "Identifier", name: "Markgraf" },
17
+ },
18
+ ],
19
+ source: {
20
+ type: "Literal",
21
+ value: "@markgrafhq/docusaurus-plugin-markgraf/dist/Markgraf.js",
22
+ raw: '"@markgrafhq/docusaurus-plugin-markgraf/dist/Markgraf.js"',
23
+ },
24
+ },
25
+ ],
26
+ },
27
+ },
28
+ };
29
+
30
+ export default function remarkMarkgraf() {
31
+ return (tree) => {
32
+ let needsImport = false;
33
+
34
+ visit(tree, "code", (node, index, parent) => {
35
+ if (node.lang !== "markgraf" || !parent || index == null) return;
36
+
37
+ needsImport = true;
38
+
39
+ const src = node.value;
40
+ parent.children[index] = {
41
+ type: "mdxJsxFlowElement",
42
+ name: "Markgraf",
43
+ attributes: [
44
+ {
45
+ type: "mdxJsxAttribute",
46
+ name: "src",
47
+ value: src,
48
+ },
49
+ ],
50
+ children: [],
51
+ };
52
+ });
53
+
54
+ if (needsImport) tree.children.unshift(importNode);
55
+ };
56
+ }
@@ -0,0 +1,56 @@
1
+ import { visit } from "unist-util-visit";
2
+
3
+ const importNode = {
4
+ type: "mdxjsEsm",
5
+ value: 'import Markgraf from "@markgrafhq/docusaurus-plugin-markgraf/dist/Markgraf.js";',
6
+ data: {
7
+ estree: {
8
+ type: "Program",
9
+ sourceType: "module",
10
+ body: [
11
+ {
12
+ type: "ImportDeclaration",
13
+ specifiers: [
14
+ {
15
+ type: "ImportDefaultSpecifier",
16
+ local: { type: "Identifier", name: "Markgraf" },
17
+ },
18
+ ],
19
+ source: {
20
+ type: "Literal",
21
+ value: "@markgrafhq/docusaurus-plugin-markgraf/dist/Markgraf.js",
22
+ raw: '"@markgrafhq/docusaurus-plugin-markgraf/dist/Markgraf.js"',
23
+ },
24
+ },
25
+ ],
26
+ },
27
+ },
28
+ };
29
+
30
+ export default function remarkMarkgraf() {
31
+ return (tree) => {
32
+ let needsImport = false;
33
+
34
+ visit(tree, "code", (node, index, parent) => {
35
+ if (node.lang !== "markgraf" || !parent || index == null) return;
36
+
37
+ needsImport = true;
38
+
39
+ const src = node.value;
40
+ parent.children[index] = {
41
+ type: "mdxJsxFlowElement",
42
+ name: "Markgraf",
43
+ attributes: [
44
+ {
45
+ type: "mdxJsxAttribute",
46
+ name: "src",
47
+ value: src,
48
+ },
49
+ ],
50
+ children: [],
51
+ };
52
+ });
53
+
54
+ if (needsImport) tree.children.unshift(importNode);
55
+ };
56
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@markgrafhq/docusaurus-plugin-markgraf",
3
+ "version": "0.0.42",
4
+ "description": "Docusaurus plugin + component for embedding markgraf animations. Transforms ```markgraf fenced code blocks into a live player and exposes a <Markgraf src=\"…\" /> MDX component.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./remark": {
15
+ "default": "./dist/remark-markgraf.js"
16
+ },
17
+ "./dist/*": "./dist/*",
18
+ "./css": "./dist/markgraf-react.css"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
25
+ "sideEffects": [
26
+ "./dist/markgraf-react.css"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsc -p tsconfig.json && cp src/remark-markgraf.mjs dist/remark-markgraf.mjs && cp src/remark-markgraf.mjs dist/remark-markgraf.js && cp src/player.css dist/markgraf-react.css"
30
+ },
31
+ "peerDependencies": {
32
+ "@docusaurus/core": ">=3",
33
+ "react": ">=18",
34
+ "react-dom": ">=18"
35
+ },
36
+ "dependencies": {
37
+ "@markgrafhq/markgraf-react": "0.0.42",
38
+ "unist-util-visit": "^5"
39
+ },
40
+ "devDependencies": {
41
+ "@types/react": "^18",
42
+ "typescript": "^5"
43
+ },
44
+ "keywords": [
45
+ "markgraf",
46
+ "docusaurus",
47
+ "docusaurus-plugin",
48
+ "mdx",
49
+ "remark",
50
+ "animation",
51
+ "diagram"
52
+ ],
53
+ "license": "MIT",
54
+ "author": "Mark Eibes <mark.eibes@gmail.com>",
55
+ "homepage": "https://github.com/markgrafhq/docusaurus-plugin-markgraf#readme",
56
+ "bugs": "https://github.com/markgrafhq/docusaurus-plugin-markgraf/issues",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/markgrafhq/docusaurus-plugin-markgraf.git"
60
+ }
61
+ }