@markdy/renderer-dom 1.0.9 → 1.0.11
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 +4 -3
- package/dist/chunk-VIZHA7GI.js +99 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +768 -328
- package/dist/svg-exporter-7FW6RIP6.js +10 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ import { createDiagram } from "@markdy/renderer-dom";
|
|
|
45
45
|
const diagram = createDiagram({
|
|
46
46
|
container: document.getElementById("scene")!,
|
|
47
47
|
code: `
|
|
48
|
-
scene
|
|
48
|
+
scene theme=paper
|
|
49
49
|
browser Web
|
|
50
50
|
service API
|
|
51
51
|
beat main:
|
|
@@ -77,8 +77,9 @@ diagram.destroy(); // clean up DOM + cancel animations
|
|
|
77
77
|
| `sceneBoundaryProgress` | `boolean \| string` | `true` | Show boundary progress bar, or pass a custom color/gradient string |
|
|
78
78
|
| `progressColor` | `string` | `plan.meta.progressColor ?? "rainbow"` | Custom progress bar color (e.g. `"#3b82f6"`) or gradient (e.g. `"#ec4899, #8b5cf6"`) |
|
|
79
79
|
| `playbackRate` | `number` | `plan.meta.playbackRate ?? 1` | Normalized timeline speed multiplier; `1` is Markdy's normal pace |
|
|
80
|
-
| `interactiveViewport` | `boolean` | `controls \|\|
|
|
81
|
-
| `controls` | `boolean` | `
|
|
80
|
+
| `interactiveViewport` | `boolean` | `controls \|\| player.interaction` | Enable wheel zoom and drag pan on the rendered viewport |
|
|
81
|
+
| `controls` | `boolean` | `player.controls` | Show the footer toolbar (play, prev/next beat, restart, seek, speed, fit, reset view, SVG, share); also enables viewport interaction |
|
|
82
|
+
| `shareUrl` | `string` | Markdy playground | Base URL used by the Share control when building `#code=` links |
|
|
82
83
|
| `onWarning` | `(warning: Diagnostic) => void` | `console.warn` | Called for each soft parse warning |
|
|
83
84
|
| `onTimeUpdate` | `(seconds: number, durationSeconds: number) => void` | — | Called whenever playback or seek changes the current time |
|
|
84
85
|
| `onPlayStateChange` | `(playing: boolean) => void` | — | Called when playback starts or pauses |
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/export/svg-exporter.ts
|
|
2
|
+
function copyRenderedStyles(source, clone) {
|
|
3
|
+
if (typeof window === "undefined" || typeof window.getComputedStyle !== "function") return;
|
|
4
|
+
const sourceElements = [source, ...Array.from(source.querySelectorAll("*"))];
|
|
5
|
+
const cloneElements = [clone, ...Array.from(clone.querySelectorAll("*"))];
|
|
6
|
+
for (let index = 0; index < Math.min(sourceElements.length, cloneElements.length); index++) {
|
|
7
|
+
const computed = window.getComputedStyle(sourceElements[index]);
|
|
8
|
+
const target = cloneElements[index].style;
|
|
9
|
+
for (let propertyIndex = 0; propertyIndex < computed.length; propertyIndex++) {
|
|
10
|
+
const property = computed.item(propertyIndex);
|
|
11
|
+
target.setProperty(property, computed.getPropertyValue(property), computed.getPropertyPriority(property));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function normalizeExportViewport(scene) {
|
|
16
|
+
scene.querySelectorAll(".markdy-viewport-transform").forEach((viewportTransform) => {
|
|
17
|
+
viewportTransform.style.transform = "translate(0px, 0px) scale(1)";
|
|
18
|
+
viewportTransform.style.transformOrigin = "0 0";
|
|
19
|
+
viewportTransform.style.willChange = "auto";
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function getDiagramSceneElement(containerEl) {
|
|
23
|
+
const sceneEl = containerEl.classList?.contains("markdy-scene-root") ? containerEl : containerEl.querySelector(".markdy-scene-root") || containerEl.querySelector("svg") || (containerEl.tagName?.toLowerCase() === "svg" ? containerEl : null);
|
|
24
|
+
if (!sceneEl) throw new Error("No Markdy scene element found in container");
|
|
25
|
+
return sceneEl;
|
|
26
|
+
}
|
|
27
|
+
function prepareHtmlSceneForExport(sceneEl, options = {}) {
|
|
28
|
+
const clonedScene = sceneEl.cloneNode(true);
|
|
29
|
+
copyRenderedStyles(sceneEl, clonedScene);
|
|
30
|
+
normalizeExportViewport(clonedScene);
|
|
31
|
+
const widthStr = clonedScene.style.width || String(sceneEl.clientWidth || 800);
|
|
32
|
+
const heightStr = clonedScene.style.height || String(sceneEl.clientHeight || 400);
|
|
33
|
+
let width = parseFloat(widthStr);
|
|
34
|
+
let height = parseFloat(heightStr);
|
|
35
|
+
if (isNaN(width)) width = 800;
|
|
36
|
+
if (isNaN(height)) height = 400;
|
|
37
|
+
const scale = options.scale || 1;
|
|
38
|
+
const scaledWidth = width * scale;
|
|
39
|
+
const scaledHeight = height * scale;
|
|
40
|
+
clonedScene.style.transform = `scale(${scale})`;
|
|
41
|
+
clonedScene.style.transformOrigin = "0 0";
|
|
42
|
+
clonedScene.style.position = "relative";
|
|
43
|
+
clonedScene.style.left = "0px";
|
|
44
|
+
clonedScene.style.top = "0px";
|
|
45
|
+
clonedScene.style.margin = "0";
|
|
46
|
+
clonedScene.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
|
47
|
+
if (options.transparentBackground) {
|
|
48
|
+
clonedScene.style.background = "transparent";
|
|
49
|
+
}
|
|
50
|
+
return { sceneEl, clonedScene, width, height, scaledWidth, scaledHeight };
|
|
51
|
+
}
|
|
52
|
+
function exportDiagramAsVectorSvg(containerEl, options = {}) {
|
|
53
|
+
const sceneEl = getDiagramSceneElement(containerEl);
|
|
54
|
+
if (sceneEl.tagName?.toLowerCase() === "svg") {
|
|
55
|
+
const clonedSvg = sceneEl.cloneNode(true);
|
|
56
|
+
if (!clonedSvg.getAttribute("xmlns")) {
|
|
57
|
+
clonedSvg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
58
|
+
}
|
|
59
|
+
const serializer2 = new XMLSerializer();
|
|
60
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
61
|
+
${serializer2.serializeToString(clonedSvg)}`;
|
|
62
|
+
}
|
|
63
|
+
const { clonedScene, scaledWidth, scaledHeight } = prepareHtmlSceneForExport(sceneEl, options);
|
|
64
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
65
|
+
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
66
|
+
svg.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
|
|
67
|
+
svg.setAttribute("width", String(scaledWidth));
|
|
68
|
+
svg.setAttribute("height", String(scaledHeight));
|
|
69
|
+
svg.setAttribute("viewBox", `0 0 ${scaledWidth} ${scaledHeight}`);
|
|
70
|
+
if (options.includeThemeStyles !== false) {
|
|
71
|
+
const styleEl = document.createElementNS("http://www.w3.org/2000/svg", "style");
|
|
72
|
+
let combinedStyles = `
|
|
73
|
+
foreignObject { width: 100%; height: 100%; }
|
|
74
|
+
.markdy-node { transition: opacity 0.3s ease; }
|
|
75
|
+
`;
|
|
76
|
+
if (typeof document !== "undefined") {
|
|
77
|
+
const styles = document.querySelectorAll("style[id^='markdy-']");
|
|
78
|
+
for (let i = 0; i < styles.length; i++) {
|
|
79
|
+
combinedStyles += styles[i].textContent + "\n";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
styleEl.textContent = combinedStyles;
|
|
83
|
+
svg.appendChild(styleEl);
|
|
84
|
+
}
|
|
85
|
+
const foreignObject = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
|
|
86
|
+
foreignObject.setAttribute("width", "100%");
|
|
87
|
+
foreignObject.setAttribute("height", "100%");
|
|
88
|
+
foreignObject.appendChild(clonedScene);
|
|
89
|
+
svg.appendChild(foreignObject);
|
|
90
|
+
const serializer = new XMLSerializer();
|
|
91
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
92
|
+
` + serializer.serializeToString(svg);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
getDiagramSceneElement,
|
|
97
|
+
prepareHtmlSceneForExport,
|
|
98
|
+
exportDiagramAsVectorSvg
|
|
99
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ interface DiagramOptions {
|
|
|
28
28
|
playbackRate?: number;
|
|
29
29
|
/** Enable wheel zoom and drag pan on the rendered viewport. Defaults to false. */
|
|
30
30
|
interactiveViewport?: boolean;
|
|
31
|
+
/** Base URL for the Share control. Defaults to the Markdy playground. */
|
|
32
|
+
shareUrl?: string;
|
|
31
33
|
/** Show built-in playback and viewport controls. Also enables viewport interaction. Defaults to false. */
|
|
32
34
|
controls?: boolean;
|
|
33
35
|
onWarning?: (warning: Diagnostic) => void;
|
|
@@ -46,6 +48,8 @@ interface Diagram {
|
|
|
46
48
|
isPlaying(): boolean;
|
|
47
49
|
beats(): BeatRange[];
|
|
48
50
|
seekToBeat(name: string): void;
|
|
51
|
+
nextBeat(): void;
|
|
52
|
+
prevBeat(): void;
|
|
49
53
|
destroy(): void;
|
|
50
54
|
}
|
|
51
55
|
declare function createDiagram(opts: DiagramOptions): Diagram;
|