@rowsncolumns/utils 9.6.2 → 9.6.3

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 (37) hide show
  1. package/dist/cjs/autocorrect.d.ts +28 -0
  2. package/dist/cjs/autocorrect.d.ts.map +1 -0
  3. package/dist/cjs/autocorrect.js +91 -0
  4. package/dist/cjs/index.d.ts +2 -0
  5. package/dist/cjs/index.d.ts.map +1 -1
  6. package/dist/cjs/index.js +2 -0
  7. package/dist/cjs/insert-date-time.d.ts +17 -0
  8. package/dist/cjs/insert-date-time.d.ts.map +1 -0
  9. package/dist/cjs/insert-date-time.js +26 -0
  10. package/dist/cjs/sparkline-groups.d.ts.map +1 -1
  11. package/dist/cjs/sparkline-groups.js +2 -0
  12. package/dist/cjs/table-style-presets.d.ts +9 -0
  13. package/dist/cjs/table-style-presets.d.ts.map +1 -0
  14. package/dist/cjs/table-style-presets.js +559 -0
  15. package/dist/cjs/table-styles.d.ts +52 -1
  16. package/dist/cjs/table-styles.d.ts.map +1 -1
  17. package/dist/cjs/table-styles.js +191 -386
  18. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  19. package/dist/esm/autocorrect.d.ts +28 -0
  20. package/dist/esm/autocorrect.d.ts.map +1 -0
  21. package/dist/esm/autocorrect.js +76 -0
  22. package/dist/esm/index.d.ts +2 -0
  23. package/dist/esm/index.d.ts.map +1 -1
  24. package/dist/esm/index.js +2 -0
  25. package/dist/esm/insert-date-time.d.ts +17 -0
  26. package/dist/esm/insert-date-time.d.ts.map +1 -0
  27. package/dist/esm/insert-date-time.js +21 -0
  28. package/dist/esm/sparkline-groups.d.ts.map +1 -1
  29. package/dist/esm/sparkline-groups.js +2 -0
  30. package/dist/esm/table-style-presets.d.ts +9 -0
  31. package/dist/esm/table-style-presets.d.ts.map +1 -0
  32. package/dist/esm/table-style-presets.js +556 -0
  33. package/dist/esm/table-styles.d.ts +52 -1
  34. package/dist/esm/table-styles.d.ts.map +1 -1
  35. package/dist/esm/table-styles.js +149 -383
  36. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  37. package/package.json +2 -2
