vizmatic 0.1.21 → 0.1.23
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/PROMPT.md +4 -0
- package/README.md +4 -0
- package/dist/cli.js +776 -0
- package/dist/index.cjs +781 -2
- package/dist/index.d.cts +79 -1
- package/dist/index.d.ts +79 -1
- package/dist/index.js +776 -0
- package/docs/PROMPT.md +4 -0
- package/docs/assets/examples/building-blocks_dark.png +0 -0
- package/docs/assets/examples/building-blocks_light.png +0 -0
- package/docs/assets/examples/manifest.json +8 -0
- package/docs/assets/examples/sources.json +10 -0
- package/examples/README.md +1 -0
- package/examples/building-blocks.tsx +85 -0
- package/examples/vizmatic-bare.d.ts +4 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -431,6 +431,113 @@ function ToneStrip({ tone, width = 34, height = 4 }) {
|
|
|
431
431
|
}
|
|
432
432
|
}, "");
|
|
433
433
|
}
|
|
434
|
+
var iconShapes = {
|
|
435
|
+
agent: [
|
|
436
|
+
{ tag: "rect", attrs: { x: 5, y: 7, width: 14, height: 12, rx: 4 } },
|
|
437
|
+
{ tag: "path", attrs: { d: "M12 7V4" } },
|
|
438
|
+
{ tag: "circle", attrs: { cx: 12, cy: 3, r: 1 } },
|
|
439
|
+
{ tag: "circle", attrs: { cx: 9, cy: 13, r: 1 } },
|
|
440
|
+
{ tag: "circle", attrs: { cx: 15, cy: 13, r: 1 } },
|
|
441
|
+
{ tag: "path", attrs: { d: "M9 17h6" } }
|
|
442
|
+
],
|
|
443
|
+
chart: [
|
|
444
|
+
{ tag: "path", attrs: { d: "M4 19V5" } },
|
|
445
|
+
{ tag: "path", attrs: { d: "M4 19h16" } },
|
|
446
|
+
{ tag: "polyline", attrs: { points: "7 15 11 11 14 13 19 7" } }
|
|
447
|
+
],
|
|
448
|
+
check: [{ tag: "polyline", attrs: { points: "20 6 9 17 4 12" } }],
|
|
449
|
+
code: [
|
|
450
|
+
{ tag: "polyline", attrs: { points: "8 9 4 12 8 15" } },
|
|
451
|
+
{ tag: "polyline", attrs: { points: "16 9 20 12 16 15" } },
|
|
452
|
+
{ tag: "path", attrs: { d: "M13 5l-2 14" } }
|
|
453
|
+
],
|
|
454
|
+
database: [
|
|
455
|
+
{ tag: "path", attrs: { d: "M4 7c0-2 16-2 16 0s-16 2-16 0Z" } },
|
|
456
|
+
{ tag: "path", attrs: { d: "M4 7v5c0 2 16 2 16 0V7" } },
|
|
457
|
+
{ tag: "path", attrs: { d: "M4 12v5c0 2 16 2 16 0v-5" } }
|
|
458
|
+
],
|
|
459
|
+
file: [
|
|
460
|
+
{ tag: "path", attrs: { d: "M6 3h8l4 4v14H6Z" } },
|
|
461
|
+
{ tag: "path", attrs: { d: "M14 3v5h5" } },
|
|
462
|
+
{ tag: "path", attrs: { d: "M9 13h6" } },
|
|
463
|
+
{ tag: "path", attrs: { d: "M9 17h4" } }
|
|
464
|
+
],
|
|
465
|
+
git: [
|
|
466
|
+
{ tag: "circle", attrs: { cx: 6, cy: 6, r: 2 } },
|
|
467
|
+
{ tag: "circle", attrs: { cx: 18, cy: 18, r: 2 } },
|
|
468
|
+
{ tag: "circle", attrs: { cx: 6, cy: 18, r: 2 } },
|
|
469
|
+
{ tag: "path", attrs: { d: "M8 6h3a5 5 0 0 1 5 5v5" } },
|
|
470
|
+
{ tag: "path", attrs: { d: "M6 8v8" } }
|
|
471
|
+
],
|
|
472
|
+
globe: [
|
|
473
|
+
{ tag: "circle", attrs: { cx: 12, cy: 12, r: 9 } },
|
|
474
|
+
{ tag: "path", attrs: { d: "M3 12h18" } },
|
|
475
|
+
{ tag: "path", attrs: { d: "M12 3a14 14 0 0 1 0 18" } },
|
|
476
|
+
{ tag: "path", attrs: { d: "M12 3a14 14 0 0 0 0 18" } }
|
|
477
|
+
],
|
|
478
|
+
image: [
|
|
479
|
+
{ tag: "rect", attrs: { x: 4, y: 5, width: 16, height: 14, rx: 3 } },
|
|
480
|
+
{ tag: "circle", attrs: { cx: 9, cy: 10, r: 1.5 } },
|
|
481
|
+
{ tag: "polyline", attrs: { points: "7 17 11 13 14 16 16 14 20 18" } }
|
|
482
|
+
],
|
|
483
|
+
layers: [
|
|
484
|
+
{ tag: "path", attrs: { d: "M12 3 3 8l9 5 9-5Z" } },
|
|
485
|
+
{ tag: "path", attrs: { d: "m3 13 9 5 9-5" } },
|
|
486
|
+
{ tag: "path", attrs: { d: "m3 18 9 5 9-5" } }
|
|
487
|
+
],
|
|
488
|
+
lock: [
|
|
489
|
+
{ tag: "rect", attrs: { x: 5, y: 10, width: 14, height: 10, rx: 2 } },
|
|
490
|
+
{ tag: "path", attrs: { d: "M8 10V7a4 4 0 0 1 8 0v3" } }
|
|
491
|
+
],
|
|
492
|
+
play: [{ tag: "path", attrs: { d: "M8 5v14l11-7Z" } }],
|
|
493
|
+
spark: [
|
|
494
|
+
{ tag: "path", attrs: { d: "M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8Z" } },
|
|
495
|
+
{ tag: "path", attrs: { d: "M5 16l.8 2.2L8 19l-2.2.8L5 22l-.8-2.2L2 19l2.2-.8Z" } }
|
|
496
|
+
],
|
|
497
|
+
terminal: [
|
|
498
|
+
{ tag: "polyline", attrs: { points: "5 7 10 12 5 17" } },
|
|
499
|
+
{ tag: "path", attrs: { d: "M12 17h7" } }
|
|
500
|
+
],
|
|
501
|
+
tool: [
|
|
502
|
+
{ tag: "path", attrs: { d: "M14 6a5 5 0 0 0 6 6L11 21l-6-6 9-9Z" } },
|
|
503
|
+
{ tag: "path", attrs: { d: "M8 18l-2-2" } }
|
|
504
|
+
],
|
|
505
|
+
warning: [
|
|
506
|
+
{ tag: "path", attrs: { d: "M12 4 22 20H2Z" } },
|
|
507
|
+
{ tag: "path", attrs: { d: "M12 9v5" } },
|
|
508
|
+
{ tag: "path", attrs: { d: "M12 17h.01" } }
|
|
509
|
+
]
|
|
510
|
+
};
|
|
511
|
+
function Icon({
|
|
512
|
+
c,
|
|
513
|
+
name,
|
|
514
|
+
tone = "blue",
|
|
515
|
+
color,
|
|
516
|
+
size = 24,
|
|
517
|
+
strokeWidth = 2,
|
|
518
|
+
label,
|
|
519
|
+
muted = false
|
|
520
|
+
}) {
|
|
521
|
+
const stroke = muted ? c.textMuted : color ?? getToneColor(tone, c);
|
|
522
|
+
const shapes = iconShapes[name];
|
|
523
|
+
return React.createElement("svg", {
|
|
524
|
+
width: size,
|
|
525
|
+
height: size,
|
|
526
|
+
viewBox: "0 0 24 24",
|
|
527
|
+
fill: "none",
|
|
528
|
+
stroke,
|
|
529
|
+
strokeWidth,
|
|
530
|
+
strokeLinecap: "round",
|
|
531
|
+
strokeLinejoin: "round",
|
|
532
|
+
role: label ? "img" : void 0,
|
|
533
|
+
"aria-hidden": label ? void 0 : "true",
|
|
534
|
+
"aria-label": label,
|
|
535
|
+
style: { flex: `0 0 ${size}px` }
|
|
536
|
+
}, shapes.map((shape, index) => React.createElement(shape.tag, {
|
|
537
|
+
key: `${name}-${index}`,
|
|
538
|
+
...shape.attrs
|
|
539
|
+
})));
|
|
540
|
+
}
|
|
434
541
|
function Panel({
|
|
435
542
|
title,
|
|
436
543
|
c,
|
|
@@ -2422,6 +2529,274 @@ function StatusList({
|
|
|
2422
2529
|
))
|
|
2423
2530
|
});
|
|
2424
2531
|
}
|
|
2532
|
+
function renderTimelineCard(event, c, math, width) {
|
|
2533
|
+
const accent = getToneColor(event.tone ?? statusTones[event.status ?? "dot"], c);
|
|
2534
|
+
const resolvedWidth = event.width ?? width;
|
|
2535
|
+
return React.createElement(
|
|
2536
|
+
"div",
|
|
2537
|
+
{
|
|
2538
|
+
style: {
|
|
2539
|
+
display: "flex",
|
|
2540
|
+
flexDirection: "column",
|
|
2541
|
+
gap: 5,
|
|
2542
|
+
...resolvedWidth != null ? { width: resolvedWidth } : {},
|
|
2543
|
+
...typeof resolvedWidth === "string" ? { minWidth: 0 } : {},
|
|
2544
|
+
padding: "10px 12px",
|
|
2545
|
+
borderRadius: 8,
|
|
2546
|
+
border: `1px solid ${accent}44`,
|
|
2547
|
+
backgroundColor: c.bgCard,
|
|
2548
|
+
boxShadow: `0 7px 18px ${c.shadow}`,
|
|
2549
|
+
boxSizing: "border-box"
|
|
2550
|
+
}
|
|
2551
|
+
},
|
|
2552
|
+
...compactChildren([
|
|
2553
|
+
event.time != null && React.createElement("div", {
|
|
2554
|
+
style: {
|
|
2555
|
+
display: "flex",
|
|
2556
|
+
color: accent,
|
|
2557
|
+
fontFamily: "JetBrains Mono",
|
|
2558
|
+
fontSize: 9,
|
|
2559
|
+
fontWeight: 900,
|
|
2560
|
+
lineHeight: 1.15,
|
|
2561
|
+
textTransform: "uppercase",
|
|
2562
|
+
letterSpacing: "0.04em"
|
|
2563
|
+
}
|
|
2564
|
+
}, renderMaybeMath(event.time, math)),
|
|
2565
|
+
React.createElement("div", {
|
|
2566
|
+
style: {
|
|
2567
|
+
display: "flex",
|
|
2568
|
+
color: c.textPrimary,
|
|
2569
|
+
fontFamily: "Inter",
|
|
2570
|
+
fontSize: 14,
|
|
2571
|
+
fontWeight: 900,
|
|
2572
|
+
lineHeight: 1.18,
|
|
2573
|
+
...textFitStyle()
|
|
2574
|
+
}
|
|
2575
|
+
}, renderMaybeMath(event.title, math)),
|
|
2576
|
+
event.detail != null && React.createElement("div", {
|
|
2577
|
+
style: {
|
|
2578
|
+
display: "flex",
|
|
2579
|
+
color: c.textSecondary,
|
|
2580
|
+
fontFamily: "Inter",
|
|
2581
|
+
fontSize: 11,
|
|
2582
|
+
fontWeight: 500,
|
|
2583
|
+
lineHeight: 1.35,
|
|
2584
|
+
...textFitStyle()
|
|
2585
|
+
}
|
|
2586
|
+
}, renderMaybeMath(event.detail, math))
|
|
2587
|
+
])
|
|
2588
|
+
);
|
|
2589
|
+
}
|
|
2590
|
+
function Timeline({
|
|
2591
|
+
events,
|
|
2592
|
+
c,
|
|
2593
|
+
title,
|
|
2594
|
+
subtitle,
|
|
2595
|
+
direction = "vertical",
|
|
2596
|
+
width,
|
|
2597
|
+
eventWidth,
|
|
2598
|
+
gap = 12,
|
|
2599
|
+
markerSize = 14,
|
|
2600
|
+
math = false
|
|
2601
|
+
}) {
|
|
2602
|
+
const header = (title != null || subtitle != null) && React.createElement(
|
|
2603
|
+
"div",
|
|
2604
|
+
{
|
|
2605
|
+
style: {
|
|
2606
|
+
display: "flex",
|
|
2607
|
+
flexDirection: "column",
|
|
2608
|
+
gap: subtitle != null ? 4 : 0,
|
|
2609
|
+
width: "100%"
|
|
2610
|
+
}
|
|
2611
|
+
},
|
|
2612
|
+
...compactChildren([
|
|
2613
|
+
title != null && React.createElement("div", {
|
|
2614
|
+
style: {
|
|
2615
|
+
display: "flex",
|
|
2616
|
+
alignItems: "center",
|
|
2617
|
+
gap: 8,
|
|
2618
|
+
color: c.textPrimary,
|
|
2619
|
+
fontFamily: "Inter",
|
|
2620
|
+
fontSize: 16,
|
|
2621
|
+
fontWeight: 900,
|
|
2622
|
+
lineHeight: 1.2
|
|
2623
|
+
}
|
|
2624
|
+
}, ToneStrip({ tone: events[0]?.tone ?? "blue" }), renderMaybeMath(title, math)),
|
|
2625
|
+
subtitle != null && React.createElement("div", {
|
|
2626
|
+
style: {
|
|
2627
|
+
display: "flex",
|
|
2628
|
+
color: c.textSecondary,
|
|
2629
|
+
fontFamily: "Inter",
|
|
2630
|
+
fontSize: 11,
|
|
2631
|
+
fontWeight: 500,
|
|
2632
|
+
lineHeight: 1.35
|
|
2633
|
+
}
|
|
2634
|
+
}, renderMaybeMath(subtitle, math))
|
|
2635
|
+
])
|
|
2636
|
+
);
|
|
2637
|
+
if (direction === "horizontal") {
|
|
2638
|
+
return React.createElement(
|
|
2639
|
+
"div",
|
|
2640
|
+
{
|
|
2641
|
+
style: {
|
|
2642
|
+
display: "flex",
|
|
2643
|
+
flexDirection: "column",
|
|
2644
|
+
gap,
|
|
2645
|
+
...width != null ? { width } : {}
|
|
2646
|
+
}
|
|
2647
|
+
},
|
|
2648
|
+
...compactChildren([
|
|
2649
|
+
header,
|
|
2650
|
+
React.createElement("div", {
|
|
2651
|
+
style: {
|
|
2652
|
+
display: "flex",
|
|
2653
|
+
alignItems: "stretch",
|
|
2654
|
+
gap: 0,
|
|
2655
|
+
width: "100%"
|
|
2656
|
+
}
|
|
2657
|
+
}, ...events.map((event, index) => {
|
|
2658
|
+
const accent = getToneColor(event.tone ?? statusTones[event.status ?? "dot"], c);
|
|
2659
|
+
return React.createElement(
|
|
2660
|
+
"div",
|
|
2661
|
+
{
|
|
2662
|
+
key: `timeline-h-${index}`,
|
|
2663
|
+
style: {
|
|
2664
|
+
display: "flex",
|
|
2665
|
+
flexDirection: "column",
|
|
2666
|
+
gap: 8,
|
|
2667
|
+
...eventWidth == null ? { flex: 1 } : {},
|
|
2668
|
+
...(event.width ?? eventWidth) != null ? { width: event.width ?? eventWidth } : {},
|
|
2669
|
+
minWidth: 0
|
|
2670
|
+
}
|
|
2671
|
+
},
|
|
2672
|
+
React.createElement(
|
|
2673
|
+
"div",
|
|
2674
|
+
{
|
|
2675
|
+
style: {
|
|
2676
|
+
display: "flex",
|
|
2677
|
+
alignItems: "center",
|
|
2678
|
+
width: "100%"
|
|
2679
|
+
}
|
|
2680
|
+
},
|
|
2681
|
+
React.createElement("div", {
|
|
2682
|
+
style: {
|
|
2683
|
+
display: "flex",
|
|
2684
|
+
flex: 1,
|
|
2685
|
+
height: 2,
|
|
2686
|
+
backgroundColor: c.borderLight,
|
|
2687
|
+
opacity: index === 0 ? 0 : 1
|
|
2688
|
+
}
|
|
2689
|
+
}),
|
|
2690
|
+
React.createElement("div", {
|
|
2691
|
+
style: {
|
|
2692
|
+
display: "flex",
|
|
2693
|
+
width: markerSize,
|
|
2694
|
+
height: markerSize,
|
|
2695
|
+
borderRadius: 999,
|
|
2696
|
+
backgroundColor: accent,
|
|
2697
|
+
border: `3px solid ${c.bg}`,
|
|
2698
|
+
boxShadow: `0 0 0 1px ${accent}`,
|
|
2699
|
+
flexShrink: 0
|
|
2700
|
+
}
|
|
2701
|
+
}),
|
|
2702
|
+
React.createElement("div", {
|
|
2703
|
+
style: {
|
|
2704
|
+
display: "flex",
|
|
2705
|
+
flex: 1,
|
|
2706
|
+
height: 2,
|
|
2707
|
+
backgroundColor: c.borderLight,
|
|
2708
|
+
opacity: index === events.length - 1 ? 0 : 1
|
|
2709
|
+
}
|
|
2710
|
+
})
|
|
2711
|
+
),
|
|
2712
|
+
renderTimelineCard(event, c, math, eventWidth)
|
|
2713
|
+
);
|
|
2714
|
+
}))
|
|
2715
|
+
])
|
|
2716
|
+
);
|
|
2717
|
+
}
|
|
2718
|
+
return React.createElement(
|
|
2719
|
+
"div",
|
|
2720
|
+
{
|
|
2721
|
+
style: {
|
|
2722
|
+
display: "flex",
|
|
2723
|
+
flexDirection: "column",
|
|
2724
|
+
gap,
|
|
2725
|
+
...width != null ? { width } : {}
|
|
2726
|
+
}
|
|
2727
|
+
},
|
|
2728
|
+
...compactChildren([
|
|
2729
|
+
header,
|
|
2730
|
+
React.createElement("div", {
|
|
2731
|
+
style: {
|
|
2732
|
+
display: "flex",
|
|
2733
|
+
flexDirection: "column",
|
|
2734
|
+
gap,
|
|
2735
|
+
width: "100%"
|
|
2736
|
+
}
|
|
2737
|
+
}, ...events.map((event, index) => {
|
|
2738
|
+
const accent = getToneColor(event.tone ?? statusTones[event.status ?? "dot"], c);
|
|
2739
|
+
return React.createElement(
|
|
2740
|
+
"div",
|
|
2741
|
+
{
|
|
2742
|
+
key: `timeline-v-${index}`,
|
|
2743
|
+
style: {
|
|
2744
|
+
display: "flex",
|
|
2745
|
+
alignItems: "stretch",
|
|
2746
|
+
gap: 11,
|
|
2747
|
+
width: "100%"
|
|
2748
|
+
}
|
|
2749
|
+
},
|
|
2750
|
+
React.createElement(
|
|
2751
|
+
"div",
|
|
2752
|
+
{
|
|
2753
|
+
style: {
|
|
2754
|
+
display: "flex",
|
|
2755
|
+
flexDirection: "column",
|
|
2756
|
+
alignItems: "center",
|
|
2757
|
+
width: markerSize + 8,
|
|
2758
|
+
flexShrink: 0
|
|
2759
|
+
}
|
|
2760
|
+
},
|
|
2761
|
+
React.createElement("div", {
|
|
2762
|
+
style: {
|
|
2763
|
+
display: "flex",
|
|
2764
|
+
flex: 1,
|
|
2765
|
+
minHeight: 4,
|
|
2766
|
+
width: 2,
|
|
2767
|
+
backgroundColor: c.borderLight,
|
|
2768
|
+
opacity: index === 0 ? 0 : 1
|
|
2769
|
+
}
|
|
2770
|
+
}),
|
|
2771
|
+
React.createElement("div", {
|
|
2772
|
+
style: {
|
|
2773
|
+
display: "flex",
|
|
2774
|
+
width: markerSize,
|
|
2775
|
+
height: markerSize,
|
|
2776
|
+
borderRadius: 999,
|
|
2777
|
+
backgroundColor: accent,
|
|
2778
|
+
border: `3px solid ${c.bg}`,
|
|
2779
|
+
boxShadow: `0 0 0 1px ${accent}`,
|
|
2780
|
+
flexShrink: 0
|
|
2781
|
+
}
|
|
2782
|
+
}),
|
|
2783
|
+
React.createElement("div", {
|
|
2784
|
+
style: {
|
|
2785
|
+
display: "flex",
|
|
2786
|
+
flex: 1,
|
|
2787
|
+
minHeight: 4,
|
|
2788
|
+
width: 2,
|
|
2789
|
+
backgroundColor: c.borderLight,
|
|
2790
|
+
opacity: index === events.length - 1 ? 0 : 1
|
|
2791
|
+
}
|
|
2792
|
+
})
|
|
2793
|
+
),
|
|
2794
|
+
renderTimelineCard(event, c, math)
|
|
2795
|
+
);
|
|
2796
|
+
}))
|
|
2797
|
+
])
|
|
2798
|
+
);
|
|
2799
|
+
}
|
|
2425
2800
|
function renderFlowStage(stage, c, math) {
|
|
2426
2801
|
const tone = stage.tone ?? "blue";
|
|
2427
2802
|
const hasDetails = Boolean(stage.children || stage.lines?.length);
|
|
@@ -2858,6 +3233,209 @@ function GraphDiagram({
|
|
|
2858
3233
|
})
|
|
2859
3234
|
);
|
|
2860
3235
|
}
|
|
3236
|
+
function countTreeLeaves(node) {
|
|
3237
|
+
if (!node.children?.length) return 1;
|
|
3238
|
+
return node.children.reduce((sum, child) => sum + countTreeLeaves(child), 0);
|
|
3239
|
+
}
|
|
3240
|
+
function maxTreeDepth(node) {
|
|
3241
|
+
if (!node.children?.length) return 0;
|
|
3242
|
+
return 1 + Math.max(...node.children.map(maxTreeDepth));
|
|
3243
|
+
}
|
|
3244
|
+
function TreeDiagram({
|
|
3245
|
+
root,
|
|
3246
|
+
c,
|
|
3247
|
+
title,
|
|
3248
|
+
subtitle,
|
|
3249
|
+
width,
|
|
3250
|
+
height,
|
|
3251
|
+
nodeWidth = 156,
|
|
3252
|
+
nodeHeight = 64,
|
|
3253
|
+
levelGap = 58,
|
|
3254
|
+
siblingGap = 24,
|
|
3255
|
+
padding = 28,
|
|
3256
|
+
math = false
|
|
3257
|
+
}) {
|
|
3258
|
+
const leafCount = Math.max(1, countTreeLeaves(root));
|
|
3259
|
+
const depthCount = maxTreeDepth(root);
|
|
3260
|
+
const resolvedWidth = width ?? Math.max(520, padding * 2 + leafCount * nodeWidth + Math.max(0, leafCount - 1) * siblingGap);
|
|
3261
|
+
const resolvedHeight = height ?? padding * 2 + (depthCount + 1) * nodeHeight + depthCount * levelGap;
|
|
3262
|
+
const levelStep = depthCount === 0 ? 0 : Math.max(nodeHeight + 18, (resolvedHeight - padding * 2 - nodeHeight) / depthCount);
|
|
3263
|
+
const usableWidth = Math.max(0, resolvedWidth - padding * 2 - nodeWidth);
|
|
3264
|
+
const leafStep = leafCount <= 1 ? 0 : usableWidth / (leafCount - 1);
|
|
3265
|
+
const positioned = [];
|
|
3266
|
+
const edges = [];
|
|
3267
|
+
let nextLeaf = 0;
|
|
3268
|
+
const placeWithEdges = (node, depth, path) => {
|
|
3269
|
+
const children = node.children ?? [];
|
|
3270
|
+
let centerIndex;
|
|
3271
|
+
const childPlacements = [];
|
|
3272
|
+
if (!children.length) {
|
|
3273
|
+
centerIndex = nextLeaf;
|
|
3274
|
+
nextLeaf += 1;
|
|
3275
|
+
} else {
|
|
3276
|
+
for (let index = 0; index < children.length; index += 1) {
|
|
3277
|
+
const child = children[index];
|
|
3278
|
+
childPlacements.push({
|
|
3279
|
+
node: child,
|
|
3280
|
+
index,
|
|
3281
|
+
center: placeWithEdges(child, depth + 1, `${path}-${index}`)
|
|
3282
|
+
});
|
|
3283
|
+
}
|
|
3284
|
+
centerIndex = childPlacements.reduce((sum, child) => sum + child.center, 0) / childPlacements.length;
|
|
3285
|
+
}
|
|
3286
|
+
const placed = {
|
|
3287
|
+
...node,
|
|
3288
|
+
key: node.id ?? path,
|
|
3289
|
+
depth,
|
|
3290
|
+
cx: leafCount <= 1 ? resolvedWidth / 2 : padding + nodeWidth / 2 + centerIndex * leafStep,
|
|
3291
|
+
cy: padding + nodeHeight / 2 + depth * levelStep
|
|
3292
|
+
};
|
|
3293
|
+
positioned.push(placed);
|
|
3294
|
+
for (const childPlacement of childPlacements) {
|
|
3295
|
+
const childKey = childPlacement.node.id ?? `${path}-${childPlacement.index}`;
|
|
3296
|
+
const childNode = positioned.find((candidate) => candidate.key === childKey);
|
|
3297
|
+
if (childNode) edges.push({ key: `${placed.key}-${childNode.key}`, from: placed, to: childNode });
|
|
3298
|
+
}
|
|
3299
|
+
return centerIndex;
|
|
3300
|
+
};
|
|
3301
|
+
placeWithEdges(root, 0, "root");
|
|
3302
|
+
const header = (title != null || subtitle != null) && React.createElement(
|
|
3303
|
+
"div",
|
|
3304
|
+
{
|
|
3305
|
+
style: {
|
|
3306
|
+
display: "flex",
|
|
3307
|
+
flexDirection: "column",
|
|
3308
|
+
gap: subtitle != null ? 4 : 0,
|
|
3309
|
+
width: resolvedWidth,
|
|
3310
|
+
maxWidth: "100%"
|
|
3311
|
+
}
|
|
3312
|
+
},
|
|
3313
|
+
...compactChildren([
|
|
3314
|
+
title != null && React.createElement("div", {
|
|
3315
|
+
style: {
|
|
3316
|
+
display: "flex",
|
|
3317
|
+
alignItems: "center",
|
|
3318
|
+
gap: 8,
|
|
3319
|
+
color: c.textPrimary,
|
|
3320
|
+
fontFamily: "Inter",
|
|
3321
|
+
fontSize: 16,
|
|
3322
|
+
fontWeight: 900,
|
|
3323
|
+
lineHeight: 1.2
|
|
3324
|
+
}
|
|
3325
|
+
}, ToneStrip({ tone: root.tone ?? "blue" }), renderMaybeMath(title, math)),
|
|
3326
|
+
subtitle != null && React.createElement("div", {
|
|
3327
|
+
style: {
|
|
3328
|
+
display: "flex",
|
|
3329
|
+
color: c.textSecondary,
|
|
3330
|
+
fontFamily: "Inter",
|
|
3331
|
+
fontSize: 11,
|
|
3332
|
+
fontWeight: 500,
|
|
3333
|
+
lineHeight: 1.35
|
|
3334
|
+
}
|
|
3335
|
+
}, renderMaybeMath(subtitle, math))
|
|
3336
|
+
])
|
|
3337
|
+
);
|
|
3338
|
+
return React.createElement(
|
|
3339
|
+
"div",
|
|
3340
|
+
{
|
|
3341
|
+
style: {
|
|
3342
|
+
display: "flex",
|
|
3343
|
+
flexDirection: "column",
|
|
3344
|
+
gap: header ? 10 : 0,
|
|
3345
|
+
width: resolvedWidth,
|
|
3346
|
+
maxWidth: "100%"
|
|
3347
|
+
}
|
|
3348
|
+
},
|
|
3349
|
+
...compactChildren([
|
|
3350
|
+
header,
|
|
3351
|
+
React.createElement(
|
|
3352
|
+
"div",
|
|
3353
|
+
{
|
|
3354
|
+
role: "img",
|
|
3355
|
+
style: {
|
|
3356
|
+
position: "relative",
|
|
3357
|
+
display: "flex",
|
|
3358
|
+
width: resolvedWidth,
|
|
3359
|
+
height: resolvedHeight,
|
|
3360
|
+
maxWidth: "100%",
|
|
3361
|
+
flexShrink: 0
|
|
3362
|
+
}
|
|
3363
|
+
},
|
|
3364
|
+
React.createElement("svg", {
|
|
3365
|
+
width: resolvedWidth,
|
|
3366
|
+
height: resolvedHeight,
|
|
3367
|
+
viewBox: `0 0 ${resolvedWidth} ${resolvedHeight}`,
|
|
3368
|
+
style: { position: "absolute", inset: 0, overflow: "visible" }
|
|
3369
|
+
}, ...edges.map((edge) => {
|
|
3370
|
+
const tone = edge.to.muted ? "neutral" : edge.to.tone ?? edge.from.tone ?? "blue";
|
|
3371
|
+
const color = edge.to.muted ? c.textMuted : getToneColor(tone, c);
|
|
3372
|
+
const startY = edge.from.cy + nodeHeight / 2;
|
|
3373
|
+
const endY = edge.to.cy - nodeHeight / 2;
|
|
3374
|
+
const midY = startY + (endY - startY) / 2;
|
|
3375
|
+
return React.createElement("path", {
|
|
3376
|
+
key: `tree-edge-${edge.key}`,
|
|
3377
|
+
d: `M ${edge.from.cx} ${startY} C ${edge.from.cx} ${midY}, ${edge.to.cx} ${midY}, ${edge.to.cx} ${endY}`,
|
|
3378
|
+
fill: "none",
|
|
3379
|
+
stroke: color,
|
|
3380
|
+
strokeWidth: edge.to.muted ? 1.4 : 2.4,
|
|
3381
|
+
strokeLinecap: "round",
|
|
3382
|
+
opacity: edge.to.muted ? 0.4 : 0.74
|
|
3383
|
+
});
|
|
3384
|
+
})),
|
|
3385
|
+
...positioned.map((node) => {
|
|
3386
|
+
const accent = node.muted ? c.textMuted : getToneColor(node.tone ?? "blue", c);
|
|
3387
|
+
return React.createElement(
|
|
3388
|
+
"div",
|
|
3389
|
+
{
|
|
3390
|
+
key: `tree-node-${node.key}`,
|
|
3391
|
+
style: {
|
|
3392
|
+
position: "absolute",
|
|
3393
|
+
left: node.cx - nodeWidth / 2,
|
|
3394
|
+
top: node.cy - nodeHeight / 2,
|
|
3395
|
+
width: nodeWidth,
|
|
3396
|
+
height: nodeHeight,
|
|
3397
|
+
display: "flex",
|
|
3398
|
+
flexDirection: "column",
|
|
3399
|
+
alignItems: "center",
|
|
3400
|
+
justifyContent: "center",
|
|
3401
|
+
gap: node.detail ? 4 : 0,
|
|
3402
|
+
padding: "8px 10px",
|
|
3403
|
+
boxSizing: "border-box",
|
|
3404
|
+
borderRadius: 8,
|
|
3405
|
+
backgroundColor: node.muted ? c.bgSubtle : c.bgCard,
|
|
3406
|
+
border: `1.5px solid ${node.muted ? c.borderLight : `${accent}88`}`,
|
|
3407
|
+
...!node.muted ? { boxShadow: `0 8px 18px ${c.shadow}` } : {},
|
|
3408
|
+
opacity: node.muted ? 0.62 : 1,
|
|
3409
|
+
color: accent,
|
|
3410
|
+
textAlign: "center"
|
|
3411
|
+
}
|
|
3412
|
+
},
|
|
3413
|
+
React.createElement("div", {
|
|
3414
|
+
style: {
|
|
3415
|
+
color: accent,
|
|
3416
|
+
fontFamily: "Inter",
|
|
3417
|
+
fontSize: 13,
|
|
3418
|
+
fontWeight: 900,
|
|
3419
|
+
lineHeight: 1.15,
|
|
3420
|
+
...textFitStyle("center")
|
|
3421
|
+
}
|
|
3422
|
+
}, renderMaybeMath(node.label, math)),
|
|
3423
|
+
node.detail != null && React.createElement("div", {
|
|
3424
|
+
style: {
|
|
3425
|
+
color: c.textMuted,
|
|
3426
|
+
fontFamily: "JetBrains Mono",
|
|
3427
|
+
fontSize: 9,
|
|
3428
|
+
fontWeight: 650,
|
|
3429
|
+
lineHeight: 1.2,
|
|
3430
|
+
...textFitStyle("center")
|
|
3431
|
+
}
|
|
3432
|
+
}, renderMaybeMath(node.detail, math))
|
|
3433
|
+
);
|
|
3434
|
+
})
|
|
3435
|
+
)
|
|
3436
|
+
])
|
|
3437
|
+
);
|
|
3438
|
+
}
|
|
2861
3439
|
function CalloutCard({
|
|
2862
3440
|
c,
|
|
2863
3441
|
children,
|
|
@@ -3807,6 +4385,200 @@ function ChartFrame({
|
|
|
3807
4385
|
)
|
|
3808
4386
|
);
|
|
3809
4387
|
}
|
|
4388
|
+
function polarPoint(cx, cy, radius, angleDegrees) {
|
|
4389
|
+
const radians = angleDegrees * Math.PI / 180;
|
|
4390
|
+
return {
|
|
4391
|
+
x: cx + radius * Math.cos(radians),
|
|
4392
|
+
y: cy + radius * Math.sin(radians)
|
|
4393
|
+
};
|
|
4394
|
+
}
|
|
4395
|
+
function donutArcPath(cx, cy, outerRadius, innerRadius, startAngle, endAngle) {
|
|
4396
|
+
const span = Math.min(359.99, Math.max(0.01, endAngle - startAngle));
|
|
4397
|
+
const safeEnd = startAngle + span;
|
|
4398
|
+
const outerStart = polarPoint(cx, cy, outerRadius, startAngle);
|
|
4399
|
+
const outerEnd = polarPoint(cx, cy, outerRadius, safeEnd);
|
|
4400
|
+
const innerEnd = polarPoint(cx, cy, innerRadius, safeEnd);
|
|
4401
|
+
const innerStart = polarPoint(cx, cy, innerRadius, startAngle);
|
|
4402
|
+
const largeArc = span > 180 ? 1 : 0;
|
|
4403
|
+
return [
|
|
4404
|
+
`M ${outerStart.x} ${outerStart.y}`,
|
|
4405
|
+
`A ${outerRadius} ${outerRadius} 0 ${largeArc} 1 ${outerEnd.x} ${outerEnd.y}`,
|
|
4406
|
+
`L ${innerEnd.x} ${innerEnd.y}`,
|
|
4407
|
+
`A ${innerRadius} ${innerRadius} 0 ${largeArc} 0 ${innerStart.x} ${innerStart.y}`,
|
|
4408
|
+
"Z"
|
|
4409
|
+
].join(" ");
|
|
4410
|
+
}
|
|
4411
|
+
function DonutChart({
|
|
4412
|
+
segments,
|
|
4413
|
+
c,
|
|
4414
|
+
title,
|
|
4415
|
+
subtitle,
|
|
4416
|
+
width = 360,
|
|
4417
|
+
height = 230,
|
|
4418
|
+
size,
|
|
4419
|
+
thickness,
|
|
4420
|
+
format = "decimal",
|
|
4421
|
+
centerLabel,
|
|
4422
|
+
centerValue,
|
|
4423
|
+
showLegend = true,
|
|
4424
|
+
footer
|
|
4425
|
+
}) {
|
|
4426
|
+
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
4427
|
+
const total = positiveSegments.reduce((sum, segment) => sum + segment.value, 0);
|
|
4428
|
+
const resolvedSize = size ?? Math.min(162, Math.max(128, height - 44), Math.max(128, width * 0.48));
|
|
4429
|
+
const resolvedThickness = thickness ?? Math.max(20, Math.round(resolvedSize * 0.18));
|
|
4430
|
+
const outerRadius = resolvedSize / 2 - 2;
|
|
4431
|
+
const innerRadius = Math.max(18, outerRadius - resolvedThickness);
|
|
4432
|
+
const cx = resolvedSize / 2;
|
|
4433
|
+
const cy = resolvedSize / 2;
|
|
4434
|
+
let cursor = -90;
|
|
4435
|
+
const resolvedCenterValue = centerValue ?? (centerLabel != null ? formatChartValue(total, format) : void 0);
|
|
4436
|
+
const paths = positiveSegments.map((segment, index) => {
|
|
4437
|
+
const rawSpan = total > 0 ? segment.value / total * 360 : 0;
|
|
4438
|
+
const gap = positiveSegments.length > 1 ? Math.min(1.5, rawSpan * 0.28) : 0;
|
|
4439
|
+
const start = cursor + gap / 2;
|
|
4440
|
+
const end = cursor + rawSpan - gap / 2;
|
|
4441
|
+
cursor += rawSpan;
|
|
4442
|
+
if (end <= start) return null;
|
|
4443
|
+
return React.createElement("path", {
|
|
4444
|
+
key: `donut-segment-${segment.label}-${index}`,
|
|
4445
|
+
d: donutArcPath(cx, cy, outerRadius, innerRadius, start, end),
|
|
4446
|
+
fill: chartColor(segment.color, c, index)
|
|
4447
|
+
});
|
|
4448
|
+
}).filter(Boolean);
|
|
4449
|
+
const legend = showLegend && positiveSegments.length > 0 && React.createElement("div", {
|
|
4450
|
+
style: {
|
|
4451
|
+
display: "flex",
|
|
4452
|
+
flexDirection: "column",
|
|
4453
|
+
gap: 8,
|
|
4454
|
+
flex: 1,
|
|
4455
|
+
minWidth: 112
|
|
4456
|
+
}
|
|
4457
|
+
}, ...positiveSegments.map((segment, index) => React.createElement(
|
|
4458
|
+
"div",
|
|
4459
|
+
{
|
|
4460
|
+
key: `donut-legend-${segment.label}-${index}`,
|
|
4461
|
+
style: {
|
|
4462
|
+
display: "flex",
|
|
4463
|
+
alignItems: "center",
|
|
4464
|
+
gap: 8,
|
|
4465
|
+
minWidth: 0
|
|
4466
|
+
}
|
|
4467
|
+
},
|
|
4468
|
+
React.createElement("span", {
|
|
4469
|
+
style: {
|
|
4470
|
+
display: "flex",
|
|
4471
|
+
width: 10,
|
|
4472
|
+
height: 10,
|
|
4473
|
+
borderRadius: 3,
|
|
4474
|
+
backgroundColor: chartColor(segment.color, c, index),
|
|
4475
|
+
flexShrink: 0
|
|
4476
|
+
}
|
|
4477
|
+
}),
|
|
4478
|
+
React.createElement("span", {
|
|
4479
|
+
style: {
|
|
4480
|
+
...typography.tiny,
|
|
4481
|
+
...textFitStyle(),
|
|
4482
|
+
color: c.textSecondary,
|
|
4483
|
+
flex: 1
|
|
4484
|
+
}
|
|
4485
|
+
}, segment.label),
|
|
4486
|
+
React.createElement("span", {
|
|
4487
|
+
style: {
|
|
4488
|
+
...typography.tiny,
|
|
4489
|
+
color: c.textPrimary,
|
|
4490
|
+
fontFamily: "JetBrains Mono",
|
|
4491
|
+
fontWeight: 850,
|
|
4492
|
+
flexShrink: 0
|
|
4493
|
+
}
|
|
4494
|
+
}, segment.valueLabel ?? formatChartValue(segment.value, format))
|
|
4495
|
+
)));
|
|
4496
|
+
return ChartFrame({
|
|
4497
|
+
c,
|
|
4498
|
+
title,
|
|
4499
|
+
subtitle,
|
|
4500
|
+
footer,
|
|
4501
|
+
width,
|
|
4502
|
+
height,
|
|
4503
|
+
padding: 16,
|
|
4504
|
+
children: React.createElement(
|
|
4505
|
+
"div",
|
|
4506
|
+
{
|
|
4507
|
+
style: {
|
|
4508
|
+
display: "flex",
|
|
4509
|
+
alignItems: "center",
|
|
4510
|
+
justifyContent: showLegend ? "space-between" : "center",
|
|
4511
|
+
gap: 18,
|
|
4512
|
+
minHeight: resolvedSize,
|
|
4513
|
+
width: "100%"
|
|
4514
|
+
}
|
|
4515
|
+
},
|
|
4516
|
+
React.createElement(
|
|
4517
|
+
"div",
|
|
4518
|
+
{
|
|
4519
|
+
style: {
|
|
4520
|
+
position: "relative",
|
|
4521
|
+
display: "flex",
|
|
4522
|
+
width: resolvedSize,
|
|
4523
|
+
height: resolvedSize,
|
|
4524
|
+
flexShrink: 0
|
|
4525
|
+
}
|
|
4526
|
+
},
|
|
4527
|
+
React.createElement(
|
|
4528
|
+
"svg",
|
|
4529
|
+
{
|
|
4530
|
+
width: resolvedSize,
|
|
4531
|
+
height: resolvedSize,
|
|
4532
|
+
viewBox: `0 0 ${resolvedSize} ${resolvedSize}`
|
|
4533
|
+
},
|
|
4534
|
+
positiveSegments.length === 0 ? React.createElement("circle", {
|
|
4535
|
+
cx,
|
|
4536
|
+
cy,
|
|
4537
|
+
r: (outerRadius + innerRadius) / 2,
|
|
4538
|
+
fill: "none",
|
|
4539
|
+
stroke: c.borderLight,
|
|
4540
|
+
strokeWidth: resolvedThickness
|
|
4541
|
+
}) : paths
|
|
4542
|
+
),
|
|
4543
|
+
(centerLabel != null || resolvedCenterValue != null) && React.createElement(
|
|
4544
|
+
"div",
|
|
4545
|
+
{
|
|
4546
|
+
style: {
|
|
4547
|
+
position: "absolute",
|
|
4548
|
+
inset: resolvedThickness,
|
|
4549
|
+
display: "flex",
|
|
4550
|
+
flexDirection: "column",
|
|
4551
|
+
alignItems: "center",
|
|
4552
|
+
justifyContent: "center",
|
|
4553
|
+
gap: 3,
|
|
4554
|
+
textAlign: "center"
|
|
4555
|
+
}
|
|
4556
|
+
},
|
|
4557
|
+
resolvedCenterValue != null && React.createElement("div", {
|
|
4558
|
+
style: {
|
|
4559
|
+
...typography.small,
|
|
4560
|
+
color: c.textPrimary,
|
|
4561
|
+
fontFamily: "JetBrains Mono",
|
|
4562
|
+
fontSize: 18,
|
|
4563
|
+
fontWeight: 900,
|
|
4564
|
+
lineHeight: 1.05,
|
|
4565
|
+
...textFitStyle("center")
|
|
4566
|
+
}
|
|
4567
|
+
}, resolvedCenterValue),
|
|
4568
|
+
centerLabel != null && React.createElement("div", {
|
|
4569
|
+
style: {
|
|
4570
|
+
...typography.tiny,
|
|
4571
|
+
color: c.textMuted,
|
|
4572
|
+
lineHeight: 1.2,
|
|
4573
|
+
...textFitStyle("center")
|
|
4574
|
+
}
|
|
4575
|
+
}, centerLabel)
|
|
4576
|
+
)
|
|
4577
|
+
),
|
|
4578
|
+
legend
|
|
4579
|
+
)
|
|
4580
|
+
});
|
|
4581
|
+
}
|
|
3810
4582
|
function StackedBar({
|
|
3811
4583
|
segments,
|
|
3812
4584
|
c,
|
|
@@ -5442,6 +6214,7 @@ export {
|
|
|
5442
6214
|
DashedLine,
|
|
5443
6215
|
DataTable,
|
|
5444
6216
|
DetailList,
|
|
6217
|
+
DonutChart,
|
|
5445
6218
|
DotPoint,
|
|
5446
6219
|
EquationCard,
|
|
5447
6220
|
Flow,
|
|
@@ -5450,6 +6223,7 @@ export {
|
|
|
5450
6223
|
GraphDiagram,
|
|
5451
6224
|
Grid,
|
|
5452
6225
|
Heatmap,
|
|
6226
|
+
Icon,
|
|
5453
6227
|
IntervalPlot,
|
|
5454
6228
|
KeyValueList,
|
|
5455
6229
|
LayeredNetwork,
|
|
@@ -5479,8 +6253,10 @@ export {
|
|
|
5479
6253
|
Tile,
|
|
5480
6254
|
TileGrid,
|
|
5481
6255
|
TiledMatrix,
|
|
6256
|
+
Timeline,
|
|
5482
6257
|
TitleBar,
|
|
5483
6258
|
ToneStrip,
|
|
6259
|
+
TreeDiagram,
|
|
5484
6260
|
ValuePill,
|
|
5485
6261
|
VectorArrow,
|
|
5486
6262
|
VectorSegment,
|