@jsfkit/types 1.0.0 → 1.1.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 (2) hide show
  1. package/dist/index.d.ts +217 -82
  2. package/package.json +8 -2
package/dist/index.d.ts CHANGED
@@ -1,35 +1,3 @@
1
- /**
2
- * A whole number without a fractional value.
3
- */
4
- type integer = number;
5
-
6
- /**
7
- * Directions on how formulas should be recalculated in the workbook.
8
- */
9
- type CalcProps = {
10
- /**
11
- * Specifies whether an attempt should be made to calculate formulas that contain circular
12
- * references. Defaults to `false` in Excel.
13
- */
14
- iterate: boolean;
15
- /**
16
- * The maximum number of calculation iterations, when `iterate` is `true`. Defaults to `100` in
17
- * Excel.
18
- */
19
- iterateCount: integer;
20
- /**
21
- * When a calculation iteration results in an absolute change that is less than iterateDelta,
22
- * then no further iterations should be attempted. Defaults to `0.001` in Excel.
23
- */
24
- iterateDelta: number;
25
- /**
26
- * Which of the two date systems the workbook uses. 1900 is the default.
27
- *
28
- * @see {@link https://support.microsoft.com/office/e7fe7167-48a9-4b96-bb53-5612a800b487}
29
- */
30
- epoch?: 1900 | 1904;
31
- };
32
-
33
1
  /**
34
2
  * Defines the type of a value contained within a cell.
35
3
  */
@@ -45,6 +13,11 @@ type Comment = {
45
13
  t: string;
46
14
  };
47
15
 
16
+ /**
17
+ * A whole number without a fractional value.
18
+ */
19
+ type integer = number;
20
+
48
21
  /**
49
22
  * A spreadsheet cell.
50
23
  */
