@lexaxai/spreadsheet-engine 0.0.0-stage → 0.1.0-dryrun.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,440 @@
1
+ // How a chart's elements look: colours, fonts, fills, outlines, effects,
2
+ // layouts, titles, the legend, 3-D surfaces and the axes.
3
+
4
+ import type { ChartLegendPosition, ChartPictureOptions, ChartTimeUnit } from './chart';
5
+
6
+ /**
7
+ * A colour: either a literal (`'#4472C4'`), a theme reference (which lets the chart
8
+ * re-colour with the workbook theme), or the parsed forms `{scheme}`/`{rgb}` that
9
+ * `getCharts()` reads back - the writer accepts all of them, so a read-back colour
10
+ * can be assigned straight back into a series.
11
+ */
12
+ export type ChartColor =
13
+ | string
14
+ | {
15
+ /** theme slot, for example 'accent1' */
16
+ theme: string;
17
+ /** luminance modulation, in thousandths of a percent */
18
+ lumMod?: number;
19
+ lumOff?: number;
20
+ alpha?: number;
21
+ }
22
+ | {
23
+ /** theme slot as read back from a file, for example 'accent1' */
24
+ scheme: string;
25
+ lumMod?: number;
26
+ lumOff?: number;
27
+ satMod?: number;
28
+ shade?: number;
29
+ tint?: number;
30
+ alpha?: number;
31
+ }
32
+ | {
33
+ /** six hex digits as read back from a file, for example '7030A0' */
34
+ rgb: string;
35
+ lumMod?: number;
36
+ lumOff?: number;
37
+ satMod?: number;
38
+ shade?: number;
39
+ tint?: number;
40
+ alpha?: number;
41
+ };
42
+
43
+ /**
44
+ * The font of a chart's text: its size, its bold and italic styles, its colour and its typeface.
45
+ */
46
+ export interface ChartFont {
47
+ /** font size in points */
48
+ size?: number;
49
+ /**
50
+ * Whether the text is bold.
51
+ */
52
+ bold?: boolean;
53
+ /**
54
+ * Whether the text is in italics.
55
+ */
56
+ italic?: boolean;
57
+ /**
58
+ * The colour of the text, as a `ChartColor`.
59
+ */
60
+ color?: ChartColor;
61
+ /** typeface name; omit to inherit the theme's minor font */
62
+ name?: string;
63
+ }
64
+
65
+ /**
66
+ * What goes inside a shape, a line or a marker. Units are those of Excel's
67
+ * Format pane: stop positions and rectangles in percent, angles in degrees.
68
+ * A bare colour is a solid fill.
69
+ */
70
+ export type ChartFill =
71
+ | 'none'
72
+ | ChartColor
73
+ | {type: 'solid'; color: ChartColor; transparency?: number}
74
+ | {
75
+ type: 'gradient';
76
+ stops: Array<{position: number; color: ChartColor}>;
77
+ /** linear gradient angle; leave out for a path gradient */
78
+ angle?: number;
79
+ scaled?: boolean;
80
+ path?: 'circle' | 'rect' | 'shape';
81
+ focus?: {left?: number; top?: number; right?: number; bottom?: number};
82
+ tile?: {left?: number; top?: number; right?: number; bottom?: number};
83
+ flip?: 'none' | 'x' | 'y' | 'xy';
84
+ rotateWithShape?: boolean;
85
+ }
86
+ | {
87
+ type: 'pattern';
88
+ /** one of the 54 preset patterns, for example 'pct50', 'dkDnDiag', 'smCheck' */
89
+ pattern: string;
90
+ fg?: ChartColor;
91
+ bg?: ChartColor;
92
+ }
93
+ | {
94
+ type: 'picture';
95
+ /** the id `workbook.addImage` returned */
96
+ image: number;
97
+ stretch?: boolean;
98
+ tile?: {offsetX?: number; offsetY?: number; scaleX?: number; scaleY?: number; flip?: string; align?: string};
99
+ transparency?: number;
100
+ rotateWithShape?: boolean;
101
+ };
102
+
103
+ /** An outline: a series line, a border, a marker's edge. */
104
+ export interface ChartOutline {
105
+ /**
106
+ * The colour of the outline, as a `ChartColor`.
107
+ */
108
+ color?: ChartColor;
109
+ /** any fill, for a gradient line */
110
+ fill?: ChartFill;
111
+ /** weight in points */
112
+ width?: number;
113
+ /** a preset, or dash and space lengths in percent of the width */
114
+ dash?: string | Array<{dash: number; space: number}>;
115
+ /**
116
+ * The shape of the ends of the line: `'rnd'` (round), `'sq'` (square) or `'flat'`.
117
+ */
118
+ cap?: 'rnd' | 'sq' | 'flat';
119
+ /**
120
+ * How the outline is drawn: `'sng'` as one line, `'dbl'` as two, `'thickThin'` and `'thinThick'` as two of
121
+ * unequal weight, or `'tri'` as three.
122
+ */
123
+ compound?: 'sng' | 'dbl' | 'thickThin' | 'thinThick' | 'tri';
124
+ /**
125
+ * How the corners of the line join: `'round'`, `'bevel'` or `'miter'`.
126
+ */
127
+ join?: 'round' | 'bevel' | 'miter';
128
+ /**
129
+ * The limit on a mitred corner, in percent of the line width, past which the corner is bevelled.
130
+ */
131
+ miterLimit?: number;
132
+ /**
133
+ * The arrowhead at the start of the line, written as `headEnd`: its `type`, and its `width` and `length`.
134
+ */
135
+ head?: {type: 'none' | 'triangle' | 'stealth' | 'diamond' | 'oval' | 'arrow'; width?: 'sm' | 'med' | 'lg'; length?: 'sm' | 'med' | 'lg'};
136
+ /**
137
+ * The arrowhead at the end of the line, written as `tailEnd`: its `type`, and its `width` and `length`.
138
+ */
139
+ tail?: {type: 'none' | 'triangle' | 'stealth' | 'diamond' | 'oval' | 'arrow'; width?: 'sm' | 'med' | 'lg'; length?: 'sm' | 'med' | 'lg'};
140
+ /**
141
+ * The transparency of the line, in percent.
142
+ */
143
+ transparency?: number;
144
+ }
145
+
146
+ /**
147
+ * A line in a chart, such as a series' line or a trendline. It takes the outline options, and `smooth` draws
148
+ * a series' line as a smooth curve through its points.
149
+ */
150
+ export interface ChartLine extends ChartOutline {
151
+ /** smooth the line between points */
152
+ smooth?: boolean;
153
+ }
154
+
155
+ /** Excel's Effects tab, in points, degrees and percent. */
156
+ export interface ChartEffects {
157
+ /**
158
+ * An outer shadow, with its blur and distance in points, its direction in degrees and its scale in percent.
159
+ */
160
+ shadow?: {blur?: number; distance?: number; direction?: number; color?: ChartColor; scaleX?: number; scaleY?: number};
161
+ /**
162
+ * An inner shadow, with its blur and distance in points and its direction in degrees.
163
+ */
164
+ innerShadow?: {blur?: number; distance?: number; direction?: number; color?: ChartColor};
165
+ /** the file requires a colour here; Excel refused a workbook holding a preset shadow without one */
166
+ presetShadow?: {preset: string; distance?: number; direction?: number; color: ChartColor};
167
+ /** the file requires a colour here, as for a preset shadow */
168
+ glow?: {radius?: number; color: ChartColor};
169
+ /**
170
+ * A soft edge that fades the outline of the shape over a radius in points.
171
+ */
172
+ softEdge?: {radius: number};
173
+ /**
174
+ * A reflection of the shape, with its blur and distance in points, its direction in degrees, and its opacity
175
+ * in percent at the start and at the end.
176
+ */
177
+ reflection?: {blur?: number; startOpacity?: number; endOpacity?: number; distance?: number; direction?: number};
178
+ /**
179
+ * A blur, with its radius in points. With `grow`, the bounding box of the shape grows with the blur.
180
+ */
181
+ blur?: {radius?: number; grow?: boolean};
182
+ }
183
+
184
+ /** The formatting any filled chart element takes, as in Excel's Format pane. */
185
+ export interface ChartShapeFormat {
186
+ /**
187
+ * The fill of the shape: a colour, `'none'`, or a `ChartFill` such as a gradient, a pattern or a picture.
188
+ */
189
+ fill?: ChartFill;
190
+ /** the outline; `line` is accepted too */
191
+ border?: ChartOutline | false;
192
+ /**
193
+ * The effects of the shape, as `ChartEffects`, or `false` for none.
194
+ */
195
+ effects?: ChartEffects | false;
196
+ /** percent, applied to a solid fill */
197
+ transparency?: number;
198
+ }
199
+
200
+ /**
201
+ * A position set by hand, in fractions of the chart area. With mode 'edge'
202
+ * (the default) from the chart's top-left corner; with 'factor' an offset from
203
+ * where Excel would put the element.
204
+ */
205
+ export interface ChartLayout {
206
+ /**
207
+ * The left edge of the element, as a fraction of the chart area. With `xMode` `'edge'`, the default, it is
208
+ * measured from the chart's top left corner; with `'factor'`, it is an offset from where Excel would put the
209
+ * element.
210
+ */
211
+ x?: number;
212
+ /**
213
+ * The top edge of the element, as a fraction of the chart area, read as `x` is read, with `yMode`.
214
+ */
215
+ y?: number;
216
+ /**
217
+ * The width of the element, as a fraction of the chart area. With `wMode` `'edge'` it is where the right
218
+ * edge stands.
219
+ */
220
+ w?: number;
221
+ /**
222
+ * The height of the element, as a fraction of the chart area. With `hMode` `'edge'` it is where the bottom
223
+ * edge stands.
224
+ */
225
+ h?: number;
226
+ /**
227
+ * How `x` is read: `'edge'`, the default, from the chart's top left corner, or `'factor'`, as an offset from
228
+ * where Excel would put the element.
229
+ */
230
+ xMode?: 'edge' | 'factor';
231
+ /**
232
+ * How `y` is read, as `xMode` reads `x`.
233
+ */
234
+ yMode?: 'edge' | 'factor';
235
+ /**
236
+ * How `w` is read: `'edge'` makes it where the right edge stands. Otherwise it is the width.
237
+ */
238
+ wMode?: 'edge' | 'factor';
239
+ /**
240
+ * How `h` is read: `'edge'` makes it where the bottom edge stands. Otherwise it is the height.
241
+ */
242
+ hMode?: 'edge' | 'factor';
243
+ }
244
+
245
+ /** A run of title text with formatting of its own. */
246
+ export interface ChartTextRun {
247
+ /**
248
+ * The words of the run.
249
+ */
250
+ text: string;
251
+ /**
252
+ * The font of the run, as a `ChartFont`, with its underline and strike-through styles and a baseline offset
253
+ * for superscript and subscript.
254
+ */
255
+ font?: ChartFont & {underline?: string; strike?: string; baseline?: number};
256
+ }
257
+
258
+ /** The chart's title or an axis's. */
259
+ export interface ChartTitle extends ChartShapeFormat {
260
+ /**
261
+ * The words of the title. A title object with no words takes Excel's own words, as `title: true` does.
262
+ */
263
+ text?: string;
264
+ /** the words in pieces, each with its own formatting */
265
+ runs?: ChartTextRun[];
266
+ /** a cell whose text the title shows, for example 'Data!$B$1' */
267
+ ref?: string;
268
+ /**
269
+ * The font of the title's words, as `ChartFont`.
270
+ */
271
+ font?: ChartFont;
272
+ /** drawn over the plot area rather than beside it */
273
+ overlay?: boolean;
274
+ /**
275
+ * The position and size of the title, set by hand, as `ChartLayout`.
276
+ */
277
+ layout?: ChartLayout;
278
+ }
279
+
280
+ /**
281
+ * The legend of a chart: where it sits, whether it is drawn over the plot area, and its entries and font.
282
+ */
283
+ export interface ChartLegend extends ChartShapeFormat {
284
+ /**
285
+ * Where the legend sits: `'top'`, `'bottom'`, `'left'`, `'right'` or `'topRight'`. `'b'`, `'t'`, `'l'`,
286
+ * `'r'` and `'tr'` are the same positions.
287
+ */
288
+ position?: ChartLegendPosition | 'b' | 't' | 'l' | 'r' | 'tr';
289
+ /**
290
+ * Whether the legend is drawn over the plot area rather than beside it.
291
+ */
292
+ overlay?: boolean;
293
+ /**
294
+ * The position and size of the legend, set by hand, as `ChartLayout`.
295
+ */
296
+ layout?: ChartLayout;
297
+ /** one line of the legend, counted from 0: taken out, or in a font of its own */
298
+ entries?: Array<{index: number; delete?: boolean; font?: ChartFont}>;
299
+ /**
300
+ * The font of the legend's text, as `ChartFont`.
301
+ */
302
+ font?: ChartFont;
303
+ }
304
+
305
+ /** The floor or a wall of a 3-D chart. */
306
+ export interface ChartSurface extends ChartShapeFormat {
307
+ /**
308
+ * The thickness of the floor or wall, in points.
309
+ */
310
+ thickness?: number;
311
+ /**
312
+ * How a picture fill is laid on the surface, as `ChartPictureOptions`.
313
+ */
314
+ pictureOptions?: ChartPictureOptions;
315
+ }
316
+
317
+ /**
318
+ * A unit a value axis shows its values in, from `hundreds` to `trillions`, as `ChartAxis.displayUnits` takes
319
+ * it.
320
+ */
321
+ export type ChartDisplayUnit =
322
+ | 'hundreds' | 'thousands' | 'tenThousands' | 'hundredThousands' | 'millions' | 'tenMillions'
323
+ | 'hundredMillions' | 'billions' | 'trillions';
324
+
325
+ /**
326
+ * An axis of a classic chart: its title, scale, gridlines, tick marks, labels and line. Used for the
327
+ * category, value, secondary value and series axes of `ChartProperties`.
328
+ */
329
+ export interface ChartAxis extends ChartShapeFormat {
330
+ /** true, or a title with no words, shows Excel's own ("Axis Title") */
331
+ title?: string | true | ChartTitle;
332
+ /** hide the axis without removing it */
333
+ delete?: boolean;
334
+ /**
335
+ * the side the file names (axPos), which Excel ignores ([MS-OI29500] 2.1.1433): an axis is
336
+ * drawn where it crosses the other, so `crosses: 'max'` moves it to the far side
337
+ */
338
+ position?: 'b' | 'l' | 'r' | 't';
339
+ /**
340
+ * Whether the axis runs in reverse, from its largest value or last category to its smallest or first.
341
+ */
342
+ reverse?: boolean;
343
+ /** a number format of its own, no longer linked to the source cells */
344
+ numFmt?: string;
345
+ /**
346
+ * The smallest value the axis shows, Excel's automatic minimum when left out.
347
+ */
348
+ min?: number;
349
+ /**
350
+ * The largest value the axis shows, Excel's automatic maximum when left out.
351
+ */
352
+ max?: number;
353
+ /**
354
+ * The interval between the major gridlines and labels, in the axis's units; automatic when left out.
355
+ */
356
+ majorUnit?: number;
357
+ /**
358
+ * The interval between the minor tick marks, in the axis's units; automatic when left out.
359
+ */
360
+ minorUnit?: number;
361
+ /**
362
+ * The base of a logarithmic scale, such as `10`; the scale is linear when left out.
363
+ */
364
+ logBase?: number;
365
+ /**
366
+ * Where THIS axis sits on the one it crosses, as the file stores it. Excel's
367
+ * Format pane shows it on the other axis: "Horizontal axis crosses: Maximum"
368
+ * in the value axis's pane is the category axis's `crosses: 'max'`.
369
+ */
370
+ crosses?: 'autoZero' | 'min' | 'max';
371
+ /**
372
+ * The value on the axis it crosses where this axis sits, in place of `crosses`.
373
+ */
374
+ crossesAt?: number;
375
+ /** value axes: cross between the categories, or on them ('midCat') */
376
+ crossBetween?: 'between' | 'midCat';
377
+ /** true for Excel's gridlines, or a line of their own */
378
+ majorGridlines?: boolean | ChartOutline;
379
+ /**
380
+ * Minor gridlines: `true` for Excel's own, or a line of their own.
381
+ */
382
+ minorGridlines?: boolean | ChartOutline;
383
+ /**
384
+ * Where the major tick marks sit: `cross`, `in`, `none` or `out`.
385
+ */
386
+ majorTickMark?: 'cross' | 'in' | 'none' | 'out';
387
+ /**
388
+ * Where the minor tick marks sit: `cross`, `in`, `none` or `out`.
389
+ */
390
+ minorTickMark?: 'cross' | 'in' | 'none' | 'out';
391
+ /**
392
+ * Where the labels sit: `high` at the top or right of the plot, `low` at the foot or left, `nextTo` beside
393
+ * the axis, or `none`.
394
+ */
395
+ tickLabelPosition?: 'high' | 'low' | 'nextTo' | 'none';
396
+ /** category axes: label every Nth category, and a tick mark every Nth */
397
+ tickLblSkip?: number;
398
+ /**
399
+ * On a category axis, a tick mark for every Nth category.
400
+ */
401
+ tickMarkSkip?: number;
402
+ /** category axes: label distance from the axis, 0..1000 percent */
403
+ labelOffset?: number;
404
+ /**
405
+ * On a category axis, how the labels align on their lines: `ctr` (centred), `l` (left) or `r` (right).
406
+ */
407
+ labelAlign?: 'ctr' | 'l' | 'r';
408
+ /** category axes: false draws a multi-level category range as one level */
409
+ multiLevelLabels?: boolean;
410
+ /** label rotation in degrees */
411
+ labelRotation?: number;
412
+ /**
413
+ * The font of the axis labels.
414
+ */
415
+ font?: ChartFont;
416
+ /** the axis line */
417
+ line?: ChartOutline | false;
418
+ /** treat the category axis as a date axis */
419
+ dateAxis?: boolean;
420
+ /** false when the axis type was chosen by hand rather than by Excel from the data */
421
+ auto?: boolean;
422
+ /** date axes */
423
+ baseTimeUnit?: ChartTimeUnit;
424
+ /**
425
+ * On a date axis, the unit of the major ticks: `days`, `months` or `years`.
426
+ */
427
+ majorTimeUnit?: ChartTimeUnit;
428
+ /**
429
+ * On a date axis, the unit of the minor ticks: `days`, `months` or `years`.
430
+ */
431
+ minorTimeUnit?: ChartTimeUnit;
432
+ /**
433
+ * Value axes: show values in hundreds, thousands... or a unit of your own,
434
+ * with the label that says so (shown unless `label: false`).
435
+ */
436
+ displayUnits?:
437
+ | ChartDisplayUnit
438
+ | number
439
+ | {unit: ChartDisplayUnit | number; label?: boolean | ChartTitle};
440
+ }