@markdy/renderer-dom 1.4.3 → 1.4.5
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 +13 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.js +76 -25
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
<a href="https://markdy.com/playground/"><img src="https://img.shields.io/badge/⚡_Live_Studio-markdy.com%2Fplayground-3b82f6?style=for-the-badge" alt="Live Studio" /></a>
|
|
5
5
|
<a href="https://markdy.com/docs/"><img src="https://img.shields.io/badge/📖_Docs-Documentation-10b981?style=for-the-badge" alt="Documentation" /></a>
|
|
6
6
|
<a href="https://markdy.com/examples/"><img src="https://img.shields.io/badge/🌟_Blueprints-30+_Examples-f59e0b?style=for-the-badge" alt="Examples" /></a>
|
|
7
|
+
<a href="https://github.com/sponsors/HoangYell"><img src="https://img.shields.io/badge/💖_Sponsor-Support_Markdy-ea4aaa?style=for-the-badge" alt="Sponsor Markdy" /></a>
|
|
7
8
|
</p>
|
|
8
9
|
|
|
9
10
|
Web Animations API renderer for [MarkdyScript](https://markdy.com/docs/) scenes. Translates a parsed AST into 60fps GPU-accelerated DOM elements and drives the animation timeline with interactive analytical capabilities (Blast Radius, Route Pathfinder, and SVG/GIF export).
|
|
10
11
|
|
|
11
12
|
> 🚀 **Try it live**: Test MarkdyScript in the browser at **[markdy.com/playground](https://markdy.com/playground/)**
|
|
12
|
-
> 📚 **Documentation**: Complete syntax guide and examples at **[markdy.com/docs](https://markdy.com/docs/)**
|
|
13
|
+
> 📚 **Documentation**: Complete syntax guide and examples at **[markdy.com/docs](https://markdy.com/docs/)**
|
|
14
|
+
> 💼 **Enterprise & Commercial**: Free under MIT. To support development or request custom architecture blueprints, explore **[GitHub Sponsors](https://github.com/sponsors/HoangYell)**.
|
|
13
15
|
|
|
14
16
|
## Features
|
|
15
17
|
|
|
@@ -149,6 +151,16 @@ when capture fails. Browser font and cross-origin image restrictions still apply
|
|
|
149
151
|
| `exportDiagramAsPng(container, opts?)` | `Function` | Export high-DPI rasterized PNG Blob |
|
|
150
152
|
| `exportDiagramAsGif(container, timeline, opts?)` | `Function` | Export animated GIF89a recording |
|
|
151
153
|
|
|
154
|
+
## Development & Visual Harness
|
|
155
|
+
|
|
156
|
+
To inspect the renderer visually during local development:
|
|
157
|
+
|
|
158
|
+
```sh
|
|
159
|
+
pnpm --filter @markdy/renderer-dom run harness
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The harness runs on **`http://127.0.0.1:4325`** (port 4325 is decoupled from Astro's default port 4321 to avoid collisions with documentation previews). It serves canonical test fixtures, live theme switching, and real-time interactive DOM rendering.
|
|
163
|
+
|
|
152
164
|
## Ecosystem & Documentation
|
|
153
165
|
|
|
154
166
|
- ⚡ **[Interactive Studio / Playground](https://markdy.com/playground/)** — edit MarkdyScript with instant live preview in your browser
|
package/dist/index.d.ts
CHANGED
|
@@ -186,6 +186,18 @@ interface DiagramOptions {
|
|
|
186
186
|
* Defaults to 28px for grouped diagrams and 22px for ungrouped diagrams.
|
|
187
187
|
*/
|
|
188
188
|
contentPadding?: number;
|
|
189
|
+
/**
|
|
190
|
+
* Initial fit-all-in-view state. Defaults to true when undeclared.
|
|
191
|
+
* If false, starts in unconstrained mode.
|
|
192
|
+
*/
|
|
193
|
+
defaultFit?: boolean;
|
|
194
|
+
/** Alias for defaultFit. */
|
|
195
|
+
fit?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Optional custom fullscreen toggle handler.
|
|
198
|
+
* When provided, the footer fullscreen control delegates toggling to this callback.
|
|
199
|
+
*/
|
|
200
|
+
onFullscreen?: (isFull: boolean) => void;
|
|
189
201
|
}
|
|
190
202
|
interface Diagram {
|
|
191
203
|
play(): void;
|
|
@@ -206,6 +218,7 @@ interface Diagram {
|
|
|
206
218
|
exportGif(options?: GifDiagramExportOptions): Promise<Blob>;
|
|
207
219
|
resize(): void;
|
|
208
220
|
resetView(): void;
|
|
221
|
+
syncFullscreen(isFull?: boolean): void;
|
|
209
222
|
destroy(): void;
|
|
210
223
|
}
|
|
211
224
|
/**
|
package/dist/index.js
CHANGED
|
@@ -6211,17 +6211,22 @@ function createDiagram(opts) {
|
|
|
6211
6211
|
onTimeUpdate,
|
|
6212
6212
|
onPlayStateChange,
|
|
6213
6213
|
onEnded,
|
|
6214
|
+
onFullscreen,
|
|
6214
6215
|
responsiveLayout = "auto",
|
|
6215
6216
|
fitMode = "auto",
|
|
6216
6217
|
minReadableScale = 0.9,
|
|
6217
6218
|
targetWidthRatio = 0.96,
|
|
6218
|
-
contentPadding
|
|
6219
|
+
contentPadding,
|
|
6220
|
+
defaultFit,
|
|
6221
|
+
fit: explicitFitOption
|
|
6219
6222
|
} = opts;
|
|
6223
|
+
const initialContainerHeight = container.clientHeight || 0;
|
|
6224
|
+
const hasInitialHeightConstraint = initialContainerHeight > 0 && !container.style.aspectRatio;
|
|
6220
6225
|
function detectContainerOrientation(previous) {
|
|
6221
6226
|
const width = container.clientWidth || (typeof window === "undefined" ? 1024 : window.innerWidth);
|
|
6222
|
-
const height =
|
|
6227
|
+
const height = hasInitialHeightConstraint ? initialContainerHeight : 0;
|
|
6223
6228
|
const breakpoint = previous === "portrait" ? 672 : previous === "landscape" ? 608 : 640;
|
|
6224
|
-
if (height > 0
|
|
6229
|
+
if (height > 0) {
|
|
6225
6230
|
const ratio = width / height;
|
|
6226
6231
|
const ratioBreakpoint = previous === "portrait" ? 1.15 : previous === "landscape" ? 0.88 : 1;
|
|
6227
6232
|
if (ratio >= ratioBreakpoint) {
|
|
@@ -6235,8 +6240,8 @@ function createDiagram(opts) {
|
|
|
6235
6240
|
for (const w of ast.diagnostics) {
|
|
6236
6241
|
if (w.severity === "warning") onWarning(w);
|
|
6237
6242
|
}
|
|
6238
|
-
const hasExplicitDirection = ast.meta.explicitDirection === true;
|
|
6239
|
-
const shouldAdaptOrientation = responsiveLayout === true || responsiveLayout === "auto" && !hasExplicitDirection;
|
|
6243
|
+
const hasExplicitDirection = ast.meta.explicitDirection === true && ast.meta.layoutMode !== "auto";
|
|
6244
|
+
const shouldAdaptOrientation = ast.meta.layoutMode === "auto" || responsiveLayout === true || responsiveLayout === "auto" && !hasExplicitDirection;
|
|
6240
6245
|
const reverseDirection = ast.meta.direction === "RL" || ast.meta.direction === "BT";
|
|
6241
6246
|
const directionForOrientation = (orientation) => orientation === "portrait" ? reverseDirection ? "BT" : "TB" : reverseDirection ? "RL" : "LR";
|
|
6242
6247
|
let activeOrientation = detectContainerOrientation();
|
|
@@ -6605,7 +6610,15 @@ function createDiagram(opts) {
|
|
|
6605
6610
|
function layoutForDirection(direction) {
|
|
6606
6611
|
const cached = layoutPlans.get(direction);
|
|
6607
6612
|
if (cached?.plan.theme === plan.theme) return cached;
|
|
6608
|
-
const
|
|
6613
|
+
const candidateAst = {
|
|
6614
|
+
...ast,
|
|
6615
|
+
meta: {
|
|
6616
|
+
...ast.meta,
|
|
6617
|
+
direction,
|
|
6618
|
+
...ast.meta.layoutMode === "auto" || responsiveLayout === true ? { explicitWidth: false, explicitHeight: false } : {}
|
|
6619
|
+
}
|
|
6620
|
+
};
|
|
6621
|
+
const candidate = compilePlan(candidateAst, plan.theme);
|
|
6609
6622
|
const entry = { plan: candidate, bounds: computeDiagramContentBounds(candidate, { padding: contentPadding }) };
|
|
6610
6623
|
layoutPlans.set(direction, entry);
|
|
6611
6624
|
return entry;
|
|
@@ -6720,20 +6733,43 @@ function createDiagram(opts) {
|
|
|
6720
6733
|
const vHeight = viewport.clientHeight || container.clientHeight || naturalHeight;
|
|
6721
6734
|
const resolvedFit = fitViewActive ? "contain" : fitMode === "auto" ? Math.abs(vHeight - naturalHeight) > 2 ? "contain" : "width" : fitMode;
|
|
6722
6735
|
const targetRatio = Math.min(1, Math.max(0.9, targetWidthRatio ?? 0.96));
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6736
|
+
const ADAPTABLE_DIAGRAM_TYPES = /* @__PURE__ */ new Set([
|
|
6737
|
+
"architecture",
|
|
6738
|
+
"flowchart",
|
|
6739
|
+
"state",
|
|
6740
|
+
"tree",
|
|
6741
|
+
"medallion",
|
|
6742
|
+
"swimlane",
|
|
6743
|
+
"timeline",
|
|
6744
|
+
"gantt",
|
|
6745
|
+
"layers",
|
|
6746
|
+
"loop",
|
|
6747
|
+
"nested",
|
|
6748
|
+
"flywheel",
|
|
6749
|
+
"pyramid"
|
|
6750
|
+
]);
|
|
6751
|
+
if (shouldAdaptOrientation && ADAPTABLE_DIAGRAM_TYPES.has(plan.diagramType)) {
|
|
6752
|
+
const detectedOrientation = detectContainerOrientation(activeOrientation);
|
|
6753
|
+
const isHeightConstrained = hasInitialHeightConstraint || vHeight > 0 && Math.abs(vHeight - naturalHeight) > 2;
|
|
6754
|
+
const containerRatio = vWidth / Math.max(1, vHeight);
|
|
6755
|
+
let currentOrientation = activeOrientation;
|
|
6756
|
+
if (!isHeightConstrained || !(activeOrientation === "landscape" && containerRatio >= 1)) {
|
|
6757
|
+
const score = (orientation) => {
|
|
6758
|
+
const { bounds: bounds2 } = layoutForDirection(directionForOrientation(orientation));
|
|
6759
|
+
const widthScale2 = vWidth * targetRatio / bounds2.width;
|
|
6760
|
+
const heightScale = isHeightConstrained ? Math.max(1, vHeight - 24) * targetRatio / bounds2.height : 1;
|
|
6761
|
+
return Math.min(1, widthScale2, heightScale);
|
|
6762
|
+
};
|
|
6763
|
+
if (activeOrientation === "landscape") {
|
|
6764
|
+
if (detectedOrientation === "portrait" || score("portrait") > score("landscape") * 1.2) {
|
|
6765
|
+
currentOrientation = "portrait";
|
|
6766
|
+
}
|
|
6767
|
+
} else {
|
|
6768
|
+
if (detectedOrientation === "landscape" && score("landscape") >= Math.min(0.85, score("portrait"))) {
|
|
6769
|
+
currentOrientation = "landscape";
|
|
6770
|
+
} else if (score("landscape") > score("portrait") * 1.2) {
|
|
6771
|
+
currentOrientation = "landscape";
|
|
6772
|
+
}
|
|
6737
6773
|
}
|
|
6738
6774
|
}
|
|
6739
6775
|
if (currentOrientation !== activeOrientation) {
|
|
@@ -6835,7 +6871,11 @@ function createDiagram(opts) {
|
|
|
6835
6871
|
let controlsTimeEl = null;
|
|
6836
6872
|
let controlsFitButton = null;
|
|
6837
6873
|
let closeCodePanel = null;
|
|
6838
|
-
|
|
6874
|
+
const explicitFit = defaultFit ?? explicitFitOption;
|
|
6875
|
+
let fitViewActive = explicitFit !== void 0 ? Boolean(explicitFit) : plan.meta.player?.controls?.fit !== void 0 ? Boolean(plan.meta.player.controls.fit) : opts.fitMode === "contain" || Boolean(fitViewButton);
|
|
6876
|
+
if (fitViewActive) {
|
|
6877
|
+
cameraLayer.style.setProperty("transform", "none", "important");
|
|
6878
|
+
}
|
|
6839
6879
|
const ICONS2 = {
|
|
6840
6880
|
play: '<svg class="markdy-icon" width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',
|
|
6841
6881
|
pause: '<svg class="markdy-icon" width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>',
|
|
@@ -7207,8 +7247,12 @@ function createDiagram(opts) {
|
|
|
7207
7247
|
resetView() {
|
|
7208
7248
|
resetViewportTransform();
|
|
7209
7249
|
},
|
|
7250
|
+
syncFullscreen(isFull) {
|
|
7251
|
+
syncFullscreenHandler?.(isFull);
|
|
7252
|
+
},
|
|
7210
7253
|
destroy() {
|
|
7211
7254
|
diagram.pause();
|
|
7255
|
+
syncFullscreenHandler = null;
|
|
7212
7256
|
hostThemeObserver?.disconnect();
|
|
7213
7257
|
hostThemeObserver = null;
|
|
7214
7258
|
if (colorSchemeQuery && mediaQueryListener) {
|
|
@@ -7612,7 +7656,7 @@ function createDiagram(opts) {
|
|
|
7612
7656
|
if (!fitViewButton) return;
|
|
7613
7657
|
controlsFitButton = makeControlButton("Fit", "Fit all items in view and ignore camera zoom", ICONS2.fit);
|
|
7614
7658
|
controlsFitButton.className = "markdy-control-fit";
|
|
7615
|
-
controlsFitButton.setAttribute("aria-pressed", "false");
|
|
7659
|
+
controlsFitButton.setAttribute("aria-pressed", fitViewActive ? "true" : "false");
|
|
7616
7660
|
controlsFitButton.addEventListener("click", toggleFitView);
|
|
7617
7661
|
toolbar.appendChild(controlsFitButton);
|
|
7618
7662
|
}
|
|
@@ -7624,6 +7668,7 @@ function createDiagram(opts) {
|
|
|
7624
7668
|
toolbar.appendChild(button);
|
|
7625
7669
|
}
|
|
7626
7670
|
let removeFullscreenListeners = null;
|
|
7671
|
+
let syncFullscreenHandler = null;
|
|
7627
7672
|
function mountFullscreenControl(toolbar) {
|
|
7628
7673
|
if (!fullscreenButton) return;
|
|
7629
7674
|
const button = makeControlButton("Full", "Toggle fullscreen view", ICONS2.fullscreen);
|
|
@@ -7641,8 +7686,8 @@ function createDiagram(opts) {
|
|
|
7641
7686
|
document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled
|
|
7642
7687
|
);
|
|
7643
7688
|
}
|
|
7644
|
-
function syncFullscreenState() {
|
|
7645
|
-
const isFull = isPseudoFull || document.fullscreenElement === host || document.fullscreenElement === viewport || document.webkitFullscreenElement === host || document.webkitFullscreenElement === viewport || document.mozFullScreenElement === host || document.msFullscreenElement === host;
|
|
7689
|
+
function syncFullscreenState(explicitFull) {
|
|
7690
|
+
const isFull = typeof explicitFull === "boolean" ? explicitFull : isPseudoFull || document.fullscreenElement === host || document.fullscreenElement === viewport || document.webkitFullscreenElement === host || document.webkitFullscreenElement === viewport || document.mozFullScreenElement === host || document.msFullscreenElement === host;
|
|
7646
7691
|
button.setAttribute("aria-pressed", isFull ? "true" : "false");
|
|
7647
7692
|
button.title = isFull ? "Exit fullscreen" : "Toggle fullscreen view";
|
|
7648
7693
|
button.innerHTML = isFull ? `${ICONS2.fullscreen}Exit` : `${ICONS2.fullscreen}Full`;
|
|
@@ -7674,9 +7719,14 @@ function createDiagram(opts) {
|
|
|
7674
7719
|
syncControls();
|
|
7675
7720
|
}, 120);
|
|
7676
7721
|
}
|
|
7722
|
+
syncFullscreenHandler = (isFull) => syncFullscreenState(isFull);
|
|
7677
7723
|
async function toggleFullscreen() {
|
|
7678
7724
|
try {
|
|
7679
|
-
const isCurrentlyFull = isPseudoFull || document.fullscreenElement === host || document.fullscreenElement === viewport || document.webkitFullscreenElement === host || document.webkitFullscreenElement === viewport || document.mozFullScreenElement === host || document.msFullscreenElement === host;
|
|
7725
|
+
const isCurrentlyFull = button.getAttribute("aria-pressed") === "true" || isPseudoFull || document.fullscreenElement === host || document.fullscreenElement === viewport || document.webkitFullscreenElement === host || document.webkitFullscreenElement === viewport || document.mozFullScreenElement === host || document.msFullscreenElement === host;
|
|
7726
|
+
if (onFullscreen) {
|
|
7727
|
+
onFullscreen(!isCurrentlyFull);
|
|
7728
|
+
return;
|
|
7729
|
+
}
|
|
7680
7730
|
if (!isCurrentlyFull) {
|
|
7681
7731
|
let enteredNative = false;
|
|
7682
7732
|
if (isNativeFullscreenSupported()) {
|
|
@@ -7744,6 +7794,7 @@ function createDiagram(opts) {
|
|
|
7744
7794
|
document.addEventListener("MSFullscreenChange", syncFullscreenState);
|
|
7745
7795
|
window.addEventListener("keydown", handleEscKey);
|
|
7746
7796
|
removeFullscreenListeners = () => {
|
|
7797
|
+
syncFullscreenHandler = null;
|
|
7747
7798
|
document.removeEventListener("fullscreenchange", syncFullscreenState);
|
|
7748
7799
|
document.removeEventListener("webkitfullscreenchange", syncFullscreenState);
|
|
7749
7800
|
document.removeEventListener("mozfullscreenchange", syncFullscreenState);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdy/renderer-dom",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Browser renderer for diagram-native animated MarkdyScript architecture diagrams, built on the Web Animations API.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"html2canvas": "^1.4.1",
|
|
49
|
-
"@markdy/core": "1.4.
|
|
49
|
+
"@markdy/core": "1.4.5"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"jsdom": "^29.1.1",
|
|
53
53
|
"tsup": "^8.5.1",
|
|
54
54
|
"typescript": "^5.9.3",
|
|
55
55
|
"vitest": "^4.1.7",
|
|
56
|
-
"@markdy/stdlib-systems": "1.4.
|
|
56
|
+
"@markdy/stdlib-systems": "1.4.5"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup",
|