@opendata-ai/openchart-vanilla 8.9.1 → 9.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +4 -4
  2. package/dist/{chunk-REH5UQCL.js → chunk-46E3QB6O.js} +6 -20
  3. package/dist/chunk-46E3QB6O.js.map +1 -0
  4. package/dist/{chunk-APMUBW72.js → chunk-5OQZRGUL.js} +1565 -294
  5. package/dist/chunk-5OQZRGUL.js.map +1 -0
  6. package/dist/{chunk-GX6BWMJD.js → chunk-5ZLSMZRM.js} +466 -330
  7. package/dist/chunk-5ZLSMZRM.js.map +1 -0
  8. package/dist/{chunk-SDJHUELU.js → chunk-A5C4VCUO.js} +26 -45
  9. package/dist/chunk-A5C4VCUO.js.map +1 -0
  10. package/dist/{chunk-MGFXAROR.js → chunk-CMIJA63X.js} +5 -3
  11. package/dist/chunk-CMIJA63X.js.map +1 -0
  12. package/dist/chunk-FFP5GXIP.js +45 -0
  13. package/dist/chunk-FFP5GXIP.js.map +1 -0
  14. package/dist/{chunk-Q7YEEF2X.js → chunk-LDSPJFOU.js} +16 -50
  15. package/dist/chunk-LDSPJFOU.js.map +1 -0
  16. package/dist/chunk-NLKQ5AOA.js +448 -0
  17. package/dist/chunk-NLKQ5AOA.js.map +1 -0
  18. package/dist/{chunk-R5TZHNTG.js → chunk-RBXIZJPE.js} +17 -5
  19. package/dist/chunk-RBXIZJPE.js.map +1 -0
  20. package/dist/{chunk-CCRFYGHU.js → chunk-RY5JEGFM.js} +2368 -2339
  21. package/dist/chunk-RY5JEGFM.js.map +1 -0
  22. package/dist/export-gif.d.ts +2 -2
  23. package/dist/export-gif.js +4 -3
  24. package/dist/graph-3d/index.d.ts +28 -1
  25. package/dist/graph-3d/index.js +26 -12
  26. package/dist/graph-3d/index.js.map +1 -1
  27. package/dist/index.d.ts +155 -29
  28. package/dist/index.js +1774 -186
  29. package/dist/index.js.map +1 -1
  30. package/dist/{mount-TEjIdF0m.d.ts → mount-types-DeUCa2hy.d.ts} +34 -21
  31. package/dist/{renderer-registry-Cng76n8F.d.ts → renderer-registry-Bu22Roek.d.ts} +5 -22
  32. package/dist/simulation-worker.js +27 -26
  33. package/dist/static.d.ts +4 -2
  34. package/dist/static.js +34 -10
  35. package/dist/static.js.map +1 -1
  36. package/dist/story/index.d.ts +8 -6
  37. package/dist/story/index.js +15 -12
  38. package/dist/story/index.js.map +1 -1
  39. package/dist/styles.css +1 -1
  40. package/dist/styles.css.map +1 -1
  41. package/package.json +3 -3
  42. package/dist/chunk-APMUBW72.js.map +0 -1
  43. package/dist/chunk-CCRFYGHU.js.map +0 -1
  44. package/dist/chunk-GX6BWMJD.js.map +0 -1
  45. package/dist/chunk-MGFXAROR.js.map +0 -1
  46. package/dist/chunk-Q7YEEF2X.js.map +0 -1
  47. package/dist/chunk-R5TZHNTG.js.map +0 -1
  48. package/dist/chunk-REH5UQCL.js.map +0 -1
  49. package/dist/chunk-SDJHUELU.js.map +0 -1
  50. package/dist/chunk-UC4IHEUO.js +0 -73
  51. package/dist/chunk-UC4IHEUO.js.map +0 -1
@@ -1,22 +1,40 @@
1
+ import {
2
+ clamp01,
3
+ cubicInOut,
4
+ cubicOut,
5
+ lerp,
6
+ linear,
7
+ renderAttributionBrand,
8
+ renderBrand,
9
+ renderChrome,
10
+ renderChromeElement,
11
+ resolvedSurface,
12
+ stampThemeProperties
13
+ } from "./chunk-NLKQ5AOA.js";
1
14
  import {
2
15
  SVG_NS,
3
- XLINK_NS,
4
16
  applyKnockoutHalo,
5
17
  applyTextStyle,
6
18
  createSVGElement,
7
19
  setAttrs
8
- } from "./chunk-SDJHUELU.js";
9
- import {
10
- resolvedSurface
11
- } from "./chunk-UC4IHEUO.js";
20
+ } from "./chunk-FFP5GXIP.js";
12
21
 
13
22
  // src/svg-ids.ts
14
23
  var counter = 0;
24
+ var idPrefix = "";
25
+ function captureSvgIdState() {
26
+ return { counter, prefix: idPrefix };
27
+ }
28
+ function restoreSvgIdState(state) {
29
+ counter = state.counter;
30
+ idPrefix = state.prefix;
31
+ }
15
32
  function nextSvgId(prefix) {
16
- return `${prefix}-${counter++}`;
33
+ return `${idPrefix}${prefix}-${counter++}`;
17
34
  }
