@markdy/renderer-dom 1.3.0 → 1.3.2
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/dist/index.d.ts +2 -0
- package/dist/index.js +372 -192
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -116,6 +116,8 @@ interface DiagramOptions {
|
|
|
116
116
|
playbackRate?: number;
|
|
117
117
|
/** Host interaction override. `true` enables default gestures; `false` suppresses script interaction. */
|
|
118
118
|
interactiveViewport?: boolean;
|
|
119
|
+
/** Host click-to-play override. `false` disables toggling playback on viewport click. */
|
|
120
|
+
clickToPlay?: boolean;
|
|
119
121
|
/** Base URL for the Share control. Defaults to the Markdy playground. */
|
|
120
122
|
shareUrl?: string;
|
|
121
123
|
/** Host controls override. `true` enables the legacy default set; `false` suppresses script controls; or pass a granular controls configuration object. */
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/diagram.ts
|
|
2
2
|
import {
|
|
3
3
|
compressMarkdyToUrlHash,
|
|
4
|
-
|
|
4
|
+
computeAdaptiveDimensions,
|
|
5
|
+
compilePlan,
|
|
6
|
+
parse,
|
|
5
7
|
resolvePlayer,
|
|
6
8
|
resolveTheme as resolveTheme2
|
|
7
9
|
} from "@markdy/core";
|
|
@@ -690,7 +692,7 @@ function circleBoundaryRoute(from, to) {
|
|
|
690
692
|
{ x: toCenter.x - ux * toRadius, y: toCenter.y - uy * toRadius }
|
|
691
693
|
]);
|
|
692
694
|
}
|
|
693
|
-
function snapPortToNodeShape(node, port, neighbor,
|
|
695
|
+
function snapPortToNodeShape(node, port, neighbor, _isSource) {
|
|
694
696
|
if (!node.shape || node.shape === "card" || node.shape === "rounded" || node.shape === "terminal" || node.shape === "container") {
|
|
695
697
|
return port;
|
|
696
698
|
}
|
|
@@ -698,45 +700,40 @@ function snapPortToNodeShape(node, port, neighbor, isSource) {
|
|
|
698
700
|
const cy = node.y + node.height / 2;
|
|
699
701
|
const hw = node.width / 2;
|
|
700
702
|
const hh = node.height / 2;
|
|
703
|
+
const facingRight = neighbor.x > port.x;
|
|
704
|
+
const facingDown = neighbor.y > port.y;
|
|
705
|
+
const isHoriz = Math.abs(port.y - neighbor.y) <= Math.abs(port.x - neighbor.x);
|
|
701
706
|
if (node.shape === "diamond") {
|
|
702
|
-
const isVert = Math.abs(port.x - neighbor.x) < 0.01;
|
|
703
|
-
const isHoriz = Math.abs(port.y - neighbor.y) < 0.01;
|
|
704
|
-
if (isVert) {
|
|
705
|
-
const goingDown = isSource ? neighbor.y > port.y : port.y > neighbor.y;
|
|
706
|
-
const boundaryY = goingDown ? cy + hh * (1 - Math.min(1, Math.abs(port.x - cx) / hw)) : cy - hh * (1 - Math.min(1, Math.abs(port.x - cx) / hw));
|
|
707
|
-
return { x: port.x, y: Math.round(boundaryY * 10) / 10 };
|
|
708
|
-
}
|
|
709
707
|
if (isHoriz) {
|
|
710
|
-
const
|
|
711
|
-
const boundaryX = goingRight ? cx + hw * (1 - Math.min(1, Math.abs(port.y - cy) / hh)) : cx - hw * (1 - Math.min(1, Math.abs(port.y - cy) / hh));
|
|
708
|
+
const boundaryX = facingRight ? cx + hw * (1 - Math.min(1, Math.abs(port.y - cy) / hh)) : cx - hw * (1 - Math.min(1, Math.abs(port.y - cy) / hh));
|
|
712
709
|
return { x: Math.round(boundaryX * 10) / 10, y: port.y };
|
|
710
|
+
} else {
|
|
711
|
+
const boundaryY = facingDown ? cy + hh * (1 - Math.min(1, Math.abs(port.x - cx) / hw)) : cy - hh * (1 - Math.min(1, Math.abs(port.x - cx) / hw));
|
|
712
|
+
return { x: port.x, y: Math.round(boundaryY * 10) / 10 };
|
|
713
713
|
}
|
|
714
714
|
}
|
|
715
715
|
if (node.shape === "circle") {
|
|
716
716
|
const r = Math.min(node.width, node.height) / 2;
|
|
717
|
-
const isVert = Math.abs(port.x - neighbor.x) < 0.01;
|
|
718
|
-
const isHoriz = Math.abs(port.y - neighbor.y) < 0.01;
|
|
719
|
-
if (isVert) {
|
|
720
|
-
const goingDown = isSource ? neighbor.y > port.y : port.y > neighbor.y;
|
|
721
|
-
return { x: cx, y: goingDown ? cy + r : cy - r };
|
|
722
|
-
}
|
|
723
717
|
if (isHoriz) {
|
|
724
|
-
const
|
|
725
|
-
|
|
718
|
+
const dy = Math.abs(port.y - cy);
|
|
719
|
+
const dx = dy <= r ? Math.sqrt(Math.max(0, r * r - dy * dy)) : 0;
|
|
720
|
+
return { x: Math.round((facingRight ? cx + dx : cx - dx) * 10) / 10, y: port.y };
|
|
721
|
+
} else {
|
|
722
|
+
const dx = Math.abs(port.x - cx);
|
|
723
|
+
const dy = dx <= r ? Math.sqrt(Math.max(0, r * r - dx * dx)) : 0;
|
|
724
|
+
return { x: port.x, y: Math.round((facingDown ? cy + dy : cy - dy) * 10) / 10 };
|
|
726
725
|
}
|
|
727
726
|
}
|
|
728
727
|
if (node.shape === "pill") {
|
|
729
728
|
const r = node.height / 2;
|
|
730
|
-
const isVert = Math.abs(port.x - neighbor.x) < 0.01;
|
|
731
|
-
const isHoriz = Math.abs(port.y - neighbor.y) < 0.01;
|
|
732
729
|
if (isHoriz) {
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
730
|
+
const dy = Math.abs(port.y - cy);
|
|
731
|
+
const dx = dy <= r ? Math.sqrt(Math.max(0, r * r - dy * dy)) : 0;
|
|
732
|
+
const boundaryX = facingRight ? node.x + node.width - r + dx : node.x + r - dx;
|
|
733
|
+
return { x: Math.round(boundaryX * 10) / 10, y: port.y };
|
|
734
|
+
} else {
|
|
738
735
|
const clampedX = Math.max(node.x + r, Math.min(node.x + node.width - r, port.x));
|
|
739
|
-
return { x: clampedX, y:
|
|
736
|
+
return { x: clampedX, y: facingDown ? node.y + node.height : node.y };
|
|
740
737
|
}
|
|
741
738
|
}
|
|
742
739
|
return port;
|
|
@@ -887,8 +884,8 @@ function computeEdgeLabelColor(edgeColor, isDark) {
|
|
|
887
884
|
}
|
|
888
885
|
function createEdgeRuntime(svg, from, to, kind, label, theme, sceneId, routeObstacles, labelObstacles, bounds, lane, existingPaths = []) {
|
|
889
886
|
ensureDefs(svg, theme, sceneId);
|
|
890
|
-
const color = theme.edges[kind];
|
|
891
|
-
const style = EDGE_STYLES[kind];
|
|
887
|
+
const color = theme.edges[kind] ?? theme.edges.request ?? theme.accent;
|
|
888
|
+
const style = EDGE_STYLES[kind] ?? EDGE_STYLES.request;
|
|
892
889
|
const isSelfLoop = from.id === to.id;
|
|
893
890
|
const points = isSelfLoop ? dedupePoints(selfLoopPath(from, bounds)) : dedupePoints(routeEdgePoints(from, to, routeObstacles, bounds, lane));
|
|
894
891
|
const d = toPathD(points, 14, existingPaths);
|
|
@@ -1167,9 +1164,6 @@ function computeFrameTransform(targetIds, nodes, bounds, requestedZoom = DEFAULT
|
|
|
1167
1164
|
const targets = new Set(targetIds);
|
|
1168
1165
|
const selected = nodes.filter((node) => targets.has(node.id));
|
|
1169
1166
|
if (selected.length === 0) return void 0;
|
|
1170
|
-
const framesEveryNode = selected.length === nodes.length && nodes.every((node) => targets.has(node.id));
|
|
1171
|
-
if (framesEveryNode) return INITIAL_CAMERA_TRANSFORM;
|
|
1172
|
-
const zoom = Number.isFinite(requestedZoom) && requestedZoom > 0 ? requestedZoom : DEFAULT_FRAME_ZOOM;
|
|
1173
1167
|
const minX = Math.min(...selected.map((node) => node.x));
|
|
1174
1168
|
const minY = Math.min(...selected.map((node) => node.y));
|
|
1175
1169
|
const maxX = Math.max(...selected.map((node) => node.x + node.width));
|
|
@@ -1177,6 +1171,19 @@ function computeFrameTransform(targetIds, nodes, bounds, requestedZoom = DEFAULT
|
|
|
1177
1171
|
const frameWidth = Math.max(1, maxX - minX + FRAME_PADDING * 2);
|
|
1178
1172
|
const frameHeight = Math.max(1, maxY - minY + FRAME_PADDING * 2);
|
|
1179
1173
|
const fitScale = Math.min(bounds.width / frameWidth, bounds.height / frameHeight);
|
|
1174
|
+
const framesEveryNode = selected.length === nodes.length && nodes.every((node) => targets.has(node.id));
|
|
1175
|
+
if (framesEveryNode) {
|
|
1176
|
+
if (fitScale >= 1 && minX >= 0 && maxX <= bounds.width && minY >= 0 && maxY <= bounds.height) {
|
|
1177
|
+
return INITIAL_CAMERA_TRANSFORM;
|
|
1178
|
+
}
|
|
1179
|
+
const scale2 = Math.min(1, Math.max(0.4, fitScale));
|
|
1180
|
+
const centerX2 = (minX + maxX) / 2;
|
|
1181
|
+
const centerY2 = (minY + maxY) / 2;
|
|
1182
|
+
const tx2 = Math.round((bounds.width / 2 - centerX2 * scale2) * 10) / 10;
|
|
1183
|
+
const ty2 = Math.round((bounds.height / 2 - centerY2 * scale2) * 10) / 10;
|
|
1184
|
+
return `translate(${tx2}px, ${ty2}px) scale(${Math.round(scale2 * 1e3) / 1e3})`;
|
|
1185
|
+
}
|
|
1186
|
+
const zoom = Number.isFinite(requestedZoom) && requestedZoom > 0 ? requestedZoom : DEFAULT_FRAME_ZOOM;
|
|
1180
1187
|
const scale = Math.max(1, Math.min(zoom, fitScale, MAX_FRAME_ZOOM));
|
|
1181
1188
|
const centerX = (minX + maxX) / 2;
|
|
1182
1189
|
const centerY = (minY + maxY) / 2;
|
|
@@ -1246,7 +1253,7 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
|
|
|
1246
1253
|
anims.push(
|
|
1247
1254
|
el.animate(
|
|
1248
1255
|
[{ opacity: 0, transform: "translateY(10px) scale(0.98)" }, { opacity: 1, transform: "translateY(0) scale(1)" }],
|
|
1249
|
-
{ duration: durMs, delay, fill: "
|
|
1256
|
+
{ duration: durMs, delay, fill: "both", easing: "cubic-bezier(0.16, 1, 0.3, 1)" }
|
|
1250
1257
|
)
|
|
1251
1258
|
);
|
|
1252
1259
|
} else {
|
|
@@ -1376,18 +1383,29 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
|
|
|
1376
1383
|
if (edgeId) edgeRuntimes.set(edgeId, runtime);
|
|
1377
1384
|
}
|
|
1378
1385
|
anims.push(...animateEdgeReveal(runtime, startMs, durMs));
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1386
|
+
if (!shownNodeSet.has(seg.from)) {
|
|
1387
|
+
shownNodeSet.add(seg.from);
|
|
1388
|
+
const fromEl = nodeEls.get(seg.from);
|
|
1389
|
+
if (fromEl) {
|
|
1390
|
+
anims.push(
|
|
1391
|
+
fromEl.animate(
|
|
1392
|
+
[{ opacity: 0, transform: "translateY(8px) scale(0.98)" }, { opacity: 1, transform: "translateY(0) scale(1)" }],
|
|
1393
|
+
{ duration: 320, delay: startMs, fill: "both", easing: "cubic-bezier(0.16, 1, 0.3, 1)" }
|
|
1394
|
+
)
|
|
1395
|
+
);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
if (!shownNodeSet.has(seg.to)) {
|
|
1399
|
+
shownNodeSet.add(seg.to);
|
|
1400
|
+
const toEl2 = nodeEls.get(seg.to);
|
|
1401
|
+
if (toEl2) {
|
|
1402
|
+
const arrivalDelay = startMs + Math.min(240, durMs * 0.65);
|
|
1403
|
+
anims.push(
|
|
1404
|
+
toEl2.animate(
|
|
1405
|
+
[{ opacity: 0, transform: "translateY(8px) scale(0.98)" }, { opacity: 1, transform: "translateY(0) scale(1)" }],
|
|
1406
|
+
{ duration: 300, delay: arrivalDelay, fill: "both", easing: "cubic-bezier(0.16, 1, 0.3, 1)" }
|
|
1407
|
+
)
|
|
1408
|
+
);
|
|
1391
1409
|
}
|
|
1392
1410
|
}
|
|
1393
1411
|
const toEl = nodeEls.get(seg.to);
|
|
@@ -1408,7 +1426,7 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
|
|
|
1408
1426
|
for (const a of anims) a.pause();
|
|
1409
1427
|
return anims;
|
|
1410
1428
|
}
|
|
1411
|
-
function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeRuntimes = /* @__PURE__ */ new Map(), sceneId = createEdgeSceneId(), diagramType = "architecture") {
|
|
1429
|
+
function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeRuntimes = /* @__PURE__ */ new Map(), sceneId = createEdgeSceneId(), diagramType = "architecture", cues = []) {
|
|
1412
1430
|
const structural = edges.filter(
|
|
1413
1431
|
(e) => e.structural && diagramType !== "sequence" && !(diagramType === "tree" && !e.label)
|
|
1414
1432
|
);
|
|
@@ -1420,6 +1438,30 @@ function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeR
|
|
|
1420
1438
|
const placedPaths = [];
|
|
1421
1439
|
const laneByPair = /* @__PURE__ */ new Map();
|
|
1422
1440
|
const svg = ensureEdgeLayer(scene);
|
|
1441
|
+
const anims = [];
|
|
1442
|
+
const nodeRevealTime = /* @__PURE__ */ new Map();
|
|
1443
|
+
for (const cue of cues) {
|
|
1444
|
+
const cueStartMs = cue.start * 1e3;
|
|
1445
|
+
const durMs = cue.duration * 1e3;
|
|
1446
|
+
if (cue.kind === "show") {
|
|
1447
|
+
cue.targets.forEach((id, idx) => {
|
|
1448
|
+
const stagger = typeof cue.params?.stagger === "number" ? cue.params.stagger * 1e3 * idx : 0;
|
|
1449
|
+
const reveal = cueStartMs + stagger;
|
|
1450
|
+
if (!nodeRevealTime.has(id) || reveal < nodeRevealTime.get(id)) {
|
|
1451
|
+
nodeRevealTime.set(id, reveal);
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
} else if (cue.kind === "flow" && cue.segments?.[0] && diagramType !== "sequence") {
|
|
1455
|
+
const seg = cue.segments[0];
|
|
1456
|
+
if (!nodeRevealTime.has(seg.from) || cueStartMs < nodeRevealTime.get(seg.from)) {
|
|
1457
|
+
nodeRevealTime.set(seg.from, cueStartMs);
|
|
1458
|
+
}
|
|
1459
|
+
const arrival = cueStartMs + Math.min(240, durMs * 0.65);
|
|
1460
|
+
if (!nodeRevealTime.has(seg.to) || arrival < nodeRevealTime.get(seg.to)) {
|
|
1461
|
+
nodeRevealTime.set(seg.to, arrival);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1423
1465
|
for (const edge of structural) {
|
|
1424
1466
|
const from = nodeById.get(edge.from);
|
|
1425
1467
|
const to = nodeById.get(edge.to);
|
|
@@ -1443,10 +1485,23 @@ function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeR
|
|
|
1443
1485
|
);
|
|
1444
1486
|
placedPaths.push(runtime.points);
|
|
1445
1487
|
if (runtime.labelRect) placedLabels.push(runtime.labelRect);
|
|
1446
|
-
setEdgeVisible(runtime, true);
|
|
1447
1488
|
edgeRuntimes.set(edge.id, runtime);
|
|
1489
|
+
const hasCues = cues.length > 0;
|
|
1490
|
+
const tFrom = nodeRevealTime.get(edge.from) ?? 0;
|
|
1491
|
+
const tTo = nodeRevealTime.get(edge.to) ?? 0;
|
|
1492
|
+
const revealDelay = Math.max(tFrom, tTo);
|
|
1493
|
+
if (hasCues) {
|
|
1494
|
+
anims.push(
|
|
1495
|
+
runtime.group.animate(
|
|
1496
|
+
[{ opacity: 0 }, { opacity: 1 }],
|
|
1497
|
+
{ duration: 240, delay: revealDelay, fill: "both", easing: "cubic-bezier(0.16, 1, 0.3, 1)" }
|
|
1498
|
+
)
|
|
1499
|
+
);
|
|
1500
|
+
} else {
|
|
1501
|
+
setEdgeVisible(runtime, true);
|
|
1502
|
+
}
|
|
1448
1503
|
}
|
|
1449
|
-
return
|
|
1504
|
+
return anims;
|
|
1450
1505
|
}
|
|
1451
1506
|
|
|
1452
1507
|
// src/annotations.ts
|
|
@@ -2074,7 +2129,7 @@ function ensureNodeStyles(doc) {
|
|
|
2074
2129
|
inset 0 0 0 1px var(--md-hairline, color-mix(in srgb, var(--md-border) 50%, transparent)),
|
|
2075
2130
|
inset 0 1px 0 rgba(255, 255, 255, 0.12);
|
|
2076
2131
|
font-family: var(--md-font-node, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif);
|
|
2077
|
-
overflow:
|
|
2132
|
+
overflow: visible;
|
|
2078
2133
|
opacity: 0;
|
|
2079
2134
|
transform: translateY(8px);
|
|
2080
2135
|
transition: box-shadow 0.25s ease, transform 0.25s ease;
|
|
@@ -2109,21 +2164,26 @@ function ensureNodeStyles(doc) {
|
|
|
2109
2164
|
box-sizing: border-box;
|
|
2110
2165
|
}
|
|
2111
2166
|
.markdy-node__icon {
|
|
2112
|
-
flex: 0 0
|
|
2167
|
+
flex: 0 0 28px;
|
|
2113
2168
|
width: 28px;
|
|
2114
2169
|
height: 28px;
|
|
2115
|
-
|
|
2170
|
+
border-radius: 7px;
|
|
2171
|
+
display: inline-flex;
|
|
2116
2172
|
align-items: center;
|
|
2117
2173
|
justify-content: center;
|
|
2174
|
+
background: color-mix(in srgb, var(--md-role-color, var(--md-accent)) 14%, transparent);
|
|
2118
2175
|
color: var(--md-role-color, var(--md-accent));
|
|
2119
|
-
|
|
2120
|
-
|
|
2176
|
+
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--md-role-color, var(--md-accent)) 35%, transparent);
|
|
2177
|
+
transition: transform 0.2s ease;
|
|
2121
2178
|
}
|
|
2122
2179
|
.markdy-node__icon svg {
|
|
2123
|
-
width:
|
|
2124
|
-
height:
|
|
2125
|
-
display: block;
|
|
2180
|
+
width: 18px;
|
|
2181
|
+
height: 18px;
|
|
2126
2182
|
stroke: currentColor;
|
|
2183
|
+
stroke-width: 1.8;
|
|
2184
|
+
fill: none;
|
|
2185
|
+
stroke-linecap: round;
|
|
2186
|
+
stroke-linejoin: round;
|
|
2127
2187
|
}
|
|
2128
2188
|
.markdy-node__icon[data-media="image"] {
|
|
2129
2189
|
background: transparent;
|
|
@@ -2158,14 +2218,10 @@ function ensureNodeStyles(doc) {
|
|
|
2158
2218
|
letter-spacing: -0.01em;
|
|
2159
2219
|
line-height: 1.24;
|
|
2160
2220
|
color: var(--md-text);
|
|
2161
|
-
display: -webkit-box;
|
|
2162
|
-
-webkit-box-orient: vertical;
|
|
2163
|
-
-webkit-line-clamp: 2;
|
|
2164
|
-
line-clamp: 2;
|
|
2165
|
-
overflow: hidden;
|
|
2166
2221
|
overflow-wrap: anywhere;
|
|
2167
2222
|
word-break: break-word;
|
|
2168
2223
|
text-wrap: pretty;
|
|
2224
|
+
white-space: pre-line;
|
|
2169
2225
|
}
|
|
2170
2226
|
.markdy-node__tech {
|
|
2171
2227
|
align-self: flex-start;
|
|
@@ -2180,9 +2236,8 @@ function ensureNodeStyles(doc) {
|
|
|
2180
2236
|
border-radius: 4px;
|
|
2181
2237
|
letter-spacing: 0.01em;
|
|
2182
2238
|
white-space: nowrap;
|
|
2183
|
-
overflow: hidden;
|
|
2184
|
-
text-overflow: ellipsis;
|
|
2185
2239
|
max-width: 100%;
|
|
2240
|
+
box-sizing: border-box;
|
|
2186
2241
|
}
|
|
2187
2242
|
.markdy-node__value {
|
|
2188
2243
|
flex: 0 0 auto;
|
|
@@ -2244,31 +2299,97 @@ function ensureNodeStyles(doc) {
|
|
|
2244
2299
|
.markdy-scene-root[data-markdy-theme="nebula"] .markdy-node[data-shape="diamond"][data-focal="1"] {
|
|
2245
2300
|
border: none;
|
|
2246
2301
|
box-shadow: none;
|
|
2302
|
+
background: transparent;
|
|
2247
2303
|
}
|
|
2248
2304
|
.markdy-node[data-shape="diamond"] {
|
|
2249
2305
|
border-radius: 0;
|
|
2250
2306
|
transform: rotate(0deg);
|
|
2251
|
-
clip-path:
|
|
2252
|
-
|
|
2307
|
+
clip-path: none;
|
|
2308
|
+
background: transparent;
|
|
2309
|
+
overflow: visible;
|
|
2253
2310
|
}
|
|
2254
|
-
.markdy-node[data-shape="diamond"]
|
|
2255
|
-
|
|
2311
|
+
.markdy-node[data-shape="diamond"] .markdy-node__shape-svg {
|
|
2312
|
+
position: absolute;
|
|
2313
|
+
inset: 0;
|
|
2314
|
+
width: 100%;
|
|
2315
|
+
height: 100%;
|
|
2316
|
+
pointer-events: none;
|
|
2317
|
+
overflow: visible;
|
|
2318
|
+
filter: drop-shadow(0 4px 16px var(--md-shadow, rgba(2, 6, 23, 0.28)));
|
|
2319
|
+
}
|
|
2320
|
+
.markdy-node[data-shape="diamond"] .markdy-node__diamond-polygon {
|
|
2321
|
+
fill: var(--md-node-surface, var(--md-surface));
|
|
2322
|
+
stroke: var(--md-hairline, rgba(255, 255, 255, 0.18));
|
|
2323
|
+
stroke-width: 1.5;
|
|
2324
|
+
stroke-linejoin: round;
|
|
2325
|
+
transition: stroke 0.2s ease, fill 0.2s ease, filter 0.2s ease;
|
|
2326
|
+
}
|
|
2327
|
+
.markdy-node[data-shape="diamond"] .markdy-node__diamond-facet {
|
|
2328
|
+
fill: none;
|
|
2329
|
+
stroke: rgba(255, 255, 255, 0.08);
|
|
2330
|
+
stroke-width: 1;
|
|
2331
|
+
stroke-linejoin: round;
|
|
2332
|
+
pointer-events: none;
|
|
2333
|
+
}
|
|
2334
|
+
.markdy-node[data-shape="diamond"][data-focal="1"] .markdy-node__diamond-polygon,
|
|
2335
|
+
.markdy-node[data-shape="diamond"][data-focused="1"] .markdy-node__diamond-polygon {
|
|
2336
|
+
stroke: var(--md-accent);
|
|
2337
|
+
stroke-width: 2;
|
|
2338
|
+
filter: drop-shadow(0 0 6px var(--md-accent));
|
|
2256
2339
|
}
|
|
2257
|
-
.markdy-node[data-shape="diamond"][data-
|
|
2258
|
-
|
|
2340
|
+
.markdy-node[data-shape="diamond"][data-glow="1"] .markdy-node__diamond-polygon {
|
|
2341
|
+
stroke: var(--md-glow-color, var(--md-accent));
|
|
2342
|
+
stroke-width: 2.2;
|
|
2343
|
+
filter: drop-shadow(0 0 10px var(--md-glow-color, var(--md-accent)));
|
|
2259
2344
|
}
|
|
2260
|
-
.markdy-node[data-shape="diamond"]
|
|
2261
|
-
|
|
2345
|
+
.markdy-node[data-shape="diamond"]:hover .markdy-node__diamond-polygon {
|
|
2346
|
+
stroke: var(--md-role-color, var(--md-accent));
|
|
2347
|
+
filter: drop-shadow(0 0 8px color-mix(in srgb, var(--md-role-color, var(--md-accent)) 60%, transparent));
|
|
2262
2348
|
}
|
|
2263
2349
|
.markdy-node[data-shape="diamond"] .markdy-node__body {
|
|
2350
|
+
flex-direction: column;
|
|
2351
|
+
align-items: center;
|
|
2264
2352
|
justify-content: center;
|
|
2265
|
-
padding:
|
|
2353
|
+
padding: 8px 14%;
|
|
2266
2354
|
text-align: center;
|
|
2355
|
+
gap: 3px;
|
|
2356
|
+
position: relative;
|
|
2357
|
+
z-index: 2;
|
|
2358
|
+
}
|
|
2359
|
+
.markdy-node[data-shape="diamond"] .markdy-node__icon {
|
|
2360
|
+
width: 20px;
|
|
2361
|
+
height: 20px;
|
|
2362
|
+
margin-bottom: 2px;
|
|
2363
|
+
display: flex;
|
|
2364
|
+
align-items: center;
|
|
2365
|
+
justify-content: center;
|
|
2366
|
+
color: var(--md-role-color, var(--md-accent));
|
|
2367
|
+
opacity: 0.95;
|
|
2368
|
+
filter: drop-shadow(0 0 4px color-mix(in srgb, var(--md-role-color, var(--md-accent)) 40%, transparent));
|
|
2369
|
+
}
|
|
2370
|
+
.markdy-node[data-shape="diamond"] .markdy-node__icon svg {
|
|
2371
|
+
width: 18px;
|
|
2372
|
+
height: 18px;
|
|
2373
|
+
}
|
|
2374
|
+
.markdy-node[data-shape="diamond"] .markdy-node__content {
|
|
2375
|
+
display: flex;
|
|
2376
|
+
flex-direction: column;
|
|
2377
|
+
align-items: center;
|
|
2378
|
+
justify-content: center;
|
|
2267
2379
|
}
|
|
2268
2380
|
.markdy-node[data-shape="diamond"] .markdy-node__label {
|
|
2269
2381
|
flex: 0 1 auto;
|
|
2270
|
-
|
|
2382
|
+
font-size: 12px;
|
|
2383
|
+
font-weight: 600;
|
|
2384
|
+
line-height: 1.25;
|
|
2271
2385
|
text-align: center;
|
|
2386
|
+
color: var(--md-text);
|
|
2387
|
+
}
|
|
2388
|
+
.markdy-node[data-shape="diamond"] .markdy-node__tech {
|
|
2389
|
+
align-self: center;
|
|
2390
|
+
font-size: 9px;
|
|
2391
|
+
padding: 1px 5px;
|
|
2392
|
+
margin-top: 2px;
|
|
2272
2393
|
}
|
|
2273
2394
|
.markdy-node[data-shape="pill"] {
|
|
2274
2395
|
border-radius: 999px;
|
|
@@ -2305,8 +2426,6 @@ function ensureNodeStyles(doc) {
|
|
|
2305
2426
|
}
|
|
2306
2427
|
.markdy-node[data-shape="circle"] .markdy-node__label {
|
|
2307
2428
|
text-align: center;
|
|
2308
|
-
-webkit-line-clamp: 4;
|
|
2309
|
-
line-clamp: 4;
|
|
2310
2429
|
}
|
|
2311
2430
|
.markdy-node[data-kind="dot"] {
|
|
2312
2431
|
width: 64px;
|
|
@@ -2861,9 +2980,26 @@ function createNodeEl(node, theme, assets) {
|
|
|
2861
2980
|
if (node.shape === "container") el.dataset.isContainer = "1";
|
|
2862
2981
|
el.title = `${node.label} (${typeText})`;
|
|
2863
2982
|
el.setAttribute("aria-label", el.title);
|
|
2983
|
+
if (node.shape === "diamond") {
|
|
2984
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
2985
|
+
svg.setAttribute("class", "markdy-node__shape-svg");
|
|
2986
|
+
svg.setAttribute("viewBox", `0 0 ${node.width} ${node.height}`);
|
|
2987
|
+
svg.setAttribute("aria-hidden", "true");
|
|
2988
|
+
const hw = node.width / 2;
|
|
2989
|
+
const hh = node.height / 2;
|
|
2990
|
+
const bg = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
2991
|
+
bg.setAttribute("points", `${hw},1.5 ${node.width - 1.5},${hh} ${hw},${node.height - 1.5} 1.5,${hh}`);
|
|
2992
|
+
bg.setAttribute("class", "markdy-node__diamond-polygon");
|
|
2993
|
+
svg.appendChild(bg);
|
|
2994
|
+
const facet = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
2995
|
+
facet.setAttribute("points", `${hw},4 ${node.width - 4},${hh} ${hw},${node.height - 4} 4,${hh}`);
|
|
2996
|
+
facet.setAttribute("class", "markdy-node__diamond-facet");
|
|
2997
|
+
svg.appendChild(facet);
|
|
2998
|
+
el.prepend(svg);
|
|
2999
|
+
}
|
|
2864
3000
|
const body = document.createElement("div");
|
|
2865
3001
|
body.className = "markdy-node__body";
|
|
2866
|
-
|
|
3002
|
+
body.append(createNodeMediaEl(document, node, assets));
|
|
2867
3003
|
const content = document.createElement("div");
|
|
2868
3004
|
content.className = "markdy-node__content";
|
|
2869
3005
|
const label = document.createElement("div");
|
|
@@ -4124,7 +4260,7 @@ function circleBoundaryRoute2(from, to) {
|
|
|
4124
4260
|
{ x: toCenter.x - ux * toRadius, y: toCenter.y - uy * toRadius }
|
|
4125
4261
|
]);
|
|
4126
4262
|
}
|
|
4127
|
-
function snapPortToNodeShape2(node, port, neighbor,
|
|
4263
|
+
function snapPortToNodeShape2(node, port, neighbor, _isSource) {
|
|
4128
4264
|
if (!node.shape || node.shape === "card" || node.shape === "rounded" || node.shape === "terminal" || node.shape === "container") {
|
|
4129
4265
|
return port;
|
|
4130
4266
|
}
|
|
@@ -4132,45 +4268,40 @@ function snapPortToNodeShape2(node, port, neighbor, isSource) {
|
|
|
4132
4268
|
const cy = node.y + node.height / 2;
|
|
4133
4269
|
const hw = node.width / 2;
|
|
4134
4270
|
const hh = node.height / 2;
|
|
4271
|
+
const facingRight = neighbor.x > port.x;
|
|
4272
|
+
const facingDown = neighbor.y > port.y;
|
|
4273
|
+
const isHoriz = Math.abs(port.y - neighbor.y) <= Math.abs(port.x - neighbor.x);
|
|
4135
4274
|
if (node.shape === "diamond") {
|
|
4136
|
-
const isVert = Math.abs(port.x - neighbor.x) < 0.01;
|
|
4137
|
-
const isHoriz = Math.abs(port.y - neighbor.y) < 0.01;
|
|
4138
|
-
if (isVert) {
|
|
4139
|
-
const goingDown = isSource ? neighbor.y > port.y : port.y > neighbor.y;
|
|
4140
|
-
const boundaryY = goingDown ? cy + hh * (1 - Math.min(1, Math.abs(port.x - cx) / hw)) : cy - hh * (1 - Math.min(1, Math.abs(port.x - cx) / hw));
|
|
4141
|
-
return { x: port.x, y: Math.round(boundaryY * 10) / 10 };
|
|
4142
|
-
}
|
|
4143
4275
|
if (isHoriz) {
|
|
4144
|
-
const
|
|
4145
|
-
const boundaryX = goingRight ? cx + hw * (1 - Math.min(1, Math.abs(port.y - cy) / hh)) : cx - hw * (1 - Math.min(1, Math.abs(port.y - cy) / hh));
|
|
4276
|
+
const boundaryX = facingRight ? cx + hw * (1 - Math.min(1, Math.abs(port.y - cy) / hh)) : cx - hw * (1 - Math.min(1, Math.abs(port.y - cy) / hh));
|
|
4146
4277
|
return { x: Math.round(boundaryX * 10) / 10, y: port.y };
|
|
4278
|
+
} else {
|
|
4279
|
+
const boundaryY = facingDown ? cy + hh * (1 - Math.min(1, Math.abs(port.x - cx) / hw)) : cy - hh * (1 - Math.min(1, Math.abs(port.x - cx) / hw));
|
|
4280
|
+
return { x: port.x, y: Math.round(boundaryY * 10) / 10 };
|
|
4147
4281
|
}
|
|
4148
4282
|
}
|
|
4149
4283
|
if (node.shape === "circle") {
|
|
4150
4284
|
const r = Math.min(node.width, node.height) / 2;
|
|
4151
|
-
const isVert = Math.abs(port.x - neighbor.x) < 0.01;
|
|
4152
|
-
const isHoriz = Math.abs(port.y - neighbor.y) < 0.01;
|
|
4153
|
-
if (isVert) {
|
|
4154
|
-
const goingDown = isSource ? neighbor.y > port.y : port.y > neighbor.y;
|
|
4155
|
-
return { x: cx, y: goingDown ? cy + r : cy - r };
|
|
4156
|
-
}
|
|
4157
4285
|
if (isHoriz) {
|
|
4158
|
-
const
|
|
4159
|
-
|
|
4286
|
+
const dy = Math.abs(port.y - cy);
|
|
4287
|
+
const dx = dy <= r ? Math.sqrt(Math.max(0, r * r - dy * dy)) : 0;
|
|
4288
|
+
return { x: Math.round((facingRight ? cx + dx : cx - dx) * 10) / 10, y: port.y };
|
|
4289
|
+
} else {
|
|
4290
|
+
const dx = Math.abs(port.x - cx);
|
|
4291
|
+
const dy = dx <= r ? Math.sqrt(Math.max(0, r * r - dx * dx)) : 0;
|
|
4292
|
+
return { x: port.x, y: Math.round((facingDown ? cy + dy : cy - dy) * 10) / 10 };
|
|
4160
4293
|
}
|
|
4161
4294
|
}
|
|
4162
4295
|
if (node.shape === "pill") {
|
|
4163
4296
|
const r = node.height / 2;
|
|
4164
|
-
const isVert = Math.abs(port.x - neighbor.x) < 0.01;
|
|
4165
|
-
const isHoriz = Math.abs(port.y - neighbor.y) < 0.01;
|
|
4166
4297
|
if (isHoriz) {
|
|
4167
|
-
const
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4298
|
+
const dy = Math.abs(port.y - cy);
|
|
4299
|
+
const dx = dy <= r ? Math.sqrt(Math.max(0, r * r - dy * dy)) : 0;
|
|
4300
|
+
const boundaryX = facingRight ? node.x + node.width - r + dx : node.x + r - dx;
|
|
4301
|
+
return { x: Math.round(boundaryX * 10) / 10, y: port.y };
|
|
4302
|
+
} else {
|
|
4172
4303
|
const clampedX = Math.max(node.x + r, Math.min(node.x + node.width - r, port.x));
|
|
4173
|
-
return { x: clampedX, y:
|
|
4304
|
+
return { x: clampedX, y: facingDown ? node.y + node.height : node.y };
|
|
4174
4305
|
}
|
|
4175
4306
|
}
|
|
4176
4307
|
return port;
|
|
@@ -4228,10 +4359,9 @@ function wrapNodeLabel(label, maxWidthPx, fontSize = 13.5) {
|
|
|
4228
4359
|
} else {
|
|
4229
4360
|
lines.push(current);
|
|
4230
4361
|
current = word;
|
|
4231
|
-
if (lines.length === 2) break;
|
|
4232
4362
|
}
|
|
4233
4363
|
}
|
|
4234
|
-
if (current
|
|
4364
|
+
if (current) {
|
|
4235
4365
|
lines.push(current);
|
|
4236
4366
|
}
|
|
4237
4367
|
return lines;
|
|
@@ -4517,7 +4647,8 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4517
4647
|
if (isDiamond) {
|
|
4518
4648
|
const hw = node.width / 2;
|
|
4519
4649
|
const hh = node.height / 2;
|
|
4520
|
-
svg += ` <polygon points="${hw},
|
|
4650
|
+
svg += ` <polygon points="${hw},1.5 ${node.width - 1.5},${hh} ${hw},${node.height - 1.5} 1.5,${hh}" fill="${surface}" stroke="${border}" stroke-width="1.5" stroke-linejoin="round" filter="url(#markdy-node-shadow)"/>
|
|
4651
|
+
<polygon points="${hw},3.5 ${node.width - 3.5},${hh} ${hw},${node.height - 3.5} 3.5,${hh}" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="1" stroke-linejoin="round"/>
|
|
4521
4652
|
`;
|
|
4522
4653
|
} else if (isCircle) {
|
|
4523
4654
|
const r = Math.min(node.width, node.height) / 2;
|
|
@@ -4539,37 +4670,54 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4539
4670
|
const valWidth = valText ? valText.length * 9.5 + 16 : 0;
|
|
4540
4671
|
const iconSize = 26;
|
|
4541
4672
|
if (isDiamond) {
|
|
4542
|
-
const availTextWidth = Math.max(40, node.width * 0.65);
|
|
4543
|
-
const lines = wrapNodeLabel(node.label, availTextWidth, 12.5);
|
|
4544
4673
|
const centerX = node.width / 2;
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4674
|
+
const availTextWidth = Math.max(40, node.width * 0.62);
|
|
4675
|
+
const lines = wrapNodeLabel(node.label, availTextWidth, 12);
|
|
4676
|
+
const diamondIconSize = 18;
|
|
4677
|
+
const iconX = (node.width - diamondIconSize) / 2;
|
|
4678
|
+
const iconY = node.height / 2 - (hasTech ? 26 : lines.length > 1 ? 22 : 18);
|
|
4679
|
+
const symbolKey = typeof node.props?.icon === "string" ? node.props.icon : typeof node.props?.symbol === "string" ? node.props.symbol : void 0;
|
|
4680
|
+
const vectorSymbol = symbolKey ? resolveVectorSymbol2(symbolKey) : null;
|
|
4681
|
+
const rawImage = node.props?.image ?? node.props?.logo;
|
|
4682
|
+
if (typeof rawImage === "string" && rawImage.length > 0) {
|
|
4683
|
+
svg += ` <image href="${escapeXml(rawImage)}" x="${iconX}" y="${iconY}" width="${diamondIconSize}" height="${diamondIconSize}" preserveAspectRatio="xMidYMid meet"/>
|
|
4549
4684
|
`;
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4685
|
+
} else if (vectorSymbol) {
|
|
4686
|
+
const symColor = vectorSymbol.brandColor || roleColor;
|
|
4687
|
+
svg += ` <g transform="translate(${iconX}, ${iconY}) scale(${diamondIconSize / 24})" fill="currentColor" color="${symColor}">
|
|
4688
|
+
${vectorSymbol.svgPaths}
|
|
4689
|
+
</g>
|
|
4554
4690
|
`;
|
|
4555
|
-
|
|
4691
|
+
} else {
|
|
4692
|
+
svg += ` <g transform="translate(${iconX}, ${iconY}) scale(${diamondIconSize / 24})" fill="none" stroke="${roleColor}" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round">
|
|
4693
|
+
`;
|
|
4694
|
+
if (glyphSpec) {
|
|
4695
|
+
for (const [tag, attrs] of glyphSpec) {
|
|
4696
|
+
const attrStr = Object.entries(attrs).map(([k, v]) => `${k}="${escapeXml(v)}"`).join(" ");
|
|
4697
|
+
svg += ` <${tag} ${attrStr} />
|
|
4698
|
+
`;
|
|
4699
|
+
}
|
|
4556
4700
|
}
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4701
|
+
svg += ` </g>
|
|
4702
|
+
`;
|
|
4703
|
+
}
|
|
4704
|
+
const textCenterY = node.height / 2 + (hasTech ? 4 : lines.length > 1 ? 8 : 7);
|
|
4705
|
+
if (lines.length === 1) {
|
|
4706
|
+
svg += ` <text x="${centerX}" y="${textCenterY}" class="markdy-svg-text" font-size="12" font-weight="600" fill="${textColor}" text-anchor="middle" dominant-baseline="central">${escapeXml(lines[0])}</text>
|
|
4561
4707
|
`;
|
|
4562
4708
|
} else {
|
|
4563
|
-
|
|
4564
|
-
|
|
4709
|
+
const startY = textCenterY - (lines.length - 1) * 14 / 2;
|
|
4710
|
+
lines.forEach((l, idx) => {
|
|
4711
|
+
svg += ` <text x="${centerX}" y="${startY + idx * 14}" class="markdy-svg-text" font-size="12" font-weight="600" fill="${textColor}" text-anchor="middle" dominant-baseline="central">${escapeXml(l)}</text>
|
|
4565
4712
|
`;
|
|
4566
|
-
}
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4713
|
+
});
|
|
4714
|
+
}
|
|
4715
|
+
if (hasTech) {
|
|
4716
|
+
const techBadgeW = Math.min(availTextWidth, techText.length * 6 + 10);
|
|
4717
|
+
const techBadgeY = textCenterY + lines.length * 7 + 6;
|
|
4718
|
+
svg += ` <rect x="${centerX - techBadgeW / 2}" y="${techBadgeY}" width="${techBadgeW}" height="14" rx="3" fill="${textColor}" fill-opacity="${isDark ? "0.08" : "0.05"}" stroke="${border}" stroke-width="0.75"/>
|
|
4719
|
+
<text x="${centerX}" y="${techBadgeY + 7}" class="markdy-svg-mono" font-size="8.5" font-weight="500" fill="${textMuted}" text-anchor="middle" dominant-baseline="central">${escapeXml(techText)}</text>
|
|
4570
4720
|
`;
|
|
4571
|
-
});
|
|
4572
|
-
}
|
|
4573
4721
|
}
|
|
4574
4722
|
} else if (isCircle) {
|
|
4575
4723
|
const centerX = node.width / 2;
|
|
@@ -4652,25 +4800,27 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4652
4800
|
const availTextWidth = node.width - textStartX - (valWidth > 0 ? valWidth + 14 : 14);
|
|
4653
4801
|
const lines = wrapNodeLabel(node.label, availTextWidth, 13.5);
|
|
4654
4802
|
if (hasTech) {
|
|
4655
|
-
const
|
|
4803
|
+
const lineHeight = 14;
|
|
4804
|
+
const totalTextH = (lines.length - 1) * lineHeight;
|
|
4805
|
+
const totalContentH = totalTextH + 26;
|
|
4806
|
+
const startY = Math.round(node.height / 2 - totalContentH / 2 + 6);
|
|
4656
4807
|
if (lines.length === 1) {
|
|
4657
4808
|
svg += ` <!-- Label -->
|
|
4658
|
-
<text x="${textStartX}" y="${
|
|
4809
|
+
<text x="${textStartX}" y="${startY}" class="markdy-svg-text" font-size="13" font-weight="600" letter-spacing="-0.01em" fill="${textColor}" dominant-baseline="central">${escapeXml(lines[0])}</text>
|
|
4659
4810
|
`;
|
|
4660
4811
|
} else {
|
|
4661
|
-
const startY = Math.round(labelCenterY - (lines.length - 1) * 14 / 2);
|
|
4662
4812
|
svg += ` <!-- Label -->
|
|
4663
4813
|
<text class="markdy-svg-text" font-size="12.5" font-weight="600" letter-spacing="-0.01em" fill="${textColor}">
|
|
4664
4814
|
`;
|
|
4665
4815
|
lines.forEach((l, idx) => {
|
|
4666
|
-
svg += ` <tspan x="${textStartX}" y="${startY + idx *
|
|
4816
|
+
svg += ` <tspan x="${textStartX}" y="${startY + idx * lineHeight}" dominant-baseline="central">${escapeXml(l)}</tspan>
|
|
4667
4817
|
`;
|
|
4668
4818
|
});
|
|
4669
4819
|
svg += ` </text>
|
|
4670
4820
|
`;
|
|
4671
4821
|
}
|
|
4672
4822
|
const techBadgeW = Math.min(availTextWidth, techText.length * 6.2 + 12);
|
|
4673
|
-
const techBadgeY =
|
|
4823
|
+
const techBadgeY = startY + (lines.length - 1) * lineHeight + 12;
|
|
4674
4824
|
svg += ` <!-- Tech Badge -->
|
|
4675
4825
|
<rect x="${textStartX}" y="${techBadgeY}" width="${techBadgeW}" height="16" rx="4" fill="${textColor}" fill-opacity="${isDark ? "0.08" : "0.05"}" stroke="${border}" stroke-width="0.75"/>
|
|
4676
4826
|
<text x="${textStartX + 6}" y="${techBadgeY + 8}" class="markdy-svg-mono" font-size="9.5" font-weight="500" fill="${textMuted}" dominant-baseline="central">${escapeXml(techText)}</text>
|
|
@@ -4679,20 +4829,17 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4679
4829
|
if (lines.length === 1) {
|
|
4680
4830
|
svg += ` <!-- Label -->
|
|
4681
4831
|
<text x="${textStartX}" y="${Math.round(node.height / 2)}" class="markdy-svg-text" font-size="13.5" font-weight="600" letter-spacing="-0.01em" fill="${textColor}" dominant-baseline="central">${escapeXml(lines[0])}</text>
|
|
4682
|
-
`;
|
|
4683
|
-
} else if (lines.length === 2) {
|
|
4684
|
-
const startY = Math.round(node.height / 2 - 8);
|
|
4685
|
-
svg += ` <!-- Label -->
|
|
4686
|
-
<text x="${textStartX}" y="${startY}" class="markdy-svg-text" font-size="13.5" font-weight="600" letter-spacing="-0.01em" fill="${textColor}" dominant-baseline="central">${escapeXml(lines[0])}</text>
|
|
4687
|
-
<text x="${textStartX}" y="${startY + 16}" class="markdy-svg-text" font-size="13.5" font-weight="600" letter-spacing="-0.01em" fill="${textColor}" dominant-baseline="central">${escapeXml(lines[1])}</text>
|
|
4688
4832
|
`;
|
|
4689
4833
|
} else {
|
|
4690
|
-
const
|
|
4834
|
+
const lineHeight = 16;
|
|
4835
|
+
const totalTextH = (lines.length - 1) * lineHeight;
|
|
4836
|
+
const startY = Math.round(node.height / 2 - totalTextH / 2);
|
|
4691
4837
|
svg += ` <!-- Label -->
|
|
4692
|
-
<text x="${textStartX}" y="${startY}" class="markdy-svg-text" font-size="13.5" font-weight="600" letter-spacing="-0.01em" fill="${textColor}" dominant-baseline="central">${escapeXml(lines[0])}</text>
|
|
4693
|
-
<text x="${textStartX}" y="${startY + 15}" class="markdy-svg-text" font-size="13.5" font-weight="600" letter-spacing="-0.01em" fill="${textColor}" dominant-baseline="central">${escapeXml(lines[1])}</text>
|
|
4694
|
-
<text x="${textStartX}" y="${startY + 30}" class="markdy-svg-text" font-size="13.5" font-weight="600" letter-spacing="-0.01em" fill="${textColor}" dominant-baseline="central">${escapeXml(lines[2])}</text>
|
|
4695
4838
|
`;
|
|
4839
|
+
lines.forEach((l, idx) => {
|
|
4840
|
+
svg += ` <text x="${textStartX}" y="${startY + idx * lineHeight}" class="markdy-svg-text" font-size="13.5" font-weight="600" letter-spacing="-0.01em" fill="${textColor}" dominant-baseline="central">${escapeXml(l)}</text>
|
|
4841
|
+
`;
|
|
4842
|
+
});
|
|
4696
4843
|
}
|
|
4697
4844
|
}
|
|
4698
4845
|
}
|
|
@@ -5594,6 +5741,54 @@ function detectHostTheme(container) {
|
|
|
5594
5741
|
}
|
|
5595
5742
|
return "paper";
|
|
5596
5743
|
}
|
|
5744
|
+
function computeDiagramContentBounds(plan) {
|
|
5745
|
+
if (!plan.nodes || plan.nodes.length === 0) {
|
|
5746
|
+
return { minX: 0, minY: 0, maxX: plan.meta.width, maxY: plan.meta.height, width: plan.meta.width, height: plan.meta.height };
|
|
5747
|
+
}
|
|
5748
|
+
let minX = Infinity;
|
|
5749
|
+
let minY = Infinity;
|
|
5750
|
+
let maxX = -Infinity;
|
|
5751
|
+
let maxY = -Infinity;
|
|
5752
|
+
for (const node of plan.nodes) {
|
|
5753
|
+
minX = Math.min(minX, node.x);
|
|
5754
|
+
minY = Math.min(minY, node.y);
|
|
5755
|
+
maxX = Math.max(maxX, node.x + node.width);
|
|
5756
|
+
maxY = Math.max(maxY, node.y + node.height);
|
|
5757
|
+
}
|
|
5758
|
+
for (const gb of plan.groupBoundaries ?? []) {
|
|
5759
|
+
minX = Math.min(minX, gb.x);
|
|
5760
|
+
minY = Math.min(minY, gb.y);
|
|
5761
|
+
maxX = Math.max(maxX, gb.x + gb.width);
|
|
5762
|
+
maxY = Math.max(maxY, gb.y + gb.height);
|
|
5763
|
+
}
|
|
5764
|
+
for (const bus of plan.treeBuses ?? []) {
|
|
5765
|
+
minX = Math.min(minX, bus.parentX, ...bus.childXs.length ? bus.childXs : [bus.parentX]);
|
|
5766
|
+
minY = Math.min(minY, bus.parentY, bus.branchY, bus.childY);
|
|
5767
|
+
maxX = Math.max(maxX, bus.parentX, ...bus.childXs.length ? bus.childXs : [bus.parentX]);
|
|
5768
|
+
maxY = Math.max(maxY, bus.parentY, bus.branchY, bus.childY);
|
|
5769
|
+
}
|
|
5770
|
+
if (plan.diagramType === "sequence") {
|
|
5771
|
+
let maxMsgY = minY;
|
|
5772
|
+
for (const msg of plan.sequenceMessages ?? []) {
|
|
5773
|
+
maxMsgY = Math.max(maxMsgY, msg.y + 60);
|
|
5774
|
+
}
|
|
5775
|
+
for (const act of plan.sequenceActivations ?? []) {
|
|
5776
|
+
maxMsgY = Math.max(maxMsgY, act.y + act.height + 40);
|
|
5777
|
+
}
|
|
5778
|
+
maxY = Math.max(maxY, maxMsgY, Math.min(plan.meta.height, 420));
|
|
5779
|
+
}
|
|
5780
|
+
if (plan.title) {
|
|
5781
|
+
minY = Math.min(minY, 20);
|
|
5782
|
+
}
|
|
5783
|
+
const pad = 36;
|
|
5784
|
+
minX = Math.max(0, minX - pad);
|
|
5785
|
+
minY = Math.max(0, minY - pad);
|
|
5786
|
+
maxX = Math.min(plan.meta.width, maxX + pad);
|
|
5787
|
+
maxY = Math.min(plan.meta.height, maxY + pad);
|
|
5788
|
+
const width = Math.max(maxX - minX, 200);
|
|
5789
|
+
const height = Math.max(maxY - minY, 140);
|
|
5790
|
+
return { minX, minY, maxX, maxY, width, height };
|
|
5791
|
+
}
|
|
5597
5792
|
function createDiagram(opts) {
|
|
5598
5793
|
const {
|
|
5599
5794
|
container,
|
|
@@ -5606,6 +5801,7 @@ function createDiagram(opts) {
|
|
|
5606
5801
|
playbackRate: initialPlaybackRate,
|
|
5607
5802
|
controls: explicitControls,
|
|
5608
5803
|
interactiveViewport: explicitInteractiveViewport,
|
|
5804
|
+
clickToPlay: explicitClickToPlay,
|
|
5609
5805
|
shareUrl,
|
|
5610
5806
|
autoplay: explicitAutoplay,
|
|
5611
5807
|
loop: explicitLoop,
|
|
@@ -5615,15 +5811,23 @@ function createDiagram(opts) {
|
|
|
5615
5811
|
onPlayStateChange,
|
|
5616
5812
|
onEnded
|
|
5617
5813
|
} = opts;
|
|
5618
|
-
const
|
|
5814
|
+
const ast = parse(code);
|
|
5619
5815
|
for (const w of ast.diagnostics) {
|
|
5620
5816
|
if (w.severity === "warning") onWarning(w);
|
|
5621
5817
|
}
|
|
5622
|
-
const
|
|
5623
|
-
if (!
|
|
5624
|
-
const
|
|
5625
|
-
|
|
5818
|
+
const hasExplicitDirection = ast.meta.explicitDirection === true;
|
|
5819
|
+
if (!hasExplicitDirection) {
|
|
5820
|
+
const isPortrait = typeof window !== "undefined" ? window.innerWidth < window.innerHeight || container && container.clientWidth > 0 && container.clientWidth < 640 : false;
|
|
5821
|
+
ast.meta.direction = isPortrait ? "TB" : "LR";
|
|
5626
5822
|
}
|
|
5823
|
+
if (!ast.meta.explicitWidth || !ast.meta.explicitHeight) {
|
|
5824
|
+
const dims = computeAdaptiveDimensions(ast);
|
|
5825
|
+
if (!ast.meta.explicitWidth) ast.meta.width = dims.width;
|
|
5826
|
+
if (!ast.meta.explicitHeight) ast.meta.height = dims.height;
|
|
5827
|
+
}
|
|
5828
|
+
const hasExplicitTheme = Boolean(ast.meta.explicitTheme === true && ast.meta.theme !== "auto");
|
|
5829
|
+
const initialTheme = hasExplicitTheme ? ast.meta.theme : detectHostTheme(container);
|
|
5830
|
+
const plan = compilePlan(ast, resolveTheme2(initialTheme));
|
|
5627
5831
|
let hostThemeObserver = null;
|
|
5628
5832
|
let mediaQueryListener = null;
|
|
5629
5833
|
let colorSchemeQuery = null;
|
|
@@ -5636,6 +5840,7 @@ function createDiagram(opts) {
|
|
|
5636
5840
|
copyright: explicitCopyright,
|
|
5637
5841
|
controls: explicitControls,
|
|
5638
5842
|
interactiveViewport: explicitInteractiveViewport,
|
|
5843
|
+
clickToPlay: explicitClickToPlay,
|
|
5639
5844
|
progress: hostProgress,
|
|
5640
5845
|
progressColor: hostProgressColor
|
|
5641
5846
|
});
|
|
@@ -5688,18 +5893,22 @@ function createDiagram(opts) {
|
|
|
5688
5893
|
});
|
|
5689
5894
|
if (container.style.aspectRatio) container.style.aspectRatio = "unset";
|
|
5690
5895
|
if (container.style.overflow === "hidden") container.style.overflow = "visible";
|
|
5896
|
+
const initialBounds = computeDiagramContentBounds(plan);
|
|
5897
|
+
const naturalRatio = `${plan.meta.width} / ${plan.meta.height}`;
|
|
5691
5898
|
const viewport = document.createElement("div");
|
|
5692
5899
|
viewport.className = "markdy-viewport";
|
|
5900
|
+
applyThemeVariables(viewport, plan.theme);
|
|
5693
5901
|
Object.assign(viewport.style, {
|
|
5694
5902
|
position: "relative",
|
|
5695
5903
|
width: "100%",
|
|
5696
5904
|
maxWidth: "100%",
|
|
5697
5905
|
maxHeight: "100%",
|
|
5698
|
-
aspectRatio:
|
|
5906
|
+
aspectRatio: naturalRatio,
|
|
5699
5907
|
overflow: "hidden",
|
|
5700
5908
|
boxSizing: "border-box",
|
|
5701
5909
|
flex: "1 1 auto",
|
|
5702
|
-
minHeight: "0"
|
|
5910
|
+
minHeight: "0",
|
|
5911
|
+
background: plan.theme.canvas
|
|
5703
5912
|
});
|
|
5704
5913
|
container.appendChild(viewport);
|
|
5705
5914
|
let progressEl = null;
|
|
@@ -5913,42 +6122,7 @@ function createDiagram(opts) {
|
|
|
5913
6122
|
let sceneOffsetX = 0;
|
|
5914
6123
|
let sceneOffsetY = 0;
|
|
5915
6124
|
function computeContentBounds() {
|
|
5916
|
-
|
|
5917
|
-
return { minX: 0, minY: 0, maxX: plan.meta.width, maxY: plan.meta.height, width: plan.meta.width, height: plan.meta.height };
|
|
5918
|
-
}
|
|
5919
|
-
let minX = Infinity;
|
|
5920
|
-
let minY = Infinity;
|
|
5921
|
-
let maxX = -Infinity;
|
|
5922
|
-
let maxY = -Infinity;
|
|
5923
|
-
for (const node of plan.nodes) {
|
|
5924
|
-
minX = Math.min(minX, node.x);
|
|
5925
|
-
minY = Math.min(minY, node.y);
|
|
5926
|
-
maxX = Math.max(maxX, node.x + node.width);
|
|
5927
|
-
maxY = Math.max(maxY, node.y + node.height);
|
|
5928
|
-
}
|
|
5929
|
-
for (const gb of plan.groupBoundaries ?? []) {
|
|
5930
|
-
minX = Math.min(minX, gb.x);
|
|
5931
|
-
minY = Math.min(minY, gb.y);
|
|
5932
|
-
maxX = Math.max(maxX, gb.x + gb.width);
|
|
5933
|
-
maxY = Math.max(maxY, gb.y + gb.height);
|
|
5934
|
-
}
|
|
5935
|
-
for (const bus of plan.treeBuses ?? []) {
|
|
5936
|
-
minX = Math.min(minX, bus.parentX, ...bus.childXs.length ? bus.childXs : [bus.parentX]);
|
|
5937
|
-
minY = Math.min(minY, bus.parentY, bus.branchY, bus.childY);
|
|
5938
|
-
maxX = Math.max(maxX, bus.parentX, ...bus.childXs.length ? bus.childXs : [bus.parentX]);
|
|
5939
|
-
maxY = Math.max(maxY, bus.parentY, bus.branchY, bus.childY);
|
|
5940
|
-
}
|
|
5941
|
-
if (plan.title) {
|
|
5942
|
-
minY = Math.min(minY, 20);
|
|
5943
|
-
}
|
|
5944
|
-
const pad = 36;
|
|
5945
|
-
minX = Math.max(0, minX - pad);
|
|
5946
|
-
minY = Math.max(0, minY - pad);
|
|
5947
|
-
maxX = Math.min(plan.meta.width, maxX + pad);
|
|
5948
|
-
maxY = Math.min(plan.meta.height, maxY + pad);
|
|
5949
|
-
const width = Math.max(maxX - minX, 200);
|
|
5950
|
-
const height = Math.max(maxY - minY, 140);
|
|
5951
|
-
return { minX, minY, maxX, maxY, width, height };
|
|
6125
|
+
return computeDiagramContentBounds(plan);
|
|
5952
6126
|
}
|
|
5953
6127
|
function scaleScene() {
|
|
5954
6128
|
const isBrowserLayout = (viewport.clientWidth || container.clientWidth || 0) > 0;
|
|
@@ -5963,9 +6137,14 @@ function createDiagram(opts) {
|
|
|
5963
6137
|
return;
|
|
5964
6138
|
}
|
|
5965
6139
|
const vWidth = viewport.clientWidth || container.clientWidth || plan.meta.width;
|
|
5966
|
-
const
|
|
5967
|
-
const
|
|
5968
|
-
const
|
|
6140
|
+
const fallbackHeight = vWidth * plan.meta.height / plan.meta.width;
|
|
6141
|
+
const vHeight = viewport.clientHeight || container.clientHeight || fallbackHeight;
|
|
6142
|
+
const padX = Math.max(12, Math.min(32, vWidth * 0.03));
|
|
6143
|
+
const padY = Math.max(12, Math.min(28, vHeight * 0.03));
|
|
6144
|
+
const availW = Math.max(80, vWidth - padX * 2);
|
|
6145
|
+
const availH = Math.max(80, vHeight - padY * 2);
|
|
6146
|
+
const canvasScaleX = availW / plan.meta.width;
|
|
6147
|
+
const canvasScaleY = availH / plan.meta.height;
|
|
5969
6148
|
fitScale = Math.min(canvasScaleX, canvasScaleY);
|
|
5970
6149
|
if (!Number.isFinite(fitScale) || fitScale <= 0) fitScale = 1;
|
|
5971
6150
|
const scaledWidth = plan.meta.width * fitScale;
|
|
@@ -6001,7 +6180,8 @@ function createDiagram(opts) {
|
|
|
6001
6180
|
{ width: plan.meta.width, height: plan.meta.height },
|
|
6002
6181
|
edgeRuntimes,
|
|
6003
6182
|
edgeSceneId,
|
|
6004
|
-
plan.diagramType
|
|
6183
|
+
plan.diagramType,
|
|
6184
|
+
plan.cues
|
|
6005
6185
|
),
|
|
6006
6186
|
...buildCueAnimations(plan.cues, nodeEls, plan.nodes, plan.theme, cameraLayer, titleEl, {
|
|
6007
6187
|
width: plan.meta.width,
|
|
@@ -6996,9 +7176,9 @@ function createDiagram(opts) {
|
|
|
6996
7176
|
ensureFooter().insertBefore(toolbar, badge);
|
|
6997
7177
|
syncControls();
|
|
6998
7178
|
}
|
|
6999
|
-
viewport.style.cursor = interactiveViewport ? "grab" : "pointer";
|
|
7179
|
+
viewport.style.cursor = interactiveViewport ? "grab" : clickToPlay ? "pointer" : "default";
|
|
7000
7180
|
if (interactiveViewport) {
|
|
7001
|
-
viewport.style.touchAction = "
|
|
7181
|
+
viewport.style.touchAction = "pan-y";
|
|
7002
7182
|
if (allowZoom) viewport.addEventListener("wheel", handleViewportWheel, { passive: false });
|
|
7003
7183
|
if (allowPan) {
|
|
7004
7184
|
viewport.addEventListener("pointerdown", handleViewportPointerDown);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdy/renderer-dom",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
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.3.
|
|
49
|
+
"@markdy/core": "1.3.2"
|
|
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.3.
|
|
56
|
+
"@markdy/stdlib-systems": "1.3.2"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup",
|