@motionscript/charts 0.1.1-alpha.1 → 0.1.1-alpha.2

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 (81) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +19 -8
  3. package/dist/bar-chart/bar-chart.d.ts +97 -65
  4. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  5. package/dist/bar-chart/bar-chart.js +9 -5
  6. package/dist/bar-chart/bar-chart.js.map +1 -1
  7. package/dist/bar-chart/chart-bars.d.ts +29 -5
  8. package/dist/bar-chart/chart-bars.d.ts.map +1 -1
  9. package/dist/bar-chart/chart-bars.js +33 -8
  10. package/dist/bar-chart/chart-bars.js.map +1 -1
  11. package/dist/bar-chart/shared.d.ts +9 -4
  12. package/dist/bar-chart/shared.d.ts.map +1 -1
  13. package/dist/bar-chart/shared.js +10 -5
  14. package/dist/bar-chart/shared.js.map +1 -1
  15. package/dist/browser/chunks/chunk-7XCRX6GE.js +2 -0
  16. package/dist/browser/chunks/chunk-7XCRX6GE.js.map +7 -0
  17. package/dist/browser/index.js +1 -1
  18. package/dist/browser/index.js.map +3 -3
  19. package/dist/browser/kit.js +1 -1
  20. package/dist/browser/manifest.json +1 -1
  21. package/dist/kit/cartesian.d.ts +6 -4
  22. package/dist/kit/cartesian.d.ts.map +1 -1
  23. package/dist/kit/cartesian.js +5 -3
  24. package/dist/kit/cartesian.js.map +1 -1
  25. package/dist/kit/style.d.ts +339 -76
  26. package/dist/kit/style.d.ts.map +1 -1
  27. package/dist/kit/style.js +196 -101
  28. package/dist/kit/style.js.map +1 -1
  29. package/dist/line-chart/line-chart.d.ts +81 -57
  30. package/dist/line-chart/line-chart.d.ts.map +1 -1
  31. package/dist/line-chart/line-chart.js +9 -7
  32. package/dist/line-chart/line-chart.js.map +1 -1
  33. package/dist/pie-chart/pie-chart.d.ts +43 -43
  34. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  35. package/dist/pie-chart/pie-chart.js +2 -1
  36. package/dist/pie-chart/pie-chart.js.map +1 -1
  37. package/dist/pie-chart/shared.d.ts +15 -8
  38. package/dist/pie-chart/shared.d.ts.map +1 -1
  39. package/dist/pie-chart/shared.js +21 -20
  40. package/dist/pie-chart/shared.js.map +1 -1
  41. package/dist/radar-chart/index.d.ts +1 -1
  42. package/dist/radar-chart/index.d.ts.map +1 -1
  43. package/dist/radar-chart/index.js +1 -1
  44. package/dist/radar-chart/index.js.map +1 -1
  45. package/dist/radar-chart/radar-chart.d.ts +37 -43
  46. package/dist/radar-chart/radar-chart.d.ts.map +1 -1
  47. package/dist/radar-chart/radar-chart.js +12 -12
  48. package/dist/radar-chart/radar-chart.js.map +1 -1
  49. package/dist/radar-chart/radar-grid.d.ts +7 -1
  50. package/dist/radar-chart/radar-grid.d.ts.map +1 -1
  51. package/dist/radar-chart/radar-grid.js +17 -15
  52. package/dist/radar-chart/radar-grid.js.map +1 -1
  53. package/dist/radar-chart/shared.d.ts +7 -2
  54. package/dist/radar-chart/shared.d.ts.map +1 -1
  55. package/dist/radar-chart/shared.js +6 -0
  56. package/dist/radar-chart/shared.js.map +1 -1
  57. package/dist/radial-chart/radial-chart.d.ts +37 -43
  58. package/dist/radial-chart/radial-chart.d.ts.map +1 -1
  59. package/dist/radial-chart/radial-chart.js +2 -1
  60. package/dist/radial-chart/radial-chart.js.map +1 -1
  61. package/dist/radial-chart/shared.d.ts +13 -9
  62. package/dist/radial-chart/shared.d.ts.map +1 -1
  63. package/dist/radial-chart/shared.js +15 -16
  64. package/dist/radial-chart/shared.js.map +1 -1
  65. package/package.json +4 -4
  66. package/src/bar-chart/bar-chart.ts +17 -6
  67. package/src/bar-chart/chart-bars.ts +48 -9
  68. package/src/bar-chart/shared.ts +20 -5
  69. package/src/kit/cartesian.ts +10 -7
  70. package/src/kit/style.ts +214 -118
  71. package/src/line-chart/line-chart.ts +14 -8
  72. package/src/pie-chart/pie-chart.ts +3 -1
  73. package/src/pie-chart/shared.ts +30 -22
  74. package/src/radar-chart/index.ts +1 -1
  75. package/src/radar-chart/radar-chart.ts +16 -13
  76. package/src/radar-chart/radar-grid.ts +18 -13
  77. package/src/radar-chart/shared.ts +9 -2
  78. package/src/radial-chart/radial-chart.ts +3 -1
  79. package/src/radial-chart/shared.ts +30 -18
  80. package/dist/browser/chunks/chunk-R3Q5EE6E.js +0 -2
  81. package/dist/browser/chunks/chunk-R3Q5EE6E.js.map +0 -7
package/dist/kit/style.js CHANGED
@@ -2,29 +2,48 @@
2
2
  * The chart family's style: one `style` entry per chart, built from the groups
3
3
  * below, so a look saved off one chart lays onto any other (a field the other
4
4
  * chart does not draw is dropped). A chart spreads the shared groups and adds a
5
- * `marks` group of its own.
5
+ * `marks` group of its own. Every run of text a chart draws is its own
6
+ * `Types.typography` field, so axis labels, titles, values and the legend are
7
+ * each set the way a text node is.
6
8
  */
7
- import { Types, } from "@motionscript/sdk";
8
- /** The style family every chart shares; a host keys saved styles by it. */
9
+ import { Types, textOps, } from "@motionscript/sdk";
10
+ /** The style family every chart shares; the built-in presets are written for it. */
9
11
  export const CHART_STYLE_FAMILY = "chart";
10
- /** The out-of-the-box series colours, cycled by series (or row) index. */
12
+ /** The out-of-the-box series fills, cycled by series (or row) index. */
11
13
  export const CHART_PALETTE_DEFAULT = ["#4f8cff", "#2fbf8f", "#f5a524", "#e5547a", "#9b6cf0"];
