@vpxa/aikit 0.1.359 → 0.1.361
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 +442 -442
- package/package.json +3 -1
- package/packages/analyzers/dist/index.d.ts +1 -1
- package/packages/claude-desktop/dist/manifest.json +31 -0
- package/packages/claude-desktop/dist/mcp-source.json +16 -0
- package/packages/cli/dist/index.js +14 -14
- package/packages/cli/dist/init-JfM6gnAO.js +7 -0
- package/packages/cli/dist/mcp-entry.json +8 -0
- package/packages/cli/dist/{templates-d2UQHjpi.js → templates-CNDa9H4e.js} +25 -25
- package/packages/core/dist/index.d.ts +46 -3
- package/packages/core/dist/index.js +1 -1
- package/packages/flows/dist/index.d.ts +1 -1
- package/packages/flows/dist/index.js +1 -1
- package/packages/present/dist/annotation-layer.js +10 -10
- package/packages/server/dist/bin.js +1 -1
- package/packages/server/dist/config-B4klhHVp.js +2 -0
- package/packages/server/dist/config-D3rRPB9X.js +1 -0
- package/packages/server/dist/index.js +1 -1
- package/packages/server/dist/observations-CfglxBMB.js +6 -0
- package/packages/server/dist/observations-CrQU_HVm.js +5 -0
- package/packages/server/dist/prelude-BIJWSWyX.js +2 -0
- package/packages/server/dist/prelude-Dxc3G0Q2.js +1 -0
- package/packages/server/dist/routes-Ct7q5jrL.js +6 -0
- package/packages/server/dist/routes-DsSm9ea0.js +5 -0
- package/packages/server/dist/sampling-BX1qQuXx.js +2 -0
- package/packages/server/dist/sampling-QHtj6UuO.js +1 -0
- package/packages/server/dist/{server-CICqmfQ_.js → server-CiPwrtSl.js} +171 -171
- package/packages/server/dist/{server-BZVPmRGV.js → server-e0mFUKvp.js} +172 -170
- package/packages/server/dist/{server-http-CPU9_eVT.js → server-http-B3dZd6bx.js} +1 -1
- package/packages/server/dist/{server-http-D3DK1H19.js → server-http-CzScS-EZ.js} +1 -1
- package/packages/server/dist/{server-stdio-BRKxFWyO.js → server-stdio-COkJ2pX9.js} +1 -1
- package/packages/server/dist/{server-stdio-l8I0RW4l.js → server-stdio-DmsOjBSR.js} +1 -1
- package/packages/server/viewers/architecture-static.html +794 -794
- package/packages/server/viewers/report-template.html +11 -11
- package/packages/server/viewers/tour-viewer.html +26 -26
- package/packages/settings-ui/dist/index.html +12 -12
- package/packages/tools/dist/index.d.ts +109 -14
- package/packages/tools/dist/index.js +118 -98
- package/scaffold/definitions/mcp-entry.json +1 -1
- package/scaffold/dist/adapters/_shared.mjs +7 -6
- package/scaffold/dist/adapters/claude-code.mjs +7 -7
- package/scaffold/dist/adapters/claude-desktop.mjs +7 -0
- package/scaffold/dist/adapters/copilot.mjs +1 -1
- package/scaffold/dist/adapters/gemini.mjs +6 -6
- package/scaffold/dist/adapters/hermes-agent.mjs +1 -1
- package/scaffold/dist/adapters/hermes.mjs +5 -5
- package/scaffold/dist/adapters/hooks.mjs +1 -1
- package/scaffold/dist/adapters/opencode.mjs +7 -7
- package/scaffold/dist/adapters/zed.mjs +1 -1
- package/scaffold/dist/definitions/exec-hooks.mjs +1 -1
- package/scaffold/dist/definitions/flows.mjs +40 -162
- package/scaffold/dist/definitions/mcp-entry.json +1 -1
- package/scaffold/dist/definitions/platform-capabilities.mjs +1 -0
- package/scaffold/dist/definitions/protocols.mjs +22 -19
- package/scaffold/dist/definitions/skills/adr-skill.mjs +1 -1
- package/scaffold/dist/definitions/skills/docs.mjs +51 -1
- package/scaffold/dist/definitions/skills/lesson-learned.mjs +21 -0
- package/scaffold/vitest.config.mjs +1 -0
- package/packages/cli/dist/init-Cvys5TD4.js +0 -7
- package/packages/server/dist/config-4M54ZAT8.js +0 -2
- package/packages/server/dist/config-BXd38nVn.js +0 -1
- package/packages/server/dist/prelude-CfXBHLpw.js +0 -1
- package/packages/server/dist/prelude-D33q42vQ.js +0 -2
- package/packages/server/dist/routes-9KnBpwfe.js +0 -6
- package/packages/server/dist/routes-B8hTXXR8.js +0 -5
- package/packages/server/dist/sampling-Cs9MoNYX.js +0 -2
- package/packages/server/dist/sampling-DFogBKrL.js +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en" data-theme="auto">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>AI Kit - Architecture Static Viewer</title>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" data-theme="auto">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>AI Kit - Architecture Static Viewer</title>
|
|
7
7
|
<style id="aikit-dt-tokens">
|
|
8
8
|
:root {
|
|
9
9
|
--dt-bg-canvas: #0c0c0f;
|
|
@@ -248,791 +248,791 @@
|
|
|
248
248
|
--dt-group-fill: rgba(240, 239, 232, 0.32);
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
-
</style>
|
|
252
|
-
|
|
253
|
-
<style>
|
|
254
|
-
* {
|
|
255
|
-
box-sizing: border-box;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
html,
|
|
259
|
-
body {
|
|
260
|
-
height: 100%;
|
|
261
|
-
margin: 0;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
body {
|
|
265
|
-
font-family: var(--dt-font-sans);
|
|
266
|
-
color: var(--dt-text-primary);
|
|
267
|
-
background:
|
|
268
|
-
var(--dt-bg-gradient),
|
|
269
|
-
var(--dt-bg-primary);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
.shell {
|
|
273
|
-
min-height: 100%;
|
|
274
|
-
display: grid;
|
|
275
|
-
grid-template-rows: auto 1fr;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
.toolbar {
|
|
279
|
-
position: sticky;
|
|
280
|
-
top: 0;
|
|
281
|
-
z-index: 2;
|
|
282
|
-
display: flex;
|
|
283
|
-
align-items: center;
|
|
284
|
-
justify-content: space-between;
|
|
285
|
-
gap: 1rem;
|
|
286
|
-
padding: 1rem 1.25rem;
|
|
287
|
-
border-bottom: 1px solid var(--dt-border-default);
|
|
288
|
-
background: var(--dt-toolbar-bg);
|
|
289
|
-
backdrop-filter: blur(16px);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
.title h1 {
|
|
293
|
-
margin: 0;
|
|
294
|
-
font-size: 1rem;
|
|
295
|
-
font-weight: 700;
|
|
296
|
-
letter-spacing: 0.02em;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
.title p {
|
|
300
|
-
margin: 0.2rem 0 0;
|
|
301
|
-
font-size: 0.82rem;
|
|
302
|
-
color: var(--dt-text-secondary);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
.actions {
|
|
306
|
-
display: flex;
|
|
307
|
-
flex-wrap: wrap;
|
|
308
|
-
justify-content: flex-end;
|
|
309
|
-
gap: 0.6rem;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
button {
|
|
313
|
-
appearance: none;
|
|
314
|
-
border: 1px solid var(--dt-border-default);
|
|
315
|
-
background: var(--dt-button-bg);
|
|
316
|
-
color: var(--dt-text-primary);
|
|
317
|
-
border-radius: 999px;
|
|
318
|
-
padding: 0.7rem 1rem;
|
|
319
|
-
font: inherit;
|
|
320
|
-
cursor: pointer;
|
|
321
|
-
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
button:hover {
|
|
325
|
-
background: var(--dt-button-hover);
|
|
326
|
-
transform: translateY(-1px);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
.stage {
|
|
330
|
-
padding: 1rem;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
.canvas-shell {
|
|
334
|
-
position: relative;
|
|
335
|
-
min-height: calc(100vh - 5.5rem);
|
|
336
|
-
border: 1px solid var(--dt-border-default);
|
|
337
|
-
border-radius: 24px;
|
|
338
|
-
background:
|
|
339
|
-
linear-gradient(var(--dt-bg-tertiary) 1px, transparent 1px),
|
|
340
|
-
linear-gradient(90deg, var(--dt-bg-tertiary) 1px, transparent 1px),
|
|
341
|
-
var(--dt-panel-bg);
|
|
342
|
-
background-size: 40px 40px, 40px 40px, 100% 100%;
|
|
343
|
-
overflow: hidden;
|
|
344
|
-
box-shadow: 0 24px 60px var(--dt-shadow-lg);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
svg {
|
|
348
|
-
display: block;
|
|
349
|
-
width: 100%;
|
|
350
|
-
height: min(78vh, 980px);
|
|
351
|
-
min-height: 480px;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
.empty-state {
|
|
355
|
-
position: absolute;
|
|
356
|
-
inset: 0;
|
|
357
|
-
display: none;
|
|
358
|
-
place-items: center;
|
|
359
|
-
padding: 2rem;
|
|
360
|
-
text-align: center;
|
|
361
|
-
color: var(--dt-text-secondary);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
.empty-state.is-visible {
|
|
365
|
-
display: grid;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
.empty-state strong {
|
|
369
|
-
display: block;
|
|
370
|
-
margin-bottom: 0.4rem;
|
|
371
|
-
color: var(--dt-text-primary);
|
|
372
|
-
font-size: 1rem;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
.badge {
|
|
376
|
-
position: fixed;
|
|
377
|
-
right: 1rem;
|
|
378
|
-
bottom: 1rem;
|
|
379
|
-
z-index: 3;
|
|
380
|
-
display: inline-flex;
|
|
381
|
-
align-items: center;
|
|
382
|
-
gap: 0.55rem;
|
|
383
|
-
padding: 0.55rem 0.8rem;
|
|
384
|
-
border: 1px solid var(--dt-border-default);
|
|
385
|
-
border-radius: 999px;
|
|
386
|
-
background: var(--dt-badge-bg);
|
|
387
|
-
color: var(--dt-text-secondary);
|
|
388
|
-
backdrop-filter: blur(14px);
|
|
389
|
-
font-size: 0.74rem;
|
|
390
|
-
letter-spacing: 0.04em;
|
|
391
|
-
text-transform: uppercase;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
.badge-mark {
|
|
395
|
-
width: 0.55rem;
|
|
396
|
-
height: 0.55rem;
|
|
397
|
-
border-radius: 999px;
|
|
398
|
-
background: var(--dt-accent-fg);
|
|
399
|
-
box-shadow: 0 0 0 0.18rem rgba(6, 182, 212, 0.2);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
.sr-only {
|
|
403
|
-
position: absolute;
|
|
404
|
-
width: 1px;
|
|
405
|
-
height: 1px;
|
|
406
|
-
padding: 0;
|
|
407
|
-
margin: -1px;
|
|
408
|
-
overflow: hidden;
|
|
409
|
-
clip: rect(0, 0, 0, 0);
|
|
410
|
-
white-space: nowrap;
|
|
411
|
-
border: 0;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
@media (max-width: 720px) {
|
|
415
|
-
.toolbar {
|
|
416
|
-
align-items: flex-start;
|
|
417
|
-
flex-direction: column;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
.actions {
|
|
421
|
-
width: 100%;
|
|
422
|
-
justify-content: flex-start;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
.stage {
|
|
426
|
-
padding: 0.75rem;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
svg {
|
|
430
|
-
min-height: 420px;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
</style>
|
|
434
|
-
</head>
|
|
435
|
-
<body>
|
|
436
|
-
<div class="shell">
|
|
437
|
-
<header class="toolbar">
|
|
438
|
-
<div class="title">
|
|
439
|
-
<h1>Architecture Diagram</h1>
|
|
440
|
-
<p>Pure SVG C4-style renderer for inline lightweight mode.</p>
|
|
441
|
-
</div>
|
|
442
|
-
<div class="actions">
|
|
443
|
-
<button id="theme-button" type="button">Theme: Auto</button>
|
|
444
|
-
|
|
445
|
-
</div>
|
|
446
|
-
</header>
|
|
447
|
-
<main class="stage">
|
|
448
|
-
<div class="canvas-shell">
|
|
449
|
-
<div class="empty-state" id="empty-state" aria-live="polite"></div>
|
|
450
|
-
<svg id="diagram" role="img" aria-labelledby="diagram-title diagram-description"></svg>
|
|
451
|
-
</div>
|
|
452
|
-
</main>
|
|
453
|
-
</div>
|
|
454
|
-
<div class="badge"><span class="badge-mark"></span>AI Kit static viewer</div>
|
|
455
|
-
<script type="application/json" id="diagram-data">{}</script>
|
|
456
|
-
<script>
|
|
457
|
-
(() => {
|
|
458
|
-
const svgNs = 'http://www.w3.org/2000/svg';
|
|
459
|
-
const root = document.documentElement;
|
|
460
|
-
const svg = document.getElementById('diagram');
|
|
461
|
-
const emptyState = document.getElementById('empty-state');
|
|
462
|
-
const themeButton = document.getElementById('theme-button');
|
|
463
|
-
const themes = ['auto', 'dark', 'light'];
|
|
464
|
-
const typeVars = {
|
|
465
|
-
person: '--dt-accent-fg',
|
|
466
|
-
system: '--dt-success-fg',
|
|
467
|
-
container: '--dt-purple-fg',
|
|
468
|
-
component: '--dt-warning-fg',
|
|
469
|
-
external: '--dt-text-tertiary',
|
|
470
|
-
database: '--dt-accent-fg',
|
|
471
|
-
queue: '--dt-warning-fg',
|
|
472
|
-
boundary: '--dt-text-tertiary',
|
|
473
|
-
};
|
|
474
|
-
const leafSize = { width: 248, height: 132 };
|
|
475
|
-
const groupInset = { top: 62, right: 26, bottom: 26, left: 26, gap: 24 };
|
|
476
|
-
const rootGap = 52;
|
|
477
|
-
const canvasPadding = 48;
|
|
478
|
-
const monoFont = (getComputedStyle(document.documentElement).getPropertyValue('--dt-font-mono').trim()) || '"JetBrains Mono", "SFMono-Regular", Consolas, ui-monospace, monospace';
|
|
479
|
-
|
|
480
|
-
function node(tag, attributes, text) {
|
|
481
|
-
const element = document.createElementNS(svgNs, tag);
|
|
482
|
-
if (attributes) {
|
|
483
|
-
Object.entries(attributes).forEach(([name, value]) => {
|
|
484
|
-
if (value !== undefined && value !== null) {
|
|
485
|
-
element.setAttribute(name, String(value));
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
if (text !== undefined) {
|
|
490
|
-
element.textContent = text;
|
|
491
|
-
}
|
|
492
|
-
return element;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
function wrapText(value, maxChars, maxLines) {
|
|
496
|
-
const words = String(value || '').trim().split(/\s+/).filter(Boolean);
|
|
497
|
-
if (!words.length) {
|
|
498
|
-
return [];
|
|
499
|
-
}
|
|
500
|
-
const lines = [];
|
|
501
|
-
let current = '';
|
|
502
|
-
for (const word of words) {
|
|
503
|
-
const next = current ? current + ' ' + word : word;
|
|
504
|
-
if (next.length > maxChars && current) {
|
|
505
|
-
lines.push(current);
|
|
506
|
-
current = word;
|
|
507
|
-
} else {
|
|
508
|
-
current = next;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
if (current) {
|
|
512
|
-
lines.push(current);
|
|
513
|
-
}
|
|
514
|
-
if (lines.length <= maxLines) {
|
|
515
|
-
return lines;
|
|
516
|
-
}
|
|
517
|
-
const clipped = lines.slice(0, maxLines);
|
|
518
|
-
clipped[maxLines - 1] = clipped[maxLines - 1].replace(/[\s.]+$/, '') + '...';
|
|
519
|
-
return clipped;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
function cssValue(name) {
|
|
523
|
-
return getComputedStyle(root).getPropertyValue(name).trim();
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
function rgba(hex, alpha) {
|
|
527
|
-
const cleaned = String(hex || '').replace('#', '').trim();
|
|
528
|
-
const value = cleaned.length === 3
|
|
529
|
-
? cleaned.split('').map((char) => char + char).join('')
|
|
530
|
-
: cleaned;
|
|
531
|
-
const number = Number.parseInt(value, 16);
|
|
532
|
-
const red = (number >> 16) & 255;
|
|
533
|
-
const green = (number >> 8) & 255;
|
|
534
|
-
const blue = number & 255;
|
|
535
|
-
return 'rgba(' + red + ', ' + green + ', ' + blue + ', ' + alpha + ')';
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
function accentFor(type) {
|
|
539
|
-
return cssValue(typeVars[type] || '--dt-text-tertiary');
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
function parseData() {
|
|
543
|
-
const source = document.getElementById('diagram-data');
|
|
544
|
-
if (!source) {
|
|
545
|
-
return {};
|
|
546
|
-
}
|
|
547
|
-
try {
|
|
548
|
-
return JSON.parse(source.textContent || '{}');
|
|
549
|
-
} catch (error) {
|
|
550
|
-
showEmpty('Invalid diagram JSON', String(error && error.message ? error.message : error));
|
|
551
|
-
return null;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
function showEmpty(title, message) {
|
|
556
|
-
emptyState.classList.add('is-visible');
|
|
557
|
-
emptyState.innerHTML = '<div><strong>' + escapeHtml(title) + '</strong><span>' + escapeHtml(message) + '</span></div>';
|
|
558
|
-
svg.innerHTML = '';
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
function hideEmpty() {
|
|
562
|
-
emptyState.classList.remove('is-visible');
|
|
563
|
-
emptyState.textContent = '';
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
function escapeHtml(value) {
|
|
567
|
-
return String(value)
|
|
568
|
-
.replace(/&/g, '&')
|
|
569
|
-
.replace(/</g, '<')
|
|
570
|
-
.replace(/>/g, '>')
|
|
571
|
-
.replace(/"/g, '"')
|
|
572
|
-
.replace(/'/g, ''');
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
function buildModel(raw) {
|
|
576
|
-
const nodes = Array.isArray(raw && raw.nodes) ? raw.nodes : [];
|
|
577
|
-
const edges = Array.isArray(raw && raw.edges) ? raw.edges : [];
|
|
578
|
-
const map = new Map();
|
|
579
|
-
const children = new Map();
|
|
580
|
-
|
|
581
|
-
nodes.forEach((item) => {
|
|
582
|
-
map.set(item.id, Object.assign({ type: 'container' }, item));
|
|
583
|
-
children.set(item.id, []);
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
nodes.forEach((item) => {
|
|
587
|
-
if (item.parent && children.has(item.parent)) {
|
|
588
|
-
children.get(item.parent).push(item.id);
|
|
589
|
-
}
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
const roots = nodes
|
|
593
|
-
.filter((item) => !item.parent || !map.has(item.parent))
|
|
594
|
-
.map((item) => item.id);
|
|
595
|
-
|
|
596
|
-
return { nodes, edges, map, children, roots };
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
function measureEntity(id, model, cache) {
|
|
600
|
-
if (cache.has(id)) {
|
|
601
|
-
return cache.get(id);
|
|
602
|
-
}
|
|
603
|
-
const childIds = model.children.get(id) || [];
|
|
604
|
-
if (!childIds.length) {
|
|
605
|
-
const measuredLeaf = Object.assign({ id, cols: 1, rows: 1, childIds: [] }, leafSize, { isGroup: false });
|
|
606
|
-
cache.set(id, measuredLeaf);
|
|
607
|
-
return measuredLeaf;
|
|
608
|
-
}
|
|
609
|
-
const measuredChildren = childIds.map((childId) => measureEntity(childId, model, cache));
|
|
610
|
-
const cols = childIds.length <= 2 ? Math.max(1, childIds.length) : Math.ceil(Math.sqrt(childIds.length));
|
|
611
|
-
let rowWidth = 0;
|
|
612
|
-
let rowHeight = 0;
|
|
613
|
-
let totalHeight = 0;
|
|
614
|
-
let maxWidth = 0;
|
|
615
|
-
let column = 0;
|
|
616
|
-
|
|
617
|
-
measuredChildren.forEach((child, index) => {
|
|
618
|
-
rowWidth += child.width;
|
|
619
|
-
if (column > 0) {
|
|
620
|
-
rowWidth += groupInset.gap;
|
|
621
|
-
}
|
|
622
|
-
rowHeight = Math.max(rowHeight, child.height);
|
|
623
|
-
column += 1;
|
|
624
|
-
const endRow = column === cols || index === measuredChildren.length - 1;
|
|
625
|
-
if (endRow) {
|
|
626
|
-
maxWidth = Math.max(maxWidth, rowWidth);
|
|
627
|
-
totalHeight += rowHeight;
|
|
628
|
-
if (index !== measuredChildren.length - 1) {
|
|
629
|
-
totalHeight += groupInset.gap;
|
|
630
|
-
}
|
|
631
|
-
rowWidth = 0;
|
|
632
|
-
rowHeight = 0;
|
|
633
|
-
column = 0;
|
|
634
|
-
}
|
|
635
|
-
});
|
|
636
|
-
|
|
637
|
-
const measuredGroup = {
|
|
638
|
-
id,
|
|
639
|
-
isGroup: true,
|
|
640
|
-
childIds,
|
|
641
|
-
cols,
|
|
642
|
-
width: Math.max(312, groupInset.left + maxWidth + groupInset.right),
|
|
643
|
-
height: Math.max(220, groupInset.top + totalHeight + groupInset.bottom),
|
|
644
|
-
};
|
|
645
|
-
cache.set(id, measuredGroup);
|
|
646
|
-
return measuredGroup;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
function placeEntity(id, x, y, model, cache, positions) {
|
|
650
|
-
const measured = cache.get(id);
|
|
651
|
-
positions.set(id, { x, y, width: measured.width, height: measured.height });
|
|
652
|
-
if (!measured.isGroup) {
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
let cursorX = x + groupInset.left;
|
|
656
|
-
let cursorY = y + groupInset.top;
|
|
657
|
-
let rowHeight = 0;
|
|
658
|
-
let column = 0;
|
|
659
|
-
|
|
660
|
-
measured.childIds.forEach((childId) => {
|
|
661
|
-
const child = cache.get(childId);
|
|
662
|
-
if (column === measured.cols) {
|
|
663
|
-
cursorX = x + groupInset.left;
|
|
664
|
-
cursorY += rowHeight + groupInset.gap;
|
|
665
|
-
rowHeight = 0;
|
|
666
|
-
column = 0;
|
|
667
|
-
}
|
|
668
|
-
placeEntity(childId, cursorX, cursorY, model, cache, positions);
|
|
669
|
-
cursorX += child.width + groupInset.gap;
|
|
670
|
-
rowHeight = Math.max(rowHeight, child.height);
|
|
671
|
-
column += 1;
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
function layout(model) {
|
|
676
|
-
const cache = new Map();
|
|
677
|
-
const positions = new Map();
|
|
678
|
-
const roots = model.roots.map((id) => measureEntity(id, model, cache));
|
|
679
|
-
const cols = roots.length <= 2 ? Math.max(1, roots.length) : Math.ceil(Math.sqrt(roots.length));
|
|
680
|
-
let cursorX = canvasPadding;
|
|
681
|
-
let cursorY = canvasPadding;
|
|
682
|
-
let rowHeight = 0;
|
|
683
|
-
let column = 0;
|
|
684
|
-
let maxRight = 0;
|
|
685
|
-
let maxBottom = 0;
|
|
686
|
-
|
|
687
|
-
model.roots.forEach((id) => {
|
|
688
|
-
const measured = cache.get(id);
|
|
689
|
-
if (column === cols) {
|
|
690
|
-
cursorX = canvasPadding;
|
|
691
|
-
cursorY += rowHeight + rootGap;
|
|
692
|
-
rowHeight = 0;
|
|
693
|
-
column = 0;
|
|
694
|
-
}
|
|
695
|
-
placeEntity(id, cursorX, cursorY, model, cache, positions);
|
|
696
|
-
maxRight = Math.max(maxRight, cursorX + measured.width);
|
|
697
|
-
maxBottom = Math.max(maxBottom, cursorY + measured.height);
|
|
698
|
-
rowHeight = Math.max(rowHeight, measured.height);
|
|
699
|
-
cursorX += measured.width + rootGap;
|
|
700
|
-
column += 1;
|
|
701
|
-
});
|
|
702
|
-
|
|
703
|
-
return {
|
|
704
|
-
positions,
|
|
705
|
-
width: Math.max(960, maxRight + canvasPadding),
|
|
706
|
-
height: Math.max(640, maxBottom + canvasPadding),
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
function anchor(box, target) {
|
|
711
|
-
const centerX = box.x + box.width / 2;
|
|
712
|
-
const centerY = box.y + box.height / 2;
|
|
713
|
-
const targetX = target.x + target.width / 2;
|
|
714
|
-
const targetY = target.y + target.height / 2;
|
|
715
|
-
const dx = targetX - centerX;
|
|
716
|
-
const dy = targetY - centerY;
|
|
717
|
-
if (Math.abs(dx) > Math.abs(dy)) {
|
|
718
|
-
return {
|
|
719
|
-
x: dx > 0 ? box.x + box.width : box.x,
|
|
720
|
-
y: centerY,
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
return {
|
|
724
|
-
x: centerX,
|
|
725
|
-
y: dy > 0 ? box.y + box.height : box.y,
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
function edgePath(sourceBox, targetBox) {
|
|
730
|
-
const start = anchor(sourceBox, targetBox);
|
|
731
|
-
const end = anchor(targetBox, sourceBox);
|
|
732
|
-
const dx = Math.abs(end.x - start.x);
|
|
733
|
-
const dy = Math.abs(end.y - start.y);
|
|
734
|
-
const curve = Math.max(48, Math.min(160, Math.max(dx * 0.35, dy * 0.35)));
|
|
735
|
-
const c1x = start.x + (end.x >= start.x ? curve : -curve);
|
|
736
|
-
const c2x = end.x + (end.x >= start.x ? -curve : curve);
|
|
737
|
-
return {
|
|
738
|
-
d: 'M ' + start.x + ' ' + start.y + ' C ' + c1x + ' ' + start.y + ', ' + c2x + ' ' + end.y + ', ' + end.x + ' ' + end.y,
|
|
739
|
-
labelX: (start.x + end.x) / 2,
|
|
740
|
-
labelY: (start.y + end.y) / 2 - 10,
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
function renderDefs() {
|
|
745
|
-
const defs = node('defs');
|
|
746
|
-
|
|
747
|
-
const marker = node('marker', {
|
|
748
|
-
id: 'arrow',
|
|
749
|
-
viewBox: '0 0 10 10',
|
|
750
|
-
refX: 8,
|
|
751
|
-
refY: 5,
|
|
752
|
-
markerWidth: 7,
|
|
753
|
-
markerHeight: 7,
|
|
754
|
-
orient: 'auto-start-reverse',
|
|
755
|
-
});
|
|
756
|
-
marker.appendChild(node('path', {
|
|
757
|
-
d: 'M 0 0 L 10 5 L 0 10 z',
|
|
758
|
-
fill: cssValue('--dt-text-secondary'),
|
|
759
|
-
}));
|
|
760
|
-
defs.appendChild(marker);
|
|
761
|
-
|
|
762
|
-
const filter = node('filter', {
|
|
763
|
-
id: 'node-shadow',
|
|
764
|
-
x: '-20%',
|
|
765
|
-
y: '-20%',
|
|
766
|
-
width: '140%',
|
|
767
|
-
height: '140%',
|
|
768
|
-
});
|
|
769
|
-
filter.appendChild(node('feDropShadow', {
|
|
770
|
-
dx: 0,
|
|
771
|
-
dy: 12,
|
|
772
|
-
stdDeviation: 12,
|
|
773
|
-
'flood-color': cssValue('--dt-shadow-lg'),
|
|
774
|
-
}));
|
|
775
|
-
defs.appendChild(filter);
|
|
776
|
-
|
|
777
|
-
Object.keys(typeVars).forEach((type) => {
|
|
778
|
-
const color = accentFor(type);
|
|
779
|
-
const gradient = node('linearGradient', {
|
|
780
|
-
id: 'grad-' + type,
|
|
781
|
-
x1: '0%',
|
|
782
|
-
y1: '0%',
|
|
783
|
-
x2: '100%',
|
|
784
|
-
y2: '100%',
|
|
785
|
-
});
|
|
786
|
-
gradient.appendChild(node('stop', {
|
|
787
|
-
offset: '0%',
|
|
788
|
-
'stop-color': rgba(color, 0.24),
|
|
789
|
-
}));
|
|
790
|
-
gradient.appendChild(node('stop', {
|
|
791
|
-
offset: '100%',
|
|
792
|
-
'stop-color': rgba(color, 0.06),
|
|
793
|
-
}));
|
|
794
|
-
defs.appendChild(gradient);
|
|
795
|
-
});
|
|
796
|
-
|
|
797
|
-
return defs;
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
function renderTextBlock(group, lines, x, y, fontSize, color, fontWeight, lineHeight, anchorMode) {
|
|
801
|
-
lines.forEach((line, index) => {
|
|
802
|
-
group.appendChild(node('text', {
|
|
803
|
-
x,
|
|
804
|
-
y: y + index * lineHeight,
|
|
805
|
-
fill: color,
|
|
806
|
-
'font-size': fontSize,
|
|
807
|
-
'font-weight': fontWeight,
|
|
808
|
-
'text-anchor': anchorMode || 'start',
|
|
809
|
-
}, line));
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
function renderLabelBadge(group, text, x, y, color) {
|
|
814
|
-
const width = Math.max(52, text.length * 7 + 18);
|
|
815
|
-
group.appendChild(node('rect', {
|
|
816
|
-
x,
|
|
817
|
-
y,
|
|
818
|
-
width,
|
|
819
|
-
height: 22,
|
|
820
|
-
rx: 11,
|
|
821
|
-
fill: rgba(color, 0.18),
|
|
822
|
-
stroke: rgba(color, 0.35),
|
|
823
|
-
}));
|
|
824
|
-
group.appendChild(node('text', {
|
|
825
|
-
x: x + width / 2,
|
|
826
|
-
y: y + 15,
|
|
827
|
-
fill: color,
|
|
828
|
-
'font-size': 10,
|
|
829
|
-
'font-family': monoFont,
|
|
830
|
-
'font-weight': 700,
|
|
831
|
-
'letter-spacing': '0.08em',
|
|
832
|
-
'text-anchor': 'middle',
|
|
833
|
-
}, text.toUpperCase()));
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
function renderGroup(id, model, positions, groupLayer) {
|
|
837
|
-
const data = model.map.get(id);
|
|
838
|
-
const box = positions.get(id);
|
|
839
|
-
const color = accentFor(data.type);
|
|
840
|
-
const labelWidth = Math.max(120, String(data.label || data.id).length * 8 + 32);
|
|
841
|
-
|
|
842
|
-
groupLayer.appendChild(node('rect', {
|
|
843
|
-
x: box.x,
|
|
844
|
-
y: box.y,
|
|
845
|
-
width: box.width,
|
|
846
|
-
height: box.height,
|
|
847
|
-
rx: 24,
|
|
848
|
-
fill: cssValue('--dt-group-fill'),
|
|
849
|
-
stroke: color,
|
|
850
|
-
'stroke-width': 1.6,
|
|
851
|
-
'stroke-dasharray': '10 8',
|
|
852
|
-
}));
|
|
853
|
-
groupLayer.appendChild(node('rect', {
|
|
854
|
-
x: box.x + 16,
|
|
855
|
-
y: box.y - 14,
|
|
856
|
-
width: labelWidth,
|
|
857
|
-
height: 28,
|
|
858
|
-
rx: 14,
|
|
859
|
-
fill: cssValue('--dt-bg-primary'),
|
|
860
|
-
stroke: color,
|
|
861
|
-
}));
|
|
862
|
-
groupLayer.appendChild(node('text', {
|
|
863
|
-
x: box.x + 28,
|
|
864
|
-
y: box.y + 4,
|
|
865
|
-
fill: color,
|
|
866
|
-
'font-size': 11,
|
|
867
|
-
'font-family': monoFont,
|
|
868
|
-
'font-weight': 700,
|
|
869
|
-
'letter-spacing': '0.08em',
|
|
870
|
-
}, String(data.label || data.id).toUpperCase()));
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
function renderLeaf(id, model, positions, nodeLayer) {
|
|
874
|
-
const data = model.map.get(id);
|
|
875
|
-
const box = positions.get(id);
|
|
876
|
-
const color = accentFor(data.type);
|
|
877
|
-
const labelLines = wrapText(data.label || data.id, 20, 2);
|
|
878
|
-
const descLines = wrapText(data.description || '', 28, 2);
|
|
879
|
-
const group = node('g');
|
|
880
|
-
|
|
881
|
-
group.appendChild(node('rect', {
|
|
882
|
-
x: box.x,
|
|
883
|
-
y: box.y,
|
|
884
|
-
width: box.width,
|
|
885
|
-
height: box.height,
|
|
886
|
-
rx: 22,
|
|
887
|
-
fill: 'url(#grad-' + (typeVars[data.type] ? data.type : 'external') + ')',
|
|
888
|
-
stroke: color,
|
|
889
|
-
'stroke-width': 1.8,
|
|
890
|
-
filter: 'url(#node-shadow)',
|
|
891
|
-
}));
|
|
892
|
-
group.appendChild(node('rect', {
|
|
893
|
-
x: box.x + 1,
|
|
894
|
-
y: box.y + 1,
|
|
895
|
-
width: box.width - 2,
|
|
896
|
-
height: box.height - 2,
|
|
897
|
-
rx: 21,
|
|
898
|
-
fill: cssValue('--dt-node-fill'),
|
|
899
|
-
}));
|
|
900
|
-
group.appendChild(node('rect', {
|
|
901
|
-
x: box.x + 18,
|
|
902
|
-
y: box.y + 18,
|
|
903
|
-
width: 6,
|
|
904
|
-
height: box.height - 36,
|
|
905
|
-
rx: 3,
|
|
906
|
-
fill: color,
|
|
907
|
-
}));
|
|
908
|
-
renderLabelBadge(group, data.type || 'node', box.x + 30, box.y + 16, color);
|
|
909
|
-
renderTextBlock(group, labelLines, box.x + 30, box.y + 56, 19, cssValue('--dt-text-primary'), 700, 22, 'start');
|
|
910
|
-
if (descLines.length) {
|
|
911
|
-
renderTextBlock(group, descLines, box.x + 30, box.y + 88, 12, cssValue('--dt-text-secondary'), 500, 16, 'start');
|
|
912
|
-
}
|
|
913
|
-
if (data.technology) {
|
|
914
|
-
const techY = box.y + box.height - 34;
|
|
915
|
-
const techWidth = Math.min(box.width - 48, Math.max(78, String(data.technology).length * 7 + 22));
|
|
916
|
-
group.appendChild(node('rect', {
|
|
917
|
-
x: box.x + 30,
|
|
918
|
-
y: techY,
|
|
919
|
-
width: techWidth,
|
|
920
|
-
height: 22,
|
|
921
|
-
rx: 11,
|
|
922
|
-
fill: rgba(color, 0.14),
|
|
923
|
-
stroke: rgba(color, 0.32),
|
|
924
|
-
}));
|
|
925
|
-
group.appendChild(node('text', {
|
|
926
|
-
x: box.x + 41,
|
|
927
|
-
y: techY + 15,
|
|
928
|
-
fill: cssValue('--dt-text-primary'),
|
|
929
|
-
'font-size': 10.5,
|
|
930
|
-
'font-family': monoFont,
|
|
931
|
-
}, data.technology));
|
|
932
|
-
}
|
|
933
|
-
nodeLayer.appendChild(group);
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
function renderEdge(edge, positions, edgeLayer) {
|
|
937
|
-
const source = positions.get(edge.source);
|
|
938
|
-
const target = positions.get(edge.target);
|
|
939
|
-
if (!source || !target) {
|
|
940
|
-
return;
|
|
941
|
-
}
|
|
942
|
-
const route = edgePath(source, target);
|
|
943
|
-
edgeLayer.appendChild(node('path', {
|
|
944
|
-
d: route.d,
|
|
945
|
-
fill: 'none',
|
|
946
|
-
stroke: cssValue('--dt-text-secondary'),
|
|
947
|
-
'stroke-width': 2,
|
|
948
|
-
'stroke-linecap': 'round',
|
|
949
|
-
'stroke-linejoin': 'round',
|
|
950
|
-
'marker-end': 'url(#arrow)',
|
|
951
|
-
opacity: 0.86,
|
|
952
|
-
}));
|
|
953
|
-
if (edge.label) {
|
|
954
|
-
const width = Math.max(62, String(edge.label).length * 7 + 16);
|
|
955
|
-
edgeLayer.appendChild(node('rect', {
|
|
956
|
-
x: route.labelX - width / 2,
|
|
957
|
-
y: route.labelY - 14,
|
|
958
|
-
width,
|
|
959
|
-
height: 24,
|
|
960
|
-
rx: 12,
|
|
961
|
-
fill: cssValue('--dt-bg-primary'),
|
|
962
|
-
stroke: cssValue('--dt-border-default'),
|
|
963
|
-
}));
|
|
964
|
-
edgeLayer.appendChild(node('text', {
|
|
965
|
-
x: route.labelX,
|
|
966
|
-
y: route.labelY + 2,
|
|
967
|
-
fill: cssValue('--dt-text-secondary'),
|
|
968
|
-
'font-size': 10,
|
|
969
|
-
'font-family': monoFont,
|
|
970
|
-
'text-anchor': 'middle',
|
|
971
|
-
}, edge.label));
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
function render() {
|
|
976
|
-
const raw = parseData();
|
|
977
|
-
if (raw === null) {
|
|
978
|
-
return;
|
|
979
|
-
}
|
|
980
|
-
const model = buildModel(raw);
|
|
981
|
-
if (!model.nodes.length) {
|
|
982
|
-
showEmpty('No data provided', 'Populate #diagram-data with nodes and optional edges to render the diagram.');
|
|
983
|
-
return;
|
|
984
|
-
}
|
|
985
|
-
hideEmpty();
|
|
986
|
-
const { positions, width, height } = layout(model);
|
|
987
|
-
svg.innerHTML = '';
|
|
988
|
-
svg.setAttribute('viewBox', '0 0 ' + width + ' ' + height);
|
|
989
|
-
svg.setAttribute('aria-label', (raw.title || 'Architecture diagram') + ' with ' + model.nodes.length + ' nodes');
|
|
990
|
-
|
|
991
|
-
svg.appendChild(renderDefs());
|
|
992
|
-
|
|
993
|
-
const title = node('title', { id: 'diagram-title' }, raw.title || 'Architecture diagram');
|
|
994
|
-
const description = node('desc', { id: 'diagram-description' }, raw.description || 'Static architecture diagram rendered with SVG');
|
|
995
|
-
svg.appendChild(title);
|
|
996
|
-
svg.appendChild(description);
|
|
997
|
-
|
|
998
|
-
const edgeLayer = node('g', { 'aria-hidden': 'true' });
|
|
999
|
-
const groupLayer = node('g', { 'aria-hidden': 'true' });
|
|
1000
|
-
const nodeLayer = node('g');
|
|
1001
|
-
|
|
1002
|
-
(model.edges || []).forEach((edge) => renderEdge(edge, positions, edgeLayer));
|
|
1003
|
-
model.nodes.forEach((item) => {
|
|
1004
|
-
if ((model.children.get(item.id) || []).length) {
|
|
1005
|
-
renderGroup(item.id, model, positions, groupLayer);
|
|
1006
|
-
}
|
|
1007
|
-
});
|
|
1008
|
-
model.nodes.forEach((item) => {
|
|
1009
|
-
if (!(model.children.get(item.id) || []).length) {
|
|
1010
|
-
renderLeaf(item.id, model, positions, nodeLayer);
|
|
1011
|
-
}
|
|
1012
|
-
});
|
|
1013
|
-
|
|
1014
|
-
svg.appendChild(edgeLayer);
|
|
1015
|
-
svg.appendChild(groupLayer);
|
|
1016
|
-
svg.appendChild(nodeLayer);
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
function updateThemeButton() {
|
|
1020
|
-
const value = root.getAttribute('data-theme') || 'auto';
|
|
1021
|
-
themeButton.textContent = 'Theme: ' + value.charAt(0).toUpperCase() + value.slice(1);
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
function cycleTheme() {
|
|
1025
|
-
const current = root.getAttribute('data-theme') || 'auto';
|
|
1026
|
-
const next = themes[(themes.indexOf(current) + 1) % themes.length];
|
|
1027
|
-
root.setAttribute('data-theme', next);
|
|
1028
|
-
updateThemeButton();
|
|
1029
|
-
render();
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
themeButton.addEventListener('click', cycleTheme);
|
|
1033
|
-
updateThemeButton();
|
|
1034
|
-
render();
|
|
1035
|
-
})();
|
|
1036
|
-
</script>
|
|
1037
|
-
</body>
|
|
1038
|
-
</html>
|
|
251
|
+
</style>
|
|
252
|
+
|
|
253
|
+
<style>
|
|
254
|
+
* {
|
|
255
|
+
box-sizing: border-box;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
html,
|
|
259
|
+
body {
|
|
260
|
+
height: 100%;
|
|
261
|
+
margin: 0;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
body {
|
|
265
|
+
font-family: var(--dt-font-sans);
|
|
266
|
+
color: var(--dt-text-primary);
|
|
267
|
+
background:
|
|
268
|
+
var(--dt-bg-gradient),
|
|
269
|
+
var(--dt-bg-primary);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.shell {
|
|
273
|
+
min-height: 100%;
|
|
274
|
+
display: grid;
|
|
275
|
+
grid-template-rows: auto 1fr;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.toolbar {
|
|
279
|
+
position: sticky;
|
|
280
|
+
top: 0;
|
|
281
|
+
z-index: 2;
|
|
282
|
+
display: flex;
|
|
283
|
+
align-items: center;
|
|
284
|
+
justify-content: space-between;
|
|
285
|
+
gap: 1rem;
|
|
286
|
+
padding: 1rem 1.25rem;
|
|
287
|
+
border-bottom: 1px solid var(--dt-border-default);
|
|
288
|
+
background: var(--dt-toolbar-bg);
|
|
289
|
+
backdrop-filter: blur(16px);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.title h1 {
|
|
293
|
+
margin: 0;
|
|
294
|
+
font-size: 1rem;
|
|
295
|
+
font-weight: 700;
|
|
296
|
+
letter-spacing: 0.02em;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.title p {
|
|
300
|
+
margin: 0.2rem 0 0;
|
|
301
|
+
font-size: 0.82rem;
|
|
302
|
+
color: var(--dt-text-secondary);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
.actions {
|
|
306
|
+
display: flex;
|
|
307
|
+
flex-wrap: wrap;
|
|
308
|
+
justify-content: flex-end;
|
|
309
|
+
gap: 0.6rem;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
button {
|
|
313
|
+
appearance: none;
|
|
314
|
+
border: 1px solid var(--dt-border-default);
|
|
315
|
+
background: var(--dt-button-bg);
|
|
316
|
+
color: var(--dt-text-primary);
|
|
317
|
+
border-radius: 999px;
|
|
318
|
+
padding: 0.7rem 1rem;
|
|
319
|
+
font: inherit;
|
|
320
|
+
cursor: pointer;
|
|
321
|
+
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
button:hover {
|
|
325
|
+
background: var(--dt-button-hover);
|
|
326
|
+
transform: translateY(-1px);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.stage {
|
|
330
|
+
padding: 1rem;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
.canvas-shell {
|
|
334
|
+
position: relative;
|
|
335
|
+
min-height: calc(100vh - 5.5rem);
|
|
336
|
+
border: 1px solid var(--dt-border-default);
|
|
337
|
+
border-radius: 24px;
|
|
338
|
+
background:
|
|
339
|
+
linear-gradient(var(--dt-bg-tertiary) 1px, transparent 1px),
|
|
340
|
+
linear-gradient(90deg, var(--dt-bg-tertiary) 1px, transparent 1px),
|
|
341
|
+
var(--dt-panel-bg);
|
|
342
|
+
background-size: 40px 40px, 40px 40px, 100% 100%;
|
|
343
|
+
overflow: hidden;
|
|
344
|
+
box-shadow: 0 24px 60px var(--dt-shadow-lg);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
svg {
|
|
348
|
+
display: block;
|
|
349
|
+
width: 100%;
|
|
350
|
+
height: min(78vh, 980px);
|
|
351
|
+
min-height: 480px;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.empty-state {
|
|
355
|
+
position: absolute;
|
|
356
|
+
inset: 0;
|
|
357
|
+
display: none;
|
|
358
|
+
place-items: center;
|
|
359
|
+
padding: 2rem;
|
|
360
|
+
text-align: center;
|
|
361
|
+
color: var(--dt-text-secondary);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.empty-state.is-visible {
|
|
365
|
+
display: grid;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.empty-state strong {
|
|
369
|
+
display: block;
|
|
370
|
+
margin-bottom: 0.4rem;
|
|
371
|
+
color: var(--dt-text-primary);
|
|
372
|
+
font-size: 1rem;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
.badge {
|
|
376
|
+
position: fixed;
|
|
377
|
+
right: 1rem;
|
|
378
|
+
bottom: 1rem;
|
|
379
|
+
z-index: 3;
|
|
380
|
+
display: inline-flex;
|
|
381
|
+
align-items: center;
|
|
382
|
+
gap: 0.55rem;
|
|
383
|
+
padding: 0.55rem 0.8rem;
|
|
384
|
+
border: 1px solid var(--dt-border-default);
|
|
385
|
+
border-radius: 999px;
|
|
386
|
+
background: var(--dt-badge-bg);
|
|
387
|
+
color: var(--dt-text-secondary);
|
|
388
|
+
backdrop-filter: blur(14px);
|
|
389
|
+
font-size: 0.74rem;
|
|
390
|
+
letter-spacing: 0.04em;
|
|
391
|
+
text-transform: uppercase;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
.badge-mark {
|
|
395
|
+
width: 0.55rem;
|
|
396
|
+
height: 0.55rem;
|
|
397
|
+
border-radius: 999px;
|
|
398
|
+
background: var(--dt-accent-fg);
|
|
399
|
+
box-shadow: 0 0 0 0.18rem rgba(6, 182, 212, 0.2);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
.sr-only {
|
|
403
|
+
position: absolute;
|
|
404
|
+
width: 1px;
|
|
405
|
+
height: 1px;
|
|
406
|
+
padding: 0;
|
|
407
|
+
margin: -1px;
|
|
408
|
+
overflow: hidden;
|
|
409
|
+
clip: rect(0, 0, 0, 0);
|
|
410
|
+
white-space: nowrap;
|
|
411
|
+
border: 0;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
@media (max-width: 720px) {
|
|
415
|
+
.toolbar {
|
|
416
|
+
align-items: flex-start;
|
|
417
|
+
flex-direction: column;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
.actions {
|
|
421
|
+
width: 100%;
|
|
422
|
+
justify-content: flex-start;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
.stage {
|
|
426
|
+
padding: 0.75rem;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
svg {
|
|
430
|
+
min-height: 420px;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
</style>
|
|
434
|
+
</head>
|
|
435
|
+
<body>
|
|
436
|
+
<div class="shell">
|
|
437
|
+
<header class="toolbar">
|
|
438
|
+
<div class="title">
|
|
439
|
+
<h1>Architecture Diagram</h1>
|
|
440
|
+
<p>Pure SVG C4-style renderer for inline lightweight mode.</p>
|
|
441
|
+
</div>
|
|
442
|
+
<div class="actions">
|
|
443
|
+
<button id="theme-button" type="button">Theme: Auto</button>
|
|
444
|
+
|
|
445
|
+
</div>
|
|
446
|
+
</header>
|
|
447
|
+
<main class="stage">
|
|
448
|
+
<div class="canvas-shell">
|
|
449
|
+
<div class="empty-state" id="empty-state" aria-live="polite"></div>
|
|
450
|
+
<svg id="diagram" role="img" aria-labelledby="diagram-title diagram-description"></svg>
|
|
451
|
+
</div>
|
|
452
|
+
</main>
|
|
453
|
+
</div>
|
|
454
|
+
<div class="badge"><span class="badge-mark"></span>AI Kit static viewer</div>
|
|
455
|
+
<script type="application/json" id="diagram-data">{}</script>
|
|
456
|
+
<script>
|
|
457
|
+
(() => {
|
|
458
|
+
const svgNs = 'http://www.w3.org/2000/svg';
|
|
459
|
+
const root = document.documentElement;
|
|
460
|
+
const svg = document.getElementById('diagram');
|
|
461
|
+
const emptyState = document.getElementById('empty-state');
|
|
462
|
+
const themeButton = document.getElementById('theme-button');
|
|
463
|
+
const themes = ['auto', 'dark', 'light'];
|
|
464
|
+
const typeVars = {
|
|
465
|
+
person: '--dt-accent-fg',
|
|
466
|
+
system: '--dt-success-fg',
|
|
467
|
+
container: '--dt-purple-fg',
|
|
468
|
+
component: '--dt-warning-fg',
|
|
469
|
+
external: '--dt-text-tertiary',
|
|
470
|
+
database: '--dt-accent-fg',
|
|
471
|
+
queue: '--dt-warning-fg',
|
|
472
|
+
boundary: '--dt-text-tertiary',
|
|
473
|
+
};
|
|
474
|
+
const leafSize = { width: 248, height: 132 };
|
|
475
|
+
const groupInset = { top: 62, right: 26, bottom: 26, left: 26, gap: 24 };
|
|
476
|
+
const rootGap = 52;
|
|
477
|
+
const canvasPadding = 48;
|
|
478
|
+
const monoFont = (getComputedStyle(document.documentElement).getPropertyValue('--dt-font-mono').trim()) || '"JetBrains Mono", "SFMono-Regular", Consolas, ui-monospace, monospace';
|
|
479
|
+
|
|
480
|
+
function node(tag, attributes, text) {
|
|
481
|
+
const element = document.createElementNS(svgNs, tag);
|
|
482
|
+
if (attributes) {
|
|
483
|
+
Object.entries(attributes).forEach(([name, value]) => {
|
|
484
|
+
if (value !== undefined && value !== null) {
|
|
485
|
+
element.setAttribute(name, String(value));
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (text !== undefined) {
|
|
490
|
+
element.textContent = text;
|
|
491
|
+
}
|
|
492
|
+
return element;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function wrapText(value, maxChars, maxLines) {
|
|
496
|
+
const words = String(value || '').trim().split(/\s+/).filter(Boolean);
|
|
497
|
+
if (!words.length) {
|
|
498
|
+
return [];
|
|
499
|
+
}
|
|
500
|
+
const lines = [];
|
|
501
|
+
let current = '';
|
|
502
|
+
for (const word of words) {
|
|
503
|
+
const next = current ? current + ' ' + word : word;
|
|
504
|
+
if (next.length > maxChars && current) {
|
|
505
|
+
lines.push(current);
|
|
506
|
+
current = word;
|
|
507
|
+
} else {
|
|
508
|
+
current = next;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (current) {
|
|
512
|
+
lines.push(current);
|
|
513
|
+
}
|
|
514
|
+
if (lines.length <= maxLines) {
|
|
515
|
+
return lines;
|
|
516
|
+
}
|
|
517
|
+
const clipped = lines.slice(0, maxLines);
|
|
518
|
+
clipped[maxLines - 1] = clipped[maxLines - 1].replace(/[\s.]+$/, '') + '...';
|
|
519
|
+
return clipped;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function cssValue(name) {
|
|
523
|
+
return getComputedStyle(root).getPropertyValue(name).trim();
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function rgba(hex, alpha) {
|
|
527
|
+
const cleaned = String(hex || '').replace('#', '').trim();
|
|
528
|
+
const value = cleaned.length === 3
|
|
529
|
+
? cleaned.split('').map((char) => char + char).join('')
|
|
530
|
+
: cleaned;
|
|
531
|
+
const number = Number.parseInt(value, 16);
|
|
532
|
+
const red = (number >> 16) & 255;
|
|
533
|
+
const green = (number >> 8) & 255;
|
|
534
|
+
const blue = number & 255;
|
|
535
|
+
return 'rgba(' + red + ', ' + green + ', ' + blue + ', ' + alpha + ')';
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function accentFor(type) {
|
|
539
|
+
return cssValue(typeVars[type] || '--dt-text-tertiary');
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function parseData() {
|
|
543
|
+
const source = document.getElementById('diagram-data');
|
|
544
|
+
if (!source) {
|
|
545
|
+
return {};
|
|
546
|
+
}
|
|
547
|
+
try {
|
|
548
|
+
return JSON.parse(source.textContent || '{}');
|
|
549
|
+
} catch (error) {
|
|
550
|
+
showEmpty('Invalid diagram JSON', String(error && error.message ? error.message : error));
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function showEmpty(title, message) {
|
|
556
|
+
emptyState.classList.add('is-visible');
|
|
557
|
+
emptyState.innerHTML = '<div><strong>' + escapeHtml(title) + '</strong><span>' + escapeHtml(message) + '</span></div>';
|
|
558
|
+
svg.innerHTML = '';
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function hideEmpty() {
|
|
562
|
+
emptyState.classList.remove('is-visible');
|
|
563
|
+
emptyState.textContent = '';
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function escapeHtml(value) {
|
|
567
|
+
return String(value)
|
|
568
|
+
.replace(/&/g, '&')
|
|
569
|
+
.replace(/</g, '<')
|
|
570
|
+
.replace(/>/g, '>')
|
|
571
|
+
.replace(/"/g, '"')
|
|
572
|
+
.replace(/'/g, ''');
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function buildModel(raw) {
|
|
576
|
+
const nodes = Array.isArray(raw && raw.nodes) ? raw.nodes : [];
|
|
577
|
+
const edges = Array.isArray(raw && raw.edges) ? raw.edges : [];
|
|
578
|
+
const map = new Map();
|
|
579
|
+
const children = new Map();
|
|
580
|
+
|
|
581
|
+
nodes.forEach((item) => {
|
|
582
|
+
map.set(item.id, Object.assign({ type: 'container' }, item));
|
|
583
|
+
children.set(item.id, []);
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
nodes.forEach((item) => {
|
|
587
|
+
if (item.parent && children.has(item.parent)) {
|
|
588
|
+
children.get(item.parent).push(item.id);
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
const roots = nodes
|
|
593
|
+
.filter((item) => !item.parent || !map.has(item.parent))
|
|
594
|
+
.map((item) => item.id);
|
|
595
|
+
|
|
596
|
+
return { nodes, edges, map, children, roots };
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function measureEntity(id, model, cache) {
|
|
600
|
+
if (cache.has(id)) {
|
|
601
|
+
return cache.get(id);
|
|
602
|
+
}
|
|
603
|
+
const childIds = model.children.get(id) || [];
|
|
604
|
+
if (!childIds.length) {
|
|
605
|
+
const measuredLeaf = Object.assign({ id, cols: 1, rows: 1, childIds: [] }, leafSize, { isGroup: false });
|
|
606
|
+
cache.set(id, measuredLeaf);
|
|
607
|
+
return measuredLeaf;
|
|
608
|
+
}
|
|
609
|
+
const measuredChildren = childIds.map((childId) => measureEntity(childId, model, cache));
|
|
610
|
+
const cols = childIds.length <= 2 ? Math.max(1, childIds.length) : Math.ceil(Math.sqrt(childIds.length));
|
|
611
|
+
let rowWidth = 0;
|
|
612
|
+
let rowHeight = 0;
|
|
613
|
+
let totalHeight = 0;
|
|
614
|
+
let maxWidth = 0;
|
|
615
|
+
let column = 0;
|
|
616
|
+
|
|
617
|
+
measuredChildren.forEach((child, index) => {
|
|
618
|
+
rowWidth += child.width;
|
|
619
|
+
if (column > 0) {
|
|
620
|
+
rowWidth += groupInset.gap;
|
|
621
|
+
}
|
|
622
|
+
rowHeight = Math.max(rowHeight, child.height);
|
|
623
|
+
column += 1;
|
|
624
|
+
const endRow = column === cols || index === measuredChildren.length - 1;
|
|
625
|
+
if (endRow) {
|
|
626
|
+
maxWidth = Math.max(maxWidth, rowWidth);
|
|
627
|
+
totalHeight += rowHeight;
|
|
628
|
+
if (index !== measuredChildren.length - 1) {
|
|
629
|
+
totalHeight += groupInset.gap;
|
|
630
|
+
}
|
|
631
|
+
rowWidth = 0;
|
|
632
|
+
rowHeight = 0;
|
|
633
|
+
column = 0;
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
const measuredGroup = {
|
|
638
|
+
id,
|
|
639
|
+
isGroup: true,
|
|
640
|
+
childIds,
|
|
641
|
+
cols,
|
|
642
|
+
width: Math.max(312, groupInset.left + maxWidth + groupInset.right),
|
|
643
|
+
height: Math.max(220, groupInset.top + totalHeight + groupInset.bottom),
|
|
644
|
+
};
|
|
645
|
+
cache.set(id, measuredGroup);
|
|
646
|
+
return measuredGroup;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
function placeEntity(id, x, y, model, cache, positions) {
|
|
650
|
+
const measured = cache.get(id);
|
|
651
|
+
positions.set(id, { x, y, width: measured.width, height: measured.height });
|
|
652
|
+
if (!measured.isGroup) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
let cursorX = x + groupInset.left;
|
|
656
|
+
let cursorY = y + groupInset.top;
|
|
657
|
+
let rowHeight = 0;
|
|
658
|
+
let column = 0;
|
|
659
|
+
|
|
660
|
+
measured.childIds.forEach((childId) => {
|
|
661
|
+
const child = cache.get(childId);
|
|
662
|
+
if (column === measured.cols) {
|
|
663
|
+
cursorX = x + groupInset.left;
|
|
664
|
+
cursorY += rowHeight + groupInset.gap;
|
|
665
|
+
rowHeight = 0;
|
|
666
|
+
column = 0;
|
|
667
|
+
}
|
|
668
|
+
placeEntity(childId, cursorX, cursorY, model, cache, positions);
|
|
669
|
+
cursorX += child.width + groupInset.gap;
|
|
670
|
+
rowHeight = Math.max(rowHeight, child.height);
|
|
671
|
+
column += 1;
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
function layout(model) {
|
|
676
|
+
const cache = new Map();
|
|
677
|
+
const positions = new Map();
|
|
678
|
+
const roots = model.roots.map((id) => measureEntity(id, model, cache));
|
|
679
|
+
const cols = roots.length <= 2 ? Math.max(1, roots.length) : Math.ceil(Math.sqrt(roots.length));
|
|
680
|
+
let cursorX = canvasPadding;
|
|
681
|
+
let cursorY = canvasPadding;
|
|
682
|
+
let rowHeight = 0;
|
|
683
|
+
let column = 0;
|
|
684
|
+
let maxRight = 0;
|
|
685
|
+
let maxBottom = 0;
|
|
686
|
+
|
|
687
|
+
model.roots.forEach((id) => {
|
|
688
|
+
const measured = cache.get(id);
|
|
689
|
+
if (column === cols) {
|
|
690
|
+
cursorX = canvasPadding;
|
|
691
|
+
cursorY += rowHeight + rootGap;
|
|
692
|
+
rowHeight = 0;
|
|
693
|
+
column = 0;
|
|
694
|
+
}
|
|
695
|
+
placeEntity(id, cursorX, cursorY, model, cache, positions);
|
|
696
|
+
maxRight = Math.max(maxRight, cursorX + measured.width);
|
|
697
|
+
maxBottom = Math.max(maxBottom, cursorY + measured.height);
|
|
698
|
+
rowHeight = Math.max(rowHeight, measured.height);
|
|
699
|
+
cursorX += measured.width + rootGap;
|
|
700
|
+
column += 1;
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
return {
|
|
704
|
+
positions,
|
|
705
|
+
width: Math.max(960, maxRight + canvasPadding),
|
|
706
|
+
height: Math.max(640, maxBottom + canvasPadding),
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
function anchor(box, target) {
|
|
711
|
+
const centerX = box.x + box.width / 2;
|
|
712
|
+
const centerY = box.y + box.height / 2;
|
|
713
|
+
const targetX = target.x + target.width / 2;
|
|
714
|
+
const targetY = target.y + target.height / 2;
|
|
715
|
+
const dx = targetX - centerX;
|
|
716
|
+
const dy = targetY - centerY;
|
|
717
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
718
|
+
return {
|
|
719
|
+
x: dx > 0 ? box.x + box.width : box.x,
|
|
720
|
+
y: centerY,
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
return {
|
|
724
|
+
x: centerX,
|
|
725
|
+
y: dy > 0 ? box.y + box.height : box.y,
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function edgePath(sourceBox, targetBox) {
|
|
730
|
+
const start = anchor(sourceBox, targetBox);
|
|
731
|
+
const end = anchor(targetBox, sourceBox);
|
|
732
|
+
const dx = Math.abs(end.x - start.x);
|
|
733
|
+
const dy = Math.abs(end.y - start.y);
|
|
734
|
+
const curve = Math.max(48, Math.min(160, Math.max(dx * 0.35, dy * 0.35)));
|
|
735
|
+
const c1x = start.x + (end.x >= start.x ? curve : -curve);
|
|
736
|
+
const c2x = end.x + (end.x >= start.x ? -curve : curve);
|
|
737
|
+
return {
|
|
738
|
+
d: 'M ' + start.x + ' ' + start.y + ' C ' + c1x + ' ' + start.y + ', ' + c2x + ' ' + end.y + ', ' + end.x + ' ' + end.y,
|
|
739
|
+
labelX: (start.x + end.x) / 2,
|
|
740
|
+
labelY: (start.y + end.y) / 2 - 10,
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function renderDefs() {
|
|
745
|
+
const defs = node('defs');
|
|
746
|
+
|
|
747
|
+
const marker = node('marker', {
|
|
748
|
+
id: 'arrow',
|
|
749
|
+
viewBox: '0 0 10 10',
|
|
750
|
+
refX: 8,
|
|
751
|
+
refY: 5,
|
|
752
|
+
markerWidth: 7,
|
|
753
|
+
markerHeight: 7,
|
|
754
|
+
orient: 'auto-start-reverse',
|
|
755
|
+
});
|
|
756
|
+
marker.appendChild(node('path', {
|
|
757
|
+
d: 'M 0 0 L 10 5 L 0 10 z',
|
|
758
|
+
fill: cssValue('--dt-text-secondary'),
|
|
759
|
+
}));
|
|
760
|
+
defs.appendChild(marker);
|
|
761
|
+
|
|
762
|
+
const filter = node('filter', {
|
|
763
|
+
id: 'node-shadow',
|
|
764
|
+
x: '-20%',
|
|
765
|
+
y: '-20%',
|
|
766
|
+
width: '140%',
|
|
767
|
+
height: '140%',
|
|
768
|
+
});
|
|
769
|
+
filter.appendChild(node('feDropShadow', {
|
|
770
|
+
dx: 0,
|
|
771
|
+
dy: 12,
|
|
772
|
+
stdDeviation: 12,
|
|
773
|
+
'flood-color': cssValue('--dt-shadow-lg'),
|
|
774
|
+
}));
|
|
775
|
+
defs.appendChild(filter);
|
|
776
|
+
|
|
777
|
+
Object.keys(typeVars).forEach((type) => {
|
|
778
|
+
const color = accentFor(type);
|
|
779
|
+
const gradient = node('linearGradient', {
|
|
780
|
+
id: 'grad-' + type,
|
|
781
|
+
x1: '0%',
|
|
782
|
+
y1: '0%',
|
|
783
|
+
x2: '100%',
|
|
784
|
+
y2: '100%',
|
|
785
|
+
});
|
|
786
|
+
gradient.appendChild(node('stop', {
|
|
787
|
+
offset: '0%',
|
|
788
|
+
'stop-color': rgba(color, 0.24),
|
|
789
|
+
}));
|
|
790
|
+
gradient.appendChild(node('stop', {
|
|
791
|
+
offset: '100%',
|
|
792
|
+
'stop-color': rgba(color, 0.06),
|
|
793
|
+
}));
|
|
794
|
+
defs.appendChild(gradient);
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
return defs;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
function renderTextBlock(group, lines, x, y, fontSize, color, fontWeight, lineHeight, anchorMode) {
|
|
801
|
+
lines.forEach((line, index) => {
|
|
802
|
+
group.appendChild(node('text', {
|
|
803
|
+
x,
|
|
804
|
+
y: y + index * lineHeight,
|
|
805
|
+
fill: color,
|
|
806
|
+
'font-size': fontSize,
|
|
807
|
+
'font-weight': fontWeight,
|
|
808
|
+
'text-anchor': anchorMode || 'start',
|
|
809
|
+
}, line));
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
function renderLabelBadge(group, text, x, y, color) {
|
|
814
|
+
const width = Math.max(52, text.length * 7 + 18);
|
|
815
|
+
group.appendChild(node('rect', {
|
|
816
|
+
x,
|
|
817
|
+
y,
|
|
818
|
+
width,
|
|
819
|
+
height: 22,
|
|
820
|
+
rx: 11,
|
|
821
|
+
fill: rgba(color, 0.18),
|
|
822
|
+
stroke: rgba(color, 0.35),
|
|
823
|
+
}));
|
|
824
|
+
group.appendChild(node('text', {
|
|
825
|
+
x: x + width / 2,
|
|
826
|
+
y: y + 15,
|
|
827
|
+
fill: color,
|
|
828
|
+
'font-size': 10,
|
|
829
|
+
'font-family': monoFont,
|
|
830
|
+
'font-weight': 700,
|
|
831
|
+
'letter-spacing': '0.08em',
|
|
832
|
+
'text-anchor': 'middle',
|
|
833
|
+
}, text.toUpperCase()));
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
function renderGroup(id, model, positions, groupLayer) {
|
|
837
|
+
const data = model.map.get(id);
|
|
838
|
+
const box = positions.get(id);
|
|
839
|
+
const color = accentFor(data.type);
|
|
840
|
+
const labelWidth = Math.max(120, String(data.label || data.id).length * 8 + 32);
|
|
841
|
+
|
|
842
|
+
groupLayer.appendChild(node('rect', {
|
|
843
|
+
x: box.x,
|
|
844
|
+
y: box.y,
|
|
845
|
+
width: box.width,
|
|
846
|
+
height: box.height,
|
|
847
|
+
rx: 24,
|
|
848
|
+
fill: cssValue('--dt-group-fill'),
|
|
849
|
+
stroke: color,
|
|
850
|
+
'stroke-width': 1.6,
|
|
851
|
+
'stroke-dasharray': '10 8',
|
|
852
|
+
}));
|
|
853
|
+
groupLayer.appendChild(node('rect', {
|
|
854
|
+
x: box.x + 16,
|
|
855
|
+
y: box.y - 14,
|
|
856
|
+
width: labelWidth,
|
|
857
|
+
height: 28,
|
|
858
|
+
rx: 14,
|
|
859
|
+
fill: cssValue('--dt-bg-primary'),
|
|
860
|
+
stroke: color,
|
|
861
|
+
}));
|
|
862
|
+
groupLayer.appendChild(node('text', {
|
|
863
|
+
x: box.x + 28,
|
|
864
|
+
y: box.y + 4,
|
|
865
|
+
fill: color,
|
|
866
|
+
'font-size': 11,
|
|
867
|
+
'font-family': monoFont,
|
|
868
|
+
'font-weight': 700,
|
|
869
|
+
'letter-spacing': '0.08em',
|
|
870
|
+
}, String(data.label || data.id).toUpperCase()));
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function renderLeaf(id, model, positions, nodeLayer) {
|
|
874
|
+
const data = model.map.get(id);
|
|
875
|
+
const box = positions.get(id);
|
|
876
|
+
const color = accentFor(data.type);
|
|
877
|
+
const labelLines = wrapText(data.label || data.id, 20, 2);
|
|
878
|
+
const descLines = wrapText(data.description || '', 28, 2);
|
|
879
|
+
const group = node('g');
|
|
880
|
+
|
|
881
|
+
group.appendChild(node('rect', {
|
|
882
|
+
x: box.x,
|
|
883
|
+
y: box.y,
|
|
884
|
+
width: box.width,
|
|
885
|
+
height: box.height,
|
|
886
|
+
rx: 22,
|
|
887
|
+
fill: 'url(#grad-' + (typeVars[data.type] ? data.type : 'external') + ')',
|
|
888
|
+
stroke: color,
|
|
889
|
+
'stroke-width': 1.8,
|
|
890
|
+
filter: 'url(#node-shadow)',
|
|
891
|
+
}));
|
|
892
|
+
group.appendChild(node('rect', {
|
|
893
|
+
x: box.x + 1,
|
|
894
|
+
y: box.y + 1,
|
|
895
|
+
width: box.width - 2,
|
|
896
|
+
height: box.height - 2,
|
|
897
|
+
rx: 21,
|
|
898
|
+
fill: cssValue('--dt-node-fill'),
|
|
899
|
+
}));
|
|
900
|
+
group.appendChild(node('rect', {
|
|
901
|
+
x: box.x + 18,
|
|
902
|
+
y: box.y + 18,
|
|
903
|
+
width: 6,
|
|
904
|
+
height: box.height - 36,
|
|
905
|
+
rx: 3,
|
|
906
|
+
fill: color,
|
|
907
|
+
}));
|
|
908
|
+
renderLabelBadge(group, data.type || 'node', box.x + 30, box.y + 16, color);
|
|
909
|
+
renderTextBlock(group, labelLines, box.x + 30, box.y + 56, 19, cssValue('--dt-text-primary'), 700, 22, 'start');
|
|
910
|
+
if (descLines.length) {
|
|
911
|
+
renderTextBlock(group, descLines, box.x + 30, box.y + 88, 12, cssValue('--dt-text-secondary'), 500, 16, 'start');
|
|
912
|
+
}
|
|
913
|
+
if (data.technology) {
|
|
914
|
+
const techY = box.y + box.height - 34;
|
|
915
|
+
const techWidth = Math.min(box.width - 48, Math.max(78, String(data.technology).length * 7 + 22));
|
|
916
|
+
group.appendChild(node('rect', {
|
|
917
|
+
x: box.x + 30,
|
|
918
|
+
y: techY,
|
|
919
|
+
width: techWidth,
|
|
920
|
+
height: 22,
|
|
921
|
+
rx: 11,
|
|
922
|
+
fill: rgba(color, 0.14),
|
|
923
|
+
stroke: rgba(color, 0.32),
|
|
924
|
+
}));
|
|
925
|
+
group.appendChild(node('text', {
|
|
926
|
+
x: box.x + 41,
|
|
927
|
+
y: techY + 15,
|
|
928
|
+
fill: cssValue('--dt-text-primary'),
|
|
929
|
+
'font-size': 10.5,
|
|
930
|
+
'font-family': monoFont,
|
|
931
|
+
}, data.technology));
|
|
932
|
+
}
|
|
933
|
+
nodeLayer.appendChild(group);
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
function renderEdge(edge, positions, edgeLayer) {
|
|
937
|
+
const source = positions.get(edge.source);
|
|
938
|
+
const target = positions.get(edge.target);
|
|
939
|
+
if (!source || !target) {
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
const route = edgePath(source, target);
|
|
943
|
+
edgeLayer.appendChild(node('path', {
|
|
944
|
+
d: route.d,
|
|
945
|
+
fill: 'none',
|
|
946
|
+
stroke: cssValue('--dt-text-secondary'),
|
|
947
|
+
'stroke-width': 2,
|
|
948
|
+
'stroke-linecap': 'round',
|
|
949
|
+
'stroke-linejoin': 'round',
|
|
950
|
+
'marker-end': 'url(#arrow)',
|
|
951
|
+
opacity: 0.86,
|
|
952
|
+
}));
|
|
953
|
+
if (edge.label) {
|
|
954
|
+
const width = Math.max(62, String(edge.label).length * 7 + 16);
|
|
955
|
+
edgeLayer.appendChild(node('rect', {
|
|
956
|
+
x: route.labelX - width / 2,
|
|
957
|
+
y: route.labelY - 14,
|
|
958
|
+
width,
|
|
959
|
+
height: 24,
|
|
960
|
+
rx: 12,
|
|
961
|
+
fill: cssValue('--dt-bg-primary'),
|
|
962
|
+
stroke: cssValue('--dt-border-default'),
|
|
963
|
+
}));
|
|
964
|
+
edgeLayer.appendChild(node('text', {
|
|
965
|
+
x: route.labelX,
|
|
966
|
+
y: route.labelY + 2,
|
|
967
|
+
fill: cssValue('--dt-text-secondary'),
|
|
968
|
+
'font-size': 10,
|
|
969
|
+
'font-family': monoFont,
|
|
970
|
+
'text-anchor': 'middle',
|
|
971
|
+
}, edge.label));
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
function render() {
|
|
976
|
+
const raw = parseData();
|
|
977
|
+
if (raw === null) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
const model = buildModel(raw);
|
|
981
|
+
if (!model.nodes.length) {
|
|
982
|
+
showEmpty('No data provided', 'Populate #diagram-data with nodes and optional edges to render the diagram.');
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
hideEmpty();
|
|
986
|
+
const { positions, width, height } = layout(model);
|
|
987
|
+
svg.innerHTML = '';
|
|
988
|
+
svg.setAttribute('viewBox', '0 0 ' + width + ' ' + height);
|
|
989
|
+
svg.setAttribute('aria-label', (raw.title || 'Architecture diagram') + ' with ' + model.nodes.length + ' nodes');
|
|
990
|
+
|
|
991
|
+
svg.appendChild(renderDefs());
|
|
992
|
+
|
|
993
|
+
const title = node('title', { id: 'diagram-title' }, raw.title || 'Architecture diagram');
|
|
994
|
+
const description = node('desc', { id: 'diagram-description' }, raw.description || 'Static architecture diagram rendered with SVG');
|
|
995
|
+
svg.appendChild(title);
|
|
996
|
+
svg.appendChild(description);
|
|
997
|
+
|
|
998
|
+
const edgeLayer = node('g', { 'aria-hidden': 'true' });
|
|
999
|
+
const groupLayer = node('g', { 'aria-hidden': 'true' });
|
|
1000
|
+
const nodeLayer = node('g');
|
|
1001
|
+
|
|
1002
|
+
(model.edges || []).forEach((edge) => renderEdge(edge, positions, edgeLayer));
|
|
1003
|
+
model.nodes.forEach((item) => {
|
|
1004
|
+
if ((model.children.get(item.id) || []).length) {
|
|
1005
|
+
renderGroup(item.id, model, positions, groupLayer);
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
model.nodes.forEach((item) => {
|
|
1009
|
+
if (!(model.children.get(item.id) || []).length) {
|
|
1010
|
+
renderLeaf(item.id, model, positions, nodeLayer);
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
svg.appendChild(edgeLayer);
|
|
1015
|
+
svg.appendChild(groupLayer);
|
|
1016
|
+
svg.appendChild(nodeLayer);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
function updateThemeButton() {
|
|
1020
|
+
const value = root.getAttribute('data-theme') || 'auto';
|
|
1021
|
+
themeButton.textContent = 'Theme: ' + value.charAt(0).toUpperCase() + value.slice(1);
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
function cycleTheme() {
|
|
1025
|
+
const current = root.getAttribute('data-theme') || 'auto';
|
|
1026
|
+
const next = themes[(themes.indexOf(current) + 1) % themes.length];
|
|
1027
|
+
root.setAttribute('data-theme', next);
|
|
1028
|
+
updateThemeButton();
|
|
1029
|
+
render();
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
themeButton.addEventListener('click', cycleTheme);
|
|
1033
|
+
updateThemeButton();
|
|
1034
|
+
render();
|
|
1035
|
+
})();
|
|
1036
|
+
</script>
|
|
1037
|
+
</body>
|
|
1038
|
+
</html>
|