@@ -45,7 +45,30 @@ export type BandingProperties = {
45
45
  export type BandedDefinition = {
46
46
  rowProperties?: Maybe<BandingProperties>;
47
47
  columnProperties?: Maybe<BandingProperties>;
48
+ /**
49
+ * The table style element by element (Excel's `<tableStyleElement>`s), set for the built-in
50
+ * styles. When present the grid paints from it with Excel's element precedence and the
51
+ * table's show-flags (`resolveTableStyleCell`); `rowProperties` / `columnProperties` remain
52
+ * as the coarse summary older readers (the custom-style editor, the exporter) understand.
53
+ */
54
+ tableStyleElements?: Maybe<TableStyleElements>;
55
+ };
56
+ /** Excel's table style element types (ECMA-376 §18.18.83 ST_TableStyleType), table subset. */
57
+ export type TableStyleElementType = "wholeTable" | "headerRow" | "totalRow" | "firstColumn" | "lastColumn" | "firstRowStripe" | "secondRowStripe" | "firstColumnStripe" | "secondColumnStripe";
58
+ /**
59
+ * One element's differential format. `top` / `bottom` / `left` / `right` rule the element's
60
+ * outer edges; `horizontal` / `vertical` rule the edges between its cells.
61
+ */
62
+ export type TableStyleElementFormat = {
63
+ fill?: Maybe<Color>;
64
+ color?: Maybe<Color>;
65
+ bold?: Maybe<boolean>;
66
+ borders?: Maybe<Borders & {
67
+ horizontal?: Maybe<Border>;
68
+ vertical?: Maybe<Border>;
69
+ }>;
48
70
  };
71
+ export type TableStyleElements = Partial<Record<TableStyleElementType, TableStyleElementFormat>>;
49
72
  export type TableTheme = "None" | "TableStyleLight1" | "TableStyleLight2" | "TableStyleLight3" | "TableStyleLight4" | "TableStyleLight5" | "TableStyleLight6" | "TableStyleLight7" | "TableStyleLight8" | "TableStyleLight9" | "TableStyleLight10" | "TableStyleLight11" | "TableStyleLight12" | "TableStyleLight13" | "TableStyleLight14" | "TableStyleLight15" | "TableStyleLight16" | "TableStyleLight17" | "TableStyleLight18" | "TableStyleLight19" | "TableStyleLight20" | "TableStyleLight21" | "TableStyleMedium1" | "TableStyleMedium2" | "TableStyleMedium3" | "TableStyleMedium4" | "TableStyleMedium5" | "TableStyleMedium6" | "TableStyleMedium7" | "TableStyleMedium8" | "TableStyleMedium9" | "TableStyleMedium10" | "TableStyleMedium11" | "TableStyleMedium12" | "TableStyleMedium13" | "TableStyleMedium14" | "TableStyleMedium15" | "TableStyleMedium16" | "TableStyleMedium17" | "TableStyleMedium18" | "TableStyleMedium19" | "TableStyleMedium20" | "TableStyleMedium21" | "TableStyleMedium22" | "TableStyleMedium23" | "TableStyleMedium24" | "TableStyleMedium25" | "TableStyleMedium26" | "TableStyleMedium27" | "TableStyleMedium28" | "TableStyleDark1" | "TableStyleDark2" | "TableStyleDark3" | "TableStyleDark4" | "TableStyleDark5" | "TableStyleDark6" | "TableStyleDark7" | "TableStyleDark8" | "TableStyleDark9" | "TableStyleDark10" | "TableStyleDark11";
50
73
  type TableStyleEntry = [
51
74
  theme: TableTheme,
@@ -54,12 +77,40 @@ type TableStyleEntry = [
54
77
  bandDefinition: BandedDefinition | undefined
55
78
  ];
56
79
  /**
57
- * Get table border styles map with all table themes and their banded definitions
80
+ * Excel's 60 built-in table styles by gallery group (Light 1–21, Medium 1–28, Dark 1–11; "None"
81
+ * leads the Light group), each with its banded definition for the given stripe toggles.
82
+ * Element formats come from ECMA-376 `presetTableStyles.xml` (`./table-style-presets`).
58
83
  */
59
84
  export declare const getTableBorderStyles: (showRowStripes: boolean | undefined, showColumnStripes: boolean | undefined) => Map<string, TableStyleEntry[]>;
60
85
  /**
61
86
  * Find the banded definition for a given table theme
62
87
  */
63
88
  export declare const findMatchingBandProperty: (tableTheme: TableTheme, showRowStripes: boolean | undefined, showColumnStripes: boolean | undefined) => BandedDefinition | undefined;
89
+ /** Where a cell sits in a table, counted over its visible rows and columns. */
90
+ export type TableStyleCellPosition = {
91
+ rowIndex: number;
92
+ columnIndex: number;
93
+ rowCount: number;
94
+ columnCount: number;
95
+ headerRow: boolean;
96
+ totalRow: boolean;
97
+ showFirstColumn: boolean;
98
+ showLastColumn: boolean;
99
+ };
100
+ export type ResolvedTableStyleCell = {
101
+ fill?: Color;
102
+ color?: Color;
103
+ bold?: boolean;
104
+ borders?: Borders;
105
+ };
106
+ /**
107
+ * A table cell's format from its style elements, the way Excel layers them: whole table, then
108
+ * column stripes, row stripes, last column, first column, header row and total row — a later
109
+ * element overrides the earlier ones on each property it sets. Stripes cover the body rows
110
+ * only; the header / total rows and first / last columns apply per the table's show-flags.
111
+ * An element's outer borders rule its region's edges and `horizontal` / `vertical` its inner
112
+ * edges.
113
+ */
114
+ export declare const resolveTableStyleCell: (elements: TableStyleElements, position: TableStyleCellPosition) => ResolvedTableStyleCell;
64
115
  export {};
65
116
  //# sourceMappingURL=table-styles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"table-styles.d.ts","sourceRoot":"","sources":["../../table-styles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAG5C,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,UAAU,CAAC;AAExC,MAAM,MAAM,WAAW,GACnB,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,MAAM,GACN,cAAc,GACd,aAAa,GACb,QAAQ,CAAC;AAGb,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,C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Ac,EAAE,MAAM,GAAG,SAAS;IAClC,cAAc,EAAE,gBAAgB,GAAG,SAAS;CAC7C,CAAC;AAmEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,gBAAgB,OAAO,GAAG,SAAS,EACnC,mBAAmB,OAAO,GAAG,SAAS,KACrC,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,CAqB/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GACnC,YAAY,UAAU,EACtB,gBAAgB,OAAO,GAAG,SAAS,EACnC,mBAAmB,OAAO,GAAG,SAAS,KACrC,gBAAgB,GAAG,SAUrB,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAChC,UAAU,kBAAkB,EAC5B,UAAU,sBAAsB,KAC/B,sBAgEF,CAAC"}
@@ -2,380 +2,91 @@
2
2
  * Table styles and banded range utilities
3
3
  * Shared between toolkit (import) and app (rendering)
4
4
  */
5
- const stripeTint = 0.8;
6
- const colorIndexes = [1, 4, 5, 6, 7, 8, 9];
5
+ import { TABLE_STYLE_PRESETS } from "./table-style-presets";
6
+ const ROW_STRIPES = ["firstRowStripe", "secondRowStripe"];
7
+ const COLUMN_STRIPES = [
8
+ "firstColumnStripe",
9
+ "secondColumnStripe",
10
+ ];
11
+ const outerEdges = (borders) => {
12
+ const { top, bottom, left, right } = borders ?? {};
13
+ const edges = {};
14
+ if (top)
15
+ edges.top = top;
16
+ if (bottom)
17
+ edges.bottom = bottom;
18
+ if (left)
19
+ edges.left = left;
20
+ if (right)
21
+ edges.right = right;
22
+ return Object.keys(edges).length ? edges : undefined;
23
+ };
24
+ const compact = (value) => {
25
+ for (const key of Object.keys(value)) {
26
+ if (value[key] == null)
27
+ delete value[key];
28
+ }
29
+ return Object.keys(value).length ? value : undefined;
30
+ };
31
+ /**
32
+ * A built-in style's banded definition for the table's stripe toggles: its elements (stripe
33
+ * elements dropped when the stripes are off) plus the coarse row / column summary.
34
+ */
35
+ const presetBandedDefinition = (preset, showRowStripes, showColumnStripes) => {
36
+ // A fresh copy per call: callers store and may mutate the result; the presets stay shared.
37
+ const elements = JSON.parse(JSON.stringify(preset));
38
+ if (!showRowStripes)
39
+ for (const type of ROW_STRIPES)
40
+ delete elements[type];
41
+ if (!showColumnStripes)
42
+ for (const type of COLUMN_STRIPES)
43
+ delete elements[type];
44
+ const { headerRow, totalRow, firstColumn, lastColumn } = elements;
45
+ const rowProperties = compact({
46
+ headerColor: headerRow?.fill,
47
+ headerBorder: outerEdges(headerRow?.borders),
48
+ firstBandColor: elements.firstRowStripe?.fill,
49
+ secondBandColor: elements.secondRowStripe?.fill,
50
+ totalRowColor: totalRow?.fill,
51
+ totalRowBorder: outerEdges(totalRow?.borders),
52
+ totalRowBold: totalRow?.bold,
53
+ firstColumnColor: firstColumn?.fill,
54
+ lastColumnColor: lastColumn?.fill,
55
+ });
56
+ const columnProperties = compact({
57
+ firstBandColor: elements.firstColumnStripe?.fill,
58
+ secondBandColor: elements.secondColumnStripe?.fill,
59
+ });
60
+ return compact({
61
+ rowProperties,
62
+ columnProperties,
63
+ tableStyleElements: elements,
64
+ });
65
+ };
66
+ const FAMILIES = [
67
+ ["Light", 21],
68
+ ["Medium", 28],
69
+ ["Dark", 11],
70
+ ];
7
71
  /**
8
- * Get table border styles map with all table themes and their banded definitions
72
+ * Excel's 60 built-in table styles by gallery group (Light 1–21, Medium 1–28, Dark 1–11; "None"
73
+ * leads the Light group), each with its banded definition for the given stripe toggles.
74
+ * Element formats come from ECMA-376 `presetTableStyles.xml` (`./table-style-presets`).
9
75
  */
10
76
  export const getTableBorderStyles = (showRowStripes, showColumnStripes) => {
11
- let runningLightIndex = 1;
12
- let runningMediumIndex = 1;
13
- let runningDarkIndex = 1;
14
- const styles = new Map([
15
- [
16
- "Light",
17
- [
18
- ["None", 0, 0, undefined],
19
- ...colorIndexes.map((value) => {
20
- return [
21
- ("TableStyleLight" + runningLightIndex++),
22
- stripeTint,
23
- 1,
24
- {
25
- rowProperties: {
26
- firstBandColor: {
27
- theme: value,
28
- tint: showRowStripes ? stripeTint : 1,
29
- },
30
- secondBandColor: showRowStripes
31
- ? {
32
- theme: 0,
33
- }
34
- : undefined,
35
- headerBorder: {
36
- top: {
37
- width: 1,
38
- style: "solid",
39
- color: { theme: value },
40
- },
41
- bottom: {
42
- width: 1,
43
- style: "solid",
44
- color: { theme: value },
45
- },
46
- },
47
- footerBorder: {
48
- bottom: {
49
- width: 1,
50
- style: "solid",
51
- color: { theme: value },
52
- },
53
- },
54
- },
55
- columnProperties: showColumnStripes
56
- ? {
57
- firstBandColor: {
58
- theme: value,
59
- tint: showColumnStripes ? stripeTint : 1,
60
- },
61
- }
62
- : undefined,
63
- },
64
- ];
65
- }),
66
- ...colorIndexes.map((value) => {
67
- return [
68
- ("TableStyleLight" + runningLightIndex++),
69
- undefined,
70
- undefined,
71
- {
72
- rowProperties: {
73
- headerColor: { theme: value },
74
- },
75
- },
76
- ];
77
- }),
78
- ...colorIndexes.map((value) => {
79
- const border = {
80
- width: 1,
81
- style: "solid",
82
- color: { theme: value },
83
- };
84
- return [
85
- ("TableStyleLight" + runningLightIndex++),
86
- stripeTint,
87
- 1,
88
- {
89
- rowProperties: {
90
- firstBandColor: {
91
- theme: value,
92
- tint: showRowStripes ? stripeTint : 1,
93
- },
94
- secondBandColor: showRowStripes
95
- ? {
96
- theme: 0,
97
- }
98
- : undefined,
99
- firstBandBorder: {
100
- top: border,
101
- left: border,
102
- right: border,
103
- bottom: border,
104
- },
105
- headerBorder: {
106
- top: border,
107
- left: border,
108
- right: border,
109
- bottom: border,
110
- },
111
- },
112
- columnProperties: showColumnStripes
113
- ? {
114
- firstBandColor: {
115
- theme: value,
116
- tint: showColumnStripes ? stripeTint : 1,
117
- },
118
- }
119
- : undefined,
120
- },
121
- ];
122
- }),
123
- ],
124
- ],
125
- [
126
- "Medium",
127
- [
128
- ...colorIndexes.map((value) => {
129
- return [
130
- ("TableStyleMedium" + runningMediumIndex++),
131
- stripeTint,
132
- 1,
133
- {
134
- rowProperties: {
135
- headerColor: { theme: value },
136
- firstBandColor: {
137
- theme: value,
138
- tint: showRowStripes ? stripeTint : 1,
139
- },
140
- secondBandColor: showRowStripes
141
- ? {
142
- theme: 0,
143
- }
144
- : undefined,
145
- firstBandBorder: {
146
- bottom: {
147
- width: 1,
148
- style: "solid",
149
- color: { theme: value },
150
- },
151
- },
152
- },
153
- columnProperties: showColumnStripes
154
- ? {
155
- firstBandColor: {
156
- theme: value,
157
- tint: showColumnStripes ? stripeTint : 1,
158
- },
159
- }
160
- : undefined,
161
- },
162
- ];
163
- }),
164
- ...colorIndexes.map((value) => {
165
- return [
166
- ("TableStyleMedium" + runningMediumIndex++),
167
- 0.6,
168
- 0.8,
169
- {
170
- rowProperties: {
171
- headerColor: { theme: value },
172
- firstBandColor: {
173
- theme: value,
174
- tint: showRowStripes ? 0.6 : 0.8,
175
- },
176
- secondBandColor: {
177
- theme: value,
178
- tint: 0.8,
179
- },
180
- },
181
- columnProperties: showColumnStripes
182
- ? {
183
- firstBandColor: {
184
- theme: value,
185
- tint: showColumnStripes ? 0.6 : 0.8,
186
- },
187
- }
188
- : undefined,
189
- },
190
- ];
191
- }),
192
- ...colorIndexes.map((value) => {
193
- const border = {
194
- width: 2,
195
- style: "solid",
196
- color: { theme: 1 },
197
- };
198
- return [
199
- ("TableStyleMedium" + runningMediumIndex++),
200
- -0.15,
201
- 1,
202
- {
203
- rowProperties: {
204
- headerColor: { theme: value },
205
- firstBandColor: {
206
- theme: 0,
207
- tint: showRowStripes ? -0.15 : 1,
208
- },
209
- secondBandColor: showRowStripes
210
- ? {
211
- theme: 0,
212
- }
213
- : undefined,
214
- headerBorder: {
215
- top: border,
216
- },
217
- footerBorder: {
218
- bottom: border,
219
- },
220
- },
221
- columnProperties: showColumnStripes
222
- ? {
223
- firstBandColor: {
224
- theme: 0,
225
- tint: showColumnStripes ? -0.15 : 1,
226
- },
227
- }
228
- : undefined,
229
- },
230
- ];
231
- }),
232
- ...colorIndexes.map((value) => {
233
- const border = {
234
- width: 1,
235
- style: "solid",
236
- color: { theme: value },
237
- };
238
- return [
239
- ("TableStyleMedium" + runningMediumIndex++),
240
- stripeTint,
241
- 0.9,
242
- {
243
- rowProperties: {
244
- headerColor: {
245
- theme: value,
246
- tint: 0.9,
247
- },
248
- firstBandColor: {
249
- theme: value,
250
- tint: showRowStripes ? stripeTint : 0.9,
251
- },
252
- secondBandColor: {
253
- theme: value,
254
- tint: 0.9,
255
- },
256
- firstBandBorder: {
257
- top: border,
258
- left: border,
259
- right: border,
260
- bottom: border,
261
- },
262
- headerBorder: {
263
- top: border,
264
- left: border,
265
- right: border,
266
- bottom: border,
267
- },
268
- },
269
- columnProperties: showColumnStripes
270
- ? {
271
- firstBandColor: {
272
- theme: value,
273
- tint: showColumnStripes ? stripeTint : 0.9,
274
- },
275
- }
276
- : undefined,
277
- },
278
- ];
279
- }),
280
- ],
281
- ],
282
- [
283
- "Dark",
284
- [
285
- ...colorIndexes.map((value) => {
286
- const firstTint = value - 1 === 0 ? 0.25 : -0.25;
287
- const secondTint = value - 1 === 0 ? 0.5 : 0;
288
- const edgeColumnColor = {
289
- theme: value,
290
- tint: value - 1 === 0 ? 0.15 : -0.5,
291
- };
292
- return [
293
- ("TableStyleDark" + runningDarkIndex++),
294
- firstTint,
295
- secondTint,
296
- {
297
- rowProperties: {
298
- headerColor: { theme: 1 },
299
- firstBandColor: {
300
- theme: value,
301
- tint: showRowStripes ? firstTint : secondTint,
302
- },
303
- secondBandColor: {
304
- theme: value,
305
- tint: secondTint,
306
- },
307
- firstColumnColor: edgeColumnColor,
308
- lastColumnColor: edgeColumnColor,
309
- },
310
- columnProperties: showColumnStripes
311
- ? {
312
- firstBandColor: {
313
- theme: value,
314
- tint: showColumnStripes ? firstTint : secondTint,
315
- },
316
- }
317
- : undefined,
318
- },
319
- ];
320
- }),
321
- ...[1, 5, 7, 9].map((value) => {
322
- const firstTint = value - 1 === 0 ? -0.35 : 0.6;
323
- const secondTint = value - 1 === 0 ? -0.15 : 0.8;
324
- const edgeColumnColor = {
325
- theme: value - 1,
326
- tint: value - 1 === 0 ? -0.5 : 0.4,
327
- };
328
- return [
329
- ("TableStyleDark" + runningDarkIndex++),
330
- firstTint,
331
- secondTint,
332
- {
333
- rowProperties: {
334
- headerColor: { theme: value },
335
- firstBandColor: {
336
- theme: value - 1,
337
- tint: showRowStripes ? firstTint : secondTint,
338
- },
339
- secondBandColor: {
340
- theme: value - 1,
341
- tint: secondTint,
342
- },
343
- firstColumnColor: edgeColumnColor,
344
- lastColumnColor: edgeColumnColor,
345
- },
346
- columnProperties: showColumnStripes
347
- ? {
348
- firstBandColor: {
349
- theme: value - 1,
350
- tint: showColumnStripes ? firstTint : secondTint,
351
- },
352
- }
353
- : undefined,
354
- },
355
- ];
356
- }),
357
- ],
358
- ],
359
- ]);
360
- // Excel's built-in table styles bold the totals row and rule it with a double top border in
361
- // the style's accent colour — the header border's colour, else the header fill's, else the
362
- // stripe border's.
363
- for (const entries of styles.values()) {
364
- for (const [, , , bandDefinition] of entries) {
365
- const rows = bandDefinition?.rowProperties;
366
- if (!rows)
367
- continue;
368
- rows.totalRowBold = true;
369
- const accent = rows.headerBorder?.top?.color ??
370
- rows.headerBorder?.bottom?.color ??
371
- rows.headerColor ??
372
- rows.firstBandBorder?.bottom?.color;
373
- if (accent && !rows.totalRowBorder) {
374
- rows.totalRowBorder = {
375
- top: { width: 1, style: "double", color: accent },
376
- };
377
- }
77
+ const styles = new Map();
78
+ for (const [family, count] of FAMILIES) {
79
+ const entries = family === "Light" ? [["None", 0, 0, undefined]] : [];
80
+ for (let n = 1; n <= count; n++) {
81
+ const name = `TableStyle${family}${n}`;
82
+ entries.push([
83
+ name,
84
+ undefined,
85
+ undefined,
86
+ presetBandedDefinition(TABLE_STYLE_PRESETS[name], showRowStripes, showColumnStripes),
87
+ ]);
378
88
  }
89
+ styles.set(family, entries);
379
90
  }
380
91
  return styles;
381
92
  };
@@ -383,18 +94,73 @@ export const getTableBorderStyles = (showRowStripes, showColumnStripes) => {
383
94
  * Find the banded definition for a given table theme
384
95
  */
385
96
  export const findMatchingBandProperty = (tableTheme, showRowStripes, showColumnStripes) => {
386
- const bandProperties = getTableBorderStyles(showRowStripes, showColumnStripes);
387
- let result;
388
- bandProperties.forEach((tableStyles) => {
389
- if (result)
97
+ const preset = Object.prototype.hasOwnProperty.call(TABLE_STYLE_PRESETS, tableTheme)
98
+ ? TABLE_STYLE_PRESETS[tableTheme]
99
+ : undefined;
100
+ return preset
101
+ ? presetBandedDefinition(preset, showRowStripes, showColumnStripes)
102
+ : undefined;
103
+ };
104
+ /**
105
+ * A table cell's format from its style elements, the way Excel layers them: whole table, then
106
+ * column stripes, row stripes, last column, first column, header row and total row — a later
107
+ * element overrides the earlier ones on each property it sets. Stripes cover the body rows
108
+ * only; the header / total rows and first / last columns apply per the table's show-flags.
109
+ * An element's outer borders rule its region's edges and `horizontal` / `vertical` its inner
110
+ * edges.
111
+ */
112
+ export const resolveTableStyleCell = (elements, position) => {
113
+ const { rowIndex: r, columnIndex: c, rowCount, columnCount } = position;
114
+ const lastRow = rowCount - 1;
115
+ const lastColumn = columnCount - 1;
116
+ const bodyStart = position.headerRow ? 1 : 0;
117
+ const bodyEnd = position.totalRow ? lastRow - 1 : lastRow;
118
+ const isBody = r >= bodyStart && r <= bodyEnd;
119
+ const out = {};
120
+ const borders = {};
121
+ const apply = (format, r0, r1, c0, c1) => {
122
+ if (!format)
390
123
  return;
391
- for (let i = 0; i < tableStyles.length; i++) {
392
- const [themeName, , , bandDefinition] = tableStyles[i];
393
- if (themeName === tableTheme) {
394
- result = bandDefinition ? { ...bandDefinition } : undefined;
395
- return;
396
- }
397
- }
398
- });
399
- return result;
124
+ if (format.fill)
125
+ out.fill = format.fill;
126
+ if (format.color)
127
+ out.color = format.color;
128
+ if (format.bold)
129
+ out.bold = true;
130
+ const b = format.borders;
131
+ if (!b)
132
+ return;
133
+ const top = r === r0 ? b.top : b.horizontal;
134
+ const bottom = r === r1 ? b.bottom : b.horizontal;
135
+ const left = c === c0 ? b.left : b.vertical;
136
+ const right = c === c1 ? b.right : b.vertical;
137
+ if (top)
138
+ borders.top = top;
139
+ if (bottom)
140
+ borders.bottom = bottom;
141
+ if (left)
142
+ borders.left = left;
143
+ if (right)
144
+ borders.right = right;
145
+ };
146
+ apply(elements.wholeTable, 0, lastRow, 0, lastColumn);
147
+ if (isBody) {
148
+ apply(elements[c % 2 === 0 ? "firstColumnStripe" : "secondColumnStripe"], bodyStart, bodyEnd, c, c);
149
+ apply(elements[(r - bodyStart) % 2 === 0 ? "firstRowStripe" : "secondRowStripe"], r, r, 0, lastColumn);
150
+ }
151
+ if (position.showLastColumn && c === lastColumn) {
152
+ apply(elements.lastColumn, 0, lastRow, c, c);
153
+ }
154
+ if (position.showFirstColumn && c === 0) {
155
+ apply(elements.firstColumn, 0, lastRow, c, c);
156
+ }
157
+ if (position.headerRow && r === 0) {
158
+ apply(elements.headerRow, r, r, 0, lastColumn);
159
+ }
160
+ if (position.totalRow && r === lastRow) {
161
+ apply(elements.totalRow, r, r, 0, lastColumn);
162
+ }
163
+ if (Object.keys(borders).length)
164
+ out.borders = borders;
165
+ return out;
400
166
  };
@@ -1 +1 @@
1
- {"root":["../../array.ts","../../cell-data-helpers.ts","../../cjk-number-format.ts","../../clipboard-html-sanitize.ts","../../color.ts","../../colors.ts","../../condition-operand.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../excel-number-format.ts","../../formatter.ts","../../formula-locale.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../rich-text-html.ts","../../rich-text-links.ts","../../selection.ts","../../shared-string-canonical.ts","../../sheet-names.ts","../../sheet-protection.ts","../../sheet-span.ts","../../sort.ts","../../sparkline-groups.ts","../../string.ts","../../table-names.ts","../../table-styles.ts","../../table-totals.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts","../../formula-locale/formula-locale-data.generated.ts"],"version":"5.8.3"}
1
+ {"root":["../../array.ts","../../autocorrect.ts","../../cell-data-helpers.ts","../../cjk-number-format.ts","../../clipboard-html-sanitize.ts","../../color.ts","../../colors.ts","../../condition-operand.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../excel-number-format.ts","../../formatter.ts","../../formula-locale.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../insert-date-time.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../rich-text-html.ts","../../rich-text-links.ts","../../selection.ts","../../shared-string-canonical.ts","../../sheet-names.ts","../../sheet-protection.ts","../../sheet-span.ts","../../sort.ts","../../sparkline-groups.ts","../../string.ts","../../table-names.ts","../../table-style-presets.ts","../../table-styles.ts","../../table-totals.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts","../../formula-locale/formula-locale-data.generated.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowsncolumns/utils",
3
- "version": "9.6.2",
3
+ "version": "9.6.3",
4
4
  "author": "Vinay M",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "main": "./dist/cjs/index.js",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "numfmt": "^3.2.2",
47
- "@rowsncolumns/common-types": ">=5.3.5"
47
+ "@rowsncolumns/common-types": ">=5.3.6"
48
48
  },
49
49
  "devDependencies": {},
50
50
  "peerDependencies": {}