18
- function resetSvgIdCounter() {
35
+ function resetSvgIdCounter(prefix = "") {
19
36
  counter = 0;
37
+ idPrefix = prefix ? `${prefix}-` : "";
20
38
  }
21
39
 
22
40
  // src/gradient-utils.ts
@@ -173,9 +191,9 @@ function resetMarkRenderState() {
173
191
  currentPatternMap = /* @__PURE__ */ new Map();
174
192
  currentSurface = "";
175
193
  }
176
- function applyLabelHalo(text, label) {
194
+ function applyLabelHalo(text2, label) {
177
195
  if (!currentSurface || label.halo === false) return;
178
- applyKnockoutHalo(text, currentSurface, label.style.fontSize);
196
+ applyKnockoutHalo(text2, currentSurface, label.style.fontSize);
179
197
  }
180
198
  function resolveFillOrPattern(fill, pattern) {
181
199
  if (pattern) return resolvePatternFill(pattern, currentPatternMap);
@@ -387,31 +405,31 @@ function renderPointMark(mark, index) {
387
405
  return circle;
388
406
  }
389
407
  function renderTextMark(mark, index) {
390
- const text = createSVGElement("text");
391
- text.setAttribute("data-mark-id", `textMark-${index}`);
392
- text.setAttribute("class", "oc-mark oc-mark-text");
393
- stampAnimationAttrs(text, mark, index);
394
- setAttrs(text, {
408
+ const text2 = createSVGElement("text");
409
+ text2.setAttribute("data-mark-id", `textMark-${index}`);
410
+ text2.setAttribute("class", "oc-mark oc-mark-text");
411
+ stampAnimationAttrs(text2, mark, index);
412
+ setAttrs(text2, {
395
413
  x: mark.x,
396
414
  y: mark.y,
397
415
  "font-size": mark.fontSize,
398
416
  "text-anchor": mark.textAnchor
399
417
  });
400
418
  if (mark.dominantBaseline) {
401
- text.setAttribute("dominant-baseline", mark.dominantBaseline);
419
+ text2.setAttribute("dominant-baseline", mark.dominantBaseline);
402
420
  }
403
- text.style.setProperty("fill", mark.fill);
421
+ text2.style.setProperty("fill", mark.fill);
404
422
  if (mark.fontWeight) {
405
- text.setAttribute("font-weight", String(mark.fontWeight));
423
+ text2.setAttribute("font-weight", String(mark.fontWeight));
406
424
  }
407
425
  if (mark.fontFamily) {
408
- text.setAttribute("font-family", mark.fontFamily);
426
+ text2.setAttribute("font-family", mark.fontFamily);
409
427
  }
410
428
  if (mark.angle) {
411
- text.setAttribute("transform", `rotate(${mark.angle}, ${mark.x}, ${mark.y})`);
429
+ text2.setAttribute("transform", `rotate(${mark.angle}, ${mark.x}, ${mark.y})`);
412
430
  }
413
- text.textContent = mark.text;
414
- return text;
431
+ text2.textContent = mark.text;
432
+ return text2;
415
433
  }
416
434
  function renderRuleMark(mark, index) {
417
435
  const line = createSVGElement("line");
@@ -563,6 +581,51 @@ function renderMarks(parent, layout, opts) {
563
581
  return labelsGroup;
564
582
  }
565
583
 
584
+ // src/interactions/annotation-notes.ts
585
+ var NOTE_SELECTOR = "[data-note-spec-index], [data-note-marker-index]";
586
+ function wireAnnotationNotes(svg) {
587
+ if (svg.getAttribute("aria-hidden") !== "true" && svg.querySelector(NOTE_SELECTOR) && svg.getAttribute("role") === "img") {
588
+ svg.setAttribute("role", "group");
589
+ }
590
+ const linked = () => [...svg.querySelectorAll(NOTE_SELECTOR)];
591
+ const key = (element3) => element3.getAttribute("data-note-spec-index") ?? element3.getAttribute("data-note-marker-index");
592
+ const target = (event) => svg.getAttribute("aria-hidden") !== "true" && event.target instanceof Element ? event.target.closest(NOTE_SELECTOR) : null;
593
+ const emphasize = (index) => {
594
+ for (const element3 of linked()) {
595
+ element3.classList.toggle("oc-note-active", index !== null && key(element3) === index);
596
+ }
597
+ };
598
+ svg.addEventListener("focusin", (event) => {
599
+ const element3 = target(event);
600
+ if (element3) emphasize(key(element3));
601
+ });
602
+ svg.addEventListener("focusout", (event) => {
603
+ if (target(event)) emphasize(null);
604
+ });
605
+ svg.addEventListener("click", (event) => {
606
+ const element3 = target(event);
607
+ if (element3) emphasize(key(element3));
608
+ });
609
+ svg.addEventListener("keydown", (event) => {
610
+ const element3 = target(event);
611
+ if (!element3) return;
612
+ if (event.key === "Escape") {
613
+ event.stopImmediatePropagation();
614
+ emphasize(null);
615
+ return;
616
+ }
617
+ if (event.key !== "Enter" && event.key !== " ") return;
618
+ event.preventDefault();
619
+ event.stopImmediatePropagation();
620
+ const isNote = element3.hasAttribute("data-note-spec-index");
621
+ const peer = linked().find(
622
+ (candidate) => key(candidate) === key(element3) && candidate.hasAttribute("data-note-spec-index") !== isNote
623
+ );
624
+ peer?.focus();
625
+ emphasize(key(element3));
626
+ });
627
+ }
628
+
566
629
  // src/svg-renderer.ts
567
630
  import { clampStaggerDelay } from "@opendata-ai/openchart-engine";
568
631
 
@@ -641,7 +704,7 @@ function renderCurvedConnector(parent, from, to, stroke, showArrow, exit, contro
641
704
  renderArrowhead(parent, to.x, to.y, tx, ty, stroke);
642
705
  }
643
706
  }
644
- function fillRichText(text, content, x, lineHeight) {
707
+ function fillRichText(text2, content, x, lineHeight) {
645
708
  const lines = content.split("\n");
646
709
  for (let i = 0; i < lines.length; i++) {
647
710
  const spans = parseAnnotationSpans(lines[i]);
@@ -654,11 +717,11 @@ function fillRichText(text, content, x, lineHeight) {
654
717
  tspan.setAttribute("font-weight", String(BOLD_SPAN_FONT_WEIGHT));
655
718
  }
656
719
  tspan.textContent = spans[s].text;
657
- text.appendChild(tspan);
720
+ text2.appendChild(tspan);
658
721
  }
659
722
  }
660
723
  }
661
- function renderAnnotation(parent, annotation, index, bgColor) {
724
+ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
662
725
  const g = createSVGElement("g");
663
726
  g.setAttribute("class", `oc-annotation oc-annotation-${annotation.type}`);
664
727
  g.setAttribute("data-annotation-index", String(annotation.specIndex ?? index));
@@ -700,6 +763,14 @@ function renderAnnotation(parent, annotation, index, bgColor) {
700
763
  g.appendChild(line);
701
764
  }
702
765
  if (annotation.footnoteIndex != null && annotation.label) {
766
+ if (annotation.specIndex !== void 0)
767
+ g.setAttribute("data-note-marker-index", String(annotation.specIndex));
768
+ if (!hidden) g.setAttribute("tabindex", "0");
769
+ g.setAttribute("role", "button");
770
+ g.setAttribute(
771
+ "aria-label",
772
+ `Annotation ${annotation.footnoteIndex}: ${annotation.label.text.replaceAll("**", "")}. Activate to read the note.`
773
+ );
703
774
  const cx = annotation.label.connector?.endpoint?.x ?? annotation.label.connector?.to.x ?? annotation.dot?.x ?? annotation.label.x;
704
775
  const cy = annotation.label.connector?.endpoint?.y ?? annotation.label.connector?.to.y ?? annotation.dot?.y ?? annotation.label.y;
705
776
  const r = 8;
@@ -725,7 +796,9 @@ function renderAnnotation(parent, annotation, index, bgColor) {
725
796
  applyTextStyle(num, {
726
797
  ...annotation.label.style,
727
798
  fontSize: 9,
728
- fontWeight: 600
799
+ fontWeight: 600,
800
+ textAnchor: "middle",
801
+ dominantBaseline: "central"
729
802
  });
730
803
  num.textContent = String(annotation.footnoteIndex);
731
804
  g.appendChild(num);
@@ -800,14 +873,14 @@ function renderAnnotation(parent, annotation, index, bgColor) {
800
873
  });
801
874
  g.appendChild(dot);
802
875
  }
803
- const text = createSVGElement("text");
804
- text.setAttribute("class", "oc-annotation-label");
805
- setAttrs(text, { x: annotation.label.x, y: annotation.label.y });
806
- applyTextStyle(text, annotation.label.style);
876
+ const text2 = createSVGElement("text");
877
+ text2.setAttribute("class", "oc-annotation-label");
878
+ setAttrs(text2, { x: annotation.label.x, y: annotation.label.y });
879
+ applyTextStyle(text2, annotation.label.style);
807
880
  const fontSize = annotation.label.style.fontSize ?? DEFAULT_ANNOTATION_FONT_SIZE;
808
881
  const lineHeight = fontSize * (annotation.label.style.lineHeight ?? DEFAULT_LINE_HEIGHT);
809
882
  fillRichText(
810
- text,
883
+ text2,
811
884
  annotation.label.lines?.join("\n") ?? annotation.label.text,
812
885
  annotation.label.x,
813
886
  lineHeight
@@ -831,9 +904,9 @@ function renderAnnotation(parent, annotation, index, bgColor) {
831
904
  });
832
905
  g.appendChild(bgRect);
833
906
  } else if (bgColor && annotation.label.halo !== false) {
834
- applyKnockoutHalo(text, bgColor, fontSize);
907
+ applyKnockoutHalo(text2, bgColor, fontSize);
835
908
  }
836
- g.appendChild(text);
909
+ g.appendChild(text2);
837
910
  if (annotation.subtitle) {
838
911
  const sub = createSVGElement("text");
839
912
  sub.setAttribute("class", "oc-annotation-subtitle");
@@ -859,7 +932,7 @@ function renderAnnotations(parent, layout) {
859
932
  parent.appendChild(g);
860
933
  const bgColor = resolvedSurface(layout.theme);
861
934
  for (let i = 0; i < layout.annotations.length; i++) {
862
- renderAnnotation(g, layout.annotations[i], i, bgColor);
935
+ renderAnnotation(g, layout.annotations[i], i, bgColor, layout.a11y.hidden);
863
936
  }
864
937
  }
865
938
  function updateAnnotationGeometry(group, annotation, bgColor) {
@@ -939,7 +1012,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
939
1012
  if (axis.tickAngle && Math.abs(axis.tickAngle) > 10) {
940
1013
  const labelX = tick.labelPosition ?? tick.position;
941
1014
  const xLabelPad = axis.labelPadding ?? layout.theme.spacing.xAxisLabelPadding;
942
- const labelY = area.y + area.height + xLabelPad;
1015
+ const labelY = axis.start.y + xLabelPad;
943
1016
  setAttrs(label, {
944
1017
  x: labelX,
945
1018
  y: labelY,
@@ -951,7 +1024,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
951
1024
  const xLabelPad = axis.labelPadding ?? layout.theme.spacing.xAxisLabelPadding;
952
1025
  setAttrs(label, {
953
1026
  x: tick.labelPosition ?? tick.position,
954
- y: area.y + area.height + xLabelPad + textAscent(axis.tickLabelStyle.fontSize),
1027
+ y: axis.start.y + xLabelPad + textAscent(axis.tickLabelStyle.fontSize),
955
1028
  "text-anchor": "middle"
956
1029
  });
957
1030
  }
@@ -980,14 +1053,14 @@ function renderAxis(parent, axis, orientation, layout, opts) {
980
1053
  label.setAttribute("class", "oc-axis-tick");
981
1054
  label.setAttribute("data-tick-key", tickKey);
982
1055
  setAttrs(label, {
983
- x: isRight ? area.x + area.width + TICK_LABEL_OFFSET : area.x - TICK_LABEL_OFFSET,
1056
+ x: isRight ? axis.start.x + TICK_LABEL_OFFSET : axis.start.x - TICK_LABEL_OFFSET,
984
1057
  y: tick.position,
985
1058
  "text-anchor": isRight ? "start" : "end",
986
1059
  "dominant-baseline": "central"
987
1060
  });
988
1061
  applyTextStyle(label, axis.tickLabelStyle);
989
1062
  if (!isRight) {
990
- const availableWidth = area.x - TICK_LABEL_OFFSET;
1063
+ const availableWidth = axis.start.x - TICK_LABEL_OFFSET;
991
1064
  const fontSize = axis.tickLabelStyle.fontSize;
992
1065
  const fontWeight = axis.tickLabelStyle.fontWeight;
993
1066
  if (tick.subtitle) {
@@ -1071,7 +1144,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
1071
1144
  y1: gridline.position,
1072
1145
  x2: area.x + area.width,
1073
1146
  y2: gridline.position,
1074
- stroke: layout.theme.colors.gridline,
1147
+ stroke: gridline.color ?? layout.theme.colors.gridline,
1075
1148
  "stroke-width": 1,
1076
1149
  "stroke-opacity": 0.6
1077
1150
  });
@@ -1081,7 +1154,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
1081
1154
  y1: area.y,
1082
1155
  x2: gridline.position,
1083
1156
  y2: area.y + area.height,
1084
- stroke: layout.theme.colors.gridline,
1157
+ stroke: gridline.color ?? layout.theme.colors.gridline,
1085
1158
  "stroke-width": 1,
1086
1159
  "stroke-opacity": 0.6
1087
1160
  });
@@ -1099,16 +1172,28 @@ function renderAxis(parent, axis, orientation, layout, opts) {
1099
1172
  const attrs = {
1100
1173
  x: tp.x,
1101
1174
  y: tp.y,
1102
- "text-anchor": "middle"
1175
+ "text-anchor": tp.textAnchor ?? "middle"
1103
1176
  };
1104
1177
  if (tp.angle) {
1105
1178
  attrs.transform = `rotate(${tp.angle}, ${tp.x}, ${tp.y})`;
1106
1179
  }
1107
1180
  setAttrs(axisLabel, attrs);
1181
+ if (axis.titleLines && axis.titleLines.length > 1) {
1182
+ axisLabel.textContent = "";
1183
+ for (const [index, line] of axis.titleLines.entries()) {
1184
+ const span = createSVGElement("tspan");
1185
+ setAttrs(span, {
1186
+ x: tp.x,
1187
+ dy: index === 0 ? 0 : axis.labelStyle.fontSize * (axis.labelStyle.lineHeight ?? 1.3)
1188
+ });
1189
+ span.textContent = line;
1190
+ axisLabel.appendChild(span);
1191
+ }
1192
+ }
1108
1193
  } else if (orientation === "x") {
1109
1194
  const tickFontSize = axis.tickLabelStyle.fontSize;
1110
1195
  const tickBand = Math.max(26, 4 + tickFontSize + Math.max(11, Math.ceil(tickFontSize * 0.7)));
1111
- let titleY = area.y + area.height + tickBand + 9;
1196
+ let titleY = axis.start.y + tickBand + 9;
1112
1197
  if (axis.tickAngle && Math.abs(axis.tickAngle) > 10) {
1113
1198
  const angleRad = Math.abs(axis.tickAngle) * (Math.PI / 180);
1114
1199
  let maxLabelWidth = 40;
@@ -1117,7 +1202,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
1117
1202
  if (w > maxLabelWidth) maxLabelWidth = w;
1118
1203
  }
1119
1204
  const rotatedHeight = Math.min(maxLabelWidth * Math.sin(angleRad) + 6, 120);
1120
- titleY = area.y + area.height + rotatedHeight + 14;
1205
+ titleY = axis.start.y + rotatedHeight + 14;
1121
1206
  }
1122
1207
  setAttrs(axisLabel, {
1123
1208
  x: area.x + area.width / 2,
@@ -1183,238 +1268,6 @@ function renderAxes(parent, layout, opts) {
1183
1268
  }
1184
1269
  }
1185
1270
 
1186
- // src/renderers/brand.ts
1187
- import { BRAND_MIN_WIDTH, computeNoteBandHeight, textAscent as textAscent2 } from "@opendata-ai/openchart-core";
1188
- var BRAND_URL = "https://tryopendata.ai";
1189
- function renderBrand(parent, layout) {
1190
- if (layout.dimensions.width < BRAND_MIN_WIDTH) return;
1191
- const { width } = layout.dimensions;
1192
- const padding = layout.theme.spacing.padding;
1193
- const rightEdge = width - padding;
1194
- const fill = layout.theme.colors.axis;
1195
- const { chrome } = layout;
1196
- const bottomOffset = chrome.bottomAnchorY ?? layout.area.y + layout.area.height;
1197
- const firstBottom = chrome.source ?? chrome.byline ?? chrome.footer;
1198
- const { legend } = layout;
1199
- const bottomLegendOffset = legend.position === "bottom" && legend.bounds.height > 0 ? legend.bounds.height + 8 : 0;
1200
- const bandHeight = layout.chrome.noteBandHeight ?? computeNoteBandHeight(layout.chrome, layout.theme);
1201
- const chromeY = firstBottom ? bottomOffset + firstBottom.y + bandHeight : bottomOffset + layout.theme.spacing.chartToFooter + bottomLegendOffset + bandHeight;
1202
- const a = createSVGElement("a");
1203
- a.setAttribute("href", BRAND_URL);
1204
- a.setAttributeNS(XLINK_NS, "xlink:href", BRAND_URL);
1205
- a.setAttribute("target", "_blank");
1206
- a.setAttribute("rel", "noopener");
1207
- a.setAttribute("class", "oc-chrome-ref");
1208
- const BRAND_LARGE = 16;
1209
- const text = createSVGElement("text");
1210
- setAttrs(text, {
1211
- x: rightEdge,
1212
- y: chromeY + textAscent2(BRAND_LARGE),
1213
- "font-family": layout.theme.fonts.family,
1214
- "font-size": BRAND_LARGE,
1215
- "font-weight": "600",
1216
- "text-anchor": "end",
1217
- "fill-opacity": 0.55
1218
- });
1219
- text.style.setProperty("fill", fill);
1220
- text.textContent = "OpenData";
1221
- a.appendChild(text);
1222
- parent.appendChild(a);
1223
- }
1224
-
1225
- // src/renderers/chrome.ts
1226
- import {
1227
- computeNoteBandHeight as computeNoteBandHeight2,
1228
- FOOTNOTE_LINE_HEIGHT,
1229
- textAscent as textAscent3,
1230
- truncateToWidth,
1231
- wrapText
1232
- } from "@opendata-ai/openchart-core";
1233
- function renderChromeElement(parent, element, className, chromeKey, measureText, uppercase = false) {
1234
- const text = createSVGElement("text");
1235
- setAttrs(text, { x: element.x, y: element.y + textAscent3(element.style.fontSize) });
1236
- applyTextStyle(text, element.style);
1237
- text.setAttribute("class", className);
1238
- text.setAttribute("data-chrome-key", chromeKey);
1239
- const renderedText = uppercase ? element.text.toUpperCase() : element.text;
1240
- const lines = wrapText(
1241
- renderedText,
1242
- element.style.fontSize,
1243
- element.style.fontWeight,
1244
- element.maxWidth,
1245
- measureText
1246
- );
1247
- let truncated = false;
1248
- if (element.maxLines != null && lines.length > element.maxLines) {
1249
- truncated = true;
1250
- lines.length = element.maxLines;
1251
- const lastIndex = element.maxLines - 1;
1252
- const measure = measureText ? (text2, fontSize, fontWeight) => measureText(text2, fontSize, fontWeight).width : void 0;
1253
- const withEllipsis = `${lines[lastIndex]}\u2026`;
1254
- lines[lastIndex] = truncateToWidth(
1255
- withEllipsis,
1256
- element.maxWidth,
1257
- element.style.fontSize,
1258
- element.style.fontWeight,
1259
- measure
1260
- );
1261
- }
1262
- if (lines.length === 1 && !truncated) {
1263
- text.textContent = renderedText;
1264
- } else if (lines.length === 1) {
1265
- text.textContent = lines[0];
1266
- } else {
1267
- const lineHeight = element.style.fontSize * (element.style.lineHeight ?? 1.3);
1268
- for (let i = 0; i < lines.length; i++) {
1269
- const tspan = createSVGElement("tspan");
1270
- setAttrs(tspan, { x: element.x, dy: i === 0 ? 0 : lineHeight });
1271
- tspan.textContent = lines[i];
1272
- text.appendChild(tspan);
1273
- }
1274
- }
1275
- parent.appendChild(text);
1276
- }
1277
- function renderChrome(parent, layout) {
1278
- const g = createSVGElement("g");
1279
- g.setAttribute("class", "oc-chrome");
1280
- const { chrome, measureText } = layout;
1281
- if (chrome.rule) {
1282
- const rule = createSVGElement("rect");
1283
- rule.setAttribute("class", "oc-chrome-rule");
1284
- setAttrs(rule, {
1285
- x: chrome.rule.x,
1286
- y: chrome.rule.y,
1287
- width: chrome.rule.width,
1288
- height: chrome.rule.thickness
1289
- });
1290
- rule.setAttribute("fill", chrome.rule.color);
1291
- rule.setAttribute("shape-rendering", "crispEdges");
1292
- g.appendChild(rule);
1293
- }
1294
- if (chrome.eyebrow && chrome.rule) {
1295
- renderChromeElement(g, chrome.eyebrow, "oc-eyebrow", "eyebrow", measureText, true);
1296
- } else if (chrome.eyebrow) {
1297
- const eyebrow = chrome.eyebrow;
1298
- const dotR = 3;
1299
- const dotGap = 8;
1300
- const dotX = eyebrow.x + dotR;
1301
- const dotY = eyebrow.y + eyebrow.style.fontSize * 0.42;
1302
- const dot = createSVGElement("circle");
1303
- dot.setAttribute("class", "oc-eyebrow-dot");
1304
- setAttrs(dot, { cx: dotX, cy: dotY, r: dotR });
1305
- dot.setAttribute("fill", eyebrow.style.fill ?? "currentColor");
1306
- g.appendChild(dot);
1307
- const shifted = {
1308
- ...eyebrow,
1309
- x: eyebrow.x + dotR * 2 + dotGap
1310
- };
1311
- renderChromeElement(g, shifted, "oc-eyebrow", "eyebrow", measureText, true);
1312
- }
1313
- if (chrome.title) {
1314
- renderChromeElement(g, chrome.title, "oc-title", "title", measureText);
1315
- }
1316
- if (chrome.subtitle) {
1317
- renderChromeElement(g, chrome.subtitle, "oc-subtitle", "subtitle", measureText);
1318
- }
1319
- const bottomOffset = layout.chrome.bottomAnchorY ?? layout.area.y + layout.area.height;
1320
- const bandHeight = layout.chrome.noteBandHeight ?? computeNoteBandHeight2(layout.chrome, layout.theme);
1321
- let noteLine = 0;
1322
- if (chrome.footnotes && chrome.footnotes.length > 0) {
1323
- const fontSize = layout.theme.fonts.sizes.small;
1324
- const pad = layout.theme.spacing.padding;
1325
- const lineHeight = fontSize * FOOTNOTE_LINE_HEIGHT;
1326
- const style = {
1327
- fontFamily: layout.theme.fonts.family,
1328
- fontSize,
1329
- fontWeight: layout.theme.fonts.weights.normal,
1330
- fill: layout.theme.chrome.source.color,
1331
- lineHeight: FOOTNOTE_LINE_HEIGHT,
1332
- textAnchor: "start"
1333
- };
1334
- for (let i = 0; i < chrome.footnotes.length; i++) {
1335
- const f = chrome.footnotes[i];
1336
- const y = bottomOffset + layout.theme.spacing.chartToFooter + textAscent3(fontSize) + noteLine * lineHeight;
1337
- const el = createSVGElement("text");
1338
- el.setAttribute("class", "oc-footnotes");
1339
- if (f.specIndex !== void 0) el.setAttribute("data-note-spec-index", String(f.specIndex));
1340
- if (f.id !== void 0) el.setAttribute("data-note-id", f.id);
1341
- setAttrs(el, { x: pad, y });
1342
- applyTextStyle(el, style);
1343
- if (f.lines) {
1344
- f.lines.forEach((line, index) => {
1345
- const span = createSVGElement("tspan");
1346
- setAttrs(span, { x: pad, dy: index === 0 ? 0 : lineHeight });
1347
- span.textContent = line;
1348
- el.appendChild(span);
1349
- });
1350
- } else el.textContent = `${f.index}. ${f.text}`;
1351
- noteLine += f.lines?.length ?? 1;
1352
- g.appendChild(el);
1353
- }
1354
- }
1355
- let summaryLine = noteLine;
1356
- for (const entry of chrome.seriesSummary ?? []) {
1357
- const size = layout.theme.fonts.sizes.small;
1358
- const el = createSVGElement("text");
1359
- el.setAttribute("class", "oc-series-summary");
1360
- el.setAttribute("data-series", entry.key);
1361
- setAttrs(el, {
1362
- x: layout.theme.spacing.padding,
1363
- y: bottomOffset + layout.theme.spacing.chartToFooter + textAscent3(size) + summaryLine * size * FOOTNOTE_LINE_HEIGHT
1364
- });
1365
- applyTextStyle(el, {
1366
- fontFamily: layout.theme.fonts.family,
1367
- fontSize: size,
1368
- fontWeight: 500,
1369
- lineHeight: FOOTNOTE_LINE_HEIGHT,
1370
- fill: entry.color
1371
- });
1372
- entry.lines.forEach((line, index) => {
1373
- const span = createSVGElement("tspan");
1374
- setAttrs(span, {
1375
- x: layout.theme.spacing.padding,
1376
- dy: index === 0 ? 0 : size * FOOTNOTE_LINE_HEIGHT
1377
- });
1378
- span.textContent = line;
1379
- el.appendChild(span);
1380
- });
1381
- summaryLine += entry.lines.length;
1382
- g.appendChild(el);
1383
- }
1384
- if (chrome.source) {
1385
- renderChromeElement(
1386
- g,
1387
- { ...chrome.source, y: bottomOffset + chrome.source.y + bandHeight },
1388
- "oc-source",
1389
- "source",
1390
- measureText
1391
- );
1392
- }
1393
- if (chrome.byline) {
1394
- renderChromeElement(
1395
- g,
1396
- { ...chrome.byline, y: bottomOffset + chrome.byline.y + bandHeight },
1397
- "oc-byline",
1398
- "byline",
1399
- measureText
1400
- );
1401
- }
1402
- if (chrome.footer) {
1403
- renderChromeElement(
1404
- g,
1405
- { ...chrome.footer, y: bottomOffset + chrome.footer.y + bandHeight },
1406
- "oc-footer",
1407
- "footer",
1408
- measureText
1409
- );
1410
- }
1411
- if (chrome.brand) {
1412
- const brandY = bottomOffset + chrome.brand.y + bandHeight;
1413
- renderChromeElement(g, { ...chrome.brand, y: brandY }, "oc-brand", "brand", measureText);
1414
- }
1415
- parent.appendChild(g);
1416
- }
1417
-
1418
1271
  // src/renderers/endpoint-labels.ts
1419
1272
  var LEADER_STROKE_WIDTH = 1;
1420
1273
  var LEADER_OPACITY = 0.45;
@@ -1433,14 +1286,17 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
1433
1286
  entryG.setAttribute("data-endpoint-index", String(i));
1434
1287
  entryG.setAttribute("data-endpoint-key", entry.seriesKey);
1435
1288
  entryG.setAttribute("data-endpoint-side", side);
1436
- entryG.setAttribute("aria-label", `${entry.seriesKey}: ${entry.value}`);
1289
+ entryG.setAttribute(
1290
+ "aria-label",
1291
+ `${entry.seriesKey}: ${entry.value}${entry.date ? ` (${entry.date})` : ""}`
1292
+ );
1437
1293
  if (entry.showLeader) {
1438
1294
  const leader = createSVGElement("line");
1439
1295
  leader.setAttribute("class", "oc-endpoint-leader");
1440
1296
  setAttrs(leader, {
1441
1297
  x1: chipX,
1442
1298
  y1: entry.labelY + labelFontSize / 2,
1443
- x2: leaderAnchorX,
1299
+ x2: entry.dataX ?? leaderAnchorX,
1444
1300
  y2: entry.dataY,
1445
1301
  stroke: entry.color,
1446
1302
  "stroke-width": LEADER_STROKE_WIDTH,
@@ -1460,6 +1316,7 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
1460
1316
  "stroke-width": 2,
1461
1317
  "stroke-linecap": "round"
1462
1318
  });
1319
+ if (entry.strokeDasharray) line.setAttribute("stroke-dasharray", entry.strokeDasharray);
1463
1320
  entryG.appendChild(line);
1464
1321
  const label = createSVGElement("text");
1465
1322
  label.setAttribute("class", "oc-endpoint-label");
@@ -1485,6 +1342,15 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
1485
1342
  applyTextStyle(value, ep.valueStyle);
1486
1343
  value.textContent = entry.value;
1487
1344
  entryG.appendChild(value);
1345
+ if (entry.date) {
1346
+ const date = createSVGElement("text");
1347
+ date.setAttribute("class", "oc-endpoint-date");
1348
+ const dateY = valueY + (entry.value ? valueFontSize * (ep.valueStyle.lineHeight ?? 1.25) + ep.valueGap : 0);
1349
+ setAttrs(date, { x: textX, y: dateY });
1350
+ applyTextStyle(date, ep.valueStyle);
1351
+ date.textContent = entry.date;
1352
+ entryG.appendChild(date);
1353
+ }
1488
1354
  if (entry.marker) {
1489
1355
  const marker = createSVGElement("circle");
1490
1356
  marker.setAttribute("class", "oc-endpoint-marker");
@@ -1503,7 +1369,7 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
1503
1369
  }
1504
1370
  function renderEndpointLabels(parent, layout) {
1505
1371
  const ep = layout.endpointLabels;
1506
- if (!ep || ep.entries.length === 0) return;
1372
+ if (!ep || ep.entries.length === 0 && !ep.interior?.length) return;
1507
1373
  const chartArea = layout.area;
1508
1374
  const root = createSVGElement("g");
1509
1375
  root.setAttribute("class", "oc-endpoint-labels");
@@ -1515,11 +1381,32 @@ function renderEndpointLabels(parent, layout) {
1515
1381
  const chartLeftX = chartArea.x;
1516
1382
  renderColumn(root, ep.leading, ep.leadingBounds, ep, chartLeftX, "leading");
1517
1383
  }
1384
+ for (const entry of ep.interior ?? []) {
1385
+ const label = createSVGElement("text");
1386
+ label.setAttribute("class", "oc-area-interior-label");
1387
+ label.setAttribute("data-endpoint-key", entry.seriesKey);
1388
+ label.setAttribute("aria-label", entry.text);
1389
+ setAttrs(label, { x: entry.x, y: entry.y + (ep.labelStyle.fontSize ?? 11) });
1390
+ applyTextStyle(label, ep.labelStyle);
1391
+ label.style.setProperty("fill", entry.color);
1392
+ label.textContent = entry.text;
1393
+ root.appendChild(label);
1394
+ }
1518
1395
  parent.appendChild(root);
1519
1396
  }
1520
1397
 
1521
1398
  // src/renderers/legend.ts
1522
1399
  import { estimateTextWidth as estimateTextWidth2 } from "@opendata-ai/openchart-core";
1400
+ function renderKeyText(parent, legend) {
1401
+ for (const row of legend.textRows ?? []) {
1402
+ const text2 = createSVGElement("text");
1403
+ text2.setAttribute("class", `oc-legend-${row.role}`);
1404
+ setAttrs(text2, { x: row.x, y: row.y, "text-anchor": row.anchor ?? "start" });
1405
+ applyTextStyle(text2, row.style);
1406
+ text2.textContent = row.text;
1407
+ parent.appendChild(text2);
1408
+ }
1409
+ }
1523
1410
  var LEGEND_HIT_HEIGHT = 24;
1524
1411
  var LEGEND_HIT_PAD = 4;
1525
1412
  function isCategorical(legend) {
@@ -1555,7 +1442,16 @@ function renderContinuousLegend(parent, legend) {
1555
1442
  g.setAttribute("role", "img");
1556
1443
  const first = legend.ticks[0];
1557
1444
  const last = legend.ticks[legend.ticks.length - 1];
1558
- if (first && last) {
1445
+ if (legend.rangeEntries) {
1446
+ g.setAttribute(
1447
+ "aria-label",
1448
+ [
1449
+ "Color ranges",
1450
+ ...(legend.textRows ?? []).map((row) => row.text),
1451
+ ...legend.noData ? [legend.noData.label] : []
1452
+ ].join("; ")
1453
+ );
1454
+ } else if (first && last) {
1559
1455
  g.setAttribute("aria-label", `Color scale from ${first.label} to ${last.label}`);
1560
1456
  } else {
1561
1457
  g.setAttribute("aria-label", "Color scale");
@@ -1599,10 +1495,10 @@ function renderContinuousLegend(parent, legend) {
1599
1495
  const rect = createSVGElement("rect");
1600
1496
  rect.setAttribute("class", "oc-legend-bin");
1601
1497
  setAttrs(rect, {
1602
- x: bin.x,
1603
- y: legend.bar.y,
1604
- width: bin.width,
1605
- height: legend.bar.height,
1498
+ x: legend.rangeEntries?.[i]?.bounds.x ?? bin.x,
1499
+ y: legend.rangeEntries?.[i]?.bounds.y ?? legend.bar.y,
1500
+ width: legend.rangeEntries?.[i]?.bounds.width ?? bin.width,
1501
+ height: legend.rangeEntries?.[i]?.bounds.height ?? legend.bar.height,
1606
1502
  fill: bin.color,
1607
1503
  "shape-rendering": "crispEdges"
1608
1504
  });
@@ -1610,7 +1506,7 @@ function renderContinuousLegend(parent, legend) {
1610
1506
  g.appendChild(rect);
1611
1507
  }
1612
1508
  }
1613
- if (legend.title && legend.titleY !== void 0) {
1509
+ if (!legend.textRows?.some((row) => row.role === "title") && legend.title && legend.titleY !== void 0) {
1614
1510
  const title = createSVGElement("text");
1615
1511
  title.setAttribute("class", "oc-legend-title");
1616
1512
  setAttrs(title, { x: legend.bar.x, y: legend.titleY, "text-anchor": "start" });
@@ -1632,6 +1528,7 @@ function renderContinuousLegend(parent, legend) {
1632
1528
  if (legend.noData) {
1633
1529
  renderNoDataSwatch(g, legend.noData, legend.labelStyle);
1634
1530
  }
1531
+ renderKeyText(g, legend);
1635
1532
  parent.appendChild(g);
1636
1533
  }
1637
1534
  function renderSizeLegend(parent, legend) {
@@ -1643,7 +1540,7 @@ function renderSizeLegend(parent, legend) {
1643
1540
  const oy = legend.bounds.y;
1644
1541
  const labelX = ox + legend.circles[0].cx + legend.circles[0].radius + 8;
1645
1542
  const leaderX = ox + legend.circles[0].cx + legend.circles[0].radius + 4;
1646
- if (legend.title && legend.titleY !== void 0) {
1543
+ if (!legend.textRows?.some((row) => row.role === "title") && legend.title && legend.titleY !== void 0) {
1647
1544
  const title = createSVGElement("text");
1648
1545
  title.setAttribute("class", "oc-legend-title");
1649
1546
  setAttrs(title, { x: ox, y: oy + legend.titleY, "text-anchor": "start" });
@@ -1682,6 +1579,7 @@ function renderSizeLegend(parent, legend) {
1682
1579
  label.textContent = circle.label;
1683
1580
  g.appendChild(label);
1684
1581
  }
1582
+ renderKeyText(g, legend);
1685
1583
  parent.appendChild(g);
1686
1584
  }
1687
1585
  function renderLegend(parent, legend) {
@@ -1780,6 +1678,7 @@ function renderLegend(parent, legend) {
1780
1678
  "stroke-width": 2,
1781
1679
  "stroke-linecap": "round"
1782
1680
  });
1681
+ if (entry.strokeDasharray) line.setAttribute("stroke-dasharray", entry.strokeDasharray);
1783
1682
  entryG.appendChild(line);
1784
1683
  } else {
1785
1684
  const rectSize = Math.round(legend.swatchSize * 0.6);
@@ -1823,6 +1722,7 @@ function renderLegend(parent, legend) {
1823
1722
  if (legend.noData) {
1824
1723
  renderNoDataSwatch(g, legend.noData, legend.labelStyle, { rx: 2, baseline: "central" });
1825
1724
  }
1725
+ renderKeyText(g, legend);
1826
1726
  parent.appendChild(g);
1827
1727
  }
1828
1728
 
@@ -1979,11 +1879,11 @@ function renderChartSVG(layout, container, opts) {
1979
1879
  const stacks = /* @__PURE__ */ new Map();
1980
1880
  for (const mark of layout.marks) {
1981
1881
  if (mark.type !== "rect" || mark.stackPos === void 0 || !mark.key) continue;
1982
- const element = Array.from(clippedGroup.children).find(
1882
+ const element3 = Array.from(clippedGroup.children).find(
1983
1883
  (child) => child.getAttribute("data-key") === mark.key
1984
1884
  );
1985
- if (!element) continue;
1986
- const horizontal = element.getAttribute("data-orient") === "horizontal";
1885
+ if (!element3) continue;
1886
+ const horizontal = element3.getAttribute("data-orient") === "horizontal";
1987
1887
  const key = `${horizontal ? "h" : "v"}:${horizontal ? mark.y : mark.x}`;
1988
1888
  let stack = stacks.get(key);
1989
1889
  if (!stack) {
@@ -1994,10 +1894,10 @@ function renderChartSVG(layout, container, opts) {
1994
1894
  "data-orient": horizontal ? "horizontal" : "vertical",
1995
1895
  "data-animation-index": 0
1996
1896
  });
1997
- clippedGroup.insertBefore(stack, element);
1897
+ clippedGroup.insertBefore(stack, element3);
1998
1898
  stacks.set(key, stack);
1999
1899
  }
2000
- stack.appendChild(element);
1900
+ stack.appendChild(element3);
2001
1901
  }
2002
1902
  }
2003
1903
  let pointCircles = null;
@@ -2102,6 +2002,7 @@ function renderChartSVG(layout, container, opts) {
2102
2002
  }
2103
2003
  svg.style.position = "relative";
2104
2004
  }
2005
+ wireAnnotationNotes(svg);
2105
2006
  container.appendChild(svg);
2106
2007
  return svg;
2107
2008
  }
@@ -2164,20 +2065,1390 @@ function renderFacetedPanels(svg, layout, panels, defs) {
2164
2065
  }
2165
2066
  }
2166
2067
 
2068
+ // src/story/tween.ts
2069
+ var easingFns = {
2070
+ linear,
2071
+ easeOutCubic: cubicOut,
2072
+ easeInOutCubic: cubicInOut,
2073
+ easeOutQuint: (t) => 1 - (1 - t) ** 5
2074
+ };
2075
+ var storyMotion = {
2076
+ /** Small opacity/emphasis shifts */
2077
+ fast: 300,
2078
+ /** Step state transitions */
2079
+ base: 500,
2080
+ /** Whole-chart crossfade fallback (steps outside the morph gate) */
2081
+ crossfade: 400,
2082
+ /** Step-mode camera transitions */
2083
+ camera: 600,
2084
+ /** Scrub-mode camera damping time constant */
2085
+ cameraTau: 100
2086
+ };
2087
+ function createTween(config) {
2088
+ const {
2089
+ lerp: lerpT,
2090
+ duration = storyMotion.base,
2091
+ ease = easingFns.easeOutCubic,
2092
+ onFrame
2093
+ } = config;
2094
+ let current = config.initial;
2095
+ let rafId = 0;
2096
+ let running = false;
2097
+ const stop = () => {
2098
+ if (running) {
2099
+ cancelAnimationFrame(rafId);
2100
+ running = false;
2101
+ }
2102
+ };
2103
+ const to = (target, opts) => {
2104
+ stop();
2105
+ if (opts?.snap || duration <= 0) {
2106
+ current = target;
2107
+ onFrame(current);
2108
+ config.onComplete?.(current);
2109
+ return;
2110
+ }
2111
+ const from = current;
2112
+ const start = performance.now();
2113
+ running = true;
2114
+ const tick = (now) => {
2115
+ const t = clamp01((now - start) / duration);
2116
+ current = lerpT(from, target, ease(t));
2117
+ onFrame(current);
2118
+ if (t < 1) {
2119
+ rafId = requestAnimationFrame(tick);
2120
+ } else {
2121
+ running = false;
2122
+ config.onComplete?.(current);
2123
+ }
2124
+ };
2125
+ rafId = requestAnimationFrame(tick);
2126
+ };
2127
+ return { to, get: () => current, cancel: stop };
2128
+ }
2129
+
2130
+ // src/story/camera-math.ts
2131
+ var FULL_VIEW = (vb) => ({
2132
+ x: 0,
2133
+ y: 0,
2134
+ width: vb.width,
2135
+ height: vb.height
2136
+ });
2137
+ function fitTarget(target, vb) {
2138
+ const pad = target.padding ?? 0;
2139
+ const w = target.width + 2 * pad;
2140
+ const h = target.height + 2 * pad;
2141
+ return {
2142
+ cx: target.x + target.width / 2,
2143
+ cy: target.y + target.height / 2,
2144
+ k: Math.min(vb.width / w, vb.height / h)
2145
+ };
2146
+ }
2147
+ function interpolateCamera(a, b, t) {
2148
+ return {
2149
+ cx: lerp(a.cx, b.cx, t),
2150
+ cy: lerp(a.cy, b.cy, t),
2151
+ k: Math.exp(lerp(Math.log(a.k), Math.log(b.k), t))
2152
+ };
2153
+ }
2154
+ function cameraTransform(c, vb) {
2155
+ return `translate(${vb.width / 2} ${vb.height / 2}) scale(${c.k}) translate(${-c.cx} ${-c.cy})`;
2156
+ }
2157
+ function damp(current, target, tauMs, dtMs) {
2158
+ if (tauMs <= 0) return target;
2159
+ return current + (target - current) * (1 - Math.exp(-dtMs / tauMs));
2160
+ }
2161
+ function dampCamera(current, target, tauMs, dtMs) {
2162
+ return {
2163
+ cx: damp(current.cx, target.cx, tauMs, dtMs),
2164
+ cy: damp(current.cy, target.cy, tauMs, dtMs),
2165
+ // k damped in log space, same rationale as interpolateCamera
2166
+ k: Math.exp(damp(Math.log(current.k), Math.log(target.k), tauMs, dtMs))
2167
+ };
2168
+ }
2169
+ function camerasClose(a, b, epsilon = 1e-3) {
2170
+ return Math.abs(a.cx - b.cx) < epsilon && Math.abs(a.cy - b.cy) < epsilon && Math.abs(Math.log(a.k) - Math.log(b.k)) < epsilon;
2171
+ }
2172
+ function scrubCamera(step, stepProgress, fitted, holdUntil, ease) {
2173
+ const n = fitted.length;
2174
+ if (n === 0) return { cx: 0, cy: 0, k: 1 };
2175
+ const clamped = Math.min(Math.max(step, 0), n - 1);
2176
+ const current = fitted[clamped];
2177
+ const next = fitted[Math.min(clamped + 1, n - 1)];
2178
+ if (step < 0 || clamped >= n - 1 || stepProgress <= holdUntil) {
2179
+ return current;
2180
+ }
2181
+ const t = (stepProgress - holdUntil) / (1 - holdUntil);
2182
+ return interpolateCamera(current, next, ease(t));
2183
+ }
2184
+
2185
+ // src/map-camera.ts
2186
+ var FOCUS_DIM_OPACITY = 0.25;
2187
+ function focusTargetForFeatures(layout, ids, padding = 16) {
2188
+ const idSet = new Set(ids.map(String));
2189
+ let minX = Infinity;
2190
+ let minY = Infinity;
2191
+ let maxX = -Infinity;
2192
+ let maxY = -Infinity;
2193
+ let found = false;
2194
+ for (const f of layout.features) {
2195
+ if (idSet.has(String(f.id))) {
2196
+ found = true;
2197
+ minX = Math.min(minX, f.bounds.x);
2198
+ minY = Math.min(minY, f.bounds.y);
2199
+ maxX = Math.max(maxX, f.bounds.x + f.bounds.width);
2200
+ maxY = Math.max(maxY, f.bounds.y + f.bounds.height);
2201
+ }
2202
+ }
2203
+ if (!found) return null;
2204
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY, padding };
2205
+ }
2206
+ function cameraForTarget(layout, target) {
2207
+ const vb = layout.mapSize;
2208
+ if (!target) return fitTarget(FULL_VIEW(vb), vb);
2209
+ const cam = fitTarget(target, vb);
2210
+ return { ...cam, k: Math.max(1, Math.min(40, cam.k)) };
2211
+ }
2212
+ var DEFAULT_MAX_ZOOM = 12;
2213
+ function resolveMapZoom(zoom) {
2214
+ if (!zoom) return null;
2215
+ const cfg = zoom === true ? {} : zoom;
2216
+ const max = cfg.maxZoom;
2217
+ return {
2218
+ maxZoom: typeof max === "number" && Number.isFinite(max) ? Math.max(1, max) : DEFAULT_MAX_ZOOM,
2219
+ controls: cfg.controls !== false
2220
+ };
2221
+ }
2222
+ function clampMapCamera(camera, vb, maxZoom) {
2223
+ const k = Math.min(Math.max(camera.k, 1), Math.max(1, maxZoom));
2224
+ const halfW = vb.width / (2 * k);
2225
+ const halfH = vb.height / (2 * k);
2226
+ return {
2227
+ cx: Math.min(Math.max(camera.cx, halfW), vb.width - halfW),
2228
+ cy: Math.min(Math.max(camera.cy, halfH), vb.height - halfH),
2229
+ k
2230
+ };
2231
+ }
2232
+ function zoomCameraAt(camera, vb, k, pivotX, pivotY) {
2233
+ const ox = pivotX - vb.width / 2;
2234
+ const oy = pivotY - vb.height / 2;
2235
+ const px = camera.cx + ox / camera.k;
2236
+ const py = camera.cy + oy / camera.k;
2237
+ return { cx: px - ox / k, cy: py - oy / k, k };
2238
+ }
2239
+ function panCamera(camera, dx, dy) {
2240
+ return { cx: camera.cx - dx / camera.k, cy: camera.cy - dy / camera.k, k: camera.k };
2241
+ }
2242
+ function wheelZoomFactor(e) {
2243
+ const perUnit = e.deltaMode === 1 ? 0.05 : e.deltaMode === 2 ? 1 : 2e-3;
2244
+ let exp = -e.deltaY * perUnit;
2245
+ if (e.ctrlKey && e.deltaMode === 0 && Math.abs(e.deltaY) < 50) exp *= 5;
2246
+ return 2 ** Math.max(-1, Math.min(1, exp));
2247
+ }
2248
+ function applyMapCamera(svg, camera, layout) {
2249
+ const scope = svg.querySelector('[data-geo-view-id="root"]') ?? svg;
2250
+ const cameraGroup = scope.querySelector("[data-oc-map-camera]");
2251
+ if (!cameraGroup) return;
2252
+ const vb = layout.mapSize;
2253
+ const isZoomed = Math.abs(camera.k - 1) > 1e-3;
2254
+ if (isZoomed) {
2255
+ cameraGroup.setAttribute("transform", cameraTransform(camera, vb));
2256
+ const paths = scope.querySelectorAll(".oc-map-feature, .oc-map-borders path");
2257
+ for (const p of paths) {
2258
+ p.setAttribute("vector-effect", "non-scaling-stroke");
2259
+ }
2260
+ const points = scope.querySelectorAll(".oc-map-point");
2261
+ for (const p of points) {
2262
+ const baseR = Number(p.getAttribute("data-base-r") ?? 5);
2263
+ const baseSW = Number(p.getAttribute("data-base-stroke-width") ?? 1);
2264
+ p.setAttribute("r", String(baseR / camera.k));
2265
+ p.setAttribute("stroke-width", String(baseSW / camera.k));
2266
+ }
2267
+ } else {
2268
+ cameraGroup.removeAttribute("transform");
2269
+ const paths = scope.querySelectorAll(".oc-map-feature, .oc-map-borders path");
2270
+ for (const p of paths) {
2271
+ p.removeAttribute("vector-effect");
2272
+ }
2273
+ const points = scope.querySelectorAll(".oc-map-point");
2274
+ for (const p of points) {
2275
+ const baseR = Number(p.getAttribute("data-base-r") ?? 5);
2276
+ const baseSW = Number(p.getAttribute("data-base-stroke-width") ?? 1);
2277
+ p.setAttribute("r", String(baseR));
2278
+ p.setAttribute("stroke-width", String(baseSW));
2279
+ p.removeAttribute("vector-effect");
2280
+ }
2281
+ }
2282
+ }
2283
+ function ensureMapClip(svg, layout, clipId) {
2284
+ if (svg.querySelector(`#${clipId}`)) return;
2285
+ let defs = svg.querySelector("defs");
2286
+ if (!defs) {
2287
+ defs = document.createElementNS("http://www.w3.org/2000/svg", "defs");
2288
+ svg.insertBefore(defs, svg.firstChild);
2289
+ }
2290
+ const clip = document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
2291
+ clip.setAttribute("id", clipId);
2292
+ const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
2293
+ rect.setAttribute("width", String(layout.area.width));
2294
+ rect.setAttribute("height", String(layout.area.height));
2295
+ clip.appendChild(rect);
2296
+ defs.appendChild(clip);
2297
+ }
2298
+
2299
+ // src/map-color-key.ts
2300
+ import { buildD3Formatter, formatNumber } from "@opendata-ai/openchart-core";
2301
+ import { geoColorKeyPosition } from "@opendata-ai/openchart-engine";
2302
+ var NS = "http://www.w3.org/2000/svg";
2303
+ var node = (tag, attrs, content) => {
2304
+ const el = document.createElementNS(NS, tag);
2305
+ for (const [key, value] of Object.entries(attrs)) el.setAttribute(key, String(value));
2306
+ if (content !== void 0) el.textContent = content;
2307
+ return el;
2308
+ };
2309
+ var text = (layout, x, y, value) => node(
2310
+ "text",
2311
+ {
2312
+ x,
2313
+ y,
2314
+ fill: layout.theme.colors.text,
2315
+ "font-family": layout.theme.fonts.family,
2316
+ "font-size": layout.theme.fonts.sizes.small
2317
+ },
2318
+ value
2319
+ );
2320
+ function renderStaticGeoColorKeys(svg, layout) {
2321
+ if (!layout.colorKeys) return;
2322
+ for (const [scope, key] of Object.entries(layout.colorKeys)) {
2323
+ const bounds = key?.distributionBounds;
2324
+ if (!key?.distribution || !bounds) continue;
2325
+ const group = node("g", { "data-geo-distribution": scope, role: "img" });
2326
+ const line = Math.ceil(layout.theme.fonts.sizes.small * 1.4);
2327
+ const noun = scope === "features" ? "Regions" : "Points";
2328
+ group.append(
2329
+ text(layout, bounds.x, bounds.y + layout.theme.fonts.sizes.small, `${noun} per range`)
2330
+ );
2331
+ group.append(
2332
+ text(
2333
+ layout,
2334
+ bounds.x,
2335
+ bounds.y + line + layout.theme.fonts.sizes.small,
2336
+ `No data: ${key.missing}`
2337
+ )
2338
+ );
2339
+ const bars = key.kind === "categorical" ? key.categories.map((category, index) => ({
2340
+ count: category.count,
2341
+ color: category.color,
2342
+ label: category.value,
2343
+ x: bounds.x + index * bounds.width / Math.max(1, key.categories.length),
2344
+ width: bounds.width / Math.max(1, key.categories.length)
2345
+ })) : key.classes.map((bin, index) => ({
2346
+ ...bin,
2347
+ x: bounds.x + index * bounds.width / Math.max(1, key.classes.length),
2348
+ width: bounds.width / Math.max(1, key.classes.length),
2349
+ label: `${bin.lower ?? "\u2212\u221E"} to ${bin.upper ?? "\u221E"}`
2350
+ }));
2351
+ const max = Math.max(1, ...bars.map((bar) => bar.count));
2352
+ const chartY = bounds.y + line * 2 + 4;
2353
+ for (const bar of bars) {
2354
+ const height = 20 * bar.count / max;
2355
+ const rectangle = node("rect", {
2356
+ x: bar.x,
2357
+ y: chartY + 20 - height,
2358
+ width: Math.max(1, bar.width - 2),
2359
+ height,
2360
+ fill: bar.color
2361
+ });
2362
+ rectangle.append(node("title", {}, `${bar.label}: ${bar.count} ${noun.toLowerCase()}`));
2363
+ group.append(rectangle);
2364
+ const label = text(
2365
+ layout,
2366
+ bar.x + bar.width / 2,
2367
+ chartY + 20 + layout.theme.fonts.sizes.small,
2368
+ String(bar.count)
2369
+ );
2370
+ label.setAttribute("text-anchor", "middle");
2371
+ group.append(label);
2372
+ }
2373
+ group.setAttribute(
2374
+ "aria-label",
2375
+ `${noun} per range. ${bars.map((bar) => `${bar.label}: ${bar.count}`).join("; ")}. No data: ${key.missing}.`
2376
+ );
2377
+ svg.append(group);
2378
+ }
2379
+ }
2380
+ function renderActiveGeoColorKeys(parent, layout, index, selection) {
2381
+ if (!layout.colorKeys) return;
2382
+ const active = selection.pinned.length ? selection.pinned : selection.preview ? [selection.preview] : [];
2383
+ for (const [scope, key] of Object.entries(layout.colorKeys)) {
2384
+ if (!key?.activeValue) continue;
2385
+ for (const [slot, observation] of active.entries()) {
2386
+ if (scope === "features" !== (observation.entity.kind === "feature")) continue;
2387
+ const record = index.byObservation.get(observation.observation);
2388
+ const row = key.activeRows[slot];
2389
+ if (!record || !row) continue;
2390
+ const value = record.color?.value;
2391
+ const position = geoColorKeyPosition(key, value);
2392
+ const format = key.format ? buildD3Formatter(key.format) : void 0;
2393
+ const exact = typeof value === "number" ? format ? format(value) : formatNumber(value) : value === "" ? "(empty)" : String(value ?? "No data");
2394
+ const suffix = position.missing ? "No data" : `${exact}${position.outside ? " \xB7 outside displayed range" : ""}`;
2395
+ const lines = key.activeLabels?.[`${typeof value}:${String(value)}`] ?? [`A: ${suffix}`];
2396
+ const advance = Math.ceil(layout.theme.fonts.sizes.small * 1.4);
2397
+ for (const [lineIndex, line] of lines.entries()) {
2398
+ const label = text(
2399
+ layout,
2400
+ row.x,
2401
+ row.y + layout.theme.fonts.sizes.small + lineIndex * advance,
2402
+ lineIndex === 0 ? line.replace(/^A:/, `${slot === 0 ? "A" : "B"}:`) : line
2403
+ );
2404
+ label.setAttribute("data-geo-active-value", scope);
2405
+ if (key.kind === "binned") {
2406
+ const title = node(
2407
+ "title",
2408
+ {},
2409
+ `${suffix}; marker identifies the range containing this value`
2410
+ );
2411
+ label.append(title);
2412
+ }
2413
+ parent.append(label);
2414
+ }
2415
+ if (position.category !== void 0) {
2416
+ const category = key.categories.find((category2) => category2.value === position.category);
2417
+ if (category)
2418
+ parent.append(
2419
+ node("rect", {
2420
+ ...category.bounds,
2421
+ fill: "none",
2422
+ stroke: layout.theme.colors.text,
2423
+ "stroke-width": 2
2424
+ })
2425
+ );
2426
+ } else if (position.x !== void 0 && key.bar)
2427
+ parent.append(
2428
+ node("path", {
2429
+ d: position.y === void 0 ? `M${position.x - 3},${key.bar.y - 4} L${position.x},${key.bar.y} L${position.x + 3},${key.bar.y - 4}` : `M${position.x - 14},${position.y - 3} L${position.x - 10},${position.y} L${position.x - 14},${position.y + 3}`,
2430
+ stroke: layout.theme.colors.text,
2431
+ "stroke-width": 2,
2432
+ fill: "none"
2433
+ })
2434
+ );
2435
+ }
2436
+ }
2437
+ }
2438
+
2439
+ // src/map-labels.ts
2440
+ import { resolveGeoOverlay } from "@opendata-ai/openchart-engine";
2441
+
2442
+ // src/dom-helpers.ts
2443
+ function applySrOnlyStyles(el) {
2444
+ el.style.position = "absolute";
2445
+ el.style.top = "0";
2446
+ el.style.left = "0";
2447
+ el.style.width = "1px";
2448
+ el.style.height = "1px";
2449
+ el.style.padding = "0";
2450
+ el.style.margin = "-1px";
2451
+ el.style.overflow = "clip";
2452
+ el.style.clipPath = "inset(50%)";
2453
+ el.style.whiteSpace = "nowrap";
2454
+ el.style.borderWidth = "0";
2455
+ }
2456
+
2457
+ // src/map-label-inventory.ts
2458
+ var explanations = {
2459
+ visible: "Visible on map",
2460
+ collision: "Omitted to avoid overlapping labels",
2461
+ "zoom-range": "Visible at another zoom level",
2462
+ offscreen: "Outside the current map view",
2463
+ unresolved: "Anchor could not be resolved",
2464
+ "geometry-budget": "Limited geographic label geometry"
2465
+ };
2466
+ var limitations = {
2467
+ "candidate-limit": "Visual label candidate limit reached",
2468
+ "vertex-limit": "Canonical anchor used because the projected geometry budget was reached",
2469
+ "search-limit": "Interior anchor search limit reached"
2470
+ };
2471
+ function geographicInventoryText(entry) {
2472
+ const anchor = entry.anchor.kind === "coordinate" ? `${entry.anchor.space} coordinate ${entry.anchor.x}, ${entry.anchor.y}` : `${entry.anchor.kind} ${entry.anchor.id}`;
2473
+ return `${entry.id}: ${entry.text}${entry.subtitle ? `. ${entry.subtitle}` : ""}. ${anchor}. ${explanations[entry.visibility]}${entry.presentation === "note" ? "; available in map notes" : ""}${entry.limitation ? `. ${limitations[entry.limitation]}` : ""}.`;
2474
+ }
2475
+ function mergeGeoLabelInventory(entries) {
2476
+ const merged = /* @__PURE__ */ new Map();
2477
+ for (const entry of entries) {
2478
+ const prior = merged.get(entry.id);
2479
+ if (!prior || entry.visibility === "visible" && prior.visibility !== "visible")
2480
+ merged.set(entry.id, entry);
2481
+ }
2482
+ return [...merged.values()];
2483
+ }
2484
+ function createMapLabelInventory(container, initial) {
2485
+ let id;
2486
+ let hidden = null;
2487
+ let disclosure = null;
2488
+ let options = initial;
2489
+ let entries = [];
2490
+ let svg = null;
2491
+ let theme;
2492
+ const fill = (target) => {
2493
+ const list = document.createElement("ul");
2494
+ for (const entry of entries) {
2495
+ const item = document.createElement("li");
2496
+ item.textContent = geographicInventoryText(entry);
2497
+ list.appendChild(item);
2498
+ }
2499
+ target.appendChild(list);
2500
+ };
2501
+ const detachAssociation = () => {
2502
+ if (!svg) return;
2503
+ const ids = (svg.getAttribute("aria-describedby") ?? "").split(/\s+/).filter((value) => value && value !== id);
2504
+ if (ids.length) svg.setAttribute("aria-describedby", ids.join(" "));
2505
+ else svg.removeAttribute("aria-describedby");
2506
+ };
2507
+ const refresh = () => {
2508
+ detachAssociation();
2509
+ if (!entries.length) {
2510
+ hidden?.remove();
2511
+ hidden = null;
2512
+ disclosure?.remove();
2513
+ disclosure = null;
2514
+ return;
2515
+ }
2516
+ if (!hidden) {
2517
+ id ??= nextSvgId("oc-map-label-inventory");
2518
+ hidden = document.createElement("div");
2519
+ hidden.id = id;
2520
+ hidden.className = "oc-map-label-inventory oc-sr-only";
2521
+ applySrOnlyStyles(hidden);
2522
+ container.appendChild(hidden);
2523
+ }
2524
+ hidden.replaceChildren();
2525
+ fill(hidden);
2526
+ if (svg)
2527
+ svg.setAttribute(
2528
+ "aria-describedby",
2529
+ [svg.getAttribute("aria-describedby"), id].filter(Boolean).join(" ")
2530
+ );
2531
+ if (options) {
2532
+ if (!disclosure) {
2533
+ disclosure = document.createElement("details");
2534
+ const summary = document.createElement("summary");
2535
+ summary.textContent = "Map places and notes";
2536
+ disclosure.appendChild(summary);
2537
+ }
2538
+ if (theme) {
2539
+ Object.assign(disclosure.style, {
2540
+ fontFamily: theme.fonts.family,
2541
+ fontSize: `${theme.fonts.sizes.body}px`,
2542
+ lineHeight: "1.5",
2543
+ color: theme.colors.text,
2544
+ padding: "12px 0"
2545
+ });
2546
+ Object.assign(disclosure.firstElementChild.style, {
2547
+ cursor: "pointer",
2548
+ fontWeight: "600",
2549
+ padding: "4px 0"
2550
+ });
2551
+ }
2552
+ const open = disclosure.open;
2553
+ while (disclosure.children.length > 1) disclosure.lastElementChild?.remove();
2554
+ fill(disclosure);
2555
+ disclosure.open = open;
2556
+ options.container.appendChild(disclosure);
2557
+ } else {
2558
+ disclosure?.remove();
2559
+ disclosure = null;
2560
+ }
2561
+ };
2562
+ return {
2563
+ update(nextSvg, next, nextTheme) {
2564
+ theme = nextTheme;
2565
+ detachAssociation();
2566
+ svg = nextSvg;
2567
+ entries = next;
2568
+ refresh();
2569
+ },
2570
+ setOptions(next) {
2571
+ options = next;
2572
+ refresh();
2573
+ },
2574
+ destroy() {
2575
+ detachAssociation();
2576
+ hidden?.remove();
2577
+ disclosure?.remove();
2578
+ hidden = null;
2579
+ disclosure = null;
2580
+ svg = null;
2581
+ entries = [];
2582
+ }
2583
+ };
2584
+ }
2585
+
2586
+ // src/map-labels.ts
2587
+ var NS2 = "http://www.w3.org/2000/svg";
2588
+ function element(tag, attrs = {}) {
2589
+ const el = document.createElementNS(NS2, tag);
2590
+ for (const [key, value] of Object.entries(attrs)) el.setAttribute(key, String(value));
2591
+ return el;
2592
+ }
2593
+ function mapLabelAffine(camera, layout) {
2594
+ return {
2595
+ k: camera.k,
2596
+ tx: layout.mapSize.width / 2 - camera.cx * camera.k,
2597
+ ty: layout.mapSize.height / 2 - camera.cy * camera.k
2598
+ };
2599
+ }
2600
+ function textBlock(parent, block, x, y, halo) {
2601
+ for (const line of block.lines) {
2602
+ const text2 = element("text", {
2603
+ x: x + line.x,
2604
+ y: y + line.y,
2605
+ "font-family": line.style.fontFamily,
2606
+ "font-size": line.style.fontSize,
2607
+ "font-weight": line.style.fontWeight,
2608
+ fill: line.style.fill,
2609
+ "text-anchor": line.style.textAnchor ?? "start",
2610
+ stroke: halo,
2611
+ "stroke-width": 2,
2612
+ "stroke-opacity": 0.85,
2613
+ "paint-order": "stroke fill",
2614
+ "stroke-linejoin": "round"
2615
+ });
2616
+ if (line.style.fontVariant) text2.setAttribute("font-variant", line.style.fontVariant);
2617
+ text2.textContent = line.text;
2618
+ parent.appendChild(text2);
2619
+ }
2620
+ }
2621
+ function projectAcceptedGeoOverlay(accepted, from, to, layout) {
2622
+ const move = (p) => ({
2623
+ x: (p.x - from.tx) / from.k * to.k + to.tx,
2624
+ y: (p.y - from.ty) / from.k * to.k + to.ty
2625
+ });
2626
+ const viewport = layout.labels?.viewport ?? {
2627
+ x: 0,
2628
+ y: 0,
2629
+ width: layout.area.width,
2630
+ height: layout.area.height
2631
+ };
2632
+ const visible = (p) => p.x >= viewport.x && p.y >= viewport.y && p.x <= viewport.x + viewport.width && p.y <= viewport.y + viewport.height;
2633
+ const candidates = new Map(layout.labels?.candidates.map((c) => [c.id, c]));
2634
+ const zoomVisible = (id) => {
2635
+ const candidate = candidates.get(id);
2636
+ return to.k >= (candidate?.minZoom ?? 1) && (candidate?.maxZoom === void 0 || to.k <= candidate.maxZoom);
2637
+ };
2638
+ const labels = accepted.labels.flatMap((label) => {
2639
+ const anchor = move(label.anchor);
2640
+ const bounds = {
2641
+ ...label.bounds,
2642
+ x: label.bounds.x + anchor.x - label.anchor.x,
2643
+ y: label.bounds.y + anchor.y - label.anchor.y
2644
+ };
2645
+ return visible(anchor) && bounds.x >= viewport.x && bounds.y >= viewport.y && bounds.x + bounds.width <= viewport.x + viewport.width && bounds.y + bounds.height <= viewport.y + viewport.height && zoomVisible(label.id) ? [{ ...label, anchor, bounds }] : [];
2646
+ });
2647
+ const ids = new Set(labels.map((label) => label.id));
2648
+ const acceptedById = new Map(accepted.labels.map((label) => [label.id, label]));
2649
+ return {
2650
+ ...accepted,
2651
+ labels,
2652
+ leaders: accepted.leaders.filter((leader) => ids.has(leader.id)).map((leader) => {
2653
+ const label = acceptedById.get(leader.id);
2654
+ const anchor = move(label.anchor);
2655
+ return {
2656
+ ...leader,
2657
+ from: move(leader.from),
2658
+ to: {
2659
+ x: leader.to.x + anchor.x - label.anchor.x,
2660
+ y: leader.to.y + anchor.y - label.anchor.y
2661
+ }
2662
+ };
2663
+ }),
2664
+ markers: accepted.markers.map((marker) => ({ ...marker, anchor: move(marker.anchor) })).filter((marker) => visible(marker.anchor) && zoomVisible(marker.id)),
2665
+ inventory: accepted.inventory.map(
2666
+ (entry) => entry.presentation === "label" && !ids.has(entry.id) ? {
2667
+ ...entry,
2668
+ visibility: zoomVisible(entry.id) ? "offscreen" : "zoom-range",
2669
+ presentation: "none"
2670
+ } : entry
2671
+ )
2672
+ };
2673
+ }
2674
+ function renderGeoLabelOverlay(svg, layout, overlay) {
2675
+ svg.querySelector(".oc-map-labels")?.remove();
2676
+ svg.querySelector(".oc-map-label-notes")?.remove();
2677
+ if (!layout.labels) return;
2678
+ const group = element("g", {
2679
+ class: "oc-map-labels",
2680
+ "pointer-events": "none",
2681
+ "aria-hidden": "true",
2682
+ transform: `translate(${layout.area.x},${layout.area.y})`
2683
+ });
2684
+ const clipId = nextSvgId("oc-map-label-clip");
2685
+ const defs = element("defs");
2686
+ const clip = element("clipPath", { id: clipId });
2687
+ clip.appendChild(element("rect", { ...layout.labels.viewport }));
2688
+ defs.appendChild(clip);
2689
+ group.appendChild(defs);
2690
+ const viewport = element("g", { "clip-path": `url(#${clipId})` });
2691
+ group.appendChild(viewport);
2692
+ const halo = layout.theme.colors.background === "transparent" ? "var(--oc-bg, #fff)" : layout.theme.colors.background;
2693
+ for (const leader of overlay.leaders)
2694
+ viewport.appendChild(
2695
+ element("line", {
2696
+ x1: leader.from.x,
2697
+ y1: leader.from.y,
2698
+ x2: leader.to.x,
2699
+ y2: leader.to.y,
2700
+ stroke: layout.theme.colors.text,
2701
+ "stroke-opacity": 0.6,
2702
+ "stroke-width": 1
2703
+ })
2704
+ );
2705
+ for (const label of overlay.labels) {
2706
+ const item = element("g", { "data-geo-label-id": label.id });
2707
+ textBlock(item, label.block, label.bounds.x, label.bounds.y, halo);
2708
+ viewport.appendChild(item);
2709
+ }
2710
+ const markerRadius = layout.labels.markerRadius ?? 7 * layout.theme.fonts.sizes.small / 12;
2711
+ const markerScale = markerRadius / 7;
2712
+ for (const marker of overlay.markers) {
2713
+ const markerViewport = layout.labels.viewport;
2714
+ if (marker.anchor.x - markerRadius < markerViewport.x || marker.anchor.y - markerRadius < markerViewport.y || marker.anchor.x + markerRadius > markerViewport.x + markerViewport.width || marker.anchor.y + markerRadius > markerViewport.y + markerViewport.height)
2715
+ continue;
2716
+ const item = element("g", { "data-geo-note-id": marker.id });
2717
+ item.appendChild(
2718
+ element("circle", {
2719
+ cx: marker.anchor.x,
2720
+ cy: marker.anchor.y,
2721
+ r: markerRadius,
2722
+ fill: halo,
2723
+ stroke: layout.theme.colors.text
2724
+ })
2725
+ );
2726
+ const number = element("text", {
2727
+ x: marker.anchor.x,
2728
+ y: marker.anchor.y + 3 * markerScale,
2729
+ "font-size": 9 * markerScale,
2730
+ "font-family": layout.theme.fonts.family,
2731
+ "text-anchor": "middle",
2732
+ fill: layout.theme.colors.text
2733
+ });
2734
+ number.textContent = String(marker.number);
2735
+ item.appendChild(number);
2736
+ viewport.appendChild(item);
2737
+ }
2738
+ const mapGroup = svg.querySelector(".oc-map-group");
2739
+ mapGroup?.insertAdjacentElement("afterend", group);
2740
+ renderGeoLabelNotes(svg, layout, overlay.notes, group);
2741
+ }
2742
+ function renderGeoLabelNotes(svg, layout, entries, after) {
2743
+ const halo = layout.theme.colors.background === "transparent" ? "var(--oc-bg, #fff)" : layout.theme.colors.background;
2744
+ const notes = element("g", {
2745
+ class: "oc-map-label-notes",
2746
+ "aria-hidden": "true",
2747
+ transform: `translate(${layout.area.x},${layout.area.y})`
2748
+ });
2749
+ for (const { id, slot } of entries) {
2750
+ const item = element("g", { "data-geo-note-id": id });
2751
+ textBlock(item, slot.block, slot.bounds.x, slot.bounds.y, halo);
2752
+ notes.appendChild(item);
2753
+ }
2754
+ if (after) after.insertAdjacentElement("afterend", notes);
2755
+ else svg.appendChild(notes);
2756
+ }
2757
+ function describeGeoLabelInventory(svg, overlay) {
2758
+ const previous = svg.querySelector("desc[data-geo-label-inventory]");
2759
+ if (previous) {
2760
+ const ids2 = (svg.getAttribute("aria-describedby") ?? "").split(/\s+/).filter((id) => id && id !== previous.id);
2761
+ if (ids2.length) svg.setAttribute("aria-describedby", ids2.join(" "));
2762
+ else svg.removeAttribute("aria-describedby");
2763
+ previous.remove();
2764
+ }
2765
+ if (!overlay.inventory.length) return;
2766
+ const desc = element("desc", {
2767
+ "data-geo-label-inventory": "",
2768
+ id: nextSvgId("oc-map-label-description")
2769
+ });
2770
+ desc.textContent = `Map places and notes. ${overlay.inventory.map(geographicInventoryText).join(" ")}`;
2771
+ svg.appendChild(desc);
2772
+ const ids = (svg.getAttribute("aria-describedby") ?? "").split(/\s+/).filter(Boolean);
2773
+ svg.setAttribute("aria-describedby", [...ids, desc.id].join(" "));
2774
+ }
2775
+ function resolveMapLabelOverlay(layout, camera) {
2776
+ return layout.labels ? resolveGeoOverlay(layout.labels, mapLabelAffine(camera, layout)) : void 0;
2777
+ }
2778
+
2779
+ // src/map-view-camera.ts
2780
+ function cameraForGeoView(view, target) {
2781
+ const camera = fitTarget(target ?? view.focus?.target ?? FULL_VIEW(view.mapSize), view.mapSize);
2782
+ return { ...camera, k: Math.max(1, Math.min(40, camera.k)) };
2783
+ }
2784
+ function createMapViewCameras(onFrame, onSettle) {
2785
+ const states = /* @__PURE__ */ new Map();
2786
+ let dead = false;
2787
+ const get = (id) => {
2788
+ const state = states.get(id);
2789
+ if (!state)
2790
+ throw new Error(
2791
+ `Unknown map view "${id}". Available views: ${[...states.keys()].join(", ") || "root"}.`
2792
+ );
2793
+ return state;
2794
+ };
2795
+ const cancelSettle = (state) => {
2796
+ if (state.settleFrame !== void 0) cancelAnimationFrame(state.settleFrame);
2797
+ state.settleFrame = void 0;
2798
+ };
2799
+ const validate = (camera) => {
2800
+ if (!Number.isFinite(camera.cx) || !Number.isFinite(camera.cy) || !Number.isFinite(camera.k) || camera.k <= 0)
2801
+ throw new Error("A map camera requires finite cx/cy and positive finite k.");
2802
+ };
2803
+ return {
2804
+ update(views) {
2805
+ if (dead) return;
2806
+ const ids = new Set(views.map((view) => view.viewId));
2807
+ for (const [id, state] of states)
2808
+ if (!ids.has(id)) {
2809
+ state.tween?.cancel();
2810
+ cancelSettle(state);
2811
+ states.delete(id);
2812
+ }
2813
+ for (const view of views) {
2814
+ const previous = states.get(view.viewId);
2815
+ if (previous) {
2816
+ previous.tween?.cancel();
2817
+ cancelSettle(previous);
2818
+ const oldSize = previous.view.mapSize;
2819
+ const changedFocus = JSON.stringify(previous.view.focus) !== JSON.stringify(view.focus);
2820
+ previous.camera = changedFocus ? cameraForGeoView(view) : {
2821
+ cx: previous.camera.cx * (oldSize.width ? view.mapSize.width / oldSize.width : 1),
2822
+ cy: previous.camera.cy * (oldSize.height ? view.mapSize.height / oldSize.height : 1),
2823
+ k: previous.camera.k
2824
+ };
2825
+ previous.view = view;
2826
+ previous.tween = void 0;
2827
+ } else states.set(view.viewId, { view, camera: cameraForGeoView(view) });
2828
+ }
2829
+ },
2830
+ has: (id) => states.has(id),
2831
+ view: (id) => get(id).view,
2832
+ get: (id) => ({ ...get(id).camera }),
2833
+ snapshots() {
2834
+ return Object.fromEntries([...states].map(([id, state]) => [id, { ...state.camera }]));
2835
+ },
2836
+ seed(id, camera) {
2837
+ validate(camera);
2838
+ const state = get(id);
2839
+ state.tween?.cancel();
2840
+ cancelSettle(state);
2841
+ state.tween = void 0;
2842
+ state.camera = { ...camera };
2843
+ },
2844
+ set(id, camera, settle = true) {
2845
+ if (dead) return;
2846
+ validate(camera);
2847
+ const state = get(id);
2848
+ state.tween?.cancel();
2849
+ cancelSettle(state);
2850
+ state.tween = void 0;
2851
+ state.camera = { ...camera };
2852
+ onFrame(id, { ...camera });
2853
+ if (settle && state.settleFrame === void 0)
2854
+ state.settleFrame = requestAnimationFrame(() => {
2855
+ state.settleFrame = void 0;
2856
+ if (!dead) onSettle(id);
2857
+ });
2858
+ },
2859
+ animate(id, camera, duration) {
2860
+ if (dead) return;
2861
+ validate(camera);
2862
+ const state = get(id);
2863
+ state.tween?.cancel();
2864
+ cancelSettle(state);
2865
+ state.tween = createTween({
2866
+ initial: state.camera,
2867
+ lerp: interpolateCamera,
2868
+ duration,
2869
+ ease: easingFns.easeInOutCubic,
2870
+ onFrame(next) {
2871
+ state.camera = next;
2872
+ onFrame(id, { ...next });
2873
+ },
2874
+ onComplete() {
2875
+ state.tween = void 0;
2876
+ onSettle(id);
2877
+ }
2878
+ });
2879
+ state.tween.to(camera);
2880
+ },
2881
+ settle(id) {
2882
+ const state = get(id);
2883
+ cancelSettle(state);
2884
+ if (!dead) onSettle(id);
2885
+ },
2886
+ destroy() {
2887
+ if (dead) return;
2888
+ dead = true;
2889
+ for (const state of states.values()) {
2890
+ state.tween?.cancel();
2891
+ cancelSettle(state);
2892
+ }
2893
+ states.clear();
2894
+ }
2895
+ };
2896
+ }
2897
+
2898
+ // src/map-view-renderer.ts
2899
+ var NS3 = "http://www.w3.org/2000/svg";
2900
+ var element2 = (tag, attrs = {}) => {
2901
+ const el = document.createElementNS(NS3, tag);
2902
+ for (const [key, value] of Object.entries(attrs)) el.setAttribute(key, String(value));
2903
+ return el;
2904
+ };
2905
+ function geoViewMapLayout(layout, view) {
2906
+ return {
2907
+ ...layout,
2908
+ views: void 0,
2909
+ area: {
2910
+ x: layout.area.x + view.viewport.x,
2911
+ y: layout.area.y + view.viewport.y,
2912
+ width: view.viewport.width,
2913
+ height: view.viewport.height
2914
+ },
2915
+ mapSize: view.mapSize,
2916
+ features: view.features,
2917
+ borders: view.borders,
2918
+ pointMarks: view.pointMarks,
2919
+ labels: view.labels,
2920
+ focus: view.focus
2921
+ };
2922
+ }
2923
+ function renderGeoMapViews(svg, layout, patterns, paint) {
2924
+ const overlays = /* @__PURE__ */ new Map();
2925
+ const inventory = [];
2926
+ for (const view of layout.views ?? []) {
2927
+ const frame = geoViewMapLayout(layout, view);
2928
+ const scene = element2("g", {
2929
+ class: "oc-map-view",
2930
+ "data-geo-view-id": view.viewId,
2931
+ role: "group",
2932
+ "aria-label": view.coverage ?? view.viewId
2933
+ });
2934
+ if (view.viewId !== "root") {
2935
+ scene.appendChild(
2936
+ element2("rect", {
2937
+ x: layout.area.x + view.frame.x,
2938
+ y: layout.area.y + view.frame.y,
2939
+ width: view.frame.width,
2940
+ height: view.frame.height,
2941
+ fill: resolvedSurface(layout.theme),
2942
+ stroke: layout.theme.colors.text,
2943
+ "stroke-opacity": 0.35,
2944
+ "stroke-width": 1
2945
+ })
2946
+ );
2947
+ if (view.label && view.labelBounds)
2948
+ for (const line of view.label.lines) {
2949
+ const label = element2("text", {
2950
+ x: layout.area.x + view.labelBounds.x + line.x,
2951
+ y: layout.area.y + view.labelBounds.y + line.y,
2952
+ fill: line.style.fill,
2953
+ "font-family": line.style.fontFamily,
2954
+ "font-size": line.style.fontSize,
2955
+ "font-weight": line.style.fontWeight
2956
+ });
2957
+ label.textContent = line.text;
2958
+ scene.appendChild(label);
2959
+ }
2960
+ }
2961
+ const mapGroup = element2("g", {
2962
+ class: "oc-map-group",
2963
+ transform: `translate(${frame.area.x},${frame.area.y})`
2964
+ });
2965
+ const defs = element2("defs"), clip = element2("clipPath", { id: nextSvgId("oc-map-view-clip") });
2966
+ clip.appendChild(element2("rect", { width: view.viewport.width, height: view.viewport.height }));
2967
+ defs.appendChild(clip);
2968
+ scene.appendChild(defs);
2969
+ mapGroup.setAttribute("clip-path", `url(#${clip.id})`);
2970
+ mapGroup.setAttribute("data-geo-view-clip", `url(#${clip.id})`);
2971
+ const camera = element2("g", { class: "oc-map-camera", "data-oc-map-camera": "" });
2972
+ paint.features(camera, view.features, patterns);
2973
+ for (const layer of view.detailLayers) {
2974
+ const detail = element2("g", {
2975
+ "data-geo-layer-id": layer.id,
2976
+ "data-min-zoom": layer.minZoom,
2977
+ ...layer.maxZoom !== void 0 ? { "data-max-zoom": layer.maxZoom } : {},
2978
+ "pointer-events": "none",
2979
+ "aria-hidden": "true",
2980
+ fill: "none",
2981
+ stroke: view.borders.interiorStroke,
2982
+ "stroke-width": view.borders.interiorWidth
2983
+ });
2984
+ for (const path of layer.paths)
2985
+ detail.appendChild(element2("path", { d: path, "vector-effect": "non-scaling-stroke" }));
2986
+ camera.appendChild(detail);
2987
+ }
2988
+ paint.borders(camera, view.borders);
2989
+ paint.points(camera, view.pointMarks);
2990
+ mapGroup.appendChild(camera);
2991
+ scene.appendChild(mapGroup);
2992
+ svg.appendChild(scene);
2993
+ const current = cameraForGeoView(view);
2994
+ applyMapCamera(scene, current, frame);
2995
+ applyGeoDetailVisibility(scene, current.k);
2996
+ const overlay = resolveMapLabelOverlay(frame, current);
2997
+ if (overlay) {
2998
+ renderGeoLabelOverlay(scene, frame, { ...overlay, notes: [] });
2999
+ overlays.set(view.viewId, overlay);
3000
+ inventory.push(...overlay.inventory);
3001
+ }
3002
+ }
3003
+ renderGeoViewNotes(svg, layout, overlays);
3004
+ if (inventory.length)
3005
+ describeGeoLabelInventory(svg, {
3006
+ labels: [],
3007
+ leaders: [],
3008
+ markers: [],
3009
+ notes: [],
3010
+ inventory: mergeGeoLabelInventory(inventory)
3011
+ });
3012
+ }
3013
+ function renderGeoViewNotes(svg, layout, overlays) {
3014
+ for (const node2 of svg.querySelectorAll(".oc-map-label-notes")) node2.remove();
3015
+ const seen = /* @__PURE__ */ new Set();
3016
+ for (const view of layout.views ?? []) {
3017
+ const entries = (overlays.get(view.viewId)?.notes ?? []).filter((note) => {
3018
+ if (seen.has(note.id)) return false;
3019
+ seen.add(note.id);
3020
+ return true;
3021
+ });
3022
+ if (entries.length) renderGeoLabelNotes(svg, geoViewMapLayout(layout, view), entries);
3023
+ }
3024
+ }
3025
+ function applyGeoDetailVisibility(scene, k) {
3026
+ for (const layer of scene.querySelectorAll("[data-geo-layer-id]")) {
3027
+ const min = Number(layer.getAttribute("data-min-zoom") ?? 1), max = Number(layer.getAttribute("data-max-zoom") ?? Infinity);
3028
+ if (k >= min && k <= max) layer.removeAttribute("display");
3029
+ else layer.setAttribute("display", "none");
3030
+ }
3031
+ }
3032
+ function findGeoViewScene(svg, id) {
3033
+ return [...svg.querySelectorAll("[data-geo-view-id]")].find(
3034
+ (scene) => scene.getAttribute("data-geo-view-id") === id
3035
+ ) ?? null;
3036
+ }
3037
+
3038
+ // src/map-renderer.ts
3039
+ var SVG_NS4 = "http://www.w3.org/2000/svg";
3040
+ var BULK_ANIMATION_THRESHOLD = 200;
3041
+ var LEGEND_BACKDROP_ALPHA = 0.5;
3042
+ function legendBackdrop(theme) {
3043
+ const surface = resolvedSurface(theme).trim();
3044
+ const hex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(surface);
3045
+ if (hex) {
3046
+ const h = hex[1];
3047
+ const full = h.length === 3 ? h.replace(/./g, (c) => c + c) : h;
3048
+ const r = Number.parseInt(full.slice(0, 2), 16);
3049
+ const g = Number.parseInt(full.slice(2, 4), 16);
3050
+ const b = Number.parseInt(full.slice(4, 6), 16);
3051
+ return `rgba(${r},${g},${b},${LEGEND_BACKDROP_ALPHA})`;
3052
+ }
3053
+ const rgb = /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i.exec(surface);
3054
+ if (rgb) {
3055
+ return `rgba(${rgb[1]},${rgb[2]},${rgb[3]},${LEGEND_BACKDROP_ALPHA})`;
3056
+ }
3057
+ return surface;
3058
+ }
3059
+ function createSVGElement2(tag) {
3060
+ return document.createElementNS(SVG_NS4, tag);
3061
+ }
3062
+ function setAttrs2(el, attrs) {
3063
+ for (const [key, value] of Object.entries(attrs)) {
3064
+ el.setAttribute(key, String(value));
3065
+ }
3066
+ }
3067
+ function renderChrome2(parent, layout) {
3068
+ const g = createSVGElement2("g");
3069
+ g.setAttribute("class", "oc-chrome");
3070
+ const { chrome, measureText } = layout;
3071
+ const bottomOffset = chrome.bottomAnchorY ?? layout.area.y + layout.area.height;
3072
+ if (chrome.title) {
3073
+ renderChromeElement(g, chrome.title, "oc-title", "title", measureText);
3074
+ }
3075
+ if (chrome.subtitle) {
3076
+ renderChromeElement(g, chrome.subtitle, "oc-subtitle", "subtitle", measureText);
3077
+ }
3078
+ if (chrome.source) {
3079
+ renderChromeElement(
3080
+ g,
3081
+ { ...chrome.source, y: bottomOffset + chrome.source.y },
3082
+ "oc-source",
3083
+ "source",
3084
+ measureText
3085
+ );
3086
+ }
3087
+ if (chrome.byline) {
3088
+ renderChromeElement(
3089
+ g,
3090
+ { ...chrome.byline, y: bottomOffset + chrome.byline.y },
3091
+ "oc-byline",
3092
+ "byline",
3093
+ measureText
3094
+ );
3095
+ }
3096
+ if (chrome.footer) {
3097
+ renderChromeElement(
3098
+ g,
3099
+ { ...chrome.footer, y: bottomOffset + chrome.footer.y },
3100
+ "oc-footer",
3101
+ "footer",
3102
+ measureText
3103
+ );
3104
+ }
3105
+ parent.appendChild(g);
3106
+ }
3107
+ function renderBorders(parent, borders) {
3108
+ const g = createSVGElement2("g");
3109
+ g.setAttribute("class", "oc-map-borders");
3110
+ if (borders.interiorPath) {
3111
+ const interior = createSVGElement2("path");
3112
+ setAttrs2(interior, {
3113
+ d: borders.interiorPath,
3114
+ fill: "none",
3115
+ stroke: borders.interiorStroke,
3116
+ "stroke-width": borders.interiorWidth,
3117
+ "stroke-linejoin": "round"
3118
+ });
3119
+ interior.setAttribute("class", "oc-map-border-interior");
3120
+ interior.setAttribute("pointer-events", "none");
3121
+ g.appendChild(interior);
3122
+ }
3123
+ if (borders.outlinePath) {
3124
+ const outline = createSVGElement2("path");
3125
+ setAttrs2(outline, {
3126
+ d: borders.outlinePath,
3127
+ fill: "none",
3128
+ stroke: borders.outlineStroke,
3129
+ "stroke-width": borders.outlineWidth,
3130
+ "stroke-linejoin": "round"
3131
+ });
3132
+ outline.setAttribute("class", "oc-map-border-outline");
3133
+ outline.setAttribute("pointer-events", "none");
3134
+ g.appendChild(outline);
3135
+ }
3136
+ parent.appendChild(g);
3137
+ }
3138
+ function renderFeatures(parent, features, animation, staggerBudget = 0, focusIds, patternMap) {
3139
+ const g = createSVGElement2("g");
3140
+ g.setAttribute("class", "oc-map-features");
3141
+ g.setAttribute("role", "list");
3142
+ const bulk = features.length > BULK_ANIMATION_THRESHOLD;
3143
+ if (bulk && animation?.enter) {
3144
+ g.setAttribute("data-bulk-animate", "");
3145
+ }
3146
+ const maxIdx = features.length - 1;
3147
+ const shuffledDelays = [];
3148
+ if (!bulk && staggerBudget > 0 && maxIdx > 0) {
3149
+ for (let i = 0; i <= maxIdx; i++) {
3150
+ shuffledDelays.push(i / maxIdx * staggerBudget);
3151
+ }
3152
+ let seed = 2654435769 ^ features.length * 2654435761;
3153
+ for (let i = maxIdx; i > 0; i--) {
3154
+ seed = seed + 1831565813 | 0;
3155
+ let t = seed ^ seed >>> 15;
3156
+ t = Math.imul(t, t | 1);
3157
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
3158
+ const r = ((t ^ t >>> 14) >>> 0) % (i + 1);
3159
+ [shuffledDelays[i], shuffledDelays[r]] = [shuffledDelays[r], shuffledDelays[i]];
3160
+ }
3161
+ }
3162
+ for (let i = 0; i < features.length; i++) {
3163
+ const feature = features[i];
3164
+ const path = createSVGElement2("path");
3165
+ path.setAttribute("class", "oc-map-feature");
3166
+ path.setAttribute("role", "listitem");
3167
+ const fill = feature.pattern && patternMap ? resolvePatternFill(feature.pattern, patternMap) : feature.fill;
3168
+ setAttrs2(path, {
3169
+ d: feature.path,
3170
+ fill,
3171
+ stroke: feature.stroke,
3172
+ "stroke-width": feature.strokeWidth
3173
+ });
3174
+ path.setAttribute("data-feature-id", String(feature.id));
3175
+ if (feature.noData) {
3176
+ path.setAttribute("data-nodata", "true");
3177
+ }
3178
+ path.setAttribute("data-key", String(feature.id));
3179
+ if (feature.binIndex !== void 0) {
3180
+ path.setAttribute("data-bin-index", String(feature.binIndex));
3181
+ }
3182
+ if (feature.name) {
3183
+ path.setAttribute("data-feature-name", feature.name);
3184
+ }
3185
+ if (feature.aria?.label) {
3186
+ path.setAttribute("aria-label", feature.aria.label);
3187
+ }
3188
+ const dimmed = focusIds ? !focusIds.has(String(feature.id)) : false;
3189
+ const s = path.style;
3190
+ if (dimmed) {
3191
+ s.setProperty("opacity", String(FOCUS_DIM_OPACITY));
3192
+ }
3193
+ if (!bulk && animation?.enter) {
3194
+ const idx = feature.animationIndex ?? i;
3195
+ path.setAttribute("data-animation-index", String(idx));
3196
+ s.setProperty("--oc-mark-index", String(idx));
3197
+ s.setProperty("--oc-feature-fill", fill);
3198
+ if (dimmed) {
3199
+ s.setProperty("--oc-feature-target-opacity", String(FOCUS_DIM_OPACITY));
3200
+ }
3201
+ if (staggerBudget > 0 && maxIdx > 0) {
3202
+ s.setProperty("--oc-map-delay", `${shuffledDelays[i]}ms`);
3203
+ }
3204
+ }
3205
+ g.appendChild(path);
3206
+ }
3207
+ parent.appendChild(g);
3208
+ }
3209
+ function renderPointMarks(parent, points, animation) {
3210
+ if (points.length === 0) return;
3211
+ const g = createSVGElement2("g");
3212
+ g.setAttribute("class", "oc-map-points");
3213
+ for (const pt of points) {
3214
+ const circle = createSVGElement2("circle");
3215
+ circle.setAttribute("class", "oc-map-point");
3216
+ setAttrs2(circle, {
3217
+ cx: pt.cx,
3218
+ cy: pt.cy,
3219
+ r: pt.r,
3220
+ fill: pt.fill,
3221
+ "fill-opacity": pt.fillOpacity,
3222
+ stroke: pt.stroke,
3223
+ "stroke-width": pt.strokeWidth
3224
+ });
3225
+ circle.setAttribute("data-point-key", pt.key);
3226
+ circle.setAttribute("data-base-r", String(pt.r));
3227
+ circle.setAttribute("data-base-stroke-width", String(pt.strokeWidth));
3228
+ if (pt.aria?.label) {
3229
+ circle.setAttribute("aria-label", pt.aria.label);
3230
+ }
3231
+ if (animation?.enter) {
3232
+ const s = circle.style;
3233
+ s.setProperty("--oc-mark-index", String(pt.animationIndex));
3234
+ s.setProperty("transform-origin", `${pt.cx}px ${pt.cy}px`);
3235
+ }
3236
+ g.appendChild(circle);
3237
+ }
3238
+ parent.appendChild(g);
3239
+ }
3240
+ function renderMapSVG(layout, opts) {
3241
+ const { width, height, features, borders, a11y, animation } = layout;
3242
+ const animate = opts?.animate && !!animation?.enter;
3243
+ const svg = createSVGElement2("svg");
3244
+ svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
3245
+ svg.setAttribute("role", "img");
3246
+ if (a11y.altText) {
3247
+ svg.setAttribute("aria-label", a11y.altText);
3248
+ }
3249
+ const classes = animate ? "oc-map oc-animate" : "oc-map";
3250
+ svg.setAttribute("class", classes);
3251
+ stampThemeProperties(svg, layout.theme);
3252
+ const background = createSVGElement2("rect");
3253
+ setAttrs2(background, {
3254
+ width,
3255
+ height,
3256
+ fill: layout.theme.colors.background,
3257
+ "aria-hidden": "true"
3258
+ });
3259
+ svg.appendChild(background);
3260
+ const bulk = features.length > BULK_ANIMATION_THRESHOLD;
3261
+ let mapStaggerBudget = 0;
3262
+ if (animate && animation?.enter) {
3263
+ const dur = animation.enter.duration;
3264
+ const perFeature = Math.min(dur, 500);
3265
+ if (!bulk) {
3266
+ mapStaggerBudget = Math.round(dur * 1.2);
3267
+ }
3268
+ const n = Math.max(features.length, 1);
3269
+ const stagger = !bulk && n > 1 ? mapStaggerBudget / (n - 1) : 0;
3270
+ stampAnimationVars(svg, {
3271
+ duration: perFeature,
3272
+ spring: animation.enter.spring,
3273
+ stagger,
3274
+ annotationDelay: animation.annotationDelay,
3275
+ ease: animation.enter.ease
3276
+ });
3277
+ }
3278
+ const defs = createSVGElement2("defs");
3279
+ svg.appendChild(defs);
3280
+ const noDataSwatch = layout.continuousLegend?.noData ?? layout.categoricalLegend?.noData;
3281
+ const patternMap = buildPatternDefs(noDataSwatch ? [...features, noDataSwatch] : features, defs);
3282
+ if (layout.views) {
3283
+ renderGeoMapViews(svg, layout, patternMap, {
3284
+ features: (parent, marks, patterns) => renderFeatures(parent, marks, void 0, 0, void 0, patterns),
3285
+ borders: renderBorders,
3286
+ points: (parent, marks) => renderPointMarks(parent, marks)
3287
+ });
3288
+ } else {
3289
+ const mapGroup = createSVGElement2("g");
3290
+ mapGroup.setAttribute("class", "oc-map-group");
3291
+ mapGroup.setAttribute("transform", `translate(${layout.area.x},${layout.area.y})`);
3292
+ const hasSideGutter = [
3293
+ layout.continuousLegend,
3294
+ layout.categoricalLegend,
3295
+ layout.pointContinuousLegend,
3296
+ layout.pointCategoricalLegend,
3297
+ layout.pointSizeLegend
3298
+ ].some(
3299
+ (legend) => legend?.position === "right" || legend?.position === "bottom-right" && legend.bounds.x >= layout.area.x + layout.area.width
3300
+ );
3301
+ if (hasSideGutter) {
3302
+ const clipId = nextSvgId("oc-map-viewport");
3303
+ const clip = createSVGElement2("clipPath");
3304
+ clip.setAttribute("id", clipId);
3305
+ const rect = createSVGElement2("rect");
3306
+ setAttrs2(rect, { x: 0, y: 0, width: layout.area.width, height: layout.area.height });
3307
+ clip.appendChild(rect);
3308
+ defs.appendChild(clip);
3309
+ mapGroup.setAttribute("clip-path", `url(#${clipId})`);
3310
+ }
3311
+ const cameraGroup = createSVGElement2("g");
3312
+ cameraGroup.setAttribute("class", "oc-map-camera");
3313
+ cameraGroup.setAttribute("data-oc-map-camera", "");
3314
+ const focusIdSet = layout.focus && layout.focus.ids.length > 0 ? new Set(layout.focus.ids.map(String)) : void 0;
3315
+ renderFeatures(
3316
+ cameraGroup,
3317
+ features,
3318
+ animate ? animation : void 0,
3319
+ mapStaggerBudget,
3320
+ focusIdSet,
3321
+ patternMap
3322
+ );
3323
+ renderBorders(cameraGroup, borders);
3324
+ if (animate && animation?.enter && layout.pointMarks.length > 1) {
3325
+ const pointStaggerBudget = animation.enter.duration * 0.5;
3326
+ const perPoint = pointStaggerBudget / (layout.pointMarks.length - 1);
3327
+ svg.style.setProperty("--oc-point-stagger", `${perPoint}ms`);
3328
+ }
3329
+ renderPointMarks(cameraGroup, layout.pointMarks, animate ? animation : void 0);
3330
+ mapGroup.appendChild(cameraGroup);
3331
+ svg.appendChild(mapGroup);
3332
+ }
3333
+ renderChrome2(svg, layout);
3334
+ if (layout.continuousLegend) {
3335
+ const contNoData = layout.continuousLegend.noData;
3336
+ renderLegend(
3337
+ svg,
3338
+ contNoData?.pattern ? {
3339
+ ...layout.continuousLegend,
3340
+ noData: { ...contNoData, fill: resolvePatternFill(contNoData.pattern, patternMap) }
3341
+ } : layout.continuousLegend
3342
+ );
3343
+ } else if (layout.categoricalLegend) {
3344
+ const catNoData = layout.categoricalLegend.noData;
3345
+ renderLegend(
3346
+ svg,
3347
+ catNoData?.pattern ? {
3348
+ ...layout.categoricalLegend,
3349
+ noData: { ...catNoData, fill: resolvePatternFill(catNoData.pattern, patternMap) }
3350
+ } : layout.categoricalLegend
3351
+ );
3352
+ }
3353
+ const ptLegend = layout.pointCategoricalLegend ?? layout.pointContinuousLegend;
3354
+ if (ptLegend) {
3355
+ if (ptLegend.position === "top-left") {
3356
+ const bg = createSVGElement2("rect");
3357
+ setAttrs2(bg, {
3358
+ x: ptLegend.bounds.x - 10,
3359
+ y: ptLegend.bounds.y - 8,
3360
+ width: ptLegend.bounds.width + 20,
3361
+ height: ptLegend.bounds.height + 16,
3362
+ rx: 4,
3363
+ fill: legendBackdrop(layout.theme)
3364
+ });
3365
+ svg.appendChild(bg);
3366
+ }
3367
+ renderLegend(svg, ptLegend);
3368
+ }
3369
+ if (layout.pointSizeLegend) {
3370
+ const sizeLegend = layout.pointSizeLegend;
3371
+ const pad = 10;
3372
+ const bg = createSVGElement2("rect");
3373
+ setAttrs2(bg, {
3374
+ x: sizeLegend.bounds.x - pad,
3375
+ y: sizeLegend.bounds.y - pad,
3376
+ width: sizeLegend.bounds.width + pad * 2,
3377
+ height: sizeLegend.bounds.height + pad * 2,
3378
+ rx: 6,
3379
+ fill: legendBackdrop(layout.theme)
3380
+ });
3381
+ if (sizeLegend.bounds.x < layout.area.x + layout.area.width && sizeLegend.bounds.y < layout.area.y + layout.area.height)
3382
+ svg.appendChild(bg);
3383
+ renderLegend(svg, sizeLegend);
3384
+ }
3385
+ renderAttributionBrand(
3386
+ svg,
3387
+ layout.chrome,
3388
+ layout.chrome.bottomAnchorY ?? layout.area.y + layout.area.height,
3389
+ layout.measureText
3390
+ );
3391
+ if (layout.labels && !layout.views) {
3392
+ const overlay = resolveMapLabelOverlay(layout, cameraForTarget(layout, layout.focus?.target));
3393
+ if (overlay) {
3394
+ renderGeoLabelOverlay(svg, layout, overlay);
3395
+ describeGeoLabelInventory(svg, overlay);
3396
+ }
3397
+ }
3398
+ renderStaticGeoColorKeys(svg, layout);
3399
+ return svg;
3400
+ }
3401
+
2167
3402
  export {
2168
3403
  stampAnimationVars,
2169
- renderChromeElement,
3404
+ captureSvgIdState,
3405
+ restoreSvgIdState,
2170
3406
  nextSvgId,
2171
3407
  resetSvgIdCounter,
2172
3408
  buildGradientDefs,
2173
3409
  resolveMarkFill,
2174
- buildPatternDefs,
2175
- resolvePatternFill,
2176
3410
  updateAnnotationGeometry,
2177
3411
  renderLegend,
2178
3412
  registerMarkRenderer,
2179
3413
  rectPathWithCorners,
2180
3414
  renderSingleMark,
2181
- renderChartSVG
3415
+ renderChartSVG,
3416
+ applySrOnlyStyles,
3417
+ mergeGeoLabelInventory,
3418
+ createMapLabelInventory,
3419
+ mapLabelAffine,
3420
+ projectAcceptedGeoOverlay,
3421
+ renderGeoLabelOverlay,
3422
+ describeGeoLabelInventory,
3423
+ resolveMapLabelOverlay,
3424
+ easingFns,
3425
+ storyMotion,
3426
+ createTween,
3427
+ FULL_VIEW,
3428
+ fitTarget,
3429
+ interpolateCamera,
3430
+ cameraTransform,
3431
+ damp,
3432
+ dampCamera,
3433
+ camerasClose,
3434
+ scrubCamera,
3435
+ cameraForGeoView,
3436
+ createMapViewCameras,
3437
+ FOCUS_DIM_OPACITY,
3438
+ focusTargetForFeatures,
3439
+ cameraForTarget,
3440
+ resolveMapZoom,
3441
+ clampMapCamera,
3442
+ zoomCameraAt,
3443
+ panCamera,
3444
+ wheelZoomFactor,
3445
+ applyMapCamera,
3446
+ ensureMapClip,
3447
+ geoViewMapLayout,
3448
+ renderGeoViewNotes,
3449
+ applyGeoDetailVisibility,
3450
+ findGeoViewScene,
3451
+ renderActiveGeoColorKeys,
3452
+ renderMapSVG
2182
3453
  };
2183
- //# sourceMappingURL=chunk-APMUBW72.js.map
3454
+ //# sourceMappingURL=chunk-5OQZRGUL.js.map