insomni-plot 0.1.0-alpha.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 (242) hide show
  1. package/LICENSE.md +674 -0
  2. package/README.md +81 -0
  3. package/dist/core.d.mts +340 -0
  4. package/dist/core.mjs +1047 -0
  5. package/dist/index.d.mts +3426 -0
  6. package/dist/index.mjs +12762 -0
  7. package/dist/interactions-DEFL_F4E.mjs +5395 -0
  8. package/dist/range-presets-CzECsu3V.d.mts +1523 -0
  9. package/package.json +34 -0
  10. package/src/annotations.d.ts +121 -0
  11. package/src/annotations.ts +438 -0
  12. package/src/axis.d.ts +184 -0
  13. package/src/axis.test.ts +131 -0
  14. package/src/axis.ts +765 -0
  15. package/src/colorbar.d.ts +69 -0
  16. package/src/colorbar.ts +294 -0
  17. package/src/colors.d.ts +57 -0
  18. package/src/colors.test.ts +28 -0
  19. package/src/colors.ts +486 -0
  20. package/src/core.ts +299 -0
  21. package/src/format.d.ts +54 -0
  22. package/src/format.ts +138 -0
  23. package/src/grammar/accessibility.d.ts +147 -0
  24. package/src/grammar/accessibility.test.ts +199 -0
  25. package/src/grammar/accessibility.ts +443 -0
  26. package/src/grammar/aes.d.ts +35 -0
  27. package/src/grammar/aes.test.ts +75 -0
  28. package/src/grammar/aes.ts +120 -0
  29. package/src/grammar/annotations.d.ts +86 -0
  30. package/src/grammar/annotations.test.ts +68 -0
  31. package/src/grammar/annotations.ts +336 -0
  32. package/src/grammar/attach-brush.d.ts +44 -0
  33. package/src/grammar/attach-brush.test.ts +214 -0
  34. package/src/grammar/attach-brush.ts +111 -0
  35. package/src/grammar/attach-presets.d.ts +33 -0
  36. package/src/grammar/attach-presets.test.ts +106 -0
  37. package/src/grammar/attach-presets.ts +215 -0
  38. package/src/grammar/chart.d.ts +952 -0
  39. package/src/grammar/chart.test.ts +118 -0
  40. package/src/grammar/chart.ts +1172 -0
  41. package/src/grammar/color-utils.d.ts +29 -0
  42. package/src/grammar/color-utils.test.ts +53 -0
  43. package/src/grammar/color-utils.ts +66 -0
  44. package/src/grammar/constants.d.ts +45 -0
  45. package/src/grammar/constants.ts +61 -0
  46. package/src/grammar/coord.d.ts +183 -0
  47. package/src/grammar/coord.test.ts +355 -0
  48. package/src/grammar/coord.ts +619 -0
  49. package/src/grammar/data/pivot.d.ts +57 -0
  50. package/src/grammar/data/pivot.ts +107 -0
  51. package/src/grammar/emphasis-driver.d.ts +69 -0
  52. package/src/grammar/emphasis-driver.test.ts +199 -0
  53. package/src/grammar/emphasis-driver.ts +205 -0
  54. package/src/grammar/equality.d.ts +3 -0
  55. package/src/grammar/equality.ts +40 -0
  56. package/src/grammar/facet.d.ts +63 -0
  57. package/src/grammar/facet.test.ts +60 -0
  58. package/src/grammar/facet.ts +175 -0
  59. package/src/grammar/geoms/_categorical.d.ts +94 -0
  60. package/src/grammar/geoms/_categorical.ts +0 -0
  61. package/src/grammar/geoms/_distribution.d.ts +52 -0
  62. package/src/grammar/geoms/_distribution.ts +125 -0
  63. package/src/grammar/geoms/_mark.d.ts +69 -0
  64. package/src/grammar/geoms/_mark.ts +136 -0
  65. package/src/grammar/geoms/_shape.d.ts +41 -0
  66. package/src/grammar/geoms/_shape.ts +74 -0
  67. package/src/grammar/geoms/aggregate.d.ts +95 -0
  68. package/src/grammar/geoms/aggregate.test.ts +554 -0
  69. package/src/grammar/geoms/aggregate.ts +840 -0
  70. package/src/grammar/geoms/area.d.ts +32 -0
  71. package/src/grammar/geoms/area.test.ts +165 -0
  72. package/src/grammar/geoms/area.ts +578 -0
  73. package/src/grammar/geoms/band.d.ts +27 -0
  74. package/src/grammar/geoms/band.test.ts +57 -0
  75. package/src/grammar/geoms/band.ts +126 -0
  76. package/src/grammar/geoms/bar.d.ts +56 -0
  77. package/src/grammar/geoms/bar.test.ts +367 -0
  78. package/src/grammar/geoms/bar.ts +1054 -0
  79. package/src/grammar/geoms/boxplot.d.ts +129 -0
  80. package/src/grammar/geoms/boxplot.test.ts +299 -0
  81. package/src/grammar/geoms/boxplot.ts +834 -0
  82. package/src/grammar/geoms/connected-scatter.d.ts +27 -0
  83. package/src/grammar/geoms/connected-scatter.test.ts +157 -0
  84. package/src/grammar/geoms/connected-scatter.ts +63 -0
  85. package/src/grammar/geoms/emphasis.d.ts +76 -0
  86. package/src/grammar/geoms/emphasis.test.ts +135 -0
  87. package/src/grammar/geoms/emphasis.ts +162 -0
  88. package/src/grammar/geoms/histogram.d.ts +75 -0
  89. package/src/grammar/geoms/histogram.test.ts +262 -0
  90. package/src/grammar/geoms/histogram.ts +740 -0
  91. package/src/grammar/geoms/index.d.ts +20 -0
  92. package/src/grammar/geoms/index.ts +77 -0
  93. package/src/grammar/geoms/interval.d.ts +31 -0
  94. package/src/grammar/geoms/interval.test.ts +154 -0
  95. package/src/grammar/geoms/interval.ts +342 -0
  96. package/src/grammar/geoms/line.d.ts +38 -0
  97. package/src/grammar/geoms/line.test.ts +247 -0
  98. package/src/grammar/geoms/line.ts +659 -0
  99. package/src/grammar/geoms/point.d.ts +57 -0
  100. package/src/grammar/geoms/point.test.ts +163 -0
  101. package/src/grammar/geoms/point.ts +545 -0
  102. package/src/grammar/geoms/polar.test.ts +216 -0
  103. package/src/grammar/geoms/ribbon.d.ts +21 -0
  104. package/src/grammar/geoms/ribbon.test.ts +170 -0
  105. package/src/grammar/geoms/ribbon.ts +87 -0
  106. package/src/grammar/geoms/ridgeline.d.ts +89 -0
  107. package/src/grammar/geoms/ridgeline.test.ts +247 -0
  108. package/src/grammar/geoms/ridgeline.ts +1164 -0
  109. package/src/grammar/geoms/rolling.d.ts +43 -0
  110. package/src/grammar/geoms/rolling.test.ts +217 -0
  111. package/src/grammar/geoms/rolling.ts +387 -0
  112. package/src/grammar/geoms/rug.d.ts +28 -0
  113. package/src/grammar/geoms/rug.test.ts +126 -0
  114. package/src/grammar/geoms/rug.ts +214 -0
  115. package/src/grammar/geoms/rule.d.ts +23 -0
  116. package/src/grammar/geoms/rule.test.ts +69 -0
  117. package/src/grammar/geoms/rule.ts +212 -0
  118. package/src/grammar/geoms/smooth.d.ts +54 -0
  119. package/src/grammar/geoms/smooth.test.ts +78 -0
  120. package/src/grammar/geoms/smooth.ts +337 -0
  121. package/src/grammar/geoms/text.d.ts +29 -0
  122. package/src/grammar/geoms/text.test.ts +64 -0
  123. package/src/grammar/geoms/text.ts +234 -0
  124. package/src/grammar/geoms/tile.d.ts +61 -0
  125. package/src/grammar/geoms/tile.test.ts +157 -0
  126. package/src/grammar/geoms/tile.ts +621 -0
  127. package/src/grammar/geoms/types.d.ts +319 -0
  128. package/src/grammar/geoms/types.ts +362 -0
  129. package/src/grammar/geoms/violin.d.ts +85 -0
  130. package/src/grammar/geoms/violin.test.ts +187 -0
  131. package/src/grammar/geoms/violin.ts +672 -0
  132. package/src/grammar/index.d.ts +22 -0
  133. package/src/grammar/index.ts +269 -0
  134. package/src/grammar/interactions/_disposable.d.ts +5 -0
  135. package/src/grammar/interactions/_disposable.ts +23 -0
  136. package/src/grammar/interactions/_z.d.ts +4 -0
  137. package/src/grammar/interactions/_z.ts +16 -0
  138. package/src/grammar/interactions/brush-selection.test.ts +262 -0
  139. package/src/grammar/interactions/brush.d.ts +63 -0
  140. package/src/grammar/interactions/brush.test.ts +483 -0
  141. package/src/grammar/interactions/brush.ts +452 -0
  142. package/src/grammar/interactions/crosshair.d.ts +19 -0
  143. package/src/grammar/interactions/crosshair.test.ts +127 -0
  144. package/src/grammar/interactions/crosshair.ts +76 -0
  145. package/src/grammar/interactions/hit-layer.d.ts +64 -0
  146. package/src/grammar/interactions/hit-layer.ts +246 -0
  147. package/src/grammar/interactions/legend.d.ts +19 -0
  148. package/src/grammar/interactions/legend.ts +101 -0
  149. package/src/grammar/interactions/menu.d.ts +93 -0
  150. package/src/grammar/interactions/menu.test.ts +373 -0
  151. package/src/grammar/interactions/menu.ts +342 -0
  152. package/src/grammar/interactions/selection.d.ts +25 -0
  153. package/src/grammar/interactions/selection.test.ts +289 -0
  154. package/src/grammar/interactions/selection.ts +142 -0
  155. package/src/grammar/interactions/series-readout.d.ts +91 -0
  156. package/src/grammar/interactions/series-readout.test.ts +668 -0
  157. package/src/grammar/interactions/series-readout.ts +422 -0
  158. package/src/grammar/interactions/series-snap.d.ts +70 -0
  159. package/src/grammar/interactions/series-snap.test.ts +214 -0
  160. package/src/grammar/interactions/series-snap.ts +218 -0
  161. package/src/grammar/interactions/tooltip-axis.test.ts +176 -0
  162. package/src/grammar/interactions/tooltip-touch.browser.test.ts +49 -0
  163. package/src/grammar/interactions/tooltip-touch.test.ts +161 -0
  164. package/src/grammar/interactions/tooltip.d.ts +140 -0
  165. package/src/grammar/interactions/tooltip.test.ts +406 -0
  166. package/src/grammar/interactions/tooltip.ts +622 -0
  167. package/src/grammar/interactions/transitions.d.ts +34 -0
  168. package/src/grammar/interactions/transitions.test.ts +172 -0
  169. package/src/grammar/interactions/transitions.ts +160 -0
  170. package/src/grammar/layout.d.ts +68 -0
  171. package/src/grammar/layout.ts +186 -0
  172. package/src/grammar/legend-merge.test.ts +332 -0
  173. package/src/grammar/mount.d.ts +78 -0
  174. package/src/grammar/mount.test.ts +479 -0
  175. package/src/grammar/mount.ts +2112 -0
  176. package/src/grammar/palettes.d.ts +54 -0
  177. package/src/grammar/palettes.test.ts +80 -0
  178. package/src/grammar/palettes.ts +167 -0
  179. package/src/grammar/pan-zoom.test.ts +398 -0
  180. package/src/grammar/phylo.d.ts +65 -0
  181. package/src/grammar/phylo.test.ts +59 -0
  182. package/src/grammar/phylo.ts +112 -0
  183. package/src/grammar/pipeline.auto-ticks.test.ts +40 -0
  184. package/src/grammar/pipeline.d.ts +158 -0
  185. package/src/grammar/pipeline.test.ts +463 -0
  186. package/src/grammar/pipeline.ts +1233 -0
  187. package/src/grammar/profiling.d.ts +8 -0
  188. package/src/grammar/profiling.ts +24 -0
  189. package/src/grammar/scales.d.ts +188 -0
  190. package/src/grammar/scales.test.ts +181 -0
  191. package/src/grammar/scales.ts +800 -0
  192. package/src/grammar/svg.d.ts +3 -0
  193. package/src/grammar/svg.ts +39 -0
  194. package/src/grammar/theme.d.ts +261 -0
  195. package/src/grammar/theme.test.ts +105 -0
  196. package/src/grammar/theme.ts +490 -0
  197. package/src/heatmap/cpu.ts +109 -0
  198. package/src/heatmap/gpu.ts +565 -0
  199. package/src/heatmap/types.ts +177 -0
  200. package/src/heatmap.browser.test.ts +308 -0
  201. package/src/heatmap.test.ts +320 -0
  202. package/src/heatmap.ts +123 -0
  203. package/src/index.d.ts +1 -0
  204. package/src/index.ts +8 -0
  205. package/src/interactions.d.ts +48 -0
  206. package/src/interactions.test.ts +226 -0
  207. package/src/interactions.ts +394 -0
  208. package/src/layout/box.d.ts +48 -0
  209. package/src/layout/box.test.ts +107 -0
  210. package/src/layout/box.ts +143 -0
  211. package/src/legend.d.ts +115 -0
  212. package/src/legend.ts +422 -0
  213. package/src/marks/curve.d.ts +43 -0
  214. package/src/marks/curve.ts +244 -0
  215. package/src/marks/stack.d.ts +53 -0
  216. package/src/marks/stack.ts +184 -0
  217. package/src/marks.d.ts +273 -0
  218. package/src/marks.test.ts +541 -0
  219. package/src/marks.ts +1292 -0
  220. package/src/navigator.test.ts +174 -0
  221. package/src/navigator.ts +393 -0
  222. package/src/range-presets.d.ts +113 -0
  223. package/src/range-presets.test.ts +345 -0
  224. package/src/range-presets.ts +349 -0
  225. package/src/scales.d.ts +98 -0
  226. package/src/scales.test.ts +103 -0
  227. package/src/scales.ts +695 -0
  228. package/src/stats/index.d.ts +200 -0
  229. package/src/stats/index.test.ts +349 -0
  230. package/src/stats/index.ts +740 -0
  231. package/src/stats/regression.d.ts +38 -0
  232. package/src/stats/regression.test.ts +56 -0
  233. package/src/stats/regression.ts +396 -0
  234. package/src/stats/rolling-window.d.ts +55 -0
  235. package/src/stats/rolling-window.test.ts +237 -0
  236. package/src/stats/rolling-window.ts +256 -0
  237. package/src/test-setup.ts +19 -0
  238. package/src/viewport/axis-state.d.ts +72 -0
  239. package/src/viewport/axis-state.ts +476 -0
  240. package/src/viewport.d.ts +170 -0
  241. package/src/viewport.test.ts +363 -0
  242. package/src/viewport.ts +510 -0
