vizmatic 0.7.0 → 0.7.1

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.
@@ -471,6 +471,20 @@ var satori = (element, options) => renderWithCanvasChartFit(renderSatori, elemen
471
471
  // src/svg-accessibility.ts
472
472
  import { cloneElement, isValidElement as isValidElement2 } from "react";
473
473
  var SVG_ACCESSIBILITY_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.svgAccessibilityComponent");
474
+ function chartAccessibilityAttributes({ id, ariaLabel, description }) {
475
+ const title = ariaLabel?.trim() || "Chart";
476
+ return {
477
+ role: "img",
478
+ "aria-label": title,
479
+ "aria-description": description,
480
+ "data-vizmatic-chart-id": id,
481
+ "data-vizmatic-chart-title": title,
482
+ "data-vizmatic-chart-description": description
483
+ };
484
+ }
485
+ function chartDescription(description, entries) {
486
+ return [description, entries.length ? `${entries.join("; ")}.` : "No data."].filter(Boolean).join(" ");
487
+ }
474
488
  function componentHasSvgMetadata(type) {
475
489
  return typeof type === "function" && type[SVG_ACCESSIBILITY_COMPONENT] === true;
476
490
  }
@@ -625,9 +639,21 @@ function edgeGroup(graph, edge, root) {
625
639
  return `${accessible}${hitTarget}</g>`;
626
640
  }
627
641
  function addSvgAccessibility(svg, graphs, layoutNodes) {
628
- if (graphs.length === 0) return svg;
629
- const title = graphs.map((graph) => graph.title).join(". ");
630
- const description = graphs.map((graph) => `${graph.title}. ${graph.description}`).join(" ");
642
+ const chartIds = /* @__PURE__ */ new Set();
643
+ const charts = layoutNodes.filter((node) => textProperty(node.props, "data-vizmatic-chart-title")).map((node, index) => {
644
+ const id = textProperty(node.props, "data-vizmatic-chart-id");
645
+ if (id && chartIds.has(id)) throw new Error(`Chart SVG id "${id}" must be unique in one exported SVG.`);
646
+ if (id) chartIds.add(id);
647
+ return {
648
+ token: id ? `id-${svgToken(id)}` : `index-${index}`,
649
+ title: textProperty(node.props, "data-vizmatic-chart-title"),
650
+ description: textProperty(node.props, "data-vizmatic-chart-description")
651
+ };
652
+ });
653
+ if (graphs.length === 0 && charts.length === 0) return svg;
654
+ const items = [...graphs, ...charts];
655
+ const title = items.map((item) => item.title).join(". ");
656
+ const description = items.map((item) => `${item.title}. ${item.description}`).join(" ");
631
657
  const hasLinks = graphs.some(
632
658
  (graph) => graph.nodes.some((node) => node.href) || graph.edges.some((edge) => edge.href)
633
659
  );
@@ -653,11 +679,15 @@ function addSvgAccessibility(svg, graphs, layoutNodes) {
653
679
  }).join("");
654
680
  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>`;
655
681
  }).join("");
682
+ const chartMarkup = charts.map((chart) => {
683
+ const id = `vizmatic-chart-${chart.token}`;
684
+ return `<g ${attribute("id", id)} role="group" aria-labelledby="${id}-title" aria-describedby="${id}-description"><title id="${id}-title">${escapeXml(chart.title)}</title><desc id="${id}-description">${escapeXml(chart.description)}</desc></g>`;
685
+ }).join("");
656
686
  const metadata = `<title id="${rootTitleId}">${escapeXml(title)}</title><desc id="${rootDescriptionId}">${escapeXml(description)}</desc>`;
657
687
  return svg.replace(
658
688
  /^<svg\b([^>]*)>/,
659
689
  (_match, attrs) => `<svg${attrs} role="${hasLinks ? "group" : "img"}" aria-labelledby="${rootTitleId}" aria-describedby="${rootDescriptionId}">${metadata}`
660
- ).replace(/<\/svg>\s*$/, `${groupMarkup}</svg>`);
690
+ ).replace(/<\/svg>\s*$/, `${groupMarkup}${chartMarkup}</svg>`);
661
691
  }
662
692
 
663
693
  // src/render.ts
@@ -3577,6 +3607,8 @@ export {
3577
3607
  getRenderBackground,
3578
3608
  withRenderContext,
3579
3609
  SVG_ACCESSIBILITY_COMPONENT,
3610
+ chartAccessibilityAttributes,
3611
+ chartDescription,
3580
3612
  prepareAccessibleSvg,
3581
3613
  addSvgAccessibility,
3582
3614
  CANVAS_CHART_COMPONENT,
@@ -177,6 +177,7 @@ var SCENE_COMPONENT_NAMES = Object.freeze([
177
177
  "DiagramLegend",
178
178
  "DonutChart",
179
179
  "DotPoint",
180
+ "EntityRelationshipDiagram",
180
181
  "EquationCard",
181
182
  "FactRows",
182
183
  "Flow",
@@ -387,7 +388,7 @@ function validateSceneComponentProps(name, props) {
387
388
  const check = (value, key) => {
388
389
  if (++values > 8192) throw new Error(`Editable scene ${name} props exceed their value budget.`);
389
390
  if (typeof value === "number") {
390
- if (/^(?:width|height|x|y|x1|y1|x2|y2|cx|cy|r|rx|ry|radius|length|padding|gap|nodeWidth|nodeHeight|cellSize|cellWidth|cellHeight|fontSize|nodeSize|tileWidth|minHeight)$/i.test(key)) finite(value, `${name}.${key}`);
391
+ if (/^(?:width|height|x|y|x1|y1|x2|y2|cx|cy|r|rx|ry|radius|length|padding|gap|nodeWidth|nodeHeight|entityWidth|cellSize|cellWidth|cellHeight|fontSize|nodeSize|tileWidth|minHeight)$/i.test(key)) finite(value, `${name}.${key}`);
391
392
  if (/^(?:rows|cols|columns|count|repeat|gridCount|tickCount)$/i.test(key)) integer(value, `${name}.${key}`, key === "gridCount" ? 0 : 1, 2e3);
392
393
  }
393
394
  if (Array.isArray(value)) value.forEach((item) => check(item, ""));
@@ -415,6 +416,12 @@ function validateSceneComponentProps(name, props) {
415
416
  for (const key of ["nodes", "groups", "boundaries", "blocks"]) entries(props[key], `${name}.${key}`, 128);
416
417
  for (const key of ["edges", "connections", "routes"]) entries(props[key], `${name}.${key}`, 256);
417
418
  }
419
+ if (name === "EntityRelationshipDiagram") {
420
+ entries(props.entities, "EntityRelationshipDiagram.entities", 128).forEach((entity) => {
421
+ entries(record(entity, "Entity relationship entity").attributes, "EntityRelationshipDiagram.attributes", 64);
422
+ });
423
+ entries(props.relationships, "EntityRelationshipDiagram.relationships", 256);
424
+ }
418
425
  if (name === "TransformerTopology" && props.expandRepeats) {
419
426
  const blocks = entries(props.blocks, "TransformerTopology.blocks", 128);
420
427
  const total = blocks.reduce((sum, block) => sum + integer(record(block, "Transformer block").repeat ?? 1, "Transformer block.repeat", 1, 128), 0);