@markdy/renderer-dom 1.2.0 → 1.3.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 +57 -109
- package/dist/index.d.ts +78 -2
- package/dist/index.js +464 -19
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
# @markdy/renderer-dom
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
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
|
+
<a href="https://markdy.com/docs/"><img src="https://img.shields.io/badge/📖_Docs-Documentation-10b981?style=for-the-badge" alt="Documentation" /></a>
|
|
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
|
+
</p>
|
|
8
|
+
|
|
9
|
+
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
|
+
> 🚀 **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/)**
|
|
4
13
|
|
|
5
14
|
## Features
|
|
6
15
|
|
|
7
16
|
- **Browser-native** — Web Animations API + CSS transforms, no Canvas or GSAP (~24 KB minzipped)
|
|
17
|
+
- **Blast Radius & Upstream Impact Lens** — compute and highlight transitive inward callers and outward impact chains dynamically
|
|
18
|
+
- **Route Pathfinder** — discover and animate the shortest topological communication route between any two services
|
|
19
|
+
- **Dynamic Port Multiplexing & Fillet Connectors** — renders balanced parallel connection lanes with smooth rounded corner paths
|
|
8
20
|
- **17 Diagram Layout Topologies** — `architecture`, `flowchart`, `tree`, `sequence`, `state`, `layers`, `nested`, `swimlane`, `timeline`, `gantt`, `medallion`, `flywheel`, `constellation`, `quadrant`, `pyramid`, `radar`, `venn`
|
|
9
21
|
- **Dynamic Theme Switching** — live runtime switching across 10 semantic themes (`paper`, `editorial`, `midnight`, `blueprint`, `graphite`, `nebula`, `terminal`, `sketchy`, `ink`, `doodle`)
|
|
10
22
|
- **Flow edges** — `->` request, `<-` response, `~>` event, `--` dependency, each with its own stroke, plus animated traveling pulse
|
|
@@ -21,133 +33,69 @@ Web Animations API renderer for [MarkdyScript](../../docs/SYNTAX.md) scenes. Tra
|
|
|
21
33
|
pnpm add @markdy/core @markdy/renderer-dom
|
|
22
34
|
```
|
|
23
35
|
|
|
24
|
-
## Package
|
|
36
|
+
## Package Position
|
|
25
37
|
|
|
26
38
|
```text
|
|
27
|
-
@markdy/core -> @markdy/renderer-dom -> browser scene playback
|
|
28
|
-
|
|
29
|
-
This package consumes parsed AST and drives DOM + Web Animations API timelines.
|
|
39
|
+
@markdy/core -> @markdy/renderer-dom -> browser scene playback & impact lens
|
|
30
40
|
```
|
|
31
41
|
|
|
32
|
-
## Output preview
|
|
33
|
-
|
|
34
|
-
<p align="center">
|
|
35
|
-
<a href="https://markdy.com/playground/">
|
|
36
|
-
<img src="https://raw.githubusercontent.com/HoangYell/markdy-com/main/website/public/images/scene-lakehouse-medallion.webp" alt="Markdy DOM Renderer Lakehouse Medallion Output" width="900" />
|
|
37
|
-
</a>
|
|
38
|
-
</p>
|
|
39
|
-
<p align="center">
|
|
40
|
-
<a href="https://markdy.com/playground/">
|
|
41
|
-
<img src="https://raw.githubusercontent.com/HoangYell/markdy-com/main/website/public/images/scene-nebula-constellation.webp" alt="Markdy DOM Renderer Nebula Constellation Output" width="900" />
|
|
42
|
-
</a>
|
|
43
|
-
</p>
|
|
44
|
-
|
|
45
42
|
## Usage
|
|
46
43
|
|
|
47
44
|
```typescript
|
|
48
|
-
import { createDiagram } from "@markdy/renderer-dom";
|
|
45
|
+
import { createDiagram, calculateBlastRadius, findShortestRoute } from "@markdy/renderer-dom";
|
|
46
|
+
import { parse } from "@markdy/core";
|
|
47
|
+
|
|
48
|
+
const code = `
|
|
49
|
+
scene "FinTech Checkout" theme=paper
|
|
50
|
+
layout LR
|
|
51
|
+
|
|
52
|
+
browser Client "Web Client"
|
|
53
|
+
gateway Gateway "API Gateway"
|
|
54
|
+
service PaymentSvc "Payment Service" @src="src/pay/index.ts#L10"
|
|
55
|
+
database LedgerDb "Ledger DB" icon=postgresql
|
|
56
|
+
|
|
57
|
+
beat checkout:
|
|
58
|
+
show $nodes stagger=60ms
|
|
59
|
+
Client -> Gateway "POST /checkout" -> PaymentSvc "Process" -> LedgerDb "Commit"
|
|
60
|
+
`;
|
|
49
61
|
|
|
50
62
|
const diagram = createDiagram({
|
|
51
63
|
container: document.getElementById("scene")!,
|
|
52
|
-
code
|
|
53
|
-
scene "Cache-Aside Architecture" theme=paper
|
|
54
|
-
layout LR
|
|
55
|
-
|
|
56
|
-
browser Client "Web Client"
|
|
57
|
-
gateway Gateway "API Gateway"
|
|
58
|
-
service Shortener "URL Service"
|
|
59
|
-
cache Redis "Redis Cluster"
|
|
60
|
-
|
|
61
|
-
beat hit:
|
|
62
|
-
show $nodes stagger=60ms
|
|
63
|
-
Client -> Gateway "GET /x9" -> Shortener "resolve"
|
|
64
|
-
Shortener -> Redis "GET slug:x9"
|
|
65
|
-
Shortener <- Redis "200 Target URL"
|
|
66
|
-
Client <- Gateway "301 Redirect"
|
|
67
|
-
`,
|
|
64
|
+
code,
|
|
68
65
|
autoplay: true,
|
|
69
66
|
});
|
|
70
67
|
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## API
|
|
79
|
-
|
|
80
|
-
### `createDiagram(options: DiagramOptions): Diagram`
|
|
81
|
-
|
|
82
|
-
| Option | Type | Default | Description |
|
|
83
|
-
|---|---|---|---|
|
|
84
|
-
| `container` | `HTMLElement` | *(required)* | DOM element to mount the scene into |
|
|
85
|
-
| `code` | `string` | *(required)* | MarkdyScript source code |
|
|
86
|
-
| `autoplay` | `boolean` | `player.playback.autoplay ?? true` | Override whether playback starts immediately |
|
|
87
|
-
| `loop` | `boolean` | `player.playback.loop ?? true` | Override whether playback loops at the end |
|
|
88
|
-
| `copyright` | `boolean` | `player.chrome.badge ?? true` | Show the linked badge at the footer's right edge |
|
|
89
|
-
| `progressBar` | `boolean \| string` | `true` | Deprecated compatibility flag for the scene-boundary progress bar |
|
|
90
|
-
| `sceneBoundaryProgress` | `boolean \| string` | `player.chrome.progress` | Override boundary progress, or pass a custom color/gradient |
|
|
91
|
-
| `progressColor` | `string` | `player.chrome.color` or rainbow | Override the progress color or gradient |
|
|
92
|
-
| `playbackRate` | `number` | `player.playback.rate ?? 1` | Override the initial timeline multiplier |
|
|
93
|
-
| `interactiveViewport` | `boolean` | `player.interaction` | `true` supplies default gestures; `false` suppresses script gestures |
|
|
94
|
-
| `controls` | `boolean` | `player.controls` | `true` supplies legacy toolbar defaults; `false` suppresses script controls |
|
|
95
|
-
| `shareUrl` | `string` | Markdy playground | Base URL used by the Share control when building `#code=` links |
|
|
96
|
-
| `onWarning` | `(warning: Diagnostic) => void` | `console.warn` | Called for each soft parse warning |
|
|
97
|
-
| `onTimeUpdate` | `(seconds: number, durationSeconds: number) => void` | — | Called whenever playback or seek changes the current time |
|
|
98
|
-
| `onPlayStateChange` | `(playing: boolean) => void` | — | Called when playback starts or pauses |
|
|
99
|
-
|
|
100
|
-
> **Note:** Prefer grouped `player:` configuration in MarkdyScript. Omitted host options preserve it; host `false` suppresses controls or interaction, while host `true` supplies legacy defaults for leaves the script does not set. A speed selector renders only with at least two distinct positive `speeds` values.
|
|
101
|
-
|
|
102
|
-
### `Diagram`
|
|
103
|
-
|
|
104
|
-
| Method | Description |
|
|
105
|
-
|---|---|
|
|
106
|
-
| `play()` | Start or resume playback |
|
|
107
|
-
| `pause()` | Pause at current position |
|
|
108
|
-
| `seek(seconds)` | Jump to a specific time |
|
|
109
|
-
| `setPlaybackRate(rate)` | Change timeline speed; ignores non-positive or non-finite values |
|
|
110
|
-
| `playbackRate()` | Current timeline speed multiplier |
|
|
111
|
-
| `currentTime()` | Current playback position in seconds |
|
|
112
|
-
| `duration()` | Total scene duration in seconds |
|
|
113
|
-
| `isPlaying()` | Whether the scene is currently playing |
|
|
114
|
-
| `setTheme(themeName)` | Switch theme dynamically at runtime across all 8 supported themes |
|
|
115
|
-
| `exportGif(options?)` | Render zero-dependency animated GIF89a with LZW compression |
|
|
116
|
-
| `exportSvg()` | Export Figma-compatible vector SVG snapshot of the current frame |
|
|
117
|
-
| `beats()` | Named `beat` ranges, in author order (empty if none) |
|
|
118
|
-
| `seekToBeat(name)` | Seek to the start of a named beat; no-op if the name doesn't match |
|
|
119
|
-
| `destroy()` | Remove DOM elements and cancel all animations |
|
|
120
|
-
|
|
121
|
-
## Module Structure
|
|
68
|
+
// Calculate Blast Radius
|
|
69
|
+
const ast = parse(code);
|
|
70
|
+
const impact = calculateBlastRadius("PaymentSvc", ast);
|
|
71
|
+
console.log("Upstream callers:", impact.upstreamNodeIds); // ['Gateway', 'Client']
|
|
72
|
+
console.log("Downstream blast:", impact.downstreamNodeIds); // ['LedgerDb']
|
|
122
73
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
diagram.ts — Public API, rAF loop, progress bar, responsive scaling
|
|
127
|
-
nodes.ts — Node element factory + scene title
|
|
128
|
-
edges.ts — Flow-edge SVG runtime, routing, and cue animations
|
|
129
|
-
sequence.ts — Participant lifelines, messages, and activation spans
|
|
130
|
-
tree.ts — Shared parent/child bus connectors
|
|
131
|
-
groups.ts — Group boundary zones
|
|
132
|
-
annotations.ts — Editorial callouts and leader lines
|
|
133
|
-
constellation.ts — Nebula halos, orbit rings, and deterministic stars
|
|
134
|
-
geometry/
|
|
135
|
-
rect.ts — Rects, points, and hit-testing (DOM-free, unit tested)
|
|
136
|
-
path.ts — Polyline measurement + obstacle-aware orthogonal routing
|
|
137
|
-
theme.ts — Scene ambience styles and theme-token application
|
|
74
|
+
// Shortest Route Pathfinder
|
|
75
|
+
const shortestPath = findShortestRoute("Client", "LedgerDb", ast);
|
|
76
|
+
console.log("Route:", shortestPath); // ['Client', 'Gateway', 'PaymentSvc', 'LedgerDb']
|
|
138
77
|
```
|
|
139
78
|
|
|
140
|
-
|
|
79
|
+
## API Exports
|
|
141
80
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
81
|
+
| Export | Type | Description |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| `createDiagram(options)` | `Function` | Mounts and drives an animated diagram in a DOM container |
|
|
84
|
+
| `calculateBlastRadius(nodeId, ast)` | `Function` | Computes upstream dependency callers and downstream blast radius |
|
|
85
|
+
| `findShortestRoute(fromId, toId, ast)` | `Function` | Finds the shortest topological message path between two nodes |
|
|
86
|
+
| `applyImpactHighlight(container, impact)` | `Function` | Highlights affected subgraph and dims non-impacted nodes |
|
|
87
|
+
| `clearImpactHighlight(container)` | `Function` | Resets all impact highlighting |
|
|
88
|
+
| `exportDiagramAsVectorSvg(container, opts?)` | `Function` | Export pure SVG vector snapshot of active scene frame |
|
|
89
|
+
| `exportDiagramAsPng(container, opts?)` | `Function` | Export high-DPI rasterized PNG Blob |
|
|
90
|
+
| `exportDiagramAsGif(diagram, opts?)` | `Function` | Export animated GIF89a recording |
|
|
145
91
|
|
|
146
|
-
## Documentation
|
|
92
|
+
## Ecosystem & Documentation
|
|
147
93
|
|
|
148
|
-
- **[
|
|
149
|
-
- **[
|
|
94
|
+
- ⚡ **[Interactive Studio / Playground](https://markdy.com/playground/)** — edit MarkdyScript with instant live preview in your browser
|
|
95
|
+
- 📖 **[Syntax Guide & Reference](https://markdy.com/docs/)** — complete language specification and keywords
|
|
96
|
+
- 🌟 **[Canonical Blueprints](https://markdy.com/examples/)** — production-grade distributed system and cloud architectures
|
|
97
|
+
- 📦 **[GitHub Repository](https://github.com/HoangYell/markdy-com)** — source code, benchmarks, and issue tracker
|
|
150
98
|
|
|
151
99
|
## License
|
|
152
100
|
|
|
153
|
-
[MIT](
|
|
101
|
+
[MIT](https://github.com/HoangYell/markdy-com/blob/main/LICENSE)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderPlan, BeatRange, ThemeTokens, PlayerControlsConfig, Diagnostic, PositionedNode } from '@markdy/core';
|
|
1
|
+
import { RenderPlan, BeatRange, ThemeTokens, PlayerControlsConfig, Diagnostic, PositionedNode, DiagramAST } from '@markdy/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* packages/renderer-dom/src/export/svg-exporter.ts
|
|
@@ -199,4 +199,80 @@ declare class DiagramPresentationController {
|
|
|
199
199
|
destroy(): void;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
/**
|
|
203
|
+
* packages/renderer-dom/src/impact.ts
|
|
204
|
+
* Upstream/Downstream Blast Radius & Route Pathfinder for Markdy.
|
|
205
|
+
* Clean-room re-engineered interactive topology analysis.
|
|
206
|
+
* Zero external dependencies.
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
interface BlastRadiusResult {
|
|
210
|
+
rootNodeId: string;
|
|
211
|
+
upstreamNodeIds: Set<string>;
|
|
212
|
+
downstreamNodeIds: Set<string>;
|
|
213
|
+
allImpactedNodeIds: Set<string>;
|
|
214
|
+
connectedEdgeKeys: Set<string>;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Traverses diagram topology to compute upstream (who depends on this)
|
|
218
|
+
* and downstream (who does this depend on) blast radius.
|
|
219
|
+
*/
|
|
220
|
+
declare function calculateBlastRadius(nodeId: string, ast: DiagramAST, maxDepth?: number): BlastRadiusResult;
|
|
221
|
+
/**
|
|
222
|
+
* Finds the shortest topological path between two nodes in the diagram.
|
|
223
|
+
*/
|
|
224
|
+
declare function findShortestRoute(fromId: string, toId: string, ast: DiagramAST): string[] | null;
|
|
225
|
+
/**
|
|
226
|
+
* Highlights impacted nodes and edges within a rendered diagram container.
|
|
227
|
+
*/
|
|
228
|
+
declare function applyImpactHighlight(container: HTMLElement, impact: BlastRadiusResult): void;
|
|
229
|
+
/**
|
|
230
|
+
* Clears any active impact highlighting on the diagram.
|
|
231
|
+
*/
|
|
232
|
+
declare function clearImpactHighlight(container: HTMLElement): void;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* packages/renderer-dom/src/export/share-card.ts
|
|
236
|
+
* High-Impact 1200x630 Contextual Share Card Export Pipeline for Markdy.
|
|
237
|
+
* Clean-room re-engineered OpenGraph & Presentation Share Card synthesis.
|
|
238
|
+
* Zero external dependencies.
|
|
239
|
+
*/
|
|
240
|
+
|
|
241
|
+
interface ShareCardOptions extends SvgExportOptions {
|
|
242
|
+
title?: string;
|
|
243
|
+
subtitle?: string;
|
|
244
|
+
variant?: "standard" | "route" | "reach";
|
|
245
|
+
theme?: "midnight" | "paper" | "blueprint" | "graphite" | "editorial" | "nebula" | "terminal";
|
|
246
|
+
pixelRatio?: number;
|
|
247
|
+
}
|
|
248
|
+
interface RouteCardOptions extends ShareCardOptions {
|
|
249
|
+
from: string;
|
|
250
|
+
to: string;
|
|
251
|
+
hops?: number;
|
|
252
|
+
protocol?: string;
|
|
253
|
+
}
|
|
254
|
+
interface ReachCardOptions extends ShareCardOptions {
|
|
255
|
+
rootId: string;
|
|
256
|
+
direction: "upstream" | "downstream" | "both";
|
|
257
|
+
impactedNodeCount?: number;
|
|
258
|
+
edgeCount?: number;
|
|
259
|
+
maxDepth?: number;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Wraps pure vector SVG within a high-density 1200x630 OpenGraph / Social Share Card.
|
|
263
|
+
*/
|
|
264
|
+
declare function renderShareCardSvg(diagramSvgXml: string, options?: ShareCardOptions): string;
|
|
265
|
+
/**
|
|
266
|
+
* Exports the live diagram container as a 1200x630 Share Card PNG Blob.
|
|
267
|
+
*/
|
|
268
|
+
declare function exportDiagramAsShareCard(containerEl: HTMLElement, options?: ShareCardOptions): Promise<Blob>;
|
|
269
|
+
/**
|
|
270
|
+
* Exports a focused message route as a 1200x630 Route Share Card PNG Blob.
|
|
271
|
+
*/
|
|
272
|
+
declare function exportRouteShareCard(containerEl: HTMLElement, route: RouteCardOptions, options?: ShareCardOptions): Promise<Blob>;
|
|
273
|
+
/**
|
|
274
|
+
* Exports an upstream or downstream blast radius subgraph as a 1200x630 Reach Share Card PNG Blob.
|
|
275
|
+
*/
|
|
276
|
+
declare function exportReachShareCard(containerEl: HTMLElement, reach: ReachCardOptions, options?: ShareCardOptions): Promise<Blob>;
|
|
277
|
+
|
|
278
|
+
export { type AnimationRecordFrame, type BlastRadiusResult, type ControllerOptions, type Diagram, type DiagramOptions, DiagramPresentationController, type GifDiagramExportOptions, type GifExportOptions, ICON_REGISTRY, type IconSpec, type PngExportOptions, type ReachCardOptions, type RouteCardOptions, type ShareCardOptions, type SvgExportOptions, type TimelineController, applyImpactHighlight, calculateBlastRadius, clearImpactHighlight, createDiagram, detectHostTheme, encodeGifSequence, exportDiagramAsGif, exportDiagramAsPng, exportDiagramAsShareCard, exportDiagramAsVectorSvg, exportLiveSceneAsPureVectorSvg, exportReachShareCard, exportRouteShareCard, findShortestRoute, iconKeyForNode, renderPureVectorSvg, renderShareCardSvg };
|
package/dist/index.js
CHANGED
|
@@ -295,21 +295,20 @@ function placeFlowLabel(points, textWidth, obstacles, bounds, boxHeight = LABEL_
|
|
|
295
295
|
);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
const stepPerp = k * perpStep;
|
|
298
|
+
const perpSteps = [halfH + 8, halfH + 22, halfH + 38, halfH + 56];
|
|
299
|
+
perpSteps.forEach((stepPerp, k) => {
|
|
301
300
|
if (horizontal) {
|
|
302
301
|
candidates.push(
|
|
303
|
-
{ x: mid.x, y: mid.y - stepPerp, penalty: 20 + k *
|
|
304
|
-
{ x: mid.x, y: mid.y + stepPerp, penalty: 24 + k *
|
|
302
|
+
{ x: mid.x, y: mid.y - stepPerp, penalty: 20 + k * 8 },
|
|
303
|
+
{ x: mid.x, y: mid.y + stepPerp, penalty: 24 + k * 8 }
|
|
305
304
|
);
|
|
306
305
|
} else {
|
|
307
306
|
candidates.push(
|
|
308
|
-
{ x: mid.x - stepPerp, y: mid.y, penalty: 20 + k *
|
|
309
|
-
{ x: mid.x + stepPerp, y: mid.y, penalty: 24 + k *
|
|
307
|
+
{ x: mid.x - stepPerp, y: mid.y, penalty: 20 + k * 8 },
|
|
308
|
+
{ x: mid.x + stepPerp, y: mid.y, penalty: 24 + k * 8 }
|
|
310
309
|
);
|
|
311
310
|
}
|
|
312
|
-
}
|
|
311
|
+
});
|
|
313
312
|
for (const cand of candidates) {
|
|
314
313
|
const cx = clamp(cand.x, pad + halfW, bounds.width - pad - halfW);
|
|
315
314
|
const cy = clamp(cand.y, pad + halfH, bounds.height - pad - halfH);
|
|
@@ -504,8 +503,9 @@ function routeOrthogonal(sourceRect, targetRect, obstacles, bounds, lane = 0) {
|
|
|
504
503
|
sY = clamp(sourceCenter.y + dirSign * 12, sourceRect.y1 + 10, sourceRect.y2 - 10);
|
|
505
504
|
tY = clamp(targetCenter.y - dirSign * 12, targetRect.y1 + 10, targetRect.y2 - 10);
|
|
506
505
|
} else {
|
|
507
|
-
|
|
508
|
-
|
|
506
|
+
const fwdShift = lane > 0 ? lane % 2 === 1 ? -10 : -18 : 0;
|
|
507
|
+
sY = clamp(sourceCenter.y + fwdShift, sourceRect.y1 + 10, sourceRect.y2 - 10);
|
|
508
|
+
tY = clamp(targetCenter.y + fwdShift, targetRect.y1 + 10, targetRect.y2 - 10);
|
|
509
509
|
}
|
|
510
510
|
const sPort = { x: sourceRect.x2, y: sY };
|
|
511
511
|
const tPort = { x: targetRect.x1, y: tY };
|
|
@@ -569,6 +569,10 @@ function routeOrthogonal(sourceRect, targetRect, obstacles, bounds, lane = 0) {
|
|
|
569
569
|
const dirSign = Math.sign(dy);
|
|
570
570
|
sY = clamp(sourceCenter.y + dirSign * 12, sourceRect.y1 + 10, sourceRect.y2 - 10);
|
|
571
571
|
tY = clamp(targetCenter.y - dirSign * 12, targetRect.y1 + 10, targetRect.y2 - 10);
|
|
572
|
+
} else {
|
|
573
|
+
const retShift = lane > 0 ? lane % 2 === 1 ? 10 : 18 : 10;
|
|
574
|
+
sY = clamp(sourceCenter.y + retShift, sourceRect.y1 + 10, sourceRect.y2 - 10);
|
|
575
|
+
tY = clamp(targetCenter.y + retShift, targetRect.y1 + 10, targetRect.y2 - 10);
|
|
572
576
|
}
|
|
573
577
|
const sPortL = { x: sourceRect.x1, y: sY };
|
|
574
578
|
const tPortR = { x: targetRect.x2, y: tY };
|
|
@@ -937,6 +941,7 @@ function createEdgeRuntime(svg, from, to, kind, label, theme, sceneId, routeObst
|
|
|
937
941
|
const boxHeight = lines.length === 1 ? 18 : lines.length * lineHeight + 6;
|
|
938
942
|
const placement = placeFlowLabel(points, textWidth, labelObstacles, bounds, boxHeight);
|
|
939
943
|
labelRect = placement.rect;
|
|
944
|
+
labelObstacles.push(inflateRect(labelRect, 4));
|
|
940
945
|
const plate = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
941
946
|
const padX = 6;
|
|
942
947
|
const halfW = textWidth / 2;
|
|
@@ -1227,6 +1232,7 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
|
|
|
1227
1232
|
{ duration: 420, delay: 0, fill: "forwards", easing: "ease-out" }
|
|
1228
1233
|
)
|
|
1229
1234
|
);
|
|
1235
|
+
const shownNodeSet = /* @__PURE__ */ new Set();
|
|
1230
1236
|
for (const cue of cues) {
|
|
1231
1237
|
const startMs = cue.start * 1e3;
|
|
1232
1238
|
const durMs = cue.duration * 1e3;
|
|
@@ -1235,12 +1241,22 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
|
|
|
1235
1241
|
const el = nodeEls.get(id);
|
|
1236
1242
|
const delay = startMs + (typeof cue.params.stagger === "number" ? cue.params.stagger * 1e3 * idx : 0);
|
|
1237
1243
|
if (el) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
+
if (!shownNodeSet.has(id)) {
|
|
1245
|
+
shownNodeSet.add(id);
|
|
1246
|
+
anims.push(
|
|
1247
|
+
el.animate(
|
|
1248
|
+
[{ opacity: 0, transform: "translateY(10px) scale(0.98)" }, { opacity: 1, transform: "translateY(0) scale(1)" }],
|
|
1249
|
+
{ duration: durMs, delay, fill: "forwards", easing: "cubic-bezier(0.16, 1, 0.3, 1)" }
|
|
1250
|
+
)
|
|
1251
|
+
);
|
|
1252
|
+
} else {
|
|
1253
|
+
anims.push(
|
|
1254
|
+
el.animate(
|
|
1255
|
+
[{ transform: "scale(1)" }, { transform: "scale(1.03)" }, { transform: "scale(1)" }],
|
|
1256
|
+
{ duration: durMs, delay, fill: "none", easing: "ease-in-out" }
|
|
1257
|
+
)
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1244
1260
|
return;
|
|
1245
1261
|
}
|
|
1246
1262
|
const runtime = edgeRuntimes.get(id);
|
|
@@ -1360,6 +1376,20 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
|
|
|
1360
1376
|
if (edgeId) edgeRuntimes.set(edgeId, runtime);
|
|
1361
1377
|
}
|
|
1362
1378
|
anims.push(...animateEdgeReveal(runtime, startMs, durMs));
|
|
1379
|
+
for (const id of [seg.from, seg.to]) {
|
|
1380
|
+
if (!shownNodeSet.has(id)) {
|
|
1381
|
+
shownNodeSet.add(id);
|
|
1382
|
+
const el = nodeEls.get(id);
|
|
1383
|
+
if (el) {
|
|
1384
|
+
anims.push(
|
|
1385
|
+
el.animate(
|
|
1386
|
+
[{ opacity: 0, transform: "translateY(8px) scale(0.98)" }, { opacity: 1, transform: "translateY(0) scale(1)" }],
|
|
1387
|
+
{ duration: 320, delay: startMs, fill: "forwards", easing: "cubic-bezier(0.16, 1, 0.3, 1)" }
|
|
1388
|
+
)
|
|
1389
|
+
);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1363
1393
|
const toEl = nodeEls.get(seg.to);
|
|
1364
1394
|
if (toEl) {
|
|
1365
1395
|
anims.push(
|
|
@@ -2018,6 +2048,7 @@ function mountGroupBoundaries(layer, boundaries, theme) {
|
|
|
2018
2048
|
}
|
|
2019
2049
|
|
|
2020
2050
|
// src/nodes.ts
|
|
2051
|
+
import { resolveVectorSymbol } from "@markdy/core";
|
|
2021
2052
|
var STYLE_ID3 = "markdy-diagram-node-styles";
|
|
2022
2053
|
function ensureNodeStyles(doc) {
|
|
2023
2054
|
if (doc.getElementById(STYLE_ID3)) return;
|
|
@@ -2695,6 +2726,7 @@ var ICON_REGISTRY = Object.freeze(ICONS);
|
|
|
2695
2726
|
function iconKeyForNode(node) {
|
|
2696
2727
|
const override = typeof node.props?.icon === "string" ? node.props.icon.toLowerCase() : void 0;
|
|
2697
2728
|
if (override && ICONS[override]) return override;
|
|
2729
|
+
if (override && resolveVectorSymbol(override)) return override;
|
|
2698
2730
|
if (node.kind === "api_gateway" || node.kind === "gateway" || node.kind === "load_balancer" || node.kind === "ingress") return "gateway";
|
|
2699
2731
|
if (node.kind === "db" || node.kind === "database" || node.kind === "sql" || node.kind === "nosql" || node.kind === "warehouse") return "database";
|
|
2700
2732
|
if (node.kind === "bucket" || node.kind === "object_store" || node.kind === "blob" || node.kind === "volume" || node.kind === "disk") return "storage";
|
|
@@ -2770,6 +2802,21 @@ function createNodeMediaEl(doc, node, assets) {
|
|
|
2770
2802
|
wrap.appendChild(img);
|
|
2771
2803
|
return wrap;
|
|
2772
2804
|
}
|
|
2805
|
+
const symbolKey = typeof node.props?.icon === "string" ? node.props.icon : typeof node.props?.symbol === "string" ? node.props.symbol : void 0;
|
|
2806
|
+
const vectorSymbol = symbolKey ? resolveVectorSymbol(symbolKey) : null;
|
|
2807
|
+
if (vectorSymbol) {
|
|
2808
|
+
wrap.dataset.vectorSymbol = vectorSymbol.name;
|
|
2809
|
+
const svg = doc.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
2810
|
+
svg.setAttribute("viewBox", vectorSymbol.viewBox);
|
|
2811
|
+
svg.setAttribute("width", "26");
|
|
2812
|
+
svg.setAttribute("height", "26");
|
|
2813
|
+
if (vectorSymbol.brandColor) {
|
|
2814
|
+
svg.style.color = vectorSymbol.brandColor;
|
|
2815
|
+
}
|
|
2816
|
+
svg.innerHTML = vectorSymbol.svgPaths;
|
|
2817
|
+
wrap.appendChild(svg);
|
|
2818
|
+
return wrap;
|
|
2819
|
+
}
|
|
2773
2820
|
appendGlyph(doc, wrap, ICONS[iconKeyForNode(node)] ?? ICONS.service);
|
|
2774
2821
|
return wrap;
|
|
2775
2822
|
}
|
|
@@ -4002,7 +4049,8 @@ function applyThemeToScene(scene, theme) {
|
|
|
4002
4049
|
// src/export/svg-exporter.ts
|
|
4003
4050
|
import {
|
|
4004
4051
|
parseAndCompile,
|
|
4005
|
-
resolveTheme
|
|
4052
|
+
resolveTheme,
|
|
4053
|
+
resolveVectorSymbol as resolveVectorSymbol2
|
|
4006
4054
|
} from "@markdy/core";
|
|
4007
4055
|
function copyRenderedStyles(source, clone) {
|
|
4008
4056
|
if (typeof window === "undefined" || typeof window.getComputedStyle !== "function") return;
|
|
@@ -4389,6 +4437,7 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4389
4437
|
<g class="markdy-edges-layer">
|
|
4390
4438
|
`;
|
|
4391
4439
|
const nodeMap = new Map(plan.nodes.map((n) => [n.id, n]));
|
|
4440
|
+
const laneByPair = /* @__PURE__ */ new Map();
|
|
4392
4441
|
plan.edges.forEach((edge, index) => {
|
|
4393
4442
|
const from = nodeMap.get(edge.from);
|
|
4394
4443
|
const to = nodeMap.get(edge.to);
|
|
@@ -4399,7 +4448,8 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4399
4448
|
const color = theme.edges?.[edge.kind] || accent;
|
|
4400
4449
|
const style = EDGE_STYLES2[edge.kind] || EDGE_STYLES2.request;
|
|
4401
4450
|
const isSelfLoop = from.id === to.id;
|
|
4402
|
-
const
|
|
4451
|
+
const lane = nextEdgeLane(laneByPair, from, to);
|
|
4452
|
+
const points = isSelfLoop ? dedupePoints2(selfLoopPath(from, bounds)) : dedupePoints2(routeEdgePoints2(from, to, routeObstacles, bounds, lane));
|
|
4403
4453
|
const d = toPathD(points, 14, existingPaths);
|
|
4404
4454
|
existingPaths.push(points);
|
|
4405
4455
|
const markerAttr = style.marker === "arrow" ? 'marker-end="url(#arrow-request)"' : style.marker === "arrow-open" ? 'marker-end="url(#arrow-response)"' : style.marker === "dot" ? 'marker-end="url(#arrow-event)"' : "";
|
|
@@ -4421,6 +4471,7 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4421
4471
|
const lineHeight = 13;
|
|
4422
4472
|
const boxHeight = lines.length === 1 ? 18 : lines.length * lineHeight + 6;
|
|
4423
4473
|
const placement = placeFlowLabel(points, textWidth, labelObstacles, bounds, boxHeight);
|
|
4474
|
+
labelObstacles.push(inflateRect(placement.rect, 4));
|
|
4424
4475
|
const padX = 6;
|
|
4425
4476
|
const halfW = textWidth / 2;
|
|
4426
4477
|
const labelX = placement.x - halfW - padX;
|
|
@@ -4527,10 +4578,19 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4527
4578
|
const circleIconSize = 20;
|
|
4528
4579
|
const iconX = (node.width - circleIconSize) / 2;
|
|
4529
4580
|
const iconY = node.height / 2 - 20;
|
|
4581
|
+
const circleSymbolKey = typeof node.props?.icon === "string" ? node.props.icon : typeof node.props?.symbol === "string" ? node.props.symbol : void 0;
|
|
4582
|
+
const circleVectorSymbol = circleSymbolKey ? resolveVectorSymbol2(circleSymbolKey) : null;
|
|
4530
4583
|
const rawImage = node.props?.image ?? node.props?.logo;
|
|
4531
4584
|
if (typeof rawImage === "string" && rawImage.length > 0) {
|
|
4532
4585
|
svg += ` <!-- Centered Custom Image -->
|
|
4533
4586
|
<image href="${escapeXml(rawImage)}" x="${iconX}" y="${iconY}" width="${circleIconSize}" height="${circleIconSize}" preserveAspectRatio="xMidYMid meet"/>
|
|
4587
|
+
`;
|
|
4588
|
+
} else if (circleVectorSymbol) {
|
|
4589
|
+
const symColor = circleVectorSymbol.brandColor || roleColor;
|
|
4590
|
+
svg += ` <!-- Centered Vector Symbol: ${escapeXml(circleVectorSymbol.name)} -->
|
|
4591
|
+
<g transform="translate(${iconX}, ${iconY}) scale(${circleIconSize / 24})" fill="currentColor" color="${symColor}">
|
|
4592
|
+
${circleVectorSymbol.svgPaths}
|
|
4593
|
+
</g>
|
|
4534
4594
|
`;
|
|
4535
4595
|
} else {
|
|
4536
4596
|
svg += ` <!-- Centered Icon Glyph -->
|
|
@@ -4560,10 +4620,19 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4560
4620
|
} else {
|
|
4561
4621
|
const iconX = 16;
|
|
4562
4622
|
const iconY = (node.height - iconSize) / 2;
|
|
4623
|
+
const cardSymbolKey = typeof node.props?.icon === "string" ? node.props.icon : typeof node.props?.symbol === "string" ? node.props.symbol : void 0;
|
|
4624
|
+
const cardVectorSymbol = cardSymbolKey ? resolveVectorSymbol2(cardSymbolKey) : null;
|
|
4563
4625
|
const rawImage = node.props?.image ?? node.props?.logo;
|
|
4564
4626
|
if (typeof rawImage === "string" && rawImage.length > 0) {
|
|
4565
4627
|
svg += ` <!-- Node Custom Image -->
|
|
4566
4628
|
<image href="${escapeXml(rawImage)}" x="${iconX}" y="${iconY}" width="${iconSize}" height="${iconSize}" preserveAspectRatio="xMidYMid meet"/>
|
|
4629
|
+
`;
|
|
4630
|
+
} else if (cardVectorSymbol) {
|
|
4631
|
+
const symColor = cardVectorSymbol.brandColor || roleColor;
|
|
4632
|
+
svg += ` <!-- Native Vector Symbol: ${escapeXml(cardVectorSymbol.name)} -->
|
|
4633
|
+
<g transform="translate(${iconX}, ${iconY}) scale(${iconSize / 24})" fill="currentColor" color="${symColor}">
|
|
4634
|
+
${cardVectorSymbol.svgPaths}
|
|
4635
|
+
</g>
|
|
4567
4636
|
`;
|
|
4568
4637
|
} else {
|
|
4569
4638
|
svg += ` <!-- Frameless Icon Glyph -->
|
|
@@ -7036,16 +7105,392 @@ var DiagramPresentationController = class {
|
|
|
7036
7105
|
}
|
|
7037
7106
|
}
|
|
7038
7107
|
};
|
|
7108
|
+
|
|
7109
|
+
// src/impact.ts
|
|
7110
|
+
function extractAllDiagramEdges(ast) {
|
|
7111
|
+
const result = [];
|
|
7112
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7113
|
+
const add = (from, to, op, label) => {
|
|
7114
|
+
const key = `${from}->${to}`;
|
|
7115
|
+
if (!seen.has(key)) {
|
|
7116
|
+
seen.add(key);
|
|
7117
|
+
result.push({ from, to, op, label });
|
|
7118
|
+
}
|
|
7119
|
+
};
|
|
7120
|
+
for (const edge of ast.edges || []) {
|
|
7121
|
+
add(edge.from, edge.to, edge.kind, edge.label);
|
|
7122
|
+
}
|
|
7123
|
+
for (const beat of ast.beats || []) {
|
|
7124
|
+
for (const cue of beat.cues || []) {
|
|
7125
|
+
if (cue.kind === "flow") {
|
|
7126
|
+
for (const segment of cue.segments) {
|
|
7127
|
+
add(segment.from, segment.to, segment.op, segment.label);
|
|
7128
|
+
}
|
|
7129
|
+
} else if (cue.kind === "parallel") {
|
|
7130
|
+
for (const childCue of cue.cues) {
|
|
7131
|
+
if (childCue.kind === "flow") {
|
|
7132
|
+
for (const segment of childCue.segments) {
|
|
7133
|
+
add(segment.from, segment.to, segment.op, segment.label);
|
|
7134
|
+
}
|
|
7135
|
+
}
|
|
7136
|
+
}
|
|
7137
|
+
}
|
|
7138
|
+
}
|
|
7139
|
+
}
|
|
7140
|
+
return result;
|
|
7141
|
+
}
|
|
7142
|
+
function calculateBlastRadius(nodeId, ast, maxDepth = 10) {
|
|
7143
|
+
const upstreamNodeIds = /* @__PURE__ */ new Set();
|
|
7144
|
+
const downstreamNodeIds = /* @__PURE__ */ new Set();
|
|
7145
|
+
const connectedEdgeKeys = /* @__PURE__ */ new Set();
|
|
7146
|
+
const edges = extractAllDiagramEdges(ast);
|
|
7147
|
+
const forwardQueue = [{ id: nodeId, depth: 0 }];
|
|
7148
|
+
const visitedForward = /* @__PURE__ */ new Set([nodeId]);
|
|
7149
|
+
while (forwardQueue.length > 0) {
|
|
7150
|
+
const { id, depth } = forwardQueue.shift();
|
|
7151
|
+
if (depth >= maxDepth) continue;
|
|
7152
|
+
for (const edge of edges) {
|
|
7153
|
+
if (edge.from === id) {
|
|
7154
|
+
connectedEdgeKeys.add(`${edge.from}->${edge.to}`);
|
|
7155
|
+
if (!visitedForward.has(edge.to)) {
|
|
7156
|
+
visitedForward.add(edge.to);
|
|
7157
|
+
downstreamNodeIds.add(edge.to);
|
|
7158
|
+
forwardQueue.push({ id: edge.to, depth: depth + 1 });
|
|
7159
|
+
}
|
|
7160
|
+
}
|
|
7161
|
+
}
|
|
7162
|
+
}
|
|
7163
|
+
const backwardQueue = [{ id: nodeId, depth: 0 }];
|
|
7164
|
+
const visitedBackward = /* @__PURE__ */ new Set([nodeId]);
|
|
7165
|
+
while (backwardQueue.length > 0) {
|
|
7166
|
+
const { id, depth } = backwardQueue.shift();
|
|
7167
|
+
if (depth >= maxDepth) continue;
|
|
7168
|
+
for (const edge of edges) {
|
|
7169
|
+
if (edge.to === id) {
|
|
7170
|
+
connectedEdgeKeys.add(`${edge.from}->${edge.to}`);
|
|
7171
|
+
if (!visitedBackward.has(edge.from)) {
|
|
7172
|
+
visitedBackward.add(edge.from);
|
|
7173
|
+
upstreamNodeIds.add(edge.from);
|
|
7174
|
+
backwardQueue.push({ id: edge.from, depth: depth + 1 });
|
|
7175
|
+
}
|
|
7176
|
+
}
|
|
7177
|
+
}
|
|
7178
|
+
}
|
|
7179
|
+
const allImpactedNodeIds = /* @__PURE__ */ new Set([nodeId, ...upstreamNodeIds, ...downstreamNodeIds]);
|
|
7180
|
+
return {
|
|
7181
|
+
rootNodeId: nodeId,
|
|
7182
|
+
upstreamNodeIds,
|
|
7183
|
+
downstreamNodeIds,
|
|
7184
|
+
allImpactedNodeIds,
|
|
7185
|
+
connectedEdgeKeys
|
|
7186
|
+
};
|
|
7187
|
+
}
|
|
7188
|
+
function findShortestRoute(fromId, toId, ast) {
|
|
7189
|
+
if (fromId === toId) return [fromId];
|
|
7190
|
+
const edges = extractAllDiagramEdges(ast);
|
|
7191
|
+
const queue = [{ current: fromId, path: [fromId] }];
|
|
7192
|
+
const visited = /* @__PURE__ */ new Set([fromId]);
|
|
7193
|
+
while (queue.length > 0) {
|
|
7194
|
+
const { current, path } = queue.shift();
|
|
7195
|
+
for (const edge of edges) {
|
|
7196
|
+
if (edge.from === current) {
|
|
7197
|
+
if (edge.to === toId) {
|
|
7198
|
+
return [...path, toId];
|
|
7199
|
+
}
|
|
7200
|
+
if (!visited.has(edge.to)) {
|
|
7201
|
+
visited.add(edge.to);
|
|
7202
|
+
queue.push({ current: edge.to, path: [...path, edge.to] });
|
|
7203
|
+
}
|
|
7204
|
+
}
|
|
7205
|
+
}
|
|
7206
|
+
}
|
|
7207
|
+
return null;
|
|
7208
|
+
}
|
|
7209
|
+
function applyImpactHighlight(container, impact) {
|
|
7210
|
+
const nodeElements = container.querySelectorAll("[data-node-id]");
|
|
7211
|
+
nodeElements.forEach((el) => {
|
|
7212
|
+
const id = el.getAttribute("data-node-id");
|
|
7213
|
+
if (!id) return;
|
|
7214
|
+
if (id === impact.rootNodeId) {
|
|
7215
|
+
el.style.opacity = "1";
|
|
7216
|
+
el.style.filter = "drop-shadow(0 0 12px rgba(56, 189, 248, 0.8))";
|
|
7217
|
+
} else if (impact.upstreamNodeIds.has(id)) {
|
|
7218
|
+
el.style.opacity = "1";
|
|
7219
|
+
el.style.filter = "drop-shadow(0 0 8px rgba(167, 139, 250, 0.6))";
|
|
7220
|
+
} else if (impact.downstreamNodeIds.has(id)) {
|
|
7221
|
+
el.style.opacity = "1";
|
|
7222
|
+
el.style.filter = "drop-shadow(0 0 8px rgba(52, 211, 153, 0.6))";
|
|
7223
|
+
} else {
|
|
7224
|
+
el.style.opacity = "0.2";
|
|
7225
|
+
el.style.filter = "grayscale(80%)";
|
|
7226
|
+
}
|
|
7227
|
+
});
|
|
7228
|
+
const edgeElements = container.querySelectorAll("[data-edge-key]");
|
|
7229
|
+
edgeElements.forEach((el) => {
|
|
7230
|
+
const key = el.getAttribute("data-edge-key");
|
|
7231
|
+
if (!key) return;
|
|
7232
|
+
if (impact.connectedEdgeKeys.has(key)) {
|
|
7233
|
+
el.style.opacity = "1";
|
|
7234
|
+
el.style.stroke = "#38bdf8";
|
|
7235
|
+
} else {
|
|
7236
|
+
el.style.opacity = "0.15";
|
|
7237
|
+
}
|
|
7238
|
+
});
|
|
7239
|
+
}
|
|
7240
|
+
function clearImpactHighlight(container) {
|
|
7241
|
+
const nodeElements = container.querySelectorAll("[data-node-id]");
|
|
7242
|
+
nodeElements.forEach((el) => {
|
|
7243
|
+
el.style.opacity = "";
|
|
7244
|
+
el.style.filter = "";
|
|
7245
|
+
});
|
|
7246
|
+
const edgeElements = container.querySelectorAll("[data-edge-key]");
|
|
7247
|
+
edgeElements.forEach((el) => {
|
|
7248
|
+
el.style.opacity = "";
|
|
7249
|
+
el.style.stroke = "";
|
|
7250
|
+
});
|
|
7251
|
+
}
|
|
7252
|
+
|
|
7253
|
+
// src/export/share-card.ts
|
|
7254
|
+
var THEME_CARD_STYLES = {
|
|
7255
|
+
midnight: {
|
|
7256
|
+
bg: "#070d18",
|
|
7257
|
+
cardBg: "#0e1a2c",
|
|
7258
|
+
text: "#f4f7fb",
|
|
7259
|
+
muted: "#93a4bb",
|
|
7260
|
+
border: "#28384f",
|
|
7261
|
+
accent: "#38bdf8"
|
|
7262
|
+
},
|
|
7263
|
+
paper: {
|
|
7264
|
+
bg: "#f6f8fc",
|
|
7265
|
+
cardBg: "#ffffff",
|
|
7266
|
+
text: "#0f1c2e",
|
|
7267
|
+
muted: "#475569",
|
|
7268
|
+
border: "#cbd5e1",
|
|
7269
|
+
accent: "#0284c7"
|
|
7270
|
+
},
|
|
7271
|
+
blueprint: {
|
|
7272
|
+
bg: "#0a1a3a",
|
|
7273
|
+
cardBg: "#10214a",
|
|
7274
|
+
text: "#eaf1ff",
|
|
7275
|
+
muted: "#9fb6e0",
|
|
7276
|
+
border: "#2c477f",
|
|
7277
|
+
accent: "#5ba3ff"
|
|
7278
|
+
},
|
|
7279
|
+
graphite: {
|
|
7280
|
+
bg: "#111317",
|
|
7281
|
+
cardBg: "#191c22",
|
|
7282
|
+
text: "#eef1f5",
|
|
7283
|
+
muted: "#9aa3b1",
|
|
7284
|
+
border: "#343a45",
|
|
7285
|
+
accent: "#2dd4bf"
|
|
7286
|
+
},
|
|
7287
|
+
editorial: {
|
|
7288
|
+
bg: "#fafafa",
|
|
7289
|
+
cardBg: "#ffffff",
|
|
7290
|
+
text: "#0f172a",
|
|
7291
|
+
muted: "#475569",
|
|
7292
|
+
border: "#e2e8f0",
|
|
7293
|
+
accent: "#047857"
|
|
7294
|
+
},
|
|
7295
|
+
nebula: {
|
|
7296
|
+
bg: "#090b1a",
|
|
7297
|
+
cardBg: "#111735",
|
|
7298
|
+
text: "#eef2ff",
|
|
7299
|
+
muted: "#a5b4fc",
|
|
7300
|
+
border: "rgba(167, 139, 250, 0.28)",
|
|
7301
|
+
accent: "#c4b5fd"
|
|
7302
|
+
},
|
|
7303
|
+
terminal: {
|
|
7304
|
+
bg: "#0a0a0a",
|
|
7305
|
+
cardBg: "#141414",
|
|
7306
|
+
text: "#f5f5f5",
|
|
7307
|
+
muted: "#888888",
|
|
7308
|
+
border: "#2b2b2b",
|
|
7309
|
+
accent: "#4ade80"
|
|
7310
|
+
}
|
|
7311
|
+
};
|
|
7312
|
+
function escapeXml2(str) {
|
|
7313
|
+
return str.replace(/[<>&"']/g, (c) => {
|
|
7314
|
+
switch (c) {
|
|
7315
|
+
case "<":
|
|
7316
|
+
return "<";
|
|
7317
|
+
case ">":
|
|
7318
|
+
return ">";
|
|
7319
|
+
case "&":
|
|
7320
|
+
return "&";
|
|
7321
|
+
case '"':
|
|
7322
|
+
return """;
|
|
7323
|
+
case "'":
|
|
7324
|
+
return "'";
|
|
7325
|
+
default:
|
|
7326
|
+
return c;
|
|
7327
|
+
}
|
|
7328
|
+
});
|
|
7329
|
+
}
|
|
7330
|
+
function renderShareCardSvg(diagramSvgXml, options = {}) {
|
|
7331
|
+
const themeKey = options.theme || "midnight";
|
|
7332
|
+
const colors = THEME_CARD_STYLES[themeKey] || THEME_CARD_STYLES.midnight;
|
|
7333
|
+
const title = options.title || "Architecture System Map";
|
|
7334
|
+
const variant = options.variant || "standard";
|
|
7335
|
+
let badgeText = "MARKDY SYSTEM MAP";
|
|
7336
|
+
let badgeColor = colors.accent;
|
|
7337
|
+
let telemetryLine = "";
|
|
7338
|
+
if (variant === "route") {
|
|
7339
|
+
const routeOpt = options;
|
|
7340
|
+
badgeText = "ROUTE PATHFINDER";
|
|
7341
|
+
badgeColor = "#38bdf8";
|
|
7342
|
+
const hops = routeOpt.hops ?? 2;
|
|
7343
|
+
const protocol = routeOpt.protocol ? ` \u2022 ${escapeXml2(routeOpt.protocol)}` : "";
|
|
7344
|
+
telemetryLine = `Active Route: ${escapeXml2(routeOpt.from || "Origin")} \u2192 ${escapeXml2(routeOpt.to || "Destination")} \u2022 ${hops} hops${protocol}`;
|
|
7345
|
+
} else if (variant === "reach") {
|
|
7346
|
+
const reachOpt = options;
|
|
7347
|
+
badgeText = "BLAST RADIUS LENS";
|
|
7348
|
+
badgeColor = reachOpt.direction === "upstream" ? "#a78bfa" : "#22c55e";
|
|
7349
|
+
const dir = reachOpt.direction ? reachOpt.direction.toUpperCase() : "DOWNSTREAM";
|
|
7350
|
+
const count = reachOpt.impactedNodeCount ?? 3;
|
|
7351
|
+
const depth = reachOpt.maxDepth ?? 2;
|
|
7352
|
+
telemetryLine = `Root: ${escapeXml2(reachOpt.rootId || "Origin")} \u2022 Direction: ${dir} \u2022 ${count} Impacted Nodes \u2022 Depth: ${depth}`;
|
|
7353
|
+
}
|
|
7354
|
+
const vbMatch = diagramSvgXml.match(/viewBox="([^"]+)"/);
|
|
7355
|
+
let vbWidth = 1e3;
|
|
7356
|
+
let vbHeight = 500;
|
|
7357
|
+
if (vbMatch) {
|
|
7358
|
+
const parts = vbMatch[1].split(/\s+/).map(Number);
|
|
7359
|
+
if (parts.length === 4 && parts[2] > 0 && parts[3] > 0) {
|
|
7360
|
+
vbWidth = parts[2];
|
|
7361
|
+
vbHeight = parts[3];
|
|
7362
|
+
}
|
|
7363
|
+
}
|
|
7364
|
+
const canvasW = 1200;
|
|
7365
|
+
const canvasH = 630;
|
|
7366
|
+
const availW = 1120;
|
|
7367
|
+
const availH = 460;
|
|
7368
|
+
const scale = Math.min(availW / vbWidth, availH / vbHeight, 1.2);
|
|
7369
|
+
const targetW = vbWidth * scale;
|
|
7370
|
+
const targetH = vbHeight * scale;
|
|
7371
|
+
const targetX = (canvasW - targetW) / 2;
|
|
7372
|
+
const targetY = 110 + (availH - targetH) / 2;
|
|
7373
|
+
const cleanedInnerSvg = diagramSvgXml.replace(/^<\?xml[^>]*\?>/i, "").replace(/^<!DOCTYPE[^>]*>/i, "").trim();
|
|
7374
|
+
const innerContent = cleanedInnerSvg.replace(/^<svg[^>]*>/i, "").replace(/<\/svg>\s*$/i, "");
|
|
7375
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 630" width="1200" height="630">
|
|
7376
|
+
<defs>
|
|
7377
|
+
<style>
|
|
7378
|
+
.card-title { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 22px; font-weight: 700; fill: ${colors.text}; }
|
|
7379
|
+
.card-badge { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-weight: 700; letter-spacing: 0.14em; fill: ${badgeColor}; }
|
|
7380
|
+
.card-telemetry { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; font-weight: 500; fill: ${colors.muted}; }
|
|
7381
|
+
.card-footer { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; font-weight: 600; fill: ${colors.muted}; }
|
|
7382
|
+
</style>
|
|
7383
|
+
<pattern id="cardGrid" width="30" height="30" patternUnits="userSpaceOnUse">
|
|
7384
|
+
<path d="M 30 0 L 0 0 0 30" fill="none" stroke="${colors.border}" stroke-width="0.75" stroke-opacity="0.35"/>
|
|
7385
|
+
</pattern>
|
|
7386
|
+
<filter id="cardGlow" x="-20%" y="-20%" width="140%" height="140%">
|
|
7387
|
+
<feDropShadow dx="0" dy="16" stdDeviation="28" flood-color="#000000" flood-opacity="0.45"/>
|
|
7388
|
+
</filter>
|
|
7389
|
+
</defs>
|
|
7390
|
+
|
|
7391
|
+
<!-- Background Canvas -->
|
|
7392
|
+
<rect width="1200" height="630" fill="${colors.bg}"/>
|
|
7393
|
+
<rect width="1200" height="630" fill="url(#cardGrid)"/>
|
|
7394
|
+
|
|
7395
|
+
<!-- Main Card Container Panel -->
|
|
7396
|
+
<rect x="30" y="30" width="1140" height="570" rx="16" fill="${colors.cardBg}" stroke="${colors.border}" stroke-width="1.5" filter="url(#cardGlow)"/>
|
|
7397
|
+
|
|
7398
|
+
<!-- Card Header -->
|
|
7399
|
+
<g transform="translate(60, 72)">
|
|
7400
|
+
<!-- Badge Capsule -->
|
|
7401
|
+
<rect x="0" y="0" width="${badgeText.length * 8.5 + 24}" height="24" rx="12" fill="${colors.border}" fill-opacity="0.5"/>
|
|
7402
|
+
<text x="12" y="16" class="card-badge">${escapeXml2(badgeText)}</text>
|
|
7403
|
+
|
|
7404
|
+
<!-- Title -->
|
|
7405
|
+
<text x="${badgeText.length * 8.5 + 40}" y="18" class="card-title">${escapeXml2(title)}</text>
|
|
7406
|
+
</g>
|
|
7407
|
+
|
|
7408
|
+
<!-- Telemetry Bar (if present) -->
|
|
7409
|
+
${telemetryLine ? `
|
|
7410
|
+
<g transform="translate(60, 110)">
|
|
7411
|
+
<text x="0" y="0" class="card-telemetry">${telemetryLine}</text>
|
|
7412
|
+
</g>` : ""}
|
|
7413
|
+
|
|
7414
|
+
<!-- Embedded Scaled Diagram -->
|
|
7415
|
+
<g transform="translate(${targetX}, ${targetY})">
|
|
7416
|
+
<svg width="${targetW}" height="${targetH}" viewBox="0 0 ${vbWidth} ${vbHeight}">
|
|
7417
|
+
${innerContent}
|
|
7418
|
+
</svg>
|
|
7419
|
+
</g>
|
|
7420
|
+
|
|
7421
|
+
<!-- Card Footer -->
|
|
7422
|
+
<g transform="translate(60, 574)">
|
|
7423
|
+
<circle cx="6" cy="-4" r="4" fill="${colors.accent}"/>
|
|
7424
|
+
<text x="18" y="0" class="card-footer">markdy.com \u2022 Deterministic Vector Verification</text>
|
|
7425
|
+
</g>
|
|
7426
|
+
</svg>`;
|
|
7427
|
+
}
|
|
7428
|
+
async function exportDiagramAsShareCard(containerEl, options = {}) {
|
|
7429
|
+
const pixelRatio = options.pixelRatio || 2;
|
|
7430
|
+
const rawSvg = exportLiveSceneAsPureVectorSvg(containerEl, options);
|
|
7431
|
+
const cardSvg = renderShareCardSvg(rawSvg, options);
|
|
7432
|
+
const inlinedSvg = await inlineSerializedSvgResources(cardSvg);
|
|
7433
|
+
const blob = new Blob([inlinedSvg], { type: "image/svg+xml;charset=utf-8" });
|
|
7434
|
+
const url = URL.createObjectURL(blob);
|
|
7435
|
+
const img = new Image();
|
|
7436
|
+
await new Promise((resolve, reject) => {
|
|
7437
|
+
img.onload = () => resolve();
|
|
7438
|
+
img.onerror = () => {
|
|
7439
|
+
URL.revokeObjectURL(url);
|
|
7440
|
+
reject(new Error("Failed to load Share Card SVG for rasterization"));
|
|
7441
|
+
};
|
|
7442
|
+
img.src = url;
|
|
7443
|
+
});
|
|
7444
|
+
const canvas = document.createElement("canvas");
|
|
7445
|
+
canvas.width = 1200 * pixelRatio;
|
|
7446
|
+
canvas.height = 630 * pixelRatio;
|
|
7447
|
+
const ctx = canvas.getContext("2d");
|
|
7448
|
+
if (!ctx) {
|
|
7449
|
+
URL.revokeObjectURL(url);
|
|
7450
|
+
throw new Error("Could not get 2D canvas context for Share Card export");
|
|
7451
|
+
}
|
|
7452
|
+
ctx.scale(pixelRatio, pixelRatio);
|
|
7453
|
+
ctx.drawImage(img, 0, 0, 1200, 630);
|
|
7454
|
+
URL.revokeObjectURL(url);
|
|
7455
|
+
return new Promise((resolve, reject) => {
|
|
7456
|
+
canvas.toBlob((b) => {
|
|
7457
|
+
if (b) resolve(b);
|
|
7458
|
+
else reject(new Error("Canvas toBlob failed for Share Card PNG"));
|
|
7459
|
+
}, "image/png");
|
|
7460
|
+
});
|
|
7461
|
+
}
|
|
7462
|
+
async function exportRouteShareCard(containerEl, route, options = {}) {
|
|
7463
|
+
return exportDiagramAsShareCard(containerEl, {
|
|
7464
|
+
...options,
|
|
7465
|
+
...route,
|
|
7466
|
+
variant: "route"
|
|
7467
|
+
});
|
|
7468
|
+
}
|
|
7469
|
+
async function exportReachShareCard(containerEl, reach, options = {}) {
|
|
7470
|
+
return exportDiagramAsShareCard(containerEl, {
|
|
7471
|
+
...options,
|
|
7472
|
+
...reach,
|
|
7473
|
+
variant: "reach"
|
|
7474
|
+
});
|
|
7475
|
+
}
|
|
7039
7476
|
export {
|
|
7040
7477
|
DiagramPresentationController,
|
|
7041
7478
|
ICON_REGISTRY,
|
|
7479
|
+
applyImpactHighlight,
|
|
7480
|
+
calculateBlastRadius,
|
|
7481
|
+
clearImpactHighlight,
|
|
7042
7482
|
createDiagram,
|
|
7043
7483
|
detectHostTheme,
|
|
7044
7484
|
encodeGifSequence,
|
|
7045
7485
|
exportDiagramAsGif,
|
|
7046
7486
|
exportDiagramAsPng,
|
|
7487
|
+
exportDiagramAsShareCard,
|
|
7047
7488
|
exportDiagramAsVectorSvg,
|
|
7048
7489
|
exportLiveSceneAsPureVectorSvg,
|
|
7490
|
+
exportReachShareCard,
|
|
7491
|
+
exportRouteShareCard,
|
|
7492
|
+
findShortestRoute,
|
|
7049
7493
|
iconKeyForNode,
|
|
7050
|
-
renderPureVectorSvg
|
|
7494
|
+
renderPureVectorSvg,
|
|
7495
|
+
renderShareCardSvg
|
|
7051
7496
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdy/renderer-dom",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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.
|
|
49
|
+
"@markdy/core": "1.3.0"
|
|
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.
|
|
56
|
+
"@markdy/stdlib-systems": "1.3.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup",
|