vizmatic 0.1.42 → 0.3.0
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 +23 -4
- package/README.md +108 -2
- package/ROADMAP.md +10 -8
- package/assets/THIRD_PARTY_LICENSES.md +12 -0
- package/assets/licenses/Apache-2.0.txt +176 -0
- package/assets/licenses/harfbuzzjs-LICENSE.txt +22 -0
- package/dist/cli.js +28 -11214
- package/dist/index.cjs +2862 -262
- package/dist/index.d.cts +237 -10
- package/dist/index.d.ts +237 -10
- package/dist/index.js +2788 -191
- package/examples/README.md +4 -0
- package/examples/orthogonal-routing.tsx +25 -0
- package/examples/pareto-bar-chart.tsx +44 -0
- package/examples/pie-chart.tsx +46 -0
- package/examples/website-workflow.tsx +38 -0
- package/package.json +18 -13
package/dist/index.cjs
CHANGED
|
@@ -36,9 +36,13 @@ __export(index_exports, {
|
|
|
36
36
|
Badge: () => Badge,
|
|
37
37
|
BadgePill: () => BadgePill,
|
|
38
38
|
BarChart: () => BarChart,
|
|
39
|
+
Board: () => Board,
|
|
39
40
|
Box: () => Box,
|
|
41
|
+
CANVAS_ITEM_COMPONENT: () => CANVAS_ITEM_COMPONENT,
|
|
42
|
+
CHECK_DIAGNOSTIC_CODES: () => CHECK_DIAGNOSTIC_CODES,
|
|
40
43
|
CalloutCard: () => CalloutCard,
|
|
41
44
|
Canvas: () => Canvas,
|
|
45
|
+
CanvasItem: () => CanvasItem,
|
|
42
46
|
CanvasOverflowError: () => CanvasOverflowError,
|
|
43
47
|
Card: () => Card,
|
|
44
48
|
ChartFrame: () => ChartFrame,
|
|
@@ -71,7 +75,9 @@ __export(index_exports, {
|
|
|
71
75
|
MetricCard: () => MetricCard,
|
|
72
76
|
MiniBarChart: () => MiniBarChart,
|
|
73
77
|
Panel: () => Panel,
|
|
78
|
+
ParetoBarChart: () => ParetoBarChart,
|
|
74
79
|
ParetoChart: () => ParetoChart,
|
|
80
|
+
PieChart: () => PieChart,
|
|
75
81
|
Pipeline: () => Pipeline,
|
|
76
82
|
ProgressList: () => ProgressList,
|
|
77
83
|
ProgressRow: () => ProgressRow,
|
|
@@ -104,6 +110,7 @@ __export(index_exports, {
|
|
|
104
110
|
WindowFrame: () => WindowFrame,
|
|
105
111
|
analyzeAnimationCadence: () => analyzeAnimationCadence,
|
|
106
112
|
canvas: () => canvas,
|
|
113
|
+
checkFrame: () => checkFrame,
|
|
107
114
|
colors: () => colors,
|
|
108
115
|
createPlotArea: () => createPlotArea,
|
|
109
116
|
cropPixels: () => cropPixels,
|
|
@@ -130,6 +137,8 @@ __export(index_exports, {
|
|
|
130
137
|
gradients: () => gradients,
|
|
131
138
|
heatColor: () => heatColor,
|
|
132
139
|
hold: () => hold,
|
|
140
|
+
importD2Graph: () => importD2Graph,
|
|
141
|
+
importMermaidGraph: () => importMermaidGraph,
|
|
133
142
|
keyframe: () => keyframe,
|
|
134
143
|
loadAdditionalAsset: () => loadAdditionalAsset,
|
|
135
144
|
normalizeWatermark: () => normalizeWatermark,
|
|
@@ -353,7 +362,7 @@ function getToneColor(tone, c) {
|
|
|
353
362
|
dark: c.textSecondary
|
|
354
363
|
}[tone];
|
|
355
364
|
}
|
|
356
|
-
function getReadableToneColor(tone, c, background = c.bgCard) {
|
|
365
|
+
function getReadableToneColor(tone, c, background = c.bgCard, backdrop = c.bgCard) {
|
|
357
366
|
const semanticColor = {
|
|
358
367
|
blue: "secondary",
|
|
359
368
|
purple: "primary",
|
|
@@ -369,7 +378,7 @@ function getReadableToneColor(tone, c, background = c.bgCard) {
|
|
|
369
378
|
dark: "neutral"
|
|
370
379
|
};
|
|
371
380
|
const color = getReadableColor(semanticColor[tone], c);
|
|
372
|
-
return colorContrast(color, background,
|
|
381
|
+
return colorContrast(color, background, backdrop) >= 4.5 ? color : getReadableTextColor(background, c, backdrop);
|
|
373
382
|
}
|
|
374
383
|
function getToneFill(tone, c) {
|
|
375
384
|
if (c.preset !== "engineering") return `${getToneColor(tone, c)}16`;
|
|
@@ -532,12 +541,12 @@ function colorContrast(left, right, rightBackdrop) {
|
|
|
532
541
|
if (leftLuminance == null || rightLuminance == null) return 0;
|
|
533
542
|
return (Math.max(leftLuminance, rightLuminance) + 0.05) / (Math.min(leftLuminance, rightLuminance) + 0.05);
|
|
534
543
|
}
|
|
535
|
-
function getReadableTextColor(background, c) {
|
|
536
|
-
if (colorLuminance(background,
|
|
544
|
+
function getReadableTextColor(background, c, backdrop = c.bgCard) {
|
|
545
|
+
if (colorLuminance(background, backdrop) == null) return c.textPrimary;
|
|
537
546
|
const candidates = [c.textPrimary, c.textOnColor, c.bg, "#000000"];
|
|
538
|
-
const readable = candidates.find((candidate) => colorContrast(candidate, background,
|
|
547
|
+
const readable = candidates.find((candidate) => colorContrast(candidate, background, backdrop) >= 4.5);
|
|
539
548
|
if (readable) return readable;
|
|
540
|
-
return candidates.reduce((best, candidate) => colorContrast(candidate, background,
|
|
549
|
+
return candidates.reduce((best, candidate) => colorContrast(candidate, background, backdrop) > colorContrast(best, background, backdrop) ? candidate : best);
|
|
541
550
|
}
|
|
542
551
|
function getGradient(name) {
|
|
543
552
|
const map = {
|
|
@@ -579,6 +588,94 @@ function lerpColor(a, b, t) {
|
|
|
579
588
|
return `#${(rr << 16 | rg << 8 | rb).toString(16).padStart(6, "0")}`;
|
|
580
589
|
}
|
|
581
590
|
|
|
591
|
+
// src/primitives.ts
|
|
592
|
+
var primitives_exports = {};
|
|
593
|
+
__export(primitives_exports, {
|
|
594
|
+
Arrow: () => Arrow,
|
|
595
|
+
ArrowMarkerDef: () => ArrowMarkerDef,
|
|
596
|
+
AxisPlot: () => AxisPlot,
|
|
597
|
+
Badge: () => Badge,
|
|
598
|
+
BadgePill: () => BadgePill,
|
|
599
|
+
BarChart: () => BarChart,
|
|
600
|
+
Board: () => Board,
|
|
601
|
+
Box: () => Box,
|
|
602
|
+
CANVAS_ITEM_COMPONENT: () => CANVAS_ITEM_COMPONENT,
|
|
603
|
+
CalloutCard: () => CalloutCard,
|
|
604
|
+
Canvas: () => Canvas,
|
|
605
|
+
CanvasItem: () => CanvasItem,
|
|
606
|
+
Card: () => Card,
|
|
607
|
+
ChartFrame: () => ChartFrame,
|
|
608
|
+
CodeBlock: () => CodeBlock,
|
|
609
|
+
Column: () => Column,
|
|
610
|
+
Comparison: () => Comparison,
|
|
611
|
+
Connector: () => Connector,
|
|
612
|
+
DashedLine: () => DashedLine,
|
|
613
|
+
DataTable: () => DataTable,
|
|
614
|
+
DataflowDiagram: () => DataflowDiagram,
|
|
615
|
+
DeploymentDiagram: () => DeploymentDiagram,
|
|
616
|
+
DetailList: () => DetailList,
|
|
617
|
+
DonutChart: () => DonutChart,
|
|
618
|
+
DotPoint: () => DotPoint,
|
|
619
|
+
EquationCard: () => EquationCard,
|
|
620
|
+
Flow: () => Flow,
|
|
621
|
+
FlowArrow: () => FlowArrow,
|
|
622
|
+
GradientChip: () => GradientChip,
|
|
623
|
+
GraphDiagram: () => GraphDiagram,
|
|
624
|
+
Grid: () => Grid,
|
|
625
|
+
Heatmap: () => Heatmap,
|
|
626
|
+
Icon: () => Icon,
|
|
627
|
+
IntervalPlot: () => IntervalPlot,
|
|
628
|
+
KeyValueList: () => KeyValueList,
|
|
629
|
+
LayeredNetwork: () => LayeredNetwork,
|
|
630
|
+
Legend: () => Legend,
|
|
631
|
+
LineChart: () => LineChart,
|
|
632
|
+
MathText: () => MathText,
|
|
633
|
+
Matrix: () => Matrix,
|
|
634
|
+
MetricCard: () => MetricCard,
|
|
635
|
+
MiniBarChart: () => MiniBarChart,
|
|
636
|
+
Panel: () => Panel,
|
|
637
|
+
ParetoBarChart: () => ParetoBarChart,
|
|
638
|
+
ParetoChart: () => ParetoChart,
|
|
639
|
+
PieChart: () => PieChart,
|
|
640
|
+
Pipeline: () => Pipeline,
|
|
641
|
+
ProgressList: () => ProgressList,
|
|
642
|
+
ProgressRow: () => ProgressRow,
|
|
643
|
+
QuadrantChart: () => QuadrantChart,
|
|
644
|
+
Row: () => Row,
|
|
645
|
+
ScatterPlot: () => ScatterPlot,
|
|
646
|
+
Scene: () => Scene,
|
|
647
|
+
SequenceDiagram: () => SequenceDiagram,
|
|
648
|
+
Stack: () => Stack,
|
|
649
|
+
StackedBar: () => StackedBar,
|
|
650
|
+
StatusList: () => StatusList,
|
|
651
|
+
StatusRow: () => StatusRow,
|
|
652
|
+
StepCard: () => StepCard,
|
|
653
|
+
SvgFrame: () => SvgFrame,
|
|
654
|
+
SvgMathText: () => SvgMathText,
|
|
655
|
+
SvgPoint: () => SvgPoint,
|
|
656
|
+
TextLabel: () => TextLabel,
|
|
657
|
+
Tile: () => Tile,
|
|
658
|
+
TileGrid: () => TileGrid,
|
|
659
|
+
TiledMatrix: () => TiledMatrix,
|
|
660
|
+
Timeline: () => Timeline,
|
|
661
|
+
TitleBar: () => TitleBar,
|
|
662
|
+
ToneStrip: () => ToneStrip,
|
|
663
|
+
TransformerTopology: () => TransformerTopology,
|
|
664
|
+
TreeDiagram: () => TreeDiagram,
|
|
665
|
+
ValuePill: () => ValuePill,
|
|
666
|
+
VectorArrow: () => VectorArrow,
|
|
667
|
+
VectorSegment: () => VectorSegment,
|
|
668
|
+
WindowFrame: () => WindowFrame,
|
|
669
|
+
createPlotArea: () => createPlotArea,
|
|
670
|
+
defineDiagramIcon: () => defineDiagramIcon,
|
|
671
|
+
defineIconRegistry: () => defineIconRegistry,
|
|
672
|
+
defineIllustration: () => defineIllustration,
|
|
673
|
+
formatMathText: () => formatMathText,
|
|
674
|
+
formatTensorShape: () => formatTensorShape,
|
|
675
|
+
getToneColor: () => getToneColor,
|
|
676
|
+
getToneGradient: () => getToneGradient
|
|
677
|
+
});
|
|
678
|
+
|
|
582
679
|
// src/primitives/layout.ts
|
|
583
680
|
var import_react = __toESM(require("react"), 1);
|
|
584
681
|
|
|
@@ -2265,6 +2362,7 @@ function MiniBarChart({
|
|
|
2265
2362
|
...compactChildren([
|
|
2266
2363
|
showValues && import_react4.default.createElement("div", {
|
|
2267
2364
|
style: {
|
|
2365
|
+
display: "flex",
|
|
2268
2366
|
color: getReadableToneColor(tone, c),
|
|
2269
2367
|
fontFamily: "JetBrains Mono",
|
|
2270
2368
|
fontSize,
|
|
@@ -2284,6 +2382,7 @@ function MiniBarChart({
|
|
|
2284
2382
|
}),
|
|
2285
2383
|
import_react4.default.createElement("div", {
|
|
2286
2384
|
style: {
|
|
2385
|
+
display: "flex",
|
|
2287
2386
|
color: c.textMuted,
|
|
2288
2387
|
fontFamily: "JetBrains Mono",
|
|
2289
2388
|
fontSize,
|
|
@@ -2654,7 +2753,7 @@ function renderComparisonDivider(divider, c, key) {
|
|
|
2654
2753
|
);
|
|
2655
2754
|
}
|
|
2656
2755
|
function Comparison({
|
|
2657
|
-
sides,
|
|
2756
|
+
sides: sides2,
|
|
2658
2757
|
c,
|
|
2659
2758
|
divider = false,
|
|
2660
2759
|
gap = 14,
|
|
@@ -2663,7 +2762,7 @@ function Comparison({
|
|
|
2663
2762
|
align = "stretch",
|
|
2664
2763
|
math = false
|
|
2665
2764
|
}) {
|
|
2666
|
-
const children =
|
|
2765
|
+
const children = sides2.flatMap((side, index) => {
|
|
2667
2766
|
const tone = side.tone ?? "blue";
|
|
2668
2767
|
const panel = import_react4.default.createElement(
|
|
2669
2768
|
import_react4.default.Fragment,
|
|
@@ -2693,7 +2792,7 @@ function Comparison({
|
|
|
2693
2792
|
) : side.children ?? DetailList({ items: side.lines ?? [], c, tone, math })
|
|
2694
2793
|
})
|
|
2695
2794
|
);
|
|
2696
|
-
if (divider && index <
|
|
2795
|
+
if (divider && index < sides2.length - 1) {
|
|
2697
2796
|
return [panel, renderComparisonDivider(divider, c, `comparison-divider-${index}`)];
|
|
2698
2797
|
}
|
|
2699
2798
|
return [panel];
|
|
@@ -2930,7 +3029,11 @@ function StatusRow({
|
|
|
2930
3029
|
}) {
|
|
2931
3030
|
const resolvedTone = tone ?? statusTones[status];
|
|
2932
3031
|
const accent = getToneColor(resolvedTone, c);
|
|
2933
|
-
const
|
|
3032
|
+
const markerAlpha = 38 / 255;
|
|
3033
|
+
const rowAlpha = boxed ? 18 / 255 : 0;
|
|
3034
|
+
const markerBackgroundAlpha = Math.round((rowAlpha + markerAlpha * (1 - rowAlpha)) * 255);
|
|
3035
|
+
const markerBackground = `${accent}${markerBackgroundAlpha.toString(16).padStart(2, "0")}`;
|
|
3036
|
+
const accentText = getReadableToneColor(resolvedTone, c, markerBackground, c.bgCard);
|
|
2934
3037
|
const glyph = statusGlyphs[status];
|
|
2935
3038
|
const marker = import_react5.default.createElement("div", {
|
|
2936
3039
|
style: {
|
|
@@ -3350,8 +3453,480 @@ function Flow({
|
|
|
3350
3453
|
}
|
|
3351
3454
|
|
|
3352
3455
|
// src/primitives/diagrams.ts
|
|
3353
|
-
var
|
|
3456
|
+
var import_react7 = __toESM(require("react"), 1);
|
|
3354
3457
|
var import_dagre = __toESM(require("@dagrejs/dagre"), 1);
|
|
3458
|
+
|
|
3459
|
+
// src/svg-accessibility.ts
|
|
3460
|
+
var import_react6 = require("react");
|
|
3461
|
+
var SVG_ACCESSIBILITY_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.svgAccessibilityComponent");
|
|
3462
|
+
function componentHasSvgMetadata(type) {
|
|
3463
|
+
return typeof type === "function" && type[SVG_ACCESSIBILITY_COMPONENT] === true;
|
|
3464
|
+
}
|
|
3465
|
+
function svgToken(value) {
|
|
3466
|
+
if (value.length === 0) return "empty";
|
|
3467
|
+
return Array.from(value, (character) => {
|
|
3468
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
3469
|
+
return /^[A-Za-z0-9.-]$/.test(character) ? character : `_u${codePoint.toString(16)}_`;
|
|
3470
|
+
}).join("");
|
|
3471
|
+
}
|
|
3472
|
+
function textProperty(props, name) {
|
|
3473
|
+
const value = props[name];
|
|
3474
|
+
return typeof value === "string" ? value : "";
|
|
3475
|
+
}
|
|
3476
|
+
function encodedTextProperty(props, name) {
|
|
3477
|
+
const value = textProperty(props, name);
|
|
3478
|
+
try {
|
|
3479
|
+
return decodeURIComponent(value);
|
|
3480
|
+
} catch {
|
|
3481
|
+
return value;
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
function prepareAccessibleSvg(element) {
|
|
3485
|
+
const graphs = [];
|
|
3486
|
+
const explicitIds = /* @__PURE__ */ new Set();
|
|
3487
|
+
const visit = (node, graph) => {
|
|
3488
|
+
if (Array.isArray(node)) return node.map((child) => visit(child, graph));
|
|
3489
|
+
if (!(0, import_react6.isValidElement)(node)) return node;
|
|
3490
|
+
const component = node.type;
|
|
3491
|
+
if (componentHasSvgMetadata(component)) {
|
|
3492
|
+
return visit(component(node.props), graph);
|
|
3493
|
+
}
|
|
3494
|
+
const props = node.props;
|
|
3495
|
+
const title = textProperty(props, "data-vizmatic-svg-title");
|
|
3496
|
+
const isGraphRoot = title.length > 0;
|
|
3497
|
+
let activeGraph = graph;
|
|
3498
|
+
let elementKey = node.key;
|
|
3499
|
+
if (isGraphRoot) {
|
|
3500
|
+
const explicitId = textProperty(props, "data-vizmatic-svg-id");
|
|
3501
|
+
if (explicitId) {
|
|
3502
|
+
if (explicitIds.has(explicitId)) {
|
|
3503
|
+
throw new Error(`GraphDiagram SVG id "${explicitId}" must be unique in one exported SVG.`);
|
|
3504
|
+
}
|
|
3505
|
+
explicitIds.add(explicitId);
|
|
3506
|
+
}
|
|
3507
|
+
const index = graphs.length;
|
|
3508
|
+
const token = explicitId ? `id-${svgToken(explicitId)}` : `index-${index}`;
|
|
3509
|
+
activeGraph = {
|
|
3510
|
+
index,
|
|
3511
|
+
token,
|
|
3512
|
+
detectionKey: `vizmatic-graph-${index}`,
|
|
3513
|
+
title,
|
|
3514
|
+
description: textProperty(props, "data-vizmatic-svg-description"),
|
|
3515
|
+
nodes: [],
|
|
3516
|
+
edges: []
|
|
3517
|
+
};
|
|
3518
|
+
graphs.push(activeGraph);
|
|
3519
|
+
elementKey = activeGraph.detectionKey;
|
|
3520
|
+
}
|
|
3521
|
+
let nextProps;
|
|
3522
|
+
if (activeGraph && Object.hasOwn(props, "data-vizmatic-graph-node-id")) {
|
|
3523
|
+
const id = textProperty(props, "data-vizmatic-graph-node-id");
|
|
3524
|
+
const label = textProperty(props, "data-vizmatic-graph-node-label") || id;
|
|
3525
|
+
const detail = textProperty(props, "data-vizmatic-graph-node-detail");
|
|
3526
|
+
activeGraph.nodes.push({
|
|
3527
|
+
id,
|
|
3528
|
+
label,
|
|
3529
|
+
detail,
|
|
3530
|
+
title: textProperty(props, "data-vizmatic-graph-node-title") || label,
|
|
3531
|
+
href: textProperty(props, "data-vizmatic-graph-node-href") || void 0
|
|
3532
|
+
});
|
|
3533
|
+
elementKey = `${activeGraph.detectionKey}-node-${svgToken(id)}`;
|
|
3534
|
+
} else if (activeGraph && textProperty(props, "data-vizmatic-graph-edge-id")) {
|
|
3535
|
+
const id = encodedTextProperty(props, "data-vizmatic-graph-edge-id");
|
|
3536
|
+
activeGraph.edges.push({
|
|
3537
|
+
id,
|
|
3538
|
+
from: encodedTextProperty(props, "data-vizmatic-graph-edge-from"),
|
|
3539
|
+
to: encodedTextProperty(props, "data-vizmatic-graph-edge-to"),
|
|
3540
|
+
label: encodedTextProperty(props, "data-vizmatic-graph-edge-label"),
|
|
3541
|
+
title: encodedTextProperty(props, "data-vizmatic-graph-edge-title"),
|
|
3542
|
+
path: textProperty(props, "d"),
|
|
3543
|
+
href: encodedTextProperty(props, "data-vizmatic-graph-edge-href") || void 0
|
|
3544
|
+
});
|
|
3545
|
+
elementKey = `${activeGraph.detectionKey}-edge-${svgToken(id)}`;
|
|
3546
|
+
}
|
|
3547
|
+
const children = props.children;
|
|
3548
|
+
if (children === void 0) {
|
|
3549
|
+
if (isGraphRoot) {
|
|
3550
|
+
nextProps = { ...props, "data-vizmatic-svg-instance": activeGraph?.token };
|
|
3551
|
+
return (0, import_react6.cloneElement)(node, { ...nextProps, key: elementKey });
|
|
3552
|
+
}
|
|
3553
|
+
return node;
|
|
3554
|
+
}
|
|
3555
|
+
const preparedChildren = visit(children, activeGraph);
|
|
3556
|
+
nextProps = isGraphRoot ? { ...props, "data-vizmatic-svg-instance": activeGraph?.token } : { ...props };
|
|
3557
|
+
return (0, import_react6.cloneElement)(
|
|
3558
|
+
node,
|
|
3559
|
+
{ ...nextProps, key: elementKey },
|
|
3560
|
+
preparedChildren
|
|
3561
|
+
);
|
|
3562
|
+
};
|
|
3563
|
+
return { element: visit(element), graphs };
|
|
3564
|
+
}
|
|
3565
|
+
function escapeXml(value) {
|
|
3566
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
3567
|
+
}
|
|
3568
|
+
function attribute(name, value) {
|
|
3569
|
+
return `${name}="${escapeXml(value)}"`;
|
|
3570
|
+
}
|
|
3571
|
+
function graphBaseId(graph) {
|
|
3572
|
+
return `vizmatic-graph-${graph.token}`;
|
|
3573
|
+
}
|
|
3574
|
+
function nodeId(graph, node) {
|
|
3575
|
+
return `${graphBaseId(graph)}-node-${svgToken(node.id)}`;
|
|
3576
|
+
}
|
|
3577
|
+
function edgeId(graph, edge) {
|
|
3578
|
+
return `${graphBaseId(graph)}-edge-${svgToken(edge.id)}`;
|
|
3579
|
+
}
|
|
3580
|
+
function labelForEdge(graph, edge) {
|
|
3581
|
+
const nodes = new Map(graph.nodes.map((node) => [node.id, node.label]));
|
|
3582
|
+
const from = nodes.get(edge.from) ?? edge.from;
|
|
3583
|
+
const to = nodes.get(edge.to) ?? edge.to;
|
|
3584
|
+
return edge.title || (edge.label ? `${from} to ${to}: ${edge.label}` : `${from} to ${to}`);
|
|
3585
|
+
}
|
|
3586
|
+
function descriptionForEdge(graph, edge) {
|
|
3587
|
+
const nodes = new Map(graph.nodes.map((node) => [node.id, node.label]));
|
|
3588
|
+
const from = nodes.get(edge.from) ?? edge.from;
|
|
3589
|
+
const to = nodes.get(edge.to) ?? edge.to;
|
|
3590
|
+
return `Relationship from ${from} to ${to}${edge.label ? `, labeled ${edge.label}` : ""}.`;
|
|
3591
|
+
}
|
|
3592
|
+
function nodeGroup(graph, node, layout) {
|
|
3593
|
+
const id = nodeId(graph, node);
|
|
3594
|
+
const label = node.detail ? `${node.label}: ${node.detail}` : node.label;
|
|
3595
|
+
const description = node.detail || node.label;
|
|
3596
|
+
const titleId = `${id}-title`;
|
|
3597
|
+
const descriptionId = `${id}-description`;
|
|
3598
|
+
const accessible = `<g ${attribute("id", id)} role="group" aria-labelledby="${titleId}" aria-describedby="${descriptionId}"><title id="${titleId}">${escapeXml(node.title || node.label)}</title><desc id="${descriptionId}">${escapeXml(description)}</desc>`;
|
|
3599
|
+
if (!layout) return `${accessible}</g>`;
|
|
3600
|
+
const rect = `<rect x="${layout.left}" y="${layout.top}" width="${layout.width}" height="${layout.height}" fill="transparent" pointer-events="all"/>`;
|
|
3601
|
+
const hitTarget = node.href ? `<a ${attribute("href", node.href)} role="link" tabindex="0" ${attribute("aria-label", label)}>${rect}</a>` : rect;
|
|
3602
|
+
return `${accessible}${hitTarget}</g>`;
|
|
3603
|
+
}
|
|
3604
|
+
function edgeGroup(graph, edge, root) {
|
|
3605
|
+
const id = edgeId(graph, edge);
|
|
3606
|
+
const title = labelForEdge(graph, edge);
|
|
3607
|
+
const titleId = `${id}-title`;
|
|
3608
|
+
const descriptionId = `${id}-description`;
|
|
3609
|
+
const accessible = `<g ${attribute("id", id)} role="group" aria-labelledby="${titleId}" aria-describedby="${descriptionId}"><title id="${titleId}">${escapeXml(title)}</title><desc id="${descriptionId}">${escapeXml(descriptionForEdge(graph, edge))}</desc>`;
|
|
3610
|
+
if (!root || !edge.path) return `${accessible}</g>`;
|
|
3611
|
+
const path = `<path d="${escapeXml(edge.path)}" transform="translate(${root.left} ${root.top})" fill="none" stroke="transparent" stroke-width="14" stroke-linecap="round" pointer-events="stroke"/>`;
|
|
3612
|
+
const hitTarget = edge.href ? `<a ${attribute("href", edge.href)} role="link" tabindex="0" ${attribute("aria-label", title)}>${path}</a>` : path;
|
|
3613
|
+
return `${accessible}${hitTarget}</g>`;
|
|
3614
|
+
}
|
|
3615
|
+
function addSvgAccessibility(svg, graphs, layoutNodes) {
|
|
3616
|
+
if (graphs.length === 0) return svg;
|
|
3617
|
+
const title = graphs.map((graph) => graph.title).join(". ");
|
|
3618
|
+
const description = graphs.map((graph) => `${graph.title}. ${graph.description}`).join(" ");
|
|
3619
|
+
const hasLinks = graphs.some(
|
|
3620
|
+
(graph) => graph.nodes.some((node) => node.href) || graph.edges.some((edge) => edge.href)
|
|
3621
|
+
);
|
|
3622
|
+
const rootTitleId = "vizmatic-svg-title";
|
|
3623
|
+
const rootDescriptionId = "vizmatic-svg-description";
|
|
3624
|
+
const groupMarkup = graphs.map((graph) => {
|
|
3625
|
+
const baseId = graphBaseId(graph);
|
|
3626
|
+
const titleId = `${baseId}-title`;
|
|
3627
|
+
const descriptionId = `${baseId}-description`;
|
|
3628
|
+
const root = layoutNodes.find((node) => node.key === graph.detectionKey);
|
|
3629
|
+
const nodes = graph.nodes.map((item) => {
|
|
3630
|
+
const layout = layoutNodes.find((node) => node.key === `${graph.detectionKey}-node-${svgToken(item.id)}`);
|
|
3631
|
+
if (item.href && !layout) {
|
|
3632
|
+
throw new Error(`Could not resolve GraphDiagram node "${item.id}" bounds for SVG link export.`);
|
|
3633
|
+
}
|
|
3634
|
+
return nodeGroup(graph, item, layout);
|
|
3635
|
+
}).join("");
|
|
3636
|
+
const edges = graph.edges.map((item) => {
|
|
3637
|
+
if (item.href && !root) {
|
|
3638
|
+
throw new Error(`Could not resolve GraphDiagram bounds for SVG edge link export: "${item.id}".`);
|
|
3639
|
+
}
|
|
3640
|
+
return edgeGroup(graph, item, root);
|
|
3641
|
+
}).join("");
|
|
3642
|
+
return `<g ${attribute("id", baseId)} role="group" aria-labelledby="${titleId}" aria-describedby="${descriptionId}"><title id="${titleId}">${escapeXml(graph.title)}</title><desc id="${descriptionId}">${escapeXml(graph.description)}</desc>${nodes}${edges}</g>`;
|
|
3643
|
+
}).join("");
|
|
3644
|
+
const metadata = `<title id="${rootTitleId}">${escapeXml(title)}</title><desc id="${rootDescriptionId}">${escapeXml(description)}</desc>`;
|
|
3645
|
+
return svg.replace(
|
|
3646
|
+
/^<svg\b([^>]*)>/,
|
|
3647
|
+
(_match, attrs) => `<svg${attrs} role="${hasLinks ? "group" : "img"}" aria-labelledby="${rootTitleId}" aria-describedby="${rootDescriptionId}">${metadata}`
|
|
3648
|
+
).replace(/<\/svg>\s*$/, `${groupMarkup}</svg>`);
|
|
3649
|
+
}
|
|
3650
|
+
|
|
3651
|
+
// src/graph-routing.ts
|
|
3652
|
+
var EPSILON = 1e-3;
|
|
3653
|
+
var MAX_GRID_POINTS = 18e3;
|
|
3654
|
+
var MAX_SEARCH_STATES = 54e3;
|
|
3655
|
+
var MAX_TOTAL_SEARCH_STATES = 16e4;
|
|
3656
|
+
var MAX_ROUTED_EDGES = 256;
|
|
3657
|
+
var MAX_OBSTACLES = 64;
|
|
3658
|
+
var sides = ["right", "bottom", "left", "top"];
|
|
3659
|
+
function box(node, clearance = 0) {
|
|
3660
|
+
return {
|
|
3661
|
+
left: node.cx - node.width / 2 - clearance,
|
|
3662
|
+
right: node.cx + node.width / 2 + clearance,
|
|
3663
|
+
top: node.cy - node.height / 2 - clearance,
|
|
3664
|
+
bottom: node.cy + node.height / 2 + clearance
|
|
3665
|
+
};
|
|
3666
|
+
}
|
|
3667
|
+
function inside(point, obstacle) {
|
|
3668
|
+
return point.x > obstacle.left + EPSILON && point.x < obstacle.right - EPSILON && point.y > obstacle.top + EPSILON && point.y < obstacle.bottom - EPSILON;
|
|
3669
|
+
}
|
|
3670
|
+
function routingSegmentBlocked(a, b, obstacle) {
|
|
3671
|
+
if (Math.abs(a.y - b.y) < EPSILON) {
|
|
3672
|
+
return a.y > obstacle.top + EPSILON && a.y < obstacle.bottom - EPSILON && Math.max(a.x, b.x) > obstacle.left + EPSILON && Math.min(a.x, b.x) < obstacle.right - EPSILON;
|
|
3673
|
+
}
|
|
3674
|
+
if (Math.abs(a.x - b.x) < EPSILON) {
|
|
3675
|
+
return a.x > obstacle.left + EPSILON && a.x < obstacle.right - EPSILON && Math.max(a.y, b.y) > obstacle.top + EPSILON && Math.min(a.y, b.y) < obstacle.bottom - EPSILON;
|
|
3676
|
+
}
|
|
3677
|
+
return true;
|
|
3678
|
+
}
|
|
3679
|
+
function preferredSide(from, to) {
|
|
3680
|
+
if (Math.abs(to.cx - from.cx) >= Math.abs(to.cy - from.cy)) return to.cx >= from.cx ? "right" : "left";
|
|
3681
|
+
return to.cy >= from.cy ? "bottom" : "top";
|
|
3682
|
+
}
|
|
3683
|
+
function routingAnchor(node, side, offset = 0.5) {
|
|
3684
|
+
const bounds = box(node);
|
|
3685
|
+
if (side === "left" || side === "right") return { x: bounds[side], y: bounds.top + node.height * offset };
|
|
3686
|
+
return { x: bounds.left + node.width * offset, y: bounds[side] };
|
|
3687
|
+
}
|
|
3688
|
+
function outward(point, side, distance) {
|
|
3689
|
+
return {
|
|
3690
|
+
x: point.x + (side === "right" ? distance : side === "left" ? -distance : 0),
|
|
3691
|
+
y: point.y + (side === "bottom" ? distance : side === "top" ? -distance : 0)
|
|
3692
|
+
};
|
|
3693
|
+
}
|
|
3694
|
+
function simplify(points) {
|
|
3695
|
+
const result = [];
|
|
3696
|
+
for (const point of points) {
|
|
3697
|
+
const last = result[result.length - 1];
|
|
3698
|
+
if (last && Math.abs(last.x - point.x) < EPSILON && Math.abs(last.y - point.y) < EPSILON) continue;
|
|
3699
|
+
const previous = result[result.length - 2];
|
|
3700
|
+
if (previous && last && (previous.x === last.x && last.x === point.x || previous.y === last.y && last.y === point.y)) {
|
|
3701
|
+
result[result.length - 1] = point;
|
|
3702
|
+
} else result.push(point);
|
|
3703
|
+
}
|
|
3704
|
+
return result;
|
|
3705
|
+
}
|
|
3706
|
+
function overlappingLength(a, b, c, d) {
|
|
3707
|
+
if (a.y === b.y && c.y === d.y && Math.abs(a.y - c.y) < EPSILON) {
|
|
3708
|
+
return Math.max(0, Math.min(Math.max(a.x, b.x), Math.max(c.x, d.x)) - Math.max(Math.min(a.x, b.x), Math.min(c.x, d.x)));
|
|
3709
|
+
}
|
|
3710
|
+
if (a.x === b.x && c.x === d.x && Math.abs(a.x - c.x) < EPSILON) {
|
|
3711
|
+
return Math.max(0, Math.min(Math.max(a.y, b.y), Math.max(c.y, d.y)) - Math.max(Math.min(a.y, b.y), Math.min(c.y, d.y)));
|
|
3712
|
+
}
|
|
3713
|
+
return 0;
|
|
3714
|
+
}
|
|
3715
|
+
var MinQueue = class {
|
|
3716
|
+
items = [];
|
|
3717
|
+
get length() {
|
|
3718
|
+
return this.items.length;
|
|
3719
|
+
}
|
|
3720
|
+
push(value) {
|
|
3721
|
+
const items = this.items;
|
|
3722
|
+
items.push(value);
|
|
3723
|
+
let index = items.length - 1;
|
|
3724
|
+
while (index > 0) {
|
|
3725
|
+
const parent = index - 1 >> 1;
|
|
3726
|
+
if (items[parent].priority <= value.priority) break;
|
|
3727
|
+
items[index] = items[parent];
|
|
3728
|
+
index = parent;
|
|
3729
|
+
}
|
|
3730
|
+
items[index] = value;
|
|
3731
|
+
}
|
|
3732
|
+
pop() {
|
|
3733
|
+
const items = this.items;
|
|
3734
|
+
const first = items[0];
|
|
3735
|
+
const last = items.pop();
|
|
3736
|
+
if (items.length === 0) return first;
|
|
3737
|
+
let index = 0;
|
|
3738
|
+
while (index * 2 + 1 < items.length) {
|
|
3739
|
+
const left = index * 2 + 1;
|
|
3740
|
+
const right = left + 1;
|
|
3741
|
+
const child = right < items.length && items[right].priority < items[left].priority ? right : left;
|
|
3742
|
+
if (items[child].priority >= last.priority) break;
|
|
3743
|
+
items[index] = items[child];
|
|
3744
|
+
index = child;
|
|
3745
|
+
}
|
|
3746
|
+
items[index] = last;
|
|
3747
|
+
return first;
|
|
3748
|
+
}
|
|
3749
|
+
};
|
|
3750
|
+
function findPath(start, end, obstacles, width, height, previousRoutes, gap, budget) {
|
|
3751
|
+
const within = (point) => point.x >= 0 && point.x <= width && point.y >= 0 && point.y <= height;
|
|
3752
|
+
if (!within(start) || !within(end) || obstacles.some((obstacle) => inside(start, obstacle) || inside(end, obstacle))) {
|
|
3753
|
+
return { reason: "an endpoint has no clear exit inside the canvas" };
|
|
3754
|
+
}
|
|
3755
|
+
const xs = /* @__PURE__ */ new Set([0, width, start.x, end.x]);
|
|
3756
|
+
const ys = /* @__PURE__ */ new Set([0, height, start.y, end.y]);
|
|
3757
|
+
for (const obstacle of obstacles) {
|
|
3758
|
+
if (obstacle.left >= 0 && obstacle.left <= width) xs.add(obstacle.left);
|
|
3759
|
+
if (obstacle.right >= 0 && obstacle.right <= width) xs.add(obstacle.right);
|
|
3760
|
+
if (obstacle.top >= 0 && obstacle.top <= height) ys.add(obstacle.top);
|
|
3761
|
+
if (obstacle.bottom >= 0 && obstacle.bottom <= height) ys.add(obstacle.bottom);
|
|
3762
|
+
}
|
|
3763
|
+
for (const route of previousRoutes.slice(-8)) for (const point of route) {
|
|
3764
|
+
for (const offset of [-gap, gap]) {
|
|
3765
|
+
if (point.x + offset >= 0 && point.x + offset <= width) xs.add(point.x + offset);
|
|
3766
|
+
if (point.y + offset >= 0 && point.y + offset <= height) ys.add(point.y + offset);
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
const xValues = [...xs].sort((a, b) => a - b);
|
|
3770
|
+
const yValues = [...ys].sort((a, b) => a - b);
|
|
3771
|
+
const columns = xValues.length;
|
|
3772
|
+
const gridSize = columns * yValues.length;
|
|
3773
|
+
if (gridSize > MAX_GRID_POINTS) return { reason: `routing grid exceeds ${MAX_GRID_POINTS} points; simplify the graph` };
|
|
3774
|
+
const startIndex = yValues.indexOf(start.y) * columns + xValues.indexOf(start.x);
|
|
3775
|
+
const endIndex = yValues.indexOf(end.y) * columns + xValues.indexOf(end.x);
|
|
3776
|
+
const pointAt = (index) => ({ x: xValues[index % columns], y: yValues[Math.floor(index / columns)] });
|
|
3777
|
+
const costs = new Float64Array(gridSize * 3).fill(Infinity);
|
|
3778
|
+
const parents = new Int32Array(gridSize * 3).fill(-1);
|
|
3779
|
+
const queue = new MinQueue();
|
|
3780
|
+
costs[startIndex * 3] = 0;
|
|
3781
|
+
queue.push({ state: startIndex * 3, cost: 0, priority: 0 });
|
|
3782
|
+
let visits = 0;
|
|
3783
|
+
while (queue.length > 0) {
|
|
3784
|
+
if (--budget.remaining < 0) return { reason: `diagram routing budget exceeds ${MAX_TOTAL_SEARCH_STATES} search states; simplify the graph` };
|
|
3785
|
+
if (++visits > MAX_SEARCH_STATES) return { reason: `routing search exceeds ${MAX_SEARCH_STATES} states; simplify the graph` };
|
|
3786
|
+
const current = queue.pop();
|
|
3787
|
+
if (current.cost !== costs[current.state]) continue;
|
|
3788
|
+
const index = Math.floor(current.state / 3);
|
|
3789
|
+
const axis = current.state % 3;
|
|
3790
|
+
if (index === endIndex) {
|
|
3791
|
+
const points = [];
|
|
3792
|
+
for (let state = current.state; state >= 0; state = parents[state]) points.push(pointAt(Math.floor(state / 3)));
|
|
3793
|
+
return { points: simplify(points.reverse()) };
|
|
3794
|
+
}
|
|
3795
|
+
const a = pointAt(index);
|
|
3796
|
+
const column = index % columns;
|
|
3797
|
+
const row = Math.floor(index / columns);
|
|
3798
|
+
const neighbors = [
|
|
3799
|
+
column > 0 ? index - 1 : -1,
|
|
3800
|
+
column < columns - 1 ? index + 1 : -1,
|
|
3801
|
+
row > 0 ? index - columns : -1,
|
|
3802
|
+
row < yValues.length - 1 ? index + columns : -1
|
|
3803
|
+
];
|
|
3804
|
+
for (const neighbor of neighbors) {
|
|
3805
|
+
if (neighbor < 0) continue;
|
|
3806
|
+
const b = pointAt(neighbor);
|
|
3807
|
+
if (obstacles.some((obstacle) => routingSegmentBlocked(a, b, obstacle))) continue;
|
|
3808
|
+
const nextAxis = a.y === b.y ? 1 : 2;
|
|
3809
|
+
const state = neighbor * 3 + nextAxis;
|
|
3810
|
+
let overlap = 0;
|
|
3811
|
+
for (const route of previousRoutes) for (let i = 1; i < route.length; i++) overlap += overlappingLength(a, b, route[i - 1], route[i]);
|
|
3812
|
+
const cost = current.cost + Math.abs(b.x - a.x) + Math.abs(b.y - a.y) + (axis !== 0 && axis !== nextAxis ? 18 : 0) + overlap * 5;
|
|
3813
|
+
if (cost >= costs[state]) continue;
|
|
3814
|
+
costs[state] = cost;
|
|
3815
|
+
parents[state] = current.state;
|
|
3816
|
+
queue.push({ state, cost, priority: cost + Math.abs(end.x - b.x) + Math.abs(end.y - b.y) });
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
return { reason: "no obstacle-free route exists inside the canvas" };
|
|
3820
|
+
}
|
|
3821
|
+
function endpoint(node, other, portId, requestedSide, selfLoop, target, ordinal, count, gap) {
|
|
3822
|
+
const port = node.ports?.find((candidate) => candidate.id === portId);
|
|
3823
|
+
const side = port?.side ?? requestedSide ?? (selfLoop ? target ? "top" : "right" : preferredSide(node, other));
|
|
3824
|
+
const length = side === "left" || side === "right" ? node.height : node.width;
|
|
3825
|
+
const separation = count > 1 ? Math.min(gap, length * 0.7 / (count - 1)) : 0;
|
|
3826
|
+
const offset = port ? port.offset ?? 0.5 : 0.5 + (ordinal - (count - 1) / 2) * separation / length;
|
|
3827
|
+
return { side, anchor: routingAnchor(node, side, offset), explicit: portId != null || requestedSide != null };
|
|
3828
|
+
}
|
|
3829
|
+
function straightGraphRoute(from, to, edge) {
|
|
3830
|
+
return [
|
|
3831
|
+
endpoint(from, to, edge.fromPort, edge.fromSide, false, false, 0, 1, 0).anchor,
|
|
3832
|
+
endpoint(to, from, edge.toPort, edge.toSide, false, true, 0, 1, 0).anchor
|
|
3833
|
+
];
|
|
3834
|
+
}
|
|
3835
|
+
function routeOrthogonalGraph(nodes, edges, width, height, clearance = 12, gap = 14, extraObstacles = []) {
|
|
3836
|
+
const routes = /* @__PURE__ */ new Map();
|
|
3837
|
+
const failures = [];
|
|
3838
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
3839
|
+
const obstacles = [...nodes.map((node) => box(node, clearance)), ...extraObstacles.map((obstacle) => ({
|
|
3840
|
+
left: obstacle.left - clearance,
|
|
3841
|
+
right: obstacle.right + clearance,
|
|
3842
|
+
top: obstacle.top - clearance,
|
|
3843
|
+
bottom: obstacle.bottom + clearance
|
|
3844
|
+
}))];
|
|
3845
|
+
const routeKey = (edge) => [edge.from, edge.to].sort().join("\0");
|
|
3846
|
+
const counts2 = /* @__PURE__ */ new Map();
|
|
3847
|
+
for (const edge of edges) counts2.set(routeKey(edge), (counts2.get(routeKey(edge)) ?? 0) + 1);
|
|
3848
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
3849
|
+
const previous = /* @__PURE__ */ new Map();
|
|
3850
|
+
const budget = { remaining: MAX_TOTAL_SEARCH_STATES };
|
|
3851
|
+
edges.forEach((edge, index) => {
|
|
3852
|
+
if (index >= MAX_ROUTED_EDGES) {
|
|
3853
|
+
failures.push({ index, reason: `orthogonal routing supports at most ${MAX_ROUTED_EDGES} edges per diagram` });
|
|
3854
|
+
return;
|
|
3855
|
+
}
|
|
3856
|
+
if (obstacles.length > MAX_OBSTACLES) {
|
|
3857
|
+
failures.push({ index, reason: `orthogonal routing supports at most ${MAX_OBSTACLES} node and header obstacles per diagram` });
|
|
3858
|
+
return;
|
|
3859
|
+
}
|
|
3860
|
+
if (budget.remaining < 0) {
|
|
3861
|
+
failures.push({ index, reason: `diagram routing budget exceeds ${MAX_TOTAL_SEARCH_STATES} search states; simplify the graph` });
|
|
3862
|
+
return;
|
|
3863
|
+
}
|
|
3864
|
+
const from = byId.get(edge.from);
|
|
3865
|
+
const to = byId.get(edge.to);
|
|
3866
|
+
const key = routeKey(edge);
|
|
3867
|
+
const ordinal = occurrences.get(key) ?? 0;
|
|
3868
|
+
occurrences.set(key, ordinal + 1);
|
|
3869
|
+
const count = counts2.get(key) ?? 1;
|
|
3870
|
+
const source = endpoint(from, to, edge.fromPort, edge.fromSide, from === to, false, ordinal, count, gap);
|
|
3871
|
+
const target = endpoint(to, from, edge.toPort, edge.toSide, from === to, true, ordinal, count, gap);
|
|
3872
|
+
const sourceSides = source.explicit ? [source.side] : [source.side, ...sides.filter((side) => side !== source.side)];
|
|
3873
|
+
const targetSides = target.explicit ? [target.side] : [target.side, ...sides.filter((side) => side !== target.side)];
|
|
3874
|
+
let failure = "no obstacle-free route exists inside the canvas";
|
|
3875
|
+
for (const sourceSide of sourceSides) {
|
|
3876
|
+
for (const targetSide of targetSides) {
|
|
3877
|
+
const start = sourceSide === source.side ? source.anchor : routingAnchor(from, sourceSide);
|
|
3878
|
+
const end = targetSide === target.side ? target.anchor : routingAnchor(to, targetSide);
|
|
3879
|
+
if (from === to && start.x === end.x && start.y === end.y) {
|
|
3880
|
+
failure = "a self-loop requires distinct endpoint anchors";
|
|
3881
|
+
continue;
|
|
3882
|
+
}
|
|
3883
|
+
const leadStart = outward(start, sourceSide, clearance);
|
|
3884
|
+
const leadEnd = outward(end, targetSide, clearance);
|
|
3885
|
+
if (obstacles.some((obstacle, obstacleIndex) => obstacleIndex !== nodes.indexOf(from) && routingSegmentBlocked(start, leadStart, obstacle) || obstacleIndex !== nodes.indexOf(to) && routingSegmentBlocked(leadEnd, end, obstacle))) {
|
|
3886
|
+
failure = "another obstacle blocks an endpoint exit";
|
|
3887
|
+
continue;
|
|
3888
|
+
}
|
|
3889
|
+
const result = findPath(leadStart, leadEnd, obstacles, width, height, previous.get(key) ?? [], Math.max(1, gap), budget);
|
|
3890
|
+
if (!result.points) {
|
|
3891
|
+
failure = result.reason;
|
|
3892
|
+
if (/routing (grid|search|budget)/.test(failure)) {
|
|
3893
|
+
failures.push({ index, reason: failure });
|
|
3894
|
+
return;
|
|
3895
|
+
}
|
|
3896
|
+
continue;
|
|
3897
|
+
}
|
|
3898
|
+
const points = simplify([start, ...result.points, end]);
|
|
3899
|
+
if (points.length < 2) continue;
|
|
3900
|
+
const repeated = (previous.get(key) ?? []).some((route) => route.length === points.length && (route.every((point, position) => point.x === points[position].x && point.y === points[position].y) || route.every((point, position) => point.x === points[points.length - 1 - position].x && point.y === points[points.length - 1 - position].y)));
|
|
3901
|
+
if (repeated) {
|
|
3902
|
+
failure = "parallel connectors have no separate lane at the requested clearance";
|
|
3903
|
+
continue;
|
|
3904
|
+
}
|
|
3905
|
+
routes.set(index, points);
|
|
3906
|
+
previous.set(key, [...previous.get(key) ?? [], points]);
|
|
3907
|
+
return;
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
failures.push({ index, reason: failure });
|
|
3911
|
+
});
|
|
3912
|
+
return { routes, failures };
|
|
3913
|
+
}
|
|
3914
|
+
function routingLabelPosition(points) {
|
|
3915
|
+
let longest = 0;
|
|
3916
|
+
let position = points[0];
|
|
3917
|
+
for (let i = 1; i < points.length; i++) {
|
|
3918
|
+
const a = points[i - 1];
|
|
3919
|
+
const b = points[i];
|
|
3920
|
+
const length = Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
3921
|
+
if (length > longest) {
|
|
3922
|
+
longest = length;
|
|
3923
|
+
position = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
3924
|
+
}
|
|
3925
|
+
}
|
|
3926
|
+
return position;
|
|
3927
|
+
}
|
|
3928
|
+
|
|
3929
|
+
// src/primitives/diagrams.ts
|
|
3355
3930
|
function distributeValues(count, start, end) {
|
|
3356
3931
|
if (count <= 0) return [];
|
|
3357
3932
|
if (count === 1) return [(start + end) / 2];
|
|
@@ -3386,7 +3961,7 @@ function LayeredNetwork({
|
|
|
3386
3961
|
return from.ys.flatMap(
|
|
3387
3962
|
(fromY, fromIndex) => to.ys.map((toY, toIndex) => {
|
|
3388
3963
|
const active = activePath[layerIndex] === fromIndex && activePath[layerIndex + 1] === toIndex;
|
|
3389
|
-
return
|
|
3964
|
+
return import_react7.default.createElement("line", {
|
|
3390
3965
|
key: `connection-${layerIndex}-${fromIndex}-${toIndex}`,
|
|
3391
3966
|
x1: from.x + radius + 4,
|
|
3392
3967
|
y1: fromY,
|
|
@@ -3400,7 +3975,7 @@ function LayeredNetwork({
|
|
|
3400
3975
|
})
|
|
3401
3976
|
);
|
|
3402
3977
|
});
|
|
3403
|
-
const label = (key, text, x, y, labelWidth, color, fontSize = 13, fontWeight = 800, fontFamily = "Inter") =>
|
|
3978
|
+
const label = (key, text, x, y, labelWidth, color, fontSize = 13, fontWeight = 800, fontFamily = "Inter") => import_react7.default.createElement("div", {
|
|
3404
3979
|
key,
|
|
3405
3980
|
style: {
|
|
3406
3981
|
position: "absolute",
|
|
@@ -3425,7 +4000,7 @@ function LayeredNetwork({
|
|
|
3425
4000
|
const active = activePath[layerIndex] === nodeIndex;
|
|
3426
4001
|
const color = getToneColor(layer.tone, c);
|
|
3427
4002
|
return [
|
|
3428
|
-
active &&
|
|
4003
|
+
active && import_react7.default.createElement("div", {
|
|
3429
4004
|
key: `halo-${layerIndex}-${nodeIndex}`,
|
|
3430
4005
|
style: {
|
|
3431
4006
|
position: "absolute",
|
|
@@ -3440,7 +4015,7 @@ function LayeredNetwork({
|
|
|
3440
4015
|
boxShadow: `0 0 18px ${c.warningLight}66`
|
|
3441
4016
|
}
|
|
3442
4017
|
}),
|
|
3443
|
-
|
|
4018
|
+
import_react7.default.createElement("div", {
|
|
3444
4019
|
key: `node-${layerIndex}-${nodeIndex}`,
|
|
3445
4020
|
style: {
|
|
3446
4021
|
position: "absolute",
|
|
@@ -3480,7 +4055,7 @@ function LayeredNetwork({
|
|
|
3480
4055
|
"JetBrains Mono"
|
|
3481
4056
|
)
|
|
3482
4057
|
);
|
|
3483
|
-
const formulaElement = (showFormula || formula) && formula ?
|
|
4058
|
+
const formulaElement = (showFormula || formula) && formula ? import_react7.default.createElement("div", {
|
|
3484
4059
|
key: "formula-wrap",
|
|
3485
4060
|
style: {
|
|
3486
4061
|
position: "absolute",
|
|
@@ -3501,7 +4076,7 @@ function LayeredNetwork({
|
|
|
3501
4076
|
boxShadow: `0 8px 18px ${c.shadow}`
|
|
3502
4077
|
}
|
|
3503
4078
|
}, formatMathText(formula)) : null;
|
|
3504
|
-
const legendElement = (showFormula || formula) && formula ?
|
|
4079
|
+
const legendElement = (showFormula || formula) && formula ? import_react7.default.createElement(
|
|
3505
4080
|
"div",
|
|
3506
4081
|
{
|
|
3507
4082
|
key: "legend-wrap",
|
|
@@ -3519,7 +4094,7 @@ function LayeredNetwork({
|
|
|
3519
4094
|
fontWeight: 800
|
|
3520
4095
|
}
|
|
3521
4096
|
},
|
|
3522
|
-
|
|
4097
|
+
import_react7.default.createElement("div", {
|
|
3523
4098
|
style: {
|
|
3524
4099
|
width: 42,
|
|
3525
4100
|
height: 5,
|
|
@@ -3529,7 +4104,7 @@ function LayeredNetwork({
|
|
|
3529
4104
|
}),
|
|
3530
4105
|
legend
|
|
3531
4106
|
) : null;
|
|
3532
|
-
return
|
|
4107
|
+
return import_react7.default.createElement(
|
|
3533
4108
|
"div",
|
|
3534
4109
|
{
|
|
3535
4110
|
role: "img",
|
|
@@ -3544,7 +4119,7 @@ function LayeredNetwork({
|
|
|
3544
4119
|
flexShrink: 0
|
|
3545
4120
|
}
|
|
3546
4121
|
},
|
|
3547
|
-
|
|
4122
|
+
import_react7.default.createElement("svg", {
|
|
3548
4123
|
width,
|
|
3549
4124
|
height,
|
|
3550
4125
|
viewBox: `0 0 ${width} ${height}`,
|
|
@@ -3687,6 +4262,20 @@ function validateGraphDiagramSpec(nodes, edges, groups, layoutMode) {
|
|
|
3687
4262
|
for (const node of nodes) {
|
|
3688
4263
|
if (nodeIds.has(node.id)) throw new Error(`GraphDiagram received duplicate node id "${node.id}".`);
|
|
3689
4264
|
nodeIds.add(node.id);
|
|
4265
|
+
const portIds = /* @__PURE__ */ new Set();
|
|
4266
|
+
for (const port of node.ports ?? []) {
|
|
4267
|
+
if (typeof port.id !== "string" || port.id.trim().length === 0) {
|
|
4268
|
+
throw new Error(`GraphDiagram node "${node.id}" port id must be a non-empty string.`);
|
|
4269
|
+
}
|
|
4270
|
+
if (portIds.has(port.id)) throw new Error(`GraphDiagram node "${node.id}" received duplicate port "${port.id}".`);
|
|
4271
|
+
portIds.add(port.id);
|
|
4272
|
+
if (!["top", "right", "bottom", "left"].includes(port.side)) {
|
|
4273
|
+
throw new Error(`GraphDiagram node "${node.id}" port "${port.id}" must use side "top", "right", "bottom", or "left".`);
|
|
4274
|
+
}
|
|
4275
|
+
if (port.offset != null && (!Number.isFinite(port.offset) || port.offset < 0 || port.offset > 1)) {
|
|
4276
|
+
throw new Error(`GraphDiagram node "${node.id}" port "${port.id}" offset must be between 0 and 1.`);
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
3690
4279
|
}
|
|
3691
4280
|
const groupsById = /* @__PURE__ */ new Map();
|
|
3692
4281
|
for (const group of groups) {
|
|
@@ -3721,15 +4310,67 @@ function validateGraphDiagramSpec(nodes, edges, groups, layoutMode) {
|
|
|
3721
4310
|
for (const group of groups) {
|
|
3722
4311
|
if (!occupiedGroups.has(group.id)) throw new Error(`GraphDiagram group "${group.id}" contains no nodes.`);
|
|
3723
4312
|
}
|
|
4313
|
+
const edgeIds = /* @__PURE__ */ new Set();
|
|
3724
4314
|
for (const edge of edges) {
|
|
3725
4315
|
if (!nodeIds.has(edge.from) || !nodeIds.has(edge.to)) {
|
|
3726
4316
|
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" references a missing node.`);
|
|
3727
4317
|
}
|
|
4318
|
+
if (edge.id != null) {
|
|
4319
|
+
if (edgeIds.has(edge.id)) throw new Error(`GraphDiagram received duplicate edge id "${edge.id}".`);
|
|
4320
|
+
edgeIds.add(edge.id);
|
|
4321
|
+
}
|
|
4322
|
+
for (const side of ["from", "to"]) {
|
|
4323
|
+
const reference = side === "from" ? edge.fromPort : edge.toPort;
|
|
4324
|
+
const endpointSide = side === "from" ? edge.fromSide : edge.toSide;
|
|
4325
|
+
const node = nodes.find((candidate) => candidate.id === edge[side]);
|
|
4326
|
+
if (reference != null && !node.ports?.some((port) => port.id === reference)) {
|
|
4327
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" references missing ${side} port "${reference}" on node "${node.id}".`);
|
|
4328
|
+
}
|
|
4329
|
+
if (endpointSide != null && !["top", "right", "bottom", "left"].includes(endpointSide)) {
|
|
4330
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" ${side}Side must be "top", "right", "bottom", or "left".`);
|
|
4331
|
+
}
|
|
4332
|
+
if (reference != null && endpointSide != null) {
|
|
4333
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" cannot combine ${side}Port and ${side}Side.`);
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
validateDiagramHref(edge.href, `edge "${edge.id ?? `${edge.from}" -> "${edge.to}`}"`);
|
|
4337
|
+
}
|
|
4338
|
+
for (const node of nodes) {
|
|
4339
|
+
validateDiagramHref(node.href, `node "${node.id}"`);
|
|
3728
4340
|
}
|
|
3729
4341
|
if (groups.length > 0 && layoutMode === "manual") {
|
|
3730
4342
|
throw new Error('GraphDiagram groups require automatic layout; omit node coordinates and layout="manual".');
|
|
3731
4343
|
}
|
|
3732
4344
|
}
|
|
4345
|
+
function validateDiagramHref(href, owner) {
|
|
4346
|
+
if (href == null) return;
|
|
4347
|
+
const normalized = href.trim().replace(/[\u0000-\u0020\u007f]/g, "");
|
|
4348
|
+
const scheme = /^([a-z][a-z\d+.-]*):/i.exec(normalized)?.[1]?.toLowerCase();
|
|
4349
|
+
if (scheme && !["http", "https", "mailto", "tel"].includes(scheme)) {
|
|
4350
|
+
throw new Error(`GraphDiagram ${owner} has an unsupported link scheme "${scheme}:".`);
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
function graphAccessibleText(value) {
|
|
4354
|
+
if (typeof value === "string" || typeof value === "number") return String(value).trim();
|
|
4355
|
+
if (Array.isArray(value)) return value.map(graphAccessibleText).filter(Boolean).join(" ");
|
|
4356
|
+
if (import_react7.default.isValidElement(value)) {
|
|
4357
|
+
const props = value.props;
|
|
4358
|
+
return graphAccessibleText(props.children);
|
|
4359
|
+
}
|
|
4360
|
+
return "";
|
|
4361
|
+
}
|
|
4362
|
+
function graphDescription(nodes, edges) {
|
|
4363
|
+
const labels = new Map(nodes.map((node) => [node.id, graphAccessibleText(node.label) || node.id]));
|
|
4364
|
+
const parts = [`${nodes.length} nodes and ${edges.length} relationships.`];
|
|
4365
|
+
const relationships = edges.slice(0, 8).map((edge) => {
|
|
4366
|
+
const from = labels.get(edge.from) ?? edge.from;
|
|
4367
|
+
const to = labels.get(edge.to) ?? edge.to;
|
|
4368
|
+
return edge.label ? `${from} ${edge.label} ${to}` : `${from} to ${to}`;
|
|
4369
|
+
});
|
|
4370
|
+
if (relationships.length) parts.push(relationships.join("; "));
|
|
4371
|
+
if (edges.length > relationships.length) parts.push(`${edges.length - relationships.length} more relationships`);
|
|
4372
|
+
return parts.join(" ");
|
|
4373
|
+
}
|
|
3733
4374
|
function graphGroupDepth(group, groupsById) {
|
|
3734
4375
|
let depth = 0;
|
|
3735
4376
|
let parent = group.parent;
|
|
@@ -3767,10 +4408,18 @@ function GraphDiagram({
|
|
|
3767
4408
|
nodeGap = 34,
|
|
3768
4409
|
rankGap = 64,
|
|
3769
4410
|
edgeGap = 14,
|
|
4411
|
+
routing = "dagre",
|
|
4412
|
+
routingClearance = 12,
|
|
3770
4413
|
sizing = "content",
|
|
3771
4414
|
iconSize = 20,
|
|
3772
|
-
|
|
4415
|
+
id,
|
|
4416
|
+
ariaLabel,
|
|
4417
|
+
title,
|
|
4418
|
+
description
|
|
3773
4419
|
}) {
|
|
4420
|
+
if (id != null && id.trim().length === 0) throw new Error("GraphDiagram id must not be empty.");
|
|
4421
|
+
if (!["dagre", "straight", "orthogonal"].includes(routing)) throw new Error('GraphDiagram routing must be "dagre", "straight", or "orthogonal".');
|
|
4422
|
+
if (!Number.isFinite(routingClearance) || routingClearance <= 0) throw new Error("GraphDiagram routingClearance must be a finite positive number.");
|
|
3774
4423
|
const fullyPositioned = nodes.filter((node) => node.x != null && node.y != null).length;
|
|
3775
4424
|
const partiallyPositioned = nodes.some((node) => node.x == null !== (node.y == null));
|
|
3776
4425
|
if (partiallyPositioned || fullyPositioned > 0 && fullyPositioned < nodes.length) {
|
|
@@ -3781,6 +4430,19 @@ function GraphDiagram({
|
|
|
3781
4430
|
throw new Error('GraphDiagram layout="manual" requires x and y on every node.');
|
|
3782
4431
|
}
|
|
3783
4432
|
validateGraphDiagramSpec(nodes, edges, groups, layoutMode);
|
|
4433
|
+
const edgeOccurrences = /* @__PURE__ */ new Map();
|
|
4434
|
+
const stableEdgeIds = edges.map((edge) => {
|
|
4435
|
+
if (edge.id != null) return `custom-${edge.id}`;
|
|
4436
|
+
const route = `${edge.from}\0${edge.to}`;
|
|
4437
|
+
const occurrence = edgeOccurrences.get(route) ?? 0;
|
|
4438
|
+
edgeOccurrences.set(route, occurrence + 1);
|
|
4439
|
+
return `route-${edge.from}-to-${edge.to}-${occurrence}`;
|
|
4440
|
+
});
|
|
4441
|
+
if (new Set(stableEdgeIds).size !== stableEdgeIds.length) {
|
|
4442
|
+
throw new Error("GraphDiagram edge ids must not collide with generated relationship ids.");
|
|
4443
|
+
}
|
|
4444
|
+
const svgTitle = title?.trim() || ariaLabel?.trim() || "Graph diagram";
|
|
4445
|
+
const svgDescription = description ?? graphDescription(nodes, edges);
|
|
3784
4446
|
let resolvedWidth = width ?? 520;
|
|
3785
4447
|
let resolvedHeight = height ?? 420;
|
|
3786
4448
|
let layout;
|
|
@@ -3852,7 +4514,30 @@ function GraphDiagram({
|
|
|
3852
4514
|
} else {
|
|
3853
4515
|
layout = manualGraphLayout(nodes, resolvedWidth, resolvedHeight, nodeWidth, nodeHeight, padding);
|
|
3854
4516
|
}
|
|
4517
|
+
const anchored = (edge) => edge.fromPort != null || edge.toPort != null || edge.fromSide != null || edge.toSide != null;
|
|
4518
|
+
const orthogonalEdges = edges.flatMap((edge, index) => routing === "orthogonal" || routing === "dagre" && anchored(edge) || routing === "straight" && edge.from === edge.to ? [{ edge, index }] : []);
|
|
4519
|
+
const routed = routeOrthogonalGraph(
|
|
4520
|
+
Array.from(layout.values()),
|
|
4521
|
+
orthogonalEdges.map(({ edge }) => edge),
|
|
4522
|
+
resolvedWidth,
|
|
4523
|
+
resolvedHeight,
|
|
4524
|
+
routingClearance,
|
|
4525
|
+
edgeGap,
|
|
4526
|
+
groupLayout.map((group) => ({
|
|
4527
|
+
left: group.cx - group.width / 2,
|
|
4528
|
+
right: group.cx + group.width / 2,
|
|
4529
|
+
top: group.cy - group.height / 2,
|
|
4530
|
+
bottom: group.cy - group.height / 2 + 26
|
|
4531
|
+
}))
|
|
4532
|
+
);
|
|
4533
|
+
const orthogonalPoints = new Map(Array.from(routed.routes, ([index, points]) => [orthogonalEdges[index].index, points]));
|
|
4534
|
+
const failedIndexes = new Set(routed.failures.map((failure) => orthogonalEdges[failure.index].index));
|
|
4535
|
+
const routingFailures = routed.failures.map((failure) => {
|
|
4536
|
+
const { edge } = orthogonalEdges[failure.index];
|
|
4537
|
+
return `Connector "${edge.from}" -> "${edge.to}" was not drawn: ${failure.reason}.`;
|
|
4538
|
+
});
|
|
3855
4539
|
const edgeLayouts = edges.flatMap((edge, index) => {
|
|
4540
|
+
if (failedIndexes.has(index)) return [];
|
|
3856
4541
|
const from = layout.get(edge.from);
|
|
3857
4542
|
const to = layout.get(edge.to);
|
|
3858
4543
|
if (!from || !to) return [];
|
|
@@ -3881,31 +4566,34 @@ function GraphDiagram({
|
|
|
3881
4566
|
{ x: from.cx + 10, y: from.cy - from.height / 2 - loopClearance },
|
|
3882
4567
|
{ x: from.cx + 10, y: from.cy - from.height / 2 }
|
|
3883
4568
|
] : void 0;
|
|
3884
|
-
const
|
|
4569
|
+
const routedPoints = orthogonalPoints.get(index);
|
|
4570
|
+
const points = routedPoints ?? (routing === "straight" ? straightGraphRoute(from, to, edge) : automatic?.points.length ? automatic.points : manualLoopPoints ?? [
|
|
3885
4571
|
{ x: from.cx + dx * fromScale, y: from.cy + dy * fromScale },
|
|
3886
4572
|
{ x: to.cx - dx * toScale, y: to.cy - dy * toScale }
|
|
3887
|
-
];
|
|
4573
|
+
]);
|
|
3888
4574
|
const manualLoopLabel = manualLoopPoints ? {
|
|
3889
4575
|
x: from.cx + from.width / 2 + loopClearance,
|
|
3890
4576
|
y: from.cy - from.height / 2 - loopClearance / 2
|
|
3891
4577
|
} : void 0;
|
|
4578
|
+
const routedLabel = routedPoints || routing === "straight" ? routingLabelPosition(points) : void 0;
|
|
3892
4579
|
return [{
|
|
3893
4580
|
...edge,
|
|
3894
4581
|
index,
|
|
4582
|
+
stableId: stableEdgeIds[index],
|
|
3895
4583
|
color,
|
|
3896
4584
|
markerId,
|
|
3897
4585
|
points,
|
|
3898
|
-
labelX: automatic?.labelX ?? manualLoopLabel?.x ?? (points[0].x + points[points.length - 1].x) / 2,
|
|
3899
|
-
labelY: automatic?.labelY ?? manualLoopLabel?.y ?? (points[0].y + points[points.length - 1].y) / 2
|
|
4586
|
+
labelX: routedLabel?.x ?? automatic?.labelX ?? manualLoopLabel?.x ?? (points[0].x + points[points.length - 1].x) / 2,
|
|
4587
|
+
labelY: routedLabel?.y ?? automatic?.labelY ?? manualLoopLabel?.y ?? (points[0].y + points[points.length - 1].y) / 2
|
|
3900
4588
|
}];
|
|
3901
4589
|
});
|
|
3902
4590
|
const crossings = connectorCrossings(edgeLayouts);
|
|
3903
4591
|
const labelCollisions = connectorLabelCollisions(edgeLayouts, layout, groupLayout);
|
|
3904
4592
|
const crowdedEndpoints = crowdedConnectorEndpoints(edgeLayouts);
|
|
3905
|
-
const parallelGroups = parallelConnectorGroups(edgeLayouts);
|
|
4593
|
+
const parallelGroups = parallelConnectorGroups(edgeLayouts.filter((edge) => !orthogonalPoints.has(edge.index)));
|
|
3906
4594
|
const groupElements = groupLayout.map((group) => {
|
|
3907
4595
|
const accent = group.muted ? c.textMuted : getToneColor(group.tone ?? "blue", c);
|
|
3908
|
-
return
|
|
4596
|
+
return import_react7.default.createElement("div", {
|
|
3909
4597
|
key: `graph-group-${group.id}`,
|
|
3910
4598
|
"data-vizmatic-graph-group": group.id,
|
|
3911
4599
|
style: {
|
|
@@ -3921,7 +4609,7 @@ function GraphDiagram({
|
|
|
3921
4609
|
backgroundColor: `${accent}${c.preset === "engineering" ? "08" : "0d"}`,
|
|
3922
4610
|
opacity: group.muted ? 0.68 : 1
|
|
3923
4611
|
}
|
|
3924
|
-
},
|
|
4612
|
+
}, import_react7.default.createElement(
|
|
3925
4613
|
"div",
|
|
3926
4614
|
{
|
|
3927
4615
|
style: {
|
|
@@ -3939,10 +4627,10 @@ function GraphDiagram({
|
|
|
3939
4627
|
whiteSpace: "nowrap"
|
|
3940
4628
|
}
|
|
3941
4629
|
},
|
|
3942
|
-
|
|
4630
|
+
import_react7.default.createElement("div", {
|
|
3943
4631
|
style: { minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", fontSize: 12, fontWeight: 800 }
|
|
3944
4632
|
}, group.label),
|
|
3945
|
-
group.detail &&
|
|
4633
|
+
group.detail && import_react7.default.createElement("div", {
|
|
3946
4634
|
style: {
|
|
3947
4635
|
minWidth: 0,
|
|
3948
4636
|
overflow: "hidden",
|
|
@@ -3955,15 +4643,21 @@ function GraphDiagram({
|
|
|
3955
4643
|
}, group.detail)
|
|
3956
4644
|
));
|
|
3957
4645
|
});
|
|
3958
|
-
return
|
|
4646
|
+
return import_react7.default.createElement(
|
|
3959
4647
|
"div",
|
|
3960
4648
|
{
|
|
4649
|
+
key: "vizmatic-graph-root",
|
|
3961
4650
|
role: "img",
|
|
3962
|
-
"aria-label": ariaLabel ??
|
|
4651
|
+
"aria-label": ariaLabel ?? svgTitle,
|
|
4652
|
+
"data-vizmatic-svg-title": svgTitle,
|
|
4653
|
+
"data-vizmatic-svg-description": svgDescription,
|
|
4654
|
+
"data-vizmatic-svg-id": id,
|
|
3963
4655
|
"data-vizmatic-connector-crossings": crossings,
|
|
3964
4656
|
"data-vizmatic-connector-label-collisions": labelCollisions,
|
|
3965
4657
|
"data-vizmatic-crowded-connector-endpoints": crowdedEndpoints,
|
|
3966
4658
|
"data-vizmatic-parallel-connector-groups": parallelGroups,
|
|
4659
|
+
"data-vizmatic-unrouted-connectors": routingFailures.length,
|
|
4660
|
+
"data-vizmatic-routing-failures": routingFailures.length ? JSON.stringify(routingFailures) : void 0,
|
|
3967
4661
|
style: {
|
|
3968
4662
|
position: "relative",
|
|
3969
4663
|
display: "flex",
|
|
@@ -3974,7 +4668,7 @@ function GraphDiagram({
|
|
|
3974
4668
|
}
|
|
3975
4669
|
},
|
|
3976
4670
|
...groupElements,
|
|
3977
|
-
|
|
4671
|
+
import_react7.default.createElement(
|
|
3978
4672
|
"svg",
|
|
3979
4673
|
{
|
|
3980
4674
|
width: resolvedWidth,
|
|
@@ -3982,7 +4676,7 @@ function GraphDiagram({
|
|
|
3982
4676
|
viewBox: `0 0 ${resolvedWidth} ${resolvedHeight}`,
|
|
3983
4677
|
style: { position: "absolute", inset: 0, overflow: "visible" }
|
|
3984
4678
|
},
|
|
3985
|
-
|
|
4679
|
+
import_react7.default.createElement(
|
|
3986
4680
|
"defs",
|
|
3987
4681
|
{},
|
|
3988
4682
|
...edgeLayouts.map((edge) => ArrowMarkerDef({
|
|
@@ -3991,8 +4685,14 @@ function GraphDiagram({
|
|
|
3991
4685
|
size: arrowSize
|
|
3992
4686
|
}))
|
|
3993
4687
|
),
|
|
3994
|
-
...edgeLayouts.map((edge) =>
|
|
4688
|
+
...edgeLayouts.map((edge) => import_react7.default.createElement("path", {
|
|
3995
4689
|
key: `graph-edge-${edge.index}`,
|
|
4690
|
+
"data-vizmatic-graph-edge-id": encodeURIComponent(edge.stableId),
|
|
4691
|
+
"data-vizmatic-graph-edge-from": encodeURIComponent(edge.from),
|
|
4692
|
+
"data-vizmatic-graph-edge-to": encodeURIComponent(edge.to),
|
|
4693
|
+
"data-vizmatic-graph-edge-label": encodeURIComponent(edge.label ?? ""),
|
|
4694
|
+
"data-vizmatic-graph-edge-title": encodeURIComponent(edge.title ?? ""),
|
|
4695
|
+
"data-vizmatic-graph-edge-href": edge.href == null ? void 0 : encodeURIComponent(edge.href),
|
|
3996
4696
|
d: edgePath(edge.points),
|
|
3997
4697
|
fill: "none",
|
|
3998
4698
|
stroke: edge.color,
|
|
@@ -4005,7 +4705,7 @@ function GraphDiagram({
|
|
|
4005
4705
|
}))
|
|
4006
4706
|
),
|
|
4007
4707
|
...edgeLayouts.flatMap((edge) => edge.label ? [
|
|
4008
|
-
|
|
4708
|
+
import_react7.default.createElement("div", {
|
|
4009
4709
|
key: `graph-edge-label-${edge.index}`,
|
|
4010
4710
|
style: {
|
|
4011
4711
|
position: "absolute",
|
|
@@ -4031,15 +4731,16 @@ function GraphDiagram({
|
|
|
4031
4731
|
] : []),
|
|
4032
4732
|
...Array.from(layout.values()).map((node) => {
|
|
4033
4733
|
const accent = node.muted ? c.textMuted : getToneColor(node.tone ?? "blue", c);
|
|
4034
|
-
const
|
|
4734
|
+
const fill = getToneFill(node.tone ?? "blue", c);
|
|
4735
|
+
const accentText = node.muted ? c.textMuted : getReadableToneColor(node.tone ?? "blue", c, fill, c.bg);
|
|
4035
4736
|
const resolvedIconSize = clamp(
|
|
4036
4737
|
node.iconSize ?? iconSize,
|
|
4037
4738
|
8,
|
|
4038
4739
|
Math.max(8, Math.min(node.width, node.height) - 16)
|
|
4039
4740
|
);
|
|
4040
4741
|
const iconLabel = typeof node.label === "string" ? `${node.label} icon` : void 0;
|
|
4041
|
-
const iconElement = typeof node.icon === "string" ? Icon({ c, name: node.icon, color: accent, size: resolvedIconSize, label: iconLabel, muted: node.muted }) :
|
|
4042
|
-
const icon = iconElement &&
|
|
4742
|
+
const iconElement = typeof node.icon === "string" ? Icon({ c, name: node.icon, color: accent, size: resolvedIconSize, label: iconLabel, muted: node.muted }) : import_react7.default.isValidElement(node.icon) ? node.icon : node.icon?.render({ c, color: accent, size: resolvedIconSize, label: iconLabel });
|
|
4743
|
+
const icon = iconElement && import_react7.default.createElement("div", {
|
|
4043
4744
|
"data-vizmatic-graph-icon": node.id,
|
|
4044
4745
|
style: {
|
|
4045
4746
|
width: resolvedIconSize,
|
|
@@ -4051,10 +4752,15 @@ function GraphDiagram({
|
|
|
4051
4752
|
overflow: "hidden"
|
|
4052
4753
|
}
|
|
4053
4754
|
}, iconElement);
|
|
4054
|
-
return
|
|
4755
|
+
return import_react7.default.createElement(
|
|
4055
4756
|
"div",
|
|
4056
4757
|
{
|
|
4057
4758
|
key: `graph-node-${node.id}`,
|
|
4759
|
+
"data-vizmatic-graph-node-id": node.id,
|
|
4760
|
+
"data-vizmatic-graph-node-label": graphAccessibleText(node.label) || node.id,
|
|
4761
|
+
"data-vizmatic-graph-node-detail": graphAccessibleText(node.detail),
|
|
4762
|
+
"data-vizmatic-graph-node-title": node.title ?? "",
|
|
4763
|
+
"data-vizmatic-graph-node-href": node.href,
|
|
4058
4764
|
style: {
|
|
4059
4765
|
position: "absolute",
|
|
4060
4766
|
left: node.cx - node.width / 2,
|
|
@@ -4069,7 +4775,7 @@ function GraphDiagram({
|
|
|
4069
4775
|
padding: "8px 10px",
|
|
4070
4776
|
boxSizing: "border-box",
|
|
4071
4777
|
borderRadius: c.preset === "engineering" ? 5 : 10,
|
|
4072
|
-
backgroundColor: node.muted ? c.bgSubtle :
|
|
4778
|
+
backgroundColor: node.muted ? c.bgSubtle : fill,
|
|
4073
4779
|
border: `${c.preset === "engineering" ? 1.25 : 1.5}px solid ${node.muted ? c.borderLight : `${accent}${c.preset === "engineering" ? "" : "88"}`}`,
|
|
4074
4780
|
...!node.muted && c.preset !== "engineering" ? { boxShadow: `0 8px 18px ${c.shadow}` } : {},
|
|
4075
4781
|
opacity: node.muted ? 0.62 : 1,
|
|
@@ -4078,7 +4784,7 @@ function GraphDiagram({
|
|
|
4078
4784
|
}
|
|
4079
4785
|
},
|
|
4080
4786
|
icon,
|
|
4081
|
-
|
|
4787
|
+
import_react7.default.createElement(
|
|
4082
4788
|
"div",
|
|
4083
4789
|
{
|
|
4084
4790
|
style: {
|
|
@@ -4089,7 +4795,7 @@ function GraphDiagram({
|
|
|
4089
4795
|
minWidth: 0
|
|
4090
4796
|
}
|
|
4091
4797
|
},
|
|
4092
|
-
|
|
4798
|
+
import_react7.default.createElement("div", {
|
|
4093
4799
|
style: {
|
|
4094
4800
|
fontFamily: c.fontSans,
|
|
4095
4801
|
fontSize: labelFontSize,
|
|
@@ -4097,7 +4803,7 @@ function GraphDiagram({
|
|
|
4097
4803
|
lineHeight: 1.15
|
|
4098
4804
|
}
|
|
4099
4805
|
}, node.label),
|
|
4100
|
-
node.detail &&
|
|
4806
|
+
node.detail && import_react7.default.createElement("div", {
|
|
4101
4807
|
style: {
|
|
4102
4808
|
color: c.textMuted,
|
|
4103
4809
|
fontFamily: c.fontMono,
|
|
@@ -4111,6 +4817,7 @@ function GraphDiagram({
|
|
|
4111
4817
|
})
|
|
4112
4818
|
);
|
|
4113
4819
|
}
|
|
4820
|
+
Object.defineProperty(GraphDiagram, SVG_ACCESSIBILITY_COMPONENT, { value: true });
|
|
4114
4821
|
function countTreeLeaves(node) {
|
|
4115
4822
|
if (!node.children?.length) return 1;
|
|
4116
4823
|
return node.children.reduce((sum, child) => sum + countTreeLeaves(child), 0);
|
|
@@ -4187,7 +4894,7 @@ function TreeDiagram({
|
|
|
4187
4894
|
return centerIndex;
|
|
4188
4895
|
};
|
|
4189
4896
|
placeWithEdges(root, 0, "root");
|
|
4190
|
-
const header = (title != null || subtitle != null) &&
|
|
4897
|
+
const header = (title != null || subtitle != null) && import_react7.default.createElement(
|
|
4191
4898
|
"div",
|
|
4192
4899
|
{
|
|
4193
4900
|
style: {
|
|
@@ -4199,7 +4906,7 @@ function TreeDiagram({
|
|
|
4199
4906
|
}
|
|
4200
4907
|
},
|
|
4201
4908
|
...compactChildren([
|
|
4202
|
-
title != null &&
|
|
4909
|
+
title != null && import_react7.default.createElement("div", {
|
|
4203
4910
|
style: {
|
|
4204
4911
|
display: "flex",
|
|
4205
4912
|
alignItems: "center",
|
|
@@ -4211,7 +4918,7 @@ function TreeDiagram({
|
|
|
4211
4918
|
lineHeight: 1.2
|
|
4212
4919
|
}
|
|
4213
4920
|
}, ToneStrip({ tone: root.tone ?? "blue" }), renderMaybeMath(title, math)),
|
|
4214
|
-
subtitle != null &&
|
|
4921
|
+
subtitle != null && import_react7.default.createElement("div", {
|
|
4215
4922
|
style: {
|
|
4216
4923
|
display: "flex",
|
|
4217
4924
|
color: c.textSecondary,
|
|
@@ -4223,7 +4930,7 @@ function TreeDiagram({
|
|
|
4223
4930
|
}, renderMaybeMath(subtitle, math))
|
|
4224
4931
|
])
|
|
4225
4932
|
);
|
|
4226
|
-
return
|
|
4933
|
+
return import_react7.default.createElement(
|
|
4227
4934
|
"div",
|
|
4228
4935
|
{
|
|
4229
4936
|
style: {
|
|
@@ -4236,7 +4943,7 @@ function TreeDiagram({
|
|
|
4236
4943
|
},
|
|
4237
4944
|
...compactChildren([
|
|
4238
4945
|
header,
|
|
4239
|
-
|
|
4946
|
+
import_react7.default.createElement(
|
|
4240
4947
|
"div",
|
|
4241
4948
|
{
|
|
4242
4949
|
role: "img",
|
|
@@ -4250,7 +4957,7 @@ function TreeDiagram({
|
|
|
4250
4957
|
flexShrink: 0
|
|
4251
4958
|
}
|
|
4252
4959
|
},
|
|
4253
|
-
|
|
4960
|
+
import_react7.default.createElement("svg", {
|
|
4254
4961
|
width: resolvedWidth,
|
|
4255
4962
|
height: resolvedHeight,
|
|
4256
4963
|
viewBox: `0 0 ${resolvedWidth} ${resolvedHeight}`,
|
|
@@ -4261,7 +4968,7 @@ function TreeDiagram({
|
|
|
4261
4968
|
const startY = edge.from.cy + nodeHeight / 2;
|
|
4262
4969
|
const endY = edge.to.cy - nodeHeight / 2;
|
|
4263
4970
|
const midY = startY + (endY - startY) / 2;
|
|
4264
|
-
return
|
|
4971
|
+
return import_react7.default.createElement("path", {
|
|
4265
4972
|
key: `tree-edge-${edge.key}`,
|
|
4266
4973
|
d: `M ${edge.from.cx} ${startY} C ${edge.from.cx} ${midY}, ${edge.to.cx} ${midY}, ${edge.to.cx} ${endY}`,
|
|
4267
4974
|
fill: "none",
|
|
@@ -4274,7 +4981,7 @@ function TreeDiagram({
|
|
|
4274
4981
|
...positioned.map((node) => {
|
|
4275
4982
|
const accent = node.muted ? c.textMuted : getToneColor(node.tone ?? "blue", c);
|
|
4276
4983
|
const accentText = node.muted ? c.textMuted : getReadableToneColor(node.tone ?? "blue", c);
|
|
4277
|
-
return
|
|
4984
|
+
return import_react7.default.createElement(
|
|
4278
4985
|
"div",
|
|
4279
4986
|
{
|
|
4280
4987
|
key: `tree-node-${node.key}`,
|
|
@@ -4300,7 +5007,7 @@ function TreeDiagram({
|
|
|
4300
5007
|
textAlign: "center"
|
|
4301
5008
|
}
|
|
4302
5009
|
},
|
|
4303
|
-
|
|
5010
|
+
import_react7.default.createElement("div", {
|
|
4304
5011
|
style: {
|
|
4305
5012
|
color: accentText,
|
|
4306
5013
|
fontFamily: "Inter",
|
|
@@ -4310,7 +5017,7 @@ function TreeDiagram({
|
|
|
4310
5017
|
...textFitStyle("center")
|
|
4311
5018
|
}
|
|
4312
5019
|
}, renderMaybeMath(node.label, math)),
|
|
4313
|
-
node.detail != null &&
|
|
5020
|
+
node.detail != null && import_react7.default.createElement("div", {
|
|
4314
5021
|
style: {
|
|
4315
5022
|
color: c.textMuted,
|
|
4316
5023
|
fontFamily: "JetBrains Mono",
|
|
@@ -4344,7 +5051,7 @@ function CalloutCard({
|
|
|
4344
5051
|
const accentText = getReadableToneColor(tone, c);
|
|
4345
5052
|
const engineering = c.preset === "engineering";
|
|
4346
5053
|
const textAlign = align;
|
|
4347
|
-
return
|
|
5054
|
+
return import_react7.default.createElement(
|
|
4348
5055
|
"div",
|
|
4349
5056
|
{
|
|
4350
5057
|
style: {
|
|
@@ -4364,7 +5071,7 @@ function CalloutCard({
|
|
|
4364
5071
|
}
|
|
4365
5072
|
},
|
|
4366
5073
|
...compactChildren([
|
|
4367
|
-
title &&
|
|
5074
|
+
title && import_react7.default.createElement("div", {
|
|
4368
5075
|
style: {
|
|
4369
5076
|
...typography.small,
|
|
4370
5077
|
...titleFontSize != null ? { fontSize: titleFontSize } : {},
|
|
@@ -4375,7 +5082,7 @@ function CalloutCard({
|
|
|
4375
5082
|
textAlign
|
|
4376
5083
|
}
|
|
4377
5084
|
}, title),
|
|
4378
|
-
detail &&
|
|
5085
|
+
detail && import_react7.default.createElement("div", {
|
|
4379
5086
|
style: {
|
|
4380
5087
|
...typography.tiny,
|
|
4381
5088
|
...detailFontSize != null ? { fontSize: detailFontSize } : {},
|
|
@@ -4385,7 +5092,7 @@ function CalloutCard({
|
|
|
4385
5092
|
textAlign
|
|
4386
5093
|
}
|
|
4387
5094
|
}, detail),
|
|
4388
|
-
children &&
|
|
5095
|
+
children && import_react7.default.createElement("div", {
|
|
4389
5096
|
style: {
|
|
4390
5097
|
display: "flex",
|
|
4391
5098
|
flexDirection: "column",
|
|
@@ -4400,7 +5107,7 @@ function CalloutCard({
|
|
|
4400
5107
|
);
|
|
4401
5108
|
}
|
|
4402
5109
|
function Pipeline({ stages, c, title }) {
|
|
4403
|
-
return
|
|
5110
|
+
return import_react7.default.createElement(
|
|
4404
5111
|
"div",
|
|
4405
5112
|
{
|
|
4406
5113
|
style: {
|
|
@@ -4410,10 +5117,10 @@ function Pipeline({ stages, c, title }) {
|
|
|
4410
5117
|
gap: 20
|
|
4411
5118
|
}
|
|
4412
5119
|
},
|
|
4413
|
-
title &&
|
|
5120
|
+
title && import_react7.default.createElement("div", {
|
|
4414
5121
|
style: { ...typography.label, color: c.textPrimary }
|
|
4415
5122
|
}, title),
|
|
4416
|
-
|
|
5123
|
+
import_react7.default.createElement(
|
|
4417
5124
|
"div",
|
|
4418
5125
|
{
|
|
4419
5126
|
style: {
|
|
@@ -4447,7 +5154,7 @@ function Pipeline({ stages, c, title }) {
|
|
|
4447
5154
|
}
|
|
4448
5155
|
|
|
4449
5156
|
// src/primitives/sequence.ts
|
|
4450
|
-
var
|
|
5157
|
+
var import_react8 = __toESM(require("react"), 1);
|
|
4451
5158
|
var sequenceFragmentKinds = ["alt", "loop", "parallel"];
|
|
4452
5159
|
var sequenceMessageKinds = ["sync", "async", "return"];
|
|
4453
5160
|
function isFragment(item) {
|
|
@@ -4686,7 +5393,7 @@ function SequenceDiagram({
|
|
|
4686
5393
|
const spanHeight = Math.max(rowHeight - 8, (span.end - span.start + 1) * rowHeight - 8);
|
|
4687
5394
|
const left = padding + span.depth * fragmentIndent;
|
|
4688
5395
|
const fragmentWidth = Math.max(0, resolvedWidth - left - padding - span.depth * fragmentIndent);
|
|
4689
|
-
return
|
|
5396
|
+
return import_react8.default.createElement(
|
|
4690
5397
|
"div",
|
|
4691
5398
|
{
|
|
4692
5399
|
key: `sequence-fragment-${span.id}`,
|
|
@@ -4705,7 +5412,7 @@ function SequenceDiagram({
|
|
|
4705
5412
|
pointerEvents: "none"
|
|
4706
5413
|
}
|
|
4707
5414
|
},
|
|
4708
|
-
|
|
5415
|
+
import_react8.default.createElement("div", {
|
|
4709
5416
|
style: {
|
|
4710
5417
|
position: "absolute",
|
|
4711
5418
|
left: 8,
|
|
@@ -4723,7 +5430,7 @@ function SequenceDiagram({
|
|
|
4723
5430
|
textTransform: "uppercase"
|
|
4724
5431
|
}
|
|
4725
5432
|
}, span.fragment.kind, span.fragment.label),
|
|
4726
|
-
...span.branchStarts.map((branch) =>
|
|
5433
|
+
...span.branchStarts.map((branch) => import_react8.default.createElement("div", {
|
|
4727
5434
|
key: `sequence-branch-${span.id}-${branch.row}`,
|
|
4728
5435
|
style: {
|
|
4729
5436
|
position: "absolute",
|
|
@@ -4742,7 +5449,7 @@ function SequenceDiagram({
|
|
|
4742
5449
|
});
|
|
4743
5450
|
const lifelineElements = participants.map((participant) => {
|
|
4744
5451
|
const x = participantXs.get(participant.id) ?? resolvedWidth / 2;
|
|
4745
|
-
return
|
|
5452
|
+
return import_react8.default.createElement("line", {
|
|
4746
5453
|
key: `sequence-lifeline-${participant.id}`,
|
|
4747
5454
|
x1: x,
|
|
4748
5455
|
y1: bodyTop - 14,
|
|
@@ -4766,7 +5473,7 @@ function SequenceDiagram({
|
|
|
4766
5473
|
const accent = activation.muted ? c.textMuted : getToneColor(activation.tone ?? "blue", c);
|
|
4767
5474
|
const top = rowCenter(start) - rowHeight / 2 + 5;
|
|
4768
5475
|
const activationHeight = Math.max(14, (end - start + 1) * rowHeight - 10);
|
|
4769
|
-
return
|
|
5476
|
+
return import_react8.default.createElement("div", {
|
|
4770
5477
|
key: `sequence-activation-${activation.id ?? index}`,
|
|
4771
5478
|
"data-vizmatic-sequence-activation": activation.participant,
|
|
4772
5479
|
style: {
|
|
@@ -4795,10 +5502,10 @@ function SequenceDiagram({
|
|
|
4795
5502
|
const markerId = `sequence-arrow-${participants.findIndex((participant) => participant.id === message.to)}-${kind}`;
|
|
4796
5503
|
const y = rowCenter(rowIndex);
|
|
4797
5504
|
const selfLoop = message.from === message.to;
|
|
4798
|
-
return
|
|
4799
|
-
|
|
5505
|
+
return import_react8.default.createElement(
|
|
5506
|
+
import_react8.default.Fragment,
|
|
4800
5507
|
{ key: `sequence-message-${message.id ?? row.key}` },
|
|
4801
|
-
|
|
5508
|
+
import_react8.default.createElement("path", {
|
|
4802
5509
|
d: sequenceMarkerPath(fromX, toX, y, rowHeight, selfLoop),
|
|
4803
5510
|
fill: "none",
|
|
4804
5511
|
stroke: color,
|
|
@@ -4808,7 +5515,7 @@ function SequenceDiagram({
|
|
|
4808
5515
|
opacity: message.muted ? 0.48 : 0.9,
|
|
4809
5516
|
markerEnd: `url(#${markerId})`
|
|
4810
5517
|
}),
|
|
4811
|
-
message.label != null &&
|
|
5518
|
+
message.label != null && import_react8.default.createElement("div", {
|
|
4812
5519
|
style: {
|
|
4813
5520
|
position: "absolute",
|
|
4814
5521
|
left: selfLoop ? fromX + 34 : (fromX + toX) / 2,
|
|
@@ -4834,7 +5541,7 @@ function SequenceDiagram({
|
|
|
4834
5541
|
const bounds = sequenceNoteBounds(note, participantXs, resolvedWidth, noteWidth, padding);
|
|
4835
5542
|
const tone = note.tone ?? "warm";
|
|
4836
5543
|
const accent = note.muted ? c.textMuted : getToneColor(tone, c);
|
|
4837
|
-
return
|
|
5544
|
+
return import_react8.default.createElement("div", {
|
|
4838
5545
|
key: `sequence-note-${note.id ?? row.key}`,
|
|
4839
5546
|
"data-vizmatic-sequence-note": note.id ?? row.key,
|
|
4840
5547
|
style: {
|
|
@@ -4873,7 +5580,7 @@ function SequenceDiagram({
|
|
|
4873
5580
|
muted: participant.muted,
|
|
4874
5581
|
label: readableNodeText(participant.label) ? `${readableNodeText(participant.label)} icon` : void 0
|
|
4875
5582
|
});
|
|
4876
|
-
return
|
|
5583
|
+
return import_react8.default.createElement(
|
|
4877
5584
|
"div",
|
|
4878
5585
|
{
|
|
4879
5586
|
key: `sequence-participant-${participant.id}`,
|
|
@@ -4900,7 +5607,7 @@ function SequenceDiagram({
|
|
|
4900
5607
|
}
|
|
4901
5608
|
},
|
|
4902
5609
|
icon,
|
|
4903
|
-
|
|
5610
|
+
import_react8.default.createElement(
|
|
4904
5611
|
"div",
|
|
4905
5612
|
{
|
|
4906
5613
|
style: {
|
|
@@ -4911,7 +5618,7 @@ function SequenceDiagram({
|
|
|
4911
5618
|
gap: participant.detail ? 3 : 0
|
|
4912
5619
|
}
|
|
4913
5620
|
},
|
|
4914
|
-
|
|
5621
|
+
import_react8.default.createElement("div", {
|
|
4915
5622
|
style: {
|
|
4916
5623
|
fontFamily: c.fontSans,
|
|
4917
5624
|
fontSize: 12,
|
|
@@ -4920,7 +5627,7 @@ function SequenceDiagram({
|
|
|
4920
5627
|
...textFitStyle(icon ? "left" : "center")
|
|
4921
5628
|
}
|
|
4922
5629
|
}, participant.label),
|
|
4923
|
-
participant.detail != null &&
|
|
5630
|
+
participant.detail != null && import_react8.default.createElement("div", {
|
|
4924
5631
|
style: {
|
|
4925
5632
|
color: c.textMuted,
|
|
4926
5633
|
fontFamily: c.fontMono,
|
|
@@ -4933,7 +5640,7 @@ function SequenceDiagram({
|
|
|
4933
5640
|
)
|
|
4934
5641
|
);
|
|
4935
5642
|
});
|
|
4936
|
-
return
|
|
5643
|
+
return import_react8.default.createElement(
|
|
4937
5644
|
"div",
|
|
4938
5645
|
{
|
|
4939
5646
|
role: "img",
|
|
@@ -4949,7 +5656,7 @@ function SequenceDiagram({
|
|
|
4949
5656
|
}
|
|
4950
5657
|
},
|
|
4951
5658
|
...fragmentElements,
|
|
4952
|
-
|
|
5659
|
+
import_react8.default.createElement(
|
|
4953
5660
|
"svg",
|
|
4954
5661
|
{
|
|
4955
5662
|
width: resolvedWidth,
|
|
@@ -4957,14 +5664,14 @@ function SequenceDiagram({
|
|
|
4957
5664
|
viewBox: `0 0 ${resolvedWidth} ${resolvedHeight}`,
|
|
4958
5665
|
style: { position: "absolute", inset: 0, overflow: "visible" }
|
|
4959
5666
|
},
|
|
4960
|
-
|
|
5667
|
+
import_react8.default.createElement("defs", {}, ...markerDefinitions),
|
|
4961
5668
|
...lifelineElements,
|
|
4962
5669
|
...messageElements
|
|
4963
5670
|
),
|
|
4964
5671
|
...activationElements,
|
|
4965
5672
|
...noteElements,
|
|
4966
5673
|
...participantElements,
|
|
4967
|
-
title != null &&
|
|
5674
|
+
title != null && import_react8.default.createElement("div", {
|
|
4968
5675
|
style: {
|
|
4969
5676
|
position: "absolute",
|
|
4970
5677
|
left: padding,
|
|
@@ -4975,7 +5682,7 @@ function SequenceDiagram({
|
|
|
4975
5682
|
fontWeight: 850
|
|
4976
5683
|
}
|
|
4977
5684
|
}, title),
|
|
4978
|
-
subtitle != null &&
|
|
5685
|
+
subtitle != null && import_react8.default.createElement("div", {
|
|
4979
5686
|
style: {
|
|
4980
5687
|
position: "absolute",
|
|
4981
5688
|
left: padding,
|
|
@@ -5006,7 +5713,7 @@ function sequenceMessageKindsForMarkers(items) {
|
|
|
5006
5713
|
}
|
|
5007
5714
|
|
|
5008
5715
|
// src/primitives/dataflow.ts
|
|
5009
|
-
var
|
|
5716
|
+
var import_react9 = __toESM(require("react"), 1);
|
|
5010
5717
|
var nodeKinds = ["source", "transform", "store", "sink"];
|
|
5011
5718
|
var edgeModes = ["batch", "stream"];
|
|
5012
5719
|
var defaultNodeTones = {
|
|
@@ -5058,7 +5765,7 @@ function detailWithSchema(detail, schema) {
|
|
|
5058
5765
|
if (!renderedSchema) return detail;
|
|
5059
5766
|
if (detail == null) return renderedSchema;
|
|
5060
5767
|
if (typeof detail === "string" || typeof detail === "number") return `${detail} \xB7 ${renderedSchema}`;
|
|
5061
|
-
return
|
|
5768
|
+
return import_react9.default.createElement(
|
|
5062
5769
|
"div",
|
|
5063
5770
|
{
|
|
5064
5771
|
style: {
|
|
@@ -5068,8 +5775,8 @@ function detailWithSchema(detail, schema) {
|
|
|
5068
5775
|
minWidth: 0
|
|
5069
5776
|
}
|
|
5070
5777
|
},
|
|
5071
|
-
|
|
5072
|
-
|
|
5778
|
+
import_react9.default.createElement("div", null, detail),
|
|
5779
|
+
import_react9.default.createElement("div", {
|
|
5073
5780
|
style: {
|
|
5074
5781
|
fontFamily: "inherit",
|
|
5075
5782
|
fontSize: "inherit",
|
|
@@ -5153,6 +5860,8 @@ function compileDataflow(spec) {
|
|
|
5153
5860
|
id: node.id,
|
|
5154
5861
|
label: node.label,
|
|
5155
5862
|
detail: detailWithSchema(node.detail, node.schema),
|
|
5863
|
+
href: node.href,
|
|
5864
|
+
title: node.title,
|
|
5156
5865
|
tone: node.tone ?? defaultNodeTones[kind],
|
|
5157
5866
|
icon: node.icon ?? defaultNodeIcons[kind],
|
|
5158
5867
|
muted: node.muted,
|
|
@@ -5165,9 +5874,12 @@ function compileDataflow(spec) {
|
|
|
5165
5874
|
const mode = edgeMode(edge);
|
|
5166
5875
|
const schema = schemaLabel(edge.schema);
|
|
5167
5876
|
return {
|
|
5877
|
+
id: edge.id,
|
|
5168
5878
|
from: edge.from,
|
|
5169
5879
|
to: edge.to,
|
|
5170
5880
|
label: edge.label ?? schema ?? mode,
|
|
5881
|
+
href: edge.href,
|
|
5882
|
+
title: edge.title,
|
|
5171
5883
|
tone: edge.tone ?? (mode === "stream" ? "cyan" : "blue"),
|
|
5172
5884
|
muted: edge.muted,
|
|
5173
5885
|
kind: mode === "stream" ? "async" : "data",
|
|
@@ -5188,6 +5900,9 @@ function DataflowDiagram({
|
|
|
5188
5900
|
edges,
|
|
5189
5901
|
boundaries,
|
|
5190
5902
|
ariaLabel,
|
|
5903
|
+
id,
|
|
5904
|
+
title,
|
|
5905
|
+
description,
|
|
5191
5906
|
width,
|
|
5192
5907
|
height,
|
|
5193
5908
|
nodeWidth = 158,
|
|
@@ -5200,6 +5915,8 @@ function DataflowDiagram({
|
|
|
5200
5915
|
nodeGap,
|
|
5201
5916
|
rankGap,
|
|
5202
5917
|
edgeGap,
|
|
5918
|
+
routing,
|
|
5919
|
+
routingClearance,
|
|
5203
5920
|
sizing,
|
|
5204
5921
|
iconSize
|
|
5205
5922
|
}) {
|
|
@@ -5210,6 +5927,9 @@ function DataflowDiagram({
|
|
|
5210
5927
|
edges: compiled.edges,
|
|
5211
5928
|
groups: compiled.groups,
|
|
5212
5929
|
ariaLabel: compiled.ariaLabel,
|
|
5930
|
+
id,
|
|
5931
|
+
title,
|
|
5932
|
+
description,
|
|
5213
5933
|
width,
|
|
5214
5934
|
height,
|
|
5215
5935
|
nodeWidth,
|
|
@@ -5222,10 +5942,13 @@ function DataflowDiagram({
|
|
|
5222
5942
|
nodeGap,
|
|
5223
5943
|
rankGap,
|
|
5224
5944
|
edgeGap,
|
|
5945
|
+
routing,
|
|
5946
|
+
routingClearance,
|
|
5225
5947
|
sizing,
|
|
5226
5948
|
iconSize
|
|
5227
5949
|
});
|
|
5228
5950
|
}
|
|
5951
|
+
Object.defineProperty(DataflowDiagram, SVG_ACCESSIBILITY_COMPONENT, { value: true });
|
|
5229
5952
|
|
|
5230
5953
|
// src/primitives/deployment.ts
|
|
5231
5954
|
var boundaryKindLabels = {
|
|
@@ -5349,8 +6072,8 @@ function portIdentity(port) {
|
|
|
5349
6072
|
function portText(port) {
|
|
5350
6073
|
if (typeof port === "string" || typeof port === "number") return String(port);
|
|
5351
6074
|
if (port.label) return port.label;
|
|
5352
|
-
const
|
|
5353
|
-
return [port.protocol,
|
|
6075
|
+
const endpoint2 = port.port ?? port.id;
|
|
6076
|
+
return [port.protocol, endpoint2 == null ? void 0 : String(endpoint2)].filter(Boolean).join("/") || port.direction || "port";
|
|
5354
6077
|
}
|
|
5355
6078
|
function portForReference(node, reference) {
|
|
5356
6079
|
if (reference == null) return void 0;
|
|
@@ -5438,10 +6161,10 @@ function validateDeploymentSpec(boundaries, nodes, connections) {
|
|
|
5438
6161
|
for (const side of ["from", "to"]) {
|
|
5439
6162
|
const reference = connectionPortReference(connection, side);
|
|
5440
6163
|
if (reference == null) continue;
|
|
5441
|
-
const
|
|
5442
|
-
const ports = portsByNode.get(
|
|
6164
|
+
const nodeId2 = side === "from" ? connection.from : connection.to;
|
|
6165
|
+
const ports = portsByNode.get(nodeId2);
|
|
5443
6166
|
if (ports != null && ports.size > 0 && !ports.has(String(reference))) {
|
|
5444
|
-
throw new Error(`DeploymentDiagram connection "${connection.from}" -> "${connection.to}" references missing ${side} port "${reference}" on node "${
|
|
6167
|
+
throw new Error(`DeploymentDiagram connection "${connection.from}" -> "${connection.to}" references missing ${side} port "${reference}" on node "${nodeId2}".`);
|
|
5445
6168
|
}
|
|
5446
6169
|
}
|
|
5447
6170
|
}
|
|
@@ -5460,6 +6183,9 @@ function compileDeployment(spec) {
|
|
|
5460
6183
|
const boundaries = spec.boundaries ?? [];
|
|
5461
6184
|
const connections = spec.connections ?? [];
|
|
5462
6185
|
validateDeploymentSpec(boundaries, spec.nodes, connections);
|
|
6186
|
+
const anchorPorts = spec.routing != null && spec.routing !== "dagre";
|
|
6187
|
+
const incomingSide = spec.direction === "TB" ? "top" : spec.direction === "BT" ? "bottom" : spec.direction === "RL" ? "right" : "left";
|
|
6188
|
+
const outgoingSide = spec.direction === "TB" ? "bottom" : spec.direction === "BT" ? "top" : spec.direction === "RL" ? "left" : "right";
|
|
5463
6189
|
const groups = boundaries.map((boundary) => ({
|
|
5464
6190
|
id: boundary.id,
|
|
5465
6191
|
label: boundary.label,
|
|
@@ -5476,6 +6202,8 @@ function compileDeployment(spec) {
|
|
|
5476
6202
|
id: node.id,
|
|
5477
6203
|
label: node.label,
|
|
5478
6204
|
detail: node.detail ?? generatedDetail,
|
|
6205
|
+
href: node.href,
|
|
6206
|
+
title: node.title,
|
|
5479
6207
|
x: node.x,
|
|
5480
6208
|
y: node.y,
|
|
5481
6209
|
tone: node.tone,
|
|
@@ -5484,7 +6212,16 @@ function compileDeployment(spec) {
|
|
|
5484
6212
|
height: node.height,
|
|
5485
6213
|
group: node.boundary,
|
|
5486
6214
|
icon: node.icon ?? nodeKindIcons[kind],
|
|
5487
|
-
iconSize: node.iconSize
|
|
6215
|
+
iconSize: node.iconSize,
|
|
6216
|
+
ports: anchorPorts ? nodePorts.map((port, index) => {
|
|
6217
|
+
const incoming = typeof port === "object" ? port.direction === "ingress" : false;
|
|
6218
|
+
const targetOnly = connections.some((connection) => connection.to === node.id && String(connection.toPort) === portIdentity(port)) && !connections.some((connection) => connection.from === node.id && String(connection.fromPort) === portIdentity(port));
|
|
6219
|
+
return {
|
|
6220
|
+
id: portIdentity(port),
|
|
6221
|
+
side: typeof port === "object" && port.side != null ? port.side : incoming || targetOnly ? incomingSide : outgoingSide,
|
|
6222
|
+
offset: typeof port === "object" && port.offset != null ? port.offset : (index + 1) / (nodePorts.length + 1)
|
|
6223
|
+
};
|
|
6224
|
+
}) : void 0
|
|
5488
6225
|
};
|
|
5489
6226
|
});
|
|
5490
6227
|
const edges = connections.map((connection) => {
|
|
@@ -5498,6 +6235,7 @@ function compileDeployment(spec) {
|
|
|
5498
6235
|
const fallbackFromPort = fromReference != null && !sourceNode?.ports?.length ? fromReference : void 0;
|
|
5499
6236
|
const fallbackToPort = toReference != null && !targetNode?.ports?.length ? toReference : void 0;
|
|
5500
6237
|
return {
|
|
6238
|
+
id: connection.id,
|
|
5501
6239
|
from: connection.from,
|
|
5502
6240
|
to: connection.to,
|
|
5503
6241
|
tone: connection.tone ?? connectionTones[kind],
|
|
@@ -5505,7 +6243,13 @@ function compileDeployment(spec) {
|
|
|
5505
6243
|
kind: graphConnectionKind(kind),
|
|
5506
6244
|
style: connection.style ?? graphConnectionStyle(kind),
|
|
5507
6245
|
arrow: connection.arrow ?? "forward",
|
|
5508
|
-
label: connectionLabel(connection, sourcePort ?? fallbackFromPort, targetPort ?? fallbackToPort)
|
|
6246
|
+
label: connectionLabel(connection, sourcePort ?? fallbackFromPort, targetPort ?? fallbackToPort),
|
|
6247
|
+
href: connection.href,
|
|
6248
|
+
title: connection.title,
|
|
6249
|
+
fromPort: anchorPorts && fromReference != null ? String(fromReference) : void 0,
|
|
6250
|
+
toPort: anchorPorts && toReference != null ? String(toReference) : void 0,
|
|
6251
|
+
fromSide: connection.fromSide,
|
|
6252
|
+
toSide: connection.toSide
|
|
5509
6253
|
};
|
|
5510
6254
|
});
|
|
5511
6255
|
return {
|
|
@@ -5523,7 +6267,7 @@ function DeploymentDiagram({
|
|
|
5523
6267
|
ariaLabel = "Deployment diagram",
|
|
5524
6268
|
...graphProps
|
|
5525
6269
|
}) {
|
|
5526
|
-
const compiled = compileDeployment({ nodes, boundaries, connections, ariaLabel });
|
|
6270
|
+
const compiled = compileDeployment({ nodes, boundaries, connections, ariaLabel, direction: graphProps.direction, routing: graphProps.routing });
|
|
5527
6271
|
return GraphDiagram({
|
|
5528
6272
|
...graphProps,
|
|
5529
6273
|
c,
|
|
@@ -5533,6 +6277,7 @@ function DeploymentDiagram({
|
|
|
5533
6277
|
ariaLabel: compiled.ariaLabel
|
|
5534
6278
|
});
|
|
5535
6279
|
}
|
|
6280
|
+
Object.defineProperty(DeploymentDiagram, SVG_ACCESSIBILITY_COMPONENT, { value: true });
|
|
5536
6281
|
|
|
5537
6282
|
// src/primitives/transformer.ts
|
|
5538
6283
|
var blockLabels = {
|
|
@@ -5731,6 +6476,8 @@ function compileTransformer(spec) {
|
|
|
5731
6476
|
id,
|
|
5732
6477
|
label,
|
|
5733
6478
|
detail: repetitionDetail,
|
|
6479
|
+
href: block.href,
|
|
6480
|
+
title: block.title,
|
|
5734
6481
|
x: block.x,
|
|
5735
6482
|
y: block.y,
|
|
5736
6483
|
tone: block.tone ?? blockTones[kind],
|
|
@@ -5745,16 +6492,20 @@ function compileTransformer(spec) {
|
|
|
5745
6492
|
const edges = [];
|
|
5746
6493
|
for (const route of routes) {
|
|
5747
6494
|
const kind = resolveRouteKind(route);
|
|
5748
|
-
|
|
6495
|
+
const endpoints = expandedRouteEndpoints(route, repeatCounts, expandRepeats);
|
|
6496
|
+
for (const [index, endpoint2] of endpoints.entries()) {
|
|
5749
6497
|
edges.push({
|
|
5750
|
-
|
|
5751
|
-
|
|
6498
|
+
id: route.id == null ? void 0 : endpoints.length === 1 ? route.id : `${route.id}-${index + 1}`,
|
|
6499
|
+
from: endpoint2.from,
|
|
6500
|
+
to: endpoint2.to,
|
|
5752
6501
|
tone: route.tone ?? routeTones[kind],
|
|
5753
6502
|
muted: route.muted,
|
|
5754
6503
|
kind: graphRouteKind(kind),
|
|
5755
6504
|
style: route.style ?? graphRouteStyle(kind),
|
|
5756
6505
|
arrow: route.arrow ?? (kind === "residual" ? "both" : "forward"),
|
|
5757
|
-
label: routeLabel(route, kind)
|
|
6506
|
+
label: routeLabel(route, kind),
|
|
6507
|
+
href: route.href,
|
|
6508
|
+
title: route.title
|
|
5758
6509
|
});
|
|
5759
6510
|
}
|
|
5760
6511
|
}
|
|
@@ -5786,9 +6537,10 @@ function TransformerTopology({
|
|
|
5786
6537
|
ariaLabel: compiled.ariaLabel
|
|
5787
6538
|
});
|
|
5788
6539
|
}
|
|
6540
|
+
Object.defineProperty(TransformerTopology, SVG_ACCESSIBILITY_COMPONENT, { value: true });
|
|
5789
6541
|
|
|
5790
6542
|
// src/primitives/data.ts
|
|
5791
|
-
var
|
|
6543
|
+
var import_react10 = __toESM(require("react"), 1);
|
|
5792
6544
|
function Matrix({
|
|
5793
6545
|
data,
|
|
5794
6546
|
c,
|
|
@@ -5818,7 +6570,7 @@ function Matrix({
|
|
|
5818
6570
|
if (value < 0.67) return c.infoDark;
|
|
5819
6571
|
return c.positiveDark;
|
|
5820
6572
|
};
|
|
5821
|
-
return
|
|
6573
|
+
return import_react10.default.createElement(
|
|
5822
6574
|
"div",
|
|
5823
6575
|
{
|
|
5824
6576
|
style: {
|
|
@@ -5828,10 +6580,10 @@ function Matrix({
|
|
|
5828
6580
|
gap: 12
|
|
5829
6581
|
}
|
|
5830
6582
|
},
|
|
5831
|
-
title &&
|
|
6583
|
+
title && import_react10.default.createElement("div", {
|
|
5832
6584
|
style: { ...typography.label, color: c.textPrimary }
|
|
5833
6585
|
}, title),
|
|
5834
|
-
|
|
6586
|
+
import_react10.default.createElement(
|
|
5835
6587
|
"div",
|
|
5836
6588
|
{
|
|
5837
6589
|
style: {
|
|
@@ -5841,7 +6593,7 @@ function Matrix({
|
|
|
5841
6593
|
}
|
|
5842
6594
|
},
|
|
5843
6595
|
// Column labels
|
|
5844
|
-
colLabels &&
|
|
6596
|
+
colLabels && import_react10.default.createElement(
|
|
5845
6597
|
"div",
|
|
5846
6598
|
{
|
|
5847
6599
|
style: {
|
|
@@ -5851,7 +6603,7 @@ function Matrix({
|
|
|
5851
6603
|
}
|
|
5852
6604
|
},
|
|
5853
6605
|
...colLabels.map(
|
|
5854
|
-
(label, i) =>
|
|
6606
|
+
(label, i) => import_react10.default.createElement("div", {
|
|
5855
6607
|
key: `col-${i}`,
|
|
5856
6608
|
style: {
|
|
5857
6609
|
width: resolvedCellWidth,
|
|
@@ -5865,7 +6617,7 @@ function Matrix({
|
|
|
5865
6617
|
)
|
|
5866
6618
|
),
|
|
5867
6619
|
...data.map(
|
|
5868
|
-
(row, ri) =>
|
|
6620
|
+
(row, ri) => import_react10.default.createElement(
|
|
5869
6621
|
"div",
|
|
5870
6622
|
{
|
|
5871
6623
|
key: `row-${ri}`,
|
|
@@ -5875,7 +6627,7 @@ function Matrix({
|
|
|
5875
6627
|
alignItems: "center"
|
|
5876
6628
|
}
|
|
5877
6629
|
},
|
|
5878
|
-
rowLabels &&
|
|
6630
|
+
rowLabels && import_react10.default.createElement("div", {
|
|
5879
6631
|
style: {
|
|
5880
6632
|
width: resolvedRowLabelWidth,
|
|
5881
6633
|
textAlign: "right",
|
|
@@ -5888,7 +6640,7 @@ function Matrix({
|
|
|
5888
6640
|
}, rowLabels[ri]),
|
|
5889
6641
|
...row.map((value, ci) => {
|
|
5890
6642
|
const backgroundColor = colorize ? cellColor(value) : c.bgCard;
|
|
5891
|
-
return
|
|
6643
|
+
return import_react10.default.createElement("div", {
|
|
5892
6644
|
key: `cell-${ri}-${ci}`,
|
|
5893
6645
|
style: {
|
|
5894
6646
|
width: resolvedCellWidth,
|
|
@@ -5957,7 +6709,7 @@ function TiledMatrix({
|
|
|
5957
6709
|
const baseAccent = getToneColor(tone, c);
|
|
5958
6710
|
const cellRows = Array.from(
|
|
5959
6711
|
{ length: safeRows },
|
|
5960
|
-
(_, row) =>
|
|
6712
|
+
(_, row) => import_react10.default.createElement(
|
|
5961
6713
|
"div",
|
|
5962
6714
|
{
|
|
5963
6715
|
key: `tiled-matrix-row-${row}`,
|
|
@@ -5972,7 +6724,7 @@ function TiledMatrix({
|
|
|
5972
6724
|
);
|
|
5973
6725
|
const region = regionIndex >= 0 ? regions[regionIndex] : void 0;
|
|
5974
6726
|
const accent = getToneColor(region?.tone ?? tone, c);
|
|
5975
|
-
return
|
|
6727
|
+
return import_react10.default.createElement("div", {
|
|
5976
6728
|
key: `tiled-matrix-cell-${row}-${col}`,
|
|
5977
6729
|
"data-region": regionIndex >= 0 ? regionIndex : void 0,
|
|
5978
6730
|
style: {
|
|
@@ -5988,7 +6740,7 @@ function TiledMatrix({
|
|
|
5988
6740
|
})
|
|
5989
6741
|
)
|
|
5990
6742
|
);
|
|
5991
|
-
const grid =
|
|
6743
|
+
const grid = import_react10.default.createElement(
|
|
5992
6744
|
"div",
|
|
5993
6745
|
{
|
|
5994
6746
|
"data-crossed-out": crossedOut ? "true" : void 0,
|
|
@@ -6007,7 +6759,7 @@ function TiledMatrix({
|
|
|
6007
6759
|
},
|
|
6008
6760
|
...cellRows,
|
|
6009
6761
|
...crossedOut ? [
|
|
6010
|
-
|
|
6762
|
+
import_react10.default.createElement("div", {
|
|
6011
6763
|
key: "cross-forward",
|
|
6012
6764
|
style: {
|
|
6013
6765
|
position: "absolute",
|
|
@@ -6022,7 +6774,7 @@ function TiledMatrix({
|
|
|
6022
6774
|
boxShadow: `0 0 0 1px ${c.bgCard}`
|
|
6023
6775
|
}
|
|
6024
6776
|
}),
|
|
6025
|
-
|
|
6777
|
+
import_react10.default.createElement("div", {
|
|
6026
6778
|
key: "cross-backward",
|
|
6027
6779
|
style: {
|
|
6028
6780
|
position: "absolute",
|
|
@@ -6039,7 +6791,7 @@ function TiledMatrix({
|
|
|
6039
6791
|
})
|
|
6040
6792
|
] : []
|
|
6041
6793
|
);
|
|
6042
|
-
return
|
|
6794
|
+
return import_react10.default.createElement(
|
|
6043
6795
|
"div",
|
|
6044
6796
|
{
|
|
6045
6797
|
role: "img",
|
|
@@ -6052,7 +6804,7 @@ function TiledMatrix({
|
|
|
6052
6804
|
}
|
|
6053
6805
|
},
|
|
6054
6806
|
...compactChildren([
|
|
6055
|
-
title &&
|
|
6807
|
+
title && import_react10.default.createElement("div", {
|
|
6056
6808
|
style: {
|
|
6057
6809
|
color: muted ? c.textMuted : getReadableToneColor(tone, c),
|
|
6058
6810
|
fontFamily: "Inter",
|
|
@@ -6062,7 +6814,7 @@ function TiledMatrix({
|
|
|
6062
6814
|
textAlign: "center"
|
|
6063
6815
|
}
|
|
6064
6816
|
}, title),
|
|
6065
|
-
subtitle &&
|
|
6817
|
+
subtitle && import_react10.default.createElement("div", {
|
|
6066
6818
|
style: {
|
|
6067
6819
|
color: c.textMuted,
|
|
6068
6820
|
fontFamily: "JetBrains Mono",
|
|
@@ -6089,7 +6841,7 @@ function DataTable({
|
|
|
6089
6841
|
math = false
|
|
6090
6842
|
}) {
|
|
6091
6843
|
const renderCell = (cell) => math && typeof cell === "string" ? formatMathText(cell) : cell;
|
|
6092
|
-
return
|
|
6844
|
+
return import_react10.default.createElement(
|
|
6093
6845
|
"div",
|
|
6094
6846
|
{
|
|
6095
6847
|
style: {
|
|
@@ -6099,7 +6851,7 @@ function DataTable({
|
|
|
6099
6851
|
alignItems: "center"
|
|
6100
6852
|
}
|
|
6101
6853
|
},
|
|
6102
|
-
...rows.map((row, rowIndex) =>
|
|
6854
|
+
...rows.map((row, rowIndex) => import_react10.default.createElement(
|
|
6103
6855
|
"div",
|
|
6104
6856
|
{
|
|
6105
6857
|
key: `${rowIndex}-${row.map(String).join("|")}`,
|
|
@@ -6111,7 +6863,7 @@ function DataTable({
|
|
|
6111
6863
|
...row.map((cell, colIndex) => {
|
|
6112
6864
|
const isHeaderRow = rowIndex < headerRows;
|
|
6113
6865
|
const isHeaderCol = colIndex < headerCols;
|
|
6114
|
-
return
|
|
6866
|
+
return import_react10.default.createElement("div", {
|
|
6115
6867
|
key: `${rowIndex}-${colIndex}-${String(cell)}`,
|
|
6116
6868
|
style: {
|
|
6117
6869
|
width: colIndex === 0 ? firstColWidth : cellWidth,
|
|
@@ -6134,7 +6886,7 @@ function DataTable({
|
|
|
6134
6886
|
);
|
|
6135
6887
|
}
|
|
6136
6888
|
function isGridCell(cell) {
|
|
6137
|
-
return typeof cell === "object" && cell !== null && !
|
|
6889
|
+
return typeof cell === "object" && cell !== null && !import_react10.default.isValidElement(cell) && ("label" in cell || "tone" in cell || "color" in cell || "backgroundColor" in cell || "borderColor" in cell || "opacity" in cell);
|
|
6138
6890
|
}
|
|
6139
6891
|
function Grid({
|
|
6140
6892
|
rows,
|
|
@@ -6155,8 +6907,9 @@ function Grid({
|
|
|
6155
6907
|
const cellStyle = (cell, rowIndex, colIndex) => {
|
|
6156
6908
|
const config = isGridCell(cell) ? cell : {};
|
|
6157
6909
|
const toneColor = config.tone ? getToneColor(config.tone, c) : void 0;
|
|
6158
|
-
const toneTextColor = config.tone ? getReadableToneColor(config.tone, c) : void 0;
|
|
6159
6910
|
const isHeader = rowIndex < headerRows || colIndex < headerCols;
|
|
6911
|
+
const backgroundColor = config.backgroundColor ?? (toneColor ? `${toneColor}22` : isHeader ? c.bgSubtle : c.bgHover);
|
|
6912
|
+
const toneTextColor = config.tone ? getReadableToneColor(config.tone, c, backgroundColor, c.bgHover) : void 0;
|
|
6160
6913
|
return {
|
|
6161
6914
|
width: cellWidth,
|
|
6162
6915
|
height: cellHeight,
|
|
@@ -6164,7 +6917,7 @@ function Grid({
|
|
|
6164
6917
|
alignItems: "center",
|
|
6165
6918
|
justifyContent: "center",
|
|
6166
6919
|
borderRadius: radius,
|
|
6167
|
-
backgroundColor
|
|
6920
|
+
backgroundColor,
|
|
6168
6921
|
border: `1px solid ${config.borderColor ?? (toneColor ? `${toneColor}55` : c.borderSubtle)}`,
|
|
6169
6922
|
color: config.color ?? (toneTextColor ?? (isHeader ? c.textPrimary : c.textSecondary)),
|
|
6170
6923
|
...config.opacity !== void 0 ? { opacity: config.opacity } : {},
|
|
@@ -6175,7 +6928,7 @@ function Grid({
|
|
|
6175
6928
|
...textFitStyle("center")
|
|
6176
6929
|
};
|
|
6177
6930
|
};
|
|
6178
|
-
return
|
|
6931
|
+
return import_react10.default.createElement(
|
|
6179
6932
|
"div",
|
|
6180
6933
|
{
|
|
6181
6934
|
style: {
|
|
@@ -6185,7 +6938,7 @@ function Grid({
|
|
|
6185
6938
|
alignItems: "center"
|
|
6186
6939
|
}
|
|
6187
6940
|
},
|
|
6188
|
-
...rows.map((row, rowIndex) =>
|
|
6941
|
+
...rows.map((row, rowIndex) => import_react10.default.createElement(
|
|
6189
6942
|
"div",
|
|
6190
6943
|
{
|
|
6191
6944
|
key: `grid-row-${rowIndex}`,
|
|
@@ -6194,7 +6947,7 @@ function Grid({
|
|
|
6194
6947
|
gap
|
|
6195
6948
|
}
|
|
6196
6949
|
},
|
|
6197
|
-
...row.map((cell, colIndex) =>
|
|
6950
|
+
...row.map((cell, colIndex) => import_react10.default.createElement("div", {
|
|
6198
6951
|
key: `grid-cell-${rowIndex}-${colIndex}`,
|
|
6199
6952
|
style: cellStyle(cell, rowIndex, colIndex)
|
|
6200
6953
|
}, renderCellLabel(cell)))
|
|
@@ -6254,7 +7007,7 @@ function AxisPlot({
|
|
|
6254
7007
|
const x = padding + innerWidth * index / (gridCount + 1);
|
|
6255
7008
|
const y = padding + innerHeight * index / (gridCount + 1);
|
|
6256
7009
|
return [
|
|
6257
|
-
|
|
7010
|
+
import_react10.default.createElement("line", {
|
|
6258
7011
|
key: `axis-grid-x-${index}`,
|
|
6259
7012
|
x1: x,
|
|
6260
7013
|
y1: padding,
|
|
@@ -6264,7 +7017,7 @@ function AxisPlot({
|
|
|
6264
7017
|
strokeWidth: 1,
|
|
6265
7018
|
opacity: 0.75
|
|
6266
7019
|
}),
|
|
6267
|
-
|
|
7020
|
+
import_react10.default.createElement("line", {
|
|
6268
7021
|
key: `axis-grid-y-${index}`,
|
|
6269
7022
|
x1: padding,
|
|
6270
7023
|
y1: y,
|
|
@@ -6279,7 +7032,7 @@ function AxisPlot({
|
|
|
6279
7032
|
}
|
|
6280
7033
|
if (showAxes) {
|
|
6281
7034
|
elements.push(
|
|
6282
|
-
|
|
7035
|
+
import_react10.default.createElement("line", {
|
|
6283
7036
|
key: "axis-x",
|
|
6284
7037
|
x1: padding,
|
|
6285
7038
|
y1: xAxisY,
|
|
@@ -6289,7 +7042,7 @@ function AxisPlot({
|
|
|
6289
7042
|
strokeWidth: 1.6,
|
|
6290
7043
|
opacity: 0.85
|
|
6291
7044
|
}),
|
|
6292
|
-
|
|
7045
|
+
import_react10.default.createElement("line", {
|
|
6293
7046
|
key: "axis-y",
|
|
6294
7047
|
x1: yAxisX,
|
|
6295
7048
|
y1: padding,
|
|
@@ -6312,7 +7065,7 @@ function AxisPlot({
|
|
|
6312
7065
|
commands.push(`L ${sx(point.x)} ${sy(point.y)}`);
|
|
6313
7066
|
}
|
|
6314
7067
|
}
|
|
6315
|
-
return [
|
|
7068
|
+
return [import_react10.default.createElement("path", {
|
|
6316
7069
|
key: `axis-path-${index}`,
|
|
6317
7070
|
d: commands.join(" "),
|
|
6318
7071
|
fill: "none",
|
|
@@ -6367,14 +7120,14 @@ function AxisPlot({
|
|
|
6367
7120
|
strokeWidth: point.strokeWidth,
|
|
6368
7121
|
opacity: point.opacity
|
|
6369
7122
|
})));
|
|
6370
|
-
elements.push(...
|
|
6371
|
-
const svg =
|
|
7123
|
+
elements.push(...import_react10.default.Children.toArray(children).filter(import_react10.default.isValidElement));
|
|
7124
|
+
const svg = import_react10.default.createElement("svg", {
|
|
6372
7125
|
width,
|
|
6373
7126
|
height,
|
|
6374
7127
|
viewBox: `0 0 ${width} ${height}`
|
|
6375
7128
|
}, ...elements);
|
|
6376
7129
|
if (!xAxisLabel && !yAxisLabel) return svg;
|
|
6377
|
-
return
|
|
7130
|
+
return import_react10.default.createElement(
|
|
6378
7131
|
"div",
|
|
6379
7132
|
{
|
|
6380
7133
|
style: {
|
|
@@ -6385,7 +7138,7 @@ function AxisPlot({
|
|
|
6385
7138
|
}
|
|
6386
7139
|
},
|
|
6387
7140
|
svg,
|
|
6388
|
-
xAxisLabel &&
|
|
7141
|
+
xAxisLabel && import_react10.default.createElement("div", {
|
|
6389
7142
|
key: "axis-x-label",
|
|
6390
7143
|
style: {
|
|
6391
7144
|
position: "absolute",
|
|
@@ -6400,7 +7153,7 @@ function AxisPlot({
|
|
|
6400
7153
|
fontWeight: 750
|
|
6401
7154
|
}
|
|
6402
7155
|
}, xAxisLabel),
|
|
6403
|
-
yAxisLabel &&
|
|
7156
|
+
yAxisLabel && import_react10.default.createElement("div", {
|
|
6404
7157
|
key: "axis-y-label",
|
|
6405
7158
|
style: {
|
|
6406
7159
|
position: "absolute",
|
|
@@ -6419,7 +7172,138 @@ function AxisPlot({
|
|
|
6419
7172
|
}
|
|
6420
7173
|
|
|
6421
7174
|
// src/primitives/charts.ts
|
|
6422
|
-
var
|
|
7175
|
+
var import_react12 = __toESM(require("react"), 1);
|
|
7176
|
+
|
|
7177
|
+
// src/canvas-chart-fit.ts
|
|
7178
|
+
var import_react11 = __toESM(require("react"), 1);
|
|
7179
|
+
var CANVAS_CHART_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvasChartComponent");
|
|
7180
|
+
var CHART_FRAME_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.chartFrameComponent");
|
|
7181
|
+
var FIT_PROP = "__vizmaticCanvasChartFit";
|
|
7182
|
+
var SCOPE_PROP = "data-vizmatic-chart-fit-scope";
|
|
7183
|
+
var VIEWPORT_PROP = "data-vizmatic-chart-fit-viewport";
|
|
7184
|
+
function isCanvasChart(component) {
|
|
7185
|
+
return typeof component === "function" && Boolean(component[CANVAS_CHART_COMPONENT]);
|
|
7186
|
+
}
|
|
7187
|
+
function CanvasChartFit({ children, width, height }) {
|
|
7188
|
+
let chart = children;
|
|
7189
|
+
for (let depth = 0; (0, import_react11.isValidElement)(chart) && typeof chart.type === "function" && depth < 16; depth += 1) {
|
|
7190
|
+
if (chart.type[CHART_FRAME_COMPONENT]) {
|
|
7191
|
+
const props = chart.props;
|
|
7192
|
+
const padding = typeof props.padding === "number" ? props.padding : 16;
|
|
7193
|
+
chart = import_react11.default.cloneElement(chart, {
|
|
7194
|
+
...props,
|
|
7195
|
+
width: typeof props.width === "number" ? props.width + 2 * (padding + 1) : props.width,
|
|
7196
|
+
height: void 0
|
|
7197
|
+
});
|
|
7198
|
+
break;
|
|
7199
|
+
}
|
|
7200
|
+
chart = chart.type(chart.props);
|
|
7201
|
+
}
|
|
7202
|
+
return import_react11.default.createElement("div", {
|
|
7203
|
+
[FIT_PROP]: { width, height },
|
|
7204
|
+
style: { position: "relative", display: "flex", width, height, flexShrink: 0 }
|
|
7205
|
+
}, import_react11.default.createElement("div", {
|
|
7206
|
+
style: { position: "absolute", left: 0, top: 0, display: "flex", alignItems: "flex-start" }
|
|
7207
|
+
}, chart));
|
|
7208
|
+
}
|
|
7209
|
+
function prepareChartFits(element) {
|
|
7210
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
7211
|
+
const visit = (node, scope) => {
|
|
7212
|
+
if (Array.isArray(node)) return node.map((child) => visit(child, scope));
|
|
7213
|
+
if (!(0, import_react11.isValidElement)(node)) return node;
|
|
7214
|
+
if (typeof node.type === "function") {
|
|
7215
|
+
const resolved = visit(node.type(node.props), scope);
|
|
7216
|
+
return node.key != null && (0, import_react11.isValidElement)(resolved) ? import_react11.default.cloneElement(resolved, { key: node.key }) : resolved;
|
|
7217
|
+
}
|
|
7218
|
+
const size = node.props[FIT_PROP];
|
|
7219
|
+
const props = { ...node.props };
|
|
7220
|
+
delete props[FIT_PROP];
|
|
7221
|
+
if (size) {
|
|
7222
|
+
const id = String(sizes.size);
|
|
7223
|
+
sizes.set(id, size);
|
|
7224
|
+
props[VIEWPORT_PROP] = id;
|
|
7225
|
+
return import_react11.default.cloneElement(node, props, visit(node.props.children, id));
|
|
7226
|
+
}
|
|
7227
|
+
if (scope !== void 0 && typeof node.type === "string") props[SCOPE_PROP] = scope;
|
|
7228
|
+
const children = node.props.children;
|
|
7229
|
+
return children === void 0 ? import_react11.default.cloneElement(node, props) : import_react11.default.cloneElement(node, props, visit(children, scope));
|
|
7230
|
+
};
|
|
7231
|
+
return { element: visit(element), sizes };
|
|
7232
|
+
}
|
|
7233
|
+
function fittedTree(element, geometry) {
|
|
7234
|
+
if (Array.isArray(element)) return element.map((child) => fittedTree(child, geometry));
|
|
7235
|
+
if (!(0, import_react11.isValidElement)(element)) return element;
|
|
7236
|
+
const id = element.props[VIEWPORT_PROP];
|
|
7237
|
+
const children = element.props.children;
|
|
7238
|
+
if (typeof id === "string") {
|
|
7239
|
+
const fit = geometry.get(id);
|
|
7240
|
+
const content = import_react11.default.Children.only(children);
|
|
7241
|
+
return import_react11.default.cloneElement(element, {}, import_react11.default.cloneElement(content, { style: {
|
|
7242
|
+
...content.props.style,
|
|
7243
|
+
left: fit.left,
|
|
7244
|
+
top: fit.top,
|
|
7245
|
+
transform: `scale(${fit.scale})`,
|
|
7246
|
+
transformOrigin: "top left"
|
|
7247
|
+
} }));
|
|
7248
|
+
}
|
|
7249
|
+
return children === void 0 ? element : import_react11.default.cloneElement(element, {}, fittedTree(children, geometry));
|
|
7250
|
+
}
|
|
7251
|
+
async function renderWithCanvasChartFit(render, element, options) {
|
|
7252
|
+
const prepared = prepareChartFits(element);
|
|
7253
|
+
if (!prepared.sizes.size) return render(prepared.element, options);
|
|
7254
|
+
const viewports = /* @__PURE__ */ new Map();
|
|
7255
|
+
const bounds = /* @__PURE__ */ new Map();
|
|
7256
|
+
await render(prepared.element, { ...options, onNodeDetected(node) {
|
|
7257
|
+
const viewport = node.props[VIEWPORT_PROP];
|
|
7258
|
+
if (typeof viewport === "string") viewports.set(viewport, node);
|
|
7259
|
+
const id = node.props[SCOPE_PROP];
|
|
7260
|
+
if (typeof id !== "string" || node.width <= 0 || node.height <= 0) return;
|
|
7261
|
+
const prior = bounds.get(id);
|
|
7262
|
+
bounds.set(id, {
|
|
7263
|
+
left: Math.min(prior?.left ?? Infinity, node.left),
|
|
7264
|
+
top: Math.min(prior?.top ?? Infinity, node.top),
|
|
7265
|
+
right: Math.max(prior?.right ?? -Infinity, node.left + node.width),
|
|
7266
|
+
bottom: Math.max(prior?.bottom ?? -Infinity, node.top + node.height)
|
|
7267
|
+
});
|
|
7268
|
+
} });
|
|
7269
|
+
const geometry = /* @__PURE__ */ new Map();
|
|
7270
|
+
for (const [id, size] of prepared.sizes) {
|
|
7271
|
+
const viewport = viewports.get(id);
|
|
7272
|
+
const measured = bounds.get(id);
|
|
7273
|
+
if (!viewport || !measured) throw new Error("Could not measure the chart inside CanvasItem.");
|
|
7274
|
+
const width = measured.right - measured.left, height = measured.bottom - measured.top;
|
|
7275
|
+
const scale = Math.min(size.width / width, size.height / height);
|
|
7276
|
+
if (!Number.isFinite(scale) || scale <= 0) throw new Error("CanvasItem charts require positive, finite dimensions.");
|
|
7277
|
+
geometry.set(id, {
|
|
7278
|
+
...size,
|
|
7279
|
+
scale,
|
|
7280
|
+
left: (size.width - width * scale) / 2 - (measured.left - viewport.left) * scale,
|
|
7281
|
+
top: (size.height - height * scale) / 2 - (measured.top - viewport.top) * scale
|
|
7282
|
+
});
|
|
7283
|
+
}
|
|
7284
|
+
const finalViewports = /* @__PURE__ */ new Map();
|
|
7285
|
+
return render(fittedTree(prepared.element, geometry), { ...options, onNodeDetected(node) {
|
|
7286
|
+
const viewport = node.props[VIEWPORT_PROP];
|
|
7287
|
+
if (typeof viewport === "string") finalViewports.set(viewport, node);
|
|
7288
|
+
const id = node.props[SCOPE_PROP];
|
|
7289
|
+
const fit = typeof id === "string" ? geometry.get(id) : void 0;
|
|
7290
|
+
const origin = typeof id === "string" ? finalViewports.get(id) : void 0;
|
|
7291
|
+
if (fit && origin) {
|
|
7292
|
+
const left = origin.left + fit.left, top = origin.top + fit.top;
|
|
7293
|
+
const style = node.props.style ?? {};
|
|
7294
|
+
options.onNodeDetected?.({
|
|
7295
|
+
...node,
|
|
7296
|
+
left: left + (node.left - left) * fit.scale,
|
|
7297
|
+
top: top + (node.top - top) * fit.scale,
|
|
7298
|
+
width: node.width * fit.scale,
|
|
7299
|
+
height: node.height * fit.scale,
|
|
7300
|
+
props: { ...node.props, style: { ...style, ...typeof style.fontSize === "number" ? { fontSize: style.fontSize * fit.scale } : {} } }
|
|
7301
|
+
});
|
|
7302
|
+
} else options.onNodeDetected?.(node);
|
|
7303
|
+
} });
|
|
7304
|
+
}
|
|
7305
|
+
|
|
7306
|
+
// src/primitives/charts.ts
|
|
6423
7307
|
var chartPalette = ["primary", "secondary", "positive", "warning", "info", "accent", "critical"];
|
|
6424
7308
|
function isColorName(value) {
|
|
6425
7309
|
return chartPalette.includes(value) || value === "neutral";
|
|
@@ -6509,7 +7393,7 @@ function chartLabel(key, text, x, y, c, options = {}) {
|
|
|
6509
7393
|
);
|
|
6510
7394
|
transform = void 0;
|
|
6511
7395
|
}
|
|
6512
|
-
return
|
|
7396
|
+
return import_react12.default.createElement("div", {
|
|
6513
7397
|
key,
|
|
6514
7398
|
style: {
|
|
6515
7399
|
position: "absolute",
|
|
@@ -6551,7 +7435,10 @@ function pointLabelPlacement(x, y, plot, index, width = 70) {
|
|
|
6551
7435
|
}
|
|
6552
7436
|
};
|
|
6553
7437
|
}
|
|
6554
|
-
function ChartFrame({
|
|
7438
|
+
function ChartFrame(props) {
|
|
7439
|
+
return import_react12.default.createElement(ChartFrameContent, props);
|
|
7440
|
+
}
|
|
7441
|
+
function ChartFrameContent({
|
|
6555
7442
|
children,
|
|
6556
7443
|
c,
|
|
6557
7444
|
title,
|
|
@@ -6562,7 +7449,7 @@ function ChartFrame({
|
|
|
6562
7449
|
height,
|
|
6563
7450
|
padding = 16
|
|
6564
7451
|
}) {
|
|
6565
|
-
return
|
|
7452
|
+
return import_react12.default.createElement(
|
|
6566
7453
|
"div",
|
|
6567
7454
|
{
|
|
6568
7455
|
style: {
|
|
@@ -6579,20 +7466,20 @@ function ChartFrame({
|
|
|
6579
7466
|
boxShadow: `0 9px 24px ${c.shadow}`
|
|
6580
7467
|
}
|
|
6581
7468
|
},
|
|
6582
|
-
(title || subtitle) &&
|
|
7469
|
+
(title || subtitle) && import_react12.default.createElement(
|
|
6583
7470
|
"div",
|
|
6584
7471
|
{
|
|
6585
7472
|
style: { display: "flex", flexDirection: "column", gap: 4, minWidth: 0, maxWidth: "100%" }
|
|
6586
7473
|
},
|
|
6587
|
-
title &&
|
|
7474
|
+
title && import_react12.default.createElement("div", {
|
|
6588
7475
|
style: { ...typography.small, ...textFitStyle(), color: c.textPrimary, fontWeight: 900 }
|
|
6589
7476
|
}, title),
|
|
6590
|
-
subtitle &&
|
|
7477
|
+
subtitle && import_react12.default.createElement("div", {
|
|
6591
7478
|
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary, lineHeight: 1.35 }
|
|
6592
7479
|
}, subtitle)
|
|
6593
7480
|
),
|
|
6594
7481
|
children,
|
|
6595
|
-
(legend || footer) &&
|
|
7482
|
+
(legend || footer) && import_react12.default.createElement(
|
|
6596
7483
|
"div",
|
|
6597
7484
|
{
|
|
6598
7485
|
style: {
|
|
@@ -6603,18 +7490,18 @@ function ChartFrame({
|
|
|
6603
7490
|
minHeight: 18
|
|
6604
7491
|
}
|
|
6605
7492
|
},
|
|
6606
|
-
legend &&
|
|
7493
|
+
legend && import_react12.default.createElement(
|
|
6607
7494
|
"div",
|
|
6608
7495
|
{
|
|
6609
7496
|
style: { display: "flex", alignItems: "center", gap: 12, flexWrap: "wrap", minWidth: 0 }
|
|
6610
7497
|
},
|
|
6611
|
-
...legend.map((item, index) =>
|
|
7498
|
+
...legend.map((item, index) => import_react12.default.createElement(
|
|
6612
7499
|
"div",
|
|
6613
7500
|
{
|
|
6614
7501
|
key: `${item.label}-${index}`,
|
|
6615
7502
|
style: { display: "flex", alignItems: "center", gap: 6, minWidth: 0 }
|
|
6616
7503
|
},
|
|
6617
|
-
|
|
7504
|
+
import_react12.default.createElement("span", {
|
|
6618
7505
|
style: {
|
|
6619
7506
|
width: 14,
|
|
6620
7507
|
height: 3,
|
|
@@ -6623,17 +7510,18 @@ function ChartFrame({
|
|
|
6623
7510
|
display: "flex"
|
|
6624
7511
|
}
|
|
6625
7512
|
}),
|
|
6626
|
-
|
|
7513
|
+
import_react12.default.createElement("span", {
|
|
6627
7514
|
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary }
|
|
6628
7515
|
}, item.label)
|
|
6629
7516
|
))
|
|
6630
7517
|
),
|
|
6631
|
-
footer &&
|
|
7518
|
+
footer && import_react12.default.createElement("div", {
|
|
6632
7519
|
style: { ...typography.tiny, ...textFitStyle("right"), color: c.textMuted }
|
|
6633
7520
|
}, footer)
|
|
6634
7521
|
)
|
|
6635
7522
|
);
|
|
6636
7523
|
}
|
|
7524
|
+
Object.defineProperty(ChartFrameContent, CHART_FRAME_COMPONENT, { value: true });
|
|
6637
7525
|
function polarPoint(cx, cy, radius, angleDegrees) {
|
|
6638
7526
|
const radians = angleDegrees * Math.PI / 180;
|
|
6639
7527
|
return {
|
|
@@ -6657,6 +7545,153 @@ function donutArcPath(cx, cy, outerRadius, innerRadius, startAngle, endAngle) {
|
|
|
6657
7545
|
"Z"
|
|
6658
7546
|
].join(" ");
|
|
6659
7547
|
}
|
|
7548
|
+
function validateNonNegativeSegments(segments, chartName) {
|
|
7549
|
+
let total = 0;
|
|
7550
|
+
for (const segment of segments) {
|
|
7551
|
+
if (!Number.isFinite(segment.value) || segment.value < 0) {
|
|
7552
|
+
throw new RangeError(`${chartName} values must be finite, non-negative numbers.`);
|
|
7553
|
+
}
|
|
7554
|
+
total += segment.value;
|
|
7555
|
+
if (!Number.isFinite(total)) {
|
|
7556
|
+
throw new RangeError(`${chartName} total must be finite.`);
|
|
7557
|
+
}
|
|
7558
|
+
}
|
|
7559
|
+
return total;
|
|
7560
|
+
}
|
|
7561
|
+
function pieSectorPath(cx, cy, radius, startAngle, endAngle) {
|
|
7562
|
+
const span = endAngle - startAngle;
|
|
7563
|
+
const start = polarPoint(cx, cy, radius, startAngle);
|
|
7564
|
+
if (span >= 359.999) {
|
|
7565
|
+
const opposite = polarPoint(cx, cy, radius, startAngle + 180);
|
|
7566
|
+
return [
|
|
7567
|
+
`M ${cx} ${cy}`,
|
|
7568
|
+
`L ${start.x} ${start.y}`,
|
|
7569
|
+
`A ${radius} ${radius} 0 1 1 ${opposite.x} ${opposite.y}`,
|
|
7570
|
+
`A ${radius} ${radius} 0 1 1 ${start.x} ${start.y}`,
|
|
7571
|
+
"Z"
|
|
7572
|
+
].join(" ");
|
|
7573
|
+
}
|
|
7574
|
+
const end = polarPoint(cx, cy, radius, endAngle);
|
|
7575
|
+
const largeArc = span > 180 ? 1 : 0;
|
|
7576
|
+
return `M ${cx} ${cy} L ${start.x} ${start.y} A ${radius} ${radius} 0 ${largeArc} 1 ${end.x} ${end.y} Z`;
|
|
7577
|
+
}
|
|
7578
|
+
function PieChart({
|
|
7579
|
+
segments,
|
|
7580
|
+
c,
|
|
7581
|
+
title,
|
|
7582
|
+
subtitle,
|
|
7583
|
+
width = 360,
|
|
7584
|
+
height = 240,
|
|
7585
|
+
size,
|
|
7586
|
+
format = "decimal",
|
|
7587
|
+
showLegend = true,
|
|
7588
|
+
footer
|
|
7589
|
+
}) {
|
|
7590
|
+
const total = validateNonNegativeSegments(segments, "PieChart");
|
|
7591
|
+
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
7592
|
+
const resolvedSize = size ?? Math.min(184, Math.max(132, height - 44), Math.max(132, width * 0.5));
|
|
7593
|
+
const radius = resolvedSize / 2 - 2;
|
|
7594
|
+
const cx = resolvedSize / 2;
|
|
7595
|
+
const cy = resolvedSize / 2;
|
|
7596
|
+
let cursor = -90;
|
|
7597
|
+
const paths = positiveSegments.map((segment, index) => {
|
|
7598
|
+
const span = total > 0 ? segment.value / total * 360 : 0;
|
|
7599
|
+
const start = cursor;
|
|
7600
|
+
const end = index === positiveSegments.length - 1 ? 270 : cursor + span;
|
|
7601
|
+
cursor += span;
|
|
7602
|
+
return import_react12.default.createElement("path", {
|
|
7603
|
+
key: `pie-segment-${segment.label}-${index}`,
|
|
7604
|
+
d: pieSectorPath(cx, cy, radius, start, end),
|
|
7605
|
+
fill: chartColor(segment.color, c, index),
|
|
7606
|
+
stroke: c.bgCard,
|
|
7607
|
+
strokeWidth: positiveSegments.length > 1 ? 2 : 0,
|
|
7608
|
+
"data-pie-label": segment.label,
|
|
7609
|
+
"data-pie-value": segment.value,
|
|
7610
|
+
"data-pie-share": total > 0 ? segment.value / total : 0
|
|
7611
|
+
});
|
|
7612
|
+
});
|
|
7613
|
+
const legend = showLegend && positiveSegments.length > 0 && import_react12.default.createElement("div", {
|
|
7614
|
+
style: {
|
|
7615
|
+
display: "flex",
|
|
7616
|
+
flexDirection: "column",
|
|
7617
|
+
gap: 8,
|
|
7618
|
+
flex: 1,
|
|
7619
|
+
minWidth: 112
|
|
7620
|
+
}
|
|
7621
|
+
}, ...positiveSegments.map((segment, index) => {
|
|
7622
|
+
const formattedValue = formatChartValue(segment.value, format);
|
|
7623
|
+
const share = formatChartValue(segment.value / total, "percent");
|
|
7624
|
+
const label = segment.valueLabel ?? (format === "percent" ? formattedValue : `${formattedValue} \xB7 ${share}`);
|
|
7625
|
+
return import_react12.default.createElement(
|
|
7626
|
+
"div",
|
|
7627
|
+
{
|
|
7628
|
+
key: `pie-legend-${segment.label}-${index}`,
|
|
7629
|
+
style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0 }
|
|
7630
|
+
},
|
|
7631
|
+
import_react12.default.createElement("span", {
|
|
7632
|
+
style: {
|
|
7633
|
+
display: "flex",
|
|
7634
|
+
width: 10,
|
|
7635
|
+
height: 10,
|
|
7636
|
+
borderRadius: 3,
|
|
7637
|
+
backgroundColor: chartColor(segment.color, c, index),
|
|
7638
|
+
flexShrink: 0
|
|
7639
|
+
}
|
|
7640
|
+
}),
|
|
7641
|
+
import_react12.default.createElement("span", {
|
|
7642
|
+
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary, flex: 1 }
|
|
7643
|
+
}, segment.label),
|
|
7644
|
+
import_react12.default.createElement("span", {
|
|
7645
|
+
style: {
|
|
7646
|
+
...typography.tiny,
|
|
7647
|
+
color: c.textPrimary,
|
|
7648
|
+
fontFamily: "JetBrains Mono",
|
|
7649
|
+
fontWeight: 850,
|
|
7650
|
+
flexShrink: 0
|
|
7651
|
+
}
|
|
7652
|
+
}, label)
|
|
7653
|
+
);
|
|
7654
|
+
}));
|
|
7655
|
+
return ChartFrame({
|
|
7656
|
+
c,
|
|
7657
|
+
title,
|
|
7658
|
+
subtitle,
|
|
7659
|
+
footer,
|
|
7660
|
+
width,
|
|
7661
|
+
children: import_react12.default.createElement(
|
|
7662
|
+
"div",
|
|
7663
|
+
{
|
|
7664
|
+
style: {
|
|
7665
|
+
display: "flex",
|
|
7666
|
+
alignItems: "center",
|
|
7667
|
+
justifyContent: showLegend ? "space-between" : "center",
|
|
7668
|
+
gap: 18,
|
|
7669
|
+
minHeight: resolvedSize,
|
|
7670
|
+
width: "100%"
|
|
7671
|
+
}
|
|
7672
|
+
},
|
|
7673
|
+
import_react12.default.createElement(
|
|
7674
|
+
"svg",
|
|
7675
|
+
{
|
|
7676
|
+
width: resolvedSize,
|
|
7677
|
+
height: resolvedSize,
|
|
7678
|
+
viewBox: `0 0 ${resolvedSize} ${resolvedSize}`,
|
|
7679
|
+
role: "img",
|
|
7680
|
+
"aria-label": title ?? "Pie chart"
|
|
7681
|
+
},
|
|
7682
|
+
positiveSegments.length === 0 ? import_react12.default.createElement("circle", {
|
|
7683
|
+
cx,
|
|
7684
|
+
cy,
|
|
7685
|
+
r: radius,
|
|
7686
|
+
fill: "none",
|
|
7687
|
+
stroke: c.borderLight,
|
|
7688
|
+
strokeWidth: 2
|
|
7689
|
+
}) : paths
|
|
7690
|
+
),
|
|
7691
|
+
legend
|
|
7692
|
+
)
|
|
7693
|
+
});
|
|
7694
|
+
}
|
|
6660
7695
|
function DonutChart({
|
|
6661
7696
|
segments,
|
|
6662
7697
|
c,
|
|
@@ -6689,13 +7724,13 @@ function DonutChart({
|
|
|
6689
7724
|
const end = cursor + rawSpan - gap / 2;
|
|
6690
7725
|
cursor += rawSpan;
|
|
6691
7726
|
if (end <= start) return null;
|
|
6692
|
-
return
|
|
7727
|
+
return import_react12.default.createElement("path", {
|
|
6693
7728
|
key: `donut-segment-${segment.label}-${index}`,
|
|
6694
7729
|
d: donutArcPath(cx, cy, outerRadius, innerRadius, start, end),
|
|
6695
7730
|
fill: chartColor(segment.color, c, index)
|
|
6696
7731
|
});
|
|
6697
7732
|
}).filter(Boolean);
|
|
6698
|
-
const legend = showLegend && positiveSegments.length > 0 &&
|
|
7733
|
+
const legend = showLegend && positiveSegments.length > 0 && import_react12.default.createElement("div", {
|
|
6699
7734
|
style: {
|
|
6700
7735
|
display: "flex",
|
|
6701
7736
|
flexDirection: "column",
|
|
@@ -6703,7 +7738,7 @@ function DonutChart({
|
|
|
6703
7738
|
flex: 1,
|
|
6704
7739
|
minWidth: 112
|
|
6705
7740
|
}
|
|
6706
|
-
}, ...positiveSegments.map((segment, index) =>
|
|
7741
|
+
}, ...positiveSegments.map((segment, index) => import_react12.default.createElement(
|
|
6707
7742
|
"div",
|
|
6708
7743
|
{
|
|
6709
7744
|
key: `donut-legend-${segment.label}-${index}`,
|
|
@@ -6714,7 +7749,7 @@ function DonutChart({
|
|
|
6714
7749
|
minWidth: 0
|
|
6715
7750
|
}
|
|
6716
7751
|
},
|
|
6717
|
-
|
|
7752
|
+
import_react12.default.createElement("span", {
|
|
6718
7753
|
style: {
|
|
6719
7754
|
display: "flex",
|
|
6720
7755
|
width: 10,
|
|
@@ -6724,7 +7759,7 @@ function DonutChart({
|
|
|
6724
7759
|
flexShrink: 0
|
|
6725
7760
|
}
|
|
6726
7761
|
}),
|
|
6727
|
-
|
|
7762
|
+
import_react12.default.createElement("span", {
|
|
6728
7763
|
style: {
|
|
6729
7764
|
...typography.tiny,
|
|
6730
7765
|
...textFitStyle(),
|
|
@@ -6732,7 +7767,7 @@ function DonutChart({
|
|
|
6732
7767
|
flex: 1
|
|
6733
7768
|
}
|
|
6734
7769
|
}, segment.label),
|
|
6735
|
-
|
|
7770
|
+
import_react12.default.createElement("span", {
|
|
6736
7771
|
style: {
|
|
6737
7772
|
...typography.tiny,
|
|
6738
7773
|
color: c.textPrimary,
|
|
@@ -6750,7 +7785,7 @@ function DonutChart({
|
|
|
6750
7785
|
width,
|
|
6751
7786
|
height,
|
|
6752
7787
|
padding: 16,
|
|
6753
|
-
children:
|
|
7788
|
+
children: import_react12.default.createElement(
|
|
6754
7789
|
"div",
|
|
6755
7790
|
{
|
|
6756
7791
|
style: {
|
|
@@ -6762,7 +7797,7 @@ function DonutChart({
|
|
|
6762
7797
|
width: "100%"
|
|
6763
7798
|
}
|
|
6764
7799
|
},
|
|
6765
|
-
|
|
7800
|
+
import_react12.default.createElement(
|
|
6766
7801
|
"div",
|
|
6767
7802
|
{
|
|
6768
7803
|
style: {
|
|
@@ -6773,14 +7808,14 @@ function DonutChart({
|
|
|
6773
7808
|
flexShrink: 0
|
|
6774
7809
|
}
|
|
6775
7810
|
},
|
|
6776
|
-
|
|
7811
|
+
import_react12.default.createElement(
|
|
6777
7812
|
"svg",
|
|
6778
7813
|
{
|
|
6779
7814
|
width: resolvedSize,
|
|
6780
7815
|
height: resolvedSize,
|
|
6781
7816
|
viewBox: `0 0 ${resolvedSize} ${resolvedSize}`
|
|
6782
7817
|
},
|
|
6783
|
-
positiveSegments.length === 0 ?
|
|
7818
|
+
positiveSegments.length === 0 ? import_react12.default.createElement("circle", {
|
|
6784
7819
|
cx,
|
|
6785
7820
|
cy,
|
|
6786
7821
|
r: (outerRadius + innerRadius) / 2,
|
|
@@ -6789,7 +7824,7 @@ function DonutChart({
|
|
|
6789
7824
|
strokeWidth: resolvedThickness
|
|
6790
7825
|
}) : paths
|
|
6791
7826
|
),
|
|
6792
|
-
(centerLabel != null || resolvedCenterValue != null) &&
|
|
7827
|
+
(centerLabel != null || resolvedCenterValue != null) && import_react12.default.createElement(
|
|
6793
7828
|
"div",
|
|
6794
7829
|
{
|
|
6795
7830
|
style: {
|
|
@@ -6808,7 +7843,7 @@ function DonutChart({
|
|
|
6808
7843
|
textAlign: "center"
|
|
6809
7844
|
}
|
|
6810
7845
|
},
|
|
6811
|
-
resolvedCenterValue != null &&
|
|
7846
|
+
resolvedCenterValue != null && import_react12.default.createElement("div", {
|
|
6812
7847
|
style: {
|
|
6813
7848
|
...typography.small,
|
|
6814
7849
|
color: c.textPrimary,
|
|
@@ -6819,7 +7854,7 @@ function DonutChart({
|
|
|
6819
7854
|
...textFitStyle("center")
|
|
6820
7855
|
}
|
|
6821
7856
|
}, resolvedCenterValue),
|
|
6822
|
-
centerLabel != null &&
|
|
7857
|
+
centerLabel != null && import_react12.default.createElement("div", {
|
|
6823
7858
|
style: {
|
|
6824
7859
|
...typography.tiny,
|
|
6825
7860
|
color: c.textMuted,
|
|
@@ -6844,7 +7879,7 @@ function StackedBar({
|
|
|
6844
7879
|
}) {
|
|
6845
7880
|
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
6846
7881
|
const total = positiveSegments.reduce((sum, segment) => sum + segment.value, 0);
|
|
6847
|
-
return
|
|
7882
|
+
return import_react12.default.createElement(
|
|
6848
7883
|
"div",
|
|
6849
7884
|
{
|
|
6850
7885
|
style: {
|
|
@@ -6854,7 +7889,7 @@ function StackedBar({
|
|
|
6854
7889
|
gap: 10
|
|
6855
7890
|
}
|
|
6856
7891
|
},
|
|
6857
|
-
(title || subtitle) &&
|
|
7892
|
+
(title || subtitle) && import_react12.default.createElement(
|
|
6858
7893
|
"div",
|
|
6859
7894
|
{
|
|
6860
7895
|
style: {
|
|
@@ -6863,14 +7898,14 @@ function StackedBar({
|
|
|
6863
7898
|
gap: 3
|
|
6864
7899
|
}
|
|
6865
7900
|
},
|
|
6866
|
-
title &&
|
|
7901
|
+
title && import_react12.default.createElement("div", {
|
|
6867
7902
|
style: { ...typography.label, color: c.textPrimary, fontWeight: 850 }
|
|
6868
7903
|
}, title),
|
|
6869
|
-
subtitle &&
|
|
7904
|
+
subtitle && import_react12.default.createElement("div", {
|
|
6870
7905
|
style: { ...typography.tiny, color: c.textSecondary }
|
|
6871
7906
|
}, subtitle)
|
|
6872
7907
|
),
|
|
6873
|
-
|
|
7908
|
+
import_react12.default.createElement(
|
|
6874
7909
|
"div",
|
|
6875
7910
|
{
|
|
6876
7911
|
style: {
|
|
@@ -6888,7 +7923,7 @@ function StackedBar({
|
|
|
6888
7923
|
const share = total > 0 ? segment.value / total : 0;
|
|
6889
7924
|
const segmentWidth = width * share;
|
|
6890
7925
|
const color = chartColor(segment.color, c, index);
|
|
6891
|
-
return
|
|
7926
|
+
return import_react12.default.createElement(
|
|
6892
7927
|
"div",
|
|
6893
7928
|
{
|
|
6894
7929
|
key: `${segment.label}-${index}`,
|
|
@@ -6902,7 +7937,7 @@ function StackedBar({
|
|
|
6902
7937
|
...index < positiveSegments.length - 1 ? { borderRight: `2px solid ${c.bgSubtle}` } : {}
|
|
6903
7938
|
}
|
|
6904
7939
|
},
|
|
6905
|
-
segmentWidth >= 64 &&
|
|
7940
|
+
segmentWidth >= 64 && import_react12.default.createElement("span", {
|
|
6906
7941
|
style: {
|
|
6907
7942
|
...typography.small,
|
|
6908
7943
|
color: getReadableTextColor(color, c),
|
|
@@ -6913,7 +7948,7 @@ function StackedBar({
|
|
|
6913
7948
|
);
|
|
6914
7949
|
})
|
|
6915
7950
|
),
|
|
6916
|
-
showLegend &&
|
|
7951
|
+
showLegend && import_react12.default.createElement(
|
|
6917
7952
|
"div",
|
|
6918
7953
|
{
|
|
6919
7954
|
style: {
|
|
@@ -6925,13 +7960,13 @@ function StackedBar({
|
|
|
6925
7960
|
},
|
|
6926
7961
|
...positiveSegments.map((segment, index) => {
|
|
6927
7962
|
const share = total > 0 ? segment.value / total : 0;
|
|
6928
|
-
return
|
|
7963
|
+
return import_react12.default.createElement(
|
|
6929
7964
|
"div",
|
|
6930
7965
|
{
|
|
6931
7966
|
key: `legend-${segment.label}-${index}`,
|
|
6932
7967
|
style: { display: "flex", alignItems: "center", gap: 7 }
|
|
6933
7968
|
},
|
|
6934
|
-
|
|
7969
|
+
import_react12.default.createElement("span", {
|
|
6935
7970
|
style: {
|
|
6936
7971
|
width: 12,
|
|
6937
7972
|
height: 12,
|
|
@@ -6940,7 +7975,7 @@ function StackedBar({
|
|
|
6940
7975
|
backgroundColor: chartColor(segment.color, c, index)
|
|
6941
7976
|
}
|
|
6942
7977
|
}),
|
|
6943
|
-
|
|
7978
|
+
import_react12.default.createElement("span", {
|
|
6944
7979
|
style: { ...typography.tiny, color: c.textSecondary }
|
|
6945
7980
|
}, `${segment.label} ${segment.valueLabel ?? formatChartValue(share, "percent")}`)
|
|
6946
7981
|
);
|
|
@@ -6986,18 +8021,18 @@ function BarChart({
|
|
|
6986
8021
|
subtitle,
|
|
6987
8022
|
width,
|
|
6988
8023
|
footer,
|
|
6989
|
-
children:
|
|
8024
|
+
children: import_react12.default.createElement(
|
|
6990
8025
|
"div",
|
|
6991
8026
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
6992
|
-
|
|
8027
|
+
import_react12.default.createElement(
|
|
6993
8028
|
"svg",
|
|
6994
8029
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
6995
|
-
showGrid &&
|
|
8030
|
+
showGrid && import_react12.default.createElement(
|
|
6996
8031
|
"g",
|
|
6997
8032
|
{},
|
|
6998
8033
|
...ticks.map((tick) => {
|
|
6999
8034
|
const y = yInPlot(tick, domain, plot);
|
|
7000
|
-
return
|
|
8035
|
+
return import_react12.default.createElement("line", {
|
|
7001
8036
|
key: `tick-${tick}`,
|
|
7002
8037
|
x1: plot.x,
|
|
7003
8038
|
y1: y,
|
|
@@ -7008,10 +8043,10 @@ function BarChart({
|
|
|
7008
8043
|
});
|
|
7009
8044
|
})
|
|
7010
8045
|
),
|
|
7011
|
-
|
|
7012
|
-
|
|
8046
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
8047
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: baselineY, x2: plot.right, y2: baselineY, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
7013
8048
|
...barGeometries.map(
|
|
7014
|
-
({ item, index, x, y, barHeight, color }) =>
|
|
8049
|
+
({ item, index, x, y, barHeight, color }) => import_react12.default.createElement("rect", {
|
|
7015
8050
|
key: `${item.label}-${index}`,
|
|
7016
8051
|
x,
|
|
7017
8052
|
y,
|
|
@@ -7047,6 +8082,186 @@ function BarChart({
|
|
|
7047
8082
|
)
|
|
7048
8083
|
});
|
|
7049
8084
|
}
|
|
8085
|
+
function ParetoBarChart({
|
|
8086
|
+
data,
|
|
8087
|
+
c,
|
|
8088
|
+
title,
|
|
8089
|
+
subtitle,
|
|
8090
|
+
width = 520,
|
|
8091
|
+
height = 300,
|
|
8092
|
+
format = "integer",
|
|
8093
|
+
showGrid = true,
|
|
8094
|
+
showValues = true,
|
|
8095
|
+
footer
|
|
8096
|
+
}) {
|
|
8097
|
+
let total = 0;
|
|
8098
|
+
for (const item of data) {
|
|
8099
|
+
if (!Number.isFinite(item.value) || item.value < 0) {
|
|
8100
|
+
throw new RangeError("ParetoBarChart values must be finite, non-negative numbers.");
|
|
8101
|
+
}
|
|
8102
|
+
total += item.value;
|
|
8103
|
+
if (!Number.isFinite(total)) {
|
|
8104
|
+
throw new RangeError("ParetoBarChart total must be finite.");
|
|
8105
|
+
}
|
|
8106
|
+
}
|
|
8107
|
+
const sorted = data.map((item, index) => ({ item, index })).sort((left, right) => right.item.value - left.item.value || left.index - right.index);
|
|
8108
|
+
const maximum = Math.max(1, ...sorted.map(({ item }) => item.value));
|
|
8109
|
+
const margin = { top: 24, right: 48, bottom: 48, left: 48 };
|
|
8110
|
+
const plot = createPlotArea(width, height, margin);
|
|
8111
|
+
const valueDomain = {
|
|
8112
|
+
min: 0,
|
|
8113
|
+
range: maximum > Number.MAX_VALUE / 1.16 ? maximum : maximum * 1.16
|
|
8114
|
+
};
|
|
8115
|
+
const countTicks = chartTicks(0, maximum, 4);
|
|
8116
|
+
const slot = plot.innerWidth / Math.max(sorted.length, 1);
|
|
8117
|
+
const barWidth = Math.max(6, Math.min(68, slot * 0.68));
|
|
8118
|
+
let accumulated = 0;
|
|
8119
|
+
const bars = sorted.map(({ item, index }, order) => {
|
|
8120
|
+
accumulated += item.value;
|
|
8121
|
+
const cumulative = total === 0 ? 0 : order === sorted.length - 1 ? 1 : accumulated / total;
|
|
8122
|
+
const x = plot.x + order * slot + (slot - barWidth) / 2;
|
|
8123
|
+
const top = yInPlot(item.value, valueDomain, plot);
|
|
8124
|
+
return {
|
|
8125
|
+
item,
|
|
8126
|
+
sourceIndex: index,
|
|
8127
|
+
order,
|
|
8128
|
+
x,
|
|
8129
|
+
y: top,
|
|
8130
|
+
height: Math.max(0, plot.bottom - top),
|
|
8131
|
+
color: chartColor(item.color, c, order),
|
|
8132
|
+
centerX: x + barWidth / 2,
|
|
8133
|
+
cumulative,
|
|
8134
|
+
cumulativeY: plot.bottom - cumulative * plot.innerHeight
|
|
8135
|
+
};
|
|
8136
|
+
});
|
|
8137
|
+
const cumulativePath = bars.map(({ centerX, cumulativeY }, index) => `${index === 0 ? "M" : "L"} ${centerX.toFixed(1)} ${cumulativeY.toFixed(1)}`).join(" ");
|
|
8138
|
+
return ChartFrame({
|
|
8139
|
+
c,
|
|
8140
|
+
title,
|
|
8141
|
+
subtitle,
|
|
8142
|
+
width,
|
|
8143
|
+
footer,
|
|
8144
|
+
children: import_react12.default.createElement(
|
|
8145
|
+
"div",
|
|
8146
|
+
{
|
|
8147
|
+
style: { position: "relative", width, height, display: "flex" }
|
|
8148
|
+
},
|
|
8149
|
+
import_react12.default.createElement(
|
|
8150
|
+
"svg",
|
|
8151
|
+
{
|
|
8152
|
+
width,
|
|
8153
|
+
height,
|
|
8154
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
8155
|
+
role: "img",
|
|
8156
|
+
"aria-label": title ?? "Pareto bar chart"
|
|
8157
|
+
},
|
|
8158
|
+
showGrid && import_react12.default.createElement(
|
|
8159
|
+
"g",
|
|
8160
|
+
{},
|
|
8161
|
+
...countTicks.map((tick) => {
|
|
8162
|
+
const y = yInPlot(tick, valueDomain, plot);
|
|
8163
|
+
return import_react12.default.createElement("line", {
|
|
8164
|
+
key: `pareto-count-grid-${tick}`,
|
|
8165
|
+
x1: plot.x,
|
|
8166
|
+
y1: y,
|
|
8167
|
+
x2: plot.right,
|
|
8168
|
+
y2: y,
|
|
8169
|
+
stroke: c.borderSubtle,
|
|
8170
|
+
strokeWidth: 1
|
|
8171
|
+
});
|
|
8172
|
+
})
|
|
8173
|
+
),
|
|
8174
|
+
import_react12.default.createElement("line", {
|
|
8175
|
+
x1: plot.x,
|
|
8176
|
+
y1: plot.bottom,
|
|
8177
|
+
x2: plot.right,
|
|
8178
|
+
y2: plot.bottom,
|
|
8179
|
+
stroke: c.borderLight,
|
|
8180
|
+
strokeWidth: 1.2
|
|
8181
|
+
}),
|
|
8182
|
+
import_react12.default.createElement("line", {
|
|
8183
|
+
x1: plot.right,
|
|
8184
|
+
y1: plot.y,
|
|
8185
|
+
x2: plot.right,
|
|
8186
|
+
y2: plot.bottom,
|
|
8187
|
+
stroke: c.borderLight,
|
|
8188
|
+
strokeWidth: 1.2
|
|
8189
|
+
}),
|
|
8190
|
+
...bars.map(({ item, order, x, y, height: barHeight, color }) => import_react12.default.createElement("rect", {
|
|
8191
|
+
key: `pareto-bar-${item.label}-${order}`,
|
|
8192
|
+
x,
|
|
8193
|
+
y,
|
|
8194
|
+
width: barWidth,
|
|
8195
|
+
height: barHeight,
|
|
8196
|
+
rx: 4,
|
|
8197
|
+
fill: color,
|
|
8198
|
+
opacity: 0.86,
|
|
8199
|
+
"data-pareto-bar": item.label,
|
|
8200
|
+
"data-pareto-value": item.value,
|
|
8201
|
+
"data-pareto-order": order
|
|
8202
|
+
})),
|
|
8203
|
+
cumulativePath && import_react12.default.createElement("path", {
|
|
8204
|
+
d: cumulativePath,
|
|
8205
|
+
fill: "none",
|
|
8206
|
+
stroke: chartColor("critical", c),
|
|
8207
|
+
strokeWidth: 3,
|
|
8208
|
+
strokeLinecap: "round",
|
|
8209
|
+
strokeLinejoin: "round",
|
|
8210
|
+
"data-pareto-cumulative-line": true
|
|
8211
|
+
}),
|
|
8212
|
+
...bars.map(({ item, sourceIndex, centerX, cumulativeY, cumulative, order }) => import_react12.default.createElement("circle", {
|
|
8213
|
+
key: `pareto-cumulative-point-${order}`,
|
|
8214
|
+
cx: centerX,
|
|
8215
|
+
cy: cumulativeY,
|
|
8216
|
+
r: 4,
|
|
8217
|
+
fill: chartColor("critical", c),
|
|
8218
|
+
stroke: c.bgCard,
|
|
8219
|
+
strokeWidth: 2,
|
|
8220
|
+
"data-pareto-category": item.label,
|
|
8221
|
+
"data-pareto-source-index": sourceIndex,
|
|
8222
|
+
"data-pareto-cumulative-percent": cumulative * 100
|
|
8223
|
+
}))
|
|
8224
|
+
),
|
|
8225
|
+
...countTicks.map((tick) => chartLabel(
|
|
8226
|
+
`pareto-count-label-${tick}`,
|
|
8227
|
+
formatChartValue(tick, format),
|
|
8228
|
+
plot.x - 7,
|
|
8229
|
+
yInPlot(tick, valueDomain, plot),
|
|
8230
|
+
c,
|
|
8231
|
+
{ align: "right", width: 36 }
|
|
8232
|
+
)),
|
|
8233
|
+
...[0, 0.5, 1].map((share) => chartLabel(
|
|
8234
|
+
`pareto-percent-label-${share}`,
|
|
8235
|
+
`${Math.round(share * 100)}%`,
|
|
8236
|
+
plot.right + 7,
|
|
8237
|
+
plot.bottom - share * plot.innerHeight,
|
|
8238
|
+
c,
|
|
8239
|
+
{ align: "left", width: 38 }
|
|
8240
|
+
)),
|
|
8241
|
+
...bars.flatMap(({ item, order, centerX, y }) => [
|
|
8242
|
+
...showValues ? [chartLabel(
|
|
8243
|
+
`pareto-value-${order}`,
|
|
8244
|
+
item.valueLabel ?? formatChartValue(item.value, format),
|
|
8245
|
+
centerX,
|
|
8246
|
+
clamp(y - 8, plot.y + 8, plot.bottom - 12),
|
|
8247
|
+
c,
|
|
8248
|
+
{ color: c.textPrimary, fontWeight: 800, width: Math.min(slot, 64), bounds: { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight } }
|
|
8249
|
+
)] : [],
|
|
8250
|
+
chartLabel(
|
|
8251
|
+
`pareto-category-${order}`,
|
|
8252
|
+
item.label,
|
|
8253
|
+
centerX,
|
|
8254
|
+
height - 17,
|
|
8255
|
+
c,
|
|
8256
|
+
{
|
|
8257
|
+
width: Math.max(1, Math.min(96, slot - 2)),
|
|
8258
|
+
bounds: { x: plot.x, y: plot.bottom + 1, width: plot.innerWidth, height: Math.max(1, height - plot.bottom - 2), padding: 0 }
|
|
8259
|
+
}
|
|
8260
|
+
)
|
|
8261
|
+
])
|
|
8262
|
+
)
|
|
8263
|
+
});
|
|
8264
|
+
}
|
|
7050
8265
|
function LineChart({
|
|
7051
8266
|
series,
|
|
7052
8267
|
c,
|
|
@@ -7090,18 +8305,18 @@ function LineChart({
|
|
|
7090
8305
|
width,
|
|
7091
8306
|
footer,
|
|
7092
8307
|
legend: series.map((item, index) => ({ label: item.name, color: item.color ?? chartPalette[index % chartPalette.length] })),
|
|
7093
|
-
children:
|
|
8308
|
+
children: import_react12.default.createElement(
|
|
7094
8309
|
"div",
|
|
7095
8310
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7096
|
-
|
|
8311
|
+
import_react12.default.createElement(
|
|
7097
8312
|
"svg",
|
|
7098
8313
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7099
|
-
showGrid &&
|
|
8314
|
+
showGrid && import_react12.default.createElement(
|
|
7100
8315
|
"g",
|
|
7101
8316
|
{},
|
|
7102
8317
|
...ticks.map((tick) => {
|
|
7103
8318
|
const y = yInPlot(tick, domain, plot);
|
|
7104
|
-
return
|
|
8319
|
+
return import_react12.default.createElement("line", {
|
|
7105
8320
|
key: `line-tick-${tick}`,
|
|
7106
8321
|
x1: plot.x,
|
|
7107
8322
|
y1: y,
|
|
@@ -7112,8 +8327,8 @@ function LineChart({
|
|
|
7112
8327
|
});
|
|
7113
8328
|
})
|
|
7114
8329
|
),
|
|
7115
|
-
|
|
7116
|
-
|
|
8330
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
8331
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
7117
8332
|
...series.flatMap((item, seriesIndex) => {
|
|
7118
8333
|
if (item.points.length === 0) return [];
|
|
7119
8334
|
const color = chartColor(item.color, c, seriesIndex);
|
|
@@ -7126,9 +8341,9 @@ function LineChart({
|
|
|
7126
8341
|
}
|
|
7127
8342
|
const elements = [];
|
|
7128
8343
|
if (areaPath) {
|
|
7129
|
-
elements.push(
|
|
8344
|
+
elements.push(import_react12.default.createElement("path", { key: `${item.name}-area`, d: areaPath, fill: color, opacity: 0.12 }));
|
|
7130
8345
|
}
|
|
7131
|
-
elements.push(
|
|
8346
|
+
elements.push(import_react12.default.createElement("path", {
|
|
7132
8347
|
key: `${item.name}-line`,
|
|
7133
8348
|
d: linePath,
|
|
7134
8349
|
fill: "none",
|
|
@@ -7140,7 +8355,7 @@ function LineChart({
|
|
|
7140
8355
|
if (showPoints) {
|
|
7141
8356
|
elements.push(...item.points.map((value, index) => {
|
|
7142
8357
|
const point = pointFor(value, index);
|
|
7143
|
-
return
|
|
8358
|
+
return import_react12.default.createElement("circle", {
|
|
7144
8359
|
key: `${item.name}-point-${index}`,
|
|
7145
8360
|
cx: point.x,
|
|
7146
8361
|
cy: point.y,
|
|
@@ -7171,9 +8386,15 @@ function LineChart({
|
|
|
7171
8386
|
)
|
|
7172
8387
|
});
|
|
7173
8388
|
}
|
|
8389
|
+
for (const chart of [PieChart, DonutChart, StackedBar, BarChart, ParetoBarChart, LineChart]) {
|
|
8390
|
+
Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
|
|
8391
|
+
}
|
|
7174
8392
|
|
|
7175
8393
|
// src/primitives/plots.ts
|
|
7176
|
-
var
|
|
8394
|
+
var import_react13 = __toESM(require("react"), 1);
|
|
8395
|
+
for (const chart of [ScatterPlot, ParetoChart, QuadrantChart, IntervalPlot]) {
|
|
8396
|
+
Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
|
|
8397
|
+
}
|
|
7177
8398
|
function xTickLabelAlign(index, count) {
|
|
7178
8399
|
if (index === 0) return "left";
|
|
7179
8400
|
if (index === count - 1) return "right";
|
|
@@ -7217,18 +8438,18 @@ function ScatterPlot({
|
|
|
7217
8438
|
subtitle,
|
|
7218
8439
|
width,
|
|
7219
8440
|
footer,
|
|
7220
|
-
children:
|
|
8441
|
+
children: import_react13.default.createElement(
|
|
7221
8442
|
"div",
|
|
7222
8443
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7223
|
-
|
|
8444
|
+
import_react13.default.createElement(
|
|
7224
8445
|
"svg",
|
|
7225
8446
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7226
|
-
showGrid &&
|
|
8447
|
+
showGrid && import_react13.default.createElement(
|
|
7227
8448
|
"g",
|
|
7228
8449
|
{},
|
|
7229
8450
|
...xTicks.map((tick) => {
|
|
7230
8451
|
const x = xInPlot(tick, xDomain, plot);
|
|
7231
|
-
return
|
|
8452
|
+
return import_react13.default.createElement("line", {
|
|
7232
8453
|
key: `x-tick-${tick}`,
|
|
7233
8454
|
x1: x,
|
|
7234
8455
|
y1: plot.y,
|
|
@@ -7240,7 +8461,7 @@ function ScatterPlot({
|
|
|
7240
8461
|
}),
|
|
7241
8462
|
...yTicks.map((tick) => {
|
|
7242
8463
|
const y = yInPlot(tick, yDomain, plot);
|
|
7243
|
-
return
|
|
8464
|
+
return import_react13.default.createElement("line", {
|
|
7244
8465
|
key: `y-tick-${tick}`,
|
|
7245
8466
|
x1: plot.x,
|
|
7246
8467
|
y1: y,
|
|
@@ -7251,9 +8472,9 @@ function ScatterPlot({
|
|
|
7251
8472
|
});
|
|
7252
8473
|
})
|
|
7253
8474
|
),
|
|
7254
|
-
|
|
8475
|
+
import_react13.default.createElement("rect", { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight, fill: "transparent", stroke: c.borderLight, strokeWidth: 1.2, rx: 6 }),
|
|
7255
8476
|
...pointGeometries.map(
|
|
7256
|
-
({ item, index, point, color }) =>
|
|
8477
|
+
({ item, index, point, color }) => import_react13.default.createElement("circle", {
|
|
7257
8478
|
key: `${item.label ?? "point"}-${index}`,
|
|
7258
8479
|
cx: point.x,
|
|
7259
8480
|
cy: point.y,
|
|
@@ -7404,18 +8625,18 @@ function ParetoChart({
|
|
|
7404
8625
|
{ label: "Pareto frontier", color: frontier },
|
|
7405
8626
|
{ label: "dominated", color: "neutral" }
|
|
7406
8627
|
],
|
|
7407
|
-
children:
|
|
8628
|
+
children: import_react13.default.createElement(
|
|
7408
8629
|
"div",
|
|
7409
8630
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7410
|
-
|
|
8631
|
+
import_react13.default.createElement(
|
|
7411
8632
|
"svg",
|
|
7412
8633
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7413
|
-
showGrid &&
|
|
8634
|
+
showGrid && import_react13.default.createElement(
|
|
7414
8635
|
"g",
|
|
7415
8636
|
{},
|
|
7416
8637
|
...xTicks.map((tick) => {
|
|
7417
8638
|
const x = pointFor(tick, yDomain.min).x;
|
|
7418
|
-
return
|
|
8639
|
+
return import_react13.default.createElement("line", {
|
|
7419
8640
|
key: `pareto-x-grid-${tick}`,
|
|
7420
8641
|
x1: x,
|
|
7421
8642
|
y1: plot.y,
|
|
@@ -7427,7 +8648,7 @@ function ParetoChart({
|
|
|
7427
8648
|
}),
|
|
7428
8649
|
...yTicks.map((tick) => {
|
|
7429
8650
|
const y = yInPlot(tick, yDomain, plot);
|
|
7430
|
-
return
|
|
8651
|
+
return import_react13.default.createElement("line", {
|
|
7431
8652
|
key: `pareto-y-grid-${tick}`,
|
|
7432
8653
|
x1: plot.x,
|
|
7433
8654
|
y1: y,
|
|
@@ -7438,7 +8659,7 @@ function ParetoChart({
|
|
|
7438
8659
|
});
|
|
7439
8660
|
})
|
|
7440
8661
|
),
|
|
7441
|
-
|
|
8662
|
+
import_react13.default.createElement("rect", {
|
|
7442
8663
|
x: plot.x,
|
|
7443
8664
|
y: plot.y,
|
|
7444
8665
|
width: plot.innerWidth,
|
|
@@ -7448,17 +8669,17 @@ function ParetoChart({
|
|
|
7448
8669
|
strokeWidth: 1.2,
|
|
7449
8670
|
rx: 6
|
|
7450
8671
|
}),
|
|
7451
|
-
showGoal &&
|
|
8672
|
+
showGoal && import_react13.default.createElement(
|
|
7452
8673
|
"g",
|
|
7453
8674
|
{ "data-pareto-goal": true, stroke: frontier, fill: "none", strokeWidth: 2, strokeLinecap: "round" },
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
8675
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalY, x2: goalXEnd, y2: goalY }),
|
|
8676
|
+
import_react13.default.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY - arrowSize }),
|
|
8677
|
+
import_react13.default.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY + arrowSize }),
|
|
8678
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalYStart, x2: goalXStart, y2: goalYEnd }),
|
|
8679
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart - arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) }),
|
|
8680
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart + arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) })
|
|
7460
8681
|
),
|
|
7461
|
-
frontierPath &&
|
|
8682
|
+
frontierPath && import_react13.default.createElement("path", {
|
|
7462
8683
|
"data-pareto-frontier": true,
|
|
7463
8684
|
d: frontierPath,
|
|
7464
8685
|
fill: "none",
|
|
@@ -7467,7 +8688,7 @@ function ParetoChart({
|
|
|
7467
8688
|
strokeLinecap: "round",
|
|
7468
8689
|
strokeLinejoin: "round"
|
|
7469
8690
|
}),
|
|
7470
|
-
...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) =>
|
|
8691
|
+
...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) => import_react13.default.createElement("circle", {
|
|
7471
8692
|
key: `pareto-point-${point.label ?? "point"}-${index}`,
|
|
7472
8693
|
"data-pareto-status": isFrontier ? "frontier" : "dominated",
|
|
7473
8694
|
cx: x,
|
|
@@ -7579,18 +8800,18 @@ function QuadrantChart({
|
|
|
7579
8800
|
subtitle,
|
|
7580
8801
|
width,
|
|
7581
8802
|
footer,
|
|
7582
|
-
children:
|
|
8803
|
+
children: import_react13.default.createElement(
|
|
7583
8804
|
"div",
|
|
7584
8805
|
{
|
|
7585
8806
|
style: { position: "relative", width, height, display: "flex" }
|
|
7586
8807
|
},
|
|
7587
|
-
|
|
8808
|
+
import_react13.default.createElement(
|
|
7588
8809
|
"svg",
|
|
7589
8810
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7590
8811
|
...regionEntries.map(({ key, region, x, y, width: regionWidth, height: regionHeight }, index) => {
|
|
7591
8812
|
const color = chartColor(region.color, c, index);
|
|
7592
8813
|
const emphasized = region.emphasis === true;
|
|
7593
|
-
return
|
|
8814
|
+
return import_react13.default.createElement("rect", {
|
|
7594
8815
|
key: `quadrant-${key}`,
|
|
7595
8816
|
x,
|
|
7596
8817
|
y,
|
|
@@ -7602,12 +8823,12 @@ function QuadrantChart({
|
|
|
7602
8823
|
strokeWidth: emphasized ? 2 : 0
|
|
7603
8824
|
});
|
|
7604
8825
|
}),
|
|
7605
|
-
showGrid &&
|
|
8826
|
+
showGrid && import_react13.default.createElement(
|
|
7606
8827
|
"g",
|
|
7607
8828
|
{},
|
|
7608
8829
|
...xTicks.map((tick) => {
|
|
7609
8830
|
const x = xInPlot(tick, xDomain, plot);
|
|
7610
|
-
return
|
|
8831
|
+
return import_react13.default.createElement("line", {
|
|
7611
8832
|
key: `quadrant-x-grid-${tick}`,
|
|
7612
8833
|
x1: x,
|
|
7613
8834
|
y1: plot.y,
|
|
@@ -7619,7 +8840,7 @@ function QuadrantChart({
|
|
|
7619
8840
|
}),
|
|
7620
8841
|
...yTicks.map((tick) => {
|
|
7621
8842
|
const y = yInPlot(tick, yDomain, plot);
|
|
7622
|
-
return
|
|
8843
|
+
return import_react13.default.createElement("line", {
|
|
7623
8844
|
key: `quadrant-y-grid-${tick}`,
|
|
7624
8845
|
x1: plot.x,
|
|
7625
8846
|
y1: y,
|
|
@@ -7630,7 +8851,7 @@ function QuadrantChart({
|
|
|
7630
8851
|
});
|
|
7631
8852
|
})
|
|
7632
8853
|
),
|
|
7633
|
-
|
|
8854
|
+
import_react13.default.createElement("rect", {
|
|
7634
8855
|
x: plot.x,
|
|
7635
8856
|
y: plot.y,
|
|
7636
8857
|
width: plot.innerWidth,
|
|
@@ -7640,7 +8861,7 @@ function QuadrantChart({
|
|
|
7640
8861
|
strokeWidth: 1.2,
|
|
7641
8862
|
rx: 8
|
|
7642
8863
|
}),
|
|
7643
|
-
|
|
8864
|
+
import_react13.default.createElement("line", {
|
|
7644
8865
|
x1: midX,
|
|
7645
8866
|
y1: plot.y,
|
|
7646
8867
|
x2: midX,
|
|
@@ -7648,7 +8869,7 @@ function QuadrantChart({
|
|
|
7648
8869
|
stroke: c.borderLight,
|
|
7649
8870
|
strokeWidth: 1.4
|
|
7650
8871
|
}),
|
|
7651
|
-
|
|
8872
|
+
import_react13.default.createElement("line", {
|
|
7652
8873
|
x1: plot.x,
|
|
7653
8874
|
y1: midY,
|
|
7654
8875
|
x2: plot.right,
|
|
@@ -7658,7 +8879,7 @@ function QuadrantChart({
|
|
|
7658
8879
|
}),
|
|
7659
8880
|
...(showTicks ? xTicks : []).map((tick) => {
|
|
7660
8881
|
const x = xInPlot(tick, xDomain, plot);
|
|
7661
|
-
return
|
|
8882
|
+
return import_react13.default.createElement("line", {
|
|
7662
8883
|
key: `quadrant-x-tick-${tick}`,
|
|
7663
8884
|
x1: x,
|
|
7664
8885
|
y1: plot.bottom,
|
|
@@ -7670,7 +8891,7 @@ function QuadrantChart({
|
|
|
7670
8891
|
}),
|
|
7671
8892
|
...(showTicks ? yTicks : []).map((tick) => {
|
|
7672
8893
|
const y = yInPlot(tick, yDomain, plot);
|
|
7673
|
-
return
|
|
8894
|
+
return import_react13.default.createElement("line", {
|
|
7674
8895
|
key: `quadrant-y-tick-${tick}`,
|
|
7675
8896
|
x1: plot.x - 5,
|
|
7676
8897
|
y1: y,
|
|
@@ -7680,7 +8901,7 @@ function QuadrantChart({
|
|
|
7680
8901
|
strokeWidth: 1.2
|
|
7681
8902
|
});
|
|
7682
8903
|
}),
|
|
7683
|
-
...pointGeometries.map(({ point, index, x, y, color }) =>
|
|
8904
|
+
...pointGeometries.map(({ point, index, x, y, color }) => import_react13.default.createElement("circle", {
|
|
7684
8905
|
key: `quadrant-point-${point.label ?? index}`,
|
|
7685
8906
|
cx: x,
|
|
7686
8907
|
cy: y,
|
|
@@ -7782,15 +9003,15 @@ function IntervalPlot({
|
|
|
7782
9003
|
subtitle,
|
|
7783
9004
|
width,
|
|
7784
9005
|
footer,
|
|
7785
|
-
children:
|
|
9006
|
+
children: import_react13.default.createElement(
|
|
7786
9007
|
"div",
|
|
7787
9008
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7788
|
-
|
|
9009
|
+
import_react13.default.createElement(
|
|
7789
9010
|
"svg",
|
|
7790
9011
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7791
9012
|
...ticks.map((tick) => {
|
|
7792
9013
|
const x = scaleX(tick);
|
|
7793
|
-
return
|
|
9014
|
+
return import_react13.default.createElement("line", {
|
|
7794
9015
|
key: `interval-tick-${tick}`,
|
|
7795
9016
|
x1: x,
|
|
7796
9017
|
y1: plot.y,
|
|
@@ -7800,10 +9021,10 @@ function IntervalPlot({
|
|
|
7800
9021
|
strokeWidth: 1
|
|
7801
9022
|
});
|
|
7802
9023
|
}),
|
|
7803
|
-
|
|
9024
|
+
import_react13.default.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
7804
9025
|
...rows.flatMap(({ item, index, y, color, lowX, midX, highX }) => [
|
|
7805
|
-
|
|
7806
|
-
|
|
9026
|
+
import_react13.default.createElement("line", { key: `${item.label}-range-${index}`, x1: lowX, y1: y, x2: highX, y2: y, stroke: color, strokeWidth: 9, strokeLinecap: "round", opacity: 0.9 }),
|
|
9027
|
+
import_react13.default.createElement("circle", { key: `${item.label}-mid-${index}`, cx: midX, cy: y, r: 10, fill: c.bgCard, stroke: color, strokeWidth: 4 })
|
|
7807
9028
|
])
|
|
7808
9029
|
),
|
|
7809
9030
|
...ticks.map((tick, index) => {
|
|
@@ -7840,7 +9061,7 @@ function IntervalPlot({
|
|
|
7840
9061
|
}
|
|
7841
9062
|
function Badge({ label, c, color = "primary" }) {
|
|
7842
9063
|
const solidColor = getReadableColor(color, c);
|
|
7843
|
-
return
|
|
9064
|
+
return import_react13.default.createElement("div", {
|
|
7844
9065
|
style: {
|
|
7845
9066
|
display: "flex",
|
|
7846
9067
|
alignItems: "center",
|
|
@@ -7861,7 +9082,7 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
|
|
|
7861
9082
|
const offY = labelOffset?.y ?? -22;
|
|
7862
9083
|
return [
|
|
7863
9084
|
// Dot
|
|
7864
|
-
|
|
9085
|
+
import_react13.default.createElement("div", {
|
|
7865
9086
|
key: `dot-${label}`,
|
|
7866
9087
|
style: {
|
|
7867
9088
|
position: "absolute",
|
|
@@ -7876,7 +9097,7 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
|
|
|
7876
9097
|
}
|
|
7877
9098
|
}),
|
|
7878
9099
|
// Label
|
|
7879
|
-
|
|
9100
|
+
import_react13.default.createElement("div", {
|
|
7880
9101
|
key: `label-${label}`,
|
|
7881
9102
|
style: {
|
|
7882
9103
|
position: "absolute",
|
|
@@ -7902,7 +9123,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
|
|
|
7902
9123
|
if (i % 2 === 1) continue;
|
|
7903
9124
|
const t = i / numDots;
|
|
7904
9125
|
dots.push(
|
|
7905
|
-
|
|
9126
|
+
import_react13.default.createElement("div", {
|
|
7906
9127
|
key: `dash-${i}`,
|
|
7907
9128
|
style: {
|
|
7908
9129
|
position: "absolute",
|
|
@@ -7919,7 +9140,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
|
|
|
7919
9140
|
return dots;
|
|
7920
9141
|
}
|
|
7921
9142
|
function Legend({ items, c, title }) {
|
|
7922
|
-
return
|
|
9143
|
+
return import_react13.default.createElement(
|
|
7923
9144
|
"div",
|
|
7924
9145
|
{
|
|
7925
9146
|
style: {
|
|
@@ -7932,7 +9153,7 @@ function Legend({ items, c, title }) {
|
|
|
7932
9153
|
padding: "14px 16px"
|
|
7933
9154
|
}
|
|
7934
9155
|
},
|
|
7935
|
-
title &&
|
|
9156
|
+
title && import_react13.default.createElement("div", {
|
|
7936
9157
|
style: {
|
|
7937
9158
|
fontSize: 11,
|
|
7938
9159
|
fontWeight: 700,
|
|
@@ -7943,13 +9164,13 @@ function Legend({ items, c, title }) {
|
|
|
7943
9164
|
}
|
|
7944
9165
|
}, title),
|
|
7945
9166
|
...items.map(
|
|
7946
|
-
(item, i) =>
|
|
9167
|
+
(item, i) => import_react13.default.createElement(
|
|
7947
9168
|
"div",
|
|
7948
9169
|
{
|
|
7949
9170
|
key: `legend-${i}`,
|
|
7950
9171
|
style: { display: "flex", alignItems: "center", gap: 8 }
|
|
7951
9172
|
},
|
|
7952
|
-
|
|
9173
|
+
import_react13.default.createElement("div", {
|
|
7953
9174
|
style: {
|
|
7954
9175
|
width: 16,
|
|
7955
9176
|
height: item.style === "dashed" ? 0 : 2,
|
|
@@ -7959,7 +9180,7 @@ function Legend({ items, c, title }) {
|
|
|
7959
9180
|
} : {}
|
|
7960
9181
|
}
|
|
7961
9182
|
}),
|
|
7962
|
-
|
|
9183
|
+
import_react13.default.createElement("div", {
|
|
7963
9184
|
style: {
|
|
7964
9185
|
fontSize: 11,
|
|
7965
9186
|
color: c.textMuted,
|
|
@@ -7971,6 +9192,45 @@ function Legend({ items, c, title }) {
|
|
|
7971
9192
|
);
|
|
7972
9193
|
}
|
|
7973
9194
|
|
|
9195
|
+
// src/primitives/board.ts
|
|
9196
|
+
var import_react14 = __toESM(require("react"), 1);
|
|
9197
|
+
var CANVAS_ITEM_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvas-item");
|
|
9198
|
+
function dimension(value, name) {
|
|
9199
|
+
if (value !== void 0 && (!Number.isFinite(value) || value <= 0 || value > 8192)) {
|
|
9200
|
+
throw new Error(`${name} must be a finite number greater than 0 and at most 8192.`);
|
|
9201
|
+
}
|
|
9202
|
+
return value;
|
|
9203
|
+
}
|
|
9204
|
+
function Board({ children, c, width = 960, height = 540, background }) {
|
|
9205
|
+
return import_react14.default.createElement("div", { style: {
|
|
9206
|
+
display: "flex",
|
|
9207
|
+
position: "relative",
|
|
9208
|
+
width: dimension(width, "Board width"),
|
|
9209
|
+
height: dimension(height, "Board height"),
|
|
9210
|
+
overflow: "hidden",
|
|
9211
|
+
backgroundColor: background ?? "transparent",
|
|
9212
|
+
color: c.textPrimary
|
|
9213
|
+
} }, children);
|
|
9214
|
+
}
|
|
9215
|
+
function CanvasItem({ children, x, y, width, height }) {
|
|
9216
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error("CanvasItem x and y must be finite numbers.");
|
|
9217
|
+
const sizedChildren = import_react14.default.Children.map(children, (child) => {
|
|
9218
|
+
if (!import_react14.default.isValidElement(child)) return child;
|
|
9219
|
+
const sized = import_react14.default.cloneElement(child, { ...width !== void 0 ? { width } : {}, ...height !== void 0 ? { height } : {} });
|
|
9220
|
+
return width !== void 0 && height !== void 0 && isCanvasChart(child.type) ? import_react14.default.createElement(CanvasChartFit, { width, height, __vizmaticTextScope: child.props.__vizmaticTextScope }, sized) : sized;
|
|
9221
|
+
});
|
|
9222
|
+
return import_react14.default.createElement("div", { style: {
|
|
9223
|
+
display: "flex",
|
|
9224
|
+
position: "absolute",
|
|
9225
|
+
left: x,
|
|
9226
|
+
top: y,
|
|
9227
|
+
width: dimension(width, "CanvasItem width"),
|
|
9228
|
+
height: dimension(height, "CanvasItem height"),
|
|
9229
|
+
alignItems: "stretch"
|
|
9230
|
+
} }, sizedChildren);
|
|
9231
|
+
}
|
|
9232
|
+
Object.defineProperty(CanvasItem, CANVAS_ITEM_COMPONENT, { value: true });
|
|
9233
|
+
|
|
7974
9234
|
// src/render.ts
|
|
7975
9235
|
var import_resvg_js = require("@resvg/resvg-js");
|
|
7976
9236
|
var import_os = require("os");
|
|
@@ -7981,12 +9241,12 @@ var import_url = require("url");
|
|
|
7981
9241
|
var import_zlib = require("zlib");
|
|
7982
9242
|
|
|
7983
9243
|
// src/brand.ts
|
|
7984
|
-
var
|
|
9244
|
+
var import_react15 = __toESM(require("react"), 1);
|
|
7985
9245
|
var DEFAULT_WATERMARK_TEXT = "Vizmatic";
|
|
7986
9246
|
var WATERMARK_COLOR_DARK = "#a78bfa";
|
|
7987
9247
|
var WATERMARK_COLOR_LIGHT = "#7c3aed";
|
|
7988
9248
|
function VizmaticIcon({ size = 14, color }) {
|
|
7989
|
-
return
|
|
9249
|
+
return import_react15.default.createElement(
|
|
7990
9250
|
"svg",
|
|
7991
9251
|
{
|
|
7992
9252
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -7995,19 +9255,19 @@ function VizmaticIcon({ size = 14, color }) {
|
|
|
7995
9255
|
viewBox: "0 0 28 28",
|
|
7996
9256
|
fill: "none"
|
|
7997
9257
|
},
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
9258
|
+
import_react15.default.createElement("rect", { x: 2.5, y: 2.5, width: 23, height: 23, rx: 6.5, stroke: color, strokeWidth: 2, opacity: 0.54 }),
|
|
9259
|
+
import_react15.default.createElement("rect", { x: 7, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.35 }),
|
|
9260
|
+
import_react15.default.createElement("rect", { x: 15.5, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color }),
|
|
9261
|
+
import_react15.default.createElement("rect", { x: 7, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.82 }),
|
|
9262
|
+
import_react15.default.createElement("rect", { x: 15.5, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, stroke: color, strokeWidth: 1.5, opacity: 0.72 }),
|
|
9263
|
+
import_react15.default.createElement("path", { d: "M9.75 9.75h8.5M9.75 18.25h8.5M9.75 9.75v8.5M18.25 9.75v8.5", stroke: color, strokeWidth: 1.6, strokeLinecap: "round", opacity: 0.88 })
|
|
8004
9264
|
);
|
|
8005
9265
|
}
|
|
8006
9266
|
function normalizeWatermark(watermark) {
|
|
8007
9267
|
if (watermark == null || watermark === false) return void 0;
|
|
8008
9268
|
if (watermark === true) return {};
|
|
8009
9269
|
if (typeof watermark === "string") return { text: watermark };
|
|
8010
|
-
if (
|
|
9270
|
+
if (import_react15.default.isValidElement(watermark)) {
|
|
8011
9271
|
if (watermark.type !== Watermark) return { element: watermark };
|
|
8012
9272
|
const { children, ...props } = watermark.props;
|
|
8013
9273
|
return {
|
|
@@ -8036,7 +9296,7 @@ function positionStyle(position) {
|
|
|
8036
9296
|
function imageNode(image) {
|
|
8037
9297
|
if (!image) return void 0;
|
|
8038
9298
|
const imageOptions = typeof image === "string" ? { src: image } : image;
|
|
8039
|
-
return
|
|
9299
|
+
return import_react15.default.createElement("img", {
|
|
8040
9300
|
src: imageOptions.src,
|
|
8041
9301
|
alt: imageOptions.alt ?? "",
|
|
8042
9302
|
width: imageOptions.width ?? 14,
|
|
@@ -8051,9 +9311,9 @@ function imageNode(image) {
|
|
|
8051
9311
|
}
|
|
8052
9312
|
function iconNode(icon, color) {
|
|
8053
9313
|
if (icon === false) return void 0;
|
|
8054
|
-
if (icon == null) return
|
|
9314
|
+
if (icon == null) return import_react15.default.createElement(VizmaticIcon, { size: 13, color });
|
|
8055
9315
|
if (typeof icon !== "string") return icon;
|
|
8056
|
-
return
|
|
9316
|
+
return import_react15.default.createElement("div", {
|
|
8057
9317
|
style: {
|
|
8058
9318
|
minWidth: 13,
|
|
8059
9319
|
height: 13,
|
|
@@ -8078,7 +9338,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8078
9338
|
const text = options?.text ?? DEFAULT_WATERMARK_TEXT;
|
|
8079
9339
|
const content = options?.element ?? [
|
|
8080
9340
|
icon,
|
|
8081
|
-
text !== false && text &&
|
|
9341
|
+
text !== false && text && import_react15.default.createElement("div", {
|
|
8082
9342
|
key: "text",
|
|
8083
9343
|
style: {
|
|
8084
9344
|
fontSize: 11,
|
|
@@ -8089,7 +9349,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8089
9349
|
}
|
|
8090
9350
|
}, text)
|
|
8091
9351
|
];
|
|
8092
|
-
return
|
|
9352
|
+
return import_react15.default.createElement(
|
|
8093
9353
|
"div",
|
|
8094
9354
|
{
|
|
8095
9355
|
style: {
|
|
@@ -8100,7 +9360,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8100
9360
|
}
|
|
8101
9361
|
},
|
|
8102
9362
|
element,
|
|
8103
|
-
options &&
|
|
9363
|
+
options && import_react15.default.createElement(
|
|
8104
9364
|
"div",
|
|
8105
9365
|
{
|
|
8106
9366
|
style: {
|
|
@@ -8223,13 +9483,13 @@ function detectOverflow(pixels, width, height, bgColor, edgeTolerance = 3, minDe
|
|
|
8223
9483
|
const right = checkEdge((i, off) => [width - 1 - off, i], height);
|
|
8224
9484
|
const top = checkEdge((i, off) => [i, off], width);
|
|
8225
9485
|
const left = checkEdge((i, off) => [off, i], height);
|
|
8226
|
-
const
|
|
8227
|
-
if (top)
|
|
8228
|
-
if (right)
|
|
8229
|
-
if (bottom)
|
|
8230
|
-
if (left)
|
|
8231
|
-
const overflows =
|
|
8232
|
-
const message = overflows ? `Content overflows canvas at: ${
|
|
9486
|
+
const overflowEdges2 = [];
|
|
9487
|
+
if (top) overflowEdges2.push("top");
|
|
9488
|
+
if (right) overflowEdges2.push("right");
|
|
9489
|
+
if (bottom) overflowEdges2.push("bottom");
|
|
9490
|
+
if (left) overflowEdges2.push("left");
|
|
9491
|
+
const overflows = overflowEdges2.length > 0;
|
|
9492
|
+
const message = overflows ? `Content overflows canvas at: ${overflowEdges2.join(", ")}. Increase the illustration dimensions.` : "";
|
|
8233
9493
|
return {
|
|
8234
9494
|
overflows,
|
|
8235
9495
|
edges: { top, right, bottom, left },
|
|
@@ -8251,7 +9511,8 @@ function resolveSatori(api) {
|
|
|
8251
9511
|
}
|
|
8252
9512
|
throw new Error("satori export could not be resolved");
|
|
8253
9513
|
}
|
|
8254
|
-
var
|
|
9514
|
+
var renderSatori = resolveSatori(satoriModule);
|
|
9515
|
+
var satori = (element, options) => renderWithCanvasChartFit(renderSatori, element, options);
|
|
8255
9516
|
|
|
8256
9517
|
// src/render.ts
|
|
8257
9518
|
var FONT_CACHE_DIR = process.env.VIZMATIC_FONT_DIR ?? (0, import_path.join)(process.env.XDG_CACHE_HOME ?? (0, import_path.join)((0, import_os.homedir)(), ".cache"), "vizmatic", "fonts");
|
|
@@ -8698,14 +9959,19 @@ async function renderToSvgInContext(element, width, height, options) {
|
|
|
8698
9959
|
options.theme ?? "dark",
|
|
8699
9960
|
watermark
|
|
8700
9961
|
) : element;
|
|
8701
|
-
const
|
|
9962
|
+
const prepared = prepareAccessibleSvg(outputElement);
|
|
9963
|
+
const layoutNodes = [];
|
|
9964
|
+
const svg = await satori(prepared.element, {
|
|
8702
9965
|
width,
|
|
8703
9966
|
height,
|
|
8704
9967
|
fonts,
|
|
8705
9968
|
loadAdditionalAsset,
|
|
8706
|
-
onNodeDetected:
|
|
9969
|
+
onNodeDetected: (node) => {
|
|
9970
|
+
layoutNodes.push(node);
|
|
9971
|
+
options.onNodeDetected?.(node);
|
|
9972
|
+
}
|
|
8707
9973
|
});
|
|
8708
|
-
return sanitizeSvg(svg);
|
|
9974
|
+
return addSvgAccessibility(sanitizeSvg(svg), prepared.graphs, layoutNodes);
|
|
8709
9975
|
}
|
|
8710
9976
|
|
|
8711
9977
|
// src/animate.ts
|
|
@@ -9486,6 +10752,1331 @@ async function renderAnimationGifWithOutput(animation, options) {
|
|
|
9486
10752
|
bytes: bytes.length
|
|
9487
10753
|
};
|
|
9488
10754
|
}
|
|
10755
|
+
|
|
10756
|
+
// src/import-types.ts
|
|
10757
|
+
function graphImportResult(source, graph, diagnostics) {
|
|
10758
|
+
if (graph.nodes.length === 0 && diagnostics.every(({ severity }) => severity !== "error")) {
|
|
10759
|
+
diagnostics.push({
|
|
10760
|
+
code: "import.empty",
|
|
10761
|
+
severity: "error",
|
|
10762
|
+
message: "The source contains no graph nodes to import.",
|
|
10763
|
+
line: 1,
|
|
10764
|
+
column: 1,
|
|
10765
|
+
excerpt: ""
|
|
10766
|
+
});
|
|
10767
|
+
}
|
|
10768
|
+
const ok = diagnostics.every(({ severity }) => severity !== "error");
|
|
10769
|
+
return ok ? { source, ok, graph, diagnostics } : { source, ok, diagnostics };
|
|
10770
|
+
}
|
|
10771
|
+
function addImportDiagnostic(diagnostics, sourceLines, line, code, severity, message, column = 1) {
|
|
10772
|
+
diagnostics.push({
|
|
10773
|
+
code,
|
|
10774
|
+
severity,
|
|
10775
|
+
message,
|
|
10776
|
+
line,
|
|
10777
|
+
column,
|
|
10778
|
+
excerpt: (sourceLines[line - 1] ?? "").trim().slice(0, 180)
|
|
10779
|
+
});
|
|
10780
|
+
}
|
|
10781
|
+
|
|
10782
|
+
// src/import-mermaid.ts
|
|
10783
|
+
var ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*/;
|
|
10784
|
+
var CONNECTORS = ["-.->", "-->", "---"];
|
|
10785
|
+
function skipWhitespace(line, index) {
|
|
10786
|
+
while (index < line.length && /\s/.test(line[index] ?? "")) index++;
|
|
10787
|
+
return index;
|
|
10788
|
+
}
|
|
10789
|
+
function readDelimited(line, start, close) {
|
|
10790
|
+
let inDoubleQuote = false;
|
|
10791
|
+
let escaped = false;
|
|
10792
|
+
for (let index = start; index < line.length; index++) {
|
|
10793
|
+
const character = line[index];
|
|
10794
|
+
if (inDoubleQuote) {
|
|
10795
|
+
if (escaped) escaped = false;
|
|
10796
|
+
else if (character === "\\") escaped = true;
|
|
10797
|
+
else if (character === '"') inDoubleQuote = false;
|
|
10798
|
+
continue;
|
|
10799
|
+
}
|
|
10800
|
+
if (character === '"') {
|
|
10801
|
+
inDoubleQuote = true;
|
|
10802
|
+
continue;
|
|
10803
|
+
}
|
|
10804
|
+
if (line.startsWith(close, index)) {
|
|
10805
|
+
return { value: line.slice(start, index), next: index + close.length };
|
|
10806
|
+
}
|
|
10807
|
+
}
|
|
10808
|
+
return void 0;
|
|
10809
|
+
}
|
|
10810
|
+
function decodeLabel(raw) {
|
|
10811
|
+
const value = raw.trim();
|
|
10812
|
+
if (!value.startsWith('"')) return value;
|
|
10813
|
+
if (!value.endsWith('"')) return void 0;
|
|
10814
|
+
try {
|
|
10815
|
+
const decoded = JSON.parse(value);
|
|
10816
|
+
return typeof decoded === "string" ? decoded : void 0;
|
|
10817
|
+
} catch {
|
|
10818
|
+
return void 0;
|
|
10819
|
+
}
|
|
10820
|
+
}
|
|
10821
|
+
function labelHasUnsupportedMarkup(label) {
|
|
10822
|
+
return /<[^>]*>|`|\*\*|__|~~|(^|\s)\*[^*]|\b_[^_]+_\b|\n|\r/.test(label);
|
|
10823
|
+
}
|
|
10824
|
+
function readEndpoint(line, from) {
|
|
10825
|
+
let index = skipWhitespace(line, from);
|
|
10826
|
+
const id = line.slice(index).match(ID_PATTERN)?.[0];
|
|
10827
|
+
if (!id) return void 0;
|
|
10828
|
+
index += id.length;
|
|
10829
|
+
const afterId = skipWhitespace(line, index);
|
|
10830
|
+
if (afterId >= line.length) return { id, label: id, shape: "rectangle", next: afterId };
|
|
10831
|
+
const rest = line.slice(afterId);
|
|
10832
|
+
const delimiters = [
|
|
10833
|
+
{ open: "[(", close: ")]", lossy: true },
|
|
10834
|
+
{ open: "([", close: "])", lossy: true },
|
|
10835
|
+
{ open: "((", close: "))", lossy: true },
|
|
10836
|
+
{ open: "{{", close: "}}", lossy: true },
|
|
10837
|
+
{ open: "[", close: "]", lossy: false },
|
|
10838
|
+
{ open: "(", close: ")", lossy: true },
|
|
10839
|
+
{ open: "{", close: "}", lossy: true }
|
|
10840
|
+
];
|
|
10841
|
+
const delimiter = delimiters.find(({ open }) => rest.startsWith(open));
|
|
10842
|
+
if (!delimiter) return { id, label: id, shape: "rectangle", next: index };
|
|
10843
|
+
const content = readDelimited(line, afterId + delimiter.open.length, delimiter.close);
|
|
10844
|
+
if (!content) return void 0;
|
|
10845
|
+
const label = decodeLabel(content.value);
|
|
10846
|
+
if (label === void 0) return void 0;
|
|
10847
|
+
return {
|
|
10848
|
+
id,
|
|
10849
|
+
label,
|
|
10850
|
+
shape: delimiter.lossy ? "lossy" : "rectangle",
|
|
10851
|
+
next: content.next
|
|
10852
|
+
};
|
|
10853
|
+
}
|
|
10854
|
+
function addNode(state, endpoint2, groupId, line, sourceLines, diagnostics, explicitlyDeclared) {
|
|
10855
|
+
if (state.groupIds.has(endpoint2.id)) {
|
|
10856
|
+
addImportDiagnostic(
|
|
10857
|
+
diagnostics,
|
|
10858
|
+
sourceLines,
|
|
10859
|
+
line,
|
|
10860
|
+
"import.unsupported_semantics",
|
|
10861
|
+
"error",
|
|
10862
|
+
`Mermaid id "${endpoint2.id}" is already used by a subgraph and cannot also be a node.`
|
|
10863
|
+
);
|
|
10864
|
+
return false;
|
|
10865
|
+
}
|
|
10866
|
+
if (labelHasUnsupportedMarkup(endpoint2.label)) {
|
|
10867
|
+
addImportDiagnostic(
|
|
10868
|
+
diagnostics,
|
|
10869
|
+
sourceLines,
|
|
10870
|
+
line,
|
|
10871
|
+
"import.unsupported_semantics",
|
|
10872
|
+
"error",
|
|
10873
|
+
`Mermaid label for node "${endpoint2.id}" uses HTML or Markdown formatting that GraphDiagram cannot preserve.`
|
|
10874
|
+
);
|
|
10875
|
+
return false;
|
|
10876
|
+
}
|
|
10877
|
+
const existingIndex = state.nodeIndexes.get(endpoint2.id);
|
|
10878
|
+
if (existingIndex !== void 0) {
|
|
10879
|
+
const existing = state.nodes[existingIndex];
|
|
10880
|
+
if (!existing) return false;
|
|
10881
|
+
if (groupId && existing.group && existing.group !== groupId) {
|
|
10882
|
+
addImportDiagnostic(
|
|
10883
|
+
diagnostics,
|
|
10884
|
+
sourceLines,
|
|
10885
|
+
line,
|
|
10886
|
+
"import.unsupported_semantics",
|
|
10887
|
+
"error",
|
|
10888
|
+
`Mermaid node "${endpoint2.id}" is assigned to more than one subgraph; GraphDiagram nodes support one group.`
|
|
10889
|
+
);
|
|
10890
|
+
return false;
|
|
10891
|
+
}
|
|
10892
|
+
if (groupId && !existing.group) {
|
|
10893
|
+
addImportDiagnostic(
|
|
10894
|
+
diagnostics,
|
|
10895
|
+
sourceLines,
|
|
10896
|
+
line,
|
|
10897
|
+
"import.unsupported_semantics",
|
|
10898
|
+
"error",
|
|
10899
|
+
`Mermaid node "${endpoint2.id}" is referenced both inside and outside a subgraph; its group membership is ambiguous.`
|
|
10900
|
+
);
|
|
10901
|
+
return false;
|
|
10902
|
+
}
|
|
10903
|
+
if (explicitlyDeclared) existing.label = endpoint2.label;
|
|
10904
|
+
} else {
|
|
10905
|
+
state.nodeIndexes.set(endpoint2.id, state.nodes.length);
|
|
10906
|
+
state.nodes.push({
|
|
10907
|
+
id: endpoint2.id,
|
|
10908
|
+
label: endpoint2.label,
|
|
10909
|
+
...groupId ? { group: groupId } : {}
|
|
10910
|
+
});
|
|
10911
|
+
}
|
|
10912
|
+
if (endpoint2.shape === "lossy" && !state.warnedShapes.has(endpoint2.id)) {
|
|
10913
|
+
state.warnedShapes.add(endpoint2.id);
|
|
10914
|
+
addImportDiagnostic(
|
|
10915
|
+
diagnostics,
|
|
10916
|
+
sourceLines,
|
|
10917
|
+
line,
|
|
10918
|
+
"import.lossy_semantics",
|
|
10919
|
+
"warning",
|
|
10920
|
+
`Mermaid node "${endpoint2.id}" uses a non-rectangular shape; it will render as a generic GraphDiagram node.`
|
|
10921
|
+
);
|
|
10922
|
+
}
|
|
10923
|
+
return true;
|
|
10924
|
+
}
|
|
10925
|
+
function parseNodeOrEdgeLine(line, groupId, lineNumber, sourceLines, state, diagnostics) {
|
|
10926
|
+
const first = readEndpoint(line, 0);
|
|
10927
|
+
if (!first) {
|
|
10928
|
+
addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.parse_error", "error", "Could not parse this Mermaid node or edge statement.");
|
|
10929
|
+
return;
|
|
10930
|
+
}
|
|
10931
|
+
const connectorStart = skipWhitespace(line, first.next);
|
|
10932
|
+
const hasConnector = CONNECTORS.some((connector) => line.startsWith(connector, connectorStart));
|
|
10933
|
+
if (!addNode(state, first, groupId, lineNumber, sourceLines, diagnostics, !hasConnector)) return;
|
|
10934
|
+
let previous = first;
|
|
10935
|
+
let cursor = first.next;
|
|
10936
|
+
while (true) {
|
|
10937
|
+
cursor = skipWhitespace(line, cursor);
|
|
10938
|
+
if (cursor >= line.length) return;
|
|
10939
|
+
const connector = CONNECTORS.find((candidate) => line.startsWith(candidate, cursor));
|
|
10940
|
+
if (!connector) {
|
|
10941
|
+
addImportDiagnostic(
|
|
10942
|
+
diagnostics,
|
|
10943
|
+
sourceLines,
|
|
10944
|
+
lineNumber,
|
|
10945
|
+
"import.unsupported_syntax",
|
|
10946
|
+
"error",
|
|
10947
|
+
"Only Mermaid -->, ---, and -.-> connections are supported; chained or styled statements must be split or simplified.",
|
|
10948
|
+
cursor + 1
|
|
10949
|
+
);
|
|
10950
|
+
return;
|
|
10951
|
+
}
|
|
10952
|
+
cursor += connector.length;
|
|
10953
|
+
cursor = skipWhitespace(line, cursor);
|
|
10954
|
+
let edgeLabel;
|
|
10955
|
+
if (line[cursor] === "|") {
|
|
10956
|
+
const end = line.indexOf("|", cursor + 1);
|
|
10957
|
+
if (end < 0) {
|
|
10958
|
+
addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.parse_error", "error", "Mermaid edge label is missing its closing |.", cursor + 1);
|
|
10959
|
+
return;
|
|
10960
|
+
}
|
|
10961
|
+
edgeLabel = line.slice(cursor + 1, end).trim();
|
|
10962
|
+
cursor = skipWhitespace(line, end + 1);
|
|
10963
|
+
if (labelHasUnsupportedMarkup(edgeLabel)) {
|
|
10964
|
+
addImportDiagnostic(
|
|
10965
|
+
diagnostics,
|
|
10966
|
+
sourceLines,
|
|
10967
|
+
lineNumber,
|
|
10968
|
+
"import.unsupported_semantics",
|
|
10969
|
+
"error",
|
|
10970
|
+
"Mermaid edge labels with HTML or Markdown formatting cannot be represented as plain GraphDiagram labels.",
|
|
10971
|
+
cursor + 1
|
|
10972
|
+
);
|
|
10973
|
+
return;
|
|
10974
|
+
}
|
|
10975
|
+
}
|
|
10976
|
+
const next = readEndpoint(line, cursor);
|
|
10977
|
+
if (!next) {
|
|
10978
|
+
addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.parse_error", "error", "Mermaid connection has no supported target node.", cursor + 1);
|
|
10979
|
+
return;
|
|
10980
|
+
}
|
|
10981
|
+
if (!addNode(state, next, groupId, lineNumber, sourceLines, diagnostics, false)) return;
|
|
10982
|
+
const edge = {
|
|
10983
|
+
from: previous.id,
|
|
10984
|
+
to: next.id,
|
|
10985
|
+
...edgeLabel !== void 0 ? { label: edgeLabel } : {},
|
|
10986
|
+
...connector === "---" ? { arrow: "none" } : connector === "-.->" ? { arrow: "forward", style: "dotted" } : { arrow: "forward" }
|
|
10987
|
+
};
|
|
10988
|
+
state.edges.push(edge);
|
|
10989
|
+
state.edgeReferences.push({ id: previous.id, line: lineNumber }, { id: next.id, line: lineNumber });
|
|
10990
|
+
previous = next;
|
|
10991
|
+
cursor = next.next;
|
|
10992
|
+
}
|
|
10993
|
+
}
|
|
10994
|
+
function importMermaidGraph(source) {
|
|
10995
|
+
const sourceLines = source.split(/\r?\n/);
|
|
10996
|
+
const diagnostics = [];
|
|
10997
|
+
const state = {
|
|
10998
|
+
nodes: [],
|
|
10999
|
+
nodeIndexes: /* @__PURE__ */ new Map(),
|
|
11000
|
+
groups: [],
|
|
11001
|
+
groupIds: /* @__PURE__ */ new Set(),
|
|
11002
|
+
edges: [],
|
|
11003
|
+
edgeReferences: [],
|
|
11004
|
+
warnedShapes: /* @__PURE__ */ new Set()
|
|
11005
|
+
};
|
|
11006
|
+
let direction = "TB";
|
|
11007
|
+
let currentGroup;
|
|
11008
|
+
let sawHeader = false;
|
|
11009
|
+
for (let index = 0; index < sourceLines.length; index++) {
|
|
11010
|
+
const lineNumber = index + 1;
|
|
11011
|
+
const rawLine = sourceLines[index] ?? "";
|
|
11012
|
+
const line = rawLine.trim();
|
|
11013
|
+
if (!line) continue;
|
|
11014
|
+
if (line.startsWith("%%{")) {
|
|
11015
|
+
addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.unsupported_semantics", "error", "Mermaid directives and embedded configuration are not imported.");
|
|
11016
|
+
continue;
|
|
11017
|
+
}
|
|
11018
|
+
if (line.startsWith("%%")) continue;
|
|
11019
|
+
if (!sawHeader) {
|
|
11020
|
+
const header = line.match(/^(?:flowchart|graph)(?:\s+(LR|RL|TB|TD|BT))?$/i);
|
|
11021
|
+
if (!header) {
|
|
11022
|
+
addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.parse_error", "error", 'Expected a Mermaid flowchart or graph header such as "flowchart LR".');
|
|
11023
|
+
sawHeader = true;
|
|
11024
|
+
continue;
|
|
11025
|
+
}
|
|
11026
|
+
sawHeader = true;
|
|
11027
|
+
const sourceDirection = header[1]?.toUpperCase();
|
|
11028
|
+
direction = sourceDirection === "TD" ? "TB" : sourceDirection ?? "TB";
|
|
11029
|
+
continue;
|
|
11030
|
+
}
|
|
11031
|
+
const subgraph = line.match(/^subgraph\s+([A-Za-z_][A-Za-z0-9_-]*)(?:\s+\[([^\]]*)\])?\s*$/i);
|
|
11032
|
+
if (subgraph) {
|
|
11033
|
+
if (currentGroup) {
|
|
11034
|
+
addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.unsupported_semantics", "error", "Nested Mermaid subgraphs are not imported.");
|
|
11035
|
+
continue;
|
|
11036
|
+
}
|
|
11037
|
+
const id = subgraph[1];
|
|
11038
|
+
if (!id) continue;
|
|
11039
|
+
if (state.groupIds.has(id) || state.nodeIndexes.has(id)) {
|
|
11040
|
+
addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.unsupported_semantics", "error", `Mermaid subgraph id "${id}" conflicts with an existing group or node.`);
|
|
11041
|
+
continue;
|
|
11042
|
+
}
|
|
11043
|
+
const rawLabel = subgraph[2];
|
|
11044
|
+
const label = rawLabel === void 0 ? id : decodeLabel(rawLabel);
|
|
11045
|
+
if (label === void 0 || labelHasUnsupportedMarkup(label)) {
|
|
11046
|
+
addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.unsupported_semantics", "error", `Mermaid subgraph "${id}" uses a label format that cannot be preserved.`);
|
|
11047
|
+
continue;
|
|
11048
|
+
}
|
|
11049
|
+
currentGroup = id;
|
|
11050
|
+
state.groupIds.add(id);
|
|
11051
|
+
state.groups.push({ id, label });
|
|
11052
|
+
continue;
|
|
11053
|
+
}
|
|
11054
|
+
if (/^subgraph\b/i.test(line)) {
|
|
11055
|
+
addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.unsupported_syntax", "error", "Use a simple Mermaid subgraph declaration with an identifier and optional bracketed label.");
|
|
11056
|
+
continue;
|
|
11057
|
+
}
|
|
11058
|
+
if (/^end\s*$/i.test(line)) {
|
|
11059
|
+
if (!currentGroup) addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.parse_error", "error", "Mermaid end has no matching subgraph.");
|
|
11060
|
+
else currentGroup = void 0;
|
|
11061
|
+
continue;
|
|
11062
|
+
}
|
|
11063
|
+
if (/^direction\b/i.test(line)) {
|
|
11064
|
+
addImportDiagnostic(
|
|
11065
|
+
diagnostics,
|
|
11066
|
+
sourceLines,
|
|
11067
|
+
lineNumber,
|
|
11068
|
+
currentGroup ? "import.unsupported_semantics" : "import.parse_error",
|
|
11069
|
+
"error",
|
|
11070
|
+
currentGroup ? "Per-subgraph Mermaid direction cannot be represented by GraphDiagram." : "Set Mermaid graph direction in the flowchart or graph header."
|
|
11071
|
+
);
|
|
11072
|
+
continue;
|
|
11073
|
+
}
|
|
11074
|
+
if (/^(?:click|class|classDef|style|linkStyle|accTitle|accDescr)\b/i.test(line)) {
|
|
11075
|
+
addImportDiagnostic(diagnostics, sourceLines, lineNumber, "import.unsupported_semantics", "error", "Mermaid classes, styling, accessibility directives, and click actions are not imported.");
|
|
11076
|
+
continue;
|
|
11077
|
+
}
|
|
11078
|
+
parseNodeOrEdgeLine(line, currentGroup, lineNumber, sourceLines, state, diagnostics);
|
|
11079
|
+
}
|
|
11080
|
+
if (!sawHeader) {
|
|
11081
|
+
addImportDiagnostic(diagnostics, sourceLines, 1, "import.parse_error", "error", "Missing Mermaid flowchart or graph header.");
|
|
11082
|
+
}
|
|
11083
|
+
if (currentGroup) {
|
|
11084
|
+
addImportDiagnostic(diagnostics, sourceLines, sourceLines.length, "import.parse_error", "error", `Mermaid subgraph "${currentGroup}" has no matching end.`);
|
|
11085
|
+
}
|
|
11086
|
+
for (const reference of state.edgeReferences) {
|
|
11087
|
+
if (state.groupIds.has(reference.id)) {
|
|
11088
|
+
addImportDiagnostic(
|
|
11089
|
+
diagnostics,
|
|
11090
|
+
sourceLines,
|
|
11091
|
+
reference.line,
|
|
11092
|
+
"import.unsupported_semantics",
|
|
11093
|
+
"error",
|
|
11094
|
+
`Mermaid edges to or from subgraph "${reference.id}" cannot be represented as GraphDiagram node edges.`
|
|
11095
|
+
);
|
|
11096
|
+
}
|
|
11097
|
+
}
|
|
11098
|
+
const graph = {
|
|
11099
|
+
nodes: state.nodes,
|
|
11100
|
+
edges: state.edges,
|
|
11101
|
+
groups: state.groups,
|
|
11102
|
+
direction
|
|
11103
|
+
};
|
|
11104
|
+
return graphImportResult("mermaid", graph, diagnostics);
|
|
11105
|
+
}
|
|
11106
|
+
|
|
11107
|
+
// src/import-d2.ts
|
|
11108
|
+
function decodeD2Label(raw) {
|
|
11109
|
+
const value = raw.trim();
|
|
11110
|
+
if (value.startsWith('"')) {
|
|
11111
|
+
if (!value.endsWith('"')) return void 0;
|
|
11112
|
+
try {
|
|
11113
|
+
const decoded = JSON.parse(value);
|
|
11114
|
+
return typeof decoded === "string" ? decoded : void 0;
|
|
11115
|
+
} catch {
|
|
11116
|
+
return void 0;
|
|
11117
|
+
}
|
|
11118
|
+
}
|
|
11119
|
+
if (value.startsWith("'")) {
|
|
11120
|
+
if (!value.endsWith("'")) return void 0;
|
|
11121
|
+
return value.slice(1, -1).replace(/\\(['\\])/g, "$1");
|
|
11122
|
+
}
|
|
11123
|
+
return value;
|
|
11124
|
+
}
|
|
11125
|
+
function hasMarkdownFormatting(label) {
|
|
11126
|
+
return /<[^>]*>|`|\*\*|__|~~|(^|\s)\*[^*]|\b_[^_]+_\b|\[[^\]]+\]\(|(^|\n)\s{0,3}(?:#{1,6}\s|[-*+]\s|\d+\.\s)/.test(label);
|
|
11127
|
+
}
|
|
11128
|
+
function hasUnquotedHash(line) {
|
|
11129
|
+
let quote;
|
|
11130
|
+
let escaped = false;
|
|
11131
|
+
for (const character of line) {
|
|
11132
|
+
if (quote) {
|
|
11133
|
+
if (escaped) escaped = false;
|
|
11134
|
+
else if (character === "\\") escaped = true;
|
|
11135
|
+
else if (character === quote) quote = void 0;
|
|
11136
|
+
continue;
|
|
11137
|
+
}
|
|
11138
|
+
if (character === '"' || character === "'") quote = character;
|
|
11139
|
+
else if (character === "#") return true;
|
|
11140
|
+
}
|
|
11141
|
+
return false;
|
|
11142
|
+
}
|
|
11143
|
+
function addNode2(nodes, id, label, line, sourceLines, diagnostics, explicitLabel) {
|
|
11144
|
+
if (hasMarkdownFormatting(label)) {
|
|
11145
|
+
addImportDiagnostic(
|
|
11146
|
+
diagnostics,
|
|
11147
|
+
sourceLines,
|
|
11148
|
+
line,
|
|
11149
|
+
"import.unsupported_semantics",
|
|
11150
|
+
"error",
|
|
11151
|
+
`D2 label for "${id}" uses Markdown or HTML formatting that GraphDiagram cannot preserve.`
|
|
11152
|
+
);
|
|
11153
|
+
return false;
|
|
11154
|
+
}
|
|
11155
|
+
const existing = nodes.get(id);
|
|
11156
|
+
if (existing) {
|
|
11157
|
+
if (explicitLabel) {
|
|
11158
|
+
existing.node.label = label;
|
|
11159
|
+
}
|
|
11160
|
+
} else {
|
|
11161
|
+
nodes.set(id, { node: { id, label } });
|
|
11162
|
+
}
|
|
11163
|
+
return true;
|
|
11164
|
+
}
|
|
11165
|
+
function reportUnsupported(diagnostics, sourceLines, line, message, code = "import.unsupported_syntax", column = 1) {
|
|
11166
|
+
addImportDiagnostic(diagnostics, sourceLines, line, code, "error", message, column);
|
|
11167
|
+
}
|
|
11168
|
+
function importD2Graph(source) {
|
|
11169
|
+
const sourceLines = source.split(/\r?\n/);
|
|
11170
|
+
const diagnostics = [];
|
|
11171
|
+
const nodesById = /* @__PURE__ */ new Map();
|
|
11172
|
+
const edges = [];
|
|
11173
|
+
const shapes = /* @__PURE__ */ new Map();
|
|
11174
|
+
let direction = "TB";
|
|
11175
|
+
let containerDepth = 0;
|
|
11176
|
+
for (let index = 0; index < sourceLines.length; index++) {
|
|
11177
|
+
const lineNumber = index + 1;
|
|
11178
|
+
const rawLine = sourceLines[index] ?? "";
|
|
11179
|
+
const line = rawLine.trim();
|
|
11180
|
+
if (!line) continue;
|
|
11181
|
+
if (containerDepth > 0) {
|
|
11182
|
+
const opens = (rawLine.match(/\{/g) ?? []).length;
|
|
11183
|
+
const closes = (rawLine.match(/\}/g) ?? []).length;
|
|
11184
|
+
containerDepth = Math.max(0, containerDepth + opens - closes);
|
|
11185
|
+
continue;
|
|
11186
|
+
}
|
|
11187
|
+
if (line.startsWith("#")) continue;
|
|
11188
|
+
if (hasUnquotedHash(line)) {
|
|
11189
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, "D2 inline comments and unquoted # text are not supported; use a comment line or quote the label.");
|
|
11190
|
+
continue;
|
|
11191
|
+
}
|
|
11192
|
+
if (line.includes(";")) {
|
|
11193
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, "D2 semicolon-separated statements are not supported; place one statement on each line.");
|
|
11194
|
+
continue;
|
|
11195
|
+
}
|
|
11196
|
+
if (line.includes("{") || line.includes("}")) {
|
|
11197
|
+
reportUnsupported(
|
|
11198
|
+
diagnostics,
|
|
11199
|
+
sourceLines,
|
|
11200
|
+
lineNumber,
|
|
11201
|
+
"D2 containers and object-property blocks are not imported. Their contents are skipped to avoid treating nested shapes as top-level nodes.",
|
|
11202
|
+
"import.unsupported_semantics"
|
|
11203
|
+
);
|
|
11204
|
+
const opens = (rawLine.match(/\{/g) ?? []).length;
|
|
11205
|
+
const closes = (rawLine.match(/\}/g) ?? []).length;
|
|
11206
|
+
containerDepth = Math.max(0, opens - closes);
|
|
11207
|
+
continue;
|
|
11208
|
+
}
|
|
11209
|
+
const directionMatch = line.match(/^direction\s*:\s*(right|left|down|up)\s*$/i);
|
|
11210
|
+
if (directionMatch) {
|
|
11211
|
+
const value = directionMatch[1]?.toLowerCase();
|
|
11212
|
+
direction = value === "left" ? "RL" : value === "down" ? "TB" : value === "up" ? "BT" : "LR";
|
|
11213
|
+
continue;
|
|
11214
|
+
}
|
|
11215
|
+
if (/^direction\b/i.test(line)) {
|
|
11216
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, "D2 direction must be right, left, down, or up.", "import.parse_error");
|
|
11217
|
+
continue;
|
|
11218
|
+
}
|
|
11219
|
+
const shapeMatch = line.match(/^([A-Za-z_][A-Za-z0-9_-]*)\.shape\s*:\s*(.*?)\s*$/);
|
|
11220
|
+
if (shapeMatch) {
|
|
11221
|
+
const id = shapeMatch[1];
|
|
11222
|
+
const shape = decodeD2Label(shapeMatch[2] ?? "");
|
|
11223
|
+
if (!id || shape === void 0 || shape === "") {
|
|
11224
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, "D2 shape declaration needs a simple identifier and a shape value.", "import.parse_error");
|
|
11225
|
+
continue;
|
|
11226
|
+
}
|
|
11227
|
+
if (!nodesById.has(id)) addNode2(nodesById, id, id, lineNumber, sourceLines, diagnostics, false);
|
|
11228
|
+
shapes.set(id, { value: shape, line: lineNumber });
|
|
11229
|
+
continue;
|
|
11230
|
+
}
|
|
11231
|
+
const edgeMatch = line.match(/^([A-Za-z_][A-Za-z0-9_-]*?)\s*(<->|->|<-|--)\s*([A-Za-z_][A-Za-z0-9_-]*?)(?:\s*:\s*(.*))?\s*$/);
|
|
11232
|
+
if (edgeMatch) {
|
|
11233
|
+
const from = edgeMatch[1];
|
|
11234
|
+
const connector = edgeMatch[2];
|
|
11235
|
+
const to = edgeMatch[3];
|
|
11236
|
+
const rawLabel = edgeMatch[4];
|
|
11237
|
+
if (!from || !connector || !to) continue;
|
|
11238
|
+
let label;
|
|
11239
|
+
if (rawLabel !== void 0) {
|
|
11240
|
+
label = decodeD2Label(rawLabel);
|
|
11241
|
+
if (label === void 0) {
|
|
11242
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, "D2 connection label has invalid quotes.", "import.parse_error");
|
|
11243
|
+
continue;
|
|
11244
|
+
}
|
|
11245
|
+
if (hasMarkdownFormatting(label)) {
|
|
11246
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, "D2 connection labels with Markdown or HTML formatting cannot be represented as plain GraphDiagram labels.", "import.unsupported_semantics");
|
|
11247
|
+
continue;
|
|
11248
|
+
}
|
|
11249
|
+
}
|
|
11250
|
+
addNode2(nodesById, from, from, lineNumber, sourceLines, diagnostics, false);
|
|
11251
|
+
addNode2(nodesById, to, to, lineNumber, sourceLines, diagnostics, false);
|
|
11252
|
+
edges.push({
|
|
11253
|
+
from,
|
|
11254
|
+
to,
|
|
11255
|
+
...label !== void 0 ? { label } : {},
|
|
11256
|
+
arrow: connector === "<->" ? "both" : connector === "<-" ? "backward" : connector === "--" ? "none" : "forward"
|
|
11257
|
+
});
|
|
11258
|
+
continue;
|
|
11259
|
+
}
|
|
11260
|
+
const nodeMatch = line.match(/^([A-Za-z_][A-Za-z0-9_-]*)(?:\s*:\s*(.*))?$/);
|
|
11261
|
+
if (nodeMatch) {
|
|
11262
|
+
const id = nodeMatch[1];
|
|
11263
|
+
const rawLabel = nodeMatch[2];
|
|
11264
|
+
if (!id) continue;
|
|
11265
|
+
let label = id;
|
|
11266
|
+
let explicitLabel = false;
|
|
11267
|
+
if (rawLabel !== void 0) {
|
|
11268
|
+
const decoded = decodeD2Label(rawLabel);
|
|
11269
|
+
if (decoded === void 0) {
|
|
11270
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, `D2 label for "${id}" has invalid quotes.`, "import.parse_error");
|
|
11271
|
+
continue;
|
|
11272
|
+
}
|
|
11273
|
+
label = decoded;
|
|
11274
|
+
explicitLabel = true;
|
|
11275
|
+
}
|
|
11276
|
+
addNode2(nodesById, id, label, lineNumber, sourceLines, diagnostics, explicitLabel);
|
|
11277
|
+
continue;
|
|
11278
|
+
}
|
|
11279
|
+
if (line.includes(".style") || line.includes(".width") || line.includes(".height") || line.includes(".near")) {
|
|
11280
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, "D2 styling, sizing, and positioning fields are not imported.", "import.unsupported_semantics");
|
|
11281
|
+
} else if (/^[A-Za-z_][A-Za-z0-9_-]*\./.test(line)) {
|
|
11282
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, "D2 dotted paths and shape properties are not supported outside the simple `.shape` declaration.");
|
|
11283
|
+
} else if (/(?:<->|->|<-|--)/.test(line)) {
|
|
11284
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, "Only one D2 connection between two simple identifiers per line is supported; chaining and connection properties are not imported.");
|
|
11285
|
+
} else {
|
|
11286
|
+
reportUnsupported(diagnostics, sourceLines, lineNumber, "Could not parse this D2 statement in the supported subset.", "import.parse_error");
|
|
11287
|
+
}
|
|
11288
|
+
}
|
|
11289
|
+
if (containerDepth > 0) {
|
|
11290
|
+
reportUnsupported(diagnostics, sourceLines, sourceLines.length, "D2 object-property block has no matching closing brace.", "import.parse_error");
|
|
11291
|
+
}
|
|
11292
|
+
for (const [id, { value, line }] of shapes) {
|
|
11293
|
+
if (value.toLowerCase() === "rectangle") continue;
|
|
11294
|
+
addImportDiagnostic(
|
|
11295
|
+
diagnostics,
|
|
11296
|
+
sourceLines,
|
|
11297
|
+
line,
|
|
11298
|
+
"import.lossy_semantics",
|
|
11299
|
+
"warning",
|
|
11300
|
+
`D2 shape "${value}" on "${id}" is reduced to a generic GraphDiagram node.`
|
|
11301
|
+
);
|
|
11302
|
+
}
|
|
11303
|
+
return graphImportResult("d2", {
|
|
11304
|
+
nodes: [...nodesById.values()].map(({ node }) => node),
|
|
11305
|
+
edges,
|
|
11306
|
+
groups: [],
|
|
11307
|
+
direction
|
|
11308
|
+
}, diagnostics);
|
|
11309
|
+
}
|
|
11310
|
+
|
|
11311
|
+
// src/check.ts
|
|
11312
|
+
var import_promises3 = require("fs/promises");
|
|
11313
|
+
var import_async_hooks2 = require("async_hooks");
|
|
11314
|
+
var import_os2 = require("os");
|
|
11315
|
+
var import_path3 = require("path");
|
|
11316
|
+
|
|
11317
|
+
// src/diagnostics.ts
|
|
11318
|
+
var import_parse_css_color3 = __toESM(require("parse-css-color"), 1);
|
|
11319
|
+
var import_react16 = require("react");
|
|
11320
|
+
var CHECK_DIAGNOSTIC_CODES = [
|
|
11321
|
+
"accessibility.low_contrast",
|
|
11322
|
+
"api.unsupported_prop",
|
|
11323
|
+
"asset.warning",
|
|
11324
|
+
"frame.load_error",
|
|
11325
|
+
"frame.unknown_preset",
|
|
11326
|
+
"layout.auto_size",
|
|
11327
|
+
"layout.connector_congestion",
|
|
11328
|
+
"layout.connector_unroutable",
|
|
11329
|
+
"layout.overflow",
|
|
11330
|
+
"layout.text_overlap",
|
|
11331
|
+
"layout.whitespace_imbalance",
|
|
11332
|
+
"readability.small_text",
|
|
11333
|
+
"render.error",
|
|
11334
|
+
"render.warning",
|
|
11335
|
+
"style.unsupported"
|
|
11336
|
+
];
|
|
11337
|
+
var MAX_CONTRAST_NODES = 5e3;
|
|
11338
|
+
var MAX_DIAGNOSTICS_PER_RULE = 12;
|
|
11339
|
+
var MIN_TEXT_SIZE = 11;
|
|
11340
|
+
function hslToRgb2(hue, saturation, lightness) {
|
|
11341
|
+
const h = (hue % 360 + 360) % 360;
|
|
11342
|
+
const s = saturation / 100;
|
|
11343
|
+
const l = lightness / 100;
|
|
11344
|
+
const chroma = (1 - Math.abs(2 * l - 1)) * s;
|
|
11345
|
+
const segment = h / 60;
|
|
11346
|
+
const intermediate = chroma * (1 - Math.abs(segment % 2 - 1));
|
|
11347
|
+
let channels;
|
|
11348
|
+
if (segment < 1) channels = [chroma, intermediate, 0];
|
|
11349
|
+
else if (segment < 2) channels = [intermediate, chroma, 0];
|
|
11350
|
+
else if (segment < 3) channels = [0, chroma, intermediate];
|
|
11351
|
+
else if (segment < 4) channels = [0, intermediate, chroma];
|
|
11352
|
+
else if (segment < 5) channels = [intermediate, 0, chroma];
|
|
11353
|
+
else channels = [chroma, 0, intermediate];
|
|
11354
|
+
const offset = l - chroma / 2;
|
|
11355
|
+
return channels.map((channel) => Math.round((channel + offset) * 255));
|
|
11356
|
+
}
|
|
11357
|
+
function colorFromCss(value) {
|
|
11358
|
+
if (typeof value !== "string") return void 0;
|
|
11359
|
+
const parsed = (0, import_parse_css_color3.default)(value);
|
|
11360
|
+
if (!parsed || parsed.values.length < 3) return void 0;
|
|
11361
|
+
const [r, g, b] = parsed.type === "hsl" ? hslToRgb2(parsed.values[0] ?? 0, parsed.values[1] ?? 0, parsed.values[2] ?? 0) : [parsed.values[0] ?? 0, parsed.values[1] ?? 0, parsed.values[2] ?? 0];
|
|
11362
|
+
return {
|
|
11363
|
+
r,
|
|
11364
|
+
g,
|
|
11365
|
+
b,
|
|
11366
|
+
alpha: parsed.alpha
|
|
11367
|
+
};
|
|
11368
|
+
}
|
|
11369
|
+
function compositeOver(foreground, background) {
|
|
11370
|
+
if (foreground.alpha >= 1 || !background) return foreground;
|
|
11371
|
+
const alpha = foreground.alpha + background.alpha * (1 - foreground.alpha);
|
|
11372
|
+
if (alpha <= 0) return { r: 0, g: 0, b: 0, alpha: 0 };
|
|
11373
|
+
return {
|
|
11374
|
+
r: (foreground.r * foreground.alpha + background.r * background.alpha * (1 - foreground.alpha)) / alpha,
|
|
11375
|
+
g: (foreground.g * foreground.alpha + background.g * background.alpha * (1 - foreground.alpha)) / alpha,
|
|
11376
|
+
b: (foreground.b * foreground.alpha + background.b * background.alpha * (1 - foreground.alpha)) / alpha,
|
|
11377
|
+
alpha
|
|
11378
|
+
};
|
|
11379
|
+
}
|
|
11380
|
+
function isUnresolvedColor(value) {
|
|
11381
|
+
if (typeof value !== "string" || value.trim() === "" || colorFromCss(value)) return false;
|
|
11382
|
+
return !["inherit", "initial", "revert", "unset"].includes(value.trim().toLowerCase());
|
|
11383
|
+
}
|
|
11384
|
+
function channelLuminance(value) {
|
|
11385
|
+
const normalized = value / 255;
|
|
11386
|
+
return normalized <= 0.04045 ? normalized / 12.92 : ((normalized + 0.055) / 1.055) ** 2.4;
|
|
11387
|
+
}
|
|
11388
|
+
function relativeLuminance(color) {
|
|
11389
|
+
return 0.2126 * channelLuminance(color.r) + 0.7152 * channelLuminance(color.g) + 0.0722 * channelLuminance(color.b);
|
|
11390
|
+
}
|
|
11391
|
+
function contrastRatio(foreground, background) {
|
|
11392
|
+
const lighter = Math.max(relativeLuminance(foreground), relativeLuminance(background));
|
|
11393
|
+
const darker = Math.min(relativeLuminance(foreground), relativeLuminance(background));
|
|
11394
|
+
return (lighter + 0.05) / (darker + 0.05);
|
|
11395
|
+
}
|
|
11396
|
+
function numericFontWeight(value) {
|
|
11397
|
+
if (typeof value === "number") return value;
|
|
11398
|
+
if (value === "bold") return 700;
|
|
11399
|
+
if (typeof value === "string" && /^\d+$/.test(value)) return Number(value);
|
|
11400
|
+
return void 0;
|
|
11401
|
+
}
|
|
11402
|
+
function fontSizePixels(value, inherited) {
|
|
11403
|
+
if (typeof value === "number") return value;
|
|
11404
|
+
if (typeof value !== "string") return inherited;
|
|
11405
|
+
const match = value.trim().match(/^(\d+(?:\.\d+)?|\.\d+)(px|pt|rem|em|%)?$/);
|
|
11406
|
+
if (!match?.[1]) return inherited;
|
|
11407
|
+
const amount = Number(match[1]);
|
|
11408
|
+
const unit = match[2] ?? "px";
|
|
11409
|
+
if (unit === "pt") return amount * 4 / 3;
|
|
11410
|
+
if (unit === "rem") return amount * 16;
|
|
11411
|
+
if (unit === "em") return amount * (inherited ?? 16);
|
|
11412
|
+
if (unit === "%") return amount / 100 * (inherited ?? 16);
|
|
11413
|
+
return amount;
|
|
11414
|
+
}
|
|
11415
|
+
function requiredContrast(context) {
|
|
11416
|
+
const large = (context.fontSize ?? 16) >= 24 || (context.fontSize ?? 16) >= 18.66 && (context.fontWeight ?? 400) >= 700;
|
|
11417
|
+
return large ? 3 : 4.5;
|
|
11418
|
+
}
|
|
11419
|
+
function styleRecord(value) {
|
|
11420
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
11421
|
+
return value;
|
|
11422
|
+
}
|
|
11423
|
+
function hasDirectText(children) {
|
|
11424
|
+
return import_react16.Children.toArray(children).some((child) => typeof child === "string" || typeof child === "number");
|
|
11425
|
+
}
|
|
11426
|
+
function elementId(props) {
|
|
11427
|
+
const value = props.id ?? props["data-vizmatic-id"];
|
|
11428
|
+
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
11429
|
+
}
|
|
11430
|
+
function resolveFunctionComponent(node, trustedComponents) {
|
|
11431
|
+
if (!(0, import_react16.isValidElement)(node) || typeof node.type !== "function" || trustedComponents.has(node.type)) return void 0;
|
|
11432
|
+
const component = node.type;
|
|
11433
|
+
if (component.__vizmaticPrimitive) return void 0;
|
|
11434
|
+
if (component.prototype?.isReactComponent) return void 0;
|
|
11435
|
+
try {
|
|
11436
|
+
return component(node.props);
|
|
11437
|
+
} catch {
|
|
11438
|
+
return void 0;
|
|
11439
|
+
}
|
|
11440
|
+
}
|
|
11441
|
+
function analyzeContrast(element, theme, trustedComponents = /* @__PURE__ */ new Set(), rootBackground2) {
|
|
11442
|
+
const diagnostics = [];
|
|
11443
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11444
|
+
let visited = 0;
|
|
11445
|
+
function visit(node, inherited, path) {
|
|
11446
|
+
if (visited++ >= MAX_CONTRAST_NODES || !(0, import_react16.isValidElement)(node)) return;
|
|
11447
|
+
const resolved = resolveFunctionComponent(node, trustedComponents);
|
|
11448
|
+
if (resolved !== void 0) {
|
|
11449
|
+
visit(resolved, inherited, path);
|
|
11450
|
+
return;
|
|
11451
|
+
}
|
|
11452
|
+
const props = node.props;
|
|
11453
|
+
const style = typeof node.type === "string" ? styleRecord(props.style) : {};
|
|
11454
|
+
const backgroundImage = typeof style.backgroundImage === "string" ? style.backgroundImage.trim().toLowerCase() : "";
|
|
11455
|
+
const backgroundShorthand = typeof style.background === "string" ? style.background.trim() : "";
|
|
11456
|
+
const isBackgroundWrapper = typeof node.type === "function" && (trustedComponents.has(node.type) || Boolean(node.type.__vizmaticPrimitive));
|
|
11457
|
+
const wrapperBackground = isBackgroundWrapper ? props.background : void 0;
|
|
11458
|
+
const hasUnresolvedBackground = backgroundImage !== "" && backgroundImage !== "none" || isUnresolvedColor(style.backgroundColor) || backgroundShorthand !== "" && backgroundShorthand.toLowerCase() !== "none" && !colorFromCss(backgroundShorthand) || isUnresolvedColor(wrapperBackground);
|
|
11459
|
+
const ownBackground = colorFromCss(style.backgroundColor) ?? colorFromCss(style.background) ?? colorFromCss(wrapperBackground);
|
|
11460
|
+
const baseBackground = path === "root" && isBackgroundWrapper && colorFromCss(wrapperBackground) ? void 0 : inherited.background;
|
|
11461
|
+
const background = hasUnresolvedBackground ? void 0 : ownBackground ? compositeOver(ownBackground, baseBackground) : baseBackground;
|
|
11462
|
+
const color = typeof style.color === "string" && style.color.trim().toLowerCase() === "currentcolor" ? inherited.color : isUnresolvedColor(style.color) ? void 0 : colorFromCss(style.color) ?? inherited.color;
|
|
11463
|
+
const fontSize = fontSizePixels(style.fontSize, inherited.fontSize);
|
|
11464
|
+
const fontWeight = numericFontWeight(style.fontWeight) ?? inherited.fontWeight;
|
|
11465
|
+
const context = { background, color, fontSize, fontWeight };
|
|
11466
|
+
if (typeof node.type === "string" && hasDirectText(props.children) && color && background !== void 0 && background.alpha >= 1) {
|
|
11467
|
+
const renderedColor = compositeOver(color, background);
|
|
11468
|
+
const ratio = contrastRatio(renderedColor, background);
|
|
11469
|
+
const required = requiredContrast(context);
|
|
11470
|
+
if (ratio < required) {
|
|
11471
|
+
const rounded = Math.round(ratio * 100) / 100;
|
|
11472
|
+
const key = `${rounded}:${required}:${path}`;
|
|
11473
|
+
if (!seen.has(key)) {
|
|
11474
|
+
seen.add(key);
|
|
11475
|
+
diagnostics.push({
|
|
11476
|
+
code: "accessibility.low_contrast",
|
|
11477
|
+
severity: "warning",
|
|
11478
|
+
theme,
|
|
11479
|
+
message: `Text contrast is ${rounded}:1 at ${path}; ${required}:1 is recommended.`,
|
|
11480
|
+
suggestion: "Use a stronger text or background color token.",
|
|
11481
|
+
elementId: elementId(props),
|
|
11482
|
+
location: { path }
|
|
11483
|
+
});
|
|
11484
|
+
}
|
|
11485
|
+
}
|
|
11486
|
+
}
|
|
11487
|
+
import_react16.Children.forEach(props.children, (child, index) => visit(child, context, `${path}.${index}`));
|
|
11488
|
+
}
|
|
11489
|
+
visit(element, { background: colorFromCss(rootBackground2) }, "root");
|
|
11490
|
+
return diagnostics;
|
|
11491
|
+
}
|
|
11492
|
+
function containsLayoutNode(parent, child) {
|
|
11493
|
+
const epsilon = 0.5;
|
|
11494
|
+
return child.left >= parent.left - epsilon && child.top >= parent.top - epsilon && child.left + child.width <= parent.left + parent.width + epsilon && child.top + child.height <= parent.top + parent.height + epsilon;
|
|
11495
|
+
}
|
|
11496
|
+
function textUnits(text) {
|
|
11497
|
+
return Array.from(text.normalize("NFC")).reduce((sum, character) => sum + ((character.codePointAt(0) ?? 0) > 255 ? 1.7 : 1), 0);
|
|
11498
|
+
}
|
|
11499
|
+
function renderedTextNodes(nodes) {
|
|
11500
|
+
const textNodes = [];
|
|
11501
|
+
const ancestors = [];
|
|
11502
|
+
for (const node of nodes) {
|
|
11503
|
+
while (ancestors.length > 0 && !containsLayoutNode(ancestors[ancestors.length - 1].node, node)) {
|
|
11504
|
+
ancestors.pop();
|
|
11505
|
+
}
|
|
11506
|
+
const inherited = ancestors[ancestors.length - 1];
|
|
11507
|
+
const style = styleRecord(node.props.style);
|
|
11508
|
+
const fontSize = fontSizePixels(style.fontSize, inherited?.fontSize) ?? 16;
|
|
11509
|
+
const textAlign = typeof style.textAlign === "string" ? style.textAlign : inherited?.textAlign ?? "left";
|
|
11510
|
+
const text = node.textContent?.trim();
|
|
11511
|
+
if (text && node.width > 0 && node.height > 0) {
|
|
11512
|
+
const estimatedLines = Math.max(1, Math.round(node.height / Math.max(fontSize * 1.5, 1)));
|
|
11513
|
+
const paintHeight = Math.min(
|
|
11514
|
+
node.height,
|
|
11515
|
+
fontSize * 0.9 + (estimatedLines - 1) * fontSize * 1.25
|
|
11516
|
+
);
|
|
11517
|
+
const unwrappedWidth = textUnits(text) * fontSize * 0.56;
|
|
11518
|
+
const paintWidth = Math.min(node.width, unwrappedWidth);
|
|
11519
|
+
const horizontalInset = textAlign === "center" ? (node.width - paintWidth) / 2 : textAlign === "right" || textAlign === "end" ? node.width - paintWidth : 0;
|
|
11520
|
+
textNodes.push({
|
|
11521
|
+
text,
|
|
11522
|
+
elementId: elementId(node.props),
|
|
11523
|
+
left: node.left,
|
|
11524
|
+
top: node.top,
|
|
11525
|
+
width: node.width,
|
|
11526
|
+
height: node.height,
|
|
11527
|
+
paintLeft: node.left + horizontalInset,
|
|
11528
|
+
paintTop: node.top + (node.height - paintHeight) / 2,
|
|
11529
|
+
paintWidth,
|
|
11530
|
+
paintHeight,
|
|
11531
|
+
fontSize
|
|
11532
|
+
});
|
|
11533
|
+
} else if (node.width > 0 && node.height > 0) {
|
|
11534
|
+
ancestors.push({ node, fontSize, textAlign });
|
|
11535
|
+
}
|
|
11536
|
+
}
|
|
11537
|
+
return textNodes;
|
|
11538
|
+
}
|
|
11539
|
+
function textExcerpt(text) {
|
|
11540
|
+
const normalized = text.replace(/\s+/g, " ").trim();
|
|
11541
|
+
return normalized.length > 40 ? `${normalized.slice(0, 37)}...` : normalized;
|
|
11542
|
+
}
|
|
11543
|
+
function meaningfulOverlap(a, b) {
|
|
11544
|
+
const width = Math.min(a.paintLeft + a.paintWidth, b.paintLeft + b.paintWidth) - Math.max(a.paintLeft, b.paintLeft);
|
|
11545
|
+
const height = Math.min(a.paintTop + a.paintHeight, b.paintTop + b.paintHeight) - Math.max(a.paintTop, b.paintTop);
|
|
11546
|
+
if (width < 2 || height < 2) return false;
|
|
11547
|
+
if (a.text === b.text && a.left === b.left && a.top === b.top && a.width === b.width && a.height === b.height) return false;
|
|
11548
|
+
const overlapArea = width * height;
|
|
11549
|
+
const smallerArea = Math.min(a.paintWidth * a.paintHeight, b.paintWidth * b.paintHeight);
|
|
11550
|
+
return overlapArea / smallerArea >= 0.08;
|
|
11551
|
+
}
|
|
11552
|
+
function overlapCandidates(nodes) {
|
|
11553
|
+
const cellSize = 96;
|
|
11554
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
11555
|
+
const pairs = [];
|
|
11556
|
+
for (let index = 0; index < nodes.length && pairs.length < MAX_DIAGNOSTICS_PER_RULE; index += 1) {
|
|
11557
|
+
const node = nodes[index];
|
|
11558
|
+
const minX = Math.floor(node.paintLeft / cellSize);
|
|
11559
|
+
const maxX = Math.floor((node.paintLeft + node.paintWidth) / cellSize);
|
|
11560
|
+
const minY = Math.floor(node.paintTop / cellSize);
|
|
11561
|
+
const maxY = Math.floor((node.paintTop + node.paintHeight) / cellSize);
|
|
11562
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
11563
|
+
for (let x = minX; x <= maxX; x += 1) {
|
|
11564
|
+
for (let y = minY; y <= maxY; y += 1) {
|
|
11565
|
+
const bucket = buckets.get(`${x}:${y}`);
|
|
11566
|
+
bucket?.forEach((candidate) => candidates.add(candidate));
|
|
11567
|
+
}
|
|
11568
|
+
}
|
|
11569
|
+
for (const candidate of candidates) {
|
|
11570
|
+
if (meaningfulOverlap(nodes[candidate], node)) pairs.push([nodes[candidate], node]);
|
|
11571
|
+
if (pairs.length >= MAX_DIAGNOSTICS_PER_RULE) break;
|
|
11572
|
+
}
|
|
11573
|
+
for (let x = minX; x <= maxX; x += 1) {
|
|
11574
|
+
for (let y = minY; y <= maxY; y += 1) {
|
|
11575
|
+
const key = `${x}:${y}`;
|
|
11576
|
+
const bucket = buckets.get(key) ?? [];
|
|
11577
|
+
bucket.push(index);
|
|
11578
|
+
buckets.set(key, bucket);
|
|
11579
|
+
}
|
|
11580
|
+
}
|
|
11581
|
+
}
|
|
11582
|
+
return pairs;
|
|
11583
|
+
}
|
|
11584
|
+
function analyzeRenderedLayout(nodes, theme) {
|
|
11585
|
+
const diagnostics = [];
|
|
11586
|
+
const textNodes = renderedTextNodes(nodes);
|
|
11587
|
+
const seenSmallText = /* @__PURE__ */ new Set();
|
|
11588
|
+
let smallTextCount = 0;
|
|
11589
|
+
for (const node of textNodes) {
|
|
11590
|
+
if (node.fontSize >= MIN_TEXT_SIZE) continue;
|
|
11591
|
+
const excerpt = textExcerpt(node.text);
|
|
11592
|
+
const key = `${excerpt}:${node.fontSize}`;
|
|
11593
|
+
if (seenSmallText.has(key)) continue;
|
|
11594
|
+
seenSmallText.add(key);
|
|
11595
|
+
diagnostics.push({
|
|
11596
|
+
code: "readability.small_text",
|
|
11597
|
+
severity: "warning",
|
|
11598
|
+
theme,
|
|
11599
|
+
message: `Text "${excerpt}" renders at ${node.fontSize}px.`,
|
|
11600
|
+
suggestion: `Use at least ${MIN_TEXT_SIZE}px for details that must remain readable when embedded.`,
|
|
11601
|
+
elementId: node.elementId,
|
|
11602
|
+
location: { x: node.left, y: node.top, width: node.width, height: node.height }
|
|
11603
|
+
});
|
|
11604
|
+
smallTextCount += 1;
|
|
11605
|
+
if (smallTextCount >= MAX_DIAGNOSTICS_PER_RULE) break;
|
|
11606
|
+
}
|
|
11607
|
+
for (const [left, right] of overlapCandidates(textNodes)) {
|
|
11608
|
+
diagnostics.push({
|
|
11609
|
+
code: "layout.text_overlap",
|
|
11610
|
+
severity: "warning",
|
|
11611
|
+
theme,
|
|
11612
|
+
message: `Text "${textExcerpt(left.text)}" overlaps "${textExcerpt(right.text)}".`,
|
|
11613
|
+
suggestion: "Increase spacing or canvas size, shorten labels, or move one label.",
|
|
11614
|
+
elementId: left.elementId,
|
|
11615
|
+
relatedElementIds: right.elementId ? [right.elementId] : void 0,
|
|
11616
|
+
location: { x: left.left, y: left.top, width: left.width, height: left.height }
|
|
11617
|
+
});
|
|
11618
|
+
}
|
|
11619
|
+
const maxDataNumber = (attribute2) => Math.max(0, ...nodes.map((node) => {
|
|
11620
|
+
const value = node.props[attribute2];
|
|
11621
|
+
return typeof value === "number" ? value : Number(value) || 0;
|
|
11622
|
+
}));
|
|
11623
|
+
for (const source of nodes.filter((node) => Number(node.props["data-vizmatic-unrouted-connectors"]) > 0)) {
|
|
11624
|
+
const messages = JSON.parse(String(source.props["data-vizmatic-routing-failures"]));
|
|
11625
|
+
for (const message of messages.slice(0, MAX_DIAGNOSTICS_PER_RULE)) diagnostics.push({
|
|
11626
|
+
code: "layout.connector_unroutable",
|
|
11627
|
+
severity: "error",
|
|
11628
|
+
theme,
|
|
11629
|
+
message,
|
|
11630
|
+
suggestion: "Increase canvas size or spacing, reduce routingClearance, or choose a different endpoint side or port.",
|
|
11631
|
+
elementId: elementId(source.props),
|
|
11632
|
+
location: { x: source.left, y: source.top, width: source.width, height: source.height }
|
|
11633
|
+
});
|
|
11634
|
+
}
|
|
11635
|
+
const connectorCrossings2 = maxDataNumber("data-vizmatic-connector-crossings");
|
|
11636
|
+
if (connectorCrossings2 > 0) {
|
|
11637
|
+
const source = nodes.find((node) => Number(node.props["data-vizmatic-connector-crossings"]) > 0);
|
|
11638
|
+
diagnostics.push({
|
|
11639
|
+
code: "layout.connector_congestion",
|
|
11640
|
+
severity: "warning",
|
|
11641
|
+
theme,
|
|
11642
|
+
message: `${connectorCrossings2} connector crossing${connectorCrossings2 === 1 ? "" : "s"} detected.`,
|
|
11643
|
+
suggestion: "Use automatic layout, change graph direction, or simplify the edge set.",
|
|
11644
|
+
elementId: source ? elementId(source.props) : void 0,
|
|
11645
|
+
location: source ? { x: source.left, y: source.top, width: source.width, height: source.height } : void 0
|
|
11646
|
+
});
|
|
11647
|
+
}
|
|
11648
|
+
const labelCollisions = maxDataNumber("data-vizmatic-connector-label-collisions");
|
|
11649
|
+
if (labelCollisions > 0) {
|
|
11650
|
+
const source = nodes.find((node) => Number(node.props["data-vizmatic-connector-label-collisions"]) > 0);
|
|
11651
|
+
diagnostics.push({
|
|
11652
|
+
code: "layout.connector_congestion",
|
|
11653
|
+
severity: "warning",
|
|
11654
|
+
theme,
|
|
11655
|
+
message: `${labelCollisions} connector label collision${labelCollisions === 1 ? "" : "s"} detected.`,
|
|
11656
|
+
suggestion: "Change graph direction or spacing, shorten edge labels, or remove nonessential labels.",
|
|
11657
|
+
elementId: source ? elementId(source.props) : void 0,
|
|
11658
|
+
location: source ? { x: source.left, y: source.top, width: source.width, height: source.height } : void 0
|
|
11659
|
+
});
|
|
11660
|
+
}
|
|
11661
|
+
const crowdedEndpoints = maxDataNumber("data-vizmatic-crowded-connector-endpoints");
|
|
11662
|
+
if (crowdedEndpoints > 0) {
|
|
11663
|
+
const source = nodes.find((node) => Number(node.props["data-vizmatic-crowded-connector-endpoints"]) > 0);
|
|
11664
|
+
diagnostics.push({
|
|
11665
|
+
code: "layout.connector_congestion",
|
|
11666
|
+
severity: "warning",
|
|
11667
|
+
theme,
|
|
11668
|
+
message: `${crowdedEndpoints} node${crowdedEndpoints === 1 ? "" : "s"} connect more than four edges.`,
|
|
11669
|
+
suggestion: "Group related branches, add an intermediate hub, or change graph direction.",
|
|
11670
|
+
elementId: source ? elementId(source.props) : void 0,
|
|
11671
|
+
location: source ? { x: source.left, y: source.top, width: source.width, height: source.height } : void 0
|
|
11672
|
+
});
|
|
11673
|
+
}
|
|
11674
|
+
const parallelGroups = maxDataNumber("data-vizmatic-parallel-connector-groups");
|
|
11675
|
+
if (parallelGroups > 0) {
|
|
11676
|
+
const source = nodes.find((node) => Number(node.props["data-vizmatic-parallel-connector-groups"]) > 0);
|
|
11677
|
+
diagnostics.push({
|
|
11678
|
+
code: "layout.connector_congestion",
|
|
11679
|
+
severity: "warning",
|
|
11680
|
+
theme,
|
|
11681
|
+
message: `${parallelGroups} connector route${parallelGroups === 1 ? "" : "s"} contain parallel edges.`,
|
|
11682
|
+
suggestion: "Merge duplicate relationships, label one combined edge, or separate the routes.",
|
|
11683
|
+
elementId: source ? elementId(source.props) : void 0,
|
|
11684
|
+
location: source ? { x: source.left, y: source.top, width: source.width, height: source.height } : void 0
|
|
11685
|
+
});
|
|
11686
|
+
}
|
|
11687
|
+
let whitespaceCount = 0;
|
|
11688
|
+
for (const container of nodes.filter((node) => node.props["data-vizmatic-layout-container"] === "panel")) {
|
|
11689
|
+
const contentNodes = nodes.filter(
|
|
11690
|
+
(node) => node.props["data-vizmatic-layout-content"] === "panel" && node.width > 0 && node.height > 0 && node.left >= container.left && node.top >= container.top && node.left + node.width <= container.left + container.width && node.top + node.height <= container.top + container.height
|
|
11691
|
+
);
|
|
11692
|
+
if (contentNodes.length === 0) continue;
|
|
11693
|
+
const contentTop = Math.min(...contentNodes.map((node) => node.top));
|
|
11694
|
+
const contentBottom = Math.max(...contentNodes.map((node) => node.top + node.height));
|
|
11695
|
+
const topGutter = contentTop - container.top;
|
|
11696
|
+
const bottomGutter = container.top + container.height - contentBottom;
|
|
11697
|
+
const difference = Math.abs(bottomGutter - topGutter);
|
|
11698
|
+
if (difference <= 48 || difference / container.height <= 0.18) continue;
|
|
11699
|
+
const largerSide = bottomGutter > topGutter ? "below" : "above";
|
|
11700
|
+
const smallerSide = largerSide === "below" ? "above" : "below";
|
|
11701
|
+
diagnostics.push({
|
|
11702
|
+
code: "layout.whitespace_imbalance",
|
|
11703
|
+
severity: "warning",
|
|
11704
|
+
theme,
|
|
11705
|
+
message: `Panel has ${Math.round(difference)}px more whitespace ${largerSide} its content than ${smallerSide} it.`,
|
|
11706
|
+
suggestion: "Reduce the panel height, distribute its contents, or avoid stretching it beside taller content.",
|
|
11707
|
+
elementId: elementId(container.props),
|
|
11708
|
+
location: { x: container.left, y: container.top, width: container.width, height: container.height }
|
|
11709
|
+
});
|
|
11710
|
+
whitespaceCount += 1;
|
|
11711
|
+
if (whitespaceCount >= MAX_DIAGNOSTICS_PER_RULE) break;
|
|
11712
|
+
}
|
|
11713
|
+
return diagnostics;
|
|
11714
|
+
}
|
|
11715
|
+
function analyzeWhitespaceBalance(bounds, width, height, theme) {
|
|
11716
|
+
const gutters = {
|
|
11717
|
+
left: bounds.x,
|
|
11718
|
+
right: width - bounds.x - bounds.width,
|
|
11719
|
+
top: bounds.y,
|
|
11720
|
+
bottom: height - bounds.y - bounds.height
|
|
11721
|
+
};
|
|
11722
|
+
const diagnostics = [];
|
|
11723
|
+
const horizontalDifference = Math.abs(gutters.left - gutters.right);
|
|
11724
|
+
const verticalDifference = Math.abs(gutters.top - gutters.bottom);
|
|
11725
|
+
if (horizontalDifference > 48 && horizontalDifference / width > 0.12) {
|
|
11726
|
+
diagnostics.push({
|
|
11727
|
+
code: "layout.whitespace_imbalance",
|
|
11728
|
+
severity: "warning",
|
|
11729
|
+
theme,
|
|
11730
|
+
message: `Horizontal gutters differ by ${Math.round(horizontalDifference)}px (${Math.round(gutters.left)}px left, ${Math.round(gutters.right)}px right).`,
|
|
11731
|
+
suggestion: "Recenter the composition, crop the canvas, or use the open space intentionally.",
|
|
11732
|
+
location: { x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height }
|
|
11733
|
+
});
|
|
11734
|
+
}
|
|
11735
|
+
if (verticalDifference > 48 && verticalDifference / height > 0.12) {
|
|
11736
|
+
diagnostics.push({
|
|
11737
|
+
code: "layout.whitespace_imbalance",
|
|
11738
|
+
severity: "warning",
|
|
11739
|
+
theme,
|
|
11740
|
+
message: `Vertical gutters differ by ${Math.round(verticalDifference)}px (${Math.round(gutters.top)}px top, ${Math.round(gutters.bottom)}px bottom).`,
|
|
11741
|
+
suggestion: "Recenter the composition, crop the canvas, or use the open space intentionally.",
|
|
11742
|
+
location: { x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height }
|
|
11743
|
+
});
|
|
11744
|
+
}
|
|
11745
|
+
return diagnostics;
|
|
11746
|
+
}
|
|
11747
|
+
function diagnosticFromMessage(message, severity, theme) {
|
|
11748
|
+
if (/unknown preset/i.test(message)) {
|
|
11749
|
+
return {
|
|
11750
|
+
code: "frame.unknown_preset",
|
|
11751
|
+
severity,
|
|
11752
|
+
theme,
|
|
11753
|
+
message,
|
|
11754
|
+
suggestion: 'Use "default" or "engineering".'
|
|
11755
|
+
};
|
|
11756
|
+
}
|
|
11757
|
+
if (/unsupported prop|unknown prop|does not recognize (?:the )?.* prop/i.test(message)) {
|
|
11758
|
+
return {
|
|
11759
|
+
code: "api.unsupported_prop",
|
|
11760
|
+
severity,
|
|
11761
|
+
theme,
|
|
11762
|
+
message,
|
|
11763
|
+
suggestion: "Remove the prop or use one documented for this Vizmatic primitive."
|
|
11764
|
+
};
|
|
11765
|
+
}
|
|
11766
|
+
if (/invalid value for css property|unsupported (?:css|style)|not supported.*css/i.test(message)) {
|
|
11767
|
+
return {
|
|
11768
|
+
code: "style.unsupported",
|
|
11769
|
+
severity,
|
|
11770
|
+
theme,
|
|
11771
|
+
message,
|
|
11772
|
+
suggestion: "Use CSS supported by Satori or a Vizmatic primitive."
|
|
11773
|
+
};
|
|
11774
|
+
}
|
|
11775
|
+
if (/font|emoji|image asset|failed to (?:download|fetch)|asset .*not found/i.test(message)) {
|
|
11776
|
+
return {
|
|
11777
|
+
code: "asset.warning",
|
|
11778
|
+
severity,
|
|
11779
|
+
theme,
|
|
11780
|
+
message,
|
|
11781
|
+
suggestion: "Use a reachable asset or install it locally before rendering offline."
|
|
11782
|
+
};
|
|
11783
|
+
}
|
|
11784
|
+
return {
|
|
11785
|
+
code: severity === "error" ? "render.error" : "render.warning",
|
|
11786
|
+
severity,
|
|
11787
|
+
theme,
|
|
11788
|
+
message
|
|
11789
|
+
};
|
|
11790
|
+
}
|
|
11791
|
+
|
|
11792
|
+
// src/check.ts
|
|
11793
|
+
var DEFAULT_WIDTH = 960;
|
|
11794
|
+
var DEFAULT_HEIGHT = 540;
|
|
11795
|
+
var MAX_WIDTH = 1920;
|
|
11796
|
+
var MAX_HEIGHT = 1440;
|
|
11797
|
+
var GROWTH = 1.25;
|
|
11798
|
+
var MAX_AUTO_SIZE_ATTEMPTS = 6;
|
|
11799
|
+
var TRUSTED_COMPONENTS = new Set(Object.values(primitives_exports));
|
|
11800
|
+
var consoleCaptureContext = new import_async_hooks2.AsyncLocalStorage();
|
|
11801
|
+
var activeConsoleCaptures = 0;
|
|
11802
|
+
var originalConsoleMethods;
|
|
11803
|
+
function formatConsoleArgs(args) {
|
|
11804
|
+
return args.map((value) => {
|
|
11805
|
+
if (value instanceof Error) return value.message;
|
|
11806
|
+
if (typeof value === "string") return value;
|
|
11807
|
+
try {
|
|
11808
|
+
return JSON.stringify(value);
|
|
11809
|
+
} catch {
|
|
11810
|
+
return String(value);
|
|
11811
|
+
}
|
|
11812
|
+
}).join(" ");
|
|
11813
|
+
}
|
|
11814
|
+
function installConsoleCapture() {
|
|
11815
|
+
if (activeConsoleCaptures === 0) {
|
|
11816
|
+
originalConsoleMethods = {
|
|
11817
|
+
debug: console.debug,
|
|
11818
|
+
error: console.error,
|
|
11819
|
+
info: console.info,
|
|
11820
|
+
log: console.log,
|
|
11821
|
+
warn: console.warn
|
|
11822
|
+
};
|
|
11823
|
+
const original = originalConsoleMethods;
|
|
11824
|
+
const intercept = (method, severity) => (...args) => {
|
|
11825
|
+
const messages = consoleCaptureContext.getStore();
|
|
11826
|
+
if (messages) {
|
|
11827
|
+
if (severity) messages.push({ severity, message: formatConsoleArgs(args) });
|
|
11828
|
+
return;
|
|
11829
|
+
}
|
|
11830
|
+
Reflect.apply(original[method], console, args);
|
|
11831
|
+
};
|
|
11832
|
+
console.debug = intercept("debug");
|
|
11833
|
+
console.error = intercept("error", "error");
|
|
11834
|
+
console.info = intercept("info");
|
|
11835
|
+
console.log = intercept("log");
|
|
11836
|
+
console.warn = intercept("warn", "warning");
|
|
11837
|
+
}
|
|
11838
|
+
activeConsoleCaptures += 1;
|
|
11839
|
+
let restored = false;
|
|
11840
|
+
return () => {
|
|
11841
|
+
if (restored) return;
|
|
11842
|
+
restored = true;
|
|
11843
|
+
activeConsoleCaptures -= 1;
|
|
11844
|
+
if (activeConsoleCaptures === 0 && originalConsoleMethods) {
|
|
11845
|
+
console.debug = originalConsoleMethods.debug;
|
|
11846
|
+
console.error = originalConsoleMethods.error;
|
|
11847
|
+
console.info = originalConsoleMethods.info;
|
|
11848
|
+
console.log = originalConsoleMethods.log;
|
|
11849
|
+
console.warn = originalConsoleMethods.warn;
|
|
11850
|
+
originalConsoleMethods = void 0;
|
|
11851
|
+
}
|
|
11852
|
+
};
|
|
11853
|
+
}
|
|
11854
|
+
async function captureConsole(run) {
|
|
11855
|
+
const messages = [];
|
|
11856
|
+
const uninstall = installConsoleCapture();
|
|
11857
|
+
try {
|
|
11858
|
+
const value = await consoleCaptureContext.run(messages, run);
|
|
11859
|
+
return { value, messages };
|
|
11860
|
+
} catch (error) {
|
|
11861
|
+
return { error, messages };
|
|
11862
|
+
} finally {
|
|
11863
|
+
uninstall();
|
|
11864
|
+
}
|
|
11865
|
+
}
|
|
11866
|
+
function normalizeAutoSize(value, defaults) {
|
|
11867
|
+
if (value === true) return { width: true, height: true };
|
|
11868
|
+
if (value === false) return { width: false, height: false };
|
|
11869
|
+
if (value) return { width: value.width ?? defaults.width, height: value.height ?? defaults.height };
|
|
11870
|
+
return defaults;
|
|
11871
|
+
}
|
|
11872
|
+
function overflowEdges(error) {
|
|
11873
|
+
if (!(error instanceof CanvasOverflowError)) return void 0;
|
|
11874
|
+
return Object.entries(error.overflow.edges).filter(([, overflows]) => overflows).map(([edge]) => edge);
|
|
11875
|
+
}
|
|
11876
|
+
function nextDimension(value, maximum) {
|
|
11877
|
+
return Math.min(maximum, Math.ceil(value * GROWTH / 10) * 10);
|
|
11878
|
+
}
|
|
11879
|
+
function nextAutoSize(width, height, autoSize, edges) {
|
|
11880
|
+
const growWidth = autoSize.width && (edges.includes("left") || edges.includes("right"));
|
|
11881
|
+
const growHeight = autoSize.height && (edges.includes("top") || edges.includes("bottom"));
|
|
11882
|
+
const nextWidth = growWidth ? nextDimension(width, MAX_WIDTH) : width;
|
|
11883
|
+
const nextHeight = growHeight ? nextDimension(height, MAX_HEIGHT) : height;
|
|
11884
|
+
if (nextWidth === width && nextHeight === height) return void 0;
|
|
11885
|
+
return { width: nextWidth, height: nextHeight };
|
|
11886
|
+
}
|
|
11887
|
+
async function renderFrame(create, theme, options) {
|
|
11888
|
+
let width = options.width;
|
|
11889
|
+
let height = options.height;
|
|
11890
|
+
for (let attempt = 0; attempt < MAX_AUTO_SIZE_ATTEMPTS; attempt += 1) {
|
|
11891
|
+
try {
|
|
11892
|
+
const layoutNodes = [];
|
|
11893
|
+
const output = await renderToPngWithOutput(create(theme), {
|
|
11894
|
+
width,
|
|
11895
|
+
height,
|
|
11896
|
+
outputPath: options.outputPath,
|
|
11897
|
+
crop: true,
|
|
11898
|
+
scale: 1,
|
|
11899
|
+
background: options.background,
|
|
11900
|
+
onNodeDetected: (node) => layoutNodes.push(node)
|
|
11901
|
+
}, create, theme);
|
|
11902
|
+
return {
|
|
11903
|
+
width,
|
|
11904
|
+
height,
|
|
11905
|
+
outputWidth: output.pixelWidth,
|
|
11906
|
+
outputHeight: output.pixelHeight,
|
|
11907
|
+
logicalOutputWidth: output.width,
|
|
11908
|
+
logicalOutputHeight: output.height,
|
|
11909
|
+
contentBounds: output.contentBounds,
|
|
11910
|
+
layoutNodes
|
|
11911
|
+
};
|
|
11912
|
+
} catch (error) {
|
|
11913
|
+
const edges = overflowEdges(error);
|
|
11914
|
+
const next = edges ? nextAutoSize(width, height, options.autoSize, edges) : void 0;
|
|
11915
|
+
if (!next || attempt === MAX_AUTO_SIZE_ATTEMPTS - 1) throw error;
|
|
11916
|
+
width = next.width;
|
|
11917
|
+
height = next.height;
|
|
11918
|
+
}
|
|
11919
|
+
}
|
|
11920
|
+
return {
|
|
11921
|
+
width,
|
|
11922
|
+
height,
|
|
11923
|
+
outputWidth: width,
|
|
11924
|
+
outputHeight: height,
|
|
11925
|
+
logicalOutputWidth: width,
|
|
11926
|
+
logicalOutputHeight: height,
|
|
11927
|
+
layoutNodes: []
|
|
11928
|
+
};
|
|
11929
|
+
}
|
|
11930
|
+
function counts(themes) {
|
|
11931
|
+
const diagnostics = themes.flatMap(({ diagnostics: themeDiagnostics }) => themeDiagnostics);
|
|
11932
|
+
return {
|
|
11933
|
+
errors: diagnostics.filter(({ severity }) => severity === "error").length,
|
|
11934
|
+
warnings: diagnostics.filter(({ severity }) => severity === "warning").length,
|
|
11935
|
+
info: diagnostics.filter(({ severity }) => severity === "info").length
|
|
11936
|
+
};
|
|
11937
|
+
}
|
|
11938
|
+
function fails(diagnostics, policy) {
|
|
11939
|
+
if (policy === "never") return false;
|
|
11940
|
+
const threshold = { error: 0, warning: 1, info: 2 }[policy];
|
|
11941
|
+
const levels = { error: 0, warning: 1, info: 2 };
|
|
11942
|
+
return diagnostics.some(({ severity }) => levels[severity] <= threshold);
|
|
11943
|
+
}
|
|
11944
|
+
function messageDiagnostics(messages, theme) {
|
|
11945
|
+
return messages.map(({ message, severity }) => diagnosticFromMessage(message, severity, theme));
|
|
11946
|
+
}
|
|
11947
|
+
function rootBackground(background, theme) {
|
|
11948
|
+
if (background === "theme") return getThemeColors(theme).bg;
|
|
11949
|
+
if (background === "transparent" || background === void 0) return void 0;
|
|
11950
|
+
return background;
|
|
11951
|
+
}
|
|
11952
|
+
async function checkFrame(input, options = {}) {
|
|
11953
|
+
const themes = options.themes ?? ["dark", "light"];
|
|
11954
|
+
if (themes.length === 0) throw new TypeError("checkFrame requires at least one theme");
|
|
11955
|
+
const width = input.width ?? DEFAULT_WIDTH;
|
|
11956
|
+
const height = input.height ?? DEFAULT_HEIGHT;
|
|
11957
|
+
if (!Number.isFinite(width) || width <= 0 || !Number.isFinite(height) || height <= 0) {
|
|
11958
|
+
throw new TypeError("checkFrame width and height must be positive finite numbers");
|
|
11959
|
+
}
|
|
11960
|
+
const autoSize = normalizeAutoSize(input.autoSize, {
|
|
11961
|
+
width: input.width == null,
|
|
11962
|
+
height: input.height == null
|
|
11963
|
+
});
|
|
11964
|
+
const create = input.create ?? (() => input.scene);
|
|
11965
|
+
const failOn = options.failOn ?? "error";
|
|
11966
|
+
const tempDir = await (0, import_promises3.mkdtemp)((0, import_path3.join)((0, import_os2.tmpdir)(), "vizmatic-check-"));
|
|
11967
|
+
const reports = [];
|
|
11968
|
+
try {
|
|
11969
|
+
for (const [themeIndex, theme] of themes.entries()) {
|
|
11970
|
+
const inputDimensions = { width, height };
|
|
11971
|
+
const diagnostics2 = [];
|
|
11972
|
+
const prepared = await captureConsole(async () => {
|
|
11973
|
+
const element = create(theme);
|
|
11974
|
+
const background = rootBackground(options.background, theme);
|
|
11975
|
+
return analyzeContrast(element, theme, TRUSTED_COMPONENTS, background);
|
|
11976
|
+
});
|
|
11977
|
+
diagnostics2.push(...messageDiagnostics(prepared.messages, theme));
|
|
11978
|
+
if (!prepared.value) {
|
|
11979
|
+
diagnostics2.push(diagnosticFromMessage(
|
|
11980
|
+
prepared.error instanceof Error ? prepared.error.message : String(prepared.error),
|
|
11981
|
+
"error",
|
|
11982
|
+
theme
|
|
11983
|
+
));
|
|
11984
|
+
reports.push({
|
|
11985
|
+
theme,
|
|
11986
|
+
ok: !fails(diagnostics2, failOn),
|
|
11987
|
+
dimensions: { input: inputDimensions },
|
|
11988
|
+
diagnostics: diagnostics2
|
|
11989
|
+
});
|
|
11990
|
+
continue;
|
|
11991
|
+
}
|
|
11992
|
+
diagnostics2.push(...prepared.value);
|
|
11993
|
+
const rendered = await captureConsole(() => renderFrame(create, theme, {
|
|
11994
|
+
width,
|
|
11995
|
+
height,
|
|
11996
|
+
autoSize,
|
|
11997
|
+
background: options.background,
|
|
11998
|
+
outputPath: (0, import_path3.join)(tempDir, `${themeIndex}.png`)
|
|
11999
|
+
}));
|
|
12000
|
+
diagnostics2.push(...messageDiagnostics(rendered.messages, theme));
|
|
12001
|
+
if (rendered.value) {
|
|
12002
|
+
diagnostics2.push(...analyzeRenderedLayout(rendered.value.layoutNodes, theme));
|
|
12003
|
+
if (rendered.value.contentBounds) {
|
|
12004
|
+
diagnostics2.push(...analyzeWhitespaceBalance(
|
|
12005
|
+
rendered.value.contentBounds,
|
|
12006
|
+
rendered.value.logicalOutputWidth,
|
|
12007
|
+
rendered.value.logicalOutputHeight,
|
|
12008
|
+
theme
|
|
12009
|
+
));
|
|
12010
|
+
}
|
|
12011
|
+
if (rendered.value.width !== width || rendered.value.height !== height) {
|
|
12012
|
+
diagnostics2.push({
|
|
12013
|
+
code: "layout.auto_size",
|
|
12014
|
+
severity: "info",
|
|
12015
|
+
theme,
|
|
12016
|
+
message: `Canvas auto-sized from ${width}\xD7${height} to ${rendered.value.width}\xD7${rendered.value.height}.`,
|
|
12017
|
+
suggestedDimensions: { width: rendered.value.width, height: rendered.value.height }
|
|
12018
|
+
});
|
|
12019
|
+
}
|
|
12020
|
+
reports.push({
|
|
12021
|
+
theme,
|
|
12022
|
+
ok: !fails(diagnostics2, failOn),
|
|
12023
|
+
dimensions: {
|
|
12024
|
+
input: inputDimensions,
|
|
12025
|
+
resolved: { width: rendered.value.width, height: rendered.value.height },
|
|
12026
|
+
output: { width: rendered.value.outputWidth, height: rendered.value.outputHeight }
|
|
12027
|
+
},
|
|
12028
|
+
diagnostics: diagnostics2
|
|
12029
|
+
});
|
|
12030
|
+
continue;
|
|
12031
|
+
}
|
|
12032
|
+
const edges = overflowEdges(rendered.error);
|
|
12033
|
+
if (edges) {
|
|
12034
|
+
const suggestion = await captureConsole(() => renderFrame(create, theme, {
|
|
12035
|
+
width,
|
|
12036
|
+
height,
|
|
12037
|
+
autoSize: { width: true, height: true },
|
|
12038
|
+
background: options.background,
|
|
12039
|
+
outputPath: (0, import_path3.join)(tempDir, `${themeIndex}-suggestion.png`)
|
|
12040
|
+
}));
|
|
12041
|
+
const suggestedDimensions = suggestion.value ? { width: suggestion.value.width, height: suggestion.value.height } : void 0;
|
|
12042
|
+
diagnostics2.push({
|
|
12043
|
+
code: "layout.overflow",
|
|
12044
|
+
severity: "error",
|
|
12045
|
+
theme,
|
|
12046
|
+
edges,
|
|
12047
|
+
message: rendered.error instanceof Error ? rendered.error.message : String(rendered.error),
|
|
12048
|
+
suggestion: suggestedDimensions ? `Increase the canvas to at least ${suggestedDimensions.width}\xD7${suggestedDimensions.height}, or remove fixed dimensions to enable auto-sizing.` : "Increase the canvas dimensions or remove fixed dimensions to enable auto-sizing.",
|
|
12049
|
+
suggestedDimensions
|
|
12050
|
+
});
|
|
12051
|
+
} else {
|
|
12052
|
+
diagnostics2.push(diagnosticFromMessage(
|
|
12053
|
+
rendered.error instanceof Error ? rendered.error.message : String(rendered.error),
|
|
12054
|
+
"error",
|
|
12055
|
+
theme
|
|
12056
|
+
));
|
|
12057
|
+
}
|
|
12058
|
+
reports.push({
|
|
12059
|
+
theme,
|
|
12060
|
+
ok: !fails(diagnostics2, failOn),
|
|
12061
|
+
dimensions: { input: inputDimensions },
|
|
12062
|
+
diagnostics: diagnostics2
|
|
12063
|
+
});
|
|
12064
|
+
}
|
|
12065
|
+
} finally {
|
|
12066
|
+
await (0, import_promises3.rm)(tempDir, { recursive: true, force: true });
|
|
12067
|
+
}
|
|
12068
|
+
const summary = counts(reports);
|
|
12069
|
+
const diagnostics = reports.flatMap(({ diagnostics: themeDiagnostics }) => themeDiagnostics);
|
|
12070
|
+
return {
|
|
12071
|
+
schemaVersion: 1,
|
|
12072
|
+
source: input.source,
|
|
12073
|
+
ok: !fails(diagnostics, failOn),
|
|
12074
|
+
rendered: reports.every(({ dimensions }) => dimensions.resolved !== void 0),
|
|
12075
|
+
autoSize,
|
|
12076
|
+
themes: reports,
|
|
12077
|
+
summary
|
|
12078
|
+
};
|
|
12079
|
+
}
|
|
9489
12080
|
// Annotate the CommonJS export names for ESM import in node:
|
|
9490
12081
|
0 && (module.exports = {
|
|
9491
12082
|
Arrow,
|
|
@@ -9494,9 +12085,13 @@ async function renderAnimationGifWithOutput(animation, options) {
|
|
|
9494
12085
|
Badge,
|
|
9495
12086
|
BadgePill,
|
|
9496
12087
|
BarChart,
|
|
12088
|
+
Board,
|
|
9497
12089
|
Box,
|
|
12090
|
+
CANVAS_ITEM_COMPONENT,
|
|
12091
|
+
CHECK_DIAGNOSTIC_CODES,
|
|
9498
12092
|
CalloutCard,
|
|
9499
12093
|
Canvas,
|
|
12094
|
+
CanvasItem,
|
|
9500
12095
|
CanvasOverflowError,
|
|
9501
12096
|
Card,
|
|
9502
12097
|
ChartFrame,
|
|
@@ -9529,7 +12124,9 @@ async function renderAnimationGifWithOutput(animation, options) {
|
|
|
9529
12124
|
MetricCard,
|
|
9530
12125
|
MiniBarChart,
|
|
9531
12126
|
Panel,
|
|
12127
|
+
ParetoBarChart,
|
|
9532
12128
|
ParetoChart,
|
|
12129
|
+
PieChart,
|
|
9533
12130
|
Pipeline,
|
|
9534
12131
|
ProgressList,
|
|
9535
12132
|
ProgressRow,
|
|
@@ -9562,6 +12159,7 @@ async function renderAnimationGifWithOutput(animation, options) {
|
|
|
9562
12159
|
WindowFrame,
|
|
9563
12160
|
analyzeAnimationCadence,
|
|
9564
12161
|
canvas,
|
|
12162
|
+
checkFrame,
|
|
9565
12163
|
colors,
|
|
9566
12164
|
createPlotArea,
|
|
9567
12165
|
cropPixels,
|
|
@@ -9588,6 +12186,8 @@ async function renderAnimationGifWithOutput(animation, options) {
|
|
|
9588
12186
|
gradients,
|
|
9589
12187
|
heatColor,
|
|
9590
12188
|
hold,
|
|
12189
|
+
importD2Graph,
|
|
12190
|
+
importMermaidGraph,
|
|
9591
12191
|
keyframe,
|
|
9592
12192
|
loadAdditionalAsset,
|
|
9593
12193
|
normalizeWatermark,
|