@opendata-ai/openchart-core 9.6.1 → 9.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1436,8 +1436,11 @@ var VL_SCHEME_ALIASES = {
1436
1436
  category10: "categorical",
1437
1437
  tableau10: "categorical"
1438
1438
  };
1439
+ function canonicalSchemeName(name) {
1440
+ return SEQUENTIAL_PALETTES[name] || DIVERGING_PALETTES[name] ? name : VL_SCHEME_ALIASES[name.toLowerCase()] ?? name.toLowerCase();
1441
+ }
1439
1442
  function resolveSchemeName(name) {
1440
- const canonical = SEQUENTIAL_PALETTES[name] || DIVERGING_PALETTES[name] ? name : VL_SCHEME_ALIASES[name.toLowerCase()] ?? name.toLowerCase();
1443
+ const canonical = canonicalSchemeName(name);
1441
1444
  if (canonical === "categorical") return [...CATEGORICAL_PALETTE];
1442
1445
  return SEQUENTIAL_PALETTES[canonical] ?? DIVERGING_PALETTES[canonical];
1443
1446
  }
@@ -1958,6 +1961,8 @@ var FONT_SIZES = {
1958
1961
  endpointValue: 12
1959
1962
  };
1960
1963
  var DEFAULT_THEME = /* @__PURE__ */ (() => ({
1964
+ locale: "en-US",
1965
+ logo: null,
1961
1966
  colors: {
1962
1967
  categorical: [...CATEGORICAL_PALETTE],
1963
1968
  categoricalFill: [...CATEGORICAL_FILL_PALETTE],
@@ -2134,6 +2139,12 @@ function adaptTheme(theme) {
2134
2139
  };
2135
2140
  const categorical = paletteForDark("categorical", CATEGORICAL_PALETTE_DARK);
2136
2141
  const categoricalFill = paletteForDark("categoricalFill", CATEGORICAL_FILL_PALETTE_DARK);
2142
+ const rampsForDark = (kind) => Object.fromEntries(
2143
+ Object.entries(theme.colors[kind]).map(([name, stops]) => [
2144
+ name,
2145
+ stops.map((color, index) => theme._rampPairs?.[kind]?.[name]?.[index]?.dark ?? color)
2146
+ ])
2147
+ );
2137
2148
  const neutral = deriveNeutralRamp(darkText, darkBg, true);
2138
2149
  const authoredColors = theme._authored?.colors && !Array.isArray(theme._authored.colors) ? theme._authored.colors : {};
2139
2150
  const authoredColor = (key, fallback) => pairs?.[`colors.${key}`]?.dark ?? (authoredColors[key] !== void 0 ? theme.colors[key] ?? fallback : fallback);
@@ -2163,6 +2174,8 @@ function adaptTheme(theme) {
2163
2174
  mapOutlineBorder: authoredColor("mapOutlineBorder", "rgba(255,255,255,0.38)"),
2164
2175
  categorical,
2165
2176
  categoricalFill,
2177
+ sequential: rampsForDark("sequential"),
2178
+ diverging: rampsForDark("diverging"),
2166
2179
  hairline: darkHairline,
2167
2180
  positive: pairs?.["colors.positive"] ? pairs["colors.positive"].dark : overridden(theme.colors.positive, light.positive, "#4ade80"),
2168
2181
  negative: pairs?.["colors.negative"] ? pairs["colors.negative"].dark : overridden(theme.colors.negative, light.negative, "#f87171"),
@@ -2375,12 +2388,46 @@ var legacyEditorial = {
2375
2388
  spacing: { padding: 20, chromeGap: 6, chromeToChart: 8, chartToFooter: 8 }
2376
2389
  };
2377
2390
 
2391
+ // src/locale/supported.ts
2392
+ var SUPPORTED_LOCALES = [
2393
+ "en-US",
2394
+ "en-GB",
2395
+ "de-DE",
2396
+ "fr-FR",
2397
+ "es-ES",
2398
+ "pt-BR",
2399
+ "pt-PT",
2400
+ "it-IT",
2401
+ "nl-NL"
2402
+ ];
2403
+ function isSupportedLocale(tag) {
2404
+ return SUPPORTED_LOCALES.some((locale) => locale === tag);
2405
+ }
2406
+ function matchLocale(tag) {
2407
+ if (typeof tag !== "string") return null;
2408
+ const lower = tag.toLowerCase();
2409
+ const exact = SUPPORTED_LOCALES.find((locale) => locale.toLowerCase() === lower);
2410
+ if (exact) return exact;
2411
+ const aliases = {
2412
+ de: "de-DE",
2413
+ en: "en-US",
2414
+ fr: "fr-FR",
2415
+ es: "es-ES",
2416
+ it: "it-IT",
2417
+ nl: "nl-NL",
2418
+ pt: "pt-BR"
2419
+ };
2420
+ return Object.hasOwn(aliases, lower) ? aliases[lower] : null;
2421
+ }
2422
+
2378
2423
  // src/theme/resolve.ts
2379
2424
  function resolveTokenLight(v) {
2380
2425
  return typeof v === "string" ? v : v.light;
2381
2426
  }
2382
2427
  function themeConfigToPartial(config, base2) {
2383
2428
  const partial = {};
2429
+ if (config.locale !== void 0) partial.locale = matchLocale(config.locale) ?? "en-US";
2430
+ if (config.logo !== void 0) partial.logo = config.logo;
2384
2431
  if (config.colors) {
2385
2432
  const colors = {};
2386
2433
  if (Array.isArray(config.colors)) {
@@ -2390,8 +2437,22 @@ function themeConfigToPartial(config, base2) {
2390
2437
  colors.categorical = config.colors.categorical.map(resolveTokenLight);
2391
2438
  if (config.colors.categoricalFill)
2392
2439
  colors.categoricalFill = config.colors.categoricalFill.map(resolveTokenLight);
2393
- if (config.colors.sequential) colors.sequential = config.colors.sequential;
2394
- if (config.colors.diverging) colors.diverging = config.colors.diverging;
2440
+ if (config.colors.sequential) {
2441
+ colors.sequential = Object.fromEntries(
2442
+ Object.entries(config.colors.sequential).map(([name, stops]) => [
2443
+ name,
2444
+ stops.map(resolveTokenLight)
2445
+ ])
2446
+ );
2447
+ }
2448
+ if (config.colors.diverging) {
2449
+ colors.diverging = Object.fromEntries(
2450
+ Object.entries(config.colors.diverging).map(([name, stops]) => [
2451
+ name,
2452
+ stops.map(resolveTokenLight)
2453
+ ])
2454
+ );
2455
+ }
2395
2456
  if (config.colors.background) colors.background = resolveTokenLight(config.colors.background);
2396
2457
  if (config.colors.text) colors.text = resolveTokenLight(config.colors.text);
2397
2458
  if (config.colors.gridline) colors.gridline = resolveTokenLight(config.colors.gridline);
@@ -2475,6 +2536,9 @@ function themeConfigToPartial(config, base2) {
2475
2536
  if (obj.fontSize !== void 0) override.fontSize = obj.fontSize;
2476
2537
  if (obj.fontWeight !== void 0) override.fontWeight = obj.fontWeight;
2477
2538
  if (obj.lineHeight !== void 0) override.lineHeight = obj.lineHeight;
2539
+ if (obj.fontFamily !== void 0) override.fontFamily = obj.fontFamily;
2540
+ if (obj.textAlign !== void 0) override.textAlign = obj.textAlign;
2541
+ if (obj.prefix !== void 0) override.prefix = obj.prefix;
2478
2542
  chrome[element] = override;
2479
2543
  }
2480
2544
  }
@@ -2547,6 +2611,22 @@ function collectTokenPairs(config) {
2547
2611
  }
2548
2612
  return Object.keys(pairs).length > 0 ? pairs : void 0;
2549
2613
  }
2614
+ function collectRampPairs(config) {
2615
+ if (!config.colors || Array.isArray(config.colors)) return void 0;
2616
+ const result = {};
2617
+ for (const kind of ["sequential", "diverging"]) {
2618
+ const ramps = config.colors[kind];
2619
+ if (ramps) {
2620
+ result[kind] = Object.fromEntries(
2621
+ Object.entries(ramps).map(([name, stops]) => [
2622
+ name,
2623
+ stops.map((stop) => typeof stop === "string" ? void 0 : stop)
2624
+ ])
2625
+ );
2626
+ }
2627
+ }
2628
+ return Object.keys(result).length ? result : void 0;
2629
+ }
2550
2630
  function relativeLuminance2(hex) {
2551
2631
  const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
2552
2632
  if (!m) return 0;
@@ -2645,6 +2725,7 @@ function resolveTheme(userTheme, base2 = DEFAULT_THEME) {
2645
2725
  }
2646
2726
  const neutral = deriveNeutralRamp(merged.colors.text, merged.colors.background, dark);
2647
2727
  const authoredColors = userTheme?.colors && !Array.isArray(userTheme.colors) ? userTheme.colors : {};
2728
+ const rampPairs = userTheme ? collectRampPairs(userTheme) : void 0;
2648
2729
  return {
2649
2730
  ...merged,
2650
2731
  _authored: userTheme,
@@ -2655,10 +2736,108 @@ function resolveTheme(userTheme, base2 = DEFAULT_THEME) {
2655
2736
  annotationPlate: authoredColors.annotationPlate === void 0 ? neutral.surface : merged.colors.annotationPlate
2656
2737
  },
2657
2738
  isDark: dark,
2658
- _tokenPairs: userTheme ? collectTokenPairs(userTheme) : void 0
2739
+ _tokenPairs: userTheme ? collectTokenPairs(userTheme) : void 0,
2740
+ ...rampPairs ? { _rampPairs: rampPairs } : {}
2659
2741
  };
2660
2742
  }
2661
2743
 
2744
+ // src/layout/chrome-align.ts
2745
+ function alignChromeText(align, width, padding, dx = 0) {
2746
+ if (align === "center") return { x: width / 2 + dx, textAnchor: "middle" };
2747
+ if (align === "right") return { x: width - padding + dx, textAnchor: "end" };
2748
+ return { x: padding + dx, textAnchor: "start" };
2749
+ }
2750
+ function chromePrefix(text, prefix) {
2751
+ return typeof prefix === "string" && prefix && !text.trimStart().toLowerCase().startsWith(prefix.trim().toLowerCase()) ? { prefix } : {};
2752
+ }
2753
+
2754
+ // src/layout/logo-source.ts
2755
+ function isSafeLogoSource(src) {
2756
+ return /^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(src) || /^data:image\/svg\+xml(;[cC][hH][aA][rR][sS][eE][tT]=[uU][tT][fF]-8)?(;base64)?,/.test(src);
2757
+ }
2758
+ function positiveSize(width, height) {
2759
+ return Number.isFinite(width) && width > 0 && Number.isFinite(height) && height > 0 ? { width, height } : null;
2760
+ }
2761
+ function readLogoSize(src) {
2762
+ if (!isSafeLogoSource(src)) return null;
2763
+ const comma = src.indexOf(",");
2764
+ const header = src.slice(0, comma);
2765
+ const payload = src.slice(comma + 1);
2766
+ let decoded;
2767
+ try {
2768
+ decoded = header.endsWith(";base64") ? atob(payload) : decodeURIComponent(payload);
2769
+ } catch (error) {
2770
+ if (error instanceof URIError || error instanceof Error && error.name === "InvalidCharacterError")
2771
+ return null;
2772
+ throw error;
2773
+ }
2774
+ if (header === "data:image/png;base64") {
2775
+ if (decoded.length < 24 || decoded.slice(0, 8) !== "\x89PNG\r\n\n" || decoded.slice(12, 16) !== "IHDR")
2776
+ return null;
2777
+ const bytes = Uint8Array.from(decoded.slice(16, 24), (char) => char.charCodeAt(0));
2778
+ const view = new DataView(bytes.buffer);
2779
+ return positiveSize(view.getUint32(0), view.getUint32(4));
2780
+ }
2781
+ const root = /<svg\b([^>]*)>/i.exec(decoded.replace(/<!--[\s\S]*?-->/g, ""))?.[1];
2782
+ if (root === void 0) return null;
2783
+ const attr = (name) => new RegExp(`\\s${name}\\s*=\\s*(["'])(.*?)\\1`, "i").exec(root)?.[2];
2784
+ const dimension = (value) => value && /^\s*\d*\.?\d+(?:e[+-]?\d+)?(?:px)?\s*$/i.test(value) ? Number.parseFloat(value) : 0;
2785
+ const explicit = positiveSize(dimension(attr("width")) || 0, dimension(attr("height")) || 0);
2786
+ if (explicit) return explicit;
2787
+ const viewBox = attr("viewBox")?.trim().split(/[\s,]+/).map(Number);
2788
+ return viewBox?.length === 4 && viewBox.every(Number.isFinite) ? positiveSize(viewBox[2], viewBox[3]) : null;
2789
+ }
2790
+
2791
+ // src/layout/chrome-logo.ts
2792
+ var MIN_CHROME_TEXT_WIDTH = 120;
2793
+ function resolveChromeLogo(logo, width, padding) {
2794
+ if (!logo || typeof logo !== "object" || Array.isArray(logo) || typeof logo.src !== "string" || !isSafeLogoSource(logo.src) || !Number.isFinite(logo.height) || logo.height <= 0 || logo.width !== void 0 && (!Number.isFinite(logo.width) || logo.width <= 0))
2795
+ return void 0;
2796
+ const intrinsic = readLogoSize(logo.src);
2797
+ const logoWidth = intrinsic ? logo.height * intrinsic.width / intrinsic.height : logo.width ?? logo.height;
2798
+ const availableWidth = width - padding * 2;
2799
+ if (!Number.isFinite(logoWidth) || logoWidth <= 0 || availableWidth <= 0) return void 0;
2800
+ const scale2 = Math.min(1, availableWidth / logoWidth);
2801
+ const resolvedWidth = Math.min(logoWidth, availableWidth);
2802
+ const position = logo.position === "top-left" || logo.position === "top-right" || logo.position === "bottom-left" ? logo.position : "bottom-right";
2803
+ return {
2804
+ href: logo.src,
2805
+ x: position.endsWith("left") ? padding : width - padding - resolvedWidth,
2806
+ y: 0,
2807
+ width: resolvedWidth,
2808
+ height: logo.height * scale2,
2809
+ position,
2810
+ ...typeof logo.alt === "string" ? { alt: logo.alt } : {}
2811
+ };
2812
+ }
2813
+ function planTopLogo(logo, padding, gap, textWidth) {
2814
+ if (!logo?.position.startsWith("top")) return { before: 0, beside: 0, height: 0 };
2815
+ const ownRow = logo.position === "top-left" || textWidth - logo.width - gap < MIN_CHROME_TEXT_WIDTH;
2816
+ return {
2817
+ logo: { ...logo, y: padding },
2818
+ before: ownRow ? logo.height + gap : 0,
2819
+ beside: ownRow ? 0 : logo.width + gap,
2820
+ height: logo.height
2821
+ };
2822
+ }
2823
+ function planBottomRightLogo(logo, brandWidth, brandHeight, contentWidth, gap, y) {
2824
+ if (logo?.position !== "bottom-right")
2825
+ return { reservedWidth: 0, height: brandHeight, ownRow: false, brandShift: 0 };
2826
+ const ownRow = brandWidth > 0 && brandWidth + gap + logo.width > contentWidth;
2827
+ return {
2828
+ logo: { ...logo, y: y + (ownRow ? brandHeight + gap : 0) },
2829
+ reservedWidth: ownRow ? 0 : logo.width + gap,
2830
+ height: ownRow ? brandHeight + gap + logo.height : Math.max(brandHeight, logo.height),
2831
+ ownRow,
2832
+ brandShift: ownRow || brandWidth === 0 ? 0 : logo.width + gap
2833
+ };
2834
+ }
2835
+ function planBottomLeftLogo(logo, contentBottom, gap, hasFooter) {
2836
+ if (logo?.position !== "bottom-left") return { height: 0 };
2837
+ const before = hasFooter ? gap : 0;
2838
+ return { logo: { ...logo, y: contentBottom + before }, height: before + logo.height };
2839
+ }
2840
+
2662
2841
  // src/layout/chrome.ts
2663
2842
  function isSafeLink(href) {
2664
2843
  try {
@@ -2691,12 +2870,12 @@ function buildTextStyle(defaults, fontFamily, textColor, width, overrides, extra
2691
2870
  const baseFontSize = overrides?.fontSize ?? defaults.fontSize;
2692
2871
  const fontSize = hasExplicitSize ? baseFontSize : Math.max(Math.round(scaleFontSize(baseFontSize, width) * extraScale), 10);
2693
2872
  return {
2694
- fontFamily: overrides?.fontFamily ?? fontFamily,
2873
+ fontFamily: typeof overrides?.fontFamily === "string" ? overrides.fontFamily : typeof defaults.fontFamily === "string" ? defaults.fontFamily : fontFamily,
2695
2874
  fontSize,
2696
2875
  fontWeight: overrides?.fontWeight ?? defaults.fontWeight,
2697
2876
  fill: overrides?.color ?? textColor ?? defaults.color,
2698
2877
  lineHeight: defaults.lineHeight,
2699
- textAnchor: "start"
2878
+ textAnchor: defaults.textAlign === "center" ? "middle" : defaults.textAlign === "right" ? "end" : "start"
2700
2879
  };
2701
2880
  }
2702
2881
  function estimateLineCount(text, style, maxWidth, measureText, maxLines) {
@@ -2709,14 +2888,19 @@ function estimateLineCount(text, style, maxWidth, measureText, maxLines) {
2709
2888
  return maxLines != null ? Math.min(count, maxLines) : count;
2710
2889
  }
2711
2890
  if (measureText) {
2712
- const textWidth = measureText(text, style.fontSize, style.fontWeight).width;
2891
+ const textWidth = measureText(text, style.fontSize, style.fontWeight, style.fontFamily).width;
2713
2892
  if (textWidth <= maxWidth) return 1;
2714
2893
  const words2 = text.split(" ");
2715
2894
  let lines2 = 1;
2716
2895
  let current2 = "";
2717
2896
  for (const word of words2) {
2718
2897
  const candidate = current2 ? `${current2} ${word}` : word;
2719
- const candidateWidth = measureText(candidate, style.fontSize, style.fontWeight).width;
2898
+ const candidateWidth = measureText(
2899
+ candidate,
2900
+ style.fontSize,
2901
+ style.fontWeight,
2902
+ style.fontFamily
2903
+ ).width;
2720
2904
  if (candidateWidth > maxWidth && current2) {
2721
2905
  lines2++;
2722
2906
  current2 = word;
@@ -2764,12 +2948,17 @@ function measuredWatermark(theme, width, pad, y, measureText) {
2764
2948
  text: "OpenChart",
2765
2949
  x: width - pad,
2766
2950
  y,
2767
- maxWidth: measureText?.("OpenChart", BRAND_FONT_SIZE, 600).width ?? "OpenChart".length * estimateCharWidth(BRAND_FONT_SIZE, 600),
2951
+ maxWidth: measureText?.("OpenChart", BRAND_FONT_SIZE, 600, style.fontFamily).width ?? "OpenChart".length * estimateCharWidth(BRAND_FONT_SIZE, 600),
2768
2952
  style
2769
2953
  };
2770
2954
  }
2771
- function computeChrome(chrome, theme, width, measureText, chromeMode = "full", padding, watermark = true, bottomLegendHeight = 0, crampedTitle = false) {
2772
- if (!chrome || chromeMode === "hidden") {
2955
+ function inheritBodyFamily(measureText, bodyFamily) {
2956
+ return measureText ? (text, fontSize, fontWeight, fontFamily) => measureText(text, fontSize, fontWeight, fontFamily === bodyFamily ? void 0 : fontFamily) : void 0;
2957
+ }
2958
+ function computeChrome(chrome, theme, width, measureTextFn, chromeMode = "full", padding, watermark = true, bottomLegendHeight = 0, crampedTitle = false) {
2959
+ const measureText = inheritBodyFamily(measureTextFn, theme.fonts.family);
2960
+ const logo = chromeMode === "full" && width >= BRAND_MIN_WIDTH && (chrome?.logo === void 0 || chrome.logo === true) ? resolveChromeLogo(theme.logo, width, padding ?? theme.spacing.padding) : void 0;
2961
+ if (!chrome && !logo || chromeMode === "hidden") {
2773
2962
  if (watermark && width >= BRAND_MIN_WIDTH) {
2774
2963
  const hiddenPad = padding ?? theme.spacing.padding;
2775
2964
  const brandHeight2 = estimateTextHeight(BRAND_FONT_SIZE, 1);
@@ -2790,20 +2979,30 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2790
2979
  }
2791
2980
  return { topHeight: 0, bottomHeight: 0 };
2792
2981
  }
2982
+ chrome ??= {};
2793
2983
  const pad = padding ?? theme.spacing.padding;
2794
2984
  const chromeGap = theme.spacing.chromeGap;
2795
2985
  const WRAP_SAFETY_BUFFER = 5;
2796
2986
  const maxWidth = width - pad * 2 - WRAP_SAFETY_BUFFER;
2987
+ const topLogo = planTopLogo(logo, pad, chromeGap, maxWidth);
2988
+ const topWidth = width - topLogo.beside;
2989
+ const topMaxWidth = topLogo.beside > 0 ? topWidth - pad * 2 - WRAP_SAFETY_BUFFER : maxWidth;
2797
2990
  const fontFamily = theme.fonts.family;
2798
- let topY = pad;
2991
+ let topY = pad + topLogo.before;
2799
2992
  const topElements = {};
2800
2993
  const eyebrowNorm = chromeMode === "compact" ? null : normalizeChromeText(chrome.eyebrow);
2801
2994
  const titleNormPeek = normalizeChromeText(chrome.title);
2802
2995
  const subtitleNormPeek = chromeMode === "compact" ? null : normalizeChromeText(chrome.subtitle);
2803
2996
  let ruleElement;
2804
2997
  if (theme.rule && (eyebrowNorm || titleNormPeek || subtitleNormPeek)) {
2998
+ const { x, textAnchor } = alignChromeText(
2999
+ theme.chrome.title.textAlign,
3000
+ topWidth,
3001
+ pad,
3002
+ theme.chrome.title.textAlign ? titleNormPeek?.offset?.dx : 0
3003
+ );
2805
3004
  ruleElement = {
2806
- x: pad,
3005
+ x: x - (textAnchor === "middle" ? theme.rule.width / 2 : textAnchor === "end" ? theme.rule.width : 0),
2807
3006
  y: topY,
2808
3007
  width: theme.rule.width,
2809
3008
  thickness: theme.rule.thickness,
@@ -2820,13 +3019,21 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2820
3019
  eyebrowNorm.style
2821
3020
  );
2822
3021
  const maxLines = eyebrowNorm.style?.maxLines;
2823
- const lineCount = estimateLineCount(eyebrowNorm.text, style, maxWidth, measureText, maxLines);
3022
+ const prefix = chromePrefix(eyebrowNorm.text, theme.chrome.eyebrow.prefix);
3023
+ const lineCount = estimateLineCount(
3024
+ (prefix.prefix ?? "") + eyebrowNorm.text,
3025
+ style,
3026
+ topMaxWidth,
3027
+ measureText,
3028
+ maxLines
3029
+ );
2824
3030
  const element = {
2825
3031
  text: eyebrowNorm.text,
3032
+ ...prefix,
2826
3033
  ...eyebrowNorm.href ? { href: eyebrowNorm.href } : {},
2827
- x: pad + (eyebrowNorm.offset?.dx ?? 0),
3034
+ x: alignChromeText(theme.chrome.eyebrow.textAlign, topWidth, pad, eyebrowNorm.offset?.dx).x,
2828
3035
  y: topY + (eyebrowNorm.offset?.dy ?? 0),
2829
- maxWidth,
3036
+ maxWidth: topMaxWidth,
2830
3037
  ...maxLines != null ? { maxLines } : {},
2831
3038
  style
2832
3039
  };
@@ -2844,13 +3051,21 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2844
3051
  crampedTitle ? CRAMPED_TITLE_SCALE : 1
2845
3052
  );
2846
3053
  const maxLines = titleNorm.style?.maxLines;
2847
- const lineCount = estimateLineCount(titleNorm.text, style, maxWidth, measureText, maxLines);
3054
+ const prefix = chromePrefix(titleNorm.text, theme.chrome.title.prefix);
3055
+ const lineCount = estimateLineCount(
3056
+ (prefix.prefix ?? "") + titleNorm.text,
3057
+ style,
3058
+ topMaxWidth,
3059
+ measureText,
3060
+ maxLines
3061
+ );
2848
3062
  const element = {
2849
3063
  text: titleNorm.text,
3064
+ ...prefix,
2850
3065
  ...titleNorm.href ? { href: titleNorm.href } : {},
2851
- x: pad + (titleNorm.offset?.dx ?? 0),
3066
+ x: alignChromeText(theme.chrome.title.textAlign, topWidth, pad, titleNorm.offset?.dx).x,
2852
3067
  y: topY + (titleNorm.offset?.dy ?? 0),
2853
- maxWidth,
3068
+ maxWidth: topMaxWidth,
2854
3069
  ...maxLines != null ? { maxLines } : {},
2855
3070
  style
2856
3071
  };
@@ -2867,13 +3082,21 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2867
3082
  subtitleNorm.style
2868
3083
  );
2869
3084
  const maxLines = subtitleNorm.style?.maxLines;
2870
- const lineCount = estimateLineCount(subtitleNorm.text, style, maxWidth, measureText, maxLines);
3085
+ const prefix = chromePrefix(subtitleNorm.text, theme.chrome.subtitle.prefix);
3086
+ const lineCount = estimateLineCount(
3087
+ (prefix.prefix ?? "") + subtitleNorm.text,
3088
+ style,
3089
+ topMaxWidth,
3090
+ measureText,
3091
+ maxLines
3092
+ );
2871
3093
  const element = {
2872
3094
  text: subtitleNorm.text,
3095
+ ...prefix,
2873
3096
  ...subtitleNorm.href ? { href: subtitleNorm.href } : {},
2874
- x: pad + (subtitleNorm.offset?.dx ?? 0),
3097
+ x: alignChromeText(theme.chrome.subtitle.textAlign, topWidth, pad, subtitleNorm.offset?.dx).x,
2875
3098
  y: topY + (subtitleNorm.offset?.dy ?? 0),
2876
- maxWidth,
3099
+ maxWidth: topMaxWidth,
2877
3100
  ...maxLines != null ? { maxLines } : {},
2878
3101
  style
2879
3102
  };
@@ -2882,7 +3105,8 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2882
3105
  }
2883
3106
  const hasTopChrome = eyebrowNorm || titleNorm || subtitleNorm;
2884
3107
  const chromeToChart = width < COMPACT_WIDTH ? Math.min(theme.spacing.chromeToChart, 2) : theme.spacing.chromeToChart;
2885
- const topHeight = hasTopChrome ? topY - pad + chromeToChart - chromeGap : 0;
3108
+ const textTopHeight = hasTopChrome ? topY - pad + chromeToChart - chromeGap : 0;
3109
+ const topHeight = topLogo.logo ? Math.max(textTopHeight, topLogo.height + chromeToChart) : textTopHeight;
2886
3110
  if (chromeMode === "compact") {
2887
3111
  let compactBottom = 0;
2888
3112
  if (watermark && width >= BRAND_MIN_WIDTH) {
@@ -2922,7 +3146,7 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2922
3146
  style.textAnchor = "end";
2923
3147
  const naturalWidth = Math.max(
2924
3148
  ...brandNorm.text.split("\n").map(
2925
- (line) => measureText?.(line, style.fontSize, style.fontWeight).width ?? line.length * estimateCharWidth(style.fontSize, style.fontWeight)
3149
+ (line) => measureText?.(line, style.fontSize, style.fontWeight, style.fontFamily).width ?? line.length * estimateCharWidth(style.fontSize, style.fontWeight)
2926
3150
  )
2927
3151
  );
2928
3152
  brandElement = {
@@ -2936,11 +3160,21 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2936
3160
  };
2937
3161
  }
2938
3162
  const brand = brandElement ?? watermarkElement;
3163
+ const gap = Math.max(12, chromeGap);
2939
3164
  const brandHeight = brand ? estimateTextHeight(
2940
3165
  brand.style.fontSize,
2941
3166
  estimateLineCount(brand.text, brand.style, brand.maxWidth, measureText, brand.maxLines),
2942
3167
  brand.style.lineHeight
2943
3168
  ) : 0;
3169
+ const rightLogo = planBottomRightLogo(
3170
+ logo,
3171
+ brand?.maxWidth ?? 0,
3172
+ brandHeight,
3173
+ width - pad * 2,
3174
+ gap,
3175
+ startY
3176
+ );
3177
+ if (brand) brand.x -= rightLogo.brandShift;
2944
3178
  const items = ["source", "byline", "footer"].flatMap((key) => {
2945
3179
  const norm = normalizeChromeText(chrome[key]);
2946
3180
  return norm ? [
@@ -2957,16 +3191,16 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2957
3191
  }
2958
3192
  ] : [];
2959
3193
  });
2960
- const gap = Math.max(12, chromeGap);
2961
- const inlineWidth = brand ? Math.max(0, brand.x - brand.maxWidth - gap - pad) : maxWidth;
3194
+ const inlineWidth = brand ? Math.max(0, brand.x - brand.maxWidth - gap - pad) : rightLogo.reservedWidth > 0 ? Math.max(0, width - pad * 2 - rightLogo.reservedWidth) : maxWidth;
2962
3195
  function resolveItems(availableWidth) {
2963
3196
  const elements = {};
2964
3197
  let y = startY;
2965
3198
  let extent = startY;
2966
3199
  for (const { key, norm, style } of items) {
2967
3200
  const available = Math.max(1, availableWidth - Math.max(0, norm.offset?.dx ?? 0));
3201
+ const prefix = chromePrefix(norm.text, theme.chrome[key].prefix);
2968
3202
  const count = estimateLineCount(
2969
- norm.text,
3203
+ (prefix.prefix ?? "") + norm.text,
2970
3204
  style,
2971
3205
  available,
2972
3206
  measureText,
@@ -2976,8 +3210,9 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2976
3210
  const itemY = y + (norm.offset?.dy ?? 0);
2977
3211
  elements[key] = {
2978
3212
  text: norm.text,
3213
+ ...prefix,
2979
3214
  ...norm.href ? { href: norm.href } : {},
2980
- x: pad + (norm.offset?.dx ?? 0),
3215
+ x: alignChromeText(theme.chrome[key].textAlign, width, pad, norm.offset?.dx).x,
2981
3216
  y: itemY,
2982
3217
  maxWidth: available,
2983
3218
  ...norm.style?.maxLines != null ? { maxLines: norm.style.maxLines } : {},
@@ -2994,13 +3229,34 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
2994
3229
  }
2995
3230
  const full = resolveItems(maxWidth);
2996
3231
  const inline = resolveItems(inlineWidth);
2997
- const inlineHeight = Math.max(inline.height, (brand?.y ?? startY) - startY + brandHeight);
2998
- const stackedHeight = full.height + (items.length ? chromeGap : 0) + brandHeight + Math.max(0, brandNorm?.offset?.dy ?? 0);
2999
- const stacked = !!brand && items.length > 0 && (inlineWidth < 40 || stackedHeight < inlineHeight);
3232
+ const rowHeight = rightLogo.height;
3233
+ const inlineHeight = Math.max(inline.height, (brand?.y ?? startY) - startY + rowHeight);
3234
+ const stackedHeight = full.height + (items.length ? chromeGap : 0) + rowHeight + Math.max(0, brandNorm?.offset?.dy ?? 0);
3235
+ const allLeft = items.every(
3236
+ ({ key }) => !theme.chrome[key].textAlign || theme.chrome[key].textAlign === "left"
3237
+ );
3238
+ const hasAttribution = !!brand || !!rightLogo.logo;
3239
+ const stacked = items.length > 0 && (!allLeft || rightLogo.ownRow || hasAttribution && (inlineWidth < 40 || stackedHeight < inlineHeight));
3000
3240
  const bottomElements = stacked ? full.elements : inline.elements;
3001
3241
  if (stacked && brand) brand.y += full.height + chromeGap;
3002
- const contentHeight = stacked ? stackedHeight : inlineHeight;
3003
- const bottomHeight = items.length || brand ? startY + contentHeight + pad : bottomLegendHeight;
3242
+ let contentHeight = stacked ? hasAttribution ? stackedHeight : full.height : inlineHeight;
3243
+ const bottomLeftLogo = planBottomLeftLogo(
3244
+ logo,
3245
+ startY + contentHeight,
3246
+ chromeGap,
3247
+ !!(items.length || brand)
3248
+ );
3249
+ contentHeight += bottomLeftLogo.height;
3250
+ const positionedLogo = topLogo.logo ?? planBottomRightLogo(
3251
+ logo,
3252
+ brand?.maxWidth ?? 0,
3253
+ brandHeight,
3254
+ width - pad * 2,
3255
+ gap,
3256
+ startY + (stacked ? full.height + chromeGap : 0)
3257
+ ).logo ?? bottomLeftLogo.logo;
3258
+ const hasBottom = items.length || brand || logo?.position.startsWith("bottom");
3259
+ const bottomHeight = hasBottom ? startY + contentHeight + pad : bottomLegendHeight;
3004
3260
  return {
3005
3261
  topHeight,
3006
3262
  bottomHeight,
@@ -3009,28 +3265,29 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
3009
3265
  ...bottomElements,
3010
3266
  ...brandElement ? { brand: brandElement } : {},
3011
3267
  ...watermarkElement ? { watermark: watermarkElement } : {},
3012
- ...items.length || brand ? { attributionLayout: stacked ? "stacked" : "inline" } : {}
3268
+ ...hasBottom ? { attributionLayout: stacked ? "stacked" : "inline" } : {},
3269
+ ...positionedLogo ? { logo: positionedLogo } : {}
3013
3270
  };
3014
3271
  }
3015
3272
 
3016
3273
  // src/layout/text-wrap.ts
3017
- function wrapText(text, fontSize, fontWeight, maxWidth, measureText) {
3274
+ function wrapText(text, fontSize, fontWeight, maxWidth, measureText, fontFamily) {
3018
3275
  if (maxWidth <= 0) return [text];
3019
3276
  const segments = text.split("\n");
3020
3277
  if (segments.length > 1) {
3021
3278
  return segments.flatMap(
3022
- (segment) => segment.length === 0 ? [""] : wrapText(segment, fontSize, fontWeight, maxWidth, measureText)
3279
+ (segment) => segment.length === 0 ? [""] : wrapText(segment, fontSize, fontWeight, maxWidth, measureText, fontFamily)
3023
3280
  );
3024
3281
  }
3025
3282
  if (measureText) {
3026
- const textWidth = measureText(text, fontSize, fontWeight).width;
3283
+ const textWidth = measureText(text, fontSize, fontWeight, fontFamily).width;
3027
3284
  if (textWidth <= maxWidth) return [text];
3028
3285
  const words2 = text.split(" ");
3029
3286
  const lines2 = [];
3030
3287
  let current2 = "";
3031
3288
  for (const word of words2) {
3032
3289
  const candidate = current2 ? `${current2} ${word}` : word;
3033
- const candidateWidth = measureText(candidate, fontSize, fontWeight).width;
3290
+ const candidateWidth = measureText(candidate, fontSize, fontWeight, fontFamily).width;
3034
3291
  if (candidateWidth > maxWidth && current2) {
3035
3292
  lines2.push(current2);
3036
3293
  current2 = word;
@@ -3194,7 +3451,583 @@ function computeLabelBounds(label) {
3194
3451
 
3195
3452
  // src/locale/format.ts
3196
3453
  import { format as d3Format } from "d3-format";
3197
- import { timeFormat, utcFormat } from "d3-time-format";
3454
+
3455
+ // src/locale/definitions.ts
3456
+ var GRANULARITY_FORMATS = /* @__PURE__ */ Object.freeze({
3457
+ year: "%Y",
3458
+ quarter: "",
3459
+ // Quarter is handled by formatDate().
3460
+ month: "%b %Y",
3461
+ week: "%b %d",
3462
+ day: "%b %d, %Y",
3463
+ hour: "%b %d %H:%M",
3464
+ minute: "%H:%M"
3465
+ });
3466
+ var GRANULARITY_FORMATS_COMPACT = /* @__PURE__ */ Object.freeze({
3467
+ year: "%Y",
3468
+ quarter: "",
3469
+ // special-cased below, like GRANULARITY_FORMATS
3470
+ month: "%b",
3471
+ week: "%b %d",
3472
+ day: "%b %d",
3473
+ hour: "%H:%M",
3474
+ minute: "%H:%M"
3475
+ });
3476
+ function definition(number, time, day, week, quarter) {
3477
+ Object.freeze(number.grouping);
3478
+ Object.freeze(number.currency);
3479
+ Object.freeze(number);
3480
+ for (const names of [time.periods, time.days, time.shortDays, time.months, time.shortMonths])
3481
+ Object.freeze(names);
3482
+ Object.freeze(time);
3483
+ return Object.freeze({
3484
+ number,
3485
+ time,
3486
+ formats: Object.freeze({
3487
+ year: "%Y",
3488
+ quarter: "",
3489
+ month: "%b %Y",
3490
+ week,
3491
+ day,
3492
+ hour: `${week} %H:%M`,
3493
+ minute: "%H:%M"
3494
+ }),
3495
+ compactFormats: Object.freeze({
3496
+ year: "%Y",
3497
+ quarter: "",
3498
+ month: "%b",
3499
+ week,
3500
+ day: week,
3501
+ hour: "%H:%M",
3502
+ minute: "%H:%M"
3503
+ }),
3504
+ quarter: `${quarter} %Y`,
3505
+ compactQuarter: `${quarter} '%y`
3506
+ });
3507
+ }
3508
+ var LOCALE_DEFINITIONS = /* @__PURE__ */ Object.freeze({
3509
+ "en-US": /* @__PURE__ */ (() => Object.freeze({
3510
+ .../* @__PURE__ */ definition(
3511
+ {
3512
+ decimal: ".",
3513
+ thousands: ",",
3514
+ grouping: [3],
3515
+ currency: ["$", ""],
3516
+ minus: "\u2212",
3517
+ percent: "%"
3518
+ },
3519
+ {
3520
+ dateTime: "%x, %X",
3521
+ date: "%-m/%-d/%Y",
3522
+ time: "%-I:%M:%S %p",
3523
+ periods: ["AM", "PM"],
3524
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
3525
+ shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
3526
+ months: [
3527
+ "January",
3528
+ "February",
3529
+ "March",
3530
+ "April",
3531
+ "May",
3532
+ "June",
3533
+ "July",
3534
+ "August",
3535
+ "September",
3536
+ "October",
3537
+ "November",
3538
+ "December"
3539
+ ],
3540
+ shortMonths: [
3541
+ "Jan",
3542
+ "Feb",
3543
+ "Mar",
3544
+ "Apr",
3545
+ "May",
3546
+ "Jun",
3547
+ "Jul",
3548
+ "Aug",
3549
+ "Sep",
3550
+ "Oct",
3551
+ "Nov",
3552
+ "Dec"
3553
+ ]
3554
+ },
3555
+ GRANULARITY_FORMATS.day,
3556
+ GRANULARITY_FORMATS.week,
3557
+ "Q{q}"
3558
+ ),
3559
+ formats: GRANULARITY_FORMATS,
3560
+ compactFormats: GRANULARITY_FORMATS_COMPACT
3561
+ }))(),
3562
+ "en-GB": /* @__PURE__ */ definition(
3563
+ {
3564
+ decimal: ".",
3565
+ thousands: ",",
3566
+ grouping: [3],
3567
+ currency: ["$", ""],
3568
+ minus: "\u2212",
3569
+ percent: "%"
3570
+ },
3571
+ {
3572
+ dateTime: "%x, %X",
3573
+ date: "%d/%m/%Y",
3574
+ time: "%H:%M:%S",
3575
+ periods: ["am", "pm"],
3576
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
3577
+ shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
3578
+ months: [
3579
+ "January",
3580
+ "February",
3581
+ "March",
3582
+ "April",
3583
+ "May",
3584
+ "June",
3585
+ "July",
3586
+ "August",
3587
+ "September",
3588
+ "October",
3589
+ "November",
3590
+ "December"
3591
+ ],
3592
+ shortMonths: [
3593
+ "Jan",
3594
+ "Feb",
3595
+ "Mar",
3596
+ "Apr",
3597
+ "May",
3598
+ "Jun",
3599
+ "Jul",
3600
+ "Aug",
3601
+ "Sept",
3602
+ "Oct",
3603
+ "Nov",
3604
+ "Dec"
3605
+ ]
3606
+ },
3607
+ "%-d %b %Y",
3608
+ "%-d %b",
3609
+ "Q{q}"
3610
+ ),
3611
+ "de-DE": /* @__PURE__ */ definition(
3612
+ {
3613
+ decimal: ",",
3614
+ thousands: ".",
3615
+ grouping: [3],
3616
+ currency: ["$", ""],
3617
+ minus: "\u2212",
3618
+ percent: "\xA0%"
3619
+ },
3620
+ {
3621
+ dateTime: "%x, %X",
3622
+ date: "%d.%m.%y",
3623
+ time: "%H:%M:%S",
3624
+ periods: ["AM", "PM"],
3625
+ days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
3626
+ shortDays: ["So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa."],
3627
+ months: [
3628
+ "Januar",
3629
+ "Februar",
3630
+ "M\xE4rz",
3631
+ "April",
3632
+ "Mai",
3633
+ "Juni",
3634
+ "Juli",
3635
+ "August",
3636
+ "September",
3637
+ "Oktober",
3638
+ "November",
3639
+ "Dezember"
3640
+ ],
3641
+ shortMonths: [
3642
+ "Jan.",
3643
+ "Feb.",
3644
+ "M\xE4rz",
3645
+ "Apr.",
3646
+ "Mai",
3647
+ "Juni",
3648
+ "Juli",
3649
+ "Aug.",
3650
+ "Sept.",
3651
+ "Okt.",
3652
+ "Nov.",
3653
+ "Dez."
3654
+ ]
3655
+ },
3656
+ "%-d. %b %Y",
3657
+ "%-d. %b",
3658
+ "Q{q}"
3659
+ ),
3660
+ "fr-FR": /* @__PURE__ */ definition(
3661
+ {
3662
+ decimal: ",",
3663
+ thousands: "\u202F",
3664
+ grouping: [3],
3665
+ currency: ["$", ""],
3666
+ minus: "\u2212",
3667
+ percent: "\u202F%"
3668
+ },
3669
+ {
3670
+ dateTime: "%x, %X",
3671
+ date: "%d/%m/%Y",
3672
+ time: "%H:%M:%S",
3673
+ periods: ["AM", "PM"],
3674
+ days: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
3675
+ shortDays: ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."],
3676
+ months: [
3677
+ "janvier",
3678
+ "f\xE9vrier",
3679
+ "mars",
3680
+ "avril",
3681
+ "mai",
3682
+ "juin",
3683
+ "juillet",
3684
+ "ao\xFBt",
3685
+ "septembre",
3686
+ "octobre",
3687
+ "novembre",
3688
+ "d\xE9cembre"
3689
+ ],
3690
+ shortMonths: [
3691
+ "janv.",
3692
+ "f\xE9vr.",
3693
+ "mars",
3694
+ "avr.",
3695
+ "mai",
3696
+ "juin",
3697
+ "juil.",
3698
+ "ao\xFBt",
3699
+ "sept.",
3700
+ "oct.",
3701
+ "nov.",
3702
+ "d\xE9c."
3703
+ ]
3704
+ },
3705
+ "%-d %b %Y",
3706
+ "%-d %b",
3707
+ "T{q}"
3708
+ ),
3709
+ "es-ES": /* @__PURE__ */ definition(
3710
+ {
3711
+ decimal: ",",
3712
+ thousands: ".",
3713
+ grouping: [3],
3714
+ currency: ["$", ""],
3715
+ minus: "\u2212",
3716
+ percent: "\xA0%"
3717
+ },
3718
+ {
3719
+ dateTime: "%x, %X",
3720
+ date: "%-d/%-m/%y",
3721
+ time: "%H:%M:%S",
3722
+ periods: ["a.\xA0m.", "p.\xA0m."],
3723
+ days: ["domingo", "lunes", "martes", "mi\xE9rcoles", "jueves", "viernes", "s\xE1bado"],
3724
+ shortDays: ["dom", "lun", "mar", "mi\xE9", "jue", "vie", "s\xE1b"],
3725
+ months: [
3726
+ "enero",
3727
+ "febrero",
3728
+ "marzo",
3729
+ "abril",
3730
+ "mayo",
3731
+ "junio",
3732
+ "julio",
3733
+ "agosto",
3734
+ "septiembre",
3735
+ "octubre",
3736
+ "noviembre",
3737
+ "diciembre"
3738
+ ],
3739
+ shortMonths: [
3740
+ "ene",
3741
+ "feb",
3742
+ "mar",
3743
+ "abr",
3744
+ "may",
3745
+ "jun",
3746
+ "jul",
3747
+ "ago",
3748
+ "sept",
3749
+ "oct",
3750
+ "nov",
3751
+ "dic"
3752
+ ]
3753
+ },
3754
+ "%-d %b %Y",
3755
+ "%-d %b",
3756
+ "T{q}"
3757
+ ),
3758
+ "pt-BR": /* @__PURE__ */ definition(
3759
+ {
3760
+ decimal: ",",
3761
+ thousands: ".",
3762
+ grouping: [3],
3763
+ currency: ["$", ""],
3764
+ minus: "\u2212",
3765
+ percent: "%"
3766
+ },
3767
+ {
3768
+ dateTime: "%x, %X",
3769
+ date: "%d/%m/%Y",
3770
+ time: "%H:%M:%S",
3771
+ periods: ["AM", "PM"],
3772
+ days: [
3773
+ "domingo",
3774
+ "segunda-feira",
3775
+ "ter\xE7a-feira",
3776
+ "quarta-feira",
3777
+ "quinta-feira",
3778
+ "sexta-feira",
3779
+ "s\xE1bado"
3780
+ ],
3781
+ shortDays: ["dom.", "seg.", "ter.", "qua.", "qui.", "sex.", "s\xE1b."],
3782
+ months: [
3783
+ "janeiro",
3784
+ "fevereiro",
3785
+ "mar\xE7o",
3786
+ "abril",
3787
+ "maio",
3788
+ "junho",
3789
+ "julho",
3790
+ "agosto",
3791
+ "setembro",
3792
+ "outubro",
3793
+ "novembro",
3794
+ "dezembro"
3795
+ ],
3796
+ shortMonths: [
3797
+ "jan.",
3798
+ "fev.",
3799
+ "mar.",
3800
+ "abr.",
3801
+ "mai.",
3802
+ "jun.",
3803
+ "jul.",
3804
+ "ago.",
3805
+ "set.",
3806
+ "out.",
3807
+ "nov.",
3808
+ "dez."
3809
+ ]
3810
+ },
3811
+ "%-d %b %Y",
3812
+ "%-d %b",
3813
+ "T{q}"
3814
+ ),
3815
+ "pt-PT": /* @__PURE__ */ definition(
3816
+ {
3817
+ decimal: ",",
3818
+ thousands: "\xA0",
3819
+ grouping: [3],
3820
+ currency: ["$", ""],
3821
+ minus: "\u2212",
3822
+ percent: "%"
3823
+ },
3824
+ {
3825
+ dateTime: "%x, %X",
3826
+ date: "%d/%m/%y",
3827
+ time: "%H:%M:%S",
3828
+ periods: ["a.m.", "p.m."],
3829
+ days: [
3830
+ "domingo",
3831
+ "segunda-feira",
3832
+ "ter\xE7a-feira",
3833
+ "quarta-feira",
3834
+ "quinta-feira",
3835
+ "sexta-feira",
3836
+ "s\xE1bado"
3837
+ ],
3838
+ shortDays: ["domingo", "segunda", "ter\xE7a", "quarta", "quinta", "sexta", "s\xE1bado"],
3839
+ months: [
3840
+ "janeiro",
3841
+ "fevereiro",
3842
+ "mar\xE7o",
3843
+ "abril",
3844
+ "maio",
3845
+ "junho",
3846
+ "julho",
3847
+ "agosto",
3848
+ "setembro",
3849
+ "outubro",
3850
+ "novembro",
3851
+ "dezembro"
3852
+ ],
3853
+ shortMonths: [
3854
+ "jan.",
3855
+ "fev.",
3856
+ "mar.",
3857
+ "abr.",
3858
+ "mai.",
3859
+ "jun.",
3860
+ "jul.",
3861
+ "ago.",
3862
+ "set.",
3863
+ "out.",
3864
+ "nov.",
3865
+ "dez."
3866
+ ]
3867
+ },
3868
+ "%-d %b %Y",
3869
+ "%-d %b",
3870
+ "T{q}"
3871
+ ),
3872
+ "it-IT": /* @__PURE__ */ definition(
3873
+ {
3874
+ decimal: ",",
3875
+ thousands: ".",
3876
+ grouping: [3],
3877
+ currency: ["$", ""],
3878
+ minus: "\u2212",
3879
+ percent: "%"
3880
+ },
3881
+ {
3882
+ dateTime: "%x, %X",
3883
+ date: "%d/%m/%y",
3884
+ time: "%H:%M:%S",
3885
+ periods: ["AM", "PM"],
3886
+ days: ["domenica", "luned\xEC", "marted\xEC", "mercoled\xEC", "gioved\xEC", "venerd\xEC", "sabato"],
3887
+ shortDays: ["dom", "lun", "mar", "mer", "gio", "ven", "sab"],
3888
+ months: [
3889
+ "gennaio",
3890
+ "febbraio",
3891
+ "marzo",
3892
+ "aprile",
3893
+ "maggio",
3894
+ "giugno",
3895
+ "luglio",
3896
+ "agosto",
3897
+ "settembre",
3898
+ "ottobre",
3899
+ "novembre",
3900
+ "dicembre"
3901
+ ],
3902
+ shortMonths: [
3903
+ "gen",
3904
+ "feb",
3905
+ "mar",
3906
+ "apr",
3907
+ "mag",
3908
+ "giu",
3909
+ "lug",
3910
+ "ago",
3911
+ "set",
3912
+ "ott",
3913
+ "nov",
3914
+ "dic"
3915
+ ]
3916
+ },
3917
+ "%-d %b %Y",
3918
+ "%-d %b",
3919
+ "T{q}"
3920
+ ),
3921
+ "nl-NL": /* @__PURE__ */ definition(
3922
+ {
3923
+ decimal: ",",
3924
+ thousands: ".",
3925
+ grouping: [3],
3926
+ currency: ["$", ""],
3927
+ minus: "\u2212",
3928
+ percent: "%"
3929
+ },
3930
+ {
3931
+ dateTime: "%x, %X",
3932
+ date: "%-d-%-m-%Y",
3933
+ time: "%H:%M:%S",
3934
+ periods: ["a.m.", "p.m."],
3935
+ days: ["zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag"],
3936
+ shortDays: ["zo", "ma", "di", "wo", "do", "vr", "za"],
3937
+ months: [
3938
+ "januari",
3939
+ "februari",
3940
+ "maart",
3941
+ "april",
3942
+ "mei",
3943
+ "juni",
3944
+ "juli",
3945
+ "augustus",
3946
+ "september",
3947
+ "oktober",
3948
+ "november",
3949
+ "december"
3950
+ ],
3951
+ shortMonths: [
3952
+ "jan",
3953
+ "feb",
3954
+ "mrt",
3955
+ "apr",
3956
+ "mei",
3957
+ "jun",
3958
+ "jul",
3959
+ "aug",
3960
+ "sep",
3961
+ "okt",
3962
+ "nov",
3963
+ "dec"
3964
+ ]
3965
+ },
3966
+ "%-d %b %Y",
3967
+ "%-d %b",
3968
+ "K{q}"
3969
+ )
3970
+ });
3971
+
3972
+ // src/locale/format-locale.ts
3973
+ import { format, formatLocale, formatPrefix } from "d3-format";
3974
+ import { timeFormat, timeFormatLocale, timeParse, utcFormat, utcParse } from "d3-time-format";
3975
+ var DEFAULT_NUMBER_LOCALE = { format, formatPrefix };
3976
+ var DEFAULT_TIME_LOCALE = { format: timeFormat, parse: timeParse, utcFormat, utcParse };
3977
+ var LOCALE_TAGS = /* @__PURE__ */ new Map();
3978
+ var NUMBER_LOCALES = /* @__PURE__ */ new Map();
3979
+ var TIME_LOCALES = /* @__PURE__ */ new Map();
3980
+ var NUMBER_FORMATTERS = /* @__PURE__ */ new Map();
3981
+ function localeTag(locale) {
3982
+ if (locale === void 0 || locale === "en-US" || typeof locale !== "string") return "en-US";
3983
+ const cached = LOCALE_TAGS.get(locale);
3984
+ if (cached) return cached;
3985
+ const tag = matchLocale(locale) ?? "en-US";
3986
+ LOCALE_TAGS.set(locale, tag);
3987
+ return tag;
3988
+ }
3989
+ function getNumberLocale(locale) {
3990
+ if (locale === void 0 || locale === "en-US") return DEFAULT_NUMBER_LOCALE;
3991
+ const tag = localeTag(locale);
3992
+ if (tag === "en-US") return DEFAULT_NUMBER_LOCALE;
3993
+ let result = NUMBER_LOCALES.get(tag);
3994
+ if (!result) {
3995
+ result = formatLocale(LOCALE_DEFINITIONS[tag].number);
3996
+ NUMBER_LOCALES.set(tag, result);
3997
+ }
3998
+ return result;
3999
+ }
4000
+ function getTimeLocale(locale) {
4001
+ if (locale === void 0 || locale === "en-US") return DEFAULT_TIME_LOCALE;
4002
+ return getTimeLocaleForTag(localeTag(locale));
4003
+ }
4004
+ function getTimeLocaleForTag(tag) {
4005
+ if (tag === "en-US") return DEFAULT_TIME_LOCALE;
4006
+ let result = TIME_LOCALES.get(tag);
4007
+ if (!result) {
4008
+ result = timeFormatLocale(LOCALE_DEFINITIONS[tag].time);
4009
+ TIME_LOCALES.set(tag, result);
4010
+ }
4011
+ return result;
4012
+ }
4013
+ function numberFormatter(fallback, pattern, locale) {
4014
+ if (locale === void 0 || locale === "en-US") return fallback;
4015
+ const tag = localeTag(locale);
4016
+ if (tag === "en-US") return fallback;
4017
+ let cache = NUMBER_FORMATTERS.get(tag);
4018
+ if (!cache) {
4019
+ cache = /* @__PURE__ */ new Map();
4020
+ NUMBER_FORMATTERS.set(tag, cache);
4021
+ }
4022
+ let formatter = cache.get(pattern);
4023
+ if (!formatter) {
4024
+ formatter = getNumberLocale(tag).format(pattern);
4025
+ cache.set(pattern, formatter);
4026
+ }
4027
+ return formatter;
4028
+ }
4029
+
4030
+ // src/locale/format.ts
3198
4031
  var FORMAT_INTEGER = /* @__PURE__ */ d3Format(",");
3199
4032
  var FORMAT_TINY = /* @__PURE__ */ d3Format(".2~r");
3200
4033
  var FORMAT_DECIMAL = /* @__PURE__ */ d3Format(",.2f");
@@ -3214,15 +4047,18 @@ var FORMAT_STEP_PRECISION = [
3214
4047
  /* @__PURE__ */ d3Format(",.2~f"),
3215
4048
  /* @__PURE__ */ d3Format(",.3~f")
3216
4049
  ];
3217
- function formatNumber(value, _locale) {
4050
+ function formatNumber(value, locale) {
3218
4051
  if (!Number.isFinite(value)) return String(value);
3219
4052
  if (Number.isInteger(value)) {
3220
- return FORMAT_INTEGER(value);
4053
+ return numberFormatter(FORMAT_INTEGER, ",", locale)(value);
3221
4054
  }
3222
4055
  if (Math.abs(value) < 5e-3) {
3223
- return FORMAT_TINY(value);
4056
+ return numberFormatter(FORMAT_TINY, ".2~r", locale)(value);
3224
4057
  }
3225
- return FORMAT_DECIMAL(value);
4058
+ return numberFormatter(FORMAT_DECIMAL, ",.2f", locale)(value);
4059
+ }
4060
+ function formatRawNumber(value, locale) {
4061
+ return String(value).replace(".", LOCALE_DEFINITIONS[localeTag(locale)].number.decimal);
3226
4062
  }
3227
4063
  var UNIT_TABLE = [
3228
4064
  { threshold: 1e12, suffix: "T", divisor: 1e12 },
@@ -3244,21 +4080,21 @@ function fractionDigits(x) {
3244
4080
  }
3245
4081
  return 4;
3246
4082
  }
3247
- function abbreviateNumber(value) {
4083
+ function abbreviateNumber(value, locale) {
3248
4084
  if (!Number.isFinite(value)) return String(value);
3249
4085
  const absValue = Math.abs(value);
3250
4086
  const sign = value < 0 ? "-" : "";
3251
4087
  for (let i = 0; i < UNIT_TABLE.length; i++) {
3252
4088
  const { threshold, suffix, divisor } = UNIT_TABLE[i];
3253
4089
  if (absValue >= threshold) {
3254
- const mantissa = FORMAT_ABBREV_MANTISSA(absValue / divisor);
4090
+ const mantissa = numberFormatter(FORMAT_ABBREV_MANTISSA, ".1~f", locale)(absValue / divisor);
3255
4091
  if (mantissa === "1000" && i > 0) {
3256
4092
  return `${sign}1${UNIT_TABLE[i - 1].suffix}`;
3257
4093
  }
3258
4094
  return `${sign}${mantissa}${suffix}`;
3259
4095
  }
3260
4096
  }
3261
- return formatNumber(value);
4097
+ return formatNumber(value, locale);
3262
4098
  }
3263
4099
  function formatOrdinal(value) {
3264
4100
  if (!Number.isFinite(value)) return String(value);
@@ -3275,17 +4111,17 @@ function formatOrdinal(value) {
3275
4111
  return `${n}${suffix}`;
3276
4112
  }
3277
4113
  var D3_FORMAT_SUFFIX_RE = /^(.*~?[efgsrdxXobcnp%])(.+)$/;
3278
- function buildD3Formatter(formatStr) {
4114
+ function buildD3Formatter(formatStr, locale) {
3279
4115
  if (!formatStr) return null;
3280
4116
  if (formatStr === "ordinal") return formatOrdinal;
3281
4117
  if (formatStr === "compact") {
3282
4118
  return (v) => {
3283
4119
  if (!Number.isFinite(v)) return String(v);
3284
- return Math.abs(v) >= 1e3 ? abbreviateNumber(v) : formatNumber(v);
4120
+ return Math.abs(v) >= 1e3 ? abbreviateNumber(v, locale) : formatNumber(v, locale);
3285
4121
  };
3286
4122
  }
3287
4123
  try {
3288
- const fmt = /* @__PURE__ */ d3Format(formatStr);
4124
+ const fmt = /* @__PURE__ */ getNumberLocale(locale).format(formatStr);
3289
4125
  if (formatStr.includes("s")) {
3290
4126
  return (v) => fmt(v).replace(/G$/, "B");
3291
4127
  }
@@ -3294,7 +4130,7 @@ function buildD3Formatter(formatStr) {
3294
4130
  const m = formatStr.match(D3_FORMAT_SUFFIX_RE);
3295
4131
  if (m) {
3296
4132
  try {
3297
- const fmt = /* @__PURE__ */ d3Format(m[1]);
4133
+ const fmt = /* @__PURE__ */ getNumberLocale(locale).format(m[1]);
3298
4134
  const suffix = m[2];
3299
4135
  return (v) => fmt(v) + suffix;
3300
4136
  } catch {
@@ -3305,29 +4141,32 @@ function buildD3Formatter(formatStr) {
3305
4141
  }
3306
4142
  function formatPercent2(value, options) {
3307
4143
  const fraction = options?.fraction ?? true;
4144
+ const locale = options?.locale;
4145
+ const suffix = LOCALE_DEFINITIONS[localeTag(locale)].number.percent;
3308
4146
  const percent = fraction ? value * 100 : value;
3309
4147
  if (Number.isFinite(percent) && percent !== 0 && Math.abs(percent) < 0.1) {
3310
- return percent < 0 ? `>${FORMAT_PERCENT_RAW(-0.1)}%` : `<${FORMAT_PERCENT_RAW(0.1)}%`;
4148
+ return percent < 0 ? `>${numberFormatter(FORMAT_PERCENT_RAW, ",.1~f", locale)(-0.1)}${suffix}` : `<${numberFormatter(FORMAT_PERCENT_RAW, ",.1~f", locale)(0.1)}${suffix}`;
3311
4149
  }
3312
4150
  if (fraction) {
3313
- return FORMAT_PERCENT_FRACTION(value);
4151
+ return numberFormatter(FORMAT_PERCENT_FRACTION, ".1~%", locale)(value);
3314
4152
  }
3315
- return `${FORMAT_PERCENT_RAW(value)}%`;
4153
+ return `${numberFormatter(FORMAT_PERCENT_RAW, ",.1~f", locale)(value)}${suffix}`;
3316
4154
  }
3317
4155
  function formatCurrency(value, options) {
3318
4156
  const compact = options?.compact ?? false;
4157
+ const locale = options?.locale;
3319
4158
  const abs = Math.abs(value);
3320
4159
  const sign = value < 0 ? "-" : "";
3321
4160
  if (compact) {
3322
4161
  if (abs >= 1e3) {
3323
- return `${sign}$${abbreviateNumber(abs)}`;
4162
+ return `${sign}$${abbreviateNumber(abs, locale)}`;
3324
4163
  }
3325
- return `${sign}$${formatNumber(abs)}`;
4164
+ return `${sign}$${formatNumber(abs, locale)}`;
3326
4165
  }
3327
4166
  if (Number.isInteger(value)) {
3328
- return sign + FORMAT_CURRENCY_INTEGER(abs);
4167
+ return sign + numberFormatter(FORMAT_CURRENCY_INTEGER, "$,", locale)(abs);
3329
4168
  }
3330
- return sign + FORMAT_CURRENCY_DECIMAL(abs);
4169
+ return sign + numberFormatter(FORMAT_CURRENCY_DECIMAL, "$,.2f", locale)(abs);
3331
4170
  }
3332
4171
  function computeFieldFormatContext(values, surface) {
3333
4172
  let min = Infinity;
@@ -3357,44 +4196,46 @@ function isYearContext(ctx) {
3357
4196
  }
3358
4197
  function resolveNumberFormatter(formatStr, ctx) {
3359
4198
  if (!formatStr) return null;
4199
+ const locale = ctx?.locale;
3360
4200
  if (formatStr === "ordinal") return formatOrdinal;
3361
4201
  if (formatStr === "compact") {
3362
4202
  return (v) => {
3363
4203
  if (!Number.isFinite(v)) return String(v);
3364
- return Math.abs(v) >= 1e3 ? abbreviateNumber(v) : formatNumber(v);
4204
+ return Math.abs(v) >= 1e3 ? abbreviateNumber(v, locale) : formatNumber(v, locale);
3365
4205
  };
3366
4206
  }
3367
4207
  if (formatStr === "percent") {
3368
4208
  const fraction = ctx?.extent ? Math.max(Math.abs(ctx.extent[0]), Math.abs(ctx.extent[1])) <= 1 : true;
3369
- return (v) => formatPercent2(v, { fraction });
4209
+ return (v) => formatPercent2(v, { fraction, locale });
3370
4210
  }
3371
4211
  if (formatStr === "currency") {
3372
4212
  const isTable = ctx?.surface === "table";
3373
4213
  if (!isTable && ctx?.step != null && (ctx.stepReference ?? 0) >= 1e3) {
3374
- const stepFmt = buildCompactStepFormatter(ctx.step);
4214
+ const stepFmt = buildCompactStepFormatter(ctx.step, locale);
3375
4215
  return (v) => {
3376
4216
  const sign = v < 0 ? "-" : "";
3377
4217
  return `${sign}$${stepFmt(Math.abs(v))}`;
3378
4218
  };
3379
4219
  }
3380
- return (v) => formatCurrency(v, { compact: !isTable });
4220
+ return (v) => formatCurrency(v, { compact: !isTable, locale });
3381
4221
  }
3382
- return buildD3Formatter(formatStr);
4222
+ return buildD3Formatter(formatStr, locale);
3383
4223
  }
3384
4224
  function defaultNumberFormatter(ctx) {
4225
+ const locale = ctx?.locale;
3385
4226
  if (isYearContext(ctx)) {
3386
4227
  return (v) => String(Math.round(v));
3387
4228
  }
3388
4229
  if (ctx?.surface === "table") {
3389
- return formatNumber;
4230
+ return (v) => formatNumber(v, locale);
3390
4231
  }
3391
4232
  if (ctx?.step != null && (ctx.stepReference ?? maxAbs(ctx.extent)) >= 1e3) {
3392
- return buildCompactStepFormatter(ctx.step);
4233
+ return buildCompactStepFormatter(ctx.step, locale);
3393
4234
  }
3394
4235
  if (ctx?.step != null && ctx.step > 0) {
3395
4236
  const p = fractionDigits(ctx.step);
3396
4237
  if (p <= 3) {
3397
- const fmt = FORMAT_STEP_PRECISION[p];
4238
+ const fmt = numberFormatter(FORMAT_STEP_PRECISION[p], `,.${p}~f`, locale);
3398
4239
  return (v) => Number.isFinite(v) ? fmt(v) : String(v);
3399
4240
  }
3400
4241
  }
@@ -3403,87 +4244,77 @@ function defaultNumberFormatter(ctx) {
3403
4244
  if (ctx?.extent === void 0 && ctx?.allIntegers === void 0) {
3404
4245
  if (Number.isInteger(v) && v >= 1500 && v <= 2500) return String(v);
3405
4246
  }
3406
- return Math.abs(v) >= 1e3 ? abbreviateNumber(v) : formatNumber(v);
4247
+ return Math.abs(v) >= 1e3 ? abbreviateNumber(v, locale) : formatNumber(v, locale);
3407
4248
  };
3408
4249
  }
3409
4250
  function maxAbs(extent) {
3410
4251
  if (!extent) return 0;
3411
4252
  return Math.max(Math.abs(extent[0]), Math.abs(extent[1]));
3412
4253
  }
3413
- function buildCompactStepFormatter(step) {
4254
+ function buildCompactStepFormatter(step, locale) {
3414
4255
  return (v) => {
3415
4256
  if (v === 0) return "0";
3416
4257
  if (!Number.isFinite(v)) return String(v);
3417
4258
  const abs = Math.abs(v);
3418
- if (abs < 1e3) return formatNumber(v);
4259
+ if (abs < 1e3) return formatNumber(v, locale);
3419
4260
  const { suffix, divisor } = unitFor(abs);
3420
4261
  const p = fractionDigits(step / divisor);
3421
4262
  if (p > 2) {
3422
- return Number.isInteger(v) ? FORMAT_INTEGER(v) : FORMAT_DECIMAL(v);
4263
+ return Number.isInteger(v) ? numberFormatter(FORMAT_INTEGER, ",", locale)(v) : numberFormatter(FORMAT_DECIMAL, ",.2f", locale)(v);
3423
4264
  }
3424
4265
  const sign = v < 0 ? "-" : "";
3425
- return sign + FORMAT_STEP_FRACTION[p](abs / divisor) + suffix;
4266
+ return sign + numberFormatter(FORMAT_STEP_FRACTION[p], `.${p}~f`, locale)(abs / divisor) + suffix;
3426
4267
  };
3427
4268
  }
3428
- var GRANULARITY_FORMATS = {
3429
- year: "%Y",
3430
- quarter: "",
3431
- // Quarter is always special-cased in formatDate() below
3432
- month: "%b %Y",
3433
- week: "%b %d",
3434
- day: "%b %d, %Y",
3435
- hour: "%b %d %H:%M",
3436
- minute: "%H:%M"
3437
- };
3438
- var GRANULARITY_FORMATS_COMPACT = {
3439
- year: "%Y",
3440
- quarter: "",
3441
- // special-cased below, like GRANULARITY_FORMATS
3442
- month: "%b",
3443
- week: "%b %d",
3444
- day: "%b %d",
3445
- hour: "%H:%M",
3446
- minute: "%H:%M"
3447
- };
3448
- function formatDate(value, _locale, granularity, useUtc = true, compact = false) {
4269
+ function formatDate(value, locale, granularity, useUtc = true, compact = false) {
3449
4270
  const date = value instanceof Date ? value : new Date(value);
3450
4271
  if (Number.isNaN(date.getTime())) return String(value);
3451
4272
  const gran = granularity ?? inferGranularity(date, useUtc);
4273
+ const tag = localeTag(locale);
4274
+ const definition2 = LOCALE_DEFINITIONS[tag];
3452
4275
  if (gran === "quarter") {
3453
4276
  const q = useUtc ? Math.ceil((date.getUTCMonth() + 1) / 3) : Math.ceil((date.getMonth() + 1) / 3);
3454
4277
  const year = useUtc ? date.getUTCFullYear() : date.getFullYear();
4278
+ if (tag !== "en-US") {
4279
+ const template = compact ? definition2.compactQuarter : definition2.quarter;
4280
+ const pattern = template.replace("{q}", String(q));
4281
+ return (useUtc ? getUtcFormatter(pattern, tag) : getTimeFormatter(pattern, tag))(date);
4282
+ }
3455
4283
  if (compact) {
3456
4284
  return `Q${q} '${String(year).slice(-2)}`;
3457
4285
  }
3458
4286
  return `Q${q} ${year}`;
3459
4287
  }
3460
- const formatStr = (compact ? GRANULARITY_FORMATS_COMPACT : GRANULARITY_FORMATS)[gran];
4288
+ const formats = compact ? definition2.compactFormats : definition2.formats;
4289
+ const formatStr = formats[gran];
3461
4290
  if (useUtc) {
3462
- return getUtcFormatter(formatStr)(date);
4291
+ return getUtcFormatter(formatStr, tag)(date);
3463
4292
  }
3464
- return getTimeFormatter(formatStr)(date);
4293
+ return getTimeFormatter(formatStr, tag)(date);
3465
4294
  }
3466
4295
  var TIME_FORMAT_CACHE = /* @__PURE__ */ new Map();
3467
4296
  var UTC_FORMAT_CACHE = /* @__PURE__ */ new Map();
3468
- function getTimeFormatter(formatStr) {
3469
- let fmt = TIME_FORMAT_CACHE.get(formatStr);
4297
+ function getTimeFormatter(formatStr, tag) {
4298
+ const key = `${tag}:${formatStr}`;
4299
+ let fmt = TIME_FORMAT_CACHE.get(key);
3470
4300
  if (!fmt) {
3471
- fmt = timeFormat(formatStr);
3472
- TIME_FORMAT_CACHE.set(formatStr, fmt);
4301
+ fmt = getTimeLocaleForTag(tag).format(formatStr);
4302
+ TIME_FORMAT_CACHE.set(key, fmt);
3473
4303
  }
3474
4304
  return fmt;
3475
4305
  }
3476
- function getUtcFormatter(formatStr) {
3477
- let fmt = UTC_FORMAT_CACHE.get(formatStr);
4306
+ function getUtcFormatter(formatStr, tag) {
4307
+ const key = `${tag}:${formatStr}`;
4308
+ let fmt = UTC_FORMAT_CACHE.get(key);
3478
4309
  if (!fmt) {
3479
- fmt = utcFormat(formatStr);
3480
- UTC_FORMAT_CACHE.set(formatStr, fmt);
4310
+ fmt = getTimeLocaleForTag(tag).utcFormat(formatStr);
4311
+ UTC_FORMAT_CACHE.set(key, fmt);
3481
4312
  }
3482
4313
  return fmt;
3483
4314
  }
3484
- function buildTemporalFormatter(formatStr) {
4315
+ function buildTemporalFormatter(formatStr, locale) {
3485
4316
  if (!formatStr) return null;
3486
- const fmt = utcFormat(formatStr);
4317
+ const fmt = getTimeLocale(locale).utcFormat(formatStr);
3487
4318
  return (value) => {
3488
4319
  const date = value instanceof Date ? value : new Date(value);
3489
4320
  if (Number.isNaN(date.getTime())) return String(value);
@@ -3504,7 +4335,8 @@ function inferGranularity(date, useUtc = true) {
3504
4335
  }
3505
4336
 
3506
4337
  // src/accessibility/alt-text.ts
3507
- function generateAltText(spec, data) {
4338
+ function generateAltText(spec, data, locale) {
4339
+ const number = getNumberLocale(locale).format("d");
3508
4340
  const markType = resolveMarkType(spec.mark);
3509
4341
  const markDef = resolveMarkDef(spec.mark);
3510
4342
  let chartName = MARK_DISPLAY_NAMES[markType] ?? `${markType} chart`;
@@ -3523,7 +4355,7 @@ function generateAltText(spec, data) {
3523
4355
  }
3524
4356
  if (markDef.type === "waffle") {
3525
4357
  const units = markDef.units ?? 100;
3526
- parts.push(`dividing ${units} units`);
4358
+ parts.push(`dividing ${number(units)} units`);
3527
4359
  }
3528
4360
  if (markType === "parliament") {
3529
4361
  const valueField = spec.encoding.theta?.field ?? spec.encoding.y?.field;
@@ -3534,7 +4366,7 @@ function generateAltText(spec, data) {
3534
4366
  }, 0);
3535
4367
  if (totalSeats > 0) {
3536
4368
  const majority = Math.floor(totalSeats / 2) + 1;
3537
- parts.push(`with ${totalSeats} seats, ${majority} needed for a majority`);
4369
+ parts.push(`with ${number(totalSeats)} seats, ${number(majority)} needed for a majority`);
3538
4370
  }
3539
4371
  }
3540
4372
  }
@@ -3571,7 +4403,7 @@ function generateAltText(spec, data) {
3571
4403
  }
3572
4404
  } else if (spec.encoding.x.type === "nominal" || spec.encoding.x.type === "ordinal") {
3573
4405
  const uniqueValues = [...new Set(values.map(String))];
3574
- parts.push(`across ${uniqueValues.length} categories`);
4406
+ parts.push(`across ${number(uniqueValues.length)} categories`);
3575
4407
  }
3576
4408
  }
3577
4409
  }
@@ -3579,14 +4411,17 @@ function generateAltText(spec, data) {
3579
4411
  const colorField = spec.encoding.color.field;
3580
4412
  const uniqueSeries = [...new Set(data.map((d) => String(d[colorField])).filter(Boolean))];
3581
4413
  if (uniqueSeries.length > 0) {
3582
- parts.push(`with ${uniqueSeries.length} series (${uniqueSeries.join(", ")})`);
4414
+ parts.push(`with ${number(uniqueSeries.length)} series (${uniqueSeries.join(", ")})`);
3583
4415
  }
3584
4416
  }
3585
- parts.push(`(${data.length} data points)`);
4417
+ parts.push(`(${number(data.length)} data points)`);
3586
4418
  return parts.join(" ");
3587
4419
  }
3588
4420
  var MAX_SR_TABLE_ROWS = 1e3;
3589
- function generateDataTable(spec, data) {
4421
+ function generateDataTable(spec, data, locale) {
4422
+ const tag = localeTag(locale);
4423
+ const localized = tag !== "en-US";
4424
+ const symbols = LOCALE_DEFINITIONS[tag].number;
3590
4425
  const fields = [];
3591
4426
  const encoding = spec.encoding;
3592
4427
  if (encoding.x) fields.push(encoding.x.field);
@@ -3596,12 +4431,53 @@ function generateDataTable(spec, data) {
3596
4431
  const uniqueFields = [...new Set(fields)];
3597
4432
  if (uniqueFields.length === 0) return [];
3598
4433
  const headers = uniqueFields;
3599
- const rows = data.slice(0, MAX_SR_TABLE_ROWS).map((row) => uniqueFields.map((field) => row[field] ?? ""));
4434
+ const granularities = /* @__PURE__ */ new Map();
4435
+ if (localized) {
4436
+ const precision = [
4437
+ "year",
4438
+ "quarter",
4439
+ "month",
4440
+ "week",
4441
+ "day",
4442
+ "hour",
4443
+ "minute"
4444
+ ];
4445
+ for (const field of uniqueFields) {
4446
+ const temporal = [encoding.x, encoding.y, encoding.color, encoding.size].some(
4447
+ (channel) => channel && "field" in channel && channel.field === field && channel.type === "temporal"
4448
+ );
4449
+ for (const row of data) {
4450
+ const value = row[field];
4451
+ if (value == null || !temporal && !(value instanceof Date)) continue;
4452
+ const date = value instanceof Date ? value : new Date(String(value));
4453
+ if (Number.isNaN(date.getTime())) continue;
4454
+ const granularity = inferGranularity(date);
4455
+ const current = granularities.get(field);
4456
+ if (!current || precision.indexOf(granularity) > precision.indexOf(current))
4457
+ granularities.set(field, granularity);
4458
+ }
4459
+ }
4460
+ }
4461
+ const rows = data.slice(0, MAX_SR_TABLE_ROWS).map(
4462
+ (row) => uniqueFields.map((field) => {
4463
+ const value = row[field];
4464
+ if (!localized || value == null) return value ?? "";
4465
+ const granularity = granularities.get(field);
4466
+ if (granularity) {
4467
+ const date = value instanceof Date ? value : new Date(String(value));
4468
+ return Number.isNaN(date.getTime()) ? String(value) : formatDate(date, tag, granularity);
4469
+ }
4470
+ return typeof value === "number" ? String(value).replace(".", symbols.decimal).replace(/^-/, symbols.minus ?? "\u2212") : value;
4471
+ })
4472
+ );
3600
4473
  return [headers, ...rows];
3601
4474
  }
3602
4475
 
3603
4476
  // src/accessibility/aria.ts
3604
- function generateAriaLabels(marks) {
4477
+ function generateAriaLabels(marks, locale) {
4478
+ const localized = localeTag(locale) !== "en-US";
4479
+ const numberFormatter2 = localized ? defaultNumberFormatter({ locale }) : ariaNumberFormatter;
4480
+ const countFormatter = getNumberLocale(locale).format("d");
3605
4481
  const labels = /* @__PURE__ */ new Map();
3606
4482
  for (let i = 0; i < marks.length; i++) {
3607
4483
  const mark = marks[i];
@@ -3610,7 +4486,7 @@ function generateAriaLabels(marks) {
3610
4486
  case "line": {
3611
4487
  const series = mark.seriesKey ?? "Series";
3612
4488
  const pointCount = mark.points.length;
3613
- labels.set(key, `Line series: ${series} with ${pointCount} points`);
4489
+ labels.set(key, `Line series: ${series} with ${countFormatter(pointCount)} points`);
3614
4490
  break;
3615
4491
  }
3616
4492
  case "area": {
@@ -3620,19 +4496,25 @@ function generateAriaLabels(marks) {
3620
4496
  }
3621
4497
  case "rect": {
3622
4498
  const dataEntries = Object.entries(mark.data).filter(([k]) => !k.startsWith("_"));
3623
- const description = dataEntries.map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
4499
+ const description = dataEntries.map(
4500
+ ([k, v]) => `${k}: ${formatValue(v, numberFormatter2, localized ? locale : void 0)}`
4501
+ ).join(", ");
3624
4502
  labels.set(key, `Data point: ${description}`);
3625
4503
  break;
3626
4504
  }
3627
4505
  case "arc": {
3628
4506
  const dataEntries = Object.entries(mark.data).filter(([k]) => !k.startsWith("_"));
3629
- const description = dataEntries.map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
4507
+ const description = dataEntries.map(
4508
+ ([k, v]) => `${k}: ${formatValue(v, numberFormatter2, localized ? locale : void 0)}`
4509
+ ).join(", ");
3630
4510
  labels.set(key, `Slice: ${description}`);
3631
4511
  break;
3632
4512
  }
3633
4513
  case "point": {
3634
4514
  const dataEntries = Object.entries(mark.data).filter(([k]) => !k.startsWith("_"));
3635
- const description = dataEntries.map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
4515
+ const description = dataEntries.map(
4516
+ ([k, v]) => `${k}: ${formatValue(v, numberFormatter2, localized ? locale : void 0)}`
4517
+ ).join(", ");
3636
4518
  labels.set(key, `Data point: ${description}`);
3637
4519
  break;
3638
4520
  }
@@ -3641,11 +4523,12 @@ function generateAriaLabels(marks) {
3641
4523
  return labels;
3642
4524
  }
3643
4525
  var ariaNumberFormatter = /* @__PURE__ */ defaultNumberFormatter();
3644
- function formatValue(value) {
4526
+ function formatValue(value, numberFormatter2, locale) {
3645
4527
  if (value == null) return "N/A";
3646
- if (value instanceof Date) return value.toISOString().slice(0, 10);
4528
+ if (value instanceof Date)
4529
+ return locale ? formatDate(value, locale, "day") : value.toISOString().slice(0, 10);
3647
4530
  if (typeof value === "number") {
3648
- return ariaNumberFormatter(value);
4531
+ return numberFormatter2(value);
3649
4532
  }
3650
4533
  return String(value);
3651
4534
  }
@@ -4918,6 +5801,7 @@ export {
4918
5801
  NARROW_VIEWPORT_MAX,
4919
5802
  OFFSET_STRATEGIES,
4920
5803
  SEQUENTIAL_PALETTES,
5804
+ SUPPORTED_LOCALES,
4921
5805
  SUPPORTED_SCHEME_NAMES,
4922
5806
  TICK_LABEL_OFFSET,
4923
5807
  TICK_LINE_HEIGHT_FACTOR,
@@ -4941,6 +5825,7 @@ export {
4941
5825
  buildCompactStepFormatter,
4942
5826
  buildD3Formatter,
4943
5827
  buildTemporalFormatter,
5828
+ canonicalSchemeName,
4944
5829
  checkPaletteDistinguishability,
4945
5830
  clampStaggerDelay,
4946
5831
  clarity,
@@ -4980,6 +5865,7 @@ export {
4980
5865
  formatNumber,
4981
5866
  formatOrdinal,
4982
5867
  formatPercent2 as formatPercent,
5868
+ formatRawNumber,
4983
5869
  generateAltText,
4984
5870
  generateAriaLabels,
4985
5871
  generateDataTable,
@@ -5007,7 +5893,9 @@ export {
5007
5893
  isRangeAnnotation,
5008
5894
  isRefLineAnnotation,
5009
5895
  isSafeLink,
5896
+ isSafeLogoSource,
5010
5897
  isSankeySpec,
5898
+ isSupportedLocale,
5011
5899
  isTableSpec,
5012
5900
  isTextAnnotation,
5013
5901
  isTileMapSpec,
@@ -5020,6 +5908,7 @@ export {
5020
5908
  lineChart,
5021
5909
  mapFeatureDuration,
5022
5910
  mapSweepTiming,
5911
+ matchLocale,
5023
5912
  maxRotatedLabelWidth,
5024
5913
  meetsAA,
5025
5914
  mergeThemeConfig,