@lostgradient/cinder 0.22.0 → 0.23.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.
Files changed (164) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/components.json +1 -1
  3. package/dist/_internal/chart/chart-bar-model.d.ts +24 -0
  4. package/dist/_internal/chart/chart-cartesian-model.d.ts +16 -0
  5. package/dist/_internal/chart/chart-layout.d.ts +23 -0
  6. package/dist/_internal/chart/chart-model-utilities.d.ts +157 -0
  7. package/dist/_internal/chart/chart-scale.d.ts +37 -0
  8. package/dist/_internal/chart/chart-utilities.d.ts +7 -164
  9. package/dist/_internal/chart/heatmap-utilities.d.ts +5 -4
  10. package/dist/components/_internal/chart-tooltip.css +21 -0
  11. package/dist/components/_internal/chart-tooltip.svelte.d.ts +11 -0
  12. package/dist/components/approval-card/index.js +5 -5
  13. package/dist/components/area-chart/area-chart.css +27 -23
  14. package/dist/components/area-chart/area-chart.schema.js +38 -1
  15. package/dist/components/area-chart/area-chart.types.d.ts +6 -2
  16. package/dist/components/area-chart/index.js +1589 -768
  17. package/dist/components/badge/badge.css +2 -2
  18. package/dist/components/badge/badge.schema.js +2 -2
  19. package/dist/components/badge/badge.types.d.ts +3 -3
  20. package/dist/components/badge/index.js +4 -4
  21. package/dist/components/bar-chart/bar-chart.css +27 -21
  22. package/dist/components/bar-chart/bar-chart.schema.js +38 -1
  23. package/dist/components/bar-chart/bar-chart.types.d.ts +7 -3
  24. package/dist/components/bar-chart/index.js +1544 -740
  25. package/dist/components/chart.types.d.ts +98 -2
  26. package/dist/components/json-schema-editor/index.js +4 -4
  27. package/dist/components/line-chart/index.js +1587 -785
  28. package/dist/components/line-chart/line-chart.css +25 -24
  29. package/dist/components/line-chart/line-chart.schema.js +38 -1
  30. package/dist/components/line-chart/line-chart.types.d.ts +6 -2
  31. package/dist/components/matrix-chart/index.js +1038 -429
  32. package/dist/components/matrix-chart/matrix-chart.css +12 -6
  33. package/dist/components/matrix-chart/matrix-chart.schema.js +26 -1
  34. package/dist/components/matrix-chart/matrix-chart.types.d.ts +5 -1
  35. package/dist/components/payload-inspector/index.js +4 -4
  36. package/dist/components/run-step-timeline/index.js +6 -6
  37. package/dist/components/sparkbar/index.js +1291 -4
  38. package/dist/components/sparkbar/sparkbar.css +5 -4
  39. package/dist/components/sparkbar/sparkbar.schema.js +26 -1
  40. package/dist/components/sparkbar/sparkbar.types.d.ts +5 -0
  41. package/dist/components/spectrogram/index.js +1076 -437
  42. package/dist/components/spectrogram/spectrogram.css +7 -6
  43. package/dist/components/spectrogram/spectrogram.schema.js +26 -1
  44. package/dist/components/spectrogram/spectrogram.types.d.ts +5 -1
  45. package/dist/components/spectrum-chart/index.js +1037 -423
  46. package/dist/components/spectrum-chart/spectrum-chart.css +8 -7
  47. package/dist/components/spectrum-chart/spectrum-chart.schema.js +26 -1
  48. package/dist/components/spectrum-chart/spectrum-chart.types.d.ts +5 -1
  49. package/dist/components/statistic/index.js +1288 -2
  50. package/dist/components/statistic/statistic.css +6 -5
  51. package/dist/components/statistic/statistic.schema.js +26 -1
  52. package/dist/components/statistic/statistic.types.d.ts +5 -0
  53. package/dist/components/statistic-group/index.js +1288 -2
  54. package/dist/components/waveform/index.js +1004 -404
  55. package/dist/components/waveform/waveform.css +8 -7
  56. package/dist/components/waveform/waveform.schema.js +26 -1
  57. package/dist/components/waveform/waveform.types.d.ts +5 -1
  58. package/dist/index.d.ts +1 -1
  59. package/dist/index.js +17734 -16540
  60. package/dist/server/components/approval-card/index.js +3 -3
  61. package/dist/server/components/area-chart/index.js +3 -3
  62. package/dist/server/components/badge/index.js +2 -2
  63. package/dist/server/components/bar-chart/index.js +3 -3
  64. package/dist/server/components/json-schema-editor/index.js +2 -2
  65. package/dist/server/components/line-chart/index.js +3 -3
  66. package/dist/server/components/matrix-chart/index.js +3 -3
  67. package/dist/server/components/payload-inspector/index.js +3 -3
  68. package/dist/server/components/run-step-timeline/index.js +2 -2
  69. package/dist/server/components/sparkbar/index.js +3 -2
  70. package/dist/server/components/spectrogram/index.js +3 -3
  71. package/dist/server/components/spectrum-chart/index.js +2 -2
  72. package/dist/server/components/statistic/index.js +4 -3
  73. package/dist/server/components/statistic-group/index.js +4 -3
  74. package/dist/server/components/waveform/index.js +2 -2
  75. package/dist/server/index.js +21 -21
  76. package/dist/server/{index.server-3dkwzkd3.js → index.server-10r7yf13.js} +110 -27
  77. package/dist/server/{index.server-pp2n6def.js → index.server-2y0xz53g.js} +37 -14
  78. package/dist/server/{index.server-bd8rcgf0.js → index.server-4hvjet4z.js} +1 -1
  79. package/dist/server/{index.server-bsm39gpy.js → index.server-5d83fkyg.js} +75 -21
  80. package/dist/server/{index.server-abqbstkt.js → index.server-9gj583qs.js} +41 -14
  81. package/dist/server/{index.server-2nmwsacy.js → index.server-9scm7zf9.js} +4 -4
  82. package/dist/server/{index.server-5j6jv7rm.js → index.server-9vwxyy06.js} +108 -29
  83. package/dist/server/{index.server-abjsjsw8.js → index.server-afpjvfz1.js} +111 -35
  84. package/dist/server/{index.server-wm8957be.js → index.server-bp0vzxby.js} +14 -1
  85. package/dist/server/{index.server-86sw5ea6.js → index.server-dw9bz17h.js} +4 -4
  86. package/dist/server/{index.server-d26jzn2m.js → index.server-en31rprd.js} +3 -3
  87. package/dist/server/{index.server-dx58qant.js → index.server-f3a0ecqg.js} +72 -9
  88. package/dist/server/{index.server-d63pwytk.js → index.server-kz8aeeq5.js} +18 -10
  89. package/dist/server/index.server-mmmrgvyd.js +1274 -0
  90. package/dist/server/{index.server-93943z3e.js → index.server-rx9aszk6.js} +1 -1
  91. package/dist/server/{index.server-1221p7e4.js → index.server-scahngwv.js} +13 -1
  92. package/dist/server/{index.server-nj8kk5bv.js → index.server-t73q59c1.js} +1 -1
  93. package/dist/server/{index.server-5schb2vt.js → index.server-tdrncj5e.js} +16 -6
  94. package/dist/server/{index.server-4wweyb2e.js → index.server-vnr1h5g5.js} +1 -1
  95. package/dist/server/{index.server-fphvzcfb.js → index.server-wqajghn9.js} +1 -1
  96. package/dist/server/{index.server-yd9shwqq.js → index.server-zjcjzcv6.js} +1 -1
  97. package/package.json +1 -1
  98. package/src/_internal/chart/chart-bar-model.ts +330 -0
  99. package/src/_internal/chart/chart-cartesian-model.ts +450 -0
  100. package/src/_internal/chart/chart-interaction.svelte.ts +25 -6
  101. package/src/_internal/chart/chart-layout.ts +348 -0
  102. package/src/_internal/chart/chart-model-utilities.ts +357 -0
  103. package/src/_internal/chart/chart-scale.ts +487 -0
  104. package/src/_internal/chart/chart-utilities.ts +22 -1078
  105. package/src/_internal/chart/heatmap-utilities.ts +21 -17
  106. package/src/components/_internal/chart-tooltip.css +21 -0
  107. package/src/components/_internal/chart-tooltip.svelte +44 -0
  108. package/src/components/approval-card/approval-card.svelte +1 -1
  109. package/src/components/area-chart/area-chart.css +27 -23
  110. package/src/components/area-chart/area-chart.examples.json +1 -1
  111. package/src/components/area-chart/area-chart.schema.json +37 -0
  112. package/src/components/area-chart/area-chart.schema.ts +40 -0
  113. package/src/components/area-chart/area-chart.svelte +103 -35
  114. package/src/components/area-chart/area-chart.types.ts +7 -1
  115. package/src/components/badge/badge.css +2 -2
  116. package/src/components/badge/badge.schema.json +1 -1
  117. package/src/components/badge/badge.schema.ts +1 -1
  118. package/src/components/badge/badge.svelte +2 -2
  119. package/src/components/badge/badge.types.ts +3 -3
  120. package/src/components/bar-chart/bar-chart.css +27 -21
  121. package/src/components/bar-chart/bar-chart.schema.json +37 -0
  122. package/src/components/bar-chart/bar-chart.schema.ts +40 -0
  123. package/src/components/bar-chart/bar-chart.svelte +94 -33
  124. package/src/components/bar-chart/bar-chart.types.ts +9 -2
  125. package/src/components/chart.types.ts +112 -2
  126. package/src/components/line-chart/line-chart.css +25 -24
  127. package/src/components/line-chart/line-chart.examples.json +1 -1
  128. package/src/components/line-chart/line-chart.schema.json +37 -0
  129. package/src/components/line-chart/line-chart.schema.ts +40 -0
  130. package/src/components/line-chart/line-chart.svelte +95 -40
  131. package/src/components/line-chart/line-chart.types.ts +7 -1
  132. package/src/components/matrix-chart/matrix-chart.css +12 -6
  133. package/src/components/matrix-chart/matrix-chart.schema.json +25 -0
  134. package/src/components/matrix-chart/matrix-chart.schema.ts +25 -0
  135. package/src/components/matrix-chart/matrix-chart.svelte +30 -12
  136. package/src/components/matrix-chart/matrix-chart.types.ts +5 -1
  137. package/src/components/run-step-timeline/run-step-timeline.svelte +2 -2
  138. package/src/components/sparkbar/sparkbar.css +5 -4
  139. package/src/components/sparkbar/sparkbar.schema.json +25 -0
  140. package/src/components/sparkbar/sparkbar.schema.ts +26 -0
  141. package/src/components/sparkbar/sparkbar.svelte +8 -1
  142. package/src/components/sparkbar/sparkbar.types.ts +5 -0
  143. package/src/components/spectrogram/spectrogram.css +7 -6
  144. package/src/components/spectrogram/spectrogram.schema.json +25 -0
  145. package/src/components/spectrogram/spectrogram.schema.ts +25 -0
  146. package/src/components/spectrogram/spectrogram.svelte +73 -28
  147. package/src/components/spectrogram/spectrogram.types.ts +5 -1
  148. package/src/components/spectrum-chart/spectrum-chart.css +8 -7
  149. package/src/components/spectrum-chart/spectrum-chart.schema.json +25 -0
  150. package/src/components/spectrum-chart/spectrum-chart.schema.ts +26 -0
  151. package/src/components/spectrum-chart/spectrum-chart.svelte +38 -12
  152. package/src/components/spectrum-chart/spectrum-chart.types.ts +5 -1
  153. package/src/components/statistic/statistic.css +6 -5
  154. package/src/components/statistic/statistic.schema.json +25 -0
  155. package/src/components/statistic/statistic.schema.ts +26 -0
  156. package/src/components/statistic/statistic.svelte +42 -1
  157. package/src/components/statistic/statistic.types.ts +5 -0
  158. package/src/components/waveform/waveform.css +8 -7
  159. package/src/components/waveform/waveform.schema.json +25 -0
  160. package/src/components/waveform/waveform.schema.ts +26 -0
  161. package/src/components/waveform/waveform.svelte +16 -3
  162. package/src/components/waveform/waveform.types.ts +5 -1
  163. package/src/index.ts +8 -0
  164. package/dist/server/index.server-6vbpz6dd.js +0 -690
