@opendata-ai/openchart-core 8.9.0 → 9.0.0-rc.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.
package/dist/index.js CHANGED
@@ -1,3 +1,127 @@
1
+ // src/helpers/json-pointer.ts
2
+ function encodePointerToken(token) {
3
+ return String(token).replace(/~/g, "~0").replace(/\//g, "~1");
4
+ }
5
+ function jsonPointer(...tokens2) {
6
+ return tokens2.map((token) => `/${encodePointerToken(token)}`).join("");
7
+ }
8
+
9
+ // src/helpers/edit-transactions.ts
10
+ function isContainer(value) {
11
+ return Array.isArray(value) || value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
12
+ }
13
+ function clone(value) {
14
+ if (Array.isArray(value)) return value.map(clone);
15
+ if (!isContainer(value)) return value;
16
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, clone(child)]));
17
+ }
18
+ function tokens(path) {
19
+ if (!path.startsWith("/")) throw new Error("Expected a non-root JSON Pointer beginning with /.");
20
+ return path.slice(1).split("/").map((token) => {
21
+ if (/~(?:[^01]|$)/.test(token)) throw new Error("Invalid JSON Pointer escape.");
22
+ const decoded = token.replace(/~1/g, "/").replace(/~0/g, "~");
23
+ if (["__proto__", "prototype", "constructor"].includes(decoded)) {
24
+ throw new Error("Unsafe property in edit path.");
25
+ }
26
+ return decoded;
27
+ });
28
+ }
29
+ function keyAt(parent, token, insert = false) {
30
+ if (!Array.isArray(parent)) return token;
31
+ if (insert && token === "-") return parent.length;
32
+ if (!/^(0|[1-9]\d*)$/.test(token)) throw new Error("Expected an array index.");
33
+ const index = Number(token);
34
+ if (!Number.isSafeInteger(index) || index > parent.length || !insert && index === parent.length) {
35
+ throw new Error("Array index is out of bounds.");
36
+ }
37
+ return index;
38
+ }
39
+ function read(parent, key) {
40
+ return parent[key];
41
+ }
42
+ function checkExpectation(root, parts, expected) {
43
+ if (!expected) return;
44
+ let end = -1;
45
+ for (let i = 0; i + 1 < parts.length; i++) {
46
+ if (parts[i] === "annotations" && /^(0|[1-9]\d*)$/.test(parts[i + 1])) end = i + 2;
47
+ }
48
+ if (end === -1) throw new Error("Annotation precondition requires an annotation path.");
49
+ let target = root;
50
+ for (const part of parts.slice(0, end)) {
51
+ if (!isContainer(target)) throw new Error("Annotation target no longer exists.");
52
+ const key = keyAt(target, part);
53
+ if (!Object.hasOwn(target, key)) throw new Error("Annotation target no longer exists.");
54
+ target = read(target, key);
55
+ }
56
+ if (!isContainer(target) || Array.isArray(target))
57
+ throw new Error("Annotation target is invalid.");
58
+ for (const field of ["id", "type", "text"]) {
59
+ const actual = field === "text" && target.type !== "text" ? target.label : target[field];
60
+ if (Object.hasOwn(expected, field) && actual !== expected[field]) {
61
+ throw new Error(`Annotation ${field} changed; discard the stale edit.`);
62
+ }
63
+ }
64
+ }
65
+ function applyEditTransaction(spec, tx) {
66
+ const result = clone(spec);
67
+ const inverse = [];
68
+ for (const [opIndex, op] of tx.ops.entries()) {
69
+ try {
70
+ if (!["set", "add", "remove"].includes(op.op)) throw new Error("Unknown edit operation.");
71
+ if (op.op !== "remove" && !Object.hasOwn(op, "value"))
72
+ throw new Error("Edit value is missing.");
73
+ const parts = tokens(op.path);
74
+ checkExpectation(result, parts, op.expect);
75
+ let parent = result;
76
+ const created = [];
77
+ for (let i = 0; i < parts.length - 1; i++) {
78
+ if (!isContainer(parent)) throw new Error("Cannot traverse a primitive or non-JSON value.");
79
+ const key2 = keyAt(parent, parts[i]);
80
+ if (!Object.hasOwn(parent, key2)) {
81
+ if (op.op !== "add" || Array.isArray(parent))
82
+ throw new Error("Intermediate container is missing.");
83
+ parent[key2] = /^(0|[1-9]\d*|-)$/.test(parts[i + 1]) ? [] : {};
84
+ created.push(jsonPointer(...parts.slice(0, i + 1)));
85
+ }
86
+ parent = read(parent, key2);
87
+ }
88
+ if (!isContainer(parent)) throw new Error("Edit parent is not a JSON container.");
89
+ const key = keyAt(parent, parts.at(-1), op.op === "add");
90
+ const exists = Object.hasOwn(parent, key);
91
+ const old = read(parent, key);
92
+ const path = jsonPointer(...parts.slice(0, -1), key);
93
+ let undo;
94
+ if (op.op === "remove") {
95
+ if (!exists) throw new Error("Edit target no longer exists.");
96
+ if (Array.isArray(parent)) parent.splice(Number(key), 1);
97
+ else delete parent[key];
98
+ undo = { op: "add", path, value: old };
99
+ } else if (op.op === "add" && Array.isArray(parent)) {
100
+ parent.splice(Number(key), 0, clone(op.value));
101
+ undo = { op: "remove", path };
102
+ } else {
103
+ parent[key] = clone(op.value);
104
+ undo = exists ? { op: "set", path, value: old } : { op: "remove", path };
105
+ }
106
+ inverse.unshift(undo, ...created.reverse().map((path2) => ({ op: "remove", path: path2 })));
107
+ } catch (error) {
108
+ return {
109
+ ok: false,
110
+ error: {
111
+ opIndex,
112
+ path: op.path,
113
+ reason: error instanceof Error ? error.message : String(error)
114
+ }
115
+ };
116
+ }
117
+ }
118
+ return {
119
+ ok: true,
120
+ spec: result,
121
+ inverse: { ...tx.revision !== void 0 ? { revision: tx.revision } : {}, ops: inverse }
122
+ };
123
+ }
124
+
1
125
  // src/types/encoding.ts
2
126
  function required(...types) {
3
127
  return { required: true, allowedTypes: types };
@@ -225,11 +349,6 @@ var elementRef = {
225
349
  key,
226
350
  ...path !== void 0 ? { path } : {}
227
351
  }),