12
- export const CHART_COLORS = {
13
- /** A colour per series (a pie's or radial's per row), cycled. */
14
- palette: Types.palette(CHART_PALETTE_DEFAULT),
15
- /** Values, legend captions, centre text. */
16
- foreground: Types.fill("#f4f4f5"),
17
- /** Axis markers and captions, spoke labels. */
18
- muted: Types.fill("#a1a1aa"),
19
- /** Behind the plot; none by default, so the chart reads against the stage. */
14
+ /** The default ink of values, legend captions and centre text, on the dark stage. */
15
+ export const CHART_FOREGROUND = "#f4f4f5";
16
+ /** The default ink of axis markers, axis captions and spoke labels. */
17
+ export const CHART_MUTED = "#a1a1aa";
18
+ export const CHART_SERIES = {
19
+ /** A fill per series (a pie's or radial's per row), cycled; each may stack several paints. */
20
+ seriesFills: Types.palette(CHART_PALETTE_DEFAULT),
21
+ };
22
+ export const CHART_BACKGROUND = {
23
+ /** Behind the whole chart, legend and axes included; none by default, so the chart reads against the stage. */
20
24
  background: Types.fill([]),
21
25
  };
22
- export const CHART_TEXT = {
23
- /** Empty: the scene's default face. */
24
- fontFamily: Types.font(""),
25
- /** Marker and legend size at 1080p; titles and values scale from it. */
26
- fontSize: Types.number(28, { min: 8, max: 160, step: 1, unit: "px" }),
27
- fontWeight: Types.number(500, { min: 100, max: 900, step: 100 }),
26
+ export const GRID_BACKGROUND = {
27
+ ...CHART_BACKGROUND,
28
+ /** Behind the plot only, under the grid lines; none by default. */
29
+ gridBackground: Types.fill([]),
30
+ };
31
+ /** The legend's captions, which every chart with a legend draws. */
32
+ export const LEGEND_TEXT = {
33
+ legendText: Types.typography({ fontSize: 28, fontWeight: 500, fill: CHART_FOREGROUND }),
34
+ };
35
+ export const CARTESIAN_TEXT = {
36
+ /** The markers under the plot: categories on a column chart, values on a horizontal bar chart. */
37
+ xLabelText: Types.typography({ fontSize: 28, fontWeight: 500, fill: CHART_MUTED }),
38
+ /** The caption under the plot. */
39
+ xTitleText: Types.typography({ fontSize: 31, fontWeight: 600, fill: CHART_MUTED }),
40
+ /** The markers beside the plot. */
41
+ yLabelText: Types.typography({ fontSize: 28, fontWeight: 500, fill: CHART_MUTED }),
42
+ /** The caption beside the plot, turned on its side. */
43
+ yTitleText: Types.typography({ fontSize: 31, fontWeight: 600, fill: CHART_MUTED }),
44
+ /** The figures printed by the marks. */
45
+ valueText: Types.typography({ fontSize: 24, fontWeight: 600, fill: CHART_FOREGROUND }),
46
+ ...LEGEND_TEXT,
28
47
  };
29
48
  export const CARTESIAN_GRID = {
30
49
  /** The lines along the value ticks of a column chart (one per tick); empty draws none. */
@@ -43,145 +62,153 @@ export const CHART_LEGEND = {
43
62
  legend: Types.oneOf(["bottom", "top", "right", "none"], { animatable: false }),
44
63
  swatch: Types.oneOf(["square", "circle", "line"]),
45
64
  };
46
- /** The rule and track fields a preset restates so its rules read on its background (a chart keeps those it draws). */
47
- const _PRESET_RULES = {
65
+ /** The fields a preset restates so its rules and text read on its background (a chart keeps those it draws). */
66
+ const _PRESET_FIELDS = {
67
+ ...CHART_SERIES,
68
+ ...GRID_BACKGROUND,
69
+ ...CARTESIAN_TEXT,
70
+ labelText: Types.typography(),
71
+ centerText: Types.typography(),
72
+ spokeText: Types.typography(),
48
73
  horizontalGrid: CARTESIAN_GRID.horizontalGrid,
49
74
  gridStroke: Types.stroke([]),
50
75
  spokeStroke: Types.stroke([]),
51
76
  track: Types.fill([]),
52
77
  };
78
+ /** Every text field's ink: `foreground` for values, the legend and centre text, `muted` for markers and captions. */
79
+ function inks(foreground, muted) {
80
+ const on = (fill) => ({ fill });
81
+ return {
82
+ xLabelText: on(muted),
83
+ xTitleText: on(muted),
84
+ yLabelText: on(muted),
85
+ yTitleText: on(muted),
86
+ valueText: on(foreground),
87
+ legendText: on(foreground),
88
+ labelText: on(muted),
89
+ centerText: on(foreground),
90
+ spokeText: on(muted),
91
+ };
92
+ }
93
+ /** Every rule a chart draws, and a radial's track, in one paint. */
94
+ function rules(fill) {
95
+ return {
96
+ horizontalGrid: { weight: 2, fill },
97
+ gridStroke: { weight: 2, fill },
98
+ spokeStroke: { weight: 2, fill },
99
+ track: fill,
100
+ };
101
+ }
53
102
  /** Ready-made looks, each stating every colour so applying one replaces the last. */
54
103
  export const CHART_STYLE_PRESETS = {
55
104
  midnight: {
56
- palette: [...CHART_PALETTE_DEFAULT],
57
- foreground: "#f4f4f5",
58
- muted: "#a1a1aa",
59
- horizontalGrid: { weight: 2, fill: "white/15" },
60
- gridStroke: { weight: 2, fill: "white/15" },
61
- spokeStroke: { weight: 2, fill: "white/15" },
105
+ seriesFills: [...CHART_PALETTE_DEFAULT],
106
+ ...inks(CHART_FOREGROUND, CHART_MUTED),
107
+ ...rules("white/15"),
62
108
  track: "white/10",
63
109
  background: [],
110
+ gridBackground: [],
64
111
  },
65
112
  paper: {
66
- palette: ["#2563eb", "#059669", "#d97706", "#db2777", "#7c3aed"],
67
- foreground: "#1c1917",
68
- muted: "#57534e",
69
- horizontalGrid: { weight: 2, fill: "#1c1917/12" },
70
- gridStroke: { weight: 2, fill: "#1c1917/12" },
71
- spokeStroke: { weight: 2, fill: "#1c1917/12" },
72
- track: "#1c1917/12",
113
+ seriesFills: ["#2563eb", "#059669", "#d97706", "#db2777", "#7c3aed"],
114
+ ...inks("#1c1917", "#57534e"),
115
+ ...rules("#1c1917/12"),
73
116
  background: "#fafaf9",
117
+ gridBackground: [],
74
118
  },
75
119
  ember: {
76
- palette: ["#d9603b", "#8194ad", "#e0a93b", "#5e9d6b", "#9ec85a"],
77
- foreground: "#e9e1d4",
78
- muted: "#8a7f70",
79
- horizontalGrid: { weight: 2, fill: "#2c2820" },
80
- gridStroke: { weight: 2, fill: "#2c2820" },
81
- spokeStroke: { weight: 2, fill: "#2c2820" },
82
- track: "#2c2820",
120
+ seriesFills: ["#d9603b", "#8194ad", "#e0a93b", "#5e9d6b", "#9ec85a"],
121
+ ...inks("#e9e1d4", "#8a7f70"),
122
+ ...rules("#2c2820"),
83
123
  background: "#15130e",
124
+ gridBackground: [],
84
125
  },
85
126
  neon: {
86
- palette: ["#22d3ee", "#a3e635", "#f472b6", "#facc15", "#818cf8"],
87
- foreground: "#ffffff",
88
- muted: "#94a3b8",
89
- horizontalGrid: { weight: 2, fill: "white/10" },
90
- gridStroke: { weight: 2, fill: "white/10" },
91
- spokeStroke: { weight: 2, fill: "white/10" },
92
- track: "white/10",
127
+ seriesFills: ["#22d3ee", "#a3e635", "#f472b6", "#facc15", "#818cf8"],
128
+ ...inks("#ffffff", "#94a3b8"),
129
+ ...rules("white/10"),
93
130
  background: [],
131
+ gridBackground: [],
94
132
  },
95
133
  ocean: {
96
- palette: ["#0ea5e9", "#14b8a6", "#6366f1", "#38bdf8", "#2dd4bf"],
97
- foreground: "#e0f2fe",
98
- muted: "#7dd3fc",
99
- horizontalGrid: { weight: 2, fill: "#7dd3fc/20" },
100
- gridStroke: { weight: 2, fill: "#7dd3fc/20" },
101
- spokeStroke: { weight: 2, fill: "#7dd3fc/20" },
102
- track: "#7dd3fc/20",
134
+ seriesFills: ["#0ea5e9", "#14b8a6", "#6366f1", "#38bdf8", "#2dd4bf"],
135
+ ...inks("#e0f2fe", "#7dd3fc"),
136
+ ...rules("#7dd3fc/20"),
103
137
  background: "#082f49",
138
+ gridBackground: [],
104
139
  },
105
140
  sunset: {
106
- palette: ["#f97316", "#ef4444", "#ec4899", "#f59e0b", "#a855f7"],
107
- foreground: "#fff7ed",
108
- muted: "#fdba74",
109
- horizontalGrid: { weight: 2, fill: "#fdba74/20" },
110
- gridStroke: { weight: 2, fill: "#fdba74/20" },
111
- spokeStroke: { weight: 2, fill: "#fdba74/20" },
112
- track: "#fdba74/20",
141
+ seriesFills: ["#f97316", "#ef4444", "#ec4899", "#f59e0b", "#a855f7"],
142
+ ...inks("#fff7ed", "#fdba74"),
143
+ ...rules("#fdba74/20"),
113
144
  background: [],
145
+ gridBackground: [],
114
146
  },
115
147
  pastel: {
116
- palette: ["#a5b4fc", "#f9a8d4", "#86efac", "#fde68a", "#7dd3fc"],
117
- foreground: "#f8fafc",
118
- muted: "#cbd5e1",
119
- horizontalGrid: { weight: 2, fill: "white/12" },
120
- gridStroke: { weight: 2, fill: "white/12" },
121
- spokeStroke: { weight: 2, fill: "white/12" },
122
- track: "white/12",
148
+ seriesFills: ["#a5b4fc", "#f9a8d4", "#86efac", "#fde68a", "#7dd3fc"],
149
+ ...inks("#f8fafc", "#cbd5e1"),
150
+ ...rules("white/12"),
123
151
  background: [],
152
+ gridBackground: [],
124
153
  },
125
154
  mono: {
126
- palette: ["#fafafa", "#a3a3a3", "#737373", "#d4d4d4", "#525252"],
127
- foreground: "#fafafa",
128
- muted: "#a3a3a3",
129
- horizontalGrid: { weight: 2, fill: "white/12" },
130
- gridStroke: { weight: 2, fill: "white/12" },
131
- spokeStroke: { weight: 2, fill: "white/12" },
132
- track: "white/12",
155
+ seriesFills: ["#fafafa", "#a3a3a3", "#737373", "#d4d4d4", "#525252"],
156
+ ...inks("#fafafa", "#a3a3a3"),
157
+ ...rules("white/12"),
133
158
  background: [],
159
+ gridBackground: [],
134
160
  },
135
161
  };
136
- /** Series `index`'s colour: its own `fill`, else the palette's, cycled. */
162
+ /** Series `index`'s fill: its own `fill`, else the style's series fills, cycled. */
137
163
  export function paletteFill(style, index, own) {
138
164
  if (own != null)
139
165
  return own;
140
- const palette = style.palette;
141
- return palette.length > 0 ? palette[index % palette.length] : "white";
166
+ const fills = style.seriesFills;
167
+ return fills.length > 0 ? fills[index % fills.length] : "white";
142
168
  }
143
169
  /** {@link paletteFill} for a series. */
144
170
  export function seriesFill(style, series, index) {
145
171
  return paletteFill(style, index, series.fill);
146
172
  }
147
- function face(style) {
148
- return style.fontFamily ? { fontFamily: style.fontFamily } : {};
173
+ /** A text style's size in px; an autofit or unset size reads as `fallback`. */
174
+ export function sizeOf(text, fallback = 28) {
175
+ const size = text?.fontSize;
176
+ return typeof size === "number" && Number.isFinite(size) ? size : fallback;
149
177
  }
150
- /** Axis markers, spoke labels: muted, at the base size. */
151
- export function markerText(style, textAlign = "center") {
152
- return { ...face(style), fontSize: style.fontSize, fontWeight: style.fontWeight, textAlign, fill: style.muted };
178
+ /**
179
+ * `text` as a text node takes it, aligned where the chart puts it, with `over`
180
+ * laid on top. Unset keys are dropped: an `undefined` spread onto a node is a
181
+ * value, and an unset face must stay unset so the host's default applies.
182
+ */
183
+ export function placedText(text, textAlign = "center", over) {
184
+ return textOps.styleProps({ ...textOps.mergeStyle(text, over), textAlign });
153
185
  }
154
- /** Axis captions: muted, a step larger and heavier than the markers. */
155
- export function titleText(style) {
156
- return {
157
- ...face(style),
158
- fontSize: Math.round(style.fontSize * 1.1),
159
- fontWeight: Math.min(900, style.fontWeight + 100),
160
- textAlign: "center",
161
- fill: style.muted,
162
- };
186
+ /** Axis markers on `axis`, aligned as that axis sets them. */
187
+ export function markerText(style, axis) {
188
+ return placedText(axis === "x" ? style.xLabelText : style.yLabelText, axis === "x" ? "center" : "right");
163
189
  }
164
- /** Values on marks and legend captions: the foreground, at the base size. */
190
+ /** The figures printed by the marks. */
165
191
  export function valueText(style, textAlign = "center") {
166
- return { ...face(style), fontSize: style.fontSize, fontWeight: Math.min(900, style.fontWeight + 100), textAlign, fill: style.foreground };
192
+ return placedText(style.valueText, textAlign);
167
193
  }
168
194
  /**
169
195
  * The kit axis parts' config from a style. `x` is the axis under the plot;
170
196
  * its grid lines are vertical (one per x marker), the `y` axis's horizontal.
171
197
  */
172
198
  export function axisConfigOf(style, axis) {
173
- const gap = Math.round(style.fontSize * 0.6);
199
+ const gap = Math.round(sizeOf(axis === "x" ? style.xLabelText : style.yLabelText) * 0.6);
174
200
  return {
175
- labelStyle: markerText(style, axis === "x" ? "center" : "right"),
176
- titleStyle: titleText(style),
201
+ labelStyle: markerText(style, axis),
202
+ titleStyle: placedText(axis === "x" ? style.xTitleText : style.yTitleText),
177
203
  lineStyle: axis === "x" ? style.verticalGrid : style.horizontalGrid,
178
204
  tickPadding: axis === "x" ? { top: gap } : { right: gap },
179
205
  titlePadding: axis === "x" ? { top: Math.round(gap / 2) } : { right: gap },
180
206
  };
181
207
  }
182
- /** The kit legend's config: captions in the foreground, the swatch shaped by `swatch`. */
208
+ /** The kit legend's config: captions in `legendText`, the swatch shaped by `swatch` and sized off the captions. */
183
209
  export function legendConfigOf(style) {
184
- const size = Math.max(8, Math.round(style.fontSize * 0.6));
210
+ const type = sizeOf(style.legendText);
211
+ const size = Math.max(8, Math.round(type * 0.6));
185
212
  const marker = style.swatch === "line"
186
213
  ? { width: Math.round(size * 2), height: Math.max(3, Math.round(size / 4)), borderRadius: size }
187
214
  : style.swatch === "circle"
@@ -189,9 +216,77 @@ export function legendConfigOf(style) {
189
216
  : { width: size, height: size, borderRadius: Math.round(size / 4) };
190
217
  return {
191
218
  padding: 0,
192
- textStyle: { ...face(style), fontSize: style.fontSize, fontWeight: style.fontWeight, textAlign: "left", fill: style.foreground },
193
- itemGap: Math.round(style.fontSize * 1.4),
219
+ textStyle: placedText(style.legendText, "left"),
220
+ itemGap: Math.round(type * 1.4),
194
221
  markerStyle: { ...marker, stroke: [], shadow: [] },
195
222
  };
196
223
  }
224
+ /**
225
+ * The `style` entry's hook for documents written before every run of text got
226
+ * its own field (0.1.1-alpha.1): `barRadius` became `barCornerRadius`, `palette` became `seriesFills`; `foreground`,
227
+ * `muted` and the one `fontFamily`/`fontSize`/`fontWeight` became the text
228
+ * fields as each chart derived them; a cartesian or radar `background`, which
229
+ * painted the plot, became `gridBackground`. A current style comes back as is.
230
+ */
231
+ export function migrateChartStyle(layout) {
232
+ return (value) => {
233
+ if (typeof value !== "object" || value === null || Array.isArray(value))
234
+ return value;
235
+ const old = value;
236
+ const retired = ["palette", "foreground", "muted", "fontFamily", "fontSize", "fontWeight", "barRadius"];
237
+ const plotBackground = layout === "cartesian" || layout === "radar";
238
+ if (!retired.some((key) => key in old) && !(plotBackground && "background" in old && !("gridBackground" in old)))
239
+ return value;
240
+ const { palette, foreground, muted, fontFamily, fontSize, fontWeight, barRadius, ...rest } = old;
241
+ const out = { ...rest };
242
+ // A bar radius rounded only the far end; its replacement states every corner.
243
+ if (typeof barRadius === "number" && out.barCornerRadius === undefined) {
244
+ out.barCornerRadius = { topLeft: barRadius, topRight: barRadius, bottomRight: 0, bottomLeft: 0 };
245
+ }
246
+ if (palette !== undefined && out.seriesFills === undefined)
247
+ out.seriesFills = palette;
248
+ if (plotBackground && "background" in old && !("gridBackground" in old)) {
249
+ out.gridBackground = old.background;
250
+ delete out.background;
251
+ }
252
+ const size = typeof fontSize === "number" ? fontSize : undefined;
253
+ const weight = typeof fontWeight === "number" ? fontWeight : undefined;
254
+ const text = (ink, scale = 1, heavier = 0) => {
255
+ const t = {};
256
+ if (typeof fontFamily === "string" && fontFamily !== "")
257
+ t.fontFamily = fontFamily;
258
+ if (size !== undefined)
259
+ t.fontSize = Math.round(size * scale);
260
+ if (weight !== undefined)
261
+ t.fontWeight = Math.min(900, weight + heavier);
262
+ if (ink !== undefined)
263
+ t.fill = ink;
264
+ return Object.keys(t).length > 0 ? t : undefined;
265
+ };
266
+ const fields = { legendText: text(foreground) };
267
+ if (layout === "cartesian") {
268
+ fields.xLabelText = text(muted);
269
+ fields.yLabelText = text(muted);
270
+ fields.xTitleText = text(muted, 1.1, 100);
271
+ fields.yTitleText = text(muted, 1.1, 100);
272
+ fields.valueText = text(foreground, 0.85, 100);
273
+ }
274
+ else if (layout === "pie") {
275
+ fields.labelText = text(muted);
276
+ fields.valueText = text(foreground, 1, 200);
277
+ fields.centerText = text(foreground, 1.8, 300);
278
+ }
279
+ else if (layout === "radar") {
280
+ fields.spokeText = text(muted);
281
+ }
282
+ else {
283
+ fields.labelText = text(muted);
284
+ fields.centerText = text(foreground, 1.8, 300);
285
+ }
286
+ for (const [key, field] of Object.entries(fields))
287
+ if (field && out[key] === undefined)
288
+ out[key] = field;
289
+ return out;
290
+ };
291
+ }
197
292
  //# sourceMappingURL=style.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"style.js","sourceRoot":"","sources":["../../src/kit/style.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,GASN,MAAM,mBAAmB,CAAA;AAI1B,2EAA2E;AAC3E,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAA;AAEzC,0EAA0E;AAC1E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAU,CAAA;AAErG,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,iEAAiE;IACjE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC;IAC7C,4CAA4C;IAC5C,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,SA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C","sourcesContent":["/**\n * The chart family's style: one `style` entry per chart, built from the groups\n * below, so a look saved off one chart lays onto any other (a field the other\n * chart does not draw is dropped). A chart spreads the shared groups and adds a\n * `marks` group of its own.\n */\n\nimport {\n Types,\n type Fill,\n type StrokeResolved,\n type Stroke as _Stroke,\n type StyleInput,\n type TextStyle,\n // Named so the emitted style types reach these through the sdk, not core.\n type FillResolved as _FillResolved,\n type Type as _Type,\n} from \"@motionscript/sdk\"\n\nimport type { AxisConfig, ChartSeries, LegendConfig } from \"./shared\"\n\n/** The style family every chart shares; a host keys saved styles by it. */\nexport const CHART_STYLE_FAMILY = \"chart\"\n\n/** The out-of-the-box series colours, cycled by series (or row) index. */\nexport const CHART_PALETTE_DEFAULT = [\"#4f8cff\", \"#2fbf8f\", \"#f5a524\", \"#e5547a\", \"#9b6cf0\"] as const\n\nexport const CHART_COLORS = {\n /** A colour per series (a pie's or radial's per row), cycled. */\n palette: Types.palette(CHART_PALETTE_DEFAULT),\n /** Values, legend captions, centre text. */\n foreground: Types.fill(\"#f4f4f5\"),\n /** Axis markers and captions, spoke labels. */\n muted: Types.fill(\"#a1a1aa\"),\n /** Behind the plot; none by default, so the chart reads against the stage. */\n background: Types.fill([]),\n}\n\nexport const CHART_TEXT = {\n /** Empty: the scene's default face. */\n fontFamily: Types.font(\"\"),\n /** Marker and legend size at 1080p; titles and values scale from it. */\n fontSize: Types.number(28, { min: 8, max: 160, step: 1, unit: \"px\" }),\n fontWeight: Types.number(500, { min: 100, max: 900, step: 100 }),\n}\n\nexport const CARTESIAN_GRID = {\n /** The lines along the value ticks of a column chart (one per tick); empty draws none. */\n horizontalGrid: Types.stroke({ weight: 2, fill: \"white/15\" }),\n /** The lines under the category markers; empty draws none. */\n verticalGrid: Types.stroke([]),\n /** The baseline and the value-axis rule; empty draws none. */\n axisStroke: Types.stroke([]),\n /** Read as the chart is built: whether the category (x) axis row is drawn. */\n showXAxis: Types.boolean(true, { animatable: false }),\n /** Read as the chart is built: whether the value (y) axis column is drawn. */\n showYAxis: Types.boolean(true, { animatable: false }),\n}\n\nexport type LegendPosition = \"bottom\" | \"top\" | \"right\" | \"none\"\nexport type LegendSwatch = \"square\" | \"circle\" | \"line\"\n\nexport const CHART_LEGEND = {\n /** Read as the chart is built: where the legend sits, or `none`. */\n legend: Types.oneOf([\"bottom\", \"top\", \"right\", \"none\"] as const, { animatable: false }),\n swatch: Types.oneOf([\"square\", \"circle\", \"line\"] as const),\n}\n\n/** The type fields, and the two text colours: what every text helper reads. */\nexport interface ChartTextStyle {\n readonly foreground: Fill\n readonly muted: Fill\n readonly fontFamily: string\n readonly fontSize: number\n readonly fontWeight: number\n}\n\n/** The fields every chart's style resolves, whichever groups it spreads. */\nexport interface ChartStyleBase extends ChartTextStyle {\n readonly palette: readonly Fill[]\n readonly background: Fill\n readonly legend: LegendPosition\n readonly swatch: LegendSwatch\n}\n\n/** The cartesian grid fields, for the line and bar charts. */\nexport interface CartesianStyle extends ChartStyleBase {\n readonly horizontalGrid: StrokeResolved[]\n readonly verticalGrid: StrokeResolved[]\n readonly axisStroke: StrokeResolved[]\n readonly showXAxis: boolean\n readonly showYAxis: boolean\n}\n\n/** The rule and track fields a preset restates so its rules read on its background (a chart keeps those it draws). */\nconst _PRESET_RULES = {\n horizontalGrid: CARTESIAN_GRID.horizontalGrid,\n gridStroke: Types.stroke([]),\n spokeStroke: Types.stroke([]),\n track: Types.fill([]),\n}\n\n/** A preset's fields: any chart's, so one preset dresses every chart. */\nexport type ChartStylePreset = StyleInput<typeof CHART_COLORS & typeof CHART_TEXT & typeof _PRESET_RULES>\n\n/** Ready-made looks, each stating every colour so applying one replaces the last. */\nexport const CHART_STYLE_PRESETS = {\n midnight: {\n palette: [...CHART_PALETTE_DEFAULT],\n foreground: \"#f4f4f5\",\n muted: \"#a1a1aa\",\n horizontalGrid: { weight: 2, fill: \"white/15\" },\n gridStroke: { weight: 2, fill: \"white/15\" },\n spokeStroke: { weight: 2, fill: \"white/15\" },\n track: \"white/10\",\n background: [],\n },\n paper: {\n palette: [\"#2563eb\", \"#059669\", \"#d97706\", \"#db2777\", \"#7c3aed\"],\n foreground: \"#1c1917\",\n muted: \"#57534e\",\n horizontalGrid: { weight: 2, fill: \"#1c1917/12\" },\n gridStroke: { weight: 2, fill: \"#1c1917/12\" },\n spokeStroke: { weight: 2, fill: \"#1c1917/12\" },\n track: \"#1c1917/12\",\n background: \"#fafaf9\",\n },\n ember: {\n palette: [\"#d9603b\", \"#8194ad\", \"#e0a93b\", \"#5e9d6b\", \"#9ec85a\"],\n foreground: \"#e9e1d4\",\n muted: \"#8a7f70\",\n horizontalGrid: { weight: 2, fill: \"#2c2820\" },\n gridStroke: { weight: 2, fill: \"#2c2820\" },\n spokeStroke: { weight: 2, fill: \"#2c2820\" },\n track: \"#2c2820\",\n background: \"#15130e\",\n },\n neon: {\n palette: [\"#22d3ee\", \"#a3e635\", \"#f472b6\", \"#facc15\", \"#818cf8\"],\n foreground: \"#ffffff\",\n muted: \"#94a3b8\",\n horizontalGrid: { weight: 2, fill: \"white/10\" },\n gridStroke: { weight: 2, fill: \"white/10\" },\n spokeStroke: { weight: 2, fill: \"white/10\" },\n track: \"white/10\",\n background: [],\n },\n ocean: {\n palette: [\"#0ea5e9\", \"#14b8a6\", \"#6366f1\", \"#38bdf8\", \"#2dd4bf\"],\n foreground: \"#e0f2fe\",\n muted: \"#7dd3fc\",\n horizontalGrid: { weight: 2, fill: \"#7dd3fc/20\" },\n gridStroke: { weight: 2, fill: \"#7dd3fc/20\" },\n spokeStroke: { weight: 2, fill: \"#7dd3fc/20\" },\n track: \"#7dd3fc/20\",\n background: \"#082f49\",\n },\n sunset: {\n palette: [\"#f97316\", \"#ef4444\", \"#ec4899\", \"#f59e0b\", \"#a855f7\"],\n foreground: \"#fff7ed\",\n muted: \"#fdba74\",\n horizontalGrid: { weight: 2, fill: \"#fdba74/20\" },\n gridStroke: { weight: 2, fill: \"#fdba74/20\" },\n spokeStroke: { weight: 2, fill: \"#fdba74/20\" },\n track: \"#fdba74/20\",\n background: [],\n },\n pastel: {\n palette: [\"#a5b4fc\", \"#f9a8d4\", \"#86efac\", \"#fde68a\", \"#7dd3fc\"],\n foreground: \"#f8fafc\",\n muted: \"#cbd5e1\",\n horizontalGrid: { weight: 2, fill: \"white/12\" },\n gridStroke: { weight: 2, fill: \"white/12\" },\n spokeStroke: { weight: 2, fill: \"white/12\" },\n track: \"white/12\",\n background: [],\n },\n mono: {\n palette: [\"#fafafa\", \"#a3a3a3\", \"#737373\", \"#d4d4d4\", \"#525252\"],\n foreground: \"#fafafa\",\n muted: \"#a3a3a3\",\n horizontalGrid: { weight: 2, fill: \"white/12\" },\n gridStroke: { weight: 2, fill: \"white/12\" },\n spokeStroke: { weight: 2, fill: \"white/12\" },\n track: \"white/12\",\n background: [],\n },\n} satisfies Record<string, ChartStylePreset>\n\n/** Series `index`'s colour: its own `fill`, else the palette's, cycled. */\nexport function paletteFill(style: Pick<ChartStyleBase, \"palette\">, index: number, own?: Fill): Fill {\n if (own != null) return own\n const palette = style.palette\n return palette.length > 0 ? palette[index % palette.length] : \"white\"\n}\n\n/** {@link paletteFill} for a series. */\nexport function seriesFill(style: Pick<ChartStyleBase, \"palette\">, series: ChartSeries, index: number): Fill {\n return paletteFill(style, index, series.fill)\n}\n\nfunction face(style: Pick<ChartTextStyle, \"fontFamily\">): Pick<TextStyle, \"fontFamily\"> {\n return style.fontFamily ? { fontFamily: style.fontFamily } : {}\n}\n\n/** Axis markers, spoke labels: muted, at the base size. */\nexport function markerText(style: ChartTextStyle, textAlign: TextStyle[\"textAlign\"] = \"center\"): TextStyle {\n return { ...face(style), fontSize: style.fontSize, fontWeight: style.fontWeight, textAlign, fill: style.muted }\n}\n\n/** Axis captions: muted, a step larger and heavier than the markers. */\nexport function titleText(style: ChartTextStyle): TextStyle {\n return {\n ...face(style),\n fontSize: Math.round(style.fontSize * 1.1),\n fontWeight: Math.min(900, style.fontWeight + 100),\n textAlign: \"center\",\n fill: style.muted,\n }\n}\n\n/** Values on marks and legend captions: the foreground, at the base size. */\nexport function valueText(style: ChartTextStyle, textAlign: TextStyle[\"textAlign\"] = \"center\"): TextStyle {\n return { ...face(style), fontSize: style.fontSize, fontWeight: Math.min(900, style.fontWeight + 100), textAlign, fill: style.foreground }\n}\n\n/**\n * The kit axis parts' config from a style. `x` is the axis under the plot;\n * its grid lines are vertical (one per x marker), the `y` axis's horizontal.\n */\nexport function axisConfigOf(style: Pick<CartesianStyle, \"verticalGrid\" | \"horizontalGrid\"> & ChartTextStyle, axis: \"x\" | \"y\"): AxisConfig {\n const gap = Math.round(style.fontSize * 0.6)\n return {\n labelStyle: markerText(style, axis === \"x\" ? \"center\" : \"right\"),\n titleStyle: titleText(style),\n lineStyle: axis === \"x\" ? style.verticalGrid : style.horizontalGrid,\n tickPadding: axis === \"x\" ? { top: gap } : { right: gap },\n titlePadding: axis === \"x\" ? { top: Math.round(gap / 2) } : { right: gap },\n }\n}\n\n/** The kit legend's config: captions in the foreground, the swatch shaped by `swatch`. */\nexport function legendConfigOf(style: ChartTextStyle & Pick<ChartStyleBase, \"swatch\">): LegendConfig {\n const size = Math.max(8, Math.round(style.fontSize * 0.6))\n const marker =\n style.swatch === \"line\"\n ? { width: Math.round(size * 2), height: Math.max(3, Math.round(size / 4)), borderRadius: size }\n : style.swatch === \"circle\"\n ? { width: size, height: size, borderRadius: size / 2 }\n : { width: size, height: size, borderRadius: Math.round(size / 4) }\n return {\n padding: 0,\n textStyle: { ...face(style), fontSize: style.fontSize, fontWeight: style.fontWeight, textAlign: \"left\", fill: style.foreground },\n itemGap: Math.round(style.fontSize * 1.4),\n markerStyle: { ...marker, stroke: [], shadow: [] },\n }\n}\n"]}
1
+ {"version":3,"file":"style.js","sourceRoot":"","sources":["../../src/kit/style.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,KAAK,EACL,OAAO,GASR,MAAM,mBAAmB,CAAA;AAI1B,oFAAoF;AACpF,MAAM,CAAC,MAAM,kBA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CAAC,CAAA;QAChC,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;YAC9B,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;QAChD,CAAC;QACD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,IAAI,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS;gBAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACxG,OAAO,GAAG,CAAA;IACZ,CAAC,CAAA;AACH,CAAC","sourcesContent":["/**\n * The chart family's style: one `style` entry per chart, built from the groups\n * below, so a look saved off one chart lays onto any other (a field the other\n * chart does not draw is dropped). A chart spreads the shared groups and adds a\n * `marks` group of its own. Every run of text a chart draws is its own\n * `Types.typography` field, so axis labels, titles, values and the legend are\n * each set the way a text node is.\n */\n\nimport {\n Types,\n textOps,\n type Fill,\n type StrokeResolved,\n type Stroke as _Stroke,\n type StyleInput,\n type TextStyle,\n // Named so the emitted style types reach these through the sdk, not core.\n type FillResolved as _FillResolved,\n type Type as _Type,\n} from \"@motionscript/sdk\"\n\nimport type { AxisConfig, ChartSeries, LegendConfig } from \"./shared\"\n\n/** The style family every chart shares; the built-in presets are written for it. */\nexport const CHART_STYLE_FAMILY = \"chart\"\n\n/** The out-of-the-box series fills, cycled by series (or row) index. */\nexport const CHART_PALETTE_DEFAULT = [\"#4f8cff\", \"#2fbf8f\", \"#f5a524\", \"#e5547a\", \"#9b6cf0\"] as const\n\n/** The default ink of values, legend captions and centre text, on the dark stage. */\nexport const CHART_FOREGROUND = \"#f4f4f5\"\n/** The default ink of axis markers, axis captions and spoke labels. */\nexport const CHART_MUTED = \"#a1a1aa\"\n\nexport const CHART_SERIES = {\n /** A fill per series (a pie's or radial's per row), cycled; each may stack several paints. */\n seriesFills: Types.palette(CHART_PALETTE_DEFAULT),\n}\n\nexport const CHART_BACKGROUND = {\n /** Behind the whole chart, legend and axes included; none by default, so the chart reads against the stage. */\n background: Types.fill([]),\n}\n\nexport const GRID_BACKGROUND = {\n ...CHART_BACKGROUND,\n /** Behind the plot only, under the grid lines; none by default. */\n gridBackground: Types.fill([]),\n}\n\n/** The legend's captions, which every chart with a legend draws. */\nexport const LEGEND_TEXT = {\n legendText: Types.typography({ fontSize: 28, fontWeight: 500, fill: CHART_FOREGROUND }),\n}\n\nexport const CARTESIAN_TEXT = {\n /** The markers under the plot: categories on a column chart, values on a horizontal bar chart. */\n xLabelText: Types.typography({ fontSize: 28, fontWeight: 500, fill: CHART_MUTED }),\n /** The caption under the plot. */\n xTitleText: Types.typography({ fontSize: 31, fontWeight: 600, fill: CHART_MUTED }),\n /** The markers beside the plot. */\n yLabelText: Types.typography({ fontSize: 28, fontWeight: 500, fill: CHART_MUTED }),\n /** The caption beside the plot, turned on its side. */\n yTitleText: Types.typography({ fontSize: 31, fontWeight: 600, fill: CHART_MUTED }),\n /** The figures printed by the marks. */\n valueText: Types.typography({ fontSize: 24, fontWeight: 600, fill: CHART_FOREGROUND }),\n ...LEGEND_TEXT,\n}\n\nexport const CARTESIAN_GRID = {\n /** The lines along the value ticks of a column chart (one per tick); empty draws none. */\n horizontalGrid: Types.stroke({ weight: 2, fill: \"white/15\" }),\n /** The lines under the category markers; empty draws none. */\n verticalGrid: Types.stroke([]),\n /** The baseline and the value-axis rule; empty draws none. */\n axisStroke: Types.stroke([]),\n /** Read as the chart is built: whether the category (x) axis row is drawn. */\n showXAxis: Types.boolean(true, { animatable: false }),\n /** Read as the chart is built: whether the value (y) axis column is drawn. */\n showYAxis: Types.boolean(true, { animatable: false }),\n}\n\nexport type LegendPosition = \"bottom\" | \"top\" | \"right\" | \"none\"\nexport type LegendSwatch = \"square\" | \"circle\" | \"line\"\n\nexport const CHART_LEGEND = {\n /** Read as the chart is built: where the legend sits, or `none`. */\n legend: Types.oneOf([\"bottom\", \"top\", \"right\", \"none\"] as const, { animatable: false }),\n swatch: Types.oneOf([\"square\", \"circle\", \"line\"] as const),\n}\n\n/** The fields every chart's style resolves, whichever groups it spreads. */\nexport interface ChartStyleBase {\n readonly seriesFills: readonly Fill[]\n readonly background: Fill\n readonly legendText: TextStyle\n readonly legend: LegendPosition\n readonly swatch: LegendSwatch\n}\n\n/** The cartesian fields, for the line and bar charts. */\nexport interface CartesianStyle extends ChartStyleBase {\n readonly gridBackground: Fill\n readonly xLabelText: TextStyle\n readonly xTitleText: TextStyle\n readonly yLabelText: TextStyle\n readonly yTitleText: TextStyle\n readonly valueText: TextStyle\n readonly horizontalGrid: StrokeResolved[]\n readonly verticalGrid: StrokeResolved[]\n readonly axisStroke: StrokeResolved[]\n readonly showXAxis: boolean\n readonly showYAxis: boolean\n}\n\n/** The fields a preset restates so its rules and text read on its background (a chart keeps those it draws). */\nconst _PRESET_FIELDS = {\n ...CHART_SERIES,\n ...GRID_BACKGROUND,\n ...CARTESIAN_TEXT,\n labelText: Types.typography(),\n centerText: Types.typography(),\n spokeText: Types.typography(),\n horizontalGrid: CARTESIAN_GRID.horizontalGrid,\n gridStroke: Types.stroke([]),\n spokeStroke: Types.stroke([]),\n track: Types.fill([]),\n}\n\n/** A preset's fields: any chart's, so one preset dresses every chart. */\nexport type ChartStylePreset = StyleInput<typeof _PRESET_FIELDS>\n\n/** Every text field's ink: `foreground` for values, the legend and centre text, `muted` for markers and captions. */\nfunction inks(foreground: string, muted: string) {\n const on = (fill: string) => ({ fill })\n return {\n xLabelText: on(muted),\n xTitleText: on(muted),\n yLabelText: on(muted),\n yTitleText: on(muted),\n valueText: on(foreground),\n legendText: on(foreground),\n labelText: on(muted),\n centerText: on(foreground),\n spokeText: on(muted),\n } satisfies ChartStylePreset\n}\n\n/** Every rule a chart draws, and a radial's track, in one paint. */\nfunction rules(fill: string) {\n return {\n horizontalGrid: { weight: 2, fill },\n gridStroke: { weight: 2, fill },\n spokeStroke: { weight: 2, fill },\n track: fill,\n } satisfies ChartStylePreset\n}\n\n/** Ready-made looks, each stating every colour so applying one replaces the last. */\nexport const CHART_STYLE_PRESETS = {\n midnight: {\n seriesFills: [...CHART_PALETTE_DEFAULT],\n ...inks(CHART_FOREGROUND, CHART_MUTED),\n ...rules(\"white/15\"),\n track: \"white/10\",\n background: [],\n gridBackground: [],\n },\n paper: {\n seriesFills: [\"#2563eb\", \"#059669\", \"#d97706\", \"#db2777\", \"#7c3aed\"],\n ...inks(\"#1c1917\", \"#57534e\"),\n ...rules(\"#1c1917/12\"),\n background: \"#fafaf9\",\n gridBackground: [],\n },\n ember: {\n seriesFills: [\"#d9603b\", \"#8194ad\", \"#e0a93b\", \"#5e9d6b\", \"#9ec85a\"],\n ...inks(\"#e9e1d4\", \"#8a7f70\"),\n ...rules(\"#2c2820\"),\n background: \"#15130e\",\n gridBackground: [],\n },\n neon: {\n seriesFills: [\"#22d3ee\", \"#a3e635\", \"#f472b6\", \"#facc15\", \"#818cf8\"],\n ...inks(\"#ffffff\", \"#94a3b8\"),\n ...rules(\"white/10\"),\n background: [],\n gridBackground: [],\n },\n ocean: {\n seriesFills: [\"#0ea5e9\", \"#14b8a6\", \"#6366f1\", \"#38bdf8\", \"#2dd4bf\"],\n ...inks(\"#e0f2fe\", \"#7dd3fc\"),\n ...rules(\"#7dd3fc/20\"),\n background: \"#082f49\",\n gridBackground: [],\n },\n sunset: {\n seriesFills: [\"#f97316\", \"#ef4444\", \"#ec4899\", \"#f59e0b\", \"#a855f7\"],\n ...inks(\"#fff7ed\", \"#fdba74\"),\n ...rules(\"#fdba74/20\"),\n background: [],\n gridBackground: [],\n },\n pastel: {\n seriesFills: [\"#a5b4fc\", \"#f9a8d4\", \"#86efac\", \"#fde68a\", \"#7dd3fc\"],\n ...inks(\"#f8fafc\", \"#cbd5e1\"),\n ...rules(\"white/12\"),\n background: [],\n gridBackground: [],\n },\n mono: {\n seriesFills: [\"#fafafa\", \"#a3a3a3\", \"#737373\", \"#d4d4d4\", \"#525252\"],\n ...inks(\"#fafafa\", \"#a3a3a3\"),\n ...rules(\"white/12\"),\n background: [],\n gridBackground: [],\n },\n} satisfies Record<string, ChartStylePreset>\n\n/** Series `index`'s fill: its own `fill`, else the style's series fills, cycled. */\nexport function paletteFill(style: Pick<ChartStyleBase, \"seriesFills\">, index: number, own?: Fill): Fill {\n if (own != null) return own\n const fills = style.seriesFills\n return fills.length > 0 ? fills[index % fills.length] : \"white\"\n}\n\n/** {@link paletteFill} for a series. */\nexport function seriesFill(style: Pick<ChartStyleBase, \"seriesFills\">, series: ChartSeries, index: number): Fill {\n return paletteFill(style, index, series.fill)\n}\n\n/** A text style's size in px; an autofit or unset size reads as `fallback`. */\nexport function sizeOf(text: TextStyle | undefined, fallback = 28): number {\n const size = text?.fontSize\n return typeof size === \"number\" && Number.isFinite(size) ? size : fallback\n}\n\n/**\n * `text` as a text node takes it, aligned where the chart puts it, with `over`\n * laid on top. Unset keys are dropped: an `undefined` spread onto a node is a\n * value, and an unset face must stay unset so the host's default applies.\n */\nexport function placedText(text: TextStyle, textAlign: TextStyle[\"textAlign\"] = \"center\", over?: TextStyle): TextStyle {\n return textOps.styleProps({ ...textOps.mergeStyle(text, over), textAlign }) as TextStyle\n}\n\n/** Axis markers on `axis`, aligned as that axis sets them. */\nexport function markerText(style: Pick<CartesianStyle, \"xLabelText\" | \"yLabelText\">, axis: \"x\" | \"y\"): TextStyle {\n return placedText(axis === \"x\" ? style.xLabelText : style.yLabelText, axis === \"x\" ? \"center\" : \"right\")\n}\n\n/** The figures printed by the marks. */\nexport function valueText(style: Pick<CartesianStyle, \"valueText\">, textAlign: TextStyle[\"textAlign\"] = \"center\"): TextStyle {\n return placedText(style.valueText, textAlign)\n}\n\n/**\n * The kit axis parts' config from a style. `x` is the axis under the plot;\n * its grid lines are vertical (one per x marker), the `y` axis's horizontal.\n */\nexport function axisConfigOf(\n style: Pick<CartesianStyle, \"verticalGrid\" | \"horizontalGrid\" | \"xLabelText\" | \"xTitleText\" | \"yLabelText\" | \"yTitleText\">,\n axis: \"x\" | \"y\"\n): AxisConfig {\n const gap = Math.round(sizeOf(axis === \"x\" ? style.xLabelText : style.yLabelText) * 0.6)\n return {\n labelStyle: markerText(style, axis),\n titleStyle: placedText(axis === \"x\" ? style.xTitleText : style.yTitleText),\n lineStyle: axis === \"x\" ? style.verticalGrid : style.horizontalGrid,\n tickPadding: axis === \"x\" ? { top: gap } : { right: gap },\n titlePadding: axis === \"x\" ? { top: Math.round(gap / 2) } : { right: gap },\n }\n}\n\n/** The kit legend's config: captions in `legendText`, the swatch shaped by `swatch` and sized off the captions. */\nexport function legendConfigOf(style: Pick<ChartStyleBase, \"swatch\" | \"legendText\">): LegendConfig {\n const type = sizeOf(style.legendText)\n const size = Math.max(8, Math.round(type * 0.6))\n const marker =\n style.swatch === \"line\"\n ? { width: Math.round(size * 2), height: Math.max(3, Math.round(size / 4)), borderRadius: size }\n : style.swatch === \"circle\"\n ? { width: size, height: size, borderRadius: size / 2 }\n : { width: size, height: size, borderRadius: Math.round(size / 4) }\n return {\n padding: 0,\n textStyle: placedText(style.legendText, \"left\"),\n itemGap: Math.round(type * 1.4),\n markerStyle: { ...marker, stroke: [], shadow: [] },\n }\n}\n\n/** Which text a chart drew from the retired shared text fields. */\nexport type ChartTextLayout = \"cartesian\" | \"pie\" | \"radar\" | \"radial\"\n\n/**\n * The `style` entry's hook for documents written before every run of text got\n * its own field (0.1.1-alpha.1): `barRadius` became `barCornerRadius`, `palette` became `seriesFills`; `foreground`,\n * `muted` and the one `fontFamily`/`fontSize`/`fontWeight` became the text\n * fields as each chart derived them; a cartesian or radar `background`, which\n * painted the plot, became `gridBackground`. A current style comes back as is.\n */\nexport function migrateChartStyle(layout: ChartTextLayout): (value: unknown) => unknown {\n return (value) => {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) return value\n const old = value as Record<string, unknown>\n const retired = [\"palette\", \"foreground\", \"muted\", \"fontFamily\", \"fontSize\", \"fontWeight\", \"barRadius\"]\n const plotBackground = layout === \"cartesian\" || layout === \"radar\"\n if (!retired.some((key) => key in old) && !(plotBackground && \"background\" in old && !(\"gridBackground\" in old))) return value\n\n const { palette, foreground, muted, fontFamily, fontSize, fontWeight, barRadius, ...rest } = old\n const out: Record<string, unknown> = { ...rest }\n // A bar radius rounded only the far end; its replacement states every corner.\n if (typeof barRadius === \"number\" && out.barCornerRadius === undefined) {\n out.barCornerRadius = { topLeft: barRadius, topRight: barRadius, bottomRight: 0, bottomLeft: 0 }\n }\n if (palette !== undefined && out.seriesFills === undefined) out.seriesFills = palette\n if (plotBackground && \"background\" in old && !(\"gridBackground\" in old)) {\n out.gridBackground = old.background\n delete out.background\n }\n const size = typeof fontSize === \"number\" ? fontSize : undefined\n const weight = typeof fontWeight === \"number\" ? fontWeight : undefined\n const text = (ink: unknown, scale = 1, heavier = 0): Record<string, unknown> | undefined => {\n const t: Record<string, unknown> = {}\n if (typeof fontFamily === \"string\" && fontFamily !== \"\") t.fontFamily = fontFamily\n if (size !== undefined) t.fontSize = Math.round(size * scale)\n if (weight !== undefined) t.fontWeight = Math.min(900, weight + heavier)\n if (ink !== undefined) t.fill = ink\n return Object.keys(t).length > 0 ? t : undefined\n }\n const fields: Record<string, Record<string, unknown> | undefined> = { legendText: text(foreground) }\n if (layout === \"cartesian\") {\n fields.xLabelText = text(muted)\n fields.yLabelText = text(muted)\n fields.xTitleText = text(muted, 1.1, 100)\n fields.yTitleText = text(muted, 1.1, 100)\n fields.valueText = text(foreground, 0.85, 100)\n } else if (layout === \"pie\") {\n fields.labelText = text(muted)\n fields.valueText = text(foreground, 1, 200)\n fields.centerText = text(foreground, 1.8, 300)\n } else if (layout === \"radar\") {\n fields.spokeText = text(muted)\n } else {\n fields.labelText = text(muted)\n fields.centerText = text(foreground, 1.8, 300)\n }\n for (const [key, field] of Object.entries(fields)) if (field && out[key] === undefined) out[key] = field\n return out\n }\n}\n"]}