werkmap 0.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,216 @@
1
+ # werkmap
2
+
3
+ A tiny spreadsheet writer for JavaScript. It writes an `.xlsx` file — rows, typed cells, styles, merged ranges, a frozen header, floating images — and nothing else. It does not read one. _Werkmap_ is Dutch for a workbook, which is the one thing this package makes.
4
+
5
+ Writing is the whole surface, so the package stays small enough to audit. The container is written against the ZIP specification over `CompressionStream`, every part is a string, and no value ever turns into code — so it runs unchanged under a Content Security Policy with no `unsafe-*` of any kind, which is what a spreadsheet export in the browser usually cannot do.
6
+
7
+ - **Byte-identical output.** Nothing consults a clock, a locale or a random source, and the ZIP epoch is pinned, so two renders of the same report are the same bytes and a build that caches by content hash keeps working.
8
+ - **Foreign readers accept it.** The suite loads every workbook it writes back through ExcelJS, an independent implementation — so the tests prove a real reader opens the file, not just that the bytes look plausible.
9
+ - **Zero dependencies.** 5.7 kB minified and brotlied, for the whole writer.
10
+ - **Strict CSP, including in the browser.** No `unsafe-eval` and no `unsafe-inline`. A Chromium page under `default-src 'none'; script-src 'self'` writes a workbook and reports any violation back, and the Node suite runs on `--disallow-code-generation-from-strings`.
11
+ - **Write-only, deliberately.** No reader, no formula engine, no chart support — see [Is werkmap the right tool?](#is-werkmap-the-right-tool) before you install it.
12
+ - **Hardened.** 53 tests at 100% branch coverage.
13
+
14
+ ```js
15
+ import { workbook } from "werkmap";
16
+
17
+ const wb = workbook({ title: "Sales" });
18
+ const sheet = wb.sheet("Report");
19
+
20
+ sheet.row([{ value: "Product" }, { value: "Amount" }]);
21
+ sheet.row([{ value: "Laptop" }, { value: 1000, style: { numberFormat: "#,##0.00" } }]);
22
+
23
+ const bytes = await wb.bytes();
24
+ //=> Uint8Array — and running this again produces byte-identical output
25
+ ```
26
+
27
+ <img src="https://getquario.com/favicon.svg" alt="Quario logo" width="16" height="16" /> <b>werkmap</b> is built by the team behind <b><a href="https://getquario.com?utm_source=github&utm_medium=readme&utm_campaign=werkmap">Quario</a></b>, a declarative reporting engine for JavaScript that renders JSON report definitions to <b>HTML, PDF, workbooks, and Word</b> — without <code>eval</code>.
28
+
29
+ ## Contents
30
+
31
+ - [Install](#install)
32
+ - [Usage](#usage)
33
+ - [Is werkmap the right tool?](#is-werkmap-the-right-tool)
34
+ - [API](#api)
35
+ - [Styles](#styles)
36
+ - [Guarantees, not options](#guarantees-not-options)
37
+ - [Determinism](#determinism)
38
+ - [Errors](#errors)
39
+ - [Content Security Policy](#content-security-policy)
40
+ - [Environments](#environments)
41
+ - [Contributing](#contributing)
42
+ - [License](#license)
43
+
44
+ ## Install
45
+
46
+ ```bash
47
+ npm install werkmap
48
+ ```
49
+
50
+ Node.js 22 or newer, ESM only. TypeScript declarations ship with the package; nothing extra to install.
51
+
52
+ ## Usage
53
+
54
+ ```js
55
+ import { workbook } from "werkmap";
56
+
57
+ const wb = workbook({ title: "Sales", creator: "Acme BV" });
58
+ const logo = wb.image(png, "png");
59
+ const sheet = wb.sheet("Report");
60
+
61
+ const head = sheet.row([
62
+ { value: "Sales", style: { font: { bold: true, size: 16 } } },
63
+ { value: null },
64
+ ]);
65
+ sheet.merge(head, 1, 2);
66
+
67
+ sheet.row([{ value: "Product" }, { value: "Amount" }]);
68
+ sheet.row([{ value: "Laptop" }, { value: 1000, style: { numberFormat: "#,##0.00" } }]);
69
+ sheet.freeze(head);
70
+ sheet.place(logo, { row: 1, width: 120, height: 40 });
71
+
72
+ const bytes = await wb.bytes(); // Uint8Array
73
+ ```
74
+
75
+ Writing the file belongs to you: `bytes()` hands back a `Uint8Array`, which Node writes with `fs` and a browser hands to a download.
76
+
77
+ ## Is werkmap the right tool?
78
+
79
+ werkmap writes the slice of the format a report needs, and refuses the rest.
80
+
81
+ **It fits when:**
82
+
83
+ - You produce spreadsheets and never consume them.
84
+ - The output must be reproducible — a content hash, a golden test, a cache key.
85
+ - The code runs under a strict Content Security Policy, in a browser or a worker.
86
+ - You care what the dependency costs: there are none, and the whole writer is one readable file.
87
+
88
+ **It does not fit when:**
89
+
90
+ - You need to read, edit or convert an existing workbook.
91
+ - You need formulas, charts, pivot tables, conditional formatting, data validation, hyperlinks, comments or sheet protection.
92
+ - You need column widths or row heights. A reader sizes columns from its own defaults.
93
+ - You have more rows than fit in memory. There is no streaming, row-at-a-time output.
94
+
95
+ ## API
96
+
97
+ ### `workbook(meta?) -> Workbook`
98
+
99
+ `meta` is one optional bag of optional strings: `{ title, creator, subject, description }`.
100
+
101
+ Members: `image`, `sheet`, `bytes`.
102
+
103
+ ### `workbook.image(bytes, format) -> number`
104
+
105
+ `bytes` is a `Uint8Array` and `format` is `"png"` or `"jpeg"`. Returns an id for `sheet.place`.
106
+
107
+ Identical bytes deduplicate and return the id already issued, so the same logo on twelve sheets is stored once.
108
+
109
+ ### `workbook.sheet(name) -> Sheet`
110
+
111
+ Any number of sheets, in call order. Throws on a name a reader refuses: empty, over 31 characters, containing `: \ / ? * [ ]`, or a duplicate.
112
+
113
+ ### `workbook.bytes() -> Promise<Uint8Array>`
114
+
115
+ The finished package. This does not seal the document: call it as often as you like, and the same call sequence yields the same bytes.
116
+
117
+ ### `sheet.row(cells) -> number`
118
+
119
+ `cells` is an array; the returned number is the row's 1-based position, which `merge`, `freeze` and `place` take.
120
+
121
+ Each element is `{ value, style }`, or `null` for an empty unstyled cell. `{ value: null, style }` is an empty **styled** cell, which is what a merged span's remaining columns need.
122
+
123
+ `value` is one of:
124
+
125
+ | Kind | Shape | Written as |
126
+ | --------- | --------------------- | --------------------------------------- |
127
+ | text | a `string` | interned into the shared string table |
128
+ | number | a finite `number` | a numeric cell |
129
+ | boolean | `true` / `false` | a boolean cell |
130
+ | date | a `Date` | a 1900-system serial, converted in UTC |
131
+ | rich text | `[{ text, font }, …]` | one formatted run per entry |
132
+ | empty | `null` | an empty cell, written only when styled |
133
+
134
+ Rich text is a **bare array** — there is no wrapper object, because nothing else in the value domain is an array. Each run carries its font in full, since a run inherits nothing from the cell font.
135
+
136
+ ### `sheet.merge(row, at, width)`
137
+
138
+ One merged range across `width` columns of `row`, starting at the 1-based column `at`.
139
+
140
+ ### `sheet.freeze(rows)`
141
+
142
+ Freeze the top `rows` rows. `0` clears.
143
+
144
+ ### `sheet.place(id, { row, col, width, height })`
145
+
146
+ One floating picture anchored to the top-left of a 1-based cell, drawn at `width` × `height` CSS pixels at 96 dpi.
147
+
148
+ All indexing is **1-based**, uniformly — rows, columns and image anchors. The XML counts from zero and this package subtracts internally; that off-by-one is its business and appears nowhere in the API.
149
+
150
+ ## Styles
151
+
152
+ A style is one object, and every part of it is optional:
153
+
154
+ ```js
155
+ {
156
+ font: { name, size, bold, italic, underline, strikethrough, color },
157
+ fill: "#eeeeee",
158
+ border: { top, right, bottom, left }, // each { style, color }, or absent
159
+ alignment: { horizontal, vertical, wrapText },
160
+ numberFormat: "#,##0.00",
161
+ }
162
+ ```
163
+
164
+ Colours are `#rrggbb`, with the `#rgb` shorthand accepted. There is no alpha channel: a colour either paints or is absent.
165
+
166
+ A **fill is a colour**, not a pattern object — solid is the only pattern here, so there is nothing for a wrapper to distinguish. A border side's `style` is `"thin"`, `"dashed"` or `"dotted"`.
167
+
168
+ Identical fonts, fills, borders and formats collapse to one entry each, so a style repeated down a thousand rows costs one record.
169
+
170
+ ## Guarantees, not options
171
+
172
+ There is nothing to configure. Each of these is a property of the writer rather than a parameter, because an option is a rule every caller has to hold in their head, and none of these is a choice a caller can make better:
173
+
174
+ - **Text is always interned** into the shared string table.
175
+ - **Style tables are always interned.**
176
+ - **Dates are the 1900 system**, converted in UTC. A reader's timezone is never consulted, and the phantom 1900-02-29 is accounted for, so a date before March 1900 lands on the day it names.
177
+ - **A date with no format of its own** gets the short-date built-in, so it reads back as a day rather than as the number underneath it.
178
+ - **Media deduplicates by bytes.**
179
+ - **Every element is written in the Open XML SDK's child order.**
180
+ - **Created and modified are always `1970-01-01T00:00:00Z`** and cannot be overridden. Byte-identity is the headline promise, and an overridable clock would quietly redefine "the same input" as "the same input at the same wall time". Put a real timestamp in `description`.
181
+
182
+ ## Determinism
183
+
184
+ The same calls produce byte-identical output **on the same runtime**, where a runtime means the engine and the zlib build inside it.
185
+
186
+ That qualifier is real rather than defensive. Deflate is not a single defined output: a conforming compressor may emit any valid stream, and engines differ. Chromium and Node happen to agree; Firefox and WebKit do not, and a Node patch release can carry a new zlib revision. So a digest of the finished archive pins a runtime as much as it pins a document.
187
+
188
+ If you want a fingerprint that survives all of that, hash the **parts** rather than the archive: unzip, then digest each part's bytes. Those are strings this package assembles, with no compressor anywhere in them.
189
+
190
+ ## Errors
191
+
192
+ The writer throws native `TypeError` and `RangeError` at the boundary, with a message naming the offending argument. There is no custom error class and no error codes: any one of these is a mistake in the calling code rather than a condition to branch on, and zero dependencies means nothing to import in order to write a `catch`.
193
+
194
+ Leniency belongs where a document is authored. Strictness belongs here, because the job is never to emit a file a reader offers to repair.
195
+
196
+ One deliberate exception is silent rather than thrown: **text the format cannot carry**. Control characters other than tab, newline and carriage return are stripped, as are unpaired surrogates, and a literal `_xHHHH_` in your text is escaped so a reader does not decode it. Failing a whole document over one stray byte in a customer's name is the wrong trade.
197
+
198
+ ## Content Security Policy
199
+
200
+ werkmap never turns a string into code. It runs under a policy with no `unsafe-eval` and no `unsafe-inline`, and its own suite proves it twice: the Node tests run with `--disallow-code-generation-from-strings`, and a Chromium page under `default-src 'none'; script-src 'self'` writes a workbook and reports any violation back.
201
+
202
+ The source is scanned for the two constructs on every run, so a regression fails the build rather than a deployment.
203
+
204
+ ## Environments
205
+
206
+ Node.js 22 or newer, and browsers with `CompressionStream` — Chromium 103, Firefox 113, Safari 16.4. Workers included; there is no DOM access anywhere.
207
+
208
+ The package is plain JavaScript with JSDoc types. There is no build step: what npm installs is what runs.
209
+
210
+ ## Contributing
211
+
212
+ Run the whole gate with `npm run check`. It formats, lints, checks for dead code and duplication, measures the bundle, runs the suite at 100% coverage, and drives the browser page.
213
+
214
+ ## License
215
+
216
+ Apache-2.0
package/lib/index.d.ts ADDED
@@ -0,0 +1,131 @@
1
+ /** A colour as `#rrggbb`, or the `#rgb` shorthand. There is no alpha channel. */
2
+ export type Colour = string;
3
+
4
+ /** A font, written in full wherever it appears: an OOXML run inherits nothing. */
5
+ export interface Font {
6
+ /** Defaults to `Calibri`. */
7
+ name?: string;
8
+ /** In points. Defaults to 11. */
9
+ size?: number;
10
+ bold?: boolean;
11
+ italic?: boolean;
12
+ underline?: boolean;
13
+ strikethrough?: boolean;
14
+ color?: Colour;
15
+ }
16
+
17
+ /** One side of a cell border. */
18
+ export interface Edge {
19
+ style: "thin" | "dashed" | "dotted";
20
+ color?: Colour;
21
+ }
22
+
23
+ export interface Border {
24
+ left?: Edge | null;
25
+ right?: Edge | null;
26
+ top?: Edge | null;
27
+ bottom?: Edge | null;
28
+ }
29
+
30
+ export interface Alignment {
31
+ horizontal?: "left" | "center" | "right" | "justify" | "fill";
32
+ vertical?: "top" | "center" | "bottom" | "justify";
33
+ wrapText?: boolean;
34
+ }
35
+
36
+ export interface Style {
37
+ font?: Font | null;
38
+ /** A fill *is* a colour: solid is the only pattern this writer emits. */
39
+ fill?: Colour | null;
40
+ border?: Border | null;
41
+ alignment?: Alignment | null;
42
+ /**
43
+ * A number format code, spelled out. A code matching a built-in is written
44
+ * as that built-in's id; anything else is interned.
45
+ */
46
+ numberFormat?: string | null;
47
+ }
48
+
49
+ /** One stretch of text inside a rich-text cell. */
50
+ export interface Run {
51
+ text: string;
52
+ font?: Font | null;
53
+ }
54
+
55
+ /**
56
+ * A cell value. `null` is an empty cell, which is still written when the cell
57
+ * carries a style. Rich text is a bare array of runs.
58
+ */
59
+ export type Value = string | number | boolean | Date | readonly Run[] | null;
60
+
61
+ export interface Cell {
62
+ value?: Value;
63
+ style?: Style | null;
64
+ }
65
+
66
+ /** Where a picture sits, and how large it is drawn. */
67
+ export interface Placement {
68
+ /** 1-based row of the cell the picture anchors to. */
69
+ row: number;
70
+ /** 1-based column of that cell. Defaults to 1. */
71
+ col?: number;
72
+ /** CSS pixels at 96 dpi. */
73
+ width: number;
74
+ /** CSS pixels at 96 dpi. */
75
+ height: number;
76
+ }
77
+
78
+ export interface Sheet {
79
+ /** This sheet's name. */
80
+ readonly name: string;
81
+ /**
82
+ * Append a row. `null` is an empty unstyled cell. Returns the row's 1-based
83
+ * position, which `merge` and `place` take.
84
+ */
85
+ row(cells: readonly (Cell | null)[]): number;
86
+ /**
87
+ * Merge `width` columns of `row`, starting at the 1-based column `at`.
88
+ * Throws on a width below 2, an overlap, or a row that does not exist yet.
89
+ */
90
+ merge(row: number, at: number, width: number): void;
91
+ /** Freeze the top `count` rows. `0` clears. */
92
+ freeze(count: number): void;
93
+ /** Float a picture over the sheet, anchored to one cell. */
94
+ place(id: number, at: Placement): void;
95
+ }
96
+
97
+ export interface Metadata {
98
+ title?: string;
99
+ creator?: string;
100
+ subject?: string;
101
+ description?: string;
102
+ }
103
+
104
+ export interface Workbook {
105
+ /**
106
+ * Embed an image. Identical bytes deduplicate and return the id already
107
+ * issued. The id is what `Sheet.place` takes.
108
+ */
109
+ image(bytes: Uint8Array, format: "png" | "jpeg"): number;
110
+ /**
111
+ * Add a worksheet. Throws on a name Excel refuses: empty, over 31
112
+ * characters, containing `: \ / ? * [ ]`, or a duplicate.
113
+ */
114
+ sheet(name: string): Sheet;
115
+ /**
116
+ * The finished package. Not terminal in the sense of sealing the document:
117
+ * call it as often as you like, and the same call sequence yields the same
118
+ * bytes.
119
+ */
120
+ bytes(): Promise<Uint8Array>;
121
+ }
122
+
123
+ /**
124
+ * Open a workbook.
125
+ *
126
+ * The document's created and modified dates are always `1970-01-01T00:00:00Z`
127
+ * and cannot be overridden: byte-identity for the same input is this writer's
128
+ * headline promise, and an overridable clock would redefine "the same input"
129
+ * as "the same input at the same wall time".
130
+ */
131
+ export declare const workbook: (meta?: Metadata) => Workbook;