228
- seriesLabel: (series, path) => ({
229
- type: "series-label",
230
- series,
231
- ...path !== void 0 ? { path } : {}
232
- }),
233
352
  legend: (path) => ({
234
353
  type: "legend",
235
354
  ...path !== void 0 ? { path } : {}
@@ -323,8 +442,7 @@ function isRangeAnnotation(annotation) {
323
442
  return annotation.type === "range";
324
443
  }
325
444
  function isRefLineAnnotation(annotation) {
326
- const type = annotation.type;
327
- return type === "refline" || type === "rule";
445
+ return annotation.type === "refline";
328
446
  }
329
447
  var MARK_DISPLAY_NAMES = {
330
448
  bar: "Bar chart",
@@ -518,9 +636,61 @@ var CSS_TOKENS = [
518
636
  { name: "--oc-title-tracking", light: "-0.022em" },
519
637
  { name: "--oc-subtitle-size", light: "14px" },
520
638
  { name: "--oc-subtitle-weight", light: "400" },
521
- { name: "--oc-source-size", light: "11px" },
639
+ { name: "--oc-source-size", light: "12px" },
522
640
  { name: "--oc-source-weight", light: "400" },
523
641
  { name: "--oc-body-size", light: "13px" },
642
+ {
643
+ name: "--oc-gridline-zero",
644
+ light: "rgba(0, 0, 0, 0.22)",
645
+ dark: "rgba(255, 255, 255, 0.24)",
646
+ comment: "Emphasis for existing zero rules; does not change the domain"
647
+ },
648
+ {
649
+ name: "--oc-endpoint-label-size",
650
+ light: "13px",
651
+ consumers: "Endpoint geometry and authored theme stamp"
652
+ },
653
+ {
654
+ name: "--oc-endpoint-value-size",
655
+ light: "12px",
656
+ consumers: "Endpoint geometry and authored theme stamp"
657
+ },
658
+ { name: "--oc-endpoint-entry-gap", light: "6px", consumers: "Endpoint collision spacing" },
659
+ { name: "--oc-endpoint-value-gap", light: "4px", consumers: "Endpoint internal spacing" },
660
+ {
661
+ name: "--oc-endpoint-column-gap",
662
+ light: "18px",
663
+ consumers: "Endpoint frame reservation and placement"
664
+ },
665
+ {
666
+ name: "--oc-map-no-data-fill",
667
+ light: "#f0f0f0",
668
+ dark: "#171719",
669
+ comment: "Engine omission derives neutral[100] from the active theme"
670
+ },
671
+ {
672
+ name: "--oc-map-no-data-hatch",
673
+ light: "#c9c9c9",
674
+ dark: "#3d3e3f",
675
+ comment: "Engine omission derives neutral[300] from the active theme"
676
+ },
677
+ {
678
+ name: "--oc-map-interior-border",
679
+ light: "rgba(0, 0, 0, 0.14)",
680
+ dark: "rgba(255, 255, 255, 0.18)"
681
+ },
682
+ {
683
+ name: "--oc-map-outline-border",
684
+ light: "rgba(0, 0, 0, 0.4)",
685
+ dark: "rgba(255, 255, 255, 0.38)"
686
+ },
687
+ { name: "--oc-annotation-label", light: "#333333", dark: "#d1d5db" },
688
+ { name: "--oc-annotation-muted", light: "#6b7280", dark: "#9ca3af" },
689
+ { name: "--oc-annotation-leader", light: "#8f8f8f", dark: "#9aa0a6" },
690
+ { name: "--oc-annotation-rule", light: "#888888", dark: "#9ca3af" },
691
+ { name: "--oc-annotation-range-fill", light: "#f0c040", dark: "#f0c040" },
692
+ { name: "--oc-annotation-marker-fill", light: "#ffffff", dark: "#09090b" },
693
+ { name: "--oc-annotation-plate", light: "#ffffff", dark: "#09090b" },
524
694
  { name: "--oc-eyebrow-size", light: "11px" },
525
695
  { name: "--oc-eyebrow-weight", light: "500" },
526
696
  { name: "--oc-eyebrow-tracking", light: "0.08em" },
@@ -568,7 +738,7 @@ var CSS_TOKENS = [
568
738
  {
569
739
  section: "Lines",
570
740
  name: "--oc-gridline",
571
- light: "rgba(0, 0, 0, 0.08)",
741
+ light: "rgba(0, 0, 0, 0.05)",
572
742
  dark: "rgba(255, 255, 255, 0.06)"
573
743
  },
574
744
  {
@@ -1355,10 +1525,8 @@ function axisTitleOffset(maxTickLabelWidth, titleFontSize, width, inline = false
1355
1525
  }
1356
1526
  var NARROW_VIEWPORT_MAX = 500;
1357
1527
  var TOP_PAD_EXTRA_NARROW = 10;
1358
- var TOP_PAD_NARROW_MAX = NARROW_VIEWPORT_MAX;
1359
1528
  var LABEL_GAP_COMPACT = 8;
1360
1529
  var LABEL_GAP_DEFAULT = 12;
1361
- var LABEL_GAP_NARROW_MAX = NARROW_VIEWPORT_MAX;
1362
1530
  var MAX_LEFT_LABEL_FRACTION_MEDIUM_MAX = 600;
1363
1531
  var MAX_LEFT_LABEL_FRACTION_COMPACT = 0.45;
1364
1532
  var MAX_LEFT_LABEL_FRACTION_MEDIUM = 0.55;
@@ -1421,6 +1589,17 @@ function truncateRotatedLabel(label, tickAngle, tickFontSize, tickFontWeight, me
1421
1589
  }
1422
1590
 
1423
1591
  // src/theme/defaults.ts
1592
+ var FONT_SIZES = {
1593
+ title: 26,
1594
+ subtitle: 14,
1595
+ body: 13,
1596
+ small: 12,
1597
+ axisTick: 12,
1598
+ metricLabel: 11,
1599
+ metricValue: 22,
1600
+ endpointLabel: 13,
1601
+ endpointValue: 12
1602
+ };
1424
1603
  var DEFAULT_THEME = {
1425
1604
  colors: {
1426
1605
  categorical: [...CATEGORICAL_PALETTE],
@@ -1429,7 +1608,10 @@ var DEFAULT_THEME = {
1429
1608
  diverging: DIVERGING_PALETTES,
1430
1609
  background: "transparent",
1431
1610
  text: "#09090b",
1432
- gridline: "rgba(0,0,0,0.08)",
1611
+ gridline: "rgba(0,0,0,0.05)",
1612
+ gridlineZero: "rgba(0,0,0,0.22)",
1613
+ mapInteriorBorder: "rgba(0,0,0,0.14)",
1614
+ mapOutlineBorder: "rgba(0,0,0,0.40)",
1433
1615
  // Structural hairline: axis lines, separators. Deliberately heavier than
1434
1616
  // the gridline and lighter than any ink, so structure reads as structure.
1435
1617
  hairline: "rgba(0,0,0,0.14)",
@@ -1439,21 +1621,20 @@ var DEFAULT_THEME = {
1439
1621
  axis: "#71717a",
1440
1622
  annotationFill: "rgba(0,0,0,0.04)",
1441
1623
  annotationText: "#71717a",
1624
+ annotationLabel: "#333333",
1625
+ annotationMuted: "#6b7280",
1626
+ annotationLeader: "#8f8f8f",
1627
+ annotationRule: "#888888",
1628
+ annotationRangeFill: "#f0c040",
1629
+ annotationMarkerFill: "#ffffff",
1630
+ annotationPlate: "#ffffff",
1442
1631
  positive: "#15803d",
1443
1632
  negative: "#dc2626"
1444
1633
  },
1445
1634
  fonts: {
1446
1635
  family: '"Inter Variable", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
1447
1636
  mono: '"JetBrains Mono", "Fira Code", "Cascadia Code", monospace',
1448
- sizes: {
1449
- title: 26,
1450
- subtitle: 14,
1451
- body: 13,
1452
- small: 11,
1453
- axisTick: 11,
1454
- metricLabel: 11,
1455
- metricValue: 22
1456
- },
1637
+ sizes: FONT_SIZES,
1457
1638
  // One ladder everywhere: 400 regular / 500 medium (eyebrow, labels, UI,
1458
1639
  // values) / 600 semibold (title, series names, annotation lede) / 700 bold.
1459
1640
  weights: {
@@ -1466,8 +1647,8 @@ var DEFAULT_THEME = {
1466
1647
  spacing: {
1467
1648
  padding: 20,
1468
1649
  chromeGap: 6,
1469
- chromeToChart: 8,
1470
- chartToFooter: 8,
1650
+ chromeToChart: 16,
1651
+ chartToFooter: 12,
1471
1652
  axisMargin: 6,
1472
1653
  xAxisHeight: X_AXIS_BAND_HEIGHT,
1473
1654
  // Gap (px) between the x-axis line and the TOP of the tick labels. The
@@ -1475,7 +1656,10 @@ var DEFAULT_THEME = {
1475
1656
  // by textAscent() to land it on the alphabetic baseline (rather than
1476
1657
  // dominant-baseline:hanging, which WebKit positions from different metrics),
1477
1658
  // so the gap holds regardless of font size.
1478
- xAxisLabelPadding: 4
1659
+ xAxisLabelPadding: 4,
1660
+ endpointEntryGap: 6,
1661
+ endpointValueGap: 4,
1662
+ endpointColumnGap: 18
1479
1663
  },
1480
1664
  /** Containers and tooltips. Marks carry their own 2px radius constant. */
1481
1665
  borderRadius: 8,
@@ -1487,31 +1671,31 @@ var DEFAULT_THEME = {
1487
1671
  lineHeight: 1.4
1488
1672
  },
1489
1673
  title: {
1490
- fontSize: 26,
1674
+ fontSize: FONT_SIZES.title,
1491
1675
  fontWeight: 600,
1492
1676
  color: "#09090b",
1493
1677
  lineHeight: 1.15
1494
1678
  },
1495
1679
  subtitle: {
1496
- fontSize: 14,
1680
+ fontSize: FONT_SIZES.subtitle,
1497
1681
  fontWeight: 400,
1498
1682
  color: "#71717a",
1499
1683
  lineHeight: 1.45
1500
1684
  },
1501
1685
  source: {
1502
- fontSize: 11,
1686
+ fontSize: FONT_SIZES.small,
1503
1687
  fontWeight: 400,
1504
1688
  color: "#71717a",
1505
1689
  lineHeight: 1.4
1506
1690
  },
1507
1691
  byline: {
1508
- fontSize: 11,
1692
+ fontSize: FONT_SIZES.small,
1509
1693
  fontWeight: 400,
1510
1694
  color: "#71717a",
1511
1695
  lineHeight: 1.4
1512
1696
  },
1513
1697
  footer: {
1514
- fontSize: 11,
1698
+ fontSize: FONT_SIZES.small,
1515
1699
  fontWeight: 400,
1516
1700
  color: "#71717a",
1517
1701
  lineHeight: 1.4
@@ -1594,6 +1778,9 @@ function adaptTheme(theme) {
1594
1778
  const categoricalFill = overridden(theme.colors.categoricalFill, light.categoricalFill, [
1595
1779
  ...CATEGORICAL_FILL_PALETTE_DARK
1596
1780
  ]);
1781
+ const neutral = deriveNeutralRamp(darkText, darkBg, true);
1782
+ const authoredColors = theme._authored?.colors && !Array.isArray(theme._authored.colors) ? theme._authored.colors : {};
1783
+ const authoredColor = (key, fallback) => pairs?.[`colors.${key}`]?.dark ?? (authoredColors[key] !== void 0 ? theme.colors[key] ?? fallback : fallback);
1597
1784
  return {
1598
1785
  ...theme,
1599
1786
  isDark: true,
@@ -1602,15 +1789,27 @@ function adaptTheme(theme) {
1602
1789
  background: darkBg,
1603
1790
  text: darkText,
1604
1791
  gridline: darkGridline,
1792
+ gridlineZero: authoredColor("gridlineZero", "rgba(255,255,255,0.24)"),
1605
1793
  axis: darkAxis,
1606
1794
  annotationFill: pairs?.["colors.annotationFill"] ? pairs["colors.annotationFill"].dark : overridden(theme.colors.annotationFill, light.annotationFill, "rgba(255,255,255,0.06)"),
1607
1795
  annotationText: pairs?.["colors.annotationText"] ? pairs["colors.annotationText"].dark : overridden(theme.colors.annotationText, light.annotationText, darkMuted),
1796
+ annotationLabel: authoredColor("annotationLabel", "#d1d5db"),
1797
+ annotationMuted: authoredColor("annotationMuted", "#9ca3af"),
1798
+ annotationLeader: authoredColor("annotationLeader", "#9aa0a6"),
1799
+ annotationRule: authoredColor("annotationRule", "#9ca3af"),
1800
+ annotationRangeFill: authoredColor("annotationRangeFill", "#f0c040"),
1801
+ annotationMarkerFill: pairs?.["colors.annotationMarkerFill"]?.dark ?? (authoredColors.annotationMarkerFill !== void 0 ? theme.colors.annotationMarkerFill : neutral.surface),
1802
+ annotationPlate: pairs?.["colors.annotationPlate"]?.dark ?? (authoredColors.annotationPlate !== void 0 ? theme.colors.annotationPlate : neutral.surface),
1803
+ mapNoDataFill: pairs?.["colors.mapNoDataFill"]?.dark ?? theme.colors.mapNoDataFill,
1804
+ mapNoDataHatch: pairs?.["colors.mapNoDataHatch"]?.dark ?? theme.colors.mapNoDataHatch,
1805
+ mapInteriorBorder: authoredColor("mapInteriorBorder", "rgba(255,255,255,0.18)"),
1806
+ mapOutlineBorder: authoredColor("mapOutlineBorder", "rgba(255,255,255,0.38)"),
1608
1807
  categorical,
1609
1808
  categoricalFill,
1610
1809
  hairline: darkHairline,
1611
1810
  positive: pairs?.["colors.positive"] ? pairs["colors.positive"].dark : overridden(theme.colors.positive, light.positive, "#4ade80"),
1612
1811
  negative: pairs?.["colors.negative"] ? pairs["colors.negative"].dark : overridden(theme.colors.negative, light.negative, "#f87171"),
1613
- neutral: deriveNeutralRamp(darkText, darkBg, true)
1812
+ neutral
1614
1813
  },
1615
1814
  chrome: {
1616
1815
  // Eyebrow keeps its accent tint (cyan in both modes) unless the user
@@ -1642,8 +1841,9 @@ function adaptTheme(theme) {
1642
1841
  }
1643
1842
  },
1644
1843
  // The editorial rule is a brand device: it keeps its authored color unless
1645
- // the theme gave an explicit dark half of the pair.
1646
- rule: theme.rule && pairs?.["rule.color"] ? { ...theme.rule, color: pairs["rule.color"].dark } : theme.rule
1844
+ // the theme gave an explicit dark half of the pair. A partial rule with no
1845
+ // color derives from text ink, so it follows the dark text.
1846
+ rule: theme.rule && pairs?.["rule.color"] ? { ...theme.rule, color: pairs["rule.color"].dark } : theme.rule && theme._authored?.rule?.color === void 0 && theme.rule.color === theme.colors.text ? { ...theme.rule, color: darkText } : theme.rule
1647
1847
  };
1648
1848
  }
1649
1849
  function adaptForLightLineStroke(color) {
@@ -1656,8 +1856,27 @@ function adaptForLightLineStroke(color) {
1656
1856
  return c.formatHex();
1657
1857
  }
1658
1858
 
1859
+ // src/theme/merge.ts
1860
+ function isRecord(value) {
1861
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1862
+ }
1863
+ function mergeThemeObjects(base, override) {
1864
+ if (!isRecord(override) || "light" in override || "dark" in override) return override;
1865
+ const result = isRecord(base) ? { ...base } : {};
1866
+ for (const [key, value] of Object.entries(override)) {
1867
+ if (value !== void 0) result[key] = mergeThemeObjects(result[key], value);
1868
+ }
1869
+ return result;
1870
+ }
1871
+ function normalize(config) {
1872
+ return Array.isArray(config.colors) ? { ...config, colors: { categorical: config.colors } } : config;
1873
+ }
1874
+ function mergeThemeConfig(base, override) {
1875
+ if (!override) return base;
1876
+ return mergeThemeObjects(base ? normalize(base) : {}, normalize(override));
1877
+ }
1878
+
1659
1879
  // src/theme/presets.ts
1660
- var editorial = {};
1661
1880
  var essay = {
1662
1881
  colors: {
1663
1882
  background: { light: "#faf8f5", dark: "#1a1816" },
@@ -1730,7 +1949,7 @@ var broadsheet = {
1730
1949
  },
1731
1950
  chrome: {
1732
1951
  eyebrow: { color: { light: "#e3120b", dark: "#f4463f" }, fontSize: 11, fontWeight: 700 },
1733
- title: { fontSize: 24, fontWeight: 700, lineHeight: 1.18 },
1952
+ title: { fontWeight: 700, lineHeight: 1.18 },
1734
1953
  subtitle: { fontWeight: 400, lineHeight: 1.45 }
1735
1954
  },
1736
1955
  /** The masthead device: a short red bar above the eyebrow. */
@@ -1765,7 +1984,7 @@ var terminal = {
1765
1984
  },
1766
1985
  chrome: {
1767
1986
  eyebrow: { color: { light: "#22d3ee", dark: "#22d3ee" }, fontSize: 10, fontWeight: 500 },
1768
- title: { fontSize: 15, fontWeight: 600, lineHeight: 1.3 },
1987
+ title: { fontWeight: 600, lineHeight: 1.3 },
1769
1988
  subtitle: { fontWeight: 400, lineHeight: 1.4 }
1770
1989
  },
1771
1990
  borderRadius: 4,
@@ -1776,13 +1995,9 @@ var clarity = {
1776
1995
  background: { light: "#ffffff", dark: "#09090b" },
1777
1996
  axis: { light: "#52525b", dark: "#a1a1aa" }
1778
1997
  },
1779
- fonts: { sizes: { title: 26, subtitle: 14, body: 13, small: 12, axisTick: 12 } },
1780
1998
  chrome: {
1781
- eyebrow: { color: { light: "#0f766e", dark: "#5eead4" } },
1782
- source: { fontSize: 12 },
1783
- footer: { fontSize: 12 }
1784
- },
1785
- spacing: { chromeToChart: 16, chartToFooter: 12 }
1999
+ eyebrow: { color: { light: "#0f766e", dark: "#5eead4" } }
2000
+ }
1786
2001
  };
1787
2002
  var legacyEditorial = {
1788
2003
  fonts: { sizes: { title: 26, subtitle: 14, body: 13, small: 11, axisTick: 11 } },
@@ -1790,23 +2005,10 @@ var legacyEditorial = {
1790
2005
  };
1791
2006
 
1792
2007
  // src/theme/resolve.ts
1793
- function deepMerge(target, source) {
1794
- const result = { ...target };
1795
- for (const key of Object.keys(source)) {
1796
- const sourceVal = source[key];
1797
- const targetVal = target[key];
1798
- if (sourceVal !== void 0 && sourceVal !== null && typeof sourceVal === "object" && !Array.isArray(sourceVal) && typeof targetVal === "object" && targetVal !== null && !Array.isArray(targetVal)) {
1799
- result[key] = deepMerge(targetVal, sourceVal);
1800
- } else if (sourceVal !== void 0) {
1801
- result[key] = sourceVal;
1802
- }
1803
- }
1804
- return result;
1805
- }
1806
2008
  function resolveTokenLight(v) {
1807
2009
  return typeof v === "string" ? v : v.light;
1808
2010
  }
1809
- function themeConfigToPartial(config) {
2011
+ function themeConfigToPartial(config, base) {
1810
2012
  const partial = {};
1811
2013
  if (config.colors) {
1812
2014
  const colors = {};
@@ -1826,6 +2028,30 @@ function themeConfigToPartial(config) {
1826
2028
  colors.annotationFill = resolveTokenLight(config.colors.annotationFill);
1827
2029
  if (config.colors.annotationText)
1828
2030
  colors.annotationText = resolveTokenLight(config.colors.annotationText);
2031
+ if (config.colors.annotationLabel)
2032
+ colors.annotationLabel = resolveTokenLight(config.colors.annotationLabel);
2033
+ if (config.colors.annotationMuted)
2034
+ colors.annotationMuted = resolveTokenLight(config.colors.annotationMuted);
2035
+ if (config.colors.annotationLeader)
2036
+ colors.annotationLeader = resolveTokenLight(config.colors.annotationLeader);
2037
+ if (config.colors.annotationRule)
2038
+ colors.annotationRule = resolveTokenLight(config.colors.annotationRule);
2039
+ if (config.colors.annotationRangeFill)
2040
+ colors.annotationRangeFill = resolveTokenLight(config.colors.annotationRangeFill);
2041
+ if (config.colors.annotationMarkerFill)
2042
+ colors.annotationMarkerFill = resolveTokenLight(config.colors.annotationMarkerFill);
2043
+ if (config.colors.annotationPlate)
2044
+ colors.annotationPlate = resolveTokenLight(config.colors.annotationPlate);
2045
+ for (const key of [
2046
+ "gridlineZero",
2047
+ "mapNoDataFill",
2048
+ "mapNoDataHatch",
2049
+ "mapInteriorBorder",
2050
+ "mapOutlineBorder"
2051
+ ]) {
2052
+ const value = config.colors[key];
2053
+ if (value !== void 0) colors[key] = resolveTokenLight(value);
2054
+ }
1829
2055
  if (config.colors.positive) colors.positive = resolveTokenLight(config.colors.positive);
1830
2056
  if (config.colors.negative) colors.negative = resolveTokenLight(config.colors.negative);
1831
2057
  }
@@ -1854,6 +2080,9 @@ function themeConfigToPartial(config) {
1854
2080
  if (config.spacing.xAxisHeight !== void 0) spacing.xAxisHeight = config.spacing.xAxisHeight;
1855
2081
  if (config.spacing.xAxisLabelPadding !== void 0)
1856
2082
  spacing.xAxisLabelPadding = config.spacing.xAxisLabelPadding;
2083
+ for (const key of ["endpointEntryGap", "endpointValueGap", "endpointColumnGap"]) {
2084
+ if (config.spacing[key] !== void 0) spacing[key] = config.spacing[key];
2085
+ }
1857
2086
  partial.spacing = spacing;
1858
2087
  }
1859
2088
  if (config.borderRadius !== void 0) {
@@ -1863,9 +2092,9 @@ function themeConfigToPartial(config) {
1863
2092
  const chrome = {};
1864
2093
  for (const [element, value] of Object.entries(config.chrome)) {
1865
2094
  if (value === void 0) continue;
1866
- if (typeof value === "string") {
1867
- chrome[element] = { color: value };
1868
- } else {
2095
+ if (typeof value === "string")
2096
+ throw new Error("theme.chrome string colors were removed in v9; use { color }.");
2097
+ {
1869
2098
  const override = {};
1870
2099
  const obj = value;
1871
2100
  if (obj.color !== void 0) override.color = resolveTokenLight(obj.color);
@@ -1879,11 +2108,14 @@ function themeConfigToPartial(config) {
1879
2108
  }
1880
2109
  if (config.rule) {
1881
2110
  partial.rule = {
1882
- color: resolveTokenLight(config.rule.color),
1883
- width: config.rule.width,
1884
- thickness: config.rule.thickness
2111
+ color: resolveTokenLight(
2112
+ config.rule.color ?? base.rule?.color ?? (config.colors && !Array.isArray(config.colors) ? config.colors.text : void 0) ?? DEFAULT_THEME.colors.text
2113
+ ),
2114
+ width: config.rule.width ?? base.rule?.width ?? 40,
2115
+ thickness: config.rule.thickness ?? base.rule?.thickness ?? 3
1885
2116
  };
1886
2117
  }
2118
+ if (config.rule === null) partial.rule = null;
1887
2119
  if (config.seriesStrategy) {
1888
2120
  partial.seriesStrategy = config.seriesStrategy;
1889
2121
  }
@@ -1896,10 +2128,22 @@ function collectTokenPairs(config) {
1896
2128
  "background",
1897
2129
  "text",
1898
2130
  "gridline",
2131
+ "gridlineZero",
1899
2132
  "hairline",
1900
2133
  "axis",
1901
2134
  "annotationFill",
1902
2135
  "annotationText",
2136
+ "annotationLabel",
2137
+ "annotationMuted",
2138
+ "annotationLeader",
2139
+ "annotationRule",
2140
+ "annotationRangeFill",
2141
+ "annotationMarkerFill",
2142
+ "annotationPlate",
2143
+ "mapNoDataFill",
2144
+ "mapNoDataHatch",
2145
+ "mapInteriorBorder",
2146
+ "mapOutlineBorder",
1903
2147
  "positive",
1904
2148
  "negative"
1905
2149
  ];
@@ -1976,36 +2220,57 @@ function adjustOpacity(hex, opacity) {
1976
2220
  return `#${toHex(mix2(r))}${toHex(mix2(g))}${toHex(mix2(b))}`;
1977
2221
  }
1978
2222
  function resolveTheme(userTheme, base = DEFAULT_THEME) {
1979
- let merged = userTheme ? deepMerge(base, themeConfigToPartial(userTheme)) : { ...base };
1980
- if (userTheme?.fonts?.sizes) {
1981
- const s = userTheme.fonts.sizes;
1982
- merged = {
1983
- ...merged,
1984
- chrome: {
1985
- ...merged.chrome,
1986
- ...s.title !== void 0 && {
1987
- title: { ...merged.chrome.title, fontSize: s.title }
1988
- },
1989
- ...s.subtitle !== void 0 && {
1990
- subtitle: { ...merged.chrome.subtitle, fontSize: s.subtitle }
1991
- },
1992
- ...s.small !== void 0 && {
1993
- source: { ...merged.chrome.source, fontSize: s.small },
1994
- byline: { ...merged.chrome.byline, fontSize: s.small },
1995
- footer: { ...merged.chrome.footer, fontSize: s.small }
2223
+ let merged = userTheme ? mergeThemeObjects(base, themeConfigToPartial(userTheme, base)) : { ...base };
2224
+ for (const [element, size] of Object.entries({
2225
+ title: "title",
2226
+ subtitle: "subtitle",
2227
+ source: "small",
2228
+ byline: "small",
2229
+ footer: "small"
2230
+ })) {
2231
+ if (userTheme?.chrome?.[element]?.fontSize === void 0) {
2232
+ merged = {
2233
+ ...merged,
2234
+ chrome: {
2235
+ ...merged.chrome,
2236
+ [element]: { ...merged.chrome[element], fontSize: merged.fonts.sizes[size] }
1996
2237
  }
1997
- }
1998
- };
2238
+ };
2239
+ }
1999
2240
  }
2000
2241
  const dark = isDarkBackground(merged.colors.background);
2001
2242
  if (dark) {
2002
- merged = adaptChromeForDarkBg(merged, merged.colors.text);
2243
+ merged = adaptChromeForDarkBg({ ...merged, colors: { ...merged.colors } }, merged.colors.text);
2244
+ const authoredColors2 = userTheme?.colors && !Array.isArray(userTheme.colors) ? userTheme.colors : {};
2245
+ for (const key of [
2246
+ "annotationLabel",
2247
+ "annotationMuted",
2248
+ "annotationLeader",
2249
+ "annotationRule",
2250
+ "annotationRangeFill",
2251
+ "annotationMarkerFill",
2252
+ "annotationPlate",
2253
+ "gridlineZero",
2254
+ "mapInteriorBorder",
2255
+ "mapOutlineBorder"
2256
+ ]) {
2257
+ if (authoredColors2[key] === void 0)
2258
+ merged.colors[key] = cssTokenDefault(
2259
+ `--oc-${key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`,
2260
+ "dark"
2261
+ );
2262
+ }
2003
2263
  }
2264
+ const neutral = deriveNeutralRamp(merged.colors.text, merged.colors.background, dark);
2265
+ const authoredColors = userTheme?.colors && !Array.isArray(userTheme.colors) ? userTheme.colors : {};
2004
2266
  return {
2005
2267
  ...merged,
2268
+ _authored: userTheme,
2006
2269
  colors: {
2007
2270
  ...merged.colors,
2008
- neutral: deriveNeutralRamp(merged.colors.text, merged.colors.background, dark)
2271
+ neutral,
2272
+ annotationMarkerFill: authoredColors.annotationMarkerFill === void 0 ? neutral.surface : merged.colors.annotationMarkerFill,
2273
+ annotationPlate: authoredColors.annotationPlate === void 0 ? neutral.surface : merged.colors.annotationPlate
2009
2274
  },
2010
2275
  isDark: dark,
2011
2276
  _tokenPairs: userTheme ? collectTokenPairs(userTheme) : void 0
@@ -2084,18 +2349,44 @@ function estimateLineCount(text, style, maxWidth, measureText, maxLines) {
2084
2349
  }
2085
2350
  var FOOTNOTE_LINE_HEIGHT = 1.3;
2086
2351
  var FOOTNOTE_BAND_GAP = 4;
2087
- function footnoteBandHeight(count, theme) {
2088
- if (count <= 0) return 0;
2089
- return count * theme.fonts.sizes.small * FOOTNOTE_LINE_HEIGHT + FOOTNOTE_BAND_GAP;
2352
+ function computeNoteBandHeight(input, theme) {
2353
+ if (typeof input !== "number" && input.noteBandHeight !== void 0) return input.noteBandHeight;
2354
+ const count = typeof input === "number" ? input : (input.footnotes?.reduce((sum, note) => sum + (note.lines?.length ?? 1), 0) ?? 0) + (input.seriesSummary?.reduce((sum, entry) => sum + entry.lines.length, 0) ?? 0);
2355
+ return count <= 0 ? 0 : count * theme.fonts.sizes.small * FOOTNOTE_LINE_HEIGHT + FOOTNOTE_BAND_GAP;
2356
+ }
2357
+ function measuredWatermark(theme, width, pad, y, measureText) {
2358
+ if (width < BRAND_MIN_WIDTH) return void 0;
2359
+ const style = {
2360
+ fontFamily: theme.fonts.family,
2361
+ fontSize: BRAND_FONT_SIZE,
2362
+ fontWeight: 600,
2363
+ fill: theme.colors.axis,
2364
+ textAnchor: "end",
2365
+ lineHeight: 1.3
2366
+ };
2367
+ return {
2368
+ text: "OpenData",
2369
+ x: width - pad,
2370
+ y,
2371
+ maxWidth: measureText?.("OpenData", BRAND_FONT_SIZE, 600).width ?? "OpenData".length * estimateCharWidth(BRAND_FONT_SIZE, 600),
2372
+ style
2373
+ };
2090
2374
  }
2091
2375
  function computeChrome(chrome, theme, width, measureText, chromeMode = "full", padding, watermark = true, bottomLegendHeight = 0, crampedTitle = false) {
2092
2376
  if (!chrome || chromeMode === "hidden") {
2093
2377
  if (watermark && width >= BRAND_MIN_WIDTH) {
2094
2378
  const hiddenPad = padding ?? theme.spacing.padding;
2095
- const brandHeight = estimateTextHeight(BRAND_FONT_SIZE, 1);
2379
+ const brandHeight2 = estimateTextHeight(BRAND_FONT_SIZE, 1);
2096
2380
  return {
2097
2381
  topHeight: 0,
2098
- bottomHeight: theme.spacing.chartToFooter + brandHeight + hiddenPad + bottomLegendHeight
2382
+ bottomHeight: theme.spacing.chartToFooter + brandHeight2 + hiddenPad + bottomLegendHeight,
2383
+ watermark: measuredWatermark(
2384
+ theme,
2385
+ width,
2386
+ hiddenPad,
2387
+ theme.spacing.chartToFooter + bottomLegendHeight,
2388
+ measureText
2389
+ )
2099
2390
  };
2100
2391
  }
2101
2392
  if (bottomLegendHeight > 0) {
@@ -2196,125 +2487,128 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2196
2487
  if (chromeMode === "compact") {
2197
2488
  let compactBottom = 0;
2198
2489
  if (watermark && width >= BRAND_MIN_WIDTH) {
2199
- const brandHeight = estimateTextHeight(BRAND_FONT_SIZE, 1);
2200
- compactBottom = theme.spacing.chartToFooter + brandHeight + pad + bottomLegendHeight;
2490
+ const brandHeight2 = estimateTextHeight(BRAND_FONT_SIZE, 1);
2491
+ compactBottom = theme.spacing.chartToFooter + brandHeight2 + pad + bottomLegendHeight;
2201
2492
  } else if (bottomLegendHeight > 0) {
2202
2493
  compactBottom = bottomLegendHeight;
2203
2494
  }
2204
2495
  return {
2205
2496
  topHeight,
2206
2497
  bottomHeight: compactBottom,
2498
+ ...watermark ? {
2499
+ watermark: measuredWatermark(
2500
+ theme,
2501
+ width,
2502
+ pad,
2503
+ theme.spacing.chartToFooter + bottomLegendHeight,
2504
+ measureText
2505
+ )
2506
+ } : {},
2207
2507
  ...ruleElement ? { rule: ruleElement } : {},
2208
2508
  ...topElements
2209
2509
  };
2210
2510
  }
2511
+ const startY = theme.spacing.chartToFooter + bottomLegendHeight;
2211
2512
  const brandNorm = normalizeChromeText(chrome.brand);
2212
- const showWatermark = watermark && !brandNorm;
2213
- const shouldReserveBrandWidth = (showWatermark || !!brandNorm) && width >= BRAND_MIN_WIDTH;
2214
- const bottomMaxWidth = maxWidth - (shouldReserveBrandWidth ? BRAND_RESERVE_WIDTH : 0);
2215
- const bottomElements = {};
2216
- let bottomHeight = 0;
2217
- const bottomItems = [];
2218
- const sourceNorm = normalizeChromeText(chrome.source);
2219
- if (sourceNorm) {
2220
- bottomItems.push({
2221
- key: "source",
2222
- norm: sourceNorm,
2223
- defaults: theme.chrome.source
2224
- });
2225
- }
2226
- const bylineNorm = normalizeChromeText(chrome.byline);
2227
- if (bylineNorm) {
2228
- bottomItems.push({
2229
- key: "byline",
2230
- norm: bylineNorm,
2231
- defaults: theme.chrome.byline
2232
- });
2233
- }
2234
- const footerNorm = normalizeChromeText(chrome.footer);
2235
- if (footerNorm) {
2236
- bottomItems.push({
2237
- key: "footer",
2238
- norm: footerNorm,
2239
- defaults: theme.chrome.footer
2240
- });
2241
- }
2242
- if (bottomItems.length > 0) {
2243
- bottomHeight += theme.spacing.chartToFooter;
2244
- bottomHeight += bottomLegendHeight;
2245
- for (const item of bottomItems) {
2246
- const style = buildTextStyle(
2247
- item.defaults,
2248
- fontFamily,
2249
- item.defaults.color,
2250
- width,
2251
- item.norm.style
2252
- );
2253
- const maxLines = item.norm.style?.maxLines;
2254
- const lineCount = estimateLineCount(
2255
- item.norm.text,
2256
- style,
2257
- bottomMaxWidth,
2258
- measureText,
2259
- maxLines
2260
- );
2261
- const height = estimateTextHeight(style.fontSize, lineCount, style.lineHeight);
2262
- bottomElements[item.key] = {
2263
- text: item.norm.text,
2264
- x: pad + (item.norm.offset?.dx ?? 0),
2265
- y: bottomHeight + (item.norm.offset?.dy ?? 0),
2266
- // offset from where bottom chrome starts
2267
- maxWidth: bottomMaxWidth,
2268
- ...maxLines != null ? { maxLines } : {},
2269
- style
2270
- };
2271
- bottomHeight += height + chromeGap;
2272
- }
2273
- bottomHeight -= chromeGap;
2274
- if (showWatermark && width >= BRAND_MIN_WIDTH) {
2275
- const brandHeight = estimateTextHeight(BRAND_FONT_SIZE, 1);
2276
- const contentBelowFirstItem = bottomHeight - theme.spacing.chartToFooter;
2277
- if (brandHeight > contentBelowFirstItem) {
2278
- bottomHeight += brandHeight - contentBelowFirstItem;
2279
- }
2280
- }
2281
- bottomHeight += pad;
2282
- } else if (showWatermark && width >= BRAND_MIN_WIDTH) {
2283
- const brandHeight = estimateTextHeight(BRAND_FONT_SIZE, 1);
2284
- bottomHeight = theme.spacing.chartToFooter + brandHeight + pad + bottomLegendHeight;
2285
- } else if (bottomLegendHeight > 0) {
2286
- bottomHeight = bottomLegendHeight;
2287
- }
2513
+ const watermarkElement = watermark && !brandNorm ? measuredWatermark(theme, width, pad, startY, measureText) : void 0;
2288
2514
  let brandElement;
2289
2515
  if (brandNorm && width >= BRAND_MIN_WIDTH) {
2290
- const brandStyle = buildTextStyle(
2516
+ const style = buildTextStyle(
2291
2517
  theme.chrome.footer,
2292
2518
  fontFamily,
2293
2519
  theme.chrome.footer.color,
2294
2520
  width,
2295
2521
  brandNorm.style
2296
2522
  );
2297
- brandStyle.textAnchor = "end";
2298
- const brandY = bottomItems.length > 0 ? theme.spacing.chartToFooter : theme.spacing.chartToFooter;
2523
+ style.textAnchor = "end";
2524
+ const naturalWidth = Math.max(
2525
+ ...brandNorm.text.split("\n").map(
2526
+ (line) => measureText?.(line, style.fontSize, style.fontWeight).width ?? line.length * estimateCharWidth(style.fontSize, style.fontWeight)
2527
+ )
2528
+ );
2299
2529
  brandElement = {
2300
2530
  text: brandNorm.text,
2301
2531
  x: width - pad + (brandNorm.offset?.dx ?? 0),
2302
- y: brandY + (brandNorm.offset?.dy ?? 0),
2303
- maxWidth: BRAND_RESERVE_WIDTH,
2304
- style: brandStyle
2532
+ y: startY + (brandNorm.offset?.dy ?? 0),
2533
+ maxWidth: Math.max(1, Math.min(maxWidth, naturalWidth)),
2534
+ ...brandNorm.style?.maxLines != null ? { maxLines: brandNorm.style.maxLines } : {},
2535
+ style
2305
2536
  };
2306
- if (bottomItems.length === 0) {
2307
- const brandHeight = estimateTextHeight(brandStyle.fontSize, 1, brandStyle.lineHeight);
2308
- bottomHeight = theme.spacing.chartToFooter + brandHeight + pad;
2537
+ }
2538
+ const brand = brandElement ?? watermarkElement;
2539
+ const brandHeight = brand ? estimateTextHeight(
2540
+ brand.style.fontSize,
2541
+ estimateLineCount(brand.text, brand.style, brand.maxWidth, measureText, brand.maxLines),
2542
+ brand.style.lineHeight
2543
+ ) : 0;
2544
+ const items = ["source", "byline", "footer"].flatMap((key) => {
2545
+ const norm = normalizeChromeText(chrome[key]);
2546
+ return norm ? [
2547
+ {
2548
+ key,
2549
+ norm,
2550
+ style: buildTextStyle(
2551
+ theme.chrome[key],
2552
+ fontFamily,
2553
+ theme.chrome[key].color,
2554
+ width,
2555
+ norm.style
2556
+ )
2557
+ }
2558
+ ] : [];
2559
+ });
2560
+ const gap = Math.max(12, chromeGap);
2561
+ const inlineWidth = brand ? Math.max(0, brand.x - brand.maxWidth - gap - pad) : maxWidth;
2562
+ function resolveItems(availableWidth) {
2563
+ const elements = {};
2564
+ let y = startY;
2565
+ let extent = startY;
2566
+ for (const { key, norm, style } of items) {
2567
+ const available = Math.max(1, availableWidth - Math.max(0, norm.offset?.dx ?? 0));
2568
+ const count = estimateLineCount(
2569
+ norm.text,
2570
+ style,
2571
+ available,
2572
+ measureText,
2573
+ norm.style?.maxLines
2574
+ );
2575
+ const height = estimateTextHeight(style.fontSize, count, style.lineHeight);
2576
+ const itemY = y + (norm.offset?.dy ?? 0);
2577
+ elements[key] = {
2578
+ text: norm.text,
2579
+ x: pad + (norm.offset?.dx ?? 0),
2580
+ y: itemY,
2581
+ maxWidth: available,
2582
+ ...norm.style?.maxLines != null ? { maxLines: norm.style.maxLines } : {},
2583
+ style
2584
+ };
2585
+ extent = Math.max(extent, itemY + height);
2586
+ y += height + chromeGap;
2309
2587
  }
2588
+ return {
2589
+ elements,
2590
+ extent,
2591
+ height: items.length ? Math.max(y - chromeGap, extent) - startY : 0
2592
+ };
2310
2593
  }
2594
+ const full = resolveItems(maxWidth);
2595
+ const inline = resolveItems(inlineWidth);
2596
+ const inlineHeight = Math.max(inline.height, (brand?.y ?? startY) - startY + brandHeight);
2597
+ const stackedHeight = full.height + (items.length ? chromeGap : 0) + brandHeight + Math.max(0, brandNorm?.offset?.dy ?? 0);
2598
+ const stacked = !!brand && items.length > 0 && (inlineWidth < 40 || stackedHeight < inlineHeight);
2599
+ const bottomElements = stacked ? full.elements : inline.elements;
2600
+ if (stacked && brand) brand.y += full.height + chromeGap;
2601
+ const contentHeight = stacked ? stackedHeight : inlineHeight;
2602
+ const bottomHeight = items.length || brand ? startY + contentHeight + pad : bottomLegendHeight;
2311
2603
  return {
2312
2604
  topHeight,
2313
2605
  bottomHeight,
2314
2606
  ...ruleElement ? { rule: ruleElement } : {},
2315
2607
  ...topElements,
2316
2608
  ...bottomElements,
2317
- ...brandElement ? { brand: brandElement } : {}
2609
+ ...brandElement ? { brand: brandElement } : {},
2610
+ ...watermarkElement ? { watermark: watermarkElement } : {},
2611
+ ...items.length || brand ? { attributionLayout: stacked ? "stacked" : "inline" } : {}
2318
2612
  };
2319
2613
  }
2320
2614
 
@@ -2509,6 +2803,12 @@ var FORMAT_PERCENT_RAW = d3Format(",.1~f");
2509
2803
  var FORMAT_CURRENCY_INTEGER = d3Format("$,");
2510
2804
  var FORMAT_CURRENCY_DECIMAL = d3Format("$,.2f");
2511
2805
  var FORMAT_STEP_FRACTION = [d3Format(".0~f"), d3Format(".1~f"), d3Format(".2~f")];
2806
+ var FORMAT_STEP_PRECISION = [
2807
+ d3Format(",.0~f"),
2808
+ d3Format(",.1~f"),
2809
+ d3Format(",.2~f"),
2810
+ d3Format(",.3~f")
2811
+ ];
2512
2812
  function formatNumber(value, _locale) {
2513
2813
  if (!Number.isFinite(value)) return String(value);
2514
2814
  if (Number.isInteger(value)) {
@@ -2600,6 +2900,10 @@ function buildD3Formatter(formatStr) {
2600
2900
  }
2601
2901
  function formatPercent(value, options) {
2602
2902
  const fraction = options?.fraction ?? true;
2903
+ const percent = fraction ? value * 100 : value;
2904
+ if (Number.isFinite(percent) && percent !== 0 && Math.abs(percent) < 0.1) {
2905
+ return percent < 0 ? `>${FORMAT_PERCENT_RAW(-0.1)}%` : `<${FORMAT_PERCENT_RAW(0.1)}%`;
2906
+ }
2603
2907
  if (fraction) {
2604
2908
  return FORMAT_PERCENT_FRACTION(value);
2605
2909
  }
@@ -2682,6 +2986,13 @@ function defaultNumberFormatter(ctx) {
2682
2986
  if (ctx?.step != null && (ctx.stepReference ?? maxAbs(ctx.extent)) >= 1e3) {
2683
2987
  return buildCompactStepFormatter(ctx.step);
2684
2988
  }
2989
+ if (ctx?.step != null && ctx.step > 0) {
2990
+ const p = fractionDigits(ctx.step);
2991
+ if (p <= 3) {
2992
+ const fmt = FORMAT_STEP_PRECISION[p];
2993
+ return (v) => Number.isFinite(v) ? fmt(v) : String(v);
2994
+ }
2995
+ }
2685
2996
  return (v) => {
2686
2997
  if (!Number.isFinite(v)) return String(v);
2687
2998
  if (ctx?.extent === void 0 && ctx?.allIntegers === void 0) {
@@ -2792,7 +3103,7 @@ function generateAltText(spec, data) {
2792
3103
  const markType = resolveMarkType(spec.mark);
2793
3104
  const markDef = resolveMarkDef(spec.mark);
2794
3105
  let chartName = MARK_DISPLAY_NAMES[markType] ?? `${markType} chart`;
2795
- if (markType === "arc" && markDef.innerRadius && markDef.innerRadius > 0) {
3106
+ if (markDef.type === "arc" && markDef.innerRadius && markDef.innerRadius > 0) {
2796
3107
  chartName = "Donut chart";
2797
3108
  }
2798
3109
  const isBinnedBar = markType === "bar" && !!spec.encoding.x2 && spec.encoding.x?.type === "quantitative" && spec.encoding.y?.type === "quantitative";
@@ -2805,7 +3116,7 @@ function generateAltText(spec, data) {
2805
3116
  const titleText = typeof title === "string" ? title : title.text;
2806
3117
  parts.push(`showing ${titleText}`);
2807
3118
  }
2808
- if (markType === "waffle") {
3119
+ if (markDef.type === "waffle") {
2809
3120
  const units = markDef.units ?? 100;
2810
3121
  parts.push(`dividing ${units} units`);
2811
3122
  }
@@ -2935,31 +3246,43 @@ function formatValue(value) {
2935
3246
  }
2936
3247
 
2937
3248
  // src/helpers/spec-builders.ts
2938
- var ISO_DATE_RE = /^\d{4}(-\d{2}(-\d{2}(T\d{2}(:\d{2}(:\d{2})?)?)?)?)?$/;
3249
+ var DATE_STRING_RES = [
3250
+ /^\d{4}-\d{2}(-\d{2}([T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?)?$/,
3251
+ /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?( \d{1,2},?)? \d{4}$/i,
3252
+ /^(\d{1,2}\/\d{1,2}\/\d{4}|\d{4}\/\d{1,2}\/\d{1,2})$/
3253
+ ];
2939
3254
  function inferFieldType(data, field) {
2940
- const sampleSize = Math.min(data.length, 20);
2941
- let hasNumber = false;
2942
- let hasDateString = false;
2943
- let hasOtherString = false;
3255
+ const sampleSize = Math.min(50, data.length);
3256
+ let numericCount = 0;
3257
+ let dateCount = 0;
3258
+ let totalNonNull = 0;
2944
3259
  for (let i = 0; i < sampleSize; i++) {
2945
3260
  const value = data[i][field];
2946
3261
  if (value == null) continue;
2947
- if (typeof value === "number") {
2948
- hasNumber = true;
2949
- } else if (typeof value === "string") {
2950
- if (ISO_DATE_RE.test(value) && !Number.isNaN(Date.parse(value))) {
2951
- hasDateString = true;
2952
- } else {
2953
- hasOtherString = true;
3262
+ totalNonNull++;
3263
+ if (typeof value === "number" && Number.isFinite(value)) {
3264
+ numericCount++;
3265
+ continue;
3266
+ }
3267
+ if (typeof value === "string") {
3268
+ const num = Number(value);
3269
+ if (!Number.isNaN(num) && Number.isFinite(num) && value.trim() !== "") {
3270
+ numericCount++;
3271
+ continue;
2954
3272
  }
2955
- } else if (value instanceof Date) {
2956
- hasDateString = true;
2957
- } else {
2958
- hasOtherString = true;
3273
+ const date = new Date(value);
3274
+ if (DATE_STRING_RES.some((re) => re.test(value)) && !Number.isNaN(date.getTime())) {
3275
+ dateCount++;
3276
+ continue;
3277
+ }
3278
+ }
3279
+ if (value instanceof Date && !Number.isNaN(value.getTime())) {
3280
+ dateCount++;
2959
3281
  }
2960
3282
  }
2961
- if (hasNumber && !hasDateString && !hasOtherString) return "quantitative";
2962
- if (hasDateString && !hasNumber && !hasOtherString) return "temporal";
3283
+ if (totalNonNull === 0) return "nominal";
3284
+ if (dateCount / totalNonNull > 0.8) return "temporal";
3285
+ if (numericCount / totalNonNull > 0.8) return "quantitative";
2963
3286
  return "nominal";
2964
3287
  }
2965
3288
  function resolveField(ref, data) {
@@ -2984,7 +3307,6 @@ function buildChartSpec(mark, data, encoding, options) {
2984
3307
  if (options?.annotations) spec.annotations = options.annotations;
2985
3308
  if (options?.responsive !== void 0) spec.responsive = options.responsive;
2986
3309
  if (options?.theme) spec.theme = options.theme;
2987
- if (options?.darkMode) spec.darkMode = options.darkMode;
2988
3310
  return spec;
2989
3311
  }
2990
3312
  function lineChart(data, x, y, options) {
@@ -3068,11 +3390,10 @@ function dataTable(data, options) {
3068
3390
  if (options?.rowKey) spec.rowKey = options.rowKey;
3069
3391
  if (options?.chrome) spec.chrome = options.chrome;
3070
3392
  if (options?.theme) spec.theme = options.theme;
3071
- if (options?.darkMode) spec.darkMode = options.darkMode;
3072
3393
  if (options?.search !== void 0) spec.search = options.search;
3073
3394
  if (options?.pagination !== void 0) spec.pagination = options.pagination;
3074
3395
  if (options?.stickyFirstColumn !== void 0) spec.stickyFirstColumn = options.stickyFirstColumn;
3075
- if (options?.compact !== void 0) spec.compact = options.compact;
3396
+ if (options?.density !== void 0) spec.density = options.density;
3076
3397
  if (options?.responsive !== void 0) spec.responsive = options.responsive;
3077
3398
  return spec;
3078
3399
  }
@@ -3086,7 +3407,6 @@ function tileMap(data, options) {
3086
3407
  ...options?.chrome && { chrome: options.chrome },
3087
3408
  ...options?.legend && { legend: options.legend },
3088
3409
  ...options?.theme && { theme: options.theme },
3089
- ...options?.darkMode && { darkMode: options.darkMode },
3090
3410
  ...options?.watermark !== void 0 && { watermark: options.watermark },
3091
3411
  ...options?.animation && { animation: options.animation },
3092
3412
  ...options?.valueFormat && { valueFormat: options.valueFormat }
@@ -3107,6 +3427,28 @@ function deepMergeSpec(target, source) {
3107
3427
  return result;
3108
3428
  }
3109
3429
 
3430
+ // src/helpers/annotation-source.ts
3431
+ var object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
3432
+ function annotationSource(spec) {
3433
+ const root = object(spec);
3434
+ if (Array.isArray(root?.annotations))
3435
+ return { annotations: root.annotations, path: "/annotations" };
3436
+ function firstLeaf(node, path) {
3437
+ if (Array.isArray(node?.layer)) {
3438
+ for (const [index, child] of node.layer.entries()) {
3439
+ const result = firstLeaf(object(child), `${path}/layer/${index}`);
3440
+ if (result) return result;
3441
+ }
3442
+ } else if (node && "mark" in node) {
3443
+ return {
3444
+ annotations: Array.isArray(node.annotations) ? node.annotations : [],
3445
+ path: `${path}/annotations`
3446
+ };
3447
+ }
3448
+ }
3449
+ return firstLeaf(root, "") ?? { annotations: [], path: "/annotations" };
3450
+ }
3451
+
3110
3452
  // src/motion/sample.ts
3111
3453
  var MOTION_REST_THRESHOLD = 1e-3;
3112
3454
  var MAX_SPRING_DURATION = 1200;
@@ -3216,7 +3558,6 @@ export {
3216
3558
  HPAD_COMPACT_MIN,
3217
3559
  LABEL_GAP_COMPACT,
3218
3560
  LABEL_GAP_DEFAULT,
3219
- LABEL_GAP_NARROW_MAX,
3220
3561
  MARK_DISPLAY_NAMES,
3221
3562
  MARK_ENCODING_RULES,
3222
3563
  MARK_TYPES,
@@ -3234,7 +3575,6 @@ export {
3234
3575
  TICK_LABEL_OFFSET,
3235
3576
  TICK_LINE_HEIGHT_FACTOR,
3236
3577
  TOP_PAD_EXTRA_NARROW,
3237
- TOP_PAD_NARROW_MAX,
3238
3578
  X_AXIS_BAND_HEIGHT,
3239
3579
  X_AXIS_ROTATED_EXTENT_CAP,
3240
3580
  X_AXIS_TITLE_BAND,
@@ -3243,6 +3583,8 @@ export {
3243
3583
  adaptColorForDarkMode,
3244
3584
  adaptForLightLineStroke,
3245
3585
  adaptTheme,
3586
+ annotationSource,
3587
+ applyEditTransaction,
3246
3588
  areaChart,
3247
3589
  axisTitleOffset,
3248
3590
  barChart,
@@ -3256,6 +3598,7 @@ export {
3256
3598
  computeChrome,
3257
3599
  computeFieldFormatContext,
3258
3600
  computeLabelBounds,
3601
+ computeNoteBandHeight,
3259
3602
  computeXAxisExtentFromLabels,
3260
3603
  contrastRatio,
3261
3604
  cssTokenDefault,
@@ -3266,12 +3609,11 @@ export {
3266
3609
  detectCollision,
3267
3610
  donutChart,
3268
3611
  dotChart,
3269
- editorial,
3270
3612
  elementRef,
3613
+ encodePointerToken,
3271
3614
  essay,
3272
3615
  estimateTextWidth,
3273
3616
  findAccessibleColor,
3274
- footnoteBandHeight,
3275
3617
  formatCurrency,
3276
3618
  formatDate,
3277
3619
  formatNumber,
@@ -3305,10 +3647,12 @@ export {
3305
3647
  isTileMapSpec,
3306
3648
  isValueDef,
3307
3649
  isYearContext,
3650
+ jsonPointer,
3308
3651
  legacyEditorial,
3309
3652
  lineChart,
3310
3653
  maxRotatedLabelWidth,
3311
3654
  meetsAA,
3655
+ mergeThemeConfig,
3312
3656
  motionCSS,
3313
3657
  overlapArea,
3314
3658
  pickLabelColor,