@shbernal/ts-xlsx 2.1.0 → 3.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.
- package/README.md +4 -1
- package/dist/bytes.d.ts +7 -0
- package/dist/bytes.js +22 -0
- package/dist/core/address.d.ts +60 -2
- package/dist/core/address.js +40 -24
- package/dist/core/autofilter.d.ts +5 -4
- package/dist/core/autofilter.js +34 -35
- package/dist/core/axis-handle.d.ts +10 -0
- package/dist/core/axis-handle.js +17 -0
- package/dist/core/cell.d.ts +25 -0
- package/dist/core/cell.js +9 -3
- package/dist/core/clone.d.ts +29 -0
- package/dist/core/clone.js +24 -0
- package/dist/core/color-resolution.js +2 -4
- package/dist/core/column.d.ts +5 -1
- package/dist/core/column.js +34 -35
- package/dist/core/comment-thread.js +2 -1
- package/dist/core/conditional-formatting-overlay.d.ts +2 -1
- package/dist/core/conditional-formatting-overlay.js +2 -2
- package/dist/core/conditional-formatting.d.ts +14 -6
- package/dist/core/conditional-formatting.js +45 -43
- package/dist/core/containers.d.ts +12 -0
- package/dist/core/containers.js +5 -0
- package/dist/core/data-validation-overlay.d.ts +2 -1
- package/dist/core/data-validation-overlay.js +4 -4
- package/dist/core/data-validation.d.ts +9 -3
- package/dist/core/data-validation.js +21 -18
- package/dist/core/date-format.d.ts +20 -0
- package/dist/core/date-format.js +160 -0
- package/dist/core/date.d.ts +43 -8
- package/dist/core/date.js +18 -2
- package/dist/core/formula.d.ts +26 -0
- package/dist/core/formula.js +20 -4
- package/dist/core/grid-edits.d.ts +2 -3
- package/dist/core/grid-edits.js +69 -70
- package/dist/core/grid-shift.d.ts +58 -9
- package/dist/core/grid-shift.js +26 -4
- package/dist/core/image.d.ts +14 -10
- package/dist/core/image.js +9 -9
- package/dist/core/internal.d.ts +8 -2
- package/dist/core/limits.d.ts +23 -0
- package/dist/core/limits.js +4 -0
- package/dist/core/merge-index.d.ts +31 -0
- package/dist/core/merge-index.js +60 -0
- package/dist/core/merge.d.ts +5 -14
- package/dist/core/merge.js +18 -27
- package/dist/core/page-setup.d.ts +72 -2
- package/dist/core/page-setup.js +34 -8
- package/dist/core/pivot-table.d.ts +1 -1
- package/dist/core/pivot-table.js +67 -53
- package/dist/core/protection.js +2 -11
- package/dist/core/range.js +34 -30
- package/dist/core/row-input.js +2 -2
- package/dist/core/row.d.ts +5 -1
- package/dist/core/row.js +22 -23
- package/dist/core/style.d.ts +134 -75
- package/dist/core/style.js +112 -53
- package/dist/core/table-style.d.ts +1 -1
- package/dist/core/table-style.js +4 -4
- package/dist/core/table.d.ts +28 -10
- package/dist/core/table.js +54 -39
- package/dist/core/theme.js +6 -5
- package/dist/core/used-extent.d.ts +44 -0
- package/dist/core/used-extent.js +102 -0
- package/dist/core/value.d.ts +9 -0
- package/dist/core/value.js +36 -34
- package/dist/core/workbook-media.d.ts +34 -0
- package/dist/core/workbook-media.js +44 -0
- package/dist/core/workbook-styles.d.ts +67 -1
- package/dist/core/workbook-vba.js +3 -2
- package/dist/core/workbook.d.ts +23 -2
- package/dist/core/workbook.js +24 -40
- package/dist/core/worksheet-comments.d.ts +2 -1
- package/dist/core/worksheet-comments.js +20 -13
- package/dist/core/worksheet-merges.d.ts +44 -0
- package/dist/core/worksheet-merges.js +59 -0
- package/dist/core/worksheet-model.d.ts +9 -1
- package/dist/core/worksheet-model.js +24 -9
- package/dist/core/worksheet.d.ts +72 -12
- package/dist/core/worksheet.js +68 -70
- package/dist/customui/ribbon.js +6 -7
- package/dist/entries/core.d.ts +18 -13
- package/dist/entries/core.js +12 -6
- package/dist/entries/xlsx.d.ts +1 -1
- package/dist/errors.d.ts +64 -0
- package/dist/errors.js +22 -0
- package/dist/hex.d.ts +8 -0
- package/dist/hex.js +3 -0
- package/dist/io/csv/delimiter.d.ts +9 -0
- package/dist/io/csv/delimiter.js +6 -0
- package/dist/io/csv/read.js +11 -4
- package/dist/io/csv/write.d.ts +9 -2
- package/dist/io/csv/write.js +9 -38
- package/dist/io/opc/inflate.js +15 -1
- package/dist/io/opc/namespaces.d.ts +16 -0
- package/dist/io/opc/namespaces.js +4 -0
- package/dist/io/opc/part-paths.d.ts +10 -0
- package/dist/io/opc/part-paths.js +16 -1
- package/dist/io/opc/read-opc.d.ts +69 -10
- package/dist/io/opc/read-opc.js +49 -55
- package/dist/io/opc/read-options.d.ts +5 -1
- package/dist/io/opc/rels.d.ts +1 -6
- package/dist/io/opc/rels.js +1 -4
- package/dist/io/opc/sniff-format.d.ts +3 -3
- package/dist/io/opc/sniff-format.js +2 -2
- package/dist/io/style/xf-style.d.ts +48 -2
- package/dist/io/style/xf-style.js +14 -0
- package/dist/io/xlsb/formula.d.ts +2 -2
- package/dist/io/xlsb/formula.js +49 -34
- package/dist/io/xlsb/primitives.js +8 -14
- package/dist/io/xlsb/ptg-functions.d.ts +19 -10
- package/dist/io/xlsb/ptg-functions.js +385 -596
- package/dist/io/xlsb/read-styles.js +50 -83
- package/dist/io/xlsb/read-worksheet.d.ts +20 -1
- package/dist/io/xlsb/read-worksheet.js +73 -89
- package/dist/io/xlsb/read.d.ts +6 -3
- package/dist/io/xlsb/read.js +47 -29
- package/dist/io/xlsb/record-stream.d.ts +30 -0
- package/dist/io/xlsb/record-stream.js +20 -0
- package/dist/io/xlsb/record-types.d.ts +1 -5
- package/dist/io/xlsb/record-types.js +1 -5
- package/dist/io/xlsx/cell-accumulator.d.ts +9 -2
- package/dist/io/xlsx/cell-accumulator.js +32 -9
- package/dist/io/xlsx/cell-style-resolution.d.ts +25 -0
- package/dist/io/xlsx/cell-style-resolution.js +29 -0
- package/dist/io/xlsx/cell-value.d.ts +5 -3
- package/dist/io/xlsx/cell-value.js +13 -15
- package/dist/io/xlsx/color-xml.js +3 -2
- package/dist/io/xlsx/column-budget.d.ts +26 -0
- package/dist/io/xlsx/column-budget.js +22 -0
- package/dist/io/xlsx/comments.d.ts +6 -2
- package/dist/io/xlsx/comments.js +36 -31
- package/dist/io/xlsx/conditional-formatting.d.ts +9 -5
- package/dist/io/xlsx/conditional-formatting.js +51 -46
- package/dist/io/xlsx/data-validation.d.ts +9 -7
- package/dist/io/xlsx/data-validation.js +38 -35
- package/dist/io/xlsx/edit-vba.d.ts +7 -2
- package/dist/io/xlsx/edit-vba.js +15 -29
- package/dist/io/xlsx/font-xml.d.ts +7 -0
- package/dist/io/xlsx/font-xml.js +104 -0
- package/dist/io/xlsx/hyperlinks.d.ts +41 -7
- package/dist/io/xlsx/hyperlinks.js +40 -28
- package/dist/io/xlsx/images.js +24 -25
- package/dist/io/xlsx/namespaces.d.ts +16 -0
- package/dist/io/xlsx/namespaces.js +7 -0
- package/dist/io/xlsx/package-plan.d.ts +23 -3
- package/dist/io/xlsx/package-plan.js +66 -25
- package/dist/io/xlsx/part-names.d.ts +41 -0
- package/dist/io/xlsx/part-names.js +46 -0
- package/dist/io/xlsx/pivot.js +8 -7
- package/dist/io/xlsx/read-parts.d.ts +59 -0
- package/dist/io/xlsx/read-parts.js +252 -0
- package/dist/io/xlsx/read-pivot.js +3 -1
- package/dist/io/xlsx/read-repair.d.ts +26 -0
- package/dist/io/xlsx/read-repair.js +39 -0
- package/dist/io/xlsx/{rich-runs.d.ts → read-rich-runs.d.ts} +1 -1
- package/dist/io/xlsx/{rich-runs.js → read-rich-runs.js} +7 -3
- package/dist/io/xlsx/read-rows.d.ts +18 -5
- package/dist/io/xlsx/read-rows.js +50 -37
- package/dist/io/xlsx/read-shared-strings.js +5 -3
- package/dist/io/xlsx/read-styles.d.ts +1 -6
- package/dist/io/xlsx/read-styles.js +65 -109
- package/dist/io/xlsx/read-workbook-xml.d.ts +36 -0
- package/dist/io/xlsx/read-workbook-xml.js +170 -0
- package/dist/io/xlsx/read-worksheet.d.ts +11 -1
- package/dist/io/xlsx/read-worksheet.js +51 -193
- package/dist/io/xlsx/read.d.ts +5 -13
- package/dist/io/xlsx/read.js +111 -436
- package/dist/io/xlsx/rich-text.js +1 -1
- package/dist/io/xlsx/row-position.d.ts +18 -0
- package/dist/io/xlsx/row-position.js +11 -0
- package/dist/io/xlsx/row-xml.d.ts +128 -0
- package/dist/io/xlsx/row-xml.js +203 -0
- package/dist/io/xlsx/shared-formulas.js +2 -2
- package/dist/io/xlsx/sheet-properties.d.ts +10 -1
- package/dist/io/xlsx/sheet-properties.js +166 -37
- package/dist/io/xlsx/style-elements.d.ts +43 -0
- package/dist/io/xlsx/style-elements.js +156 -0
- package/dist/io/xlsx/styles.d.ts +12 -3
- package/dist/io/xlsx/styles.js +5 -204
- package/dist/io/xlsx/tables.js +11 -14
- package/dist/io/xlsx/theme-xml.d.ts +26 -4
- package/dist/io/xlsx/theme-xml.js +107 -69
- package/dist/io/xlsx/threaded-comments.d.ts +8 -10
- package/dist/io/xlsx/threaded-comments.js +3 -1
- package/dist/io/xlsx/workbook-xml.d.ts +54 -4
- package/dist/io/xlsx/workbook-xml.js +84 -57
- package/dist/io/xlsx/worksheet-xml.d.ts +23 -70
- package/dist/io/xlsx/worksheet-xml.js +59 -242
- package/dist/io/xlsx/write-stream.d.ts +71 -16
- package/dist/io/xlsx/write-stream.js +79 -41
- package/dist/io/xlsx/write.d.ts +6 -2
- package/dist/io/xlsx/write.js +217 -153
- package/dist/rel-type.d.ts +16 -0
- package/dist/rel-type.js +6 -0
- package/dist/token-set.d.ts +28 -0
- package/dist/token-set.js +7 -0
- package/dist/vba/bytes.d.ts +14 -5
- package/dist/vba/bytes.js +16 -6
- package/dist/vba/cfb-format.d.ts +32 -0
- package/dist/vba/cfb-format.js +13 -0
- package/dist/vba/cfb-writer.d.ts +9 -0
- package/dist/vba/cfb-writer.js +28 -25
- package/dist/vba/cfb.d.ts +13 -1
- package/dist/vba/cfb.js +73 -57
- package/dist/vba/codepage.js +2 -1
- package/dist/vba/errors.d.ts +7 -0
- package/dist/vba/ms-ovba.js +79 -23
- package/dist/vba/project-editor.js +35 -40
- package/dist/vba/project.d.ts +11 -1
- package/dist/vba/project.js +40 -21
- package/dist/vba/vba-encoding.js +5 -6
- package/dist/xml/xml-attrs.d.ts +37 -0
- package/dist/xml/xml-attrs.js +30 -0
- package/dist/xml/xml-chars.d.ts +40 -0
- package/dist/xml/xml-chars.js +12 -0
- package/dist/xml/xml-namespaces.d.ts +31 -0
- package/dist/xml/xml-namespaces.js +50 -0
- package/dist/xml/xml-read.d.ts +128 -81
- package/dist/xml/xml-read.js +161 -178
- package/dist/xml/xml-scan.d.ts +78 -0
- package/dist/xml/xml-scan.js +180 -0
- package/dist/xml/xml.d.ts +29 -28
- package/dist/xml/xml.js +24 -24
- package/package.json +13 -9
package/dist/core/style.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type ClonePlan } from './clone.ts';
|
|
2
|
+
import { type AssertNever, NAMED_STYLE_ID } from './internal.ts';
|
|
1
3
|
/** Underline can be a plain flag or one of Excel's named underline styles. */
|
|
2
4
|
export type UnderlineStyle = boolean | 'none' | 'single' | 'double' | 'singleAccounting' | 'doubleAccounting';
|
|
3
5
|
/** Narrow a raw `<u val>` token to a named {@link UnderlineStyle} (the non-boolean members). */
|
|
4
|
-
export declare
|
|
6
|
+
export declare const isNamedUnderlineStyle: (value: string) => value is "double" | "doubleAccounting" | "none" | "single" | "singleAccounting";
|
|
5
7
|
/** A colour, expressed as an ARGB hex string (`"FF0000FF"`) or an indexed theme colour. */
|
|
6
8
|
export interface Color {
|
|
7
9
|
/** 8-digit ARGB hex, uppercase, no leading `#`. */
|
|
@@ -35,13 +37,37 @@ export interface Color {
|
|
|
35
37
|
*/
|
|
36
38
|
export declare function parseArgb(value: string): string | undefined;
|
|
37
39
|
/**
|
|
38
|
-
* Fill pattern kinds,
|
|
40
|
+
* Fill pattern kinds, in the order OOXML's `ST_PatternType` enumerates them. `none` is the
|
|
39
41
|
* absence of a fill; `solid` paints the whole cell with the foreground colour (the
|
|
40
42
|
* common case). The remaining hatch patterns are carried for fidelity on read.
|
|
43
|
+
*
|
|
44
|
+
* The order is load-bearing rather than cosmetic, which is why it is stated twice over -- here, and
|
|
45
|
+
* in {@link FILL_PATTERNS_IN_SCHEMA_ORDER}, tied together by a proof. BIFF12 stores a pattern as its
|
|
46
|
+
* *index* into this enumeration, so the binary codec needs the sequence as a value; the doc above
|
|
47
|
+
* this type used to claim schema order while the union put `gray125` and `gray0625` at positions 2
|
|
48
|
+
* and 6, where the schema puts them last, and the binary codec carried a third copy that was right.
|
|
49
|
+
*/
|
|
50
|
+
export type FillPatternType = 'none' | 'solid' | 'mediumGray' | 'darkGray' | 'lightGray' | 'darkHorizontal' | 'darkVertical' | 'darkDown' | 'darkUp' | 'darkGrid' | 'darkTrellis' | 'lightHorizontal' | 'lightVertical' | 'lightDown' | 'lightUp' | 'lightGrid' | 'lightTrellis' | 'gray125' | 'gray0625';
|
|
51
|
+
/**
|
|
52
|
+
* Every {@link FillPatternType}, in `ST_PatternType` order, which is also the order BIFF12's `fls`
|
|
53
|
+
* field indexes: `fls` 1 is `solid`, 2 is `mediumGray`, and so on. Index 0 is `none`, which the
|
|
54
|
+
* model spells as no fill at all rather than as a pattern.
|
|
55
|
+
*
|
|
56
|
+
* One list, consulted by the guard below and by `io/xlsb/read-styles.ts`. It replaced three
|
|
57
|
+
* hand-maintained copies of one enumeration -- the union, the guard's own table, and the binary
|
|
58
|
+
* codec's index array -- of which only the first two were checked against each other, so adding a
|
|
59
|
+
* pattern forced the guard to be updated and let the binary codec silently drop it.
|
|
60
|
+
*/
|
|
61
|
+
export declare const FILL_PATTERNS_IN_SCHEMA_ORDER: readonly ["none", "solid", "mediumGray", "darkGray", "lightGray", "darkHorizontal", "darkVertical", "darkDown", "darkUp", "darkGrid", "darkTrellis", "lightHorizontal", "lightVertical", "lightDown", "lightUp", "lightGrid", "lightTrellis", "gray125", "gray0625"];
|
|
62
|
+
/**
|
|
63
|
+
* The two halves of the proof {@link FILL_PATTERNS_IN_SCHEMA_ORDER} owes, since a list -- unlike the
|
|
64
|
+
* `Record` shape every other token guard here is built from -- can name fewer members than its union
|
|
65
|
+
* without the compiler minding. `satisfies` above covers "no invented name"; this covers "no
|
|
66
|
+
* omission".
|
|
41
67
|
*/
|
|
42
|
-
export type
|
|
68
|
+
export type EveryFillPatternIsOrdered = AssertNever<Exclude<FillPatternType, (typeof FILL_PATTERNS_IN_SCHEMA_ORDER)[number]>>;
|
|
43
69
|
/** Narrow a raw `<patternFill patternType>` token to a known {@link FillPatternType}. */
|
|
44
|
-
export declare
|
|
70
|
+
export declare const isFillPatternType: (value: string) => value is FillPatternType;
|
|
45
71
|
/**
|
|
46
72
|
* A pattern fill. For a `solid` fill the visible colour is the pattern *foreground*
|
|
47
73
|
* (`fgColor`), OOXML's counter-intuitive rule, while `bgColor` is the automatic
|
|
@@ -78,13 +104,25 @@ export interface GradientFill {
|
|
|
78
104
|
}
|
|
79
105
|
/** A cell/row background fill: a flat pattern or a colour gradient. */
|
|
80
106
|
export type Fill = PatternFill | GradientFill;
|
|
107
|
+
declare const GRADIENT_STOP_CLONE: ClonePlan<GradientStop>;
|
|
108
|
+
/** The proof that {@link GRADIENT_STOP_CLONE} names every field of a gradient stop. */
|
|
109
|
+
export type EveryGradientStopFieldIsCloned = AssertNever<Exclude<keyof Required<GradientStop>, keyof typeof GRADIENT_STOP_CLONE>>;
|
|
110
|
+
declare const PATTERN_FILL_CLONE: ClonePlan<PatternFill>;
|
|
111
|
+
/** The proof that {@link PATTERN_FILL_CLONE} names every field of a pattern fill. */
|
|
112
|
+
export type EveryPatternFillFieldIsCloned = AssertNever<Exclude<keyof Required<PatternFill>, keyof typeof PATTERN_FILL_CLONE>>;
|
|
113
|
+
declare const GRADIENT_FILL_CLONE: ClonePlan<GradientFill>;
|
|
114
|
+
/** The proof that {@link GRADIENT_FILL_CLONE} names every field of a gradient fill. */
|
|
115
|
+
export type EveryGradientFillFieldIsCloned = AssertNever<Exclude<keyof Required<GradientFill>, keyof typeof GRADIENT_FILL_CLONE>>;
|
|
116
|
+
/** A defensive deep copy of a fill, whichever of the two shapes it is. The union is dispatched on
|
|
117
|
+
* `type` because the two halves share no field beyond it, so one plan could not describe both. */
|
|
118
|
+
export declare function cloneFill(fill: Fill): Fill;
|
|
81
119
|
/**
|
|
82
120
|
* Line styles a cell border edge can take, as OOXML's `ST_BorderStyle` enumerates them.
|
|
83
121
|
* `none` is the absence of an edge and is expressed by omitting the edge, not by this value.
|
|
84
122
|
*/
|
|
85
123
|
export type BorderStyle = 'thin' | 'medium' | 'thick' | 'dashed' | 'dotted' | 'double' | 'hair' | 'mediumDashed' | 'dashDot' | 'mediumDashDot' | 'dashDotDot' | 'mediumDashDotDot' | 'slantDashDot';
|
|
86
124
|
/** Narrow a raw border-edge `style` attribute to a known {@link BorderStyle}. */
|
|
87
|
-
export declare
|
|
125
|
+
export declare const isBorderStyle: (value: string) => value is BorderStyle;
|
|
88
126
|
/** One edge of a cell border: its line style, and optionally the line colour. */
|
|
89
127
|
export interface BorderEdge {
|
|
90
128
|
readonly style: BorderStyle;
|
|
@@ -105,15 +143,23 @@ export interface Border {
|
|
|
105
143
|
readonly diagonalUp?: boolean;
|
|
106
144
|
readonly diagonalDown?: boolean;
|
|
107
145
|
}
|
|
146
|
+
declare const BORDER_EDGE_CLONE: ClonePlan<BorderEdge>;
|
|
147
|
+
/** The proof that {@link BORDER_EDGE_CLONE} names every field of a border edge. */
|
|
148
|
+
export type EveryBorderEdgeFieldIsCloned = AssertNever<Exclude<keyof Required<BorderEdge>, keyof typeof BORDER_EDGE_CLONE>>;
|
|
149
|
+
declare const BORDER_CLONE: ClonePlan<Border>;
|
|
150
|
+
/** The proof that {@link BORDER_CLONE} names every side of a border. */
|
|
151
|
+
export type EveryBorderFieldIsCloned = AssertNever<Exclude<keyof Required<Border>, keyof typeof BORDER_CLONE>>;
|
|
152
|
+
/** A defensive deep copy of a border, each present edge and its colour included. */
|
|
153
|
+
export declare function cloneBorder(border: Border): Border;
|
|
108
154
|
/** Vertical alignment of a font relative to the baseline (super/subscript). */
|
|
109
155
|
export type FontVerticalAlignment = 'superscript' | 'subscript';
|
|
110
156
|
/** Narrow a raw `<vertAlign val>` token to a known {@link FontVerticalAlignment}. */
|
|
111
|
-
export declare
|
|
157
|
+
export declare const isFontVerticalAlignment: (value: string) => value is FontVerticalAlignment;
|
|
112
158
|
/** The theme-font role a `<scheme val>` names: `"minor"`/`"major"` bind the font to whichever
|
|
113
159
|
* face the workbook theme assigns that role, `"none"` leaves it a literal, unbound face. */
|
|
114
160
|
export type FontScheme = 'minor' | 'major' | 'none';
|
|
115
161
|
/** Narrow a raw `<scheme val>` token to a known {@link FontScheme}. */
|
|
116
|
-
export declare
|
|
162
|
+
export declare const isFontScheme: (value: string) => value is FontScheme;
|
|
117
163
|
/** A font, as it applies to a cell or a single rich-text run. Every facet is optional and
|
|
118
164
|
* independent, like {@link Border}/{@link Alignment}/{@link Protection}: a font sets only the
|
|
119
165
|
* facets it overrides (Excel's own default font backs the rest), so no consumer ever holds every
|
|
@@ -132,17 +178,22 @@ export interface Font {
|
|
|
132
178
|
readonly outline?: boolean;
|
|
133
179
|
readonly vertAlign?: FontVerticalAlignment;
|
|
134
180
|
}
|
|
181
|
+
declare const FONT_CLONE: ClonePlan<Font>;
|
|
182
|
+
/** The proof that {@link FONT_CLONE} names every facet of a font. */
|
|
183
|
+
export type EveryFontFieldIsCloned = AssertNever<Exclude<keyof Required<Font>, keyof typeof FONT_CLONE>>;
|
|
184
|
+
/** A defensive deep copy of a font, its nested colour included. */
|
|
185
|
+
export declare function cloneFont(font: Font): Font;
|
|
135
186
|
/** How a cell's content sits horizontally within its bounds, as OOXML's `ST_HorizontalAlignment`
|
|
136
187
|
* enumerates it. `general` is the type-dependent default (text left, numbers right) and reads
|
|
137
188
|
* back as no explicit horizontal alignment. */
|
|
138
189
|
export type HorizontalAlignment = 'general' | 'left' | 'center' | 'right' | 'fill' | 'justify' | 'centerContinuous' | 'distributed';
|
|
139
190
|
/** Narrow a raw `<alignment horizontal>` token to a known {@link HorizontalAlignment}. */
|
|
140
|
-
export declare
|
|
191
|
+
export declare const isHorizontalAlignment: (value: string) => value is HorizontalAlignment;
|
|
141
192
|
/** How a cell's content sits vertically within its bounds, as OOXML's `ST_VerticalAlignment`
|
|
142
193
|
* enumerates it. */
|
|
143
194
|
export type VerticalAlignment = 'top' | 'center' | 'bottom' | 'justify' | 'distributed';
|
|
144
195
|
/** Narrow a raw `<alignment vertical>` token to a known {@link VerticalAlignment}. */
|
|
145
|
-
export declare
|
|
196
|
+
export declare const isVerticalAlignment: (value: string) => value is VerticalAlignment;
|
|
146
197
|
/**
|
|
147
198
|
* A cell's alignment. Every facet is optional and independent; an absent facet means the cell
|
|
148
199
|
* takes Excel's default for it. The boolean flags default to off, so a cell that never enabled
|
|
@@ -158,6 +209,53 @@ export interface Alignment {
|
|
|
158
209
|
readonly shrinkToFit?: boolean;
|
|
159
210
|
readonly readingOrder?: number;
|
|
160
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* How one `<alignment>` facet encodes: which model key it is, what kind of value it carries, and the
|
|
214
|
+
* value that means "default", which the writer omits and the reader drops.
|
|
215
|
+
*
|
|
216
|
+
* Format-blind on purpose. `Alignment` is a core type and the layering gate forbids core importing a
|
|
217
|
+
* serialisation, so the table states what a facet *is* and each codec supplies the reading and the
|
|
218
|
+
* writing off the `kind`. That is where {@link SHEET_PROTECTION_FLAGS} sits and how it is consumed,
|
|
219
|
+
* and it is the shape the BIFF12 codec drives off too: `io/xlsb/read-styles.ts` walks this list and
|
|
220
|
+
* looks each facet up in a `Record` keyed by {@link Alignment}, so the bit layout stays a BIFF12 fact
|
|
221
|
+
* in the BIFF12 codec while the *set* of facets is decided here, once, for both. (That sentence used
|
|
222
|
+
* to read "if alignment ever reaches it". Alignment had reached it; the comment had not noticed, and
|
|
223
|
+
* the binary reader was restating all seven facets and their default-omission rules by hand.)
|
|
224
|
+
*
|
|
225
|
+
* The OOXML attribute name is the model key for all seven facets, so it is not restated here: a
|
|
226
|
+
* second list that is always identical is a second list to keep in step. A future facet whose
|
|
227
|
+
* attribute differs from its key is the one that would have to add the field.
|
|
228
|
+
*/
|
|
229
|
+
export type AlignmentFacet = {
|
|
230
|
+
readonly key: 'horizontal' | 'vertical';
|
|
231
|
+
readonly kind: 'token';
|
|
232
|
+
/** The enumeration guard, and what to call it in the error when a value fails it. */
|
|
233
|
+
readonly isValid: (value: string) => boolean;
|
|
234
|
+
readonly label: string;
|
|
235
|
+
/** The token that means the OOXML default, expressed by omitting the attribute. */
|
|
236
|
+
readonly omit?: string;
|
|
237
|
+
} | {
|
|
238
|
+
readonly key: 'textRotation' | 'indent' | 'readingOrder';
|
|
239
|
+
readonly kind: 'number';
|
|
240
|
+
} | {
|
|
241
|
+
readonly key: 'wrapText' | 'shrinkToFit';
|
|
242
|
+
readonly kind: 'flag';
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* The seven `<alignment>` facets, declared once. Both directions key off this list, so a facet
|
|
246
|
+
* written but not read (it survives a re-write and vanishes on load) or read but not written (the
|
|
247
|
+
* reverse) is no longer something a reviewer has to notice: {@link EveryAlignmentFacetIsDeclared}
|
|
248
|
+
* makes a facet added to {@link Alignment} and forgotten here a compile error.
|
|
249
|
+
*
|
|
250
|
+
* In ECMA-376 CT_CellAlignment order, which is the order the writer emits.
|
|
251
|
+
*/
|
|
252
|
+
export declare const ALIGNMENT_FACETS: readonly AlignmentFacet[];
|
|
253
|
+
/**
|
|
254
|
+
* Compile-time proof that {@link ALIGNMENT_FACETS} covers every {@link Alignment} facet. A facet
|
|
255
|
+
* added to the type without a table entry resolves this to that facet's name, which does not satisfy
|
|
256
|
+
* `never`, so the error names what is missing.
|
|
257
|
+
*/
|
|
258
|
+
export type EveryAlignmentFacetIsDeclared = AssertNever<Exclude<keyof Alignment, (typeof ALIGNMENT_FACETS)[number]['key']>>;
|
|
161
259
|
/**
|
|
162
260
|
* A cell's protection state, enforced only when the worksheet itself is protected. The flags
|
|
163
261
|
* do nothing on an unprotected sheet. `locked` defaults to TRUE in OOXML (every cell is locked
|
|
@@ -190,6 +288,32 @@ export interface CellStyle {
|
|
|
190
288
|
}
|
|
191
289
|
/** The names of the {@link CellStyle} facets, for helpers that copy the tuple facet-by-facet. */
|
|
192
290
|
export declare const CELL_STYLE_FACETS: (keyof CellStyle)[];
|
|
291
|
+
/**
|
|
292
|
+
* Everything a cell's *formatting* is, which is the six {@link CellStyle} facets plus two that only a
|
|
293
|
+
* cell can carry: the quote-prefix flag and the link to a named cell style.
|
|
294
|
+
*
|
|
295
|
+
* The two extras are on the cell's `xf` record exactly as the six are, and are written and read back
|
|
296
|
+
* exactly as the six are, but they sat outside the tuple, so every copy path driven by the tuple
|
|
297
|
+
* dropped them: a splice, a `duplicateRow`, or a `dst.model = src.model` turned a leading-apostrophe
|
|
298
|
+
* text cell back into an unprefixed one. That is the merge-loss the tuple exists to make impossible,
|
|
299
|
+
* so they join it. Callers that mean "the six shared facets" (a column default, a named style, a
|
|
300
|
+
* `<dxf>`) still say {@link CellStyle}; callers copying a *cell* say this.
|
|
301
|
+
*/
|
|
302
|
+
export type CellContent = CellStyle & {
|
|
303
|
+
quotePrefix?: boolean | undefined;
|
|
304
|
+
[NAMED_STYLE_ID]?: number | undefined;
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* The names of every {@link CellContent} facet, the six shared ones first. Helpers that copy a cell's
|
|
308
|
+
* whole formatting drive off this, so a facet added to either half reaches all of them at once.
|
|
309
|
+
*/
|
|
310
|
+
export declare const CELL_CONTENT_FACETS: (keyof CellContent)[];
|
|
311
|
+
/**
|
|
312
|
+
* Copy every present facet of a cell's formatting from `source` onto `target`, leaving facets
|
|
313
|
+
* `source` omits untouched: {@link assignStyleFacets} widened to the two cell-only facets. This is
|
|
314
|
+
* what a copy of a *cell* uses, so no structural edit can drop one.
|
|
315
|
+
*/
|
|
316
|
+
export declare function assignContentFacets(target: CellContent, source: Readonly<CellContent>): void;
|
|
193
317
|
/**
|
|
194
318
|
* Copy each present facet of `source` onto `target`, leaving facets `source` omits untouched: the
|
|
195
319
|
* plain-record counterpart to a cell's `applyCellStyle`, for the {@link CellStyle}-shaped targets a
|
|
@@ -205,69 +329,4 @@ export declare function assignStyleFacets(target: CellStyle, source: Readonly<Ce
|
|
|
205
329
|
* the tuple reaches a `<col>` style without anyone remembering to widen a literal.
|
|
206
330
|
*/
|
|
207
331
|
export declare function pickStyleFacets(source: Readonly<CellStyle>): CellStyle;
|
|
208
|
-
|
|
209
|
-
* A named cell style: the OOXML `cellStyleXfs`/`cellStyles` layer. A spreadsheet applies a built-in
|
|
210
|
-
* or custom style (e.g. "Normal", "Accent1") whose visual facets live in this shared, named layer
|
|
211
|
-
* rather than on each cell's direct format; a cell links to it and inherits any facet the direct
|
|
212
|
-
* format leaves unset. The facets are a cell's own (see {@link CellStyle}); `name` is the style's
|
|
213
|
-
* display name and `builtinId` its Excel gallery index when it is a built-in style.
|
|
214
|
-
*/
|
|
215
|
-
export type NamedCellStyle = Readonly<CellStyle> & {
|
|
216
|
-
readonly name?: string;
|
|
217
|
-
readonly builtinId?: number;
|
|
218
|
-
};
|
|
219
|
-
/**
|
|
220
|
-
* A differential style (OOXML CT_Dxf): formatting laid *over* whatever a cell already carries. Only
|
|
221
|
-
* the facets present override; the rest of the cell's own style shows through. It carries the subset
|
|
222
|
-
* of the cell-style facets (see {@link CellStyle}) a `<dxf>` can express: font, number format, fill,
|
|
223
|
-
* and border.
|
|
224
|
-
*
|
|
225
|
-
* Differential styles live in one workbook-level table (`<dxfs>`) that several features index into:
|
|
226
|
-
* a conditional-formatting rule's highlight format, and a table style's per-element formatting
|
|
227
|
-
* (`<tableStyleElement dxfId="…">`). They are interned and shared, so two features asking for the
|
|
228
|
-
* same formatting land on one entry.
|
|
229
|
-
*
|
|
230
|
-
* Not every facet reaches every consumer. As a **table style element**, Excel applies only the font,
|
|
231
|
-
* fill, and border: its own object model exposes `Font`, `Interior`, and `Borders` on a table style
|
|
232
|
-
* element and nothing for a number format, so a `numFmt` set here is carried faithfully through a
|
|
233
|
-
* round-trip but has no visible effect. The type is left whole rather than split, because the same
|
|
234
|
-
* value is legitimately reused across both consumers and narrowing it would only move the surprise.
|
|
235
|
-
*/
|
|
236
|
-
export type DifferentialStyle = Pick<CellStyle, 'font' | 'numFmt' | 'fill' | 'border'>;
|
|
237
|
-
/**
|
|
238
|
-
* The `<tableStyles>` block of a styles part: the custom table/pivot style definitions a file
|
|
239
|
-
* declares, and the two gallery names it nominates as the default for a new table and a new pivot.
|
|
240
|
-
*
|
|
241
|
-
* Each entry of {@link styles} is one `<tableStyle>…</tableStyle>` fragment kept verbatim, for the
|
|
242
|
-
* same reason a `<dxf>` is: a `tableStyleElement`'s `dxfId` indexes the differential-style table,
|
|
243
|
-
* which the writer re-emits **at its original indices**, so the references stay valid without
|
|
244
|
-
* reparsing anything. That index-stability is load-bearing: renumbering the dxf table would
|
|
245
|
-
* silently re-point every preserved table style at a different format.
|
|
246
|
-
*
|
|
247
|
-
* The two default names are ordinary strings, not fragments: they are re-escaped on write, so they
|
|
248
|
-
* are held decoded.
|
|
249
|
-
*/
|
|
250
|
-
export interface TableStyleTable {
|
|
251
|
-
readonly styles: readonly string[];
|
|
252
|
-
readonly defaultTableStyle?: string | undefined;
|
|
253
|
-
readonly defaultPivotStyle?: string | undefined;
|
|
254
|
-
/**
|
|
255
|
-
* The namespace prefixes the verbatim {@link styles} fragments use, mapped to their URI and to
|
|
256
|
-
* whether the source marked the prefix ignorable (`mc:Ignorable`).
|
|
257
|
-
*
|
|
258
|
-
* Carrying a fragment verbatim carries its *prefixes* too. Excel stamps a revision id
|
|
259
|
-
* (`xr9:uid="{…}"`) on every `<tableStyle>` it writes, so a fragment re-emitted under a
|
|
260
|
-
* `<styleSheet>` that declares only the default namespace is not namespace-well-formed, and no
|
|
261
|
-
* consumer can parse the part at all, which is a far louder failure than the dropped table style
|
|
262
|
-
* this preservation exists to prevent. The writer re-declares each prefix on `<styleSheet>` and
|
|
263
|
-
* re-states the ignorable ones, exactly as the source did.
|
|
264
|
-
*/
|
|
265
|
-
readonly namespaces?: readonly TableStyleNamespace[];
|
|
266
|
-
}
|
|
267
|
-
/** One namespace declaration a preserved `<tableStyle>` fragment depends on. */
|
|
268
|
-
export interface TableStyleNamespace {
|
|
269
|
-
readonly prefix: string;
|
|
270
|
-
readonly uri: string;
|
|
271
|
-
/** Whether the source listed this prefix in the stylesheet's `mc:Ignorable`. */
|
|
272
|
-
readonly ignorable: boolean;
|
|
273
|
-
}
|
|
332
|
+
export {};
|
package/dist/core/style.js
CHANGED
|
@@ -1,43 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
import { tokenSet, tokenSetOf } from '../token-set.js';
|
|
2
|
+
import { cloneWith } from './clone.js';
|
|
3
|
+
import { copyKeyIfPresent } from './containers.js';
|
|
4
|
+
import { NAMED_STYLE_ID } from './internal.js';
|
|
5
|
+
export const isNamedUnderlineStyle = tokenSet({
|
|
2
6
|
none: true,
|
|
3
7
|
single: true,
|
|
4
8
|
double: true,
|
|
5
9
|
singleAccounting: true,
|
|
6
10
|
doubleAccounting: true,
|
|
7
|
-
};
|
|
8
|
-
export function isNamedUnderlineStyle(value) {
|
|
9
|
-
return Object.hasOwn(NAMED_UNDERLINE_STYLES, value);
|
|
10
|
-
}
|
|
11
|
+
});
|
|
11
12
|
export function parseArgb(value) {
|
|
12
13
|
const hex = value.startsWith('#') ? value.slice(1) : value;
|
|
13
14
|
const argb = hex.length === 6 ? `FF${hex}` : hex;
|
|
14
15
|
return /^[0-9a-fA-F]{8}$/.test(argb) ? argb : undefined;
|
|
15
16
|
}
|
|
16
|
-
const
|
|
17
|
-
none
|
|
18
|
-
solid
|
|
19
|
-
|
|
20
|
-
darkGray
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
17
|
+
export const FILL_PATTERNS_IN_SCHEMA_ORDER = [
|
|
18
|
+
'none',
|
|
19
|
+
'solid',
|
|
20
|
+
'mediumGray',
|
|
21
|
+
'darkGray',
|
|
22
|
+
'lightGray',
|
|
23
|
+
'darkHorizontal',
|
|
24
|
+
'darkVertical',
|
|
25
|
+
'darkDown',
|
|
26
|
+
'darkUp',
|
|
27
|
+
'darkGrid',
|
|
28
|
+
'darkTrellis',
|
|
29
|
+
'lightHorizontal',
|
|
30
|
+
'lightVertical',
|
|
31
|
+
'lightDown',
|
|
32
|
+
'lightUp',
|
|
33
|
+
'lightGrid',
|
|
34
|
+
'lightTrellis',
|
|
35
|
+
'gray125',
|
|
36
|
+
'gray0625',
|
|
37
|
+
];
|
|
38
|
+
export const isFillPatternType = tokenSetOf(FILL_PATTERNS_IN_SCHEMA_ORDER);
|
|
39
|
+
const GRADIENT_STOP_CLONE = { position: 'value', color: 'record' };
|
|
40
|
+
const PATTERN_FILL_CLONE = {
|
|
41
|
+
type: 'value',
|
|
42
|
+
pattern: 'value',
|
|
43
|
+
fgColor: 'record',
|
|
44
|
+
bgColor: 'record',
|
|
36
45
|
};
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
const GRADIENT_FILL_CLONE = {
|
|
47
|
+
type: 'value',
|
|
48
|
+
gradient: 'value',
|
|
49
|
+
degree: 'value',
|
|
50
|
+
left: 'value',
|
|
51
|
+
right: 'value',
|
|
52
|
+
top: 'value',
|
|
53
|
+
bottom: 'value',
|
|
54
|
+
stops: (stops) => stops.map((stop) => cloneWith(stop, GRADIENT_STOP_CLONE)),
|
|
55
|
+
};
|
|
56
|
+
export function cloneFill(fill) {
|
|
57
|
+
return fill.type === 'gradient'
|
|
58
|
+
? cloneWith(fill, GRADIENT_FILL_CLONE)
|
|
59
|
+
: cloneWith(fill, PATTERN_FILL_CLONE);
|
|
39
60
|
}
|
|
40
|
-
const
|
|
61
|
+
export const isBorderStyle = tokenSet({
|
|
41
62
|
thin: true,
|
|
42
63
|
medium: true,
|
|
43
64
|
thick: true,
|
|
@@ -51,22 +72,44 @@ const BORDER_STYLES = {
|
|
|
51
72
|
dashDotDot: true,
|
|
52
73
|
mediumDashDotDot: true,
|
|
53
74
|
slantDashDot: true,
|
|
75
|
+
});
|
|
76
|
+
const BORDER_EDGE_CLONE = { style: 'value', color: 'record' };
|
|
77
|
+
const cloneBorderEdge = (edge) => cloneWith(edge, BORDER_EDGE_CLONE);
|
|
78
|
+
const BORDER_CLONE = {
|
|
79
|
+
left: cloneBorderEdge,
|
|
80
|
+
right: cloneBorderEdge,
|
|
81
|
+
top: cloneBorderEdge,
|
|
82
|
+
bottom: cloneBorderEdge,
|
|
83
|
+
diagonal: cloneBorderEdge,
|
|
84
|
+
diagonalUp: 'value',
|
|
85
|
+
diagonalDown: 'value',
|
|
54
86
|
};
|
|
55
|
-
export function
|
|
56
|
-
return
|
|
87
|
+
export function cloneBorder(border) {
|
|
88
|
+
return cloneWith(border, BORDER_CLONE);
|
|
57
89
|
}
|
|
58
|
-
const
|
|
90
|
+
export const isFontVerticalAlignment = tokenSet({
|
|
59
91
|
superscript: true,
|
|
60
92
|
subscript: true,
|
|
93
|
+
});
|
|
94
|
+
export const isFontScheme = tokenSet({ minor: true, major: true, none: true });
|
|
95
|
+
const FONT_CLONE = {
|
|
96
|
+
name: 'value',
|
|
97
|
+
size: 'value',
|
|
98
|
+
family: 'value',
|
|
99
|
+
scheme: 'value',
|
|
100
|
+
charset: 'value',
|
|
101
|
+
color: 'record',
|
|
102
|
+
bold: 'value',
|
|
103
|
+
italic: 'value',
|
|
104
|
+
underline: 'value',
|
|
105
|
+
strike: 'value',
|
|
106
|
+
outline: 'value',
|
|
107
|
+
vertAlign: 'value',
|
|
61
108
|
};
|
|
62
|
-
export function
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
const FONT_SCHEMES = { minor: true, major: true, none: true };
|
|
66
|
-
export function isFontScheme(value) {
|
|
67
|
-
return Object.hasOwn(FONT_SCHEMES, value);
|
|
109
|
+
export function cloneFont(font) {
|
|
110
|
+
return cloneWith(font, FONT_CLONE);
|
|
68
111
|
}
|
|
69
|
-
const
|
|
112
|
+
export const isHorizontalAlignment = tokenSet({
|
|
70
113
|
general: true,
|
|
71
114
|
left: true,
|
|
72
115
|
center: true,
|
|
@@ -75,20 +118,29 @@ const HORIZONTAL_ALIGNMENTS = {
|
|
|
75
118
|
justify: true,
|
|
76
119
|
centerContinuous: true,
|
|
77
120
|
distributed: true,
|
|
78
|
-
};
|
|
79
|
-
export
|
|
80
|
-
return Object.hasOwn(HORIZONTAL_ALIGNMENTS, value);
|
|
81
|
-
}
|
|
82
|
-
const VERTICAL_ALIGNMENTS = {
|
|
121
|
+
});
|
|
122
|
+
export const isVerticalAlignment = tokenSet({
|
|
83
123
|
top: true,
|
|
84
124
|
center: true,
|
|
85
125
|
bottom: true,
|
|
86
126
|
justify: true,
|
|
87
127
|
distributed: true,
|
|
88
|
-
};
|
|
89
|
-
export
|
|
90
|
-
|
|
91
|
-
|
|
128
|
+
});
|
|
129
|
+
export const ALIGNMENT_FACETS = [
|
|
130
|
+
{
|
|
131
|
+
key: 'horizontal',
|
|
132
|
+
kind: 'token',
|
|
133
|
+
isValid: isHorizontalAlignment,
|
|
134
|
+
label: 'horizontal alignment',
|
|
135
|
+
omit: 'general',
|
|
136
|
+
},
|
|
137
|
+
{ key: 'vertical', kind: 'token', isValid: isVerticalAlignment, label: 'vertical alignment' },
|
|
138
|
+
{ key: 'textRotation', kind: 'number' },
|
|
139
|
+
{ key: 'wrapText', kind: 'flag' },
|
|
140
|
+
{ key: 'indent', kind: 'number' },
|
|
141
|
+
{ key: 'shrinkToFit', kind: 'flag' },
|
|
142
|
+
{ key: 'readingOrder', kind: 'number' },
|
|
143
|
+
];
|
|
92
144
|
const CELL_STYLE_FACET_KEYS = {
|
|
93
145
|
fill: true,
|
|
94
146
|
numFmt: true,
|
|
@@ -98,17 +150,24 @@ const CELL_STYLE_FACET_KEYS = {
|
|
|
98
150
|
protection: true,
|
|
99
151
|
};
|
|
100
152
|
export const CELL_STYLE_FACETS = Object.keys(CELL_STYLE_FACET_KEYS);
|
|
153
|
+
const CELL_CONTENT_ONLY_KEYS = {
|
|
154
|
+
quotePrefix: true,
|
|
155
|
+
[NAMED_STYLE_ID]: true,
|
|
156
|
+
};
|
|
157
|
+
export const CELL_CONTENT_FACETS = [
|
|
158
|
+
...CELL_STYLE_FACETS,
|
|
159
|
+
...Reflect.ownKeys(CELL_CONTENT_ONLY_KEYS),
|
|
160
|
+
];
|
|
161
|
+
export function assignContentFacets(target, source) {
|
|
162
|
+
for (const facet of CELL_CONTENT_FACETS)
|
|
163
|
+
copyKeyIfPresent(target, source, facet);
|
|
164
|
+
}
|
|
101
165
|
export function assignStyleFacets(target, source) {
|
|
102
166
|
for (const facet of CELL_STYLE_FACETS)
|
|
103
|
-
|
|
167
|
+
copyKeyIfPresent(target, source, facet);
|
|
104
168
|
}
|
|
105
169
|
export function pickStyleFacets(source) {
|
|
106
170
|
const facets = {};
|
|
107
171
|
assignStyleFacets(facets, source);
|
|
108
172
|
return facets;
|
|
109
173
|
}
|
|
110
|
-
function copyFacet(target, source, key) {
|
|
111
|
-
const value = source[key];
|
|
112
|
-
if (value !== undefined)
|
|
113
|
-
target[key] = value;
|
|
114
|
-
}
|
package/dist/core/table-style.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthoringError } from '../errors.js';
|
|
1
|
+
import { AuthoringError, invalidToken, quoted } from '../errors.js';
|
|
2
2
|
export const TABLE_STYLE_ELEMENT_TYPES = [
|
|
3
3
|
'wholeTable',
|
|
4
4
|
'headerRow',
|
|
@@ -46,17 +46,17 @@ export function checkTableStyle(style) {
|
|
|
46
46
|
if (element === undefined)
|
|
47
47
|
continue;
|
|
48
48
|
if (!isTableStyleElementType(type)) {
|
|
49
|
-
throw
|
|
49
|
+
throw invalidToken('table style element', type);
|
|
50
50
|
}
|
|
51
51
|
const { size } = element;
|
|
52
52
|
if (size === undefined)
|
|
53
53
|
continue;
|
|
54
54
|
if (!STRIPE_ELEMENT_TYPES.has(type)) {
|
|
55
|
-
throw new AuthoringError(`table style element
|
|
55
|
+
throw new AuthoringError(`table style element ${quoted(type)} cannot carry a size: band width applies only to ` +
|
|
56
56
|
`${[...STRIPE_ELEMENT_TYPES].join(', ')}`);
|
|
57
57
|
}
|
|
58
58
|
if (!Number.isInteger(size) || size < 1) {
|
|
59
|
-
throw new RangeError(`
|
|
59
|
+
throw new RangeError(`invalid table style band size ${size}: expected a positive integer`);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
package/dist/core/table.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { type GridRect } from './address.ts';
|
|
2
|
+
import { type ClonePlan } from './clone.ts';
|
|
3
|
+
import { type AxisSplice } from './grid-shift.ts';
|
|
4
|
+
import type { AssertNever } from './internal.ts';
|
|
2
5
|
import type { CellStyle } from './style.ts';
|
|
3
6
|
import type { CellValue } from './value.ts';
|
|
4
7
|
/** A per-column cell format applied to a table's body cells: the facets Excel's table-column style
|
|
@@ -57,6 +60,16 @@ export interface TableStyleInfo {
|
|
|
57
60
|
/** Band the columns (alternating fill). */
|
|
58
61
|
readonly showColumnStripes?: boolean;
|
|
59
62
|
}
|
|
63
|
+
/** Copy a style, keeping only its defined fields off the literal so `exactOptionalPropertyTypes`
|
|
64
|
+
* never sees a fabricated `key: undefined`: an absent attribute must stay absent across a copy.
|
|
65
|
+
*
|
|
66
|
+
* The sentinel name `"None"` (Excel's table-style gallery entry for *no* style) is normalised to an
|
|
67
|
+
* absent name: OOXML expresses "unstyled" as a `<tableStyleInfo>` with no `name` attribute, so a
|
|
68
|
+
* literal `name="None"` would reference a style that does not exist and make the file suspect. The
|
|
69
|
+
* banding flags set alongside it are untouched. */
|
|
70
|
+
declare const STYLE_INFO_CLONE: ClonePlan<TableStyleInfo>;
|
|
71
|
+
/** The proof that {@link STYLE_INFO_CLONE} names every field of the style. */
|
|
72
|
+
export type EveryTableStyleInfoFieldIsCloned = AssertNever<Exclude<keyof Required<TableStyleInfo>, keyof typeof STYLE_INFO_CLONE>>;
|
|
60
73
|
/**
|
|
61
74
|
* OOXML's totals-row function names (`ST_TotalsRowFunction`) to the `SUBTOTAL` first-argument code
|
|
62
75
|
* Excel writes into a materialised totals cell. The `10x` band ignores manually hidden rows, the
|
|
@@ -75,7 +88,7 @@ export declare const TOTALS_ROW_SUBTOTAL_CODE: Readonly<Partial<Record<TotalsRow
|
|
|
75
88
|
*/
|
|
76
89
|
export type TotalsRowFunction = 'average' | 'countNums' | 'count' | 'max' | 'min' | 'stdDev' | 'sum' | 'var' | 'custom' | 'none';
|
|
77
90
|
/** Narrow a raw `totalsRowFunction` attribute to a known {@link TotalsRowFunction}. */
|
|
78
|
-
export declare
|
|
91
|
+
export declare const isTotalsRowFunction: (value: string) => value is TotalsRowFunction;
|
|
79
92
|
/** One column of a table: a header name and its optional totals-row behaviour. */
|
|
80
93
|
export interface TableColumn {
|
|
81
94
|
/** The column's header/display name. Must be unique within the table (case-insensitively):
|
|
@@ -158,20 +171,24 @@ export declare class Table {
|
|
|
158
171
|
*/
|
|
159
172
|
addRow(values?: readonly CellValue[]): void;
|
|
160
173
|
/**
|
|
161
|
-
* Re-pin the table through a row splice
|
|
162
|
-
*
|
|
163
|
-
* whole range by `delta`; one landing inside grows or shrinks the data rows to absorb the change;
|
|
174
|
+
* Re-pin the table through a row splice. A splice entirely above the table moves its whole range
|
|
175
|
+
* by the splice's `delta`; one landing inside grows or shrinks the data rows to absorb the change;
|
|
164
176
|
* one that deletes the table's every row removes it. Returns `false` when the table no longer has
|
|
165
177
|
* a row to occupy (the caller drops it), `true` when it survives.
|
|
166
178
|
*/
|
|
167
|
-
shiftRows(
|
|
179
|
+
shiftRows(splice: AxisSplice): boolean;
|
|
168
180
|
/**
|
|
169
|
-
* Re-pin the table through a column splice. A splice entirely to
|
|
170
|
-
* by `delta`; one to its right leaves it untouched
|
|
171
|
-
*
|
|
172
|
-
*
|
|
181
|
+
* Re-pin the table through a column splice, the mirror of {@link shiftRows}. A splice entirely to
|
|
182
|
+
* the table's left moves its anchor by the splice's `delta`; one to its right leaves it untouched;
|
|
183
|
+
* one that deletes the table's every column removes it. Returns `false` when the table no longer
|
|
184
|
+
* has a column to occupy (the caller drops it), `true` when it survives.
|
|
185
|
+
*
|
|
186
|
+
* A splice landing *inside* the table's columns is structural surgery on named columns with no
|
|
187
|
+
* unambiguous answer, so those columns are left as-is rather than fabricated or dropped. Whole-table
|
|
188
|
+
* deletion is not that case: a table left declared over whatever slid into its place, carrying the
|
|
189
|
+
* names of columns that no longer exist, is content the writer then emits.
|
|
173
190
|
*/
|
|
174
|
-
shiftColumns(
|
|
191
|
+
shiftColumns(splice: AxisSplice): boolean;
|
|
175
192
|
/**
|
|
176
193
|
* The options that reconstruct this table: the anchor as a single-cell ref (not the derived
|
|
177
194
|
* full range), the columns, and the data-row count with the header/totals flags. Feeding this
|
|
@@ -194,3 +211,4 @@ export declare class Table {
|
|
|
194
211
|
/** The occupied rectangle, for conflict checks such as overlapping merges. */
|
|
195
212
|
get region(): TableRegion;
|
|
196
213
|
}
|
|
214
|
+
export {};
|