@@ -60,6 +33,8 @@ type Cell = {
60
33
  * Cell formula expression. When the value is a string it will be a formula with A1-style
61
34
  * references. When the value is a number is an index to a formula in the workbook's `formulas`
62
35
  * array.
36
+ *
37
+ * @see {@link Workbook.formulas}
63
38
  */
64
39
  f?: string | integer;
65
40
  /** The range of enclosing array if the formula is an array formula. */
@@ -71,6 +46,7 @@ type Cell = {
71
46
  /**
72
47
  * An index to a style in the workbook's `styles`.
73
48
  *
49
+ * @see {@link Workbook.styles}
74
50
  * @default 0
75
51
  */
76
52
  s?: integer;
@@ -80,7 +56,8 @@ type Cell = {
80
56
  c?: Comment[];
81
57
  /**
82
58
  * The type of the value contained in the cell. Cells with errors or dates must include this
83
- * property, but it's otherwise optional (the type can be inferred from the `v` property).
59
+ * property, but it's otherwise optional (the type can be inferred from the {@link Cell.v}
60
+ * property).
84
61
  */
85
62
  t?: CellValueType;
86
63
  };
@@ -98,7 +75,7 @@ type CellId = string;
98
75
  /**
99
76
  * A cell coordinate range in an uppercase A1-style reference format (e.g. `H6:J36`).
100
77
  *
101
- * The range consists of two {@link CellId}s separated by a colon (`:`) character.
78
+ * The range consists of two {@link CellId | CellIds} separated by a colon (`:`) character.
102
79
  *
103
80
  * @pattern ^([A-Z]{1,3}[0-9]{1,3}):([A-Z]{1,3}[0-9]{1,3})$
104
81
  */
@@ -148,8 +125,8 @@ type ExternalWorksheet = {
148
125
  /**
149
126
  * The cells belonging to the worksheet that have any data attached.
150
127
  *
151
- * Typically, these will have only values and calculation directives attached as they will not
152
- * be rendered by a spreadsheet application.
128
+ * Typically, these will have only values attached, as external worksheet cells serve purely as
129
+ * inputs to formulas in other sheets.
153
130
  */
154
131
  cells: Record<CellId, Cell>;
155
132
  };
@@ -182,11 +159,12 @@ type PixelValue = number;
182
159
  * A size of a UI-grid measure over a range of items.
183
160
  *
184
161
  * GridSize information is run-length encoded. The start and end attributes indicate the range of
185
- * items that the `size` and `s` attributes affect. The range is expressed using integers, where
186
- * 1 corresponds to column A or row 1.
162
+ * items that the {@link GridSize.size} and {@link GridSize.s} attributes affect. The range is
163
+ * expressed using integers, where 1 corresponds to column A or row 1.
187
164
  *
188
- * GridSize may have a style-index (`s`) attribute like individual cells. The styling information on
189
- * the column should be used for all cells that are not present in the sheet's cell collection.
165
+ * GridSize may have a style-index ({@link GridSize.s}) attribute like individual cells. The styling
166
+ * information on the column should be used for all cells that are not present in the sheet's cell
167
+ * collection.
190
168
  */
191
169
  type GridSize = {
192
170
  /** A 1-based inclusive start index. */
@@ -202,51 +180,81 @@ type GridSize = {
202
180
  /**
203
181
  * The style to use when drawing a cell border. If the worksheet's zoom factor is changed the width
204
182
  * of the border is expected to stay the same.
205
- *
206
- * - `none`: no border is drawn.
207
- * - `dashDot`: equivalent to SVG `stroke-dasharray="4 1 2 1"`, at a 1px width.
208
- * - `dashDotDot`: equivalent to SVG `stroke-dasharray="4 1 2 1 2 1"`, at a 1px width.
209
- * - `dashed`: equivalent to SVG `stroke-dasharray=""3 1`, at a 1px width.
210
- * - `dotted`: equivalent to SVG `stroke-dasharray="1"`, at a 1px width.
211
- * - `double`: draw two 1px wide continuous parallel lines with a 1px gap between them.
212
- * - `hair`: draw a 1px wide pixel continuous hairline.
213
- * - `medium`: draw a 2px wide pixel continuous line.
214
- * - `mediumDashDot`: equivalent to SVG `stroke-dasharray="4 1 2 1"`, at a 2px width.
215
- * - `mediumDashDotDot`: equivalent to SVG `stroke-dasharray="4 1 2 1 2 1"`, at a 2px width.
216
- * - `mediumDashed`: equivalent to SVG `stroke-dasharray=""3 1`, at a 2px width.
217
- * - `slantDashDot`: draw two 1px parallel dashed lines where the lower/left line 1px "behind" the
218
- * other, creating a slant.
219
- * - `thick`: draw a 3px wide pixel continuous line.
220
- * - `thin`: draw a 1px wide pixel continuous line.
221
183
  */
222
- type BorderStyle = 'none' | 'dashDot' | 'dashDotDot' | 'dashed' | 'dotted' | 'double' | 'hair' | 'medium' | 'mediumDashDot' | 'mediumDashDotDot' | 'mediumDashed' | 'slantDashDot' | 'thick' | 'thin';
184
+ type BorderStyle =
185
+ /** No border is drawn.*/
186
+ 'none' |
187
+ /** Equivalent to SVG `stroke-dasharray="4 1 2 1"`, at a 1px width.*/
188
+ 'dashDot' |
189
+ /** Equivalent to SVG `stroke-dasharray="4 1 2 1 2 1"`, at a 1px width.*/
190
+ 'dashDotDot' |
191
+ /** Equivalent to SVG `stroke-dasharray=""3 1`, at a 1px width.*/
192
+ 'dashed' |
193
+ /** Equivalent to SVG `stroke-dasharray="1"`, at a 1px width.*/
194
+ 'dotted' |
195
+ /** Draw two 1px wide continuous parallel lines with a 1px gap between them.*/
196
+ 'double' |
197
+ /** Draw a 1px wide pixel continuous hairline.*/
198
+ 'hair' |
199
+ /** Draw a 2px wide pixel continuous line.*/
200
+ 'medium' |
201
+ /** Equivalent to SVG `stroke-dasharray="4 1 2 1"`, at a 2px width.*/
202
+ 'mediumDashDot' |
203
+ /** Equivalent to SVG `stroke-dasharray="4 1 2 1 2 1"`, at a 2px width.*/
204
+ 'mediumDashDotDot' |
205
+ /** Equivalent to SVG `stroke-dasharray=""3 1`, at a 2px width.*/
206
+ 'mediumDashed' |
207
+ /**
208
+ * Draw two 1px parallel dashed lines where the lower/left line 1px "behind" the other, creating
209
+ * a slant.
210
+ */
211
+ 'slantDashDot' |
212
+ /** Draw a 3px wide pixel continuous line.*/
213
+ 'thick' |
214
+ /** Draw a 1px wide pixel continuous line.*/
215
+ 'thin';
223
216
 
224
217
  /**
225
218
  * A hex-encoded RGB or RGBA value that conforms to the CSS4 color specification (e.g. `"#3cb371"`).
226
219
  *
227
- * @see {@link https://www.w3.org/TR/css-color-4/#hex-notation|CSS spec}
220
+ * @see {@link https://www.w3.org/TR/css-color-4/#hex-notation | CSS hexadecimal notation spec}
228
221
  * @pattern ^#([a-fA-F0-9]{3,4}|([a-fA-F0-9][a-fA-F0-9]){3,4})$
229
222
  */
230
223
  type Color = `#${string}`;
231
224
 
232
225
  /**
233
226
  * Specifies the horizontal alignment of content (text) within a container (cell).
234
- *
235
- * - `center`: the horizontal alignment is centered, meaning the text is centered across the cell.
236
- * - `centerContinuous`: the horizontal alignment is centered across multiple cells.
237
- * - `distributed`: indicates that each 'word' in each line of text inside the cell is evenly
238
- * distributed across the width of the cell, with flush right and left margins.
239
- * - `fill`: indicates that the value of the cell should be filled across the entire width of the
240
- * cell. If blank cells to the right also have the fill alignment, they are also filled with the
241
- * value, using a convention similar to `centerContinuous`.
242
- * - `general`: the horizontal alignment is general-aligned. Text data is left-aligned. Numbers,
243
- * dates, and times are right- aligned. Boolean types are centered.
244
- * - `justify`: for each line of text, aligns each line of the wrapped text in a cell to the right
245
- * and left (except the last line).
246
- * - `left`: aligns content at the left edge of the cell (even in RTL mode).
247
- * - `right`: aligns content at the right edge of the cell (even in RTL mode).
248
227
  */
249
- type HAlign = 'general' | 'left' | 'center' | 'right' | 'fill' | 'justify' | 'centerContinuous' | 'distributed';
228
+ type HAlign =
229
+ /**
230
+ * The horizontal alignment is general-aligned. Text data is left-aligned. Numbers, dates, and
231
+ * times are right- aligned. Boolean types are centered.
232
+ */
233
+ 'general' |
234
+ /** Aligns content at the left edge of the cell (even in RTL mode). */
235
+ 'left' |
236
+ /** The horizontal alignment is centered, meaning the text is centered across the cell. */
237
+ 'center' |
238
+ /** Aligns content at the right edge of the cell (even in RTL mode). */
239
+ 'right' |
240
+ /**
241
+ * Indicates that the value of the cell should be filled across the entire width of the cell. If
242
+ * blank cells to the right also have the fill alignment, they are also filled with the value,
243
+ * using a convention similar to `centerContinuous`.
244
+ */
245
+ 'fill' |
246
+ /**
247
+ * For each line of text, aligns each line of the wrapped text in a cell to the right and left
248
+ * (except the last line).
249
+ */
250
+ 'justify' |
251
+ /** The horizontal alignment is centered across multiple cells. */
252
+ 'centerContinuous' |
253
+ /**
254
+ * Indicates that each 'word' in each line of text inside the cell is evenly distributed across
255
+ * the width of the cell, with flush right and left margins.
256
+ */
257
+ 'distributed';
250
258
 
251
259
  /**
252
260
  * The style of fill pattern used for a cell background. If the worksheets zoom factor is changed
@@ -506,11 +514,38 @@ type Table = {
506
514
  headerRowCount?: integer;
507
515
  /**
508
516
  * Presentation information for the table. When not present tables should be rendered using
509
- * `"TableStyleMedium2"` style with `showRowStripes` active.
517
+ * `"TableStyleMedium2"` style with {@link TableStyle.showRowStripes} set to `true`.
510
518
  */
511
519
  style?: TableStyle;
512
520
  };
513
521
 
522
+ /**
523
+ * Directions on how formulas should be recalculated in the workbook.
524
+ */
525
+ type CalcProps = {
526
+ /**
527
+ * Specifies whether an attempt should be made to calculate formulas that contain circular
528
+ * references. Defaults to `false` in Excel.
529
+ */
530
+ iterate: boolean;
531
+ /**
532
+ * The maximum number of calculation iterations, when {@link CalcProps.iterate} is `true`.
533
+ * Defaults to `100` in Excel.
534
+ */
535
+ iterateCount: integer;
536
+ /**
537
+ * When a calculation iteration results in an absolute change that is less than iterateDelta,
538
+ * then no further iterations should be attempted. Defaults to `0.001` in Excel.
539
+ */
540
+ iterateDelta: number;
541
+ /**
542
+ * Which of the two date systems the workbook uses. 1900 is the default.
543
+ *
544
+ * @see {@link https://support.microsoft.com/office/e7fe7167-48a9-4b96-bb53-5612a800b487 | Date systems in Excel}
545
+ */
546
+ epoch?: 1900 | 1904;
547
+ };
548
+
514
549
  /**
515
550
  * A collection of default properties that apply to cells, rows, or columns in the worksheet.
516
551
  */
@@ -521,6 +556,80 @@ type WorksheetDefaults = {
521
556
  rowHeight: PixelValue;
522
557
  };
523
558
 
559
+ /**
560
+ * Visual scale (aka zoom level, aka magnification) applied when displaying a worksheet.
561
+ *
562
+ * Each of the three layouts has its own scale. A scale is represented as a percentage, with `100`
563
+ * (100%) being the default 1:1 scale. When a layout has no explicit scale, use 100%.
564
+ */
565
+ type WorksheetLayoutScales = {
566
+ /**
567
+ * Zoom level for normal view.
568
+ *
569
+ * @min 10
570
+ * @max 400
571
+ * @defaultValue 100
572
+ * */
573
+ normal?: integer;
574
+ /**
575
+ * Zoom level for page layout view.
576
+ *
577
+ * @min 10
578
+ * @max 400
579
+ * @defaultValue 100
580
+ */
581
+ pageLayout?: integer;
582
+ /**
583
+ * Zoom level for page break preview (aka sheet layout view).
584
+ *
585
+ * @min 10
586
+ * @max 400
587
+ * @defaultValue 100
588
+ */
589
+ pageBreakPreview?: integer;
590
+ };
591
+
592
+ /**
593
+ * A worksheet view.
594
+ *
595
+ * A worksheet view is a display configuration for a particular worksheet. Worksheet view settings
596
+ * can include:
597
+ *
598
+ * - Active cell
599
+ * - Selected ranges
600
+ * - View type (normal, page layout, or page break layout)
601
+ * - Zoom level
602
+ *
603
+ * Currently JSF does not include all available settings for a worksheet.
604
+ */
605
+ type WorksheetView = {
606
+ /**
607
+ * The id of the workbook view this worksheet view belongs to.
608
+ *
609
+ * This is a zero-based index of the workbook view, as stored in the {@link Workbook.views} array.
610
+ *
611
+ * Within a single worksheet, each view must reference a distinct workbook view (i.e. no two views
612
+ * in the same worksheet can share the same `workbookView` id). However, views from different
613
+ * worksheets may reference the same workbook view.
614
+ */
615
+ workbookView: integer;
616
+ /** Cell that is selected by default when the sheet is visible. */
617
+ activeCell?: CellId;
618
+ /** Ranges of cells that are selected by default when the sheet is visible. */
619
+ activeRanges?: CellRange[];
620
+ /**
621
+ * The layout used to display the worksheet.
622
+ *
623
+ * @defaultValue "normal"
624
+ */
625
+ activeLayout?: 'normal' | 'pageLayout' | 'pageBreakPreview';
626
+ /**
627
+ * Scale (aka zoom level, aka magnification) applied when displaying a worksheet. Each different
628
+ * layout has its own scale.
629
+ */
630
+ layoutScales?: WorksheetLayoutScales;
631
+ };
632
+
524
633
  /**
525
634
  * A rectangle of cells. A sheet within a spreadsheet.
526
635
  */
@@ -530,13 +639,13 @@ type Worksheet = {
530
639
  /** The cells belonging to the worksheet that have some data attached. */
531
640
  cells: Record<CellId, Cell>;
532
641
  /** Widths and styles of the columns in the worksheet. */
533
- columns: GridSize[];
642
+ columns?: GridSize[];
534
643
  /** Heights and styles of the rows in the worksheet. */
535
- rows: GridSize[];
644
+ rows?: GridSize[];
536
645
  /** Ranges that capture which cells have been merged. */
537
- merges: string[];
646
+ merges?: string[];
538
647
  /** A collection of default properties that apply to cells, rows, or columns in the worksheet. */
539
- defaults: WorksheetDefaults;
648
+ defaults?: WorksheetDefaults;
540
649
  /**
541
650
  * Whether or not the sheet should be shown to a user in a UI displaying the workbook.
542
651
  *
@@ -549,6 +658,30 @@ type Worksheet = {
549
658
  hidden?: 0 | 1 | 2;
550
659
  /** Indicates whether a hairline-grid should be drawn when displaying the sheet. */
551
660
  showGridLines?: boolean;
661
+ /** The different display configurations saved for the worksheet. */
662
+ views?: WorksheetView[];
663
+ };
664
+
665
+ /**
666
+ * A workbook view.
667
+ *
668
+ * A workbook view is the display settings that apply to the entire workbook. Workbook view settings
669
+ * include:
670
+ *
671
+ * - Active sheet
672
+ * - Window size and position
673
+ * - Window state (whether the window is maximised, minimised, etc)
674
+ * - Scroll bar visibility
675
+ *
676
+ * Currently JSF does not include all available settings for a workbook.
677
+ */
678
+ type WorkbookView = {
679
+ /**
680
+ * Index to the active sheet in this workbook view. The default value is 0 (first sheet).
681
+ *
682
+ * @defaultValue 0
683
+ */
684
+ activeSheet?: integer;
552
685
  };
553
686
 
554
687
  /**
@@ -561,13 +694,13 @@ type Workbook = {
561
694
  /** An ordered array of the worksheets in the workbook. */
562
695
  sheets: Worksheet[];
563
696
  /** An array of the workbook's defined names. */
564
- names: DefinedName[];
697
+ names?: DefinedName[];
565
698
  /** Metadata on the workbook's tables. */
566
- tables: Table[];
699
+ tables?: Table[];
567
700
  /** Directions on how formulas should be recalculated in the workbook. */
568
701
  calculationProperties?: CalcProps;
569
702
  /** Styles for cells in the workbook. */
570
- styles: Style[];
703
+ styles?: Style[];
571
704
  /** External cells referenced by the workbook. An external cell is a cell in another workbook. */
572
705
  externals?: External[];
573
706
  /**
@@ -576,6 +709,8 @@ type Workbook = {
576
709
  * identical.
577
710
  */
578
711
  formulas?: string[];
712
+ /** The different display configurations saved for the workbook. */
713
+ views?: WorkbookView[];
579
714
  };
580
715
 
581
- export type { BorderStyle, CalcProps, Cell, CellId, CellRange, CellValueType, Color, Comment, DefinedName, External, ExternalWorksheet, GridSize, HAlign, PatternStyle, PixelValue, Style, Table, TableColumn, TableColumnDataType, TableStyle, TableStyleName, Underline, VAlign, Workbook, Worksheet, WorksheetDefaults };
716
+ export type { BorderStyle, CalcProps, Cell, CellId, CellRange, CellValueType, Color, Comment, DefinedName, External, ExternalWorksheet, GridSize, HAlign, PatternStyle, PixelValue, Style, Table, TableColumn, TableColumnDataType, TableStyle, TableStyleName, Underline, VAlign, Workbook, WorkbookView, Worksheet, WorksheetDefaults, WorksheetLayoutScales, WorksheetView };
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@jsfkit/types",
3
- "version": "1.0.0",
4
- "description": "A JSON representation for spreadsheets",
3
+ "version": "1.1.0",
4
+ "description": "TypeScript types for JSF: a JSON spreadsheet representation",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/jsfkit/types.git"
10
10
  },
11
+ "homepage": "https://jsfkit.github.io/types/",
12
+ "bugs": "https://github.com/jsfkit/types/issues",
11
13
  "keywords": [
12
14
  "excel",
13
15
  "json",
@@ -24,11 +26,14 @@
24
26
  "import": "./dist/index.js"
25
27
  }
26
28
  },
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
27
31
  "files": [
28
32
  "dist"
29
33
  ],
30
34
  "scripts": {
31
35
  "build": "tsup",
36
+ "build:docs": "typedoc",
32
37
  "check": "npm run lint && npm run typecheck",
33
38
  "lint": "eslint src",
34
39
  "format": "eslint src --fix",
@@ -41,6 +46,7 @@
41
46
  "eslint": "^9.38.0",
42
47
  "globals": "^16.4.0",
43
48
  "tsup": "^8.5.0",
49
+ "typedoc": "^0.28.14",
44
50
  "typescript": "^5.9.3",
45
51
  "typescript-eslint": "^8.46.1"
46
52
  }