@opendata-ai/openchart-core 9.7.1 → 9.8.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.d.ts CHANGED
@@ -326,6 +326,8 @@ interface ThemeColors {
326
326
  hairline: string;
327
327
  /** Sequential palettes keyed by name. Each is an array of color stops from light to dark. */
328
328
  sequential: Record<string, string[]>;
329
+ /** Default sequential ramp key; resolved to the first ramp when omitted or unknown. */
330
+ defaultSequential?: string;
329
331
  /** Diverging palettes keyed by name. Each is an array of color stops with a neutral midpoint. */
330
332
  diverging: Record<string, string[]>;
331
333
  /** Background color for the visualization container. */
@@ -376,6 +378,8 @@ interface ThemeColors {
376
378
  * neutral ramp derived from the theme's own text/background pair.
377
379
  */
378
380
  interface ResolvedThemeColors extends ThemeColors {
381
+ /** Key of the default sequential ramp in the merged palette record. */
382
+ defaultSequential: string;
379
383
  /** Grays derived by mixing `text` toward `background`. */
380
384
  neutral: NeutralRamp;
381
385
  }
@@ -4421,7 +4425,21 @@ type DarkMode = 'auto' | 'force' | 'off';
4421
4425
  type ChromeAlign = 'left' | 'center' | 'right';
4422
4426
  /** Placement of a theme logo relative to the visualization. */
4423
4427
  type LogoPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
4424
- /** Theme logo source, size and placement. */
4428
+ /**
4429
+ * Theme logo source, size and placement.
4430
+ *
4431
+ * @remarks
4432
+ * Set `chrome.logo: false` to hide it per spec. Logos require full chrome and
4433
+ * a total visualization width of at least 120 px.
4434
+ * Charts, including fixed-size charts, use compact chrome at heights from 100
4435
+ * through 350 px and hidden chrome below 100 px. They also reduce chrome when
4436
+ * full chrome would squeeze the plot. Compact and hidden chrome omit the logo.
4437
+ * `display: 'sparkline'` hides chrome by default; explicit spec chrome can keep it.
4438
+ * Geo maps reduce chrome from full to compact to hidden when it would leave the
4439
+ * map area below MIN_GEO_MAP_HEIGHT (40 px), unless chrome grows outside the
4440
+ * height budget. Other spec kinds keep full chrome regardless of height.
4441
+ * Fixed spec width/height override the container size before these rules apply.
4442
+ */
4425
4443
  interface ThemeLogo {
4426
4444
  /** Logo image data URL. */
4427
4445
  src: string;
@@ -4479,6 +4497,8 @@ interface ThemeConfig {
4479
4497
  hairline?: TokenValue;
4480
4498
  /** Sequential palettes keyed by name. Each is an array of color stops. */
4481
4499
  sequential?: Record<string, TokenValue[]>;
4500
+ /** Default sequential ramp key. Unknown or omitted names use the first merged ramp. */
4501
+ defaultSequential?: string;
4482
4502
  /** Diverging palettes keyed by name. Each is an array of color stops with a neutral midpoint. */
4483
4503
  diverging?: Record<string, TokenValue[]>;
4484
4504
  /** Background color. Accepts a TokenValue for light/dark pairs. */
@@ -7485,7 +7505,7 @@ interface ReaderSliceIndexOptions {
7485
7505
  /**
7486
7506
  * Color blindness simulation and palette distinguishability checks.
7487
7507
  *
7488
- * Uses Brettel, Vienot, and Mollon (1997) simulation matrices for
7508
+ * Uses Machado, Oliveira & Fernandes (2009), severity 1.0, for
7489
7509
  * protanopia, deuteranopia, and tritanopia.
7490
7510
  *
7491
7511
  * These are approximations suitable for checking palette accessibility,
@@ -7495,15 +7515,19 @@ interface ReaderSliceIndexOptions {
7495
7515
  type ColorBlindnessType = 'protanopia' | 'deuteranopia' | 'tritanopia' | 'achromatopsia';
7496
7516
  /**
7497
7517
  * Simulate how a color appears under a given color blindness type.
7498
- * Returns a hex color string.
7518
+ * Returns a clamped sRGB hex color string. Unresolvable colors (including
7519
+ * transparent) and unsupported types return the input color unchanged.
7499
7520
  */
7500
7521
  declare function simulateColorBlindness(color: string, type: ColorBlindnessType): string;
7501
7522
  /**
7502
7523
  * Check if colors in a palette are distinguishable under a given
7503
7524
  * color blindness type.
7504
7525
  *
7505
- * Uses a minimum perceptual distance threshold in simulated space.
7506
- * Returns true if all pairs of colors are sufficiently different.
7526
+ * Uses CIE76 distance in d3-color's D50 CIELAB after simulation, with a
7527
+ * default minDistance of 15 delta E units as a screening heuristic.
7528
+ * Returns true if every pair has distance >= minDistance (also for empty or
7529
+ * single-color palettes). Unresolvable colors/palettes and unsupported types
7530
+ * return false. Non-finite or negative thresholds fall back to 15.
7507
7531
  */
7508
7532
  declare function checkPaletteDistinguishability(colors: string[], type: ColorBlindnessType, minDistance?: number): boolean;
7509
7533
 
@@ -7595,9 +7619,8 @@ declare const ACHROMATIC_RAMP: {
7595
7619
  * Construction rules (the contract; the hexes below are output, not input):
7596
7620
  * - Hue order cyan 216 -> ochre 70 -> blue 262 -> rose 350 -> green 155 ->
7597
7621
  * violet 300, so every adjacent pair including the wrap is >= 80° apart.
7598
- * - Lightness varies rather than matching: colour-vision deficiency
7599
- * collapses hue and only lightness survives, so a matched-lightness ramp
7600
- * fails the repo's own Brettel simulator on ochre/rose and blue/violet.
7622
+ * - Lightness varies rather than matching: colour-vision deficiency can
7623
+ * reduce hue separation, while differences in lightness can survive.
7601
7624
  * - Fills use equal or lower chroma and equal or higher lightness than
7602
7625
  * strokes (within sRGB rounding), while clearing 3:1 on near-white.
7603
7626
  * Cyan uses reduced chroma to remain in gamut at its darker lightness.
@@ -7608,9 +7631,11 @@ declare const ACHROMATIC_RAMP: {
7608
7631
  * the dark-mode adapter's hsl-based binary search). Each entry carries its
7609
7632
  * *measured* OKLCH so the ramp can be regenerated; do not edit hexes directly.
7610
7633
  *
7611
- * Every array here clears `checkPaletteDistinguishability` at the default
7612
- * minDistance 30 for deuteranopia and protanopia — see
7613
- * `colors/__tests__/palette-a11y.test.ts`, which is the guard on any change.
7634
+ * With Machado simulation and the heuristic CIE76 threshold of 15, light
7635
+ * strokes pass deuteranopia and dark strokes pass tritanopia; the other
7636
+ * array/deficiency combinations fail. The colors are kept for compatibility.
7637
+ * See docs/design-system.md for every nearest pair and measured distance,
7638
+ * and `colors/__tests__/palette-a11y.test.ts` for the regression checks.
7614
7639
  */
7615
7640
  declare const CATEGORICAL_PALETTE: readonly ["#0a879e", "#bf7e1f", "#4170cb", "#b2417f", "#3ca368", "#9c7bd2"];
7616
7641
  /**
@@ -7740,9 +7765,9 @@ declare const wire: ThemeConfig;
7740
7765
  * Broadsheet preset: newspaper editorial. Warm paper, a red masthead rule and
7741
7766
  * eyebrow, a bold 24px title, and a quiet palette built around one loud hue.
7742
7767
  *
7743
- * Palette (measured OKLCH; checked with the repo's Brettel CVD simulator —
7744
- * deuteranopia and protanopia both pass, nearest simulated pair 48.7 against
7745
- * a threshold of 30):
7768
+ * Palette (measured OKLCH). Machado severity 1.0, CIE76 threshold 15:
7769
+ * light strokes fail deuteranopia (nearest green/gray, 5.75) and protanopia
7770
+ * (green/gray, 8.44); light fills also fail both (5.80 and 7.74).
7746
7771
  * 1 #1d5f8a oklch(0.466 0.095 242) ink blue
7747
7772
  * 2 #e3120b oklch(0.580 0.232 29) house red — the one loud hue
7748
7773
  * 3 #7fb0d3 oklch(0.735 0.073 240) pale blue
@@ -7753,9 +7778,9 @@ declare const wire: ThemeConfig;
7753
7778
  *
7754
7779
  * Dark mode is the same page after nightfall: the newsprint gives way to an
7755
7780
  * ink-blue ground, with the same hues lifted to hold their contrast on it.
7756
- * Palette (dark; checked with the Brettel simulator, nearest simulated pair
7757
- * 31.6 under deuteranopia against a threshold of 30, every stroke at 5.8:1
7758
- * or better and every fill at 5.3:1 or better on #12181f):
7781
+ * Dark strokes fail deuteranopia (nearest green/gray, 8.55) and pass
7782
+ * protanopia (green/gray, 15.26). Dark fills fail both (nearest green/gray,
7783
+ * 9.22 under deuteranopia; pale blue/gray, 13.98 under protanopia).
7759
7784
  * 1 #5e9fd6 ink blue, lifted 2 #f4655a house red, lifted
7760
7785
  * 3 #93c2e2 pale blue 4 #e0b267 ochre
7761
7786
  * 5 #4fb093 green 6 #9aa1a8 gray, cooled
package/dist/index.js CHANGED
@@ -521,21 +521,21 @@ var MARK_DISPLAY_NAMES = {
521
521
  };
522
522
 
523
523
  // src/colors/colorblind.ts
524
- import { rgb } from "d3-color";
524
+ import { lab, rgb } from "d3-color";
525
525
  var PROTAN_MATRIX = [
526
- [0.567, 0.433, 0],
527
- [0.558, 0.442, 0],
528
- [0, 0.242, 0.758]
526
+ [0.152286, 1.052583, -0.204868],
527
+ [0.114503, 0.786281, 0.099216],
528
+ [-3882e-6, -0.048116, 1.051998]
529
529
  ];
530
530
  var DEUTAN_MATRIX = [
531
- [0.625, 0.375, 0],
532
- [0.7, 0.3, 0],
533
- [0, 0.3, 0.7]
531
+ [0.367322, 0.860646, -0.227968],
532
+ [0.280085, 0.672501, 0.047413],
533
+ [-0.01182, 0.04294, 0.968881]
534
534
  ];
535
535
  var TRITAN_MATRIX = [
536
- [0.95, 0.05, 0],
537
- [0, 0.433, 0.567],
538
- [0, 0.475, 0.525]
536
+ [1.255528, -0.076749, -0.178779],
537
+ [-0.078411, 0.930809, 0.147602],
538
+ [4733e-6, 0.691367, 0.3039]
539
539
  ];
540
540
  var ACHROMAT_MATRIX = [
541
541
  [0.2126, 0.7152, 0.0722],
@@ -557,8 +557,9 @@ function delinearize(v) {
557
557
  return Math.round(Math.max(0, Math.min(255, s * 255)));
558
558
  }
559
559
  function simulateColorBlindness(color, type) {
560
+ if (typeof color !== "string" || !Object.hasOwn(MATRICES, type)) return color;
560
561
  const c = rgb(color);
561
- if (c == null) return color;
562
+ if (![c.r, c.g, c.b].every(Number.isFinite)) return color;
562
563
  const lin = [linearize(c.r), linearize(c.g), linearize(c.b)];
563
564
  const m = MATRICES[type];
564
565
  const r = m[0][0] * lin[0] + m[0][1] * lin[1] + m[0][2] * lin[2];
@@ -566,18 +567,23 @@ function simulateColorBlindness(color, type) {
566
567
  const b = m[2][0] * lin[0] + m[2][1] * lin[1] + m[2][2] * lin[2];
567
568
  return rgb(delinearize(r), delinearize(g), delinearize(b)).formatHex();
568
569
  }
569
- function checkPaletteDistinguishability(colors, type, minDistance = 30) {
570
- const simulated = colors.map((c) => {
571
- const s = rgb(simulateColorBlindness(c, type));
572
- return s ? [s.r, s.g, s.b] : [0, 0, 0];
573
- });
570
+ function checkPaletteDistinguishability(colors, type, minDistance = 15) {
571
+ if (!Array.isArray(colors) || !Object.hasOwn(MATRICES, type)) return false;
572
+ const threshold = Number.isFinite(minDistance) && minDistance >= 0 ? minDistance : 15;
573
+ const simulated = [];
574
+ for (const color of colors) {
575
+ if (typeof color !== "string") return false;
576
+ const s = lab(simulateColorBlindness(color, type));
577
+ if (![s.l, s.a, s.b].every(Number.isFinite)) return false;
578
+ simulated.push(s);
579
+ }
574
580
  for (let i = 0; i < simulated.length; i++) {
575
581
  for (let j = i + 1; j < simulated.length; j++) {
576
- const dr = simulated[i][0] - simulated[j][0];
577
- const dg = simulated[i][1] - simulated[j][1];
578
- const db = simulated[i][2] - simulated[j][2];
579
- const dist = Math.sqrt(dr * dr + dg * dg + db * db);
580
- if (dist < minDistance) return false;
582
+ const dl = simulated[i].l - simulated[j].l;
583
+ const da = simulated[i].a - simulated[j].a;
584
+ const db = simulated[i].b - simulated[j].b;
585
+ const dist = Math.hypot(dl, da, db);
586
+ if (dist < threshold) return false;
581
587
  }
582
588
  }
583
589
  return true;
@@ -2280,7 +2286,7 @@ var wire = {
2280
2286
  },
2281
2287
  fonts: {
2282
2288
  family: '"JetBrains Mono", "Fira Code", "Cascadia Code", monospace',
2283
- sizes: { title: 16, subtitle: 12, body: 11, small: 10, axisTick: 10 },
2289
+ sizes: { title: 16, subtitle: 12, body: 11, small: 10, axisTick: 12 },
2284
2290
  weights: { normal: 400, medium: 500, semibold: 600, bold: 700 }
2285
2291
  },
2286
2292
  spacing: {
@@ -2358,7 +2364,7 @@ var terminal = /* @__PURE__ */ (() => ({
2358
2364
  fonts: {
2359
2365
  family: '"Inter Variable", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
2360
2366
  mono: '"JetBrains Mono", "Fira Code", "Cascadia Code", monospace',
2361
- sizes: { title: 15, subtitle: 12, body: 12, small: 10, axisTick: 10 }
2367
+ sizes: { title: 15, subtitle: 12, body: 12, small: 10, axisTick: 12 }
2362
2368
  },
2363
2369
  spacing: {
2364
2370
  padding: 12,
@@ -2454,6 +2460,8 @@ function themeConfigToPartial(config, base2) {
2454
2460
  if (Array.isArray(config.colors)) {
2455
2461
  colors.categorical = config.colors;
2456
2462
  } else {
2463
+ const { defaultSequential } = config.colors;
2464
+ if (typeof defaultSequential === "string") colors.defaultSequential = defaultSequential;
2457
2465
  if (config.colors.categorical)
2458
2466
  colors.categorical = config.colors.categorical.map(resolveTokenLight);
2459
2467
  if (config.colors.categoricalFill)
@@ -2742,12 +2750,14 @@ function resolveTheme(userTheme, base2 = DEFAULT_THEME) {
2742
2750
  const neutral = deriveNeutralRamp(merged.colors.text, merged.colors.background, dark);
2743
2751
  const authoredColors = userTheme?.colors && !Array.isArray(userTheme.colors) ? userTheme.colors : {};
2744
2752
  const rampPairs = userTheme ? collectRampPairs(userTheme) : void 0;
2753
+ const { sequential, defaultSequential } = merged.colors;
2745
2754
  return {
2746
2755
  ...merged,
2747
2756
  _authored: userTheme,
2748
2757
  colors: {
2749
2758
  ...merged.colors,
2750
2759
  neutral,
2760
+ defaultSequential: typeof defaultSequential === "string" && Object.hasOwn(sequential, defaultSequential) ? defaultSequential : Object.keys(sequential)[0] ?? "",
2751
2761
  annotationMarkerFill: authoredColors.annotationMarkerFill === void 0 ? neutral.surface : merged.colors.annotationMarkerFill,
2752
2762
  annotationPlate: authoredColors.annotationPlate === void 0 ? neutral.surface : merged.colors.annotationPlate
2753
2763
  },