package/src/colors.ts ADDED
@@ -0,0 +1,486 @@
1
+ import { cssHex, lerpInSpace, type BlendSpace, type Color } from "insomni";
2
+ import { clamp } from "./scales.ts";
3
+
4
+ export interface ContinuousPalette {
5
+ (t: number): Color;
6
+ readonly kind: "continuous";
7
+ readonly stops: readonly Color[];
8
+ /** Color space used to interpolate between adjacent stops. */
9
+ readonly blendSpace: BlendSpace;
10
+ /**
11
+ * Return a new palette with the same stops but interpolating in the given
12
+ * space. The original is unchanged. Cheap — palettes are stateless.
13
+ */
14
+ withBlendSpace(space: BlendSpace): ContinuousPalette;
15
+ }
16
+
17
+ export interface CategoricalPalette {
18
+ (index: number): Color;
19
+ readonly kind: "categorical";
20
+ readonly colors: readonly Color[];
21
+ }
22
+
23
+ export function colorScale(
24
+ palette: ContinuousPalette,
25
+ domain: readonly [number, number],
26
+ ): (value: number) => Color;
27
+ export function colorScale<Domain>(
28
+ palette: CategoricalPalette,
29
+ domain: readonly Domain[],
30
+ ): (value: Domain) => Color;
31
+ export function colorScale<Domain>(
32
+ palette: ContinuousPalette | CategoricalPalette,
33
+ domain: readonly [number, number] | readonly Domain[],
34
+ ): (value: number | Domain) => Color {
35
+ if (
36
+ Array.isArray(domain) &&
37
+ domain.length === 2 &&
38
+ typeof domain[0] === "number" &&
39
+ typeof domain[1] === "number"
40
+ ) {
41
+ const [d0, d1] = domain;
42
+ if (palette.kind === "continuous") {
43
+ return (value: number | Domain) => {
44
+ const numeric = value as number;
45
+ const t = d0 === d1 ? 0.5 : (numeric - d0) / (d1 - d0);
46
+ return palette(t);
47
+ };
48
+ }
49
+
50
+ const colors = palette.colors;
51
+ return (value: number | Domain) => {
52
+ const numeric = value as number;
53
+ const t = d0 === d1 ? 0 : (numeric - d0) / (d1 - d0);
54
+ const index = Math.round(clamp(t, 0, 1) * Math.max(colors.length - 1, 0));
55
+ return colors[index] ?? colors[colors.length - 1]!;
56
+ };
57
+ }
58
+
59
+ const categories = [...(domain as readonly Domain[])];
60
+ const index = new Map<Domain, number>();
61
+ for (let offset = 0; offset < categories.length; offset++) {
62
+ index.set(categories[offset]!, offset);
63
+ }
64
+
65
+ if (palette.kind === "categorical") {
66
+ return (value: number | Domain) => palette(index.get(value as Domain) ?? 0);
67
+ }
68
+
69
+ return (value: number | Domain) => {
70
+ const offset = index.get(value as Domain) ?? 0;
71
+ const t = categories.length <= 1 ? 0.5 : offset / (categories.length - 1);
72
+ return palette(t);
73
+ };
74
+ }
75
+
76
+ function paletteFromStops(stops: readonly Color[], space: BlendSpace): ContinuousPalette {
77
+ const palette = ((t: number) => {
78
+ const normalized = clamp(t, 0, 1);
79
+ if (stops.length === 1) return stops[0]!;
80
+ const scaled = normalized * (stops.length - 1);
81
+ const index = Math.min(Math.floor(scaled), stops.length - 2);
82
+ const localT = scaled - index;
83
+ return lerpInSpace(stops[index]!, stops[index + 1]!, localT, space);
84
+ }) as ContinuousPalette;
85
+
86
+ Object.defineProperties(palette, {
87
+ kind: { value: "continuous", enumerable: true },
88
+ stops: { value: stops, enumerable: true },
89
+ blendSpace: { value: space, enumerable: true },
90
+ withBlendSpace: {
91
+ value: (next: BlendSpace) => (next === space ? palette : paletteFromStops(stops, next)),
92
+ enumerable: false,
93
+ },
94
+ });
95
+
96
+ return palette;
97
+ }
98
+
99
+ function createContinuousPalette(
100
+ hexStops: readonly string[],
101
+ options: { blendSpace?: BlendSpace } = {},
102
+ ): ContinuousPalette {
103
+ // Default to sRGB so the built-in palettes (viridis, magma, …) keep the
104
+ // exact gradient their authors hand-tuned. Charts upgrade to OKLch via
105
+ // `theme.paletteBlendSpace` so consumers get the perceptual blend by
106
+ // default without breaking standalone palette use.
107
+ const space = options.blendSpace ?? "srgb";
108
+ const stops = hexStops.map((value) => cssHex(value));
109
+ return paletteFromStops(stops, space);
110
+ }
111
+
112
+ function createCategoricalPalette(hexColors: readonly string[]): CategoricalPalette {
113
+ const colors = hexColors.map((value) => cssHex(value));
114
+ const palette = ((index: number) => {
115
+ if (colors.length === 0) {
116
+ throw new Error("Categorical palettes must contain at least one color.");
117
+ }
118
+ const resolved = ((Math.trunc(index) % colors.length) + colors.length) % colors.length;
119
+ return colors[resolved]!;
120
+ }) as CategoricalPalette;
121
+
122
+ Object.defineProperties(palette, {
123
+ kind: { value: "categorical", enumerable: true },
124
+ colors: { value: colors, enumerable: true },
125
+ });
126
+
127
+ return palette;
128
+ }
129
+
130
+ export const viridis = createContinuousPalette([
131
+ "#440154",
132
+ "#414487",
133
+ "#2a788e",
134
+ "#22a884",
135
+ "#7ad151",
136
+ "#fde725",
137
+ ]);
138
+
139
+ export const plasma = createContinuousPalette([
140
+ "#0d0887",
141
+ "#5b02a3",
142
+ "#9a179b",
143
+ "#cb4679",
144
+ "#ed7953",
145
+ "#fdb42f",
146
+ "#f0f921",
147
+ ]);
148
+
149
+ export const inferno = createContinuousPalette([
150
+ "#000004",
151
+ "#320a5a",
152
+ "#781b6c",
153
+ "#bb3654",
154
+ "#ed6925",
155
+ "#fbb41a",
156
+ "#fcffa4",
157
+ ]);
158
+
159
+ export const magma = createContinuousPalette([
160
+ "#000004",
161
+ "#221150",
162
+ "#5f187f",
163
+ "#982d80",
164
+ "#d3436e",
165
+ "#f8765c",
166
+ "#fcfdbf",
167
+ ]);
168
+
169
+ export const cividis = createContinuousPalette([
170
+ "#00204c",
171
+ "#2e3f6d",
172
+ "#575d6d",
173
+ "#7d7c5c",
174
+ "#a59c46",
175
+ "#d5be38",
176
+ "#ffe945",
177
+ ]);
178
+
179
+ export const coolwarm = createContinuousPalette([
180
+ "#3b4cc0",
181
+ "#6f92f3",
182
+ "#aac7fd",
183
+ "#dddcdc",
184
+ "#f7b89c",
185
+ "#e7745b",
186
+ "#b40426",
187
+ ]);
188
+
189
+ export const rdbu = createContinuousPalette([
190
+ "#67001f",
191
+ "#b2182b",
192
+ "#d6604d",
193
+ "#fddbc7",
194
+ "#f7f7f7",
195
+ "#d1e5f0",
196
+ "#4393c3",
197
+ "#2166ac",
198
+ "#053061",
199
+ ]);
200
+
201
+ export const spectral = createContinuousPalette([
202
+ "#9e0142",
203
+ "#d53e4f",
204
+ "#f46d43",
205
+ "#fdae61",
206
+ "#fee08b",
207
+ "#ffffbf",
208
+ "#e6f598",
209
+ "#abdda4",
210
+ "#66c2a5",
211
+ "#3288bd",
212
+ "#5e4fa2",
213
+ ]);
214
+
215
+ export const tableau10 = createCategoricalPalette([
216
+ "#4e79a7",
217
+ "#f28e2b",
218
+ "#e15759",
219
+ "#76b7b2",
220
+ "#59a14f",
221
+ "#edc948",
222
+ "#b07aa1",
223
+ "#ff9da7",
224
+ "#9c755f",
225
+ "#bab0ab",
226
+ ]);
227
+
228
+ export const category10 = createCategoricalPalette([
229
+ "#1f77b4",
230
+ "#ff7f0e",
231
+ "#2ca02c",
232
+ "#d62728",
233
+ "#9467bd",
234
+ "#8c564b",
235
+ "#e377c2",
236
+ "#7f7f7f",
237
+ "#bcbd22",
238
+ "#17becf",
239
+ ]);
240
+
241
+ export const pastel = createCategoricalPalette([
242
+ "#fbb4ae",
243
+ "#b3cde3",
244
+ "#ccebc5",
245
+ "#decbe4",
246
+ "#fed9a6",
247
+ "#ffffcc",
248
+ "#e5d8bd",
249
+ "#fddaec",
250
+ ]);
251
+
252
+ // ---------------------------------------------------------------------------
253
+ // Categorical — ColorBrewer
254
+ // ---------------------------------------------------------------------------
255
+
256
+ export const set1 = createCategoricalPalette([
257
+ "#e41a1c",
258
+ "#377eb8",
259
+ "#4daf4a",
260
+ "#984ea3",
261
+ "#ff7f00",
262
+ "#ffff33",
263
+ "#a65628",
264
+ "#f781bf",
265
+ "#999999",
266
+ ]);
267
+
268
+ export const set2 = createCategoricalPalette([
269
+ "#66c2a5",
270
+ "#fc8d62",
271
+ "#8da0cb",
272
+ "#e78ac3",
273
+ "#a6d854",
274
+ "#ffd92f",
275
+ "#e5c494",
276
+ "#b3b3b3",
277
+ ]);
278
+
279
+ export const set3 = createCategoricalPalette([
280
+ "#8dd3c7",
281
+ "#ffffb3",
282
+ "#bebada",
283
+ "#fb8072",
284
+ "#80b1d3",
285
+ "#fdb462",
286
+ "#b3de69",
287
+ "#fccde5",
288
+ "#d9d9d9",
289
+ "#bc80bd",
290
+ "#ccebc5",
291
+ "#ffed6f",
292
+ ]);
293
+
294
+ export const dark2 = createCategoricalPalette([
295
+ "#1b9e77",
296
+ "#d95f02",
297
+ "#7570b3",
298
+ "#e7298a",
299
+ "#66a61e",
300
+ "#e6ab02",
301
+ "#a6761d",
302
+ "#666666",
303
+ ]);
304
+
305
+ export const accent = createCategoricalPalette([
306
+ "#7fc97f",
307
+ "#beaed4",
308
+ "#fdc086",
309
+ "#ffff99",
310
+ "#386cb0",
311
+ "#f0027f",
312
+ "#bf5b17",
313
+ "#666666",
314
+ ]);
315
+
316
+ export const paired = createCategoricalPalette([
317
+ "#a6cee3",
318
+ "#1f78b4",
319
+ "#b2df8a",
320
+ "#33a02c",
321
+ "#fb9a99",
322
+ "#e31a1c",
323
+ "#fdbf6f",
324
+ "#ff7f00",
325
+ "#cab2d6",
326
+ "#6a3d9a",
327
+ "#ffff99",
328
+ "#b15928",
329
+ ]);
330
+
331
+ // ---------------------------------------------------------------------------
332
+ // Sequential single-hue — ColorBrewer
333
+ // ---------------------------------------------------------------------------
334
+
335
+ export const blues = createContinuousPalette([
336
+ "#f7fbff",
337
+ "#deebf7",
338
+ "#c6dbef",
339
+ "#9ecae1",
340
+ "#6baed6",
341
+ "#4292c6",
342
+ "#2171b5",
343
+ "#08519c",
344
+ "#08306b",
345
+ ]);
346
+
347
+ export const greens = createContinuousPalette([
348
+ "#f7fcf5",
349
+ "#e5f5e0",
350
+ "#c7e9c0",
351
+ "#a1d99b",
352
+ "#74c476",
353
+ "#41ab5d",
354
+ "#238b45",
355
+ "#006d2c",
356
+ "#00441b",
357
+ ]);
358
+
359
+ export const oranges = createContinuousPalette([
360
+ "#fff5eb",
361
+ "#fee6ce",
362
+ "#fdd0a2",
363
+ "#fdae6b",
364
+ "#fd8d3c",
365
+ "#f16913",
366
+ "#d94801",
367
+ "#a63603",
368
+ "#7f2704",
369
+ ]);
370
+
371
+ export const reds = createContinuousPalette([
372
+ "#fff5f0",
373
+ "#fee0d2",
374
+ "#fcbba1",
375
+ "#fc9272",
376
+ "#fb6a4a",
377
+ "#ef3b2c",
378
+ "#cb181d",
379
+ "#a50f15",
380
+ "#67000d",
381
+ ]);
382
+
383
+ export const purples = createContinuousPalette([
384
+ "#fcfbfd",
385
+ "#efedf5",
386
+ "#dadaeb",
387
+ "#bcbddc",
388
+ "#9e9ac8",
389
+ "#807dba",
390
+ "#6a51a3",
391
+ "#54278f",
392
+ "#3f007d",
393
+ ]);
394
+
395
+ export const greys = createContinuousPalette([
396
+ "#ffffff",
397
+ "#f0f0f0",
398
+ "#d9d9d9",
399
+ "#bdbdbd",
400
+ "#969696",
401
+ "#737373",
402
+ "#525252",
403
+ "#252525",
404
+ "#000000",
405
+ ]);
406
+
407
+ // ---------------------------------------------------------------------------
408
+ // Diverging — ColorBrewer
409
+ // ---------------------------------------------------------------------------
410
+
411
+ export const brbg = createContinuousPalette([
412
+ "#543005",
413
+ "#8c510a",
414
+ "#bf812d",
415
+ "#dfc27d",
416
+ "#f6e8c3",
417
+ "#f5f5f5",
418
+ "#c7eae5",
419
+ "#80cdc1",
420
+ "#35978f",
421
+ "#01665e",
422
+ "#003c30",
423
+ ]);
424
+
425
+ export const prgn = createContinuousPalette([
426
+ "#40004b",
427
+ "#762a83",
428
+ "#9970ab",
429
+ "#c2a5cf",
430
+ "#e7d4e8",
431
+ "#f7f7f7",
432
+ "#d9f0d3",
433
+ "#a6dba0",
434
+ "#5aae61",
435
+ "#1b7837",
436
+ "#00441b",
437
+ ]);
438
+
439
+ export const piyg = createContinuousPalette([
440
+ "#8e0152",
441
+ "#c51b7d",
442
+ "#de77ae",
443
+ "#f1b6da",
444
+ "#fde0ef",
445
+ "#f7f7f7",
446
+ "#e6f5d0",
447
+ "#b8e186",
448
+ "#7fbc41",
449
+ "#4d9221",
450
+ "#276419",
451
+ ]);
452
+
453
+ export const puor = createContinuousPalette([
454
+ "#7f3b08",
455
+ "#b35806",
456
+ "#e08214",
457
+ "#fdb863",
458
+ "#fee0b6",
459
+ "#f7f7f7",
460
+ "#d8daeb",
461
+ "#b2abd2",
462
+ "#8073ac",
463
+ "#542788",
464
+ "#2d004b",
465
+ ]);
466
+
467
+ // ---------------------------------------------------------------------------
468
+ // Custom palette factories — for users who want their own gradients/sets
469
+ // without re-implementing the closure plumbing.
470
+ // ---------------------------------------------------------------------------
471
+
472
+ /**
473
+ * Build a continuous palette from an arbitrary list of CSS hex stops.
474
+ * Stops are evenly spaced; sample with `palette(t)` where `t ∈ [0, 1]`.
475
+ */
476
+ export function continuousPalette(hexStops: readonly string[]): ContinuousPalette {
477
+ return createContinuousPalette(hexStops);
478
+ }
479
+
480
+ /**
481
+ * Build a categorical palette from an arbitrary list of CSS hex colors.
482
+ * Indices wrap modulo length, so `palette(N)` always returns a valid color.
483
+ */
484
+ export function categoricalPalette(hexColors: readonly string[]): CategoricalPalette {
485
+ return createCategoricalPalette(hexColors);
486
+ }