@@ -45,6 +45,31 @@
45
45
  "type": "string",
46
46
  "description": "Custom data table caption; falls back to `label`."
47
47
  },
48
+ "theme": {
49
+ "type": "object",
50
+ "properties": {
51
+ "foreground": {
52
+ "type": "string"
53
+ },
54
+ "muted": {
55
+ "type": "string"
56
+ },
57
+ "grid": {
58
+ "type": "string"
59
+ },
60
+ "background": {
61
+ "type": "string"
62
+ },
63
+ "palette": {
64
+ "type": "array",
65
+ "items": {
66
+ "type": "string"
67
+ }
68
+ }
69
+ },
70
+ "additionalProperties": false,
71
+ "description": "Partial visual theme override. Omitted fields inherit the surrounding application."
72
+ },
48
73
  "class": {
49
74
  "type": "string",
50
75
  "description": "Custom class applied to the root element."
@@ -47,6 +47,32 @@ const schema = {
47
47
  type: 'string',
48
48
  description: 'Custom data table caption; falls back to `label`.',
49
49
  },
50
+ theme: {
51
+ type: 'object',
52
+ properties: {
53
+ foreground: {
54
+ type: 'string',
55
+ },
56
+ muted: {
57
+ type: 'string',
58
+ },
59
+ grid: {
60
+ type: 'string',
61
+ },
62
+ background: {
63
+ type: 'string',
64
+ },
65
+ palette: {
66
+ type: 'array',
67
+ items: {
68
+ type: 'string',
69
+ },
70
+ },
71
+ },
72
+ additionalProperties: false,
73
+ description:
74
+ 'Partial visual theme override. Omitted fields inherit the surrounding application.',
75
+ },
50
76
  class: {
51
77
  type: 'string',
52
78
  description: 'Custom class applied to the root element.',
@@ -3,17 +3,14 @@ export {};
3
3
  </script>
4
4
 
5
5
  <script lang="ts">
6
- import { dataTableClass, formatNumericValue } from '../../_internal/chart/chart-utilities.ts';
6
+ import { onMount } from 'svelte';
7
+ import { chartPaletteColor, createChartGeometry, dataTableClass, formatNumericValue, observeChartFontLoading, resolveChartTheme, } from '../../_internal/chart/chart-utilities.ts';
7
8
  import { classNames } from '../../utilities/class-names.ts';
8
9
  import { useResizeObserver } from '../../utilities/use-resize-observer.svelte.ts';
9
- let { label, description, bins, height = 160, loading = false, dataTableVisibility = 'screen-reader-only', dataTableCaption, class: customClassName, empty, loadingContent, id, ...rest } = $props();
10
+ let { label, description, bins, height = 160, loading = false, dataTableVisibility = 'screen-reader-only', dataTableCaption, theme, class: customClassName, empty, loadingContent, id, ...rest } = $props();
10
11
  const generatedId = $props.id();
11
12
  const rootId = $derived(id ?? generatedId);
12
13
  const descriptionId = $derived(description ? `${rootId}-description` : undefined);
13
- const marginTop = 8;
14
- const marginRight = 8;
15
- const marginBottom = 32;
16
- const marginLeft = 40;
17
14
  let measuredWidth = $state(400);
18
15
  const observeResize = useResizeObserver((entries) => {
19
16
  const entry = entries[0];
@@ -22,9 +19,17 @@ const observeResize = useResizeObserver((entries) => {
22
19
  if (entry && entry.contentRect.width > 0)
23
20
  measuredWidth = entry.contentRect.width;
24
21
  });
25
- const plotWidth = $derived(Math.max(1, measuredWidth - marginLeft - marginRight));
26
- const plotHeight = $derived(Math.max(1, height - marginTop - marginBottom));
27
22
  const isEmpty = $derived(bins.length === 0);
23
+ const resolvedTheme = $derived(resolveChartTheme(theme));
24
+ let rootElement = $state();
25
+ let measureText = $state(false);
26
+ let measurementVersion = $state(0);
27
+ onMount(() => {
28
+ measureText = true;
29
+ return observeChartFontLoading(() => {
30
+ measurementVersion += 1;
31
+ });
32
+ });
28
33
  // Spectrum magnitudes are linear non-negative. Coerce each bin's value to a
29
34
  // finite, non-negative number so a stray NaN/Infinity/negative can't break the
30
35
  // axis domain or invert bar geometry.
@@ -49,6 +54,21 @@ const yTicks = $derived.by(() => {
49
54
  return [0];
50
55
  return Array.from({ length: tickCount }, (_, index) => (maxValue * index) / (tickCount - 1));
51
56
  });
57
+ // Feed the actual guide labels into the shared geometry calculator so long
58
+ // numeric/frequency labels receive enough room without fixed margins.
59
+ const maxXLabels = 8;
60
+ const xLabelStep = $derived(Math.max(1, Math.ceil(bins.length / maxXLabels)));
61
+ const xTickLabels = $derived(bins.filter((_, index) => index % xLabelStep === 0).map((bin) => bin.label));
62
+ const yTickLabels = $derived(yTicks.map((tick, index) => formatNumericValue(tick, undefined, undefined, { index })));
63
+ const geometry = $derived(createChartGeometry(measuredWidth, height, {
64
+ xTickLabels,
65
+ yTickLabels,
66
+ measureText,
67
+ measurementElement: rootElement,
68
+ measurementVersion,
69
+ }));
70
+ const plotWidth = $derived(geometry.plotWidth);
71
+ const plotHeight = $derived(geometry.plotHeight);
52
72
  function scaleY(value) {
53
73
  if (maxValue <= 0)
54
74
  return plotHeight;
@@ -71,19 +91,22 @@ const spectrumBars = $derived.by(() => {
71
91
  };
72
92
  });
73
93
  });
74
- // Show only a subset of x-axis labels to avoid clutter
75
- const maxXLabels = 8;
76
- const xLabelStep = $derived(Math.max(1, Math.ceil(bins.length / maxXLabels)));
77
94
  const hasDataTable = $derived(dataTableVisibility !== 'hidden');
78
95
  </script>
79
96
 
80
97
  <figure
81
98
  {...rest}
82
99
  {@attach observeResize}
100
+ bind:this={rootElement}
83
101
  id={rootId}
84
102
  class={classNames('cinder-spectrum-chart', customClassName)}
85
103
  aria-label={label}
86
104
  aria-describedby={descriptionId}
105
+ style:--_cinder-chart-foreground={resolvedTheme.foreground}
106
+ style:--_cinder-chart-muted={resolvedTheme.muted}
107
+ style:--_cinder-chart-grid={resolvedTheme.grid}
108
+ style:--_cinder-chart-background={resolvedTheme.background}
109
+ style:--_cinder-chart-series-color={chartPaletteColor(0, resolvedTheme.palette)}
87
110
  >
88
111
  {#if description}
89
112
  <p id={descriptionId} class="cinder-spectrum-chart__description">{description}</p>
@@ -115,7 +138,7 @@ const hasDataTable = $derived(dataTableVisibility !== 'hidden');
115
138
  overlay would have a stray baseline grid line and ticks drawn under it
116
139
  (yTicks falls back to [0] when there is no data). -->
117
140
  {#if !loading && !isEmpty}
118
- <g transform={`translate(${marginLeft}, ${marginTop})`}>
141
+ <g transform={`translate(${geometry.marginLeft}, ${geometry.marginTop})`}>
119
142
  <!-- Y-axis ticks -->
120
143
  {#each yTicks as tick, index (index)}
121
144
  <text
@@ -124,6 +147,7 @@ const hasDataTable = $derived(dataTableVisibility !== 'hidden');
124
147
  y={scaleY(tick)}
125
148
  text-anchor="end"
126
149
  dominant-baseline="middle"
150
+ fill={resolvedTheme.muted}
127
151
  >{formatNumericValue(tick, undefined, undefined, { index })}</text
128
152
  >
129
153
  <line
@@ -133,6 +157,7 @@ const hasDataTable = $derived(dataTableVisibility !== 'hidden');
133
157
  y1={scaleY(tick)}
134
158
  y2={scaleY(tick)}
135
159
  aria-hidden="true"
160
+ stroke={resolvedTheme.grid}
136
161
  />
137
162
  {/each}
138
163
  <!-- Frequency bars -->
@@ -145,6 +170,7 @@ const hasDataTable = $derived(dataTableVisibility !== 'hidden');
145
170
  height={bar.barHeight}
146
171
  aria-hidden="true"
147
172
  data-cinder-bin={bar.label}
173
+ fill={chartPaletteColor(0, resolvedTheme.palette)}
148
174
  />
149
175
  {/each}
150
176
  <!-- X-axis frequency labels (sampled to avoid overlap) -->
@@ -1,6 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
- import type { ChartDataTableVisibility } from '../chart.types.ts';
3
+ import type { ChartDataTableVisibility, ChartTheme, ChartThemeSchema } from '../chart.types.ts';
4
4
 
5
5
  /** @schemaObject */
6
6
  export type SpectrumBin = {
@@ -25,6 +25,8 @@ export type SpectrumChartProps = Omit<HTMLAttributes<HTMLElement>, 'class'> & {
25
25
  dataTableVisibility?: ChartDataTableVisibility;
26
26
  /** Custom data table caption; falls back to `label`. */
27
27
  dataTableCaption?: string;
28
+ /** Partial visual theme override. Omitted fields inherit the surrounding application. */
29
+ theme?: ChartTheme;
28
30
  /** Custom class applied to the root element. */
29
31
  class?: string;
30
32
  /** Snippet rendered when there are no bins. */
@@ -48,6 +50,8 @@ export type SpectrumChartSchemaProps = {
48
50
  dataTableVisibility?: ChartDataTableVisibility;
49
51
  /** Custom data table caption; falls back to `label`. */
50
52
  dataTableCaption?: string;
53
+ /** Partial visual theme override. Omitted fields inherit the surrounding application. */
54
+ theme?: ChartThemeSchema;
51
55
  /** Custom class applied to the root element. */
52
56
  class?: string;
53
57
  };
@@ -14,7 +14,8 @@
14
14
  grid-template-rows: auto auto auto;
15
15
  row-gap: var(--cinder-statistic-row-gap, var(--cinder-space-1, 0.25rem));
16
16
  align-items: start;
17
- color: var(--cinder-text);
17
+ color: var(--_cinder-chart-foreground, currentColor);
18
+ background: var(--_cinder-chart-background, transparent);
18
19
  }
19
20
 
20
21
  .cinder-statistic[data-cinder-has-icon] {
@@ -29,12 +30,12 @@
29
30
  display: inline-flex;
30
31
  align-items: center;
31
32
  justify-content: center;
32
- color: var(--cinder-text-muted);
33
+ color: var(--_cinder-chart-muted, currentColor);
33
34
  }
34
35
 
35
36
  .cinder-statistic__label {
36
37
  font-size: var(--cinder-statistic-label-font-size, var(--cinder-text-sm));
37
- color: var(--cinder-text-muted);
38
+ color: var(--_cinder-chart-muted, currentColor);
38
39
  }
39
40
 
40
41
  .cinder-statistic[data-cinder-has-icon] .cinder-statistic__label {
@@ -72,10 +73,10 @@
72
73
  }
73
74
 
74
75
  .cinder-statistic__change[data-cinder-direction='neutral'] {
75
- color: var(--cinder-text-muted);
76
+ color: var(--_cinder-chart-muted, currentColor);
76
77
  }
77
78
 
78
79
  .cinder-statistic__change-description {
79
- color: var(--cinder-text-muted);
80
+ color: var(--_cinder-chart-muted, currentColor);
80
81
  }
81
82
  }
@@ -17,6 +17,31 @@
17
17
  ],
18
18
  "description": "The statistic. Strings rendered verbatim; numbers formatted via formatNumber."
19
19
  },
20
+ "theme": {
21
+ "type": "object",
22
+ "properties": {
23
+ "foreground": {
24
+ "type": "string"
25
+ },
26
+ "muted": {
27
+ "type": "string"
28
+ },
29
+ "grid": {
30
+ "type": "string"
31
+ },
32
+ "background": {
33
+ "type": "string"
34
+ },
35
+ "palette": {
36
+ "type": "array",
37
+ "items": {
38
+ "type": "string"
39
+ }
40
+ }
41
+ },
42
+ "additionalProperties": false,
43
+ "description": "Partial visual theme override. Omitted fields inherit the surrounding application."
44
+ },
20
45
  "valueLocale": {
21
46
  "type": "string",
22
47
  "description": "Locale forwarded to formatNumber. Defaults to the nearest LocaleProvider locale, then en-US."
@@ -19,6 +19,32 @@ const schema = {
19
19
  ],
20
20
  description: 'The statistic. Strings rendered verbatim; numbers formatted via formatNumber.',
21
21
  },
22
+ theme: {
23
+ type: 'object',
24
+ properties: {
25
+ foreground: {
26
+ type: 'string',
27
+ },
28
+ muted: {
29
+ type: 'string',
30
+ },
31
+ grid: {
32
+ type: 'string',
33
+ },
34
+ background: {
35
+ type: 'string',
36
+ },
37
+ palette: {
38
+ type: 'array',
39
+ items: {
40
+ type: 'string',
41
+ },
42
+ },
43
+ },
44
+ additionalProperties: false,
45
+ description:
46
+ 'Partial visual theme override. Omitted fields inherit the surrounding application.',
47
+ },
22
48
  valueLocale: {
23
49
  type: 'string',
24
50
  description:
@@ -3,6 +3,7 @@ export {};
3
3
  </script>
4
4
 
5
5
  <script lang="ts">
6
+ import { resolveChartTheme } from '../../_internal/chart/chart-utilities.ts';
6
7
  import { getLocaleContext } from '../../_internal/locale-context.ts';
7
8
  import { classNames } from '../../utilities/class-names.ts';
8
9
  import { formatNumber } from '../../utilities/format-number.ts';
@@ -10,7 +11,7 @@ import { formatNumber } from '../../utilities/format-number.ts';
10
11
  // instance. Pass an explicit `id` prop to control the base when a specific value
11
12
  // is required (e.g. for testing or when a stable server-rendered id is needed).
12
13
  const generatedId = $props.id();
13
- let { label, value, change, icon, valueFormatOptions, valueLocale, class: customClassName, id, ...rest } = $props();
14
+ let { label, value, change, icon, theme, valueFormatOptions, valueLocale, class: customClassName, id, ...rest } = $props();
14
15
  const localeContext = getLocaleContext();
15
16
  const stableId = $derived(id ?? generatedId);
16
17
  const labelId = $derived(`${stableId}-label`);
@@ -31,6 +32,43 @@ const changeAccessibleText = $derived.by(() => {
31
32
  return `decreased by ${change.value}${suffix}`;
32
33
  return `no change, ${change.value}${suffix}`;
33
34
  });
35
+ /**
36
+ * Statistic is page text, not chart glyphs, so it cannot take
37
+ * `resolveChartTheme`'s unthemed defaults as-is: that returns
38
+ * `currentColor` for `foreground` and `muted`, and this component writes
39
+ * both as INLINE custom properties, so the `var(--_cinder-chart-*, …)`
40
+ * fallbacks in `statistic.css` can never apply. An unthemed Statistic
41
+ * therefore painted its label, icon, and change description at full text
42
+ * colour — visually identical to the value, with the muted hierarchy gone.
43
+ *
44
+ * The chart components absorb the same `currentColor` default with a
45
+ * compensating `opacity` on their tick labels; that is the wrong tool for
46
+ * text, which has to clear the 4.5:1 AA floor rather than land wherever a
47
+ * multiplier puts it.
48
+ *
49
+ * So the substitution is all-or-nothing on `theme`'s presence, NOT
50
+ * per-field: with no theme at all, both colours come from the
51
+ * contrast-tuned text tokens (restoring the pre-#1248 hierarchy); with any
52
+ * theme, `resolveChartTheme` is used untouched so omitted fields still
53
+ * inherit `currentColor` as the partial-theme contract documents. A
54
+ * per-field fallback would put the app's `--cinder-text-muted` on a caller's
55
+ * custom dark panel. A surface that colours its own text through an
56
+ * ancestor and wants the Statistic to follow can say so explicitly with
57
+ * `theme={{ foreground: 'currentColor', muted: 'currentColor' }}`.
58
+ */
59
+ const resolvedTheme = $derived(theme
60
+ ? // A supplied theme — even a partial one — keeps `resolveChartTheme`'s
61
+ // `currentColor` inheritance for the fields it omits, per the documented
62
+ // partial-theme contract. Substituting the global text tokens here would
63
+ // break exactly the case the contract exists for: a caller passing
64
+ // `{ foreground: 'white', background: 'black' }` for a dark panel would
65
+ // get the app's dark `--cinder-text-muted` label on that black surface.
66
+ resolveChartTheme(theme)
67
+ : {
68
+ ...resolveChartTheme(undefined),
69
+ foreground: 'var(--cinder-text)',
70
+ muted: 'var(--cinder-text-muted)',
71
+ });
34
72
  </script>
35
73
 
36
74
  <div
@@ -40,6 +78,9 @@ const changeAccessibleText = $derived.by(() => {
40
78
  role="group"
41
79
  aria-labelledby={`${labelId} ${valueId}`}
42
80
  data-cinder-has-icon={icon ? '' : undefined}
81
+ style:--_cinder-chart-foreground={resolvedTheme.foreground}
82
+ style:--_cinder-chart-muted={resolvedTheme.muted}
83
+ style:--_cinder-chart-background={resolvedTheme.background}
43
84
  >
44
85
  {#if icon}
45
86
  <span class="cinder-statistic__icon" aria-hidden="true">{@render icon()}</span>
@@ -1,5 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
+ import type { ChartTheme, ChartThemeSchema } from '../chart.types.ts';
3
4
  /** Direction of a stat change indicator. */
4
5
  export type StatisticChangeDirection = 'up' | 'down' | 'neutral';
5
6
  /** Data for the optional change indicator rendered below the stat value. */
@@ -24,6 +25,8 @@ export type StatisticProps = Omit<HTMLAttributes<HTMLDivElement>, 'class'> & {
24
25
  value: string | number;
25
26
  /** Optional change indicator with direction and accessible wording. */
26
27
  change?: StatisticChange;
28
+ /** Partial visual theme override. Omitted fields inherit the surrounding application. */
29
+ theme?: ChartTheme;
27
30
  /** Optional leading icon snippet (decorative — wrapper is aria-hidden). */
28
31
  icon?: Snippet;
29
32
  /** Intl.NumberFormat options applied only when `value` is a number. */
@@ -42,6 +45,8 @@ export interface StatisticSchemaProps {
42
45
  value: string | number;
43
46
  /** Optional change indicator with direction and accessible wording. */
44
47
  change?: StatisticChange;
48
+ /** Partial visual theme override. Omitted fields inherit the surrounding application. */
49
+ theme?: ChartThemeSchema;
45
50
  /** Optional leading icon snippet (decorative — wrapper is aria-hidden). */
46
51
  icon?: Snippet;
47
52
  /** Intl.NumberFormat options applied only when `value` is a number. */
@@ -3,12 +3,13 @@
3
3
  .cinder-waveform {
4
4
  display: grid;
5
5
  gap: var(--cinder-space-2);
6
- color: var(--cinder-text);
6
+ color: var(--_cinder-chart-foreground, currentColor);
7
+ background: var(--_cinder-chart-background, transparent);
7
8
  }
8
9
 
9
10
  .cinder-waveform__description {
10
11
  margin: 0;
11
- color: var(--cinder-text-muted);
12
+ color: var(--_cinder-chart-muted, currentColor);
12
13
  font-size: var(--cinder-text-sm);
13
14
  }
14
15
 
@@ -23,13 +24,13 @@
23
24
  }
24
25
 
25
26
  .cinder-waveform__baseline {
26
- stroke: var(--cinder-border-muted);
27
+ stroke: var(--_cinder-chart-grid, currentColor);
27
28
  stroke-width: 1;
28
29
  }
29
30
 
30
31
  .cinder-waveform__path {
31
32
  fill: none;
32
- stroke: var(--cinder-chart-series-1);
33
+ stroke: var(--_cinder-chart-series-color, currentColor);
33
34
  stroke-width: 1.5;
34
35
  stroke-linecap: round;
35
36
  stroke-linejoin: round;
@@ -37,7 +38,7 @@
37
38
  }
38
39
 
39
40
  .cinder-waveform__bar {
40
- fill: var(--cinder-chart-series-1);
41
+ fill: var(--_cinder-chart-series-color, currentColor);
41
42
  rx: 1;
42
43
  }
43
44
 
@@ -46,8 +47,8 @@
46
47
  inset: 0;
47
48
  display: grid;
48
49
  place-items: center;
49
- color: var(--cinder-text-muted);
50
- background: color-mix(in oklch, var(--cinder-surface) 88%, transparent);
50
+ color: var(--_cinder-chart-muted, currentColor);
51
+ background: var(--_cinder-chart-background, transparent);
51
52
  z-index: 1;
52
53
  }
53
54
  }
@@ -37,6 +37,31 @@
37
37
  "type": "string",
38
38
  "description": "Custom data table caption; falls back to `label`."
39
39
  },
40
+ "theme": {
41
+ "type": "object",
42
+ "properties": {
43
+ "foreground": {
44
+ "type": "string"
45
+ },
46
+ "muted": {
47
+ "type": "string"
48
+ },
49
+ "grid": {
50
+ "type": "string"
51
+ },
52
+ "background": {
53
+ "type": "string"
54
+ },
55
+ "palette": {
56
+ "type": "array",
57
+ "items": {
58
+ "type": "string"
59
+ }
60
+ }
61
+ },
62
+ "additionalProperties": false,
63
+ "description": "Partial visual theme override. Omitted fields inherit the surrounding application."
64
+ },
40
65
  "class": {
41
66
  "type": "string",
42
67
  "description": "Custom class applied to the root element."
@@ -41,6 +41,32 @@ const schema = {
41
41
  type: 'string',
42
42
  description: 'Custom data table caption; falls back to `label`.',
43
43
  },
44
+ theme: {
45
+ type: 'object',
46
+ properties: {
47
+ foreground: {
48
+ type: 'string',
49
+ },
50
+ muted: {
51
+ type: 'string',
52
+ },
53
+ grid: {
54
+ type: 'string',
55
+ },
56
+ background: {
57
+ type: 'string',
58
+ },
59
+ palette: {
60
+ type: 'array',
61
+ items: {
62
+ type: 'string',
63
+ },
64
+ },
65
+ },
66
+ additionalProperties: false,
67
+ description:
68
+ 'Partial visual theme override. Omitted fields inherit the surrounding application.',
69
+ },
44
70
  class: {
45
71
  type: 'string',
46
72
  description: 'Custom class applied to the root element.',
@@ -3,13 +3,14 @@ export {};
3
3
  </script>
4
4
 
5
5
  <script lang="ts">
6
- import { dataTableClass } from '../../_internal/chart/chart-utilities.ts';
6
+ import { chartPaletteColor, dataTableClass, resolveChartTheme, } from '../../_internal/chart/chart-utilities.ts';
7
7
  import { classNames } from '../../utilities/class-names.ts';
8
8
  import { useResizeObserver } from '../../utilities/use-resize-observer.svelte.ts';
9
- let { label, description, data, renderMode = 'path', height = 80, loading = false, dataTableVisibility = 'screen-reader-only', dataTableCaption, class: customClassName, empty, loadingContent, id, ...rest } = $props();
9
+ let { label, description, data, renderMode = 'path', height = 80, loading = false, dataTableVisibility = 'screen-reader-only', dataTableCaption, theme, class: customClassName, empty, loadingContent, id, ...rest } = $props();
10
10
  const generatedId = $props.id();
11
11
  const rootId = $derived(id ?? generatedId);
12
12
  const descriptionId = $derived(description ? `${rootId}-description` : undefined);
13
+ const resolvedTheme = $derived(resolveChartTheme(theme));
13
14
  let measuredWidth = $state(400);
14
15
  const observeResize = useResizeObserver((entries) => {
15
16
  const entry = entries[0];
@@ -159,6 +160,11 @@ const tableCaption = $derived.by(() => {
159
160
  aria-label={label}
160
161
  aria-describedby={descriptionId}
161
162
  data-cinder-render-mode={renderMode}
163
+ style:--_cinder-chart-foreground={resolvedTheme.foreground}
164
+ style:--_cinder-chart-muted={resolvedTheme.muted}
165
+ style:--_cinder-chart-grid={resolvedTheme.grid}
166
+ style:--_cinder-chart-background={resolvedTheme.background}
167
+ style:--_cinder-chart-series-color={chartPaletteColor(0, resolvedTheme.palette)}
162
168
  >
163
169
  {#if description}
164
170
  <p id={descriptionId} class="cinder-waveform__description">{description}</p>
@@ -194,6 +200,7 @@ const tableCaption = $derived.by(() => {
194
200
  x2={measuredWidth}
195
201
  y1={midY}
196
202
  y2={midY}
203
+ stroke={resolvedTheme.grid}
197
204
  aria-hidden="true"
198
205
  />
199
206
  {#if renderMode === 'bars'}
@@ -204,11 +211,17 @@ const tableCaption = $derived.by(() => {
204
211
  y={bar.y}
205
212
  width={bar.width}
206
213
  height={bar.height}
214
+ fill={chartPaletteColor(0, resolvedTheme.palette)}
207
215
  aria-hidden="true"
208
216
  />
209
217
  {/each}
210
218
  {:else}
211
- <path class="cinder-waveform__path" d={waveformPath} aria-hidden="true" />
219
+ <path
220
+ class="cinder-waveform__path"
221
+ d={waveformPath}
222
+ stroke={chartPaletteColor(0, resolvedTheme.palette)}
223
+ aria-hidden="true"
224
+ />
212
225
  {/if}
213
226
  {/if}
214
227
  </svg>
@@ -1,6 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
- import type { ChartDataTableVisibility } from '../chart.types.ts';
3
+ import type { ChartDataTableVisibility, ChartTheme, ChartThemeSchema } from '../chart.types.ts';
4
4
 
5
5
  export type WaveformRenderMode = 'path' | 'bars';
6
6
 
@@ -24,6 +24,8 @@ export type WaveformProps = Omit<HTMLAttributes<HTMLElement>, 'class'> & {
24
24
  dataTableVisibility?: ChartDataTableVisibility;
25
25
  /** Custom data table caption; falls back to `label`. */
26
26
  dataTableCaption?: string;
27
+ /** Partial visual theme override. Omitted fields inherit the surrounding application. */
28
+ theme?: ChartTheme;
27
29
  /** Custom class applied to the root element. */
28
30
  class?: string;
29
31
  /** Snippet rendered when the chart has no data. */
@@ -49,6 +51,8 @@ export type WaveformSchemaProps = {
49
51
  dataTableVisibility?: ChartDataTableVisibility;
50
52
  /** Custom data table caption; falls back to `label`. */
51
53
  dataTableCaption?: string;
54
+ /** Partial visual theme override. Omitted fields inherit the surrounding application. */
55
+ theme?: ChartThemeSchema;
52
56
  /** Custom class applied to the root element. */
53
57
  class?: string;
54
58
  };
package/src/index.ts CHANGED
@@ -95,6 +95,7 @@ export type {
95
95
  BarChartDatum,
96
96
  BarChartMode,
97
97
  BarChartOrientation,
98
+ BarChartPlacedBar,
98
99
  BarChartSchemaDatum,
99
100
  BarChartSchemaSeries,
100
101
  BarChartSeries,
@@ -104,16 +105,23 @@ export type {
104
105
  ChartCartesianSeries,
105
106
  ChartDataTableVisibility,
106
107
  ChartFormatterContext,
108
+ ChartGeometry,
107
109
  ChartJsonValue,
108
110
  ChartJsonXValue,
109
111
  ChartLegendPosition,
112
+ ChartMarkContext,
110
113
  ChartNumericValue,
111
114
  ChartPoint,
112
115
  ChartSchemaPoint,
113
116
  ChartSharedProps,
117
+ ChartTarget,
118
+ ChartTheme,
114
119
  ChartTickFormatter,
115
120
  ChartValueFormatter,
121
+ ChartXAxisConfiguration,
116
122
  ChartXValue,
123
+ NormalizedXValue,
124
+ PlacedPoint,
117
125
  } from './components/chart.types.ts';
118
126
 
119
127
  export { default as BentoCell } from './components/bento-cell/index.ts';