@opendata-ai/openchart-core 2.0.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 (51) hide show
  1. package/README.md +130 -0
  2. package/dist/index.d.ts +2030 -0
  3. package/dist/index.js +1176 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/styles.css +757 -0
  6. package/package.json +61 -0
  7. package/src/accessibility/__tests__/alt-text.test.ts +110 -0
  8. package/src/accessibility/__tests__/aria.test.ts +125 -0
  9. package/src/accessibility/alt-text.ts +120 -0
  10. package/src/accessibility/aria.ts +73 -0
  11. package/src/accessibility/index.ts +6 -0
  12. package/src/colors/__tests__/colorblind.test.ts +63 -0
  13. package/src/colors/__tests__/contrast.test.ts +71 -0
  14. package/src/colors/__tests__/palettes.test.ts +54 -0
  15. package/src/colors/colorblind.ts +122 -0
  16. package/src/colors/contrast.ts +94 -0
  17. package/src/colors/index.ts +27 -0
  18. package/src/colors/palettes.ts +118 -0
  19. package/src/helpers/__tests__/spec-builders.test.ts +336 -0
  20. package/src/helpers/spec-builders.ts +410 -0
  21. package/src/index.ts +129 -0
  22. package/src/labels/__tests__/collision.test.ts +197 -0
  23. package/src/labels/collision.ts +154 -0
  24. package/src/labels/index.ts +6 -0
  25. package/src/layout/__tests__/chrome.test.ts +114 -0
  26. package/src/layout/__tests__/text-measure.test.ts +49 -0
  27. package/src/layout/chrome.ts +223 -0
  28. package/src/layout/index.ts +6 -0
  29. package/src/layout/text-measure.ts +54 -0
  30. package/src/locale/__tests__/format.test.ts +90 -0
  31. package/src/locale/format.ts +132 -0
  32. package/src/locale/index.ts +6 -0
  33. package/src/responsive/__tests__/breakpoints.test.ts +58 -0
  34. package/src/responsive/breakpoints.ts +92 -0
  35. package/src/responsive/index.ts +18 -0
  36. package/src/styles/viz.css +757 -0
  37. package/src/theme/__tests__/dark-mode.test.ts +68 -0
  38. package/src/theme/__tests__/defaults.test.ts +47 -0
  39. package/src/theme/__tests__/resolve.test.ts +61 -0
  40. package/src/theme/dark-mode.ts +123 -0
  41. package/src/theme/defaults.ts +85 -0
  42. package/src/theme/index.ts +7 -0
  43. package/src/theme/resolve.ts +190 -0
  44. package/src/types/__tests__/spec.test.ts +387 -0
  45. package/src/types/encoding.ts +144 -0
  46. package/src/types/events.ts +96 -0
  47. package/src/types/index.ts +141 -0
  48. package/src/types/layout.ts +794 -0
  49. package/src/types/spec.ts +563 -0
  50. package/src/types/table.ts +105 -0
  51. package/src/types/theme.ts +159 -0
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Theme types: color palettes, typography, spacing, and chrome defaults.
3
+ *
4
+ * Theme is the user-facing partial config (all optional).
5
+ * ResolvedTheme is the engine-internal fully resolved version (no optionals).
6
+ */
7
+
8
+ // ---------------------------------------------------------------------------
9
+ // Color palette types
10
+ // ---------------------------------------------------------------------------
11
+
12
+ /** Color palettes for the visualization. */
13
+ export interface ThemeColors {
14
+ /** Categorical palette for nominal data. Array of CSS color strings. */
15
+ categorical: string[];
16
+ /** Sequential palettes keyed by name. Each is an array of color stops from light to dark. */
17
+ sequential: Record<string, string[]>;
18
+ /** Diverging palettes keyed by name. Each is an array of color stops with a neutral midpoint. */
19
+ diverging: Record<string, string[]>;
20
+ /** Background color for the visualization container. */
21
+ background: string;
22
+ /** Default text color. */
23
+ text: string;
24
+ /** Gridline color. */
25
+ gridline: string;
26
+ /** Axis line and tick color. */
27
+ axis: string;
28
+ /** Annotation fill color. */
29
+ annotationFill: string;
30
+ /** Annotation text color. */
31
+ annotationText: string;
32
+ }
33
+
34
+ // ---------------------------------------------------------------------------
35
+ // Typography types
36
+ // ---------------------------------------------------------------------------
37
+
38
+ /** Font size presets for the typography scale. */
39
+ export interface ThemeFontSizes {
40
+ /** Title font size in pixels. */
41
+ title: number;
42
+ /** Subtitle font size in pixels. */
43
+ subtitle: number;
44
+ /** Body/label font size in pixels. */
45
+ body: number;
46
+ /** Small text (source, footer) font size in pixels. */
47
+ small: number;
48
+ /** Axis tick label font size in pixels. */
49
+ axisTick: number;
50
+ }
51
+
52
+ /** Font weight presets. */
53
+ export interface ThemeFontWeights {
54
+ /** Normal text weight. */
55
+ normal: number;
56
+ /** Medium text weight (subtitles). */
57
+ medium: number;
58
+ /** Semibold text weight (titles). */
59
+ semibold: number;
60
+ /** Bold text weight. */
61
+ bold: number;
62
+ }
63
+
64
+ /** Complete typography configuration. */
65
+ export interface ThemeFonts {
66
+ /** Primary font family. */
67
+ family: string;
68
+ /** Monospace font family (for tabular numbers). */
69
+ mono: string;
70
+ /** Font sizes. */
71
+ sizes: ThemeFontSizes;
72
+ /** Font weights. */
73
+ weights: ThemeFontWeights;
74
+ }
75
+
76
+ // ---------------------------------------------------------------------------
77
+ // Spacing types
78
+ // ---------------------------------------------------------------------------
79
+
80
+ /** Spacing configuration in pixels. */
81
+ export interface ThemeSpacing {
82
+ /** Padding inside the visualization container (all sides). */
83
+ padding: number;
84
+ /** Gap between chrome elements (title to subtitle, subtitle to chart, etc.). */
85
+ chromeGap: number;
86
+ /** Gap between the last chrome element and the chart area. */
87
+ chromeToChart: number;
88
+ /** Gap between chart area and source/footer below. */
89
+ chartToFooter: number;
90
+ /** Internal padding within the chart area (axes margins). */
91
+ axisMargin: number;
92
+ }
93
+
94
+ // ---------------------------------------------------------------------------
95
+ // Chrome default styles
96
+ // ---------------------------------------------------------------------------
97
+
98
+ /** Default style configuration for a chrome text element. */
99
+ export interface ChromeDefaults {
100
+ /** Font size in pixels. */
101
+ fontSize: number;
102
+ /** Font weight. */
103
+ fontWeight: number;
104
+ /** Text color (CSS color string). */
105
+ color: string;
106
+ /** Line height multiplier. */
107
+ lineHeight: number;
108
+ }
109
+
110
+ /** Default chrome styles for each element type. */
111
+ export interface ThemeChromeDefaults {
112
+ title: ChromeDefaults;
113
+ subtitle: ChromeDefaults;
114
+ source: ChromeDefaults;
115
+ byline: ChromeDefaults;
116
+ footer: ChromeDefaults;
117
+ }
118
+
119
+ // ---------------------------------------------------------------------------
120
+ // Theme (user-facing, all optional)
121
+ // ---------------------------------------------------------------------------
122
+
123
+ /**
124
+ * Complete theme interface. Used internally after merging user overrides
125
+ * onto defaults. All fields are required here (this is what the engine
126
+ * works with).
127
+ *
128
+ * Users provide ThemeConfig (from spec.ts) which is the partial/optional
129
+ * version. The theme resolver deep-merges ThemeConfig onto the default Theme
130
+ * to produce a ResolvedTheme.
131
+ */
132
+ export interface Theme {
133
+ /** Color palettes. */
134
+ colors: ThemeColors;
135
+ /** Typography settings. */
136
+ fonts: ThemeFonts;
137
+ /** Spacing values in pixels. */
138
+ spacing: ThemeSpacing;
139
+ /** Border radius for containers and tooltips. */
140
+ borderRadius: number;
141
+ /** Default chrome text styles. */
142
+ chrome: ThemeChromeDefaults;
143
+ }
144
+
145
+ /**
146
+ * Fully resolved theme with no optional fields.
147
+ *
148
+ * This is the result of resolveTheme(): the default theme with user
149
+ * overrides deep-merged in. Every property is guaranteed to have a value.
150
+ * The engine uses ResolvedTheme internally so it never needs null checks.
151
+ *
152
+ * Structurally identical to Theme (both have all required fields), but
153
+ * exists as a separate type for semantic clarity: Theme is the default
154
+ * definition, ResolvedTheme is the runtime-resolved instance.
155
+ */
156
+ export interface ResolvedTheme extends Theme {
157
+ /** Whether dark mode adaptations have been applied to this theme. */
158
+ isDark: boolean;
159
+ }