@markdy/renderer-dom 1.2.0 → 1.3.1

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 CHANGED
@@ -1,10 +1,22 @@
1
1
  # @markdy/renderer-dom
2
2
 
3
- Web Animations API renderer for [MarkdyScript](../../docs/SYNTAX.md) scenes. Translates a parsed AST into DOM elements and drives the animation timeline.
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 position (text)
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
- // Playback control
72
- diagram.pause();
73
- diagram.seek(1.5); // jump to 1.5 seconds
74
- diagram.play();
75
- diagram.destroy(); // clean up DOM + cancel animations
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
- src/
125
- index.ts — Barrel exports (createDiagram)
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
- ### Adding a cue or edge kind
79
+ ## API Exports
141
80
 
142
- Cue and edge animations live in `edges.ts` (`buildCueAnimations`). Add the new
143
- keyword or operator to `@markdy/core`'s `registry.ts` so the parser accepts it,
144
- then handle it in the corresponding branch of `buildCueAnimations`.
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
- - **[Syntax Reference](../../docs/SYNTAX.md)** — complete DSL language spec
149
- - **[Architecture](../../docs/ARCHITECTURE.md)** — renderer internals and playback design
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](../../LICENSE)
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
- export { type AnimationRecordFrame, type ControllerOptions, type Diagram, type DiagramOptions, DiagramPresentationController, type GifDiagramExportOptions, type GifExportOptions, ICON_REGISTRY, type IconSpec, type PngExportOptions, type SvgExportOptions, type TimelineController, createDiagram, detectHostTheme, encodeGifSequence, exportDiagramAsGif, exportDiagramAsPng, exportDiagramAsVectorSvg, exportLiveSceneAsPureVectorSvg, iconKeyForNode, renderPureVectorSvg };
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 perpStep = halfH + 8;
299
- for (let k = 1; k <= 3; k++) {
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 * 6 },
304
- { x: mid.x, y: mid.y + stepPerp, penalty: 24 + k * 6 }
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 * 6 },
309
- { x: mid.x + stepPerp, y: mid.y, penalty: 24 + k * 6 }
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
- sY = clamp(sourceCenter.y + (lane > 0 ? lane % 2 === 1 ? 4 : -4 : 0), sourceRect.y1 + 10, sourceRect.y2 - 10);
508
- tY = clamp(targetCenter.y + (lane > 0 ? lane % 2 === 1 ? 4 : -4 : 0), targetRect.y1 + 10, targetRect.y2 - 10);
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 };
@@ -883,8 +887,8 @@ function computeEdgeLabelColor(edgeColor, isDark) {
883
887
  }
