@lostgradient/cinder 0.22.0 → 0.23.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.
Files changed (164) hide show
  1. package/CHANGELOG.md +31 -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 +1284 -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 +1284 -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 +17730 -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-93943z3e.js → index.server-151dt1tx.js} +1 -1
  78. package/dist/server/{index.server-pp2n6def.js → index.server-2y0xz53g.js} +37 -14
  79. package/dist/server/{index.server-bd8rcgf0.js → index.server-4hvjet4z.js} +1 -1
  80. package/dist/server/{index.server-bsm39gpy.js → index.server-5d83fkyg.js} +75 -21
  81. package/dist/server/{index.server-4wweyb2e.js → index.server-8dh2rtnc.js} +1 -1
  82. package/dist/server/{index.server-abqbstkt.js → index.server-9gj583qs.js} +41 -14
  83. package/dist/server/{index.server-2nmwsacy.js → index.server-9scm7zf9.js} +4 -4
  84. package/dist/server/{index.server-5j6jv7rm.js → index.server-9vwxyy06.js} +108 -29
  85. package/dist/server/{index.server-abjsjsw8.js → index.server-afpjvfz1.js} +111 -35
  86. package/dist/server/{index.server-86sw5ea6.js → index.server-dw9bz17h.js} +4 -4
  87. package/dist/server/{index.server-d26jzn2m.js → index.server-en31rprd.js} +3 -3
  88. package/dist/server/{index.server-dx58qant.js → index.server-f3a0ecqg.js} +72 -9
  89. package/dist/server/{index.server-d63pwytk.js → index.server-kz8aeeq5.js} +18 -10
  90. package/dist/server/index.server-mmmrgvyd.js +1274 -0
  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-wm8957be.js → index.server-veqke4sq.js} +10 -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 +6 -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
@@ -3,20 +3,26 @@ export {};
3
3
  </script>
4
4
 
5
5
  <script lang="ts">
6
- import { dataTableClass } from '../../_internal/chart/chart-utilities.ts';
6
+ import { onMount } from 'svelte';
7
+ import { createChartGeometry, dataTableClass, observeChartFontLoading, resolveChartTheme, } from '../../_internal/chart/chart-utilities.ts';
7
8
  import ChartDataTable from '../_internal/chart-data-table.svelte';
8
9
  import { heatmapCellFill, heatmapDomain, heatmapLabelFill, toFiniteOrNull, } from '../../_internal/chart/heatmap-utilities.ts';
9
10
  import { classNames } from '../../utilities/class-names.ts';
10
11
  import { useResizeObserver } from '../../utilities/use-resize-observer.svelte.ts';
11
- let { label, description, data, xField, yField, valueField, colorScale = 'sequential', cellLabelsVisible = true, height = 280, loading = false, dataTableCaption, dataTableVisibility = 'screen-reader-only', class: customClassName, empty, loadingContent, id, ...rest } = $props();
12
+ let { label, description, data, xField, yField, valueField, colorScale = 'sequential', cellLabelsVisible = true, height = 280, loading = false, dataTableCaption, dataTableVisibility = 'screen-reader-only', theme, class: customClassName, empty, loadingContent, id, ...rest } = $props();
12
13
  const generatedId = $props.id();
13
14
  const rootId = $derived(id ?? generatedId);
14
15
  const descriptionId = $derived(description ? `${rootId}-description` : undefined);
15
- // Geometry constants
16
- const marginTop = 40;
17
- const marginRight = 16;
18
- const marginBottom = 16;
19
- const marginLeft = 80;
16
+ const resolvedTheme = $derived(resolveChartTheme(theme));
17
+ let rootElement = $state();
18
+ let measureText = $state(false);
19
+ let measurementVersion = $state(0);
20
+ onMount(() => {
21
+ measureText = true;
22
+ return observeChartFontLoading(() => {
23
+ measurementVersion += 1;
24
+ });
25
+ });
20
26
  let measuredWidth = $state(400);
