@sheetpane/tables 0.0.0-stage → 0.4.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Arpit Arya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,41 @@
1
- # Temporary Holding Version
1
+ # @sheetpane/tables
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Excel tables in `<sheetpane-excel>`, drawn as their style draws them — header row, banded rows and columns, totals row.**
4
+
5
+ A table (a ListObject — *Insert › Table* in Excel) is read by `@sheetpane/import` whether or not
6
+ this plugin is on: every sheet carries its `tables` (name, range, header and totals rows, columns,
7
+ style). This plugin only draws them:
8
+
9
+ ```js
10
+ import '@sheetpane/grid';
11
+ import '@sheetpane/tables'; // registers `tables`
12
+ excel.setAttribute('plugins', 'tables styles');
13
+ ```
14
+
15
+ or `createWorkbook({ plugins: [tables()] })`.
16
+
17
+ | a table's | drawn |
18
+ |---|---|
19
+ | header row | bold; filled in the style's colour with light text (Medium), or a line under it (Light) |
20
+ | banded rows / columns | every other data row or column filled in a light tint of the style's colour |
21
+ | first / last column | bold, when the table turns it on |
22
+ | totals row | bold, under a double line |
23
+ | lines | Light: over and under the table; Medium: under every row |
24
+
25
+ - **Styles:** `TableStyleLight1`–`7` and `TableStyleMedium1`–`7`, in the workbook's theme colours
26
+ (style 1 in the dark text colour, 2–7 in accents 1–6) — `TABLE_STYLES`. Any other style (Light
27
+ 8–21, Medium 8–28, Dark, a custom style) draws a bold header row only; a table with no style
28
+ draws nothing, as Excel's *None*.
29
+ - **Order:** a cell's own format (`@sheetpane/styles`) and a conditional format
30
+ (`@sheetpane/condfmt`) draw over the table's style, as in Excel, whatever order `plugins` lists
31
+ them in.
32
+ - **Draw-only:** no control, no change, nothing written — a download keeps the file's table parts
33
+ as they were.
34
+ - **Headless helpers:** `tableAt(sheet, row, col)`, `findTable(book, name)`, `tableCss(table, row,
35
+ col, theme)`, `paletteOf(style, theme)`.
36
+
37
+ **Structured references** — `Units[Name]`, `Units[[#Data],[Name]]` — are resolved by
38
+ `@sheetpane/export`'s `resolveStructuredRef`, which `@sheetpane/validation` uses for list sources:
39
+ a dropdown over a table column reads the table's cells, with or without this plugin.
40
+
41
+ Spec: [SR-TABLES](../../records/0122_TABLES.md). MIT.
@@ -0,0 +1,66 @@
1
+ import { type CellContext, type Plugin, type StyleSubset } from '@sheetpane/grid';
2
+ export { TABLE_STYLES, DEFAULT_THEME, paletteOf, tint, type TablePalette } from './styles.js';
3
+ /** The plugin's id, and the name `plugins="…"` takes. */
4
+ export declare const PLUGIN_ID = "tables";
5
+ /** A sheet, as a hook sees it. */
6
+ export type Sheet = CellContext['sheet'];
7
+ /** The workbook, as a hook sees it. */
8
+ export type Book = CellContext['book'];
9
+ /** One Excel table: `@sheetpane/import`'s `Table`. */
10
+ export type Table = Sheet['tables'][number];
11
+ /**
12
+ * The table a cell sits in, if any.
13
+ *
14
+ * @param sheet - The sheet.
15
+ * @param row - The cell's row, 0-based.
16
+ * @param col - The cell's column, 0-based.
17
+ * @returns The table, or `undefined`.
18
+ */
19
+ export declare function tableAt(sheet: Sheet, row: number, col: number): Table | undefined;
20
+ /**
21
+ * A table by its name — the name formulas use — case-insensitive, and the sheet it sits on.
22
+ *
23
+ * @param book - The workbook.
24
+ * @param name - The table's name, e.g. `Units`.
25
+ * @returns The table and its sheet's name, or `undefined`.
26
+ */
27
+ export declare function findTable(book: Book, name: string): {
28
+ sheet: string;
29
+ table: Table;
30
+ } | undefined;
31
+ /**
32
+ * One cell's look inside a table: the header row bold (filled, for a Medium style), banded rows and columns
33
+ * filled, the first and last columns bold, the totals row bold under a double line, the style's lines. A
34
+ * style outside {@link TABLE_STYLES} draws a bold header row only; a table that names no style draws nothing,
35
+ * as Excel's *None*. A filled cell is given the theme's dark text colour, so it reads in a dark host too.
36
+ *
37
+ * @param table - The table.
38
+ * @param row - The cell's row, 0-based.
39
+ * @param col - The cell's column, 0-based.
40
+ * @param theme - The workbook's theme colours (`RRGGBB` by SpreadsheetML index); Office's when empty.
41
+ * @returns The CSS, or `undefined` when the cell is outside the table or nothing is drawn there.
42
+ */
43
+ export declare function tableCss(table: Table, row: number, col: number, theme?: readonly string[]): StyleSubset | undefined;
44
+ /**
45
+ * The tables plugin: each Excel table in the workbook drawn as its style draws it — header row, banded rows
46
+ * and columns, first and last column, totals row — through the `decorate` hook. A cell's own format
47
+ * (`@sheetpane/styles`) and conditional formats (`@sheetpane/condfmt`) draw over it, as in Excel. Importing
48
+ * this module registers it as `tables`.
49
+ *
50
+ * @returns The plugin (`id: 'tables'`).
51
+ * @see https://github.com/arpitarya/sheetpane/blob/main/records/0122_TABLES.md
52
+ * @example
53
+ * ```ts
54
+ * import { createWorkbook } from '@sheetpane/grid';
55
+ * import { tables } from '@sheetpane/tables';
56
+ *
57
+ * excel.workbook = createWorkbook({ plugins: [tables()] });
58
+ * ```
59
+ * @example
60
+ * ```ts
61
+ * import '@sheetpane/tables'; // registers `tables`
62
+ * excel.setAttribute('plugins', 'tables styles');
63
+ * ```
64
+ */
65
+ export declare function tables(): Plugin;
66
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAIlG,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE9F,yDAAyD;AACzD,eAAO,MAAM,SAAS,WAAW,CAAC;AAElC,kCAAkC;AAClC,MAAM,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;AACzC,uCAAuC;AACvC,MAAM,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AACvC,sDAAsD;AACtD,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAe5C;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAEjF;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG,SAAS,CAO/F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,WAAW,GAAG,SAAS,CAmBvH;AAeD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAS/B"}
package/dist/index.js ADDED
@@ -0,0 +1,143 @@
1
+ // @sheetpane/tables (W-61) — a workbook's Excel tables, drawn: each table's header row, banded rows and
2
+ // columns, first and last column and totals row, from its built-in table style, through the `decorate`
3
+ // hook. Reading the tables is @sheetpane/import's (`ImportedSheet.tables`); resolving `Units[Name]` is
4
+ // @sheetpane/export's `resolveStructuredRef`. Draw-only: no control, no change, nothing exported.
5
+ // Spec: records/0122_TABLES.md (SR-TABLES).
6
+ import { registerPlugin } from '@sheetpane/grid';
7
+ import { parseRange } from '@sheetpane/export';
8
+ import { paletteOf } from './styles.js';
9
+ export { TABLE_STYLES, DEFAULT_THEME, paletteOf, tint } from './styles.js';
10
+ /** The plugin's id, and the name `plugins="…"` takes. */
11
+ export const PLUGIN_ID = 'tables';
12
+ const placed = new WeakMap();
13
+ function placedOf(sheet) {
14
+ let list = placed.get(sheet);
15
+ if (!list) {
16
+ list = [];
17
+ for (const table of sheet.tables ?? []) {
18
+ const box = parseRange(table.ref);
19
+ if (box)
20
+ list.push({ table, box });
21
+ }
22
+ placed.set(sheet, list);
23
+ }
24
+ return list;
25
+ }
26
+ /**
27
+ * The table a cell sits in, if any.
28
+ *
29
+ * @param sheet - The sheet.
30
+ * @param row - The cell's row, 0-based.
31
+ * @param col - The cell's column, 0-based.
32
+ * @returns The table, or `undefined`.
33
+ */
34
+ export function tableAt(sheet, row, col) {
35
+ return placedOf(sheet).find(({ box }) => row >= box.top && row <= box.bottom && col >= box.left && col <= box.right)?.table;
36
+ }
37
+ /**
38
+ * A table by its name — the name formulas use — case-insensitive, and the sheet it sits on.
39
+ *
40
+ * @param book - The workbook.
41
+ * @param name - The table's name, e.g. `Units`.
42
+ * @returns The table and its sheet's name, or `undefined`.
43
+ */
44
+ export function findTable(book, name) {
45
+ const want = name.toLowerCase();
46
+ for (const s of book.sheets) {
47
+ const table = (s.tables ?? []).find((t) => t.name.toLowerCase() === want);
48
+ if (table)
49
+ return { sheet: s.name, table };
50
+ }
51
+ return undefined;
52
+ }
53
+ /**
54
+ * One cell's look inside a table: the header row bold (filled, for a Medium style), banded rows and columns
55
+ * filled, the first and last columns bold, the totals row bold under a double line, the style's lines. A
56
+ * style outside {@link TABLE_STYLES} draws a bold header row only; a table that names no style draws nothing,
57
+ * as Excel's *None*. A filled cell is given the theme's dark text colour, so it reads in a dark host too.
58
+ *
59
+ * @param table - The table.
60
+ * @param row - The cell's row, 0-based.
61
+ * @param col - The cell's column, 0-based.
62
+ * @param theme - The workbook's theme colours (`RRGGBB` by SpreadsheetML index); Office's when empty.
63
+ * @returns The CSS, or `undefined` when the cell is outside the table or nothing is drawn there.
64
+ */
65
+ export function tableCss(table, row, col, theme = []) {
66
+ const box = parseRange(table.ref);
67
+ if (!box || row < box.top || row > box.bottom || col < box.left || col > box.right)
68
+ return undefined;
69
+ const h = Math.max(0, table.headerRowCount), t = Math.max(0, table.totalsRowCount);
70
+ const header = row < box.top + h, totals = row > box.bottom - t;
71
+ const style = table.style;
72
+ if (!style.name)
73
+ return undefined;
74
+ const p = paletteOf(style.name, theme);
75
+ if (!p)
76
+ return header ? { 'font-weight': '700' } : undefined;
77
+ const css = {};
78
+ const bold = header || totals || (style.showFirstColumn && col === box.left) || (style.showLastColumn && col === box.right);
79
+ if (bold)
80
+ css['font-weight'] = '700';
81
+ draw(css, p, { header, totals, top: row === box.top, bottom: row === box.bottom });
82
+ if (!header && !totals) {
83
+ const r = row - box.top - h, c = col - box.left;
84
+ if ((style.showRowStripes && r % 2 === 0) || (style.showColumnStripes && c % 2 === 0))
85
+ css['background-color'] = p.stripe;
86
+ }
87
+ if (css['background-color'] && !css.color)
88
+ css.color = p.ink;
89
+ return Object.keys(css).length ? css : undefined;
90
+ }
91
+ /** The lines and the header fill: Light — a line over and under the table and under the header; Medium — the header filled, a line under every row. */
92
+ function draw(css, p, at) {
93
+ if (p.kind === 'light') {
94
+ if (at.top)
95
+ css['border-top'] = `1px solid ${p.accent}`;
96
+ if (at.bottom || at.header)
97
+ css['border-bottom'] = `1px solid ${p.accent}`;
98
+ }
99
+ else {
100
+ if (at.top)
101
+ css['border-top'] = `1px solid ${p.line}`;
102
+ css['border-bottom'] = `1px solid ${p.line}`;
103
+ if (at.header) {
104
+ css['background-color'] = p.accent;
105
+ css.color = p.onAccent;
106
+ }
107
+ }
108
+ if (at.totals)
109
+ css['border-top'] = `3px double ${p.accent}`;
110
+ }
111
+ /**
112
+ * The tables plugin: each Excel table in the workbook drawn as its style draws it — header row, banded rows
113
+ * and columns, first and last column, totals row — through the `decorate` hook. A cell's own format
114
+ * (`@sheetpane/styles`) and conditional formats (`@sheetpane/condfmt`) draw over it, as in Excel. Importing
115
+ * this module registers it as `tables`.
116
+ *
117
+ * @returns The plugin (`id: 'tables'`).
118
+ * @see https://github.com/arpitarya/sheetpane/blob/main/records/0122_TABLES.md
119
+ * @example
120
+ * ```ts
121
+ * import { createWorkbook } from '@sheetpane/grid';
122
+ * import { tables } from '@sheetpane/tables';
123
+ *
124
+ * excel.workbook = createWorkbook({ plugins: [tables()] });
125
+ * ```
126
+ * @example
127
+ * ```ts
128
+ * import '@sheetpane/tables'; // registers `tables`
129
+ * excel.setAttribute('plugins', 'tables styles');
130
+ * ```
131
+ */
132
+ export function tables() {
133
+ return {
134
+ id: PLUGIN_ID,
135
+ provides: ['decorate'],
136
+ decorate(cell) {
137
+ const table = tableAt(cell.sheet, cell.row, cell.col);
138
+ return table && tableCss(table, cell.row, cell.col, cell.book.themeColors);
139
+ },
140
+ };
141
+ }
142
+ registerPlugin(PLUGIN_ID, () => tables());
143
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,uGAAuG;AACvG,uG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IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YACtD,OAAO,KAAK,IAAI,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC7E,CAAC;KACF,CAAC;AACJ,CAAC;AAED,cAAc,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC"}
@@ -0,0 +1,37 @@
1
+ /** Office's default theme (lt1, dk1, lt2, dk2, accents 1–6), used when a workbook names none. */
2
+ export declare const DEFAULT_THEME: readonly string[];
3
+ /** Every style name this plugin draws in full; any other draws a bold header row only. */
4
+ export declare const TABLE_STYLES: readonly string[];
5
+ /** What one table style paints: `#RRGGBB` colours, or `undefined` for a style outside the subset. */
6
+ export interface TablePalette {
7
+ kind: 'light' | 'medium';
8
+ /** The style's colour: the header fill (Medium), the outer and header lines (Light), the totals row's double line. */
9
+ accent: string;
10
+ /** The line between rows (Medium). */
11
+ line: string;
12
+ /** The banded rows' and columns' fill. */
13
+ stripe: string;
14
+ /** Text on a filled cell: the theme's dark text colour (a filled cell never takes the host's ink). */
15
+ ink: string;
16
+ /** Text on the header fill (Medium): the theme's light colour. */
17
+ onAccent: string;
18
+ }
19
+ /**
20
+ * Excel's tint (ECMA-376 Part 1, §18.8.19): in HSL, a negative tint darkens (`L·(1+tint)`), a positive one
21
+ * lightens (`L·(1−tint) + tint`). The same tint as `@sheetpane/styles`' `applyTint`, kept here so this plugin
22
+ * needs no peer.
23
+ *
24
+ * @param rgb - The colour, `RRGGBB` (no `#`).
25
+ * @param tint - The tint, -1 to 1.
26
+ * @returns The tinted colour, `RRGGBB` upper case.
27
+ */
28
+ export declare function tint(rgb: string, tint: number): string;
29
+ /**
30
+ * The colours a built-in table style paints with, from the workbook's theme.
31
+ *
32
+ * @param name - The style's name, e.g. `TableStyleMedium2`.
33
+ * @param theme - The workbook's theme colours by SpreadsheetML index (`RRGGBB`); Office's when empty.
34
+ * @returns The palette, or `undefined` when the style is outside the subset ({@link TABLE_STYLES}).
35
+ */
36
+ export declare function paletteOf(name: string | undefined, theme?: readonly string[]): TablePalette | undefined;
37
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAIA,iGAAiG;AACjG,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAAyG,CAAC;AAErJ,0FAA0F;AAC1F,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAA0F,CAAC;AAErI,qGAAqG;AACrG,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IACzB,sHAAsH;IACtH,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,sGAAsG;IACtG,GAAG,EAAE,MAAM,CAAC;IACZ,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAUtD;AAID;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,YAAY,GAAG,SAAS,CAe3G"}
package/dist/styles.js ADDED
@@ -0,0 +1,53 @@
1
+ // The table styles this plugin draws (W-61; SR-TABLES decision 3): Excel's built-in Light 1–7 and
2
+ // Medium 1–7, approximated from the workbook's theme — style 1 is in the theme's dark text colour,
3
+ // styles 2–7 in accents 1–6. Any other style name draws a bold header row only.
4
+ /** Office's default theme (lt1, dk1, lt2, dk2, accents 1–6), used when a workbook names none. */
5
+ export const DEFAULT_THEME = ['FFFFFF', '000000', 'E7E6E6', '44546A', '4472C4', 'ED7D31', 'A5A5A5', 'FFC000', '5B9BD5', '70AD47'];
6
+ /** Every style name this plugin draws in full; any other draws a bold header row only. */
7
+ export const TABLE_STYLES = [1, 2, 3, 4, 5, 6, 7].flatMap((n) => [`TableStyleLight${n}`, `TableStyleMedium${n}`]);
8
+ /**
9
+ * Excel's tint (ECMA-376 Part 1, §18.8.19): in HSL, a negative tint darkens (`L·(1+tint)`), a positive one
10
+ * lightens (`L·(1−tint) + tint`). The same tint as `@sheetpane/styles`' `applyTint`, kept here so this plugin
11
+ * needs no peer.
12
+ *
13
+ * @param rgb - The colour, `RRGGBB` (no `#`).
14
+ * @param tint - The tint, -1 to 1.
15
+ * @returns The tinted colour, `RRGGBB` upper case.
16
+ */
17
+ export function tint(rgb, tint) {
18
+ const [r, g, b] = [0, 2, 4].map((i) => parseInt(rgb.slice(i, i + 2), 16) / 255);
19
+ const mx = Math.max(r, g, b), mn = Math.min(r, g, b), l0 = (mx + mn) / 2, d = mx - mn;
20
+ const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l0 - 1));
21
+ const h = d === 0 ? 0 : mx === r ? ((g - b) / d + 6) % 6 : mx === g ? (b - r) / d + 2 : (r - g) / d + 4;
22
+ const t = Math.max(-1, Math.min(1, tint));
23
+ const l = t < 0 ? l0 * (1 + t) : l0 * (1 - t) + t;
24
+ const c = (1 - Math.abs(2 * l - 1)) * s, x = c * (1 - Math.abs((h % 2) - 1)), m = l - c / 2;
25
+ const [p, q, w] = h < 1 ? [c, x, 0] : h < 2 ? [x, c, 0] : h < 3 ? [0, c, x] : h < 4 ? [0, x, c] : h < 5 ? [x, 0, c] : [c, 0, x];
26
+ return [p, q, w].map((v) => Math.round(Math.max(0, Math.min(1, v + m)) * 255).toString(16).padStart(2, '0')).join('').toUpperCase();
27
+ }
28
+ const STYLE = /^TableStyle(Light|Medium)([1-7])$/;
29
+ /**
30
+ * The colours a built-in table style paints with, from the workbook's theme.
31
+ *
32
+ * @param name - The style's name, e.g. `TableStyleMedium2`.
33
+ * @param theme - The workbook's theme colours by SpreadsheetML index (`RRGGBB`); Office's when empty.
34
+ * @returns The palette, or `undefined` when the style is outside the subset ({@link TABLE_STYLES}).
35
+ */
36
+ export function paletteOf(name, theme = []) {
37
+ const m = name ? STYLE.exec(name) : null;
38
+ if (!m)
39
+ return undefined;
40
+ const th = (i) => (theme[i] ?? DEFAULT_THEME[i]).toUpperCase();
41
+ const n = Number(m[2]);
42
+ const base = n === 1 ? th(1) : th(n + 2); // style 1: the dark text colour; 2–7: accents 1–6
43
+ const dark = n === 1; // a black or grey base takes lighter tints to read as grey
44
+ return {
45
+ kind: m[1] === 'Light' ? 'light' : 'medium',
46
+ accent: `#${base}`,
47
+ line: `#${tint(base, dark ? 0.5 : 0.4)}`,
48
+ stripe: `#${tint(base, dark ? 0.85 : 0.8)}`,
49
+ ink: `#${th(1)}`,
50
+ onAccent: `#${th(0)}`,
51
+ };
52
+ }
53
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,mGAAmG;AACnG,gFAAgF;AAEhF,iGAAiG;AACjG,MAAM,CAAC,MAAM,aAAa,GAAsB,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAErJ,0FAA0F;AAC1F,MAAM,CAAC,MAAM,YAAY,GAAsB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,EAAE,EAAE,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC;AAiBrI;;;;;;;;G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AG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;QACxC,MAAM,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;QAC3C,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;QAChB,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;KACtB,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@sheetpane/tables",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.4.1",
4
+ "description": "Excel tables for sheetpane — each table's header row, banded rows and columns and totals row drawn from its built-in table style, as a plugin on the `decorate` hook. The tables themselves are read by @sheetpane/import.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/arpitarya/sheetpane.git",
9
+ "directory": "packages/tables"
10
+ },
11
+ "type": "module",
12
+ "sideEffects": [
13
+ "./dist/index.js",
14
+ "./src/index.ts"
15
+ ],
16
+ "engines": {
17
+ "node": ">=22"
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "peerDependencies": {
29
+ "@sheetpane/grid": "0.4.1"
30
+ },
31
+ "dependencies": {
32
+ "@sheetpane/export": "0.4.1",
33
+ "@sheetpane/skills": "0.4.1"
34
+ },
35
+ "devDependencies": {
36
+ "@sheetpane/grid": "0.4.1",
37
+ "@sheetpane/styles": "0.4.1"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.build.json",
44
+ "typecheck": "tsc -p tsconfig.json --noEmit"
45
+ }
6
46
  }