884
888
  function createEdgeRuntime(svg, from, to, kind, label, theme, sceneId, routeObstacles, labelObstacles, bounds, lane, existingPaths = []) {
885
889
  ensureDefs(svg, theme, sceneId);
886
- const color = theme.edges[kind];
887
- const style = EDGE_STYLES[kind];
890
+ const color = theme.edges[kind] ?? theme.edges.request ?? theme.accent;
891
+ const style = EDGE_STYLES[kind] ?? EDGE_STYLES.request;
888
892
  const isSelfLoop = from.id === to.id;
889
893
  const points = isSelfLoop ? dedupePoints(selfLoopPath(from, bounds)) : dedupePoints(routeEdgePoints(from, to, routeObstacles, bounds, lane));
890
894
  const d = toPathD(points, 14, existingPaths);
@@ -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
- anims.push(
1239
- el.animate(
1240
- [{ opacity: 0, transform: "translateY(10px) scale(0.98)" }, { opacity: 1, transform: "translateY(0) scale(1)" }],
1241
- { duration: durMs, delay, fill: "forwards", easing: "cubic-bezier(0.16, 1, 0.3, 1)" }
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: "both", 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,31 @@ 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
+ if (!shownNodeSet.has(seg.from)) {
1380
+ shownNodeSet.add(seg.from);
1381
+ const fromEl = nodeEls.get(seg.from);
1382
+ if (fromEl) {
1383
+ anims.push(
1384
+ fromEl.animate(
1385
+ [{ opacity: 0, transform: "translateY(8px) scale(0.98)" }, { opacity: 1, transform: "translateY(0) scale(1)" }],
1386
+ { duration: 320, delay: startMs, fill: "both", easing: "cubic-bezier(0.16, 1, 0.3, 1)" }
1387
+ )
1388
+ );
1389
+ }
1390
+ }
1391
+ if (!shownNodeSet.has(seg.to)) {
1392
+ shownNodeSet.add(seg.to);
1393
+ const toEl2 = nodeEls.get(seg.to);
1394
+ if (toEl2) {
1395
+ const arrivalDelay = startMs + Math.min(240, durMs * 0.65);
1396
+ anims.push(
1397
+ toEl2.animate(
1398
+ [{ opacity: 0, transform: "translateY(8px) scale(0.98)" }, { opacity: 1, transform: "translateY(0) scale(1)" }],
1399
+ { duration: 300, delay: arrivalDelay, fill: "both", easing: "cubic-bezier(0.16, 1, 0.3, 1)" }
1400
+ )
1401
+ );
1402
+ }
1403
+ }
1363
1404
  const toEl = nodeEls.get(seg.to);
1364
1405
  if (toEl) {
1365
1406
  anims.push(
@@ -1378,7 +1419,7 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
1378
1419
  for (const a of anims) a.pause();
1379
1420
  return anims;
1380
1421
  }
1381
- function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeRuntimes = /* @__PURE__ */ new Map(), sceneId = createEdgeSceneId(), diagramType = "architecture") {
1422
+ function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeRuntimes = /* @__PURE__ */ new Map(), sceneId = createEdgeSceneId(), diagramType = "architecture", cues = []) {
1382
1423
  const structural = edges.filter(
1383
1424
  (e) => e.structural && diagramType !== "sequence" && !(diagramType === "tree" && !e.label)
1384
1425
  );
@@ -1390,6 +1431,30 @@ function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeR
1390
1431
  const placedPaths = [];
1391
1432
  const laneByPair = /* @__PURE__ */ new Map();
1392
1433
  const svg = ensureEdgeLayer(scene);
1434
+ const anims = [];
1435
+ const nodeRevealTime = /* @__PURE__ */ new Map();
1436
+ for (const cue of cues) {
1437
+ const cueStartMs = cue.start * 1e3;
1438
+ const durMs = cue.duration * 1e3;
1439
+ if (cue.kind === "show") {
1440
+ cue.targets.forEach((id, idx) => {
1441
+ const stagger = typeof cue.params?.stagger === "number" ? cue.params.stagger * 1e3 * idx : 0;
1442
+ const reveal = cueStartMs + stagger;
1443
+ if (!nodeRevealTime.has(id) || reveal < nodeRevealTime.get(id)) {
1444
+ nodeRevealTime.set(id, reveal);
1445
+ }
1446
+ });
1447
+ } else if (cue.kind === "flow" && cue.segments?.[0] && diagramType !== "sequence") {
1448
+ const seg = cue.segments[0];
1449
+ if (!nodeRevealTime.has(seg.from) || cueStartMs < nodeRevealTime.get(seg.from)) {
1450
+ nodeRevealTime.set(seg.from, cueStartMs);
1451
+ }
1452
+ const arrival = cueStartMs + Math.min(240, durMs * 0.65);
1453
+ if (!nodeRevealTime.has(seg.to) || arrival < nodeRevealTime.get(seg.to)) {
1454
+ nodeRevealTime.set(seg.to, arrival);
1455
+ }
1456
+ }
1457
+ }
1393
1458
  for (const edge of structural) {
1394
1459
  const from = nodeById.get(edge.from);
1395
1460
  const to = nodeById.get(edge.to);
@@ -1413,10 +1478,23 @@ function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeR
1413
1478
  );
1414
1479
  placedPaths.push(runtime.points);
1415
1480
  if (runtime.labelRect) placedLabels.push(runtime.labelRect);
1416
- setEdgeVisible(runtime, true);
1417
1481
  edgeRuntimes.set(edge.id, runtime);
1482
+ const hasCues = cues.length > 0;
1483
+ const tFrom = nodeRevealTime.get(edge.from) ?? 0;
1484
+ const tTo = nodeRevealTime.get(edge.to) ?? 0;
1485
+ const revealDelay = Math.max(tFrom, tTo);
1486
+ if (hasCues) {
1487
+ anims.push(
1488
+ runtime.group.animate(
1489
+ [{ opacity: 0 }, { opacity: 1 }],
1490
+ { duration: 240, delay: revealDelay, fill: "both", easing: "cubic-bezier(0.16, 1, 0.3, 1)" }
1491
+ )
1492
+ );
1493
+ } else {
1494
+ setEdgeVisible(runtime, true);
1495
+ }
1418
1496
  }
1419
- return [];
1497
+ return anims;
1420
1498
  }
1421
1499
 
1422
1500
  // src/annotations.ts
@@ -2018,6 +2096,7 @@ function mountGroupBoundaries(layer, boundaries, theme) {
2018
2096
  }
2019
2097
 
2020
2098
  // src/nodes.ts
2099
+ import { resolveVectorSymbol } from "@markdy/core";
2021
2100
  var STYLE_ID3 = "markdy-diagram-node-styles";
2022
2101
  function ensureNodeStyles(doc) {
2023
2102
  if (doc.getElementById(STYLE_ID3)) return;
@@ -2695,6 +2774,7 @@ var ICON_REGISTRY = Object.freeze(ICONS);
2695
2774
  function iconKeyForNode(node) {
2696
2775
  const override = typeof node.props?.icon === "string" ? node.props.icon.toLowerCase() : void 0;
2697
2776
  if (override && ICONS[override]) return override;
2777
+ if (override && resolveVectorSymbol(override)) return override;
2698
2778
  if (node.kind === "api_gateway" || node.kind === "gateway" || node.kind === "load_balancer" || node.kind === "ingress") return "gateway";
2699
2779
  if (node.kind === "db" || node.kind === "database" || node.kind === "sql" || node.kind === "nosql" || node.kind === "warehouse") return "database";
2700
2780
  if (node.kind === "bucket" || node.kind === "object_store" || node.kind === "blob" || node.kind === "volume" || node.kind === "disk") return "storage";
@@ -2770,6 +2850,21 @@ function createNodeMediaEl(doc, node, assets) {
2770
2850
  wrap.appendChild(img);
2771
2851
  return wrap;
2772
2852
  }
2853
+ const symbolKey = typeof node.props?.icon === "string" ? node.props.icon : typeof node.props?.symbol === "string" ? node.props.symbol : void 0;
2854
+ const vectorSymbol = symbolKey ? resolveVectorSymbol(symbolKey) : null;
2855
+ if (vectorSymbol) {
2856
+ wrap.dataset.vectorSymbol = vectorSymbol.name;
2857
+ const svg = doc.createElementNS("http://www.w3.org/2000/svg", "svg");
2858
+ svg.setAttribute("viewBox", vectorSymbol.viewBox);
2859
+ svg.setAttribute("width", "26");
2860
+ svg.setAttribute("height", "26");
2861
+ if (vectorSymbol.brandColor) {
2862
+ svg.style.color = vectorSymbol.brandColor;
2863
+ }
2864
+ svg.innerHTML = vectorSymbol.svgPaths;
2865
+ wrap.appendChild(svg);
2866
+ return wrap;
2867
+ }
2773
2868
  appendGlyph(doc, wrap, ICONS[iconKeyForNode(node)] ?? ICONS.service);
2774
2869
  return wrap;
2775
2870
  }
@@ -4002,7 +4097,8 @@ function applyThemeToScene(scene, theme) {
4002
4097
  // src/export/svg-exporter.ts
4003
4098
  import {
4004
4099
  parseAndCompile,
4005
- resolveTheme
4100
+ resolveTheme,
4101
+ resolveVectorSymbol as resolveVectorSymbol2
4006
4102
  } from "@markdy/core";
4007
4103
  function copyRenderedStyles(source, clone) {
4008
4104
  if (typeof window === "undefined" || typeof window.getComputedStyle !== "function") return;
@@ -4389,6 +4485,7 @@ function renderPureVectorSvg(plan, options = {}) {
4389
4485
  <g class="markdy-edges-layer">
4390
4486
  `;
4391
4487
  const nodeMap = new Map(plan.nodes.map((n) => [n.id, n]));
4488
+ const laneByPair = /* @__PURE__ */ new Map();
4392
4489
  plan.edges.forEach((edge, index) => {
4393
4490
  const from = nodeMap.get(edge.from);
4394
4491
  const to = nodeMap.get(edge.to);
@@ -4399,7 +4496,8 @@ function renderPureVectorSvg(plan, options = {}) {
4399
4496
  const color = theme.edges?.[edge.kind] || accent;
4400
4497
  const style = EDGE_STYLES2[edge.kind] || EDGE_STYLES2.request;
4401
4498
  const isSelfLoop = from.id === to.id;
4402
- const points = isSelfLoop ? dedupePoints2(selfLoopPath(from, bounds)) : dedupePoints2(routeEdgePoints2(from, to, routeObstacles, bounds, index));
4499
+ const lane = nextEdgeLane(laneByPair, from, to);
4500
+ const points = isSelfLoop ? dedupePoints2(selfLoopPath(from, bounds)) : dedupePoints2(routeEdgePoints2(from, to, routeObstacles, bounds, lane));
4403
4501
  const d = toPathD(points, 14, existingPaths);
4404
4502
  existingPaths.push(points);
4405
4503
  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 +4519,7 @@ function renderPureVectorSvg(plan, options = {}) {
4421
4519
  const lineHeight = 13;
4422
4520
  const boxHeight = lines.length === 1 ? 18 : lines.length * lineHeight + 6;
4423
4521
  const placement = placeFlowLabel(points, textWidth, labelObstacles, bounds, boxHeight);
4522
+ labelObstacles.push(inflateRect(placement.rect, 4));
4424
4523
  const padX = 6;
4425
4524
  const halfW = textWidth / 2;
4426
4525
  const labelX = placement.x - halfW - padX;
@@ -4527,10 +4626,19 @@ function renderPureVectorSvg(plan, options = {}) {
4527
4626
  const circleIconSize = 20;
4528
4627
  const iconX = (node.width - circleIconSize) / 2;
4529
4628
  const iconY = node.height / 2 - 20;
4629
+ const circleSymbolKey = typeof node.props?.icon === "string" ? node.props.icon : typeof node.props?.symbol === "string" ? node.props.symbol : void 0;
4630
+ const circleVectorSymbol = circleSymbolKey ? resolveVectorSymbol2(circleSymbolKey) : null;
4530
4631
  const rawImage = node.props?.image ?? node.props?.logo;
4531
4632
  if (typeof rawImage === "string" && rawImage.length > 0) {
4532
4633
  svg += ` <!-- Centered Custom Image -->
4533
4634
  <image href="${escapeXml(rawImage)}" x="${iconX}" y="${iconY}" width="${circleIconSize}" height="${circleIconSize}" preserveAspectRatio="xMidYMid meet"/>
4635
+ `;
4636
+ } else if (circleVectorSymbol) {
4637
+ const symColor = circleVectorSymbol.brandColor || roleColor;
4638
+ svg += ` <!-- Centered Vector Symbol: ${escapeXml(circleVectorSymbol.name)} -->
4639
+ <g transform="translate(${iconX}, ${iconY}) scale(${circleIconSize / 24})" fill="currentColor" color="${symColor}">
4640
+ ${circleVectorSymbol.svgPaths}
4641
+ </g>
4534
4642
  `;
4535
4643
  } else {
4536
4644
  svg += ` <!-- Centered Icon Glyph -->
@@ -4560,10 +4668,19 @@ function renderPureVectorSvg(plan, options = {}) {
4560
4668
  } else {
4561
4669
  const iconX = 16;
4562
4670
  const iconY = (node.height - iconSize) / 2;
4671
+ const cardSymbolKey = typeof node.props?.icon === "string" ? node.props.icon : typeof node.props?.symbol === "string" ? node.props.symbol : void 0;
4672
+ const cardVectorSymbol = cardSymbolKey ? resolveVectorSymbol2(cardSymbolKey) : null;
4563
4673
  const rawImage = node.props?.image ?? node.props?.logo;
4564
4674
  if (typeof rawImage === "string" && rawImage.length > 0) {
4565
4675
  svg += ` <!-- Node Custom Image -->
4566
4676
  <image href="${escapeXml(rawImage)}" x="${iconX}" y="${iconY}" width="${iconSize}" height="${iconSize}" preserveAspectRatio="xMidYMid meet"/>
4677
+ `;
4678
+ } else if (cardVectorSymbol) {
4679
+ const symColor = cardVectorSymbol.brandColor || roleColor;
4680
+ svg += ` <!-- Native Vector Symbol: ${escapeXml(cardVectorSymbol.name)} -->
4681
+ <g transform="translate(${iconX}, ${iconY}) scale(${iconSize / 24})" fill="currentColor" color="${symColor}">
4682
+ ${cardVectorSymbol.svgPaths}
4683
+ </g>
4567
4684
  `;
4568
4685
  } else {
4569
4686
  svg += ` <!-- Frameless Icon Glyph -->
@@ -5932,7 +6049,8 @@ function createDiagram(opts) {
5932
6049
  { width: plan.meta.width, height: plan.meta.height },
5933
6050
  edgeRuntimes,
5934
6051
  edgeSceneId,
5935
- plan.diagramType
6052
+ plan.diagramType,
6053
+ plan.cues
5936
6054
  ),
5937
6055
  ...buildCueAnimations(plan.cues, nodeEls, plan.nodes, plan.theme, cameraLayer, titleEl, {
5938
6056
  width: plan.meta.width,
@@ -7036,16 +7154,392 @@ var DiagramPresentationController = class {
7036
7154
  }
7037
7155
  }
7038
7156
  };
7157
+
7158
+ // src/impact.ts
7159
+ function extractAllDiagramEdges(ast) {
7160
+ const result = [];
7161
+ const seen = /* @__PURE__ */ new Set();
7162
+ const add = (from, to, op, label) => {
7163
+ const key = `${from}->${to}`;
7164
+ if (!seen.has(key)) {
7165
+ seen.add(key);
7166
+ result.push({ from, to, op, label });
7167
+ }
7168
+ };
7169
+ for (const edge of ast.edges || []) {
7170
+ add(edge.from, edge.to, edge.kind, edge.label);
7171
+ }
7172
+ for (const beat of ast.beats || []) {
7173
+ for (const cue of beat.cues || []) {
7174
+ if (cue.kind === "flow") {
7175
+ for (const segment of cue.segments) {
7176
+ add(segment.from, segment.to, segment.op, segment.label);
7177
+ }
7178
+ } else if (cue.kind === "parallel") {
7179
+ for (const childCue of cue.cues) {
7180
+ if (childCue.kind === "flow") {
7181
+ for (const segment of childCue.segments) {
7182
+ add(segment.from, segment.to, segment.op, segment.label);
7183
+ }
7184
+ }
7185
+ }
7186
+ }
7187
+ }
7188
+ }
7189
+ return result;
7190
+ }
7191
+ function calculateBlastRadius(nodeId, ast, maxDepth = 10) {
7192
+ const upstreamNodeIds = /* @__PURE__ */ new Set();
7193
+ const downstreamNodeIds = /* @__PURE__ */ new Set();
7194
+ const connectedEdgeKeys = /* @__PURE__ */ new Set();
7195
+ const edges = extractAllDiagramEdges(ast);
7196
+ const forwardQueue = [{ id: nodeId, depth: 0 }];
7197
+ const visitedForward = /* @__PURE__ */ new Set([nodeId]);
7198
+ while (forwardQueue.length > 0) {
7199
+ const { id, depth } = forwardQueue.shift();
7200
+ if (depth >= maxDepth) continue;
7201
+ for (const edge of edges) {
7202
+ if (edge.from === id) {
7203
+ connectedEdgeKeys.add(`${edge.from}->${edge.to}`);
7204
+ if (!visitedForward.has(edge.to)) {
7205
+ visitedForward.add(edge.to);
7206
+ downstreamNodeIds.add(edge.to);
7207
+ forwardQueue.push({ id: edge.to, depth: depth + 1 });
7208
+ }
7209
+ }
7210
+ }
7211
+ }
7212
+ const backwardQueue = [{ id: nodeId, depth: 0 }];
7213
+ const visitedBackward = /* @__PURE__ */ new Set([nodeId]);
7214
+ while (backwardQueue.length > 0) {
7215
+ const { id, depth } = backwardQueue.shift();
7216
+ if (depth >= maxDepth) continue;
7217
+ for (const edge of edges) {
7218
+ if (edge.to === id) {
7219
+ connectedEdgeKeys.add(`${edge.from}->${edge.to}`);
7220
+ if (!visitedBackward.has(edge.from)) {
7221
+ visitedBackward.add(edge.from);
7222
+ upstreamNodeIds.add(edge.from);
7223
+ backwardQueue.push({ id: edge.from, depth: depth + 1 });
7224
+ }
7225
+ }
7226
+ }
7227
+ }
7228
+ const allImpactedNodeIds = /* @__PURE__ */ new Set([nodeId, ...upstreamNodeIds, ...downstreamNodeIds]);
7229
+ return {
7230
+ rootNodeId: nodeId,
7231
+ upstreamNodeIds,
7232
+ downstreamNodeIds,
7233
+ allImpactedNodeIds,
7234
+ connectedEdgeKeys
7235
+ };
7236
+ }
7237
+ function findShortestRoute(fromId, toId, ast) {
7238
+ if (fromId === toId) return [fromId];
7239
+ const edges = extractAllDiagramEdges(ast);
7240
+ const queue = [{ current: fromId, path: [fromId] }];
7241
+ const visited = /* @__PURE__ */ new Set([fromId]);
7242
+ while (queue.length > 0) {
7243
+ const { current, path } = queue.shift();
7244
+ for (const edge of edges) {
7245
+ if (edge.from === current) {
7246
+ if (edge.to === toId) {
7247
+ return [...path, toId];
7248
+ }
7249
+ if (!visited.has(edge.to)) {
7250
+ visited.add(edge.to);
7251
+ queue.push({ current: edge.to, path: [...path, edge.to] });
7252
+ }
7253
+ }
7254
+ }
7255
+ }
7256
+ return null;
7257
+ }
7258
+ function applyImpactHighlight(container, impact) {
7259
+ const nodeElements = container.querySelectorAll("[data-node-id]");
7260
+ nodeElements.forEach((el) => {
7261
+ const id = el.getAttribute("data-node-id");
7262
+ if (!id) return;
7263
+ if (id === impact.rootNodeId) {
7264
+ el.style.opacity = "1";
7265
+ el.style.filter = "drop-shadow(0 0 12px rgba(56, 189, 248, 0.8))";
7266
+ } else if (impact.upstreamNodeIds.has(id)) {
7267
+ el.style.opacity = "1";
7268
+ el.style.filter = "drop-shadow(0 0 8px rgba(167, 139, 250, 0.6))";
7269
+ } else if (impact.downstreamNodeIds.has(id)) {
7270
+ el.style.opacity = "1";
7271
+ el.style.filter = "drop-shadow(0 0 8px rgba(52, 211, 153, 0.6))";
7272
+ } else {
7273
+ el.style.opacity = "0.2";
7274
+ el.style.filter = "grayscale(80%)";
7275
+ }
7276
+ });
7277
+ const edgeElements = container.querySelectorAll("[data-edge-key]");
7278
+ edgeElements.forEach((el) => {
7279
+ const key = el.getAttribute("data-edge-key");
7280
+ if (!key) return;
7281
+ if (impact.connectedEdgeKeys.has(key)) {
7282
+ el.style.opacity = "1";
7283
+ el.style.stroke = "#38bdf8";
7284
+ } else {
7285
+ el.style.opacity = "0.15";
7286
+ }
7287
+ });
7288
+ }
7289
+ function clearImpactHighlight(container) {
7290
+ const nodeElements = container.querySelectorAll("[data-node-id]");
7291
+ nodeElements.forEach((el) => {
7292
+ el.style.opacity = "";
7293
+ el.style.filter = "";
7294
+ });
7295
+ const edgeElements = container.querySelectorAll("[data-edge-key]");
7296
+ edgeElements.forEach((el) => {
7297
+ el.style.opacity = "";
7298
+ el.style.stroke = "";
7299
+ });
7300
+ }
7301
+
7302
+ // src/export/share-card.ts
7303
+ var THEME_CARD_STYLES = {
7304
+ midnight: {
7305
+ bg: "#070d18",
7306
+ cardBg: "#0e1a2c",
7307
+ text: "#f4f7fb",
7308
+ muted: "#93a4bb",
7309
+ border: "#28384f",
7310
+ accent: "#38bdf8"
7311
+ },
7312
+ paper: {
7313
+ bg: "#f6f8fc",
7314
+ cardBg: "#ffffff",
7315
+ text: "#0f1c2e",
7316
+ muted: "#475569",
7317
+ border: "#cbd5e1",
7318
+ accent: "#0284c7"
7319
+ },
7320
+ blueprint: {
7321
+ bg: "#0a1a3a",
7322
+ cardBg: "#10214a",
7323
+ text: "#eaf1ff",
7324
+ muted: "#9fb6e0",
7325
+ border: "#2c477f",
7326
+ accent: "#5ba3ff"
7327
+ },
7328
+ graphite: {
7329
+ bg: "#111317",
7330
+ cardBg: "#191c22",
7331
+ text: "#eef1f5",
7332
+ muted: "#9aa3b1",
7333
+ border: "#343a45",
7334
+ accent: "#2dd4bf"
7335
+ },
7336
+ editorial: {
7337
+ bg: "#fafafa",
7338
+ cardBg: "#ffffff",
7339
+ text: "#0f172a",
7340
+ muted: "#475569",
7341
+ border: "#e2e8f0",
7342
+ accent: "#047857"
7343
+ },
7344
+ nebula: {
7345
+ bg: "#090b1a",
7346
+ cardBg: "#111735",
7347
+ text: "#eef2ff",
7348
+ muted: "#a5b4fc",
7349
+ border: "rgba(167, 139, 250, 0.28)",
7350
+ accent: "#c4b5fd"
7351
+ },
7352
+ terminal: {
7353
+ bg: "#0a0a0a",
7354
+ cardBg: "#141414",
7355
+ text: "#f5f5f5",
7356
+ muted: "#888888",
7357
+ border: "#2b2b2b",
7358
+ accent: "#4ade80"
7359
+ }
7360
+ };
7361
+ function escapeXml2(str) {
7362
+ return str.replace(/[<>&"']/g, (c) => {
7363
+ switch (c) {
7364
+ case "<":
7365
+ return "&lt;";
7366
+ case ">":
7367
+ return "&gt;";
7368
+ case "&":
7369
+ return "&amp;";
7370
+ case '"':
7371
+ return "&quot;";
7372
+ case "'":
7373
+ return "&apos;";
7374
+ default:
7375
+ return c;
7376
+ }
7377
+ });
7378
+ }
7379
+ function renderShareCardSvg(diagramSvgXml, options = {}) {
7380
+ const themeKey = options.theme || "midnight";
7381
+ const colors = THEME_CARD_STYLES[themeKey] || THEME_CARD_STYLES.midnight;
7382
+ const title = options.title || "Architecture System Map";
7383
+ const variant = options.variant || "standard";
7384
+ let badgeText = "MARKDY SYSTEM MAP";
7385
+ let badgeColor = colors.accent;
7386
+ let telemetryLine = "";
7387
+ if (variant === "route") {
7388
+ const routeOpt = options;
7389
+ badgeText = "ROUTE PATHFINDER";
7390
+ badgeColor = "#38bdf8";
7391
+ const hops = routeOpt.hops ?? 2;
7392
+ const protocol = routeOpt.protocol ? ` \u2022 ${escapeXml2(routeOpt.protocol)}` : "";
7393
+ telemetryLine = `Active Route: ${escapeXml2(routeOpt.from || "Origin")} \u2192 ${escapeXml2(routeOpt.to || "Destination")} \u2022 ${hops} hops${protocol}`;
7394
+ } else if (variant === "reach") {
7395
+ const reachOpt = options;
7396
+ badgeText = "BLAST RADIUS LENS";
7397
+ badgeColor = reachOpt.direction === "upstream" ? "#a78bfa" : "#22c55e";
7398
+ const dir = reachOpt.direction ? reachOpt.direction.toUpperCase() : "DOWNSTREAM";
7399
+ const count = reachOpt.impactedNodeCount ?? 3;
7400
+ const depth = reachOpt.maxDepth ?? 2;
7401
+ telemetryLine = `Root: ${escapeXml2(reachOpt.rootId || "Origin")} \u2022 Direction: ${dir} \u2022 ${count} Impacted Nodes \u2022 Depth: ${depth}`;
7402
+ }
7403
+ const vbMatch = diagramSvgXml.match(/viewBox="([^"]+)"/);
7404
+ let vbWidth = 1e3;
7405
+ let vbHeight = 500;
7406
+ if (vbMatch) {
7407
+ const parts = vbMatch[1].split(/\s+/).map(Number);
7408
+ if (parts.length === 4 && parts[2] > 0 && parts[3] > 0) {
7409
+ vbWidth = parts[2];
7410
+ vbHeight = parts[3];
7411
+ }
7412
+ }
7413
+ const canvasW = 1200;
7414
+ const canvasH = 630;
7415
+ const availW = 1120;
7416
+ const availH = 460;
7417
+ const scale = Math.min(availW / vbWidth, availH / vbHeight, 1.2);
7418
+ const targetW = vbWidth * scale;
7419
+ const targetH = vbHeight * scale;
7420
+ const targetX = (canvasW - targetW) / 2;
7421
+ const targetY = 110 + (availH - targetH) / 2;
7422
+ const cleanedInnerSvg = diagramSvgXml.replace(/^<\?xml[^>]*\?>/i, "").replace(/^<!DOCTYPE[^>]*>/i, "").trim();
7423
+ const innerContent = cleanedInnerSvg.replace(/^<svg[^>]*>/i, "").replace(/<\/svg>\s*$/i, "");
7424
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 630" width="1200" height="630">
7425
+ <defs>
7426
+ <style>
7427
+ .card-title { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 22px; font-weight: 700; fill: ${colors.text}; }
7428
+ .card-badge { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-weight: 700; letter-spacing: 0.14em; fill: ${badgeColor}; }
7429
+ .card-telemetry { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; font-weight: 500; fill: ${colors.muted}; }
7430
+ .card-footer { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; font-weight: 600; fill: ${colors.muted}; }
7431
+ </style>
7432
+ <pattern id="cardGrid" width="30" height="30" patternUnits="userSpaceOnUse">
7433
+ <path d="M 30 0 L 0 0 0 30" fill="none" stroke="${colors.border}" stroke-width="0.75" stroke-opacity="0.35"/>
7434
+ </pattern>
7435
+ <filter id="cardGlow" x="-20%" y="-20%" width="140%" height="140%">
7436
+ <feDropShadow dx="0" dy="16" stdDeviation="28" flood-color="#000000" flood-opacity="0.45"/>
7437
+ </filter>
7438
+ </defs>
7439
+
7440
+ <!-- Background Canvas -->
7441
+ <rect width="1200" height="630" fill="${colors.bg}"/>
7442
+ <rect width="1200" height="630" fill="url(#cardGrid)"/>
7443
+
7444
+ <!-- Main Card Container Panel -->
7445
+ <rect x="30" y="30" width="1140" height="570" rx="16" fill="${colors.cardBg}" stroke="${colors.border}" stroke-width="1.5" filter="url(#cardGlow)"/>
7446
+
7447
+ <!-- Card Header -->
7448
+ <g transform="translate(60, 72)">
7449
+ <!-- Badge Capsule -->
7450
+ <rect x="0" y="0" width="${badgeText.length * 8.5 + 24}" height="24" rx="12" fill="${colors.border}" fill-opacity="0.5"/>
7451
+ <text x="12" y="16" class="card-badge">${escapeXml2(badgeText)}</text>
7452
+
7453
+ <!-- Title -->
7454
+ <text x="${badgeText.length * 8.5 + 40}" y="18" class="card-title">${escapeXml2(title)}</text>
7455
+ </g>
7456
+
7457
+ <!-- Telemetry Bar (if present) -->
7458
+ ${telemetryLine ? `
7459
+ <g transform="translate(60, 110)">
7460
+ <text x="0" y="0" class="card-telemetry">${telemetryLine}</text>
7461
+ </g>` : ""}
7462
+
7463
+ <!-- Embedded Scaled Diagram -->
7464
+ <g transform="translate(${targetX}, ${targetY})">
7465
+ <svg width="${targetW}" height="${targetH}" viewBox="0 0 ${vbWidth} ${vbHeight}">
7466
+ ${innerContent}
7467
+ </svg>
7468
+ </g>
7469
+
7470
+ <!-- Card Footer -->
7471
+ <g transform="translate(60, 574)">
7472
+ <circle cx="6" cy="-4" r="4" fill="${colors.accent}"/>
7473
+ <text x="18" y="0" class="card-footer">markdy.com \u2022 Deterministic Vector Verification</text>
7474
+ </g>
7475
+ </svg>`;
7476
+ }
7477
+ async function exportDiagramAsShareCard(containerEl, options = {}) {
7478
+ const pixelRatio = options.pixelRatio || 2;
7479
+ const rawSvg = exportLiveSceneAsPureVectorSvg(containerEl, options);
7480
+ const cardSvg = renderShareCardSvg(rawSvg, options);
7481
+ const inlinedSvg = await inlineSerializedSvgResources(cardSvg);
7482
+ const blob = new Blob([inlinedSvg], { type: "image/svg+xml;charset=utf-8" });
7483
+ const url = URL.createObjectURL(blob);
7484
+ const img = new Image();
7485
+ await new Promise((resolve, reject) => {
7486
+ img.onload = () => resolve();
7487
+ img.onerror = () => {
7488
+ URL.revokeObjectURL(url);
7489
+ reject(new Error("Failed to load Share Card SVG for rasterization"));
7490
+ };
7491
+ img.src = url;
7492
+ });
7493
+ const canvas = document.createElement("canvas");
7494
+ canvas.width = 1200 * pixelRatio;
7495
+ canvas.height = 630 * pixelRatio;
7496
+ const ctx = canvas.getContext("2d");
7497
+ if (!ctx) {
7498
+ URL.revokeObjectURL(url);
7499
+ throw new Error("Could not get 2D canvas context for Share Card export");
7500
+ }
7501
+ ctx.scale(pixelRatio, pixelRatio);
7502
+ ctx.drawImage(img, 0, 0, 1200, 630);
7503
+ URL.revokeObjectURL(url);
7504
+ return new Promise((resolve, reject) => {
7505
+ canvas.toBlob((b) => {
7506
+ if (b) resolve(b);
7507
+ else reject(new Error("Canvas toBlob failed for Share Card PNG"));
7508
+ }, "image/png");
7509
+ });
7510
+ }
7511
+ async function exportRouteShareCard(containerEl, route, options = {}) {
7512
+ return exportDiagramAsShareCard(containerEl, {
7513
+ ...options,
7514
+ ...route,
7515
+ variant: "route"
7516
+ });
7517
+ }
7518
+ async function exportReachShareCard(containerEl, reach, options = {}) {
7519
+ return exportDiagramAsShareCard(containerEl, {
7520
+ ...options,
7521
+ ...reach,
7522
+ variant: "reach"
7523
+ });
7524
+ }
7039
7525
  export {
7040
7526
  DiagramPresentationController,
7041
7527
  ICON_REGISTRY,
7528
+ applyImpactHighlight,
7529
+ calculateBlastRadius,
7530
+ clearImpactHighlight,
7042
7531
  createDiagram,
7043
7532
  detectHostTheme,
7044
7533
  encodeGifSequence,
7045
7534
  exportDiagramAsGif,
7046
7535
  exportDiagramAsPng,
7536
+ exportDiagramAsShareCard,
7047
7537
  exportDiagramAsVectorSvg,
7048
7538
  exportLiveSceneAsPureVectorSvg,
7539
+ exportReachShareCard,
7540
+ exportRouteShareCard,
7541
+ findShortestRoute,
7049
7542
  iconKeyForNode,
7050
- renderPureVectorSvg
7543
+ renderPureVectorSvg,
7544
+ renderShareCardSvg
7051
7545
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/renderer-dom",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
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.2.0"
49
+ "@markdy/core": "1.3.1"
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.2.0"
56
+ "@markdy/stdlib-systems": "1.3.1"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",