21
27
  const observeResize = useResizeObserver((entries) => {
22
28
  const entry = entries[0];
@@ -25,8 +31,6 @@ const observeResize = useResizeObserver((entries) => {
25
31
  if (entry && entry.contentRect.width > 0)
26
32
  measuredWidth = entry.contentRect.width;
27
33
  });
28
- const plotWidth = $derived(Math.max(1, measuredWidth - marginLeft - marginRight));
29
- const plotHeight = $derived(Math.max(1, height - marginTop - marginBottom));
30
34
  // Collect unique x and y labels in insertion order
31
35
  const xLabels = $derived.by(() => {
32
36
  const seen = new Set();
@@ -58,6 +62,15 @@ const yLabels = $derived.by(() => {
58
62
  }
59
63
  return result;
60
64
  });
65
+ const geometry = $derived(createChartGeometry(measuredWidth, height, {
66
+ xTickLabels: xLabels,
67
+ yTickLabels: yLabels,
68
+ xTickPosition: 'top',
69
+ measureText,
70
+ measurementElement: rootElement,
71
+ measurementVersion,
72
+ }));
73
+ const { plotWidth, plotHeight, marginTop, marginLeft } = $derived(geometry);
61
74
  const isEmpty = $derived(xLabels.length === 0 || yLabels.length === 0);
62
75
  // Cell pixel dimensions
63
76
  const cellWidth = $derived(xLabels.length > 0 ? plotWidth / xLabels.length : 0);
@@ -111,7 +124,7 @@ const cells = $derived.by(() => {
111
124
  // zero-centred inside the utility so 0 always maps to the neutral midpoint.
112
125
  const domain = $derived(heatmapDomain(cells.map((cell) => cell.value)));
113
126
  function cellFill(value) {
114
- return heatmapCellFill(value, domain, colorScale);
127
+ return heatmapCellFill(value, domain, colorScale, resolvedTheme.palette, theme?.background ?? 'var(--cinder-surface-inset)');
115
128
  }
116
129
  // Hoisted so a dense grid's ~3x(rows*cols) formatting calls (tooltip
117
130
  // title, visible label, and data-table fallback per cell) reuse one
@@ -123,7 +136,7 @@ function formatValue(value) {
123
136
  return numberFormatter.format(value);
124
137
  }
125
138
  function cellLabelFill(value) {
126
- return heatmapLabelFill(value, domain, colorScale);
139
+ return heatmapLabelFill(value, resolvedTheme.muted);
127
140
  }
128
141
  const hasDataTable = $derived(dataTableVisibility !== 'hidden');
129
142
  // Pointer hover tracking: the key of the cell under the pointer, or null.
@@ -149,8 +162,13 @@ const tableRows = $derived.by(() => {
149
162
  <figure
150
163
  {...rest}
151
164
  {@attach observeResize}
165
+ bind:this={rootElement}
152
166
  id={rootId}
153
167
  class={classNames('cinder-matrix-chart', customClassName)}
168
+ style:--_cinder-chart-foreground={resolvedTheme.foreground}
169
+ style:--_cinder-chart-muted={resolvedTheme.muted}
170
+ style:--_cinder-chart-grid={resolvedTheme.grid}
171
+ style:--_cinder-chart-background={resolvedTheme.background}
154
172
  aria-label={label}
155
173
  aria-describedby={descriptionId}
156
174
  data-cinder-color-scale={colorScale}
@@ -215,7 +233,7 @@ const tableRows = $derived.by(() => {
215
233
  {/each}
216
234
  <!-- Matrix cells -->
217
235
  {#each cells as cell (cell.key)}
218
- <g>
236
+ <g class="cinder-matrix-chart__cell-group">
219
237
  <rect
220
238
  class="cinder-matrix-chart__cell"
221
239
  x={cell.x}
@@ -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 MatrixColorScale = 'sequential' | 'diverging';
6
6
 
@@ -31,6 +31,8 @@ export type MatrixChartProps = Omit<HTMLAttributes<HTMLElement>, 'class'> & {
31
31
  dataTableCaption?: string;
32
32
  /** Controls data table visibility. Default `screen-reader-only`. */
33
33
  dataTableVisibility?: ChartDataTableVisibility;
34
+ /** Partial visual theme override. */
35
+ theme?: ChartTheme;
34
36
  /** Custom class applied to the root element. */
35
37
  class?: string;
36
38
  /** Snippet rendered when the chart has no data. */
@@ -64,6 +66,8 @@ export type MatrixChartSchemaProps = {
64
66
  dataTableCaption?: string;
65
67
  /** Controls data table visibility. Default `screen-reader-only`. @default "screen-reader-only" */
66
68
  dataTableVisibility?: ChartDataTableVisibility;
69
+ /** Partial visual theme override. */
70
+ theme?: ChartThemeSchema;
67
71
  /** Custom class applied to the root element. */
68
72
  class?: string;
69
73
  };
@@ -349,10 +349,10 @@ function createStepSelectionAttachment(stepPathKey) {
349
349
  </Badge>
350
350
  {/if}
351
351
  {#if step.attemptCount !== undefined && step.attemptCount > 1}
352
- <Badge variant="neutral" size="xs" monochrome>attempt {step.attemptCount}</Badge>
352
+ <Badge variant="neutral" size="xs" monospace>attempt {step.attemptCount}</Badge>
353
353
  {/if}
354
354
  {#if step.actionsCount !== undefined && step.actionsCount > 0}
355
- <Badge variant="neutral" size="xs" monochrome
355
+ <Badge variant="neutral" size="xs" monospace
356
356
  >{actionsCountLabel(step.actionsCount)}</Badge
357
357
  >
358
358
  {/if}
@@ -5,7 +5,8 @@
5
5
  gap: 0.375rem;
6
6
  min-inline-size: 0;
7
7
  inline-size: 100%;
8
- color: var(--cinder-text);
8
+ color: var(--_cinder-chart-foreground, currentColor);
9
+ background: var(--_cinder-chart-background, transparent);
9
10
  }
10
11
 
11
12
  .cinder-sparkbar__row {
@@ -26,7 +27,7 @@
26
27
 
27
28
  .cinder-sparkbar__trailing {
28
29
  flex: none;
29
- color: var(--cinder-text-muted);
30
+ color: var(--_cinder-chart-muted, currentColor);
30
31
  font-variant-numeric: tabular-nums;
31
32
  }
32
33
 
@@ -35,7 +36,7 @@
35
36
  overflow: hidden;
36
37
  inline-size: 100%;
37
38
  border-radius: var(--cinder-radius-full);
38
- background: var(--cinder-surface-inset);
39
+ background: var(--_cinder-sparkbar-track-background, var(--cinder-surface-inset));
39
40
  isolation: isolate;
40
41
  }
41
42
 
@@ -45,7 +46,7 @@
45
46
  inset-inline-start: 0;
46
47
  inline-size: 100%;
47
48
  border-radius: inherit;
48
- background: var(--cinder-accent);
49
+ background: var(--_cinder-chart-accent, currentColor);
49
50
  transform: scaleX(var(--_cinder-sparkbar-progress, 0));
50
51
  transform-origin: center left;
51
52
  transition: transform var(--cinder-duration-moderate) var(--cinder-ease-in-out);
@@ -26,6 +26,31 @@
26
26
  "enum": ["accent", "success", "warning"],
27
27
  "description": "Fill color intent. Default `accent`."
28
28
  },
29
+ "theme": {
30
+ "type": "object",
31
+ "properties": {
32
+ "foreground": {
33
+ "type": "string"
34
+ },
35
+ "muted": {
36
+ "type": "string"
37
+ },
38
+ "grid": {
39
+ "type": "string"
40
+ },
41
+ "background": {
42
+ "type": "string"
43
+ },
44
+ "palette": {
45
+ "type": "array",
46
+ "items": {
47
+ "type": "string"
48
+ }
49
+ }
50
+ },
51
+ "additionalProperties": false,
52
+ "description": "Partial visual theme override. Omitted fields inherit the surrounding application."
53
+ },
29
54
  "ariaLabel": {
30
55
  "type": "string",
31
56
  "description": "Accessible name override. Defaults to `${label}, ${percentage}%`."
@@ -28,6 +28,32 @@ const schema = {
28
28
  enum: ['accent', 'success', 'warning'],
29
29
  description: 'Fill color intent. Default `accent`.',
30
30
  },
31
+ theme: {
32
+ type: 'object',
33
+ properties: {
34
+ foreground: {
35
+ type: 'string',
36
+ },
37
+ muted: {
38
+ type: 'string',
39
+ },
40
+ grid: {
41
+ type: 'string',
42
+ },
43
+ background: {
44
+ type: 'string',
45
+ },
46
+ palette: {
47
+ type: 'array',
48
+ items: {
49
+ type: 'string',
50
+ },
51
+ },
52
+ },
53
+ additionalProperties: false,
54
+ description:
55
+ 'Partial visual theme override. Omitted fields inherit the surrounding application.',
56
+ },
31
57
  ariaLabel: {
32
58
  type: 'string',
33
59
  description: 'Accessible name override. Defaults to `${label}, ${percentage}%`.',
@@ -3,8 +3,9 @@ export {};
3
3
  </script>
4
4
 
5
5
  <script lang="ts">
6
+ import { chartPaletteColor, resolveChartTheme } from '../../_internal/chart/chart-utilities.ts';
6
7
  import { classNames } from '../../utilities/class-names.ts';
7
- let { value, max = 1, label, trailing, size = 'md', variant = 'accent', ariaLabel, ariaValueText, class: customClassName, ...rest } = $props();
8
+ let { value, max = 1, label, trailing, size = 'md', variant = 'accent', theme, ariaLabel, ariaValueText, class: customClassName, ...rest } = $props();
8
9
  const effectiveMax = $derived(Number.isFinite(max) && max > 0 ? max : 1);
9
10
  const clampedValue = $derived(Number.isFinite(value) ? Math.max(0, Math.min(effectiveMax, value)) : 0);
10
11
  const percent = $derived(Math.round((clampedValue / effectiveMax) * 100));
@@ -13,6 +14,7 @@ const normalizedTrailing = $derived(trailing?.trim() || undefined);
13
14
  const normalizedAriaValueText = $derived(ariaValueText?.trim() || undefined);
14
15
  const accessibleName = $derived(normalizedAriaLabel ?? `${label}, ${percent}%`);
15
16
  const accessibleValueText = $derived(normalizedAriaValueText ?? normalizedTrailing);
17
+ const resolvedTheme = $derived(resolveChartTheme(theme));
16
18
  </script>
17
19
 
18
20
  <div
@@ -26,6 +28,11 @@ const accessibleValueText = $derived(normalizedAriaValueText ?? normalizedTraili
26
28
  aria-valuetext={accessibleValueText}
27
29
  data-cinder-size={size}
28
30
  data-cinder-variant={variant}
31
+ style:--_cinder-chart-foreground={resolvedTheme.foreground}
32
+ style:--_cinder-chart-muted={resolvedTheme.muted}
33
+ style:--_cinder-chart-background={resolvedTheme.background}
34
+ style:--_cinder-chart-accent={chartPaletteColor(0, resolvedTheme.palette)}
35
+ style:--_cinder-sparkbar-track-background={theme?.background ?? 'var(--cinder-surface-inset)'}
29
36
  >
30
37
  <div class="cinder-sparkbar__row">
31
38
  <span class="cinder-sparkbar__label">{label}</span>
@@ -1,4 +1,5 @@
1
1
  import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { ChartTheme, ChartThemeSchema } from '../chart.types.ts';
2
3
 
3
4
  export type SparkbarSize = 'sm' | 'md' | 'lg';
4
5
  export type SparkbarVariant = 'accent' | 'success' | 'warning';
@@ -17,6 +18,8 @@ export type SparkbarProps = HTMLAttributes<HTMLDivElement> & {
17
18
  size?: SparkbarSize;
18
19
  /** Fill color intent. Default `accent`. */
19
20
  variant?: SparkbarVariant;
21
+ /** Partial visual theme override. Omitted fields inherit the surrounding application. */
22
+ theme?: ChartTheme;
20
23
  /** Accessible name override. Defaults to `${label}, ${percentage}%`. */
21
24
  ariaLabel?: string;
22
25
  /** Accessible value text override. Defaults to the trimmed trailing value when provided. */
@@ -39,6 +42,8 @@ export type SparkbarSchemaProps = {
39
42
  size?: SparkbarSize;
40
43
  /** Fill color intent. Default `accent`. */
41
44
  variant?: SparkbarVariant;
45
+ /** Partial visual theme override. Omitted fields inherit the surrounding application. */
46
+ theme?: ChartThemeSchema;
42
47
  /** Accessible name override. Defaults to `${label}, ${percentage}%`. */
43
48
  ariaLabel?: string;
44
49
  /** Accessible value text override. Defaults to the trimmed trailing value when provided. */
@@ -3,12 +3,13 @@
3
3
  .cinder-spectrogram {
4
4
  display: grid;
5
5
  gap: var(--cinder-space-3);
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-spectrogram__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,12 +24,12 @@
23
24
  }
24
25
 
25
26
  .cinder-spectrogram__cell {
26
- stroke: color-mix(in oklch, var(--cinder-text), transparent 88%);
27
+ stroke: color-mix(in oklch, var(--_cinder-chart-grid, currentColor), transparent 88%);
27
28
  stroke-width: 0.5;
28
29
  }
29
30
 
30
31
  .cinder-spectrogram__tick-label {
31
- fill: var(--cinder-text-muted);
32
+ fill: var(--_cinder-chart-muted, currentColor);
32
33
  font-size: var(--cinder-text-xs);
33
34
  }
34
35
 
@@ -37,8 +38,8 @@
37
38
  inset: 0;
38
39
  display: grid;
39
40
  place-items: center;
40
- color: var(--cinder-text-muted);
41
- background: color-mix(in oklch, var(--cinder-surface) 88%, transparent);
41
+ color: var(--_cinder-chart-muted, currentColor);
42
+ background: var(--_cinder-chart-background, transparent);
42
43
  z-index: 1;
43
44
  }
44
45
  }
@@ -51,6 +51,31 @@
51
51
  "enum": ["screen-reader-only", "visible", "hidden"],
52
52
  "description": "Controls data table visibility. Default `screen-reader-only`."
53
53
  },
54
+ "theme": {
55
+ "type": "object",
56
+ "properties": {
57
+ "foreground": {
58
+ "type": "string"
59
+ },
60
+ "muted": {
61
+ "type": "string"
62
+ },
63
+ "grid": {
64
+ "type": "string"
65
+ },
66
+ "background": {
67
+ "type": "string"
68
+ },
69
+ "palette": {
70
+ "type": "array",
71
+ "items": {
72
+ "type": "string"
73
+ }
74
+ }
75
+ },
76
+ "additionalProperties": false,
77
+ "description": "Partial visual theme override."
78
+ },
54
79
  "dataTableCaption": {
55
80
  "type": "string",
56
81
  "description": "Custom data table caption; falls back to `label`."
@@ -56,6 +56,31 @@ const schema = {
56
56
  enum: ['screen-reader-only', 'visible', 'hidden'],
57
57
  description: 'Controls data table visibility. Default `screen-reader-only`.',
58
58
  },
59
+ theme: {
60
+ type: 'object',
61
+ properties: {
62
+ foreground: {
63
+ type: 'string',
64
+ },
65
+ muted: {
66
+ type: 'string',
67
+ },
68
+ grid: {
69
+ type: 'string',
70
+ },
71
+ background: {
72
+ type: 'string',
73
+ },
74
+ palette: {
75
+ type: 'array',
76
+ items: {
77
+ type: 'string',
78
+ },
79
+ },
80
+ },
81
+ additionalProperties: false,
82
+ description: 'Partial visual theme override.',
83
+ },
59
84
  dataTableCaption: {
60
85
  type: 'string',
61
86
  description: 'Custom data table caption; falls back to `label`.',
@@ -3,18 +3,25 @@ export {};
3
3
  </script>
4
4
 
5
5
  <script lang="ts">
6
- import { dataTableClass } from '../../_internal/chart/chart-utilities.ts';
6
+ import { onMount } from 'svelte';
7
+ import { createChartGeometry, dataTableClass, observeChartFontLoading, resolveChartTheme, } from '../../_internal/chart/chart-utilities.ts';
7
8
  import { heatmapCellFill, heatmapDomainOfRows, toFiniteOrNull, } from '../../_internal/chart/heatmap-utilities.ts';
8
9
  import { classNames } from '../../utilities/class-names.ts';
9
10
  import { useResizeObserver } from '../../utilities/use-resize-observer.svelte.ts';
10
- let { label, description, frames, frequencyLabels, height = 200, loading = false, dataTableVisibility = 'screen-reader-only', dataTableCaption, class: customClassName, empty, loadingContent, id, ...rest } = $props();
11
+ let { label, description, frames, frequencyLabels, height = 200, loading = false, dataTableVisibility = 'screen-reader-only', theme, dataTableCaption, class: customClassName, empty, loadingContent, id, ...rest } = $props();
11
12
  const generatedId = $props.id();
12
13
  const rootId = $derived(id ?? generatedId);
13
14
  const descriptionId = $derived(description ? `${rootId}-description` : undefined);
14
- const marginTop = 8;
15
- const marginRight = 16;
16
- const marginBottom = 32;
17
- const marginLeft = 60;
15
+ const resolvedTheme = $derived(resolveChartTheme(theme));
16
+ let rootElement = $state();
17
+ let measureText = $state(false);
18
+ let measurementVersion = $state(0);
19
+ onMount(() => {
20
+ measureText = true;
21
+ return observeChartFontLoading(() => {
22
+ measurementVersion += 1;
23
+ });
24
+ });
18
25
  let measuredWidth = $state(400);
19
26
  const observeResize = useResizeObserver((entries) => {
20
27
  const entry = entries[0];
@@ -23,33 +30,42 @@ const observeResize = useResizeObserver((entries) => {
23
30
  if (entry && entry.contentRect.width > 0)
24
31
  measuredWidth = entry.contentRect.width;
25
32
  });
26
- const plotWidth = $derived(Math.max(1, measuredWidth - marginLeft - marginRight));
27
- const plotHeight = $derived(Math.max(1, height - marginTop - marginBottom));
28
33
  // Frequency-bin count is the MAX across frames so ragged input renders a full
29
34
  // rectangular grid: shorter frames leave explicit missing cells rather than
30
35
  // overflowing the plot or silently dropping rows.
31
36
  const binCount = $derived(frames.reduce((max, frame) => Math.max(max, frame.bins.length), 0));
32
- // The bin-index list [0, 1, …, binCount-1], computed once and reused for every
33
- // frame's column rather than rebuilding an Array.from() per frame in the render
34
- // loop.
35
- const binIndices = $derived(Array.from({ length: binCount }, (_, index) => index));
36
37
  // A frame with zero bins contributes no usable data; the chart is "empty" when
37
38
  // there are no frames OR no frequency bins anywhere.
38
39
  const isEmpty = $derived(frames.length === 0 || binCount === 0);
39
- // Cell dimensions
40
- const cellWidth = $derived(frames.length > 0 ? plotWidth / frames.length : 0);
41
- const cellHeight = $derived(binCount > 0 ? plotHeight / binCount : 0);
42
40
  // Read a frame's bin as a finite value or null (missing). Non-finite values
43
41
  // (NaN/Infinity) and out-of-range indices (ragged frames) are missing.
44
42
  function binValueAt(frameIndex, binIndex) {
45
43
  return toFiniteOrNull(frames[frameIndex]?.bins[binIndex]);
46
44
  }
45
+ // Sampled plot cells cover a rectangular bucket of source cells. Aggregate
46
+ // with a maximum so a narrow transient is not lost merely because it is not
47
+ // the bucket's first frame/bin. Each source cell is visited at most once
48
+ // across the rendered buckets, keeping this O(original frame × bin) work.
49
+ function plotBucketValue(frameIndex, frameSpan, binIndex, binSpan) {
50
+ let maximum = null;
51
+ for (let frameOffset = 0; frameOffset < frameSpan; frameOffset += 1) {
52
+ const frame = frames[frameIndex + frameOffset];
53
+ if (!frame)
54
+ continue;
55
+ for (let binOffset = 0; binOffset < binSpan; binOffset += 1) {
56
+ const value = toFiniteOrNull(frame.bins[binIndex + binOffset]);
57
+ if (value !== null && (maximum === null || value > maximum))
58
+ maximum = value;
59
+ }
60
+ }
61
+ return maximum;
62
+ }
47
63
  // Global color domain over the finite values only (shared with MatrixChart).
48
64
  // Computed in a single nested pass over the frames so a large frames × bins
49
65
  // grid never materializes a full flattened copy of every bin.
50
66
  const domain = $derived(heatmapDomainOfRows(frames.map((frame) => frame.bins)));
51
67
  function cellFill(value) {
52
- return heatmapCellFill(value, domain, 'sequential');
68
+ return heatmapCellFill(value, domain, 'sequential', resolvedTheme.palette, theme?.background ?? 'var(--cinder-surface-inset)');
53
69
  }
54
70
  // Convert a bin index to a y-coordinate. Frequency increases UPWARD (the audio
55
71
  // convention): bin 0 (lowest frequency) sits at the BOTTOM of the plot.
@@ -61,12 +77,25 @@ function binY(binIndex) {
61
77
  // its length fall back to the numeric index (rather than discarding all of the
62
78
  // provided labels just because later/ragged frames added extra bins).
63
79
  const yLabels = $derived.by(() => Array.from({ length: binCount }, (_, index) => frequencyLabels?.[index] ?? String(index)));
64
- // Show a subset of y-axis labels
80
+ // Measure exactly the labels rendered by the sampled axes so hidden labels
81
+ // cannot reserve guide space that the SVG never uses.
65
82
  const maxYLabels = 8;
66
83
  const yLabelStep = $derived(Math.max(1, Math.ceil(binCount / maxYLabels)));
67
- // Show a subset of x-axis (time) labels
84
+ const renderedYLabels = $derived(yLabels.filter((_, index) => index % yLabelStep === 0));
68
85
  const maxXLabels = 10;
69
86
  const xLabelStep = $derived(Math.max(1, Math.ceil(frames.length / maxXLabels)));
87
+ const renderedXLabels = $derived(frames.filter((_, index) => index % xLabelStep === 0).map((frame) => frame.label));
88
+ const geometry = $derived(createChartGeometry(measuredWidth, height, {
89
+ xTickLabels: renderedXLabels,
90
+ yTickLabels: renderedYLabels,
91
+ measureText,
92
+ measurementElement: rootElement,
93
+ measurementVersion,
94
+ }));
95
+ const { plotWidth, plotHeight, marginTop, marginLeft } = $derived(geometry);
96
+ // Cell dimensions
97
+ const cellWidth = $derived(frames.length > 0 ? plotWidth / frames.length : 0);
98
+ const cellHeight = $derived(binCount > 0 ? plotHeight / binCount : 0);
70
99
  const hasDataTable = $derived(dataTableVisibility !== 'hidden');
71
100
  // The primary SVG plot renders one <rect> per frame-per-bin with no cap,
72
101
  // unlike the accessible data table below (already capped/sampled to
@@ -78,11 +107,20 @@ const maxPlotFrames = 400;
78
107
  const maxPlotBins = 256;
79
108
  const plotFrameStep = $derived(Math.max(1, Math.ceil(frames.length / maxPlotFrames)));
80
109
  const plotBinStep = $derived(Math.max(1, Math.ceil(binCount / maxPlotBins)));
81
- const plotFrames = $derived(frames
82
- .map((frame, frameIndex) => ({ frame, frameIndex }))
83
- .filter((_, index) => index % plotFrameStep === 0)
84
- .slice(0, maxPlotFrames));
85
- const plotBinIndices = $derived(binIndices.filter((index) => index % plotBinStep === 0).slice(0, maxPlotBins));
110
+ const plotFrames = $derived.by(() => Array.from({ length: Math.min(maxPlotFrames, Math.ceil(frames.length / plotFrameStep)) }, (_, bucketIndex) => {
111
+ const frameIndex = bucketIndex * plotFrameStep;
112
+ return {
113
+ frameIndex,
114
+ span: Math.min(plotFrameStep, frames.length - frameIndex),
115
+ };
116
+ }));
117
+ const plotBins = $derived.by(() => Array.from({ length: Math.min(maxPlotBins, Math.ceil(binCount / plotBinStep)) }, (_, bucketIndex) => {
118
+ const binIndex = bucketIndex * plotBinStep;
119
+ return {
120
+ binIndex,
121
+ span: Math.min(plotBinStep, binCount - binIndex),
122
+ };
123
+ }));
86
124
  // Table rows: each frame is a column; rows are frequency bins.
87
125
  // For accessibility, sample every-Nth frame and bin so the full range is represented
88
126
  // rather than silently truncating to first-N.
@@ -116,8 +154,13 @@ function formatValue(value) {
116
154
  <figure
117
155
  {...rest}
118
156
  {@attach observeResize}
157
+ bind:this={rootElement}
119
158
  id={rootId}
120
159
  class={classNames('cinder-spectrogram', customClassName)}
160
+ style:--_cinder-chart-foreground={resolvedTheme.foreground}
161
+ style:--_cinder-chart-muted={resolvedTheme.muted}
162
+ style:--_cinder-chart-grid={resolvedTheme.grid}
163
+ style:--_cinder-chart-background={resolvedTheme.background}
121
164
  aria-label={label}
122
165
  aria-describedby={descriptionId}
123
166
  >
@@ -156,14 +199,16 @@ function formatValue(value) {
156
199
  non-finite cells render as the "missing" fill. Low frequency (bin 0)
157
200
  is at the bottom. -->
158
201
  {#each plotFrames as entry (entry.frameIndex)}
159
- {#each plotBinIndices as binIndex (binIndex)}
202
+ {#each plotBins as bin (bin.binIndex)}
160
203
  <rect
161
204
  class="cinder-spectrogram__cell"
162
205
  x={entry.frameIndex * cellWidth}
163
- y={binY(binIndex)}
164
- width={cellWidth}
165
- height={cellHeight}
166
- fill={cellFill(binValueAt(entry.frameIndex, binIndex))}
206
+ y={binY(bin.binIndex + bin.span - 1)}
207
+ width={entry.span * cellWidth}
208
+ height={bin.span * cellHeight}
209
+ fill={cellFill(
210
+ plotBucketValue(entry.frameIndex, entry.span, bin.binIndex, bin.span),
211
+ )}
167
212
  aria-hidden="true"
168
213
  />
169
214
  {/each}
@@ -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
  /**
6
6
  * A single time-frame of frequency-bin magnitudes.
@@ -42,6 +42,8 @@ export type SpectrogramProps = Omit<HTMLAttributes<HTMLElement>, 'class'> & {
42
42
  loading?: boolean;
43
43
  /** Controls data table visibility. Default `screen-reader-only`. */
44
44
  dataTableVisibility?: ChartDataTableVisibility;
45
+ /** Partial visual theme override. */
46
+ theme?: ChartTheme;
45
47
  /** Custom data table caption; falls back to `label`. */
46
48
  dataTableCaption?: string;
47
49
  /** Custom class applied to the root element. */
@@ -67,6 +69,8 @@ export type SpectrogramSchemaProps = {
67
69
  loading?: boolean;
68
70
  /** Controls data table visibility. Default `screen-reader-only`. */
69
71
  dataTableVisibility?: ChartDataTableVisibility;
72
+ /** Partial visual theme override. */
73
+ theme?: ChartThemeSchema;
70
74
  /** Custom data table caption; falls back to `label`. */
71
75
  dataTableCaption?: string;
72
76
  /** Custom class applied to the root element. */
@@ -3,12 +3,13 @@
3
3
  .cinder-spectrum-chart {
4
4
  display: grid;
5
5
  gap: var(--cinder-space-3);
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-spectrum-chart__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,17 +24,17 @@
23
24
  }
24
25
 
25
26
  .cinder-spectrum-chart__bar {
26
- fill: var(--cinder-chart-series-1);
27
+ fill: var(--_cinder-chart-series-color, currentColor);
27
28
  rx: 2;
28
29
  }
29
30
 
30
31
  .cinder-spectrum-chart__grid-line {
31
- stroke: var(--cinder-border-muted);
32
+ stroke: var(--_cinder-chart-grid, currentColor);
32
33
  stroke-dasharray: 3 3;
33
34
  }
34
35
 
35
36
  .cinder-spectrum-chart__tick-label {
36
- fill: var(--cinder-text-muted);
37
+ fill: var(--_cinder-chart-muted, currentColor);
37
38
  font-size: var(--cinder-text-xs);
38
39
  }
39
40
 
@@ -42,8 +43,8 @@
42
43
  inset: 0;
43
44
  display: grid;
44
45
  place-items: center;
45
- color: var(--cinder-text-muted);
46
- background: color-mix(in oklch, var(--cinder-surface) 88%, transparent);
46
+ color: var(--_cinder-chart-muted, currentColor);
47
+ background: var(--_cinder-chart-background, transparent);
47
48
  z-index: 1;
48
49
  }
49
50
  }