@markdy/renderer-dom 1.3.1 → 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 +304 -173
- 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;
|
|
@@ -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;
|
|
@@ -2122,7 +2129,7 @@ function ensureNodeStyles(doc) {
|
|
|
2122
2129
|
inset 0 0 0 1px var(--md-hairline, color-mix(in srgb, var(--md-border) 50%, transparent)),
|
|
2123
2130
|
inset 0 1px 0 rgba(255, 255, 255, 0.12);
|
|
2124
2131
|
font-family: var(--md-font-node, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif);
|
|
2125
|
-
overflow:
|
|
2132
|
+
overflow: visible;
|
|
2126
2133
|
opacity: 0;
|
|
2127
2134
|
transform: translateY(8px);
|
|
2128
2135
|
transition: box-shadow 0.25s ease, transform 0.25s ease;
|
|
@@ -2157,21 +2164,26 @@ function ensureNodeStyles(doc) {
|
|
|
2157
2164
|
box-sizing: border-box;
|
|
2158
2165
|
}
|
|
2159
2166
|
.markdy-node__icon {
|
|
2160
|
-
flex: 0 0
|
|
2167
|
+
flex: 0 0 28px;
|
|
2161
2168
|
width: 28px;
|
|
2162
2169
|
height: 28px;
|
|
2163
|
-
|
|
2170
|
+
border-radius: 7px;
|
|
2171
|
+
display: inline-flex;
|
|
2164
2172
|
align-items: center;
|
|
2165
2173
|
justify-content: center;
|
|
2174
|
+
background: color-mix(in srgb, var(--md-role-color, var(--md-accent)) 14%, transparent);
|
|
2166
2175
|
color: var(--md-role-color, var(--md-accent));
|
|
2167
|
-
|
|
2168
|
-
|
|
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;
|
|
2169
2178
|
}
|
|
2170
2179
|
.markdy-node__icon svg {
|
|
2171
|
-
width:
|
|
2172
|
-
height:
|
|
2173
|
-
display: block;
|
|
2180
|
+
width: 18px;
|
|
2181
|
+
height: 18px;
|
|
2174
2182
|
stroke: currentColor;
|
|
2183
|
+
stroke-width: 1.8;
|
|
2184
|
+
fill: none;
|
|
2185
|
+
stroke-linecap: round;
|
|
2186
|
+
stroke-linejoin: round;
|
|
2175
2187
|
}
|
|
2176
2188
|
.markdy-node__icon[data-media="image"] {
|
|
2177
2189
|
background: transparent;
|
|
@@ -2206,14 +2218,10 @@ function ensureNodeStyles(doc) {
|
|
|
2206
2218
|
letter-spacing: -0.01em;
|
|
2207
2219
|
line-height: 1.24;
|
|
2208
2220
|
color: var(--md-text);
|
|
2209
|
-
display: -webkit-box;
|
|
2210
|
-
-webkit-box-orient: vertical;
|
|
2211
|
-
-webkit-line-clamp: 2;
|
|
2212
|
-
line-clamp: 2;
|
|
2213
|
-
overflow: hidden;
|
|
2214
2221
|
overflow-wrap: anywhere;
|
|
2215
2222
|
word-break: break-word;
|
|
2216
2223
|
text-wrap: pretty;
|
|
2224
|
+
white-space: pre-line;
|
|
2217
2225
|
}
|
|
2218
2226
|
.markdy-node__tech {
|
|
2219
2227
|
align-self: flex-start;
|
|
@@ -2228,9 +2236,8 @@ function ensureNodeStyles(doc) {
|
|
|
2228
2236
|
border-radius: 4px;
|
|
2229
2237
|
letter-spacing: 0.01em;
|
|
2230
2238
|
white-space: nowrap;
|
|
2231
|
-
overflow: hidden;
|
|
2232
|
-
text-overflow: ellipsis;
|
|
2233
2239
|
max-width: 100%;
|
|
2240
|
+
box-sizing: border-box;
|
|
2234
2241
|
}
|
|
2235
2242
|
.markdy-node__value {
|
|
2236
2243
|
flex: 0 0 auto;
|
|
@@ -2292,31 +2299,97 @@ function ensureNodeStyles(doc) {
|
|
|
2292
2299
|
.markdy-scene-root[data-markdy-theme="nebula"] .markdy-node[data-shape="diamond"][data-focal="1"] {
|
|
2293
2300
|
border: none;
|
|
2294
2301
|
box-shadow: none;
|
|
2302
|
+
background: transparent;
|
|
2295
2303
|
}
|
|
2296
2304
|
.markdy-node[data-shape="diamond"] {
|
|
2297
2305
|
border-radius: 0;
|
|
2298
2306
|
transform: rotate(0deg);
|
|
2299
|
-
clip-path:
|
|
2300
|
-
|
|
2307
|
+
clip-path: none;
|
|
2308
|
+
background: transparent;
|
|
2309
|
+
overflow: visible;
|
|
2310
|
+
}
|
|
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;
|
|
2301
2333
|
}
|
|
2302
|
-
.markdy-node[data-shape="diamond"][data-focal="1"]
|
|
2303
|
-
|
|
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));
|
|
2304
2339
|
}
|
|
2305
|
-
.markdy-node[data-shape="diamond"][data-
|
|
2306
|
-
|
|
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)));
|
|
2307
2344
|
}
|
|
2308
|
-
.markdy-node[data-shape="diamond"]
|
|
2309
|
-
|
|
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));
|
|
2310
2348
|
}
|
|
2311
2349
|
.markdy-node[data-shape="diamond"] .markdy-node__body {
|
|
2350
|
+
flex-direction: column;
|
|
2351
|
+
align-items: center;
|
|
2312
2352
|
justify-content: center;
|
|
2313
|
-
padding:
|
|
2353
|
+
padding: 8px 14%;
|
|
2314
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;
|
|
2315
2379
|
}
|
|
2316
2380
|
.markdy-node[data-shape="diamond"] .markdy-node__label {
|
|
2317
2381
|
flex: 0 1 auto;
|
|
2318
|
-
|
|
2382
|
+
font-size: 12px;
|
|
2383
|
+
font-weight: 600;
|
|
2384
|
+
line-height: 1.25;
|
|
2319
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;
|
|
2320
2393
|
}
|
|
2321
2394
|
.markdy-node[data-shape="pill"] {
|
|
2322
2395
|
border-radius: 999px;
|
|
@@ -2353,8 +2426,6 @@ function ensureNodeStyles(doc) {
|
|
|
2353
2426
|
}
|
|
2354
2427
|
.markdy-node[data-shape="circle"] .markdy-node__label {
|
|
2355
2428
|
text-align: center;
|
|
2356
|
-
-webkit-line-clamp: 4;
|
|
2357
|
-
line-clamp: 4;
|
|
2358
2429
|
}
|
|
2359
2430
|
.markdy-node[data-kind="dot"] {
|
|
2360
2431
|
width: 64px;
|
|
@@ -2909,9 +2980,26 @@ function createNodeEl(node, theme, assets) {
|
|
|
2909
2980
|
if (node.shape === "container") el.dataset.isContainer = "1";
|
|
2910
2981
|
el.title = `${node.label} (${typeText})`;
|
|
2911
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
|
+
}
|
|
2912
3000
|
const body = document.createElement("div");
|
|
2913
3001
|
body.className = "markdy-node__body";
|
|
2914
|
-
|
|
3002
|
+
body.append(createNodeMediaEl(document, node, assets));
|
|
2915
3003
|
const content = document.createElement("div");
|
|
2916
3004
|
content.className = "markdy-node__content";
|
|
2917
3005
|
const label = document.createElement("div");
|
|
@@ -4172,7 +4260,7 @@ function circleBoundaryRoute2(from, to) {
|
|
|
4172
4260
|
{ x: toCenter.x - ux * toRadius, y: toCenter.y - uy * toRadius }
|
|
4173
4261
|
]);
|
|
4174
4262
|
}
|
|
4175
|
-
function snapPortToNodeShape2(node, port, neighbor,
|
|
4263
|
+
function snapPortToNodeShape2(node, port, neighbor, _isSource) {
|
|
4176
4264
|
if (!node.shape || node.shape === "card" || node.shape === "rounded" || node.shape === "terminal" || node.shape === "container") {
|
|
4177
4265
|
return port;
|
|
4178
4266
|
}
|
|
@@ -4180,45 +4268,40 @@ function snapPortToNodeShape2(node, port, neighbor, isSource) {
|
|
|
4180
4268
|
const cy = node.y + node.height / 2;
|
|
4181
4269
|
const hw = node.width / 2;
|
|
4182
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);
|
|
4183
4274
|
if (node.shape === "diamond") {
|
|
4184
|
-
const isVert = Math.abs(port.x - neighbor.x) < 0.01;
|
|
4185
|
-
const isHoriz = Math.abs(port.y - neighbor.y) < 0.01;
|
|
4186
|
-
if (isVert) {
|
|
4187
|
-
const goingDown = isSource ? neighbor.y > port.y : port.y > neighbor.y;
|
|
4188
|
-
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));
|
|
4189
|
-
return { x: port.x, y: Math.round(boundaryY * 10) / 10 };
|
|
4190
|
-
}
|
|
4191
4275
|
if (isHoriz) {
|
|
4192
|
-
const
|
|
4193
|
-
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));
|
|
4194
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 };
|
|
4195
4281
|
}
|
|
4196
4282
|
}
|
|
4197
4283
|
if (node.shape === "circle") {
|
|
4198
4284
|
const r = Math.min(node.width, node.height) / 2;
|
|
4199
|
-
const isVert = Math.abs(port.x - neighbor.x) < 0.01;
|
|
4200
|
-
const isHoriz = Math.abs(port.y - neighbor.y) < 0.01;
|
|
4201
|
-
if (isVert) {
|
|
4202
|
-
const goingDown = isSource ? neighbor.y > port.y : port.y > neighbor.y;
|
|
4203
|
-
return { x: cx, y: goingDown ? cy + r : cy - r };
|
|
4204
|
-
}
|
|
4205
4285
|
if (isHoriz) {
|
|
4206
|
-
const
|
|
4207
|
-
|
|
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 };
|
|
4208
4293
|
}
|
|
4209
4294
|
}
|
|
4210
4295
|
if (node.shape === "pill") {
|
|
4211
4296
|
const r = node.height / 2;
|
|
4212
|
-
const isVert = Math.abs(port.x - neighbor.x) < 0.01;
|
|
4213
|
-
const isHoriz = Math.abs(port.y - neighbor.y) < 0.01;
|
|
4214
4297
|
if (isHoriz) {
|
|
4215
|
-
const
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
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 {
|
|
4220
4303
|
const clampedX = Math.max(node.x + r, Math.min(node.x + node.width - r, port.x));
|
|
4221
|
-
return { x: clampedX, y:
|
|
4304
|
+
return { x: clampedX, y: facingDown ? node.y + node.height : node.y };
|
|
4222
4305
|
}
|
|
4223
4306
|
}
|
|
4224
4307
|
return port;
|
|
@@ -4276,10 +4359,9 @@ function wrapNodeLabel(label, maxWidthPx, fontSize = 13.5) {
|
|
|
4276
4359
|
} else {
|
|
4277
4360
|
lines.push(current);
|
|
4278
4361
|
current = word;
|
|
4279
|
-
if (lines.length === 2) break;
|
|
4280
4362
|
}
|
|
4281
4363
|
}
|
|
4282
|
-
if (current
|
|
4364
|
+
if (current) {
|
|
4283
4365
|
lines.push(current);
|
|
4284
4366
|
}
|
|
4285
4367
|
return lines;
|
|
@@ -4565,7 +4647,8 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4565
4647
|
if (isDiamond) {
|
|
4566
4648
|
const hw = node.width / 2;
|
|
4567
4649
|
const hh = node.height / 2;
|
|
4568
|
-
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"/>
|
|
4569
4652
|
`;
|
|
4570
4653
|
} else if (isCircle) {
|
|
4571
4654
|
const r = Math.min(node.width, node.height) / 2;
|
|
@@ -4587,37 +4670,54 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4587
4670
|
const valWidth = valText ? valText.length * 9.5 + 16 : 0;
|
|
4588
4671
|
const iconSize = 26;
|
|
4589
4672
|
if (isDiamond) {
|
|
4590
|
-
const availTextWidth = Math.max(40, node.width * 0.65);
|
|
4591
|
-
const lines = wrapNodeLabel(node.label, availTextWidth, 12.5);
|
|
4592
4673
|
const centerX = node.width / 2;
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
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"/>
|
|
4597
4684
|
`;
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
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>
|
|
4602
4690
|
`;
|
|
4603
|
-
|
|
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
|
+
}
|
|
4604
4700
|
}
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
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>
|
|
4609
4707
|
`;
|
|
4610
4708
|
} else {
|
|
4611
|
-
|
|
4612
|
-
|
|
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>
|
|
4613
4712
|
`;
|
|
4614
|
-
}
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
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>
|
|
4618
4720
|
`;
|
|
4619
|
-
});
|
|
4620
|
-
}
|
|
4621
4721
|
}
|
|
4622
4722
|
} else if (isCircle) {
|
|
4623
4723
|
const centerX = node.width / 2;
|
|
@@ -4700,25 +4800,27 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4700
4800
|
const availTextWidth = node.width - textStartX - (valWidth > 0 ? valWidth + 14 : 14);
|
|
4701
4801
|
const lines = wrapNodeLabel(node.label, availTextWidth, 13.5);
|
|
4702
4802
|
if (hasTech) {
|
|
4703
|
-
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);
|
|
4704
4807
|
if (lines.length === 1) {
|
|
4705
4808
|
svg += ` <!-- Label -->
|
|
4706
|
-
<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>
|
|
4707
4810
|
`;
|
|
4708
4811
|
} else {
|
|
4709
|
-
const startY = Math.round(labelCenterY - (lines.length - 1) * 14 / 2);
|
|
4710
4812
|
svg += ` <!-- Label -->
|
|
4711
4813
|
<text class="markdy-svg-text" font-size="12.5" font-weight="600" letter-spacing="-0.01em" fill="${textColor}">
|
|
4712
4814
|
`;
|
|
4713
4815
|
lines.forEach((l, idx) => {
|
|
4714
|
-
svg += ` <tspan x="${textStartX}" y="${startY + idx *
|
|
4816
|
+
svg += ` <tspan x="${textStartX}" y="${startY + idx * lineHeight}" dominant-baseline="central">${escapeXml(l)}</tspan>
|
|
4715
4817
|
`;
|
|
4716
4818
|
});
|
|
4717
4819
|
svg += ` </text>
|
|
4718
4820
|
`;
|
|
4719
4821
|
}
|
|
4720
4822
|
const techBadgeW = Math.min(availTextWidth, techText.length * 6.2 + 12);
|
|
4721
|
-
const techBadgeY =
|
|
4823
|
+
const techBadgeY = startY + (lines.length - 1) * lineHeight + 12;
|
|
4722
4824
|
svg += ` <!-- Tech Badge -->
|
|
4723
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"/>
|
|
4724
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>
|
|
@@ -4727,20 +4829,17 @@ function renderPureVectorSvg(plan, options = {}) {
|
|
|
4727
4829
|
if (lines.length === 1) {
|
|
4728
4830
|
svg += ` <!-- Label -->
|
|
4729
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>
|
|
4730
|
-
`;
|
|
4731
|
-
} else if (lines.length === 2) {
|
|
4732
|
-
const startY = Math.round(node.height / 2 - 8);
|
|
4733
|
-
svg += ` <!-- Label -->
|
|
4734
|
-
<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>
|
|
4735
|
-
<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>
|
|
4736
4832
|
`;
|
|
4737
4833
|
} else {
|
|
4738
|
-
const
|
|
4834
|
+
const lineHeight = 16;
|
|
4835
|
+
const totalTextH = (lines.length - 1) * lineHeight;
|
|
4836
|
+
const startY = Math.round(node.height / 2 - totalTextH / 2);
|
|
4739
4837
|
svg += ` <!-- Label -->
|
|
4740
|
-
<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>
|
|
4741
|
-
<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>
|
|
4742
|
-
<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>
|
|
4743
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
|
+
});
|
|
4744
4843
|
}
|
|
4745
4844
|
}
|
|
4746
4845
|
}
|
|
@@ -5642,6 +5741,54 @@ function detectHostTheme(container) {
|
|
|
5642
5741
|
}
|
|
5643
5742
|
return "paper";
|
|
5644
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
|
+
}
|
|
5645
5792
|
function createDiagram(opts) {
|
|
5646
5793
|
const {
|
|
5647
5794
|
container,
|
|
@@ -5654,6 +5801,7 @@ function createDiagram(opts) {
|
|
|
5654
5801
|
playbackRate: initialPlaybackRate,
|
|
5655
5802
|
controls: explicitControls,
|
|
5656
5803
|
interactiveViewport: explicitInteractiveViewport,
|
|
5804
|
+
clickToPlay: explicitClickToPlay,
|
|
5657
5805
|
shareUrl,
|
|
5658
5806
|
autoplay: explicitAutoplay,
|
|
5659
5807
|
loop: explicitLoop,
|
|
@@ -5663,15 +5811,23 @@ function createDiagram(opts) {
|
|
|
5663
5811
|
onPlayStateChange,
|
|
5664
5812
|
onEnded
|
|
5665
5813
|
} = opts;
|
|
5666
|
-
const
|
|
5814
|
+
const ast = parse(code);
|
|
5667
5815
|
for (const w of ast.diagnostics) {
|
|
5668
5816
|
if (w.severity === "warning") onWarning(w);
|
|
5669
5817
|
}
|
|
5670
|
-
const
|
|
5671
|
-
if (!
|
|
5672
|
-
const
|
|
5673
|
-
|
|
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";
|
|
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;
|
|
5674
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));
|
|
5675
5831
|
let hostThemeObserver = null;
|
|
5676
5832
|
let mediaQueryListener = null;
|
|
5677
5833
|
let colorSchemeQuery = null;
|
|
@@ -5684,6 +5840,7 @@ function createDiagram(opts) {
|
|
|
5684
5840
|
copyright: explicitCopyright,
|
|
5685
5841
|
controls: explicitControls,
|
|
5686
5842
|
interactiveViewport: explicitInteractiveViewport,
|
|
5843
|
+
clickToPlay: explicitClickToPlay,
|
|
5687
5844
|
progress: hostProgress,
|
|
5688
5845
|
progressColor: hostProgressColor
|
|
5689
5846
|
});
|
|
@@ -5736,18 +5893,22 @@ function createDiagram(opts) {
|
|
|
5736
5893
|
});
|
|
5737
5894
|
if (container.style.aspectRatio) container.style.aspectRatio = "unset";
|
|
5738
5895
|
if (container.style.overflow === "hidden") container.style.overflow = "visible";
|
|
5896
|
+
const initialBounds = computeDiagramContentBounds(plan);
|
|
5897
|
+
const naturalRatio = `${plan.meta.width} / ${plan.meta.height}`;
|
|
5739
5898
|
const viewport = document.createElement("div");
|
|
5740
5899
|
viewport.className = "markdy-viewport";
|
|
5900
|
+
applyThemeVariables(viewport, plan.theme);
|
|
5741
5901
|
Object.assign(viewport.style, {
|
|
5742
5902
|
position: "relative",
|
|
5743
5903
|
width: "100%",
|
|
5744
5904
|
maxWidth: "100%",
|
|
5745
5905
|
maxHeight: "100%",
|
|
5746
|
-
aspectRatio:
|
|
5906
|
+
aspectRatio: naturalRatio,
|
|
5747
5907
|
overflow: "hidden",
|
|
5748
5908
|
boxSizing: "border-box",
|
|
5749
5909
|
flex: "1 1 auto",
|
|
5750
|
-
minHeight: "0"
|
|
5910
|
+
minHeight: "0",
|
|
5911
|
+
background: plan.theme.canvas
|
|
5751
5912
|
});
|
|
5752
5913
|
container.appendChild(viewport);
|
|
5753
5914
|
let progressEl = null;
|
|
@@ -5961,42 +6122,7 @@ function createDiagram(opts) {
|
|
|
5961
6122
|
let sceneOffsetX = 0;
|
|
5962
6123
|
let sceneOffsetY = 0;
|
|
5963
6124
|
function computeContentBounds() {
|
|
5964
|
-
|
|
5965
|
-
return { minX: 0, minY: 0, maxX: plan.meta.width, maxY: plan.meta.height, width: plan.meta.width, height: plan.meta.height };
|
|
5966
|
-
}
|
|
5967
|
-
let minX = Infinity;
|
|
5968
|
-
let minY = Infinity;
|
|
5969
|
-
let maxX = -Infinity;
|
|
5970
|
-
let maxY = -Infinity;
|
|
5971
|
-
for (const node of plan.nodes) {
|
|
5972
|
-
minX = Math.min(minX, node.x);
|
|
5973
|
-
minY = Math.min(minY, node.y);
|
|
5974
|
-
maxX = Math.max(maxX, node.x + node.width);
|
|
5975
|
-
maxY = Math.max(maxY, node.y + node.height);
|
|
5976
|
-
}
|
|
5977
|
-
for (const gb of plan.groupBoundaries ?? []) {
|
|
5978
|
-
minX = Math.min(minX, gb.x);
|
|
5979
|
-
minY = Math.min(minY, gb.y);
|
|
5980
|
-
maxX = Math.max(maxX, gb.x + gb.width);
|
|
5981
|
-
maxY = Math.max(maxY, gb.y + gb.height);
|
|
5982
|
-
}
|
|
5983
|
-
for (const bus of plan.treeBuses ?? []) {
|
|
5984
|
-
minX = Math.min(minX, bus.parentX, ...bus.childXs.length ? bus.childXs : [bus.parentX]);
|
|
5985
|
-
minY = Math.min(minY, bus.parentY, bus.branchY, bus.childY);
|
|
5986
|
-
maxX = Math.max(maxX, bus.parentX, ...bus.childXs.length ? bus.childXs : [bus.parentX]);
|
|
5987
|
-
maxY = Math.max(maxY, bus.parentY, bus.branchY, bus.childY);
|
|
5988
|
-
}
|
|
5989
|
-
if (plan.title) {
|
|
5990
|
-
minY = Math.min(minY, 20);
|
|
5991
|
-
}
|
|
5992
|
-
const pad = 36;
|
|
5993
|
-
minX = Math.max(0, minX - pad);
|
|
5994
|
-
minY = Math.max(0, minY - pad);
|
|
5995
|
-
maxX = Math.min(plan.meta.width, maxX + pad);
|
|
5996
|
-
maxY = Math.min(plan.meta.height, maxY + pad);
|
|
5997
|
-
const width = Math.max(maxX - minX, 200);
|
|
5998
|
-
const height = Math.max(maxY - minY, 140);
|
|
5999
|
-
return { minX, minY, maxX, maxY, width, height };
|
|
6125
|
+
return computeDiagramContentBounds(plan);
|
|
6000
6126
|
}
|
|
6001
6127
|
function scaleScene() {
|
|
6002
6128
|
const isBrowserLayout = (viewport.clientWidth || container.clientWidth || 0) > 0;
|
|
@@ -6011,9 +6137,14 @@ function createDiagram(opts) {
|
|
|
6011
6137
|
return;
|
|
6012
6138
|
}
|
|
6013
6139
|
const vWidth = viewport.clientWidth || container.clientWidth || plan.meta.width;
|
|
6014
|
-
const
|
|
6015
|
-
const
|
|
6016
|
-
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;
|
|
6017
6148
|
fitScale = Math.min(canvasScaleX, canvasScaleY);
|
|
6018
6149
|
if (!Number.isFinite(fitScale) || fitScale <= 0) fitScale = 1;
|
|
6019
6150
|
const scaledWidth = plan.meta.width * fitScale;
|
|
@@ -7045,9 +7176,9 @@ function createDiagram(opts) {
|
|
|
7045
7176
|
ensureFooter().insertBefore(toolbar, badge);
|
|
7046
7177
|
syncControls();
|
|
7047
7178
|
}
|
|
7048
|
-
viewport.style.cursor = interactiveViewport ? "grab" : "pointer";
|
|
7179
|
+
viewport.style.cursor = interactiveViewport ? "grab" : clickToPlay ? "pointer" : "default";
|
|
7049
7180
|
if (interactiveViewport) {
|
|
7050
|
-
viewport.style.touchAction = "
|
|
7181
|
+
viewport.style.touchAction = "pan-y";
|
|
7051
7182
|
if (allowZoom) viewport.addEventListener("wheel", handleViewportWheel, { passive: false });
|
|
7052
7183
|
if (allowPan) {
|
|
7053
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",
|