@office-kit/xlsx 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +319 -0
  3. package/THIRD_PARTY_NOTICES.md +56 -0
  4. package/dist/cell/cell.d.ts +234 -0
  5. package/dist/cell/index.d.ts +4 -0
  6. package/dist/cell/rich-text.d.ts +37 -0
  7. package/dist/cell-D9CaNKnU.mjs +320 -0
  8. package/dist/cell-D9CaNKnU.mjs.map +1 -0
  9. package/dist/cell-style-BEDjMX1y.mjs +1579 -0
  10. package/dist/cell-style-BEDjMX1y.mjs.map +1 -0
  11. package/dist/cell.mjs +2 -0
  12. package/dist/chart/chart-xml.d.ts +16 -0
  13. package/dist/chart/chart.d.ts +735 -0
  14. package/dist/chart/cx/chartex-xml.d.ts +6 -0
  15. package/dist/chart/cx/chartex.d.ts +279 -0
  16. package/dist/chart/index.d.ts +6 -0
  17. package/dist/chart/user-shapes-xml.d.ts +4 -0
  18. package/dist/chart/user-shapes.d.ts +61 -0
  19. package/dist/chart.mjs +232 -0
  20. package/dist/chart.mjs.map +1 -0
  21. package/dist/chartsheet/chartsheet-xml.d.ts +17 -0
  22. package/dist/chartsheet/chartsheet.d.ts +121 -0
  23. package/dist/chartsheet/index.d.ts +2 -0
  24. package/dist/chartsheet-C3-tqkPy.mjs +23 -0
  25. package/dist/chartsheet-C3-tqkPy.mjs.map +1 -0
  26. package/dist/chartsheet.mjs +2 -0
  27. package/dist/colors-ovWAwnZI.mjs +67 -0
  28. package/dist/colors-ovWAwnZI.mjs.map +1 -0
  29. package/dist/compat/numbers.d.ts +14 -0
  30. package/dist/coordinate-96Ecci4d.mjs +276 -0
  31. package/dist/coordinate-96Ecci4d.mjs.map +1 -0
  32. package/dist/datetime-B2ySVlXt.mjs +71 -0
  33. package/dist/datetime-B2ySVlXt.mjs.map +1 -0
  34. package/dist/defined-names-CviWmtQg.mjs +89 -0
  35. package/dist/defined-names-CviWmtQg.mjs.map +1 -0
  36. package/dist/differential-D4dg-qtZ.mjs +37 -0
  37. package/dist/differential-D4dg-qtZ.mjs.map +1 -0
  38. package/dist/drawing/anchor.d.ts +63 -0
  39. package/dist/drawing/dml/colors.d.ts +109 -0
  40. package/dist/drawing/dml/dml-xml.d.ts +35 -0
  41. package/dist/drawing/dml/effect.d.ts +92 -0
  42. package/dist/drawing/dml/fill.d.ts +115 -0
  43. package/dist/drawing/dml/geometry.d.ts +113 -0
  44. package/dist/drawing/dml/line.d.ts +41 -0
  45. package/dist/drawing/dml/shape-properties.d.ts +33 -0
  46. package/dist/drawing/dml/text.d.ts +218 -0
  47. package/dist/drawing/drawing-xml.d.ts +5 -0
  48. package/dist/drawing/drawing.d.ts +117 -0
  49. package/dist/drawing/image.d.ts +40 -0
  50. package/dist/drawing/index.d.ts +14 -0
  51. package/dist/drawing-BxzLuryn.mjs +415 -0
  52. package/dist/drawing-BxzLuryn.mjs.map +1 -0
  53. package/dist/drawing.mjs +119 -0
  54. package/dist/drawing.mjs.map +1 -0
  55. package/dist/escape-DFTE7ZJc.mjs +51 -0
  56. package/dist/escape-DFTE7ZJc.mjs.map +1 -0
  57. package/dist/exceptions-D-CFwxgm.mjs +37 -0
  58. package/dist/exceptions-D-CFwxgm.mjs.map +1 -0
  59. package/dist/formula/tokenizer.d.ts +61 -0
  60. package/dist/formula/translate.d.ts +67 -0
  61. package/dist/inference-B3ES3KEJ.mjs +42 -0
  62. package/dist/inference-B3ES3KEJ.mjs.map +1 -0
  63. package/dist/io/browser.d.ts +41 -0
  64. package/dist/io/index.d.ts +7 -0
  65. package/dist/io/load.d.ts +46 -0
  66. package/dist/io/node-fs.d.ts +62 -0
  67. package/dist/io/node-save.d.ts +3 -0
  68. package/dist/io/node.d.ts +17 -0
  69. package/dist/io/save.d.ts +14 -0
  70. package/dist/io/sink.d.ts +54 -0
  71. package/dist/io/source.d.ts +14 -0
  72. package/dist/io.mjs +212 -0
  73. package/dist/io.mjs.map +1 -0
  74. package/dist/load-D5cbhoGx.mjs +1069 -0
  75. package/dist/load-D5cbhoGx.mjs.map +1 -0
  76. package/dist/manifest-Dps1-OpP.mjs +801 -0
  77. package/dist/manifest-Dps1-OpP.mjs.map +1 -0
  78. package/dist/node.d.ts +3 -0
  79. package/dist/node.mjs +308 -0
  80. package/dist/node.mjs.map +1 -0
  81. package/dist/packaging/core.d.ts +45 -0
  82. package/dist/packaging/custom.d.ts +62 -0
  83. package/dist/packaging/extended.d.ts +45 -0
  84. package/dist/packaging/index.d.ts +10 -0
  85. package/dist/packaging/manifest.d.ts +24 -0
  86. package/dist/packaging/relationships.d.ts +30 -0
  87. package/dist/packaging.mjs +2 -0
  88. package/dist/parser-DuLejQy1.mjs +156 -0
  89. package/dist/parser-DuLejQy1.mjs.map +1 -0
  90. package/dist/reader-D1fNW9k1.mjs +534 -0
  91. package/dist/reader-D1fNW9k1.mjs.map +1 -0
  92. package/dist/save-RohQtgEZ.mjs +745 -0
  93. package/dist/save-RohQtgEZ.mjs.map +1 -0
  94. package/dist/schema/core.d.ts +133 -0
  95. package/dist/schema/index.d.ts +3 -0
  96. package/dist/schema/serialize.d.ts +6 -0
  97. package/dist/schema.mjs +2 -0
  98. package/dist/serialize-55EnT30e.mjs +254 -0
  99. package/dist/serialize-55EnT30e.mjs.map +1 -0
  100. package/dist/serializer-BwbgHYJV.mjs +116 -0
  101. package/dist/serializer-BwbgHYJV.mjs.map +1 -0
  102. package/dist/streaming/index.d.ts +2 -0
  103. package/dist/streaming/read-only.d.ts +38 -0
  104. package/dist/streaming/write-only.d.ts +47 -0
  105. package/dist/streaming.mjs +612 -0
  106. package/dist/streaming.mjs.map +1 -0
  107. package/dist/styles/alignment.d.ts +33 -0
  108. package/dist/styles/alignment.schema.d.ts +3 -0
  109. package/dist/styles/borders.d.ts +40 -0
  110. package/dist/styles/borders.schema.d.ts +4 -0
  111. package/dist/styles/cell-style.d.ts +270 -0
  112. package/dist/styles/colors.d.ts +128 -0
  113. package/dist/styles/colors.schema.d.ts +3 -0
  114. package/dist/styles/differential.d.ts +41 -0
  115. package/dist/styles/fills.d.ts +54 -0
  116. package/dist/styles/fills.schema.d.ts +6 -0
  117. package/dist/styles/fonts.d.ts +44 -0
  118. package/dist/styles/fonts.schema.d.ts +3 -0
  119. package/dist/styles/index.d.ts +21 -0
  120. package/dist/styles/named-styles.d.ts +52 -0
  121. package/dist/styles/numbers.d.ts +39 -0
  122. package/dist/styles/numbers.schema.d.ts +3 -0
  123. package/dist/styles/protection.d.ts +9 -0
  124. package/dist/styles/protection.schema.d.ts +3 -0
  125. package/dist/styles/stylesheet-reader.d.ts +7 -0
  126. package/dist/styles/stylesheet-writer.d.ts +3 -0
  127. package/dist/styles/stylesheet.d.ts +95 -0
  128. package/dist/styles.mjs +4 -0
  129. package/dist/stylesheet-writer-C2eRmn22.mjs +8624 -0
  130. package/dist/stylesheet-writer-C2eRmn22.mjs.map +1 -0
  131. package/dist/table-DkX6UniA.mjs +113 -0
  132. package/dist/table-DkX6UniA.mjs.map +1 -0
  133. package/dist/tree-Bbs1C8Rc.mjs +192 -0
  134. package/dist/tree-Bbs1C8Rc.mjs.map +1 -0
  135. package/dist/units-rOMQqXh2.mjs +41 -0
  136. package/dist/units-rOMQqXh2.mjs.map +1 -0
  137. package/dist/user-shapes-DfmCGKB0.mjs +252 -0
  138. package/dist/user-shapes-DfmCGKB0.mjs.map +1 -0
  139. package/dist/utf8-D91g1XTG.mjs +143 -0
  140. package/dist/utf8-D91g1XTG.mjs.map +1 -0
  141. package/dist/utils/coordinate.d.ts +103 -0
  142. package/dist/utils/css.d.ts +18 -0
  143. package/dist/utils/datetime.d.ts +38 -0
  144. package/dist/utils/escape.d.ts +34 -0
  145. package/dist/utils/exceptions.d.ts +34 -0
  146. package/dist/utils/index.d.ts +11 -0
  147. package/dist/utils/inference.d.ts +24 -0
  148. package/dist/utils/stable-stringify.d.ts +7 -0
  149. package/dist/utils/units.d.ts +14 -0
  150. package/dist/utils/utf8.d.ts +1 -0
  151. package/dist/utils.mjs +39 -0
  152. package/dist/utils.mjs.map +1 -0
  153. package/dist/workbook/calc-properties.d.ts +47 -0
  154. package/dist/workbook/defined-names.d.ts +121 -0
  155. package/dist/workbook/file-recovery.d.ts +11 -0
  156. package/dist/workbook/file-sharing.d.ts +14 -0
  157. package/dist/workbook/file-version.d.ts +13 -0
  158. package/dist/workbook/function-groups.d.ts +10 -0
  159. package/dist/workbook/index.d.ts +24 -0
  160. package/dist/workbook/protection.d.ts +35 -0
  161. package/dist/workbook/shared-strings.d.ts +57 -0
  162. package/dist/workbook/smart-tags.d.ts +13 -0
  163. package/dist/workbook/views.d.ts +89 -0
  164. package/dist/workbook/workbook-properties.d.ts +57 -0
  165. package/dist/workbook/workbook.d.ts +643 -0
  166. package/dist/workbook-HGYNRBlV.mjs +636 -0
  167. package/dist/workbook-HGYNRBlV.mjs.map +1 -0
  168. package/dist/workbook.mjs +58 -0
  169. package/dist/workbook.mjs.map +1 -0
  170. package/dist/worksheet/auto-filter.d.ts +34 -0
  171. package/dist/worksheet/cell-range.d.ts +121 -0
  172. package/dist/worksheet/comments-xml.d.ts +24 -0
  173. package/dist/worksheet/comments.d.ts +13 -0
  174. package/dist/worksheet/conditional-formatting.d.ts +150 -0
  175. package/dist/worksheet/custom-sheet-views.d.ts +43 -0
  176. package/dist/worksheet/data-consolidate.d.ts +29 -0
  177. package/dist/worksheet/data-validations.d.ts +72 -0
  178. package/dist/worksheet/dimensions.d.ts +40 -0
  179. package/dist/worksheet/errors.d.ts +40 -0
  180. package/dist/worksheet/hyperlinks.d.ts +42 -0
  181. package/dist/worksheet/index.d.ts +46 -0
  182. package/dist/worksheet/ole-objects.d.ts +37 -0
  183. package/dist/worksheet/page-setup.d.ts +173 -0
  184. package/dist/worksheet/phonetic.d.ts +11 -0
  185. package/dist/worksheet/properties.d.ts +34 -0
  186. package/dist/worksheet/protected-ranges.d.ts +19 -0
  187. package/dist/worksheet/protection.d.ts +44 -0
  188. package/dist/worksheet/reader.d.ts +38 -0
  189. package/dist/worksheet/scenarios.d.ts +36 -0
  190. package/dist/worksheet/smart-tags.d.ts +23 -0
  191. package/dist/worksheet/sort-state.d.ts +28 -0
  192. package/dist/worksheet/table-xml.d.ts +5 -0
  193. package/dist/worksheet/table.d.ts +80 -0
  194. package/dist/worksheet/views.d.ts +47 -0
  195. package/dist/worksheet/web-publish.d.ts +21 -0
  196. package/dist/worksheet/worksheet.d.ts +935 -0
  197. package/dist/worksheet/writer.d.ts +72 -0
  198. package/dist/worksheet-CmCNoIgD.mjs +1726 -0
  199. package/dist/worksheet-CmCNoIgD.mjs.map +1 -0
  200. package/dist/worksheet.mjs +247 -0
  201. package/dist/worksheet.mjs.map +1 -0
  202. package/dist/writer-DspzfkNA.mjs +221 -0
  203. package/dist/writer-DspzfkNA.mjs.map +1 -0
  204. package/dist/xml/index.d.ts +10 -0
  205. package/dist/xml/iterparse.d.ts +22 -0
  206. package/dist/xml/namespaces.d.ts +91 -0
  207. package/dist/xml/parser.d.ts +7 -0
  208. package/dist/xml/serializer.d.ts +14 -0
  209. package/dist/xml/stream-writer.d.ts +39 -0
  210. package/dist/xml/tree.d.ts +37 -0
  211. package/dist/xml.mjs +140 -0
  212. package/dist/xml.mjs.map +1 -0
  213. package/dist/zip/decompression-guard.d.ts +70 -0
  214. package/dist/zip/index.d.ts +6 -0
  215. package/dist/zip/random-access-reader.d.ts +16 -0
  216. package/dist/zip/reader.d.ts +45 -0
  217. package/dist/zip/writer.d.ts +65 -0
  218. package/dist/zip/zip64-patch.d.ts +12 -0
  219. package/dist/zip.mjs +3 -0
  220. package/package.json +147 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming.mjs","names":[],"sources":["../src/streaming/read-only.ts","../src/streaming/write-only.ts"],"sourcesContent":["// Streaming read-only workbook.\n//\n// `loadWorkbookStream` opens the zip + parses workbook.xml / sharedStrings.xml\n// / styles.xml metadata up front (small even on million-row archives), then\n// exposes a lazy `openWorksheet(name)` that SAX-iterates the sheet body via\n// `iterParse`. The iterator streams rows without materialising the full sheet\n// in memory.\n\nimport { type SharedStringsTable, parseSharedStringsXml } from '../workbook/shared-strings';\nimport { ARC_CONTENT_TYPES, ARC_ROOT_RELS, ARC_SHARED_STRINGS, ARC_STYLE, REL_NS, SHEET_MAIN_NS } from '../xml/namespaces';\nimport { findById, relsFromBytes } from '../packaging/relationships';\nimport { manifestFromBytes } from '../packaging/manifest';\nimport { OpenXmlSchemaError } from '../utils/exceptions';\nimport type { DecompressionLimits } from '../zip/decompression-guard';\nimport { type ZipArchive, openZip } from '../zip/reader';\nimport type { CellValue, ExcelErrorCode } from '../cell/cell';\nimport { ERROR_CODES } from '../utils/inference';\nimport { iterParse, type SaxEvent, type SaxInput } from '../xml/iterparse';\nimport { parseXml } from '../xml/parser';\nimport { findChild, findChildren } from '../xml/tree';\nimport type { XlsxSource } from '../io/source';\nimport { coordinateToTuple } from '../utils/coordinate';\nimport { type Stylesheet, makeStylesheet } from '../styles/stylesheet';\nimport { parseStylesheetXml } from '../styles/stylesheet-reader';\nimport { resolveRelTarget } from '../io/load';\n\nconst SHEET_TAG = `{${SHEET_MAIN_NS}}sheet`;\nconst SHEETS_TAG = `{${SHEET_MAIN_NS}}sheets`;\n\nexport interface IterRowsOptions {\n minRow?: number;\n maxRow?: number;\n minCol?: number;\n maxCol?: number;\n}\n\nexport interface ReadOnlyCell {\n readonly row: number;\n readonly col: number;\n readonly value: CellValue;\n readonly styleId: number;\n}\n\nexport interface ReadOnlyWorksheet {\n title: string;\n iterRows(opts?: IterRowsOptions): AsyncIterableIterator<ReadOnlyCell[]>;\n iterValues(opts?: IterRowsOptions): AsyncIterableIterator<CellValue[]>;\n}\n\nexport interface ReadOnlyWorkbook {\n sheetNames: string[];\n styles: Stylesheet;\n openWorksheet(name: string): ReadOnlyWorksheet;\n close(): Promise<void>;\n}\n\ninterface SheetEntry {\n name: string;\n rId: string;\n partPath: string;\n}\n\nconst parseSheetList = (workbookXml: Uint8Array, workbookPath: string, archive: ZipArchive): SheetEntry[] => {\n const root = parseXml(workbookXml);\n const sheetsEl = findChild(root, SHEETS_TAG);\n if (!sheetsEl) return [];\n const wbRelsPath = relsPathFor(workbookPath);\n const wbRels = archive.has(wbRelsPath) ? relsFromBytes(archive.read(wbRelsPath)) : { rels: [] };\n const out: SheetEntry[] = [];\n for (const sheet of findChildren(sheetsEl, SHEET_TAG)) {\n const name = sheet.attrs['name'];\n const rId = sheet.attrs[`{${REL_NS}}id`];\n if (!name || !rId) continue;\n const rel = findById(wbRels, rId);\n if (!rel) continue;\n const partPath = resolveRelTarget(workbookPath, rel.target);\n out.push({ name, rId, partPath });\n }\n return out;\n};\n\nconst relsPathFor = (partPath: string): string => {\n const i = partPath.lastIndexOf('/');\n if (i < 0) return `_rels/${partPath}.rels`;\n return `${partPath.slice(0, i)}/_rels/${partPath.slice(i + 1)}.rels`;\n};\n\nconst localName = (qname: string): string => {\n const i = qname.lastIndexOf('}');\n return i < 0 ? qname : qname.slice(i + 1);\n};\n\nconst decodeCellValue = (\n t: string,\n vText: string | undefined,\n inlineText: string | undefined,\n sst: ReadonlyArray<string>,\n): CellValue => {\n switch (t) {\n case 'n':\n return vText !== undefined && vText !== '' ? Number.parseFloat(vText) : null;\n case 's': {\n if (vText === undefined) return null;\n const idx = Number.parseInt(vText, 10);\n if (!Number.isInteger(idx) || idx < 0 || idx >= sst.length) return null;\n return sst[idx] ?? null;\n }\n case 'b':\n return vText === '1';\n case 'e': {\n if (!vText || !ERROR_CODES.has(vText)) return null;\n return { kind: 'error', code: vText as ExcelErrorCode };\n }\n case 'str':\n return vText ?? '';\n case 'inlineStr':\n return inlineText ?? '';\n default:\n return vText !== undefined && vText !== '' ? Number.parseFloat(vText) : null;\n }\n};\n\n/**\n * SAX-iterate `<sheetData>/<row>/<c>` events out of the worksheet bytes (or a\n * stream that yields them), yielding one `ReadOnlyCell[]` per row that matches\n * `opts`.\n */\nasync function* iterSheetRows(\n sheetInput: SaxInput,\n sst: ReadonlyArray<string>,\n opts: IterRowsOptions,\n): AsyncIterableIterator<ReadOnlyCell[]> {\n const minRow = opts.minRow ?? 1;\n const maxRow = opts.maxRow ?? Number.POSITIVE_INFINITY;\n const minCol = opts.minCol ?? 1;\n const maxCol = opts.maxCol ?? Number.POSITIVE_INFINITY;\n\n let inSheetData = false;\n let currentRow = -1;\n let currentRowAttrs: Record<string, string> | null = null;\n let currentCells: ReadOnlyCell[] = [];\n\n // Per-cell state. Reset when each <c> starts.\n let cellOpen = false;\n let cellRow = 0;\n let cellCol = 0;\n let cellType = 'n';\n let cellStyleId = 0;\n let inV = false;\n let vText = '';\n let inIs = false;\n let inIsT = false;\n let isText = '';\n\n for await (const ev of iterParse(sheetInput)) {\n const e = ev as SaxEvent;\n if (e.kind === 'start') {\n const local = localName(e.name);\n if (!inSheetData) {\n if (local === 'sheetData') inSheetData = true;\n continue;\n }\n switch (local) {\n case 'row': {\n currentRowAttrs = e.attrs;\n const rRaw = e.attrs['r'];\n currentRow = rRaw ? Number.parseInt(rRaw, 10) : currentRow + 1;\n currentCells = [];\n break;\n }\n case 'c': {\n if (currentRow < 0) break;\n // Skip cell-attr parsing entirely when the row is outside the\n // requested band — saves the parseInt + coordinateToTuple hit on\n // every cell of every excluded row.\n if (currentRow < minRow || currentRow > maxRow) break;\n cellOpen = true;\n cellType = e.attrs['t'] ?? 'n';\n const sRaw = e.attrs['s'];\n cellStyleId = sRaw ? Number.parseInt(sRaw, 10) || 0 : 0;\n const ref = e.attrs['r'];\n if (ref) {\n const tup = coordinateToTuple(ref);\n cellRow = tup.row;\n cellCol = tup.col;\n } else {\n cellRow = currentRow;\n cellCol = (currentCells[currentCells.length - 1]?.col ?? 0) + 1;\n }\n vText = '';\n isText = '';\n break;\n }\n case 'v':\n if (cellOpen) inV = true;\n break;\n case 'is':\n if (cellOpen) inIs = true;\n break;\n case 't':\n if (inIs) inIsT = true;\n break;\n default:\n break;\n }\n continue;\n }\n if (e.kind === 'text') {\n if (inV) vText += e.text;\n else if (inIsT) isText += e.text;\n continue;\n }\n // end\n const local = localName(e.name);\n if (!inSheetData) continue;\n switch (local) {\n case 'sheetData':\n inSheetData = false;\n return;\n case 'row': {\n if (currentRow >= minRow && currentRow <= maxRow && currentCells.length > 0) {\n yield currentCells;\n }\n // Once we've crossed maxRow there are no more rows to yield — every\n // subsequent <row> would just be parsed and dropped. Stop iterating\n // early. ECMA-376 emits rows in ascending order.\n if (currentRow > maxRow) {\n inSheetData = false;\n return;\n }\n currentRow = -1;\n currentRowAttrs = null;\n currentCells = [];\n break;\n }\n case 'c': {\n if (cellOpen && cellCol >= minCol && cellCol <= maxCol && cellRow >= minRow && cellRow <= maxRow) {\n const value = decodeCellValue(cellType, vText, isText, sst);\n currentCells.push({ row: cellRow, col: cellCol, value, styleId: cellStyleId });\n }\n cellOpen = false;\n break;\n }\n case 'v':\n inV = false;\n break;\n case 'is':\n inIs = false;\n break;\n case 't':\n if (inIs) inIsT = false;\n break;\n default:\n break;\n }\n }\n // Avoid unused-var lint when row attrs never touched.\n void currentRowAttrs;\n}\n\n/**\n * Build a sorted `[rowNum, byteOffset]` index for every `<row r=\"N\">`\n * occurrence in a worksheet's bytes. Pure byte-level scan (no SAX), cheap\n * relative to the per-cell SAX walk: ~50 ns per row on M-series Node 22.\n *\n * `sheetDataEnd` is the byte offset of `</sheetData>` so callers can clip the\n * slice that gets handed to saxes.\n */\nconst buildRowOffsetIndex = (\n bytes: Uint8Array,\n): { index: ReadonlyArray<{ row: number; offset: number }>; sheetDataEnd: number } => {\n const out: Array<{ row: number; offset: number }> = [];\n let sheetDataEnd = -1;\n let i = 0;\n while (i < bytes.length) {\n if (bytes[i] !== 0x3c /* '<' */) {\n i++;\n continue;\n }\n // Detect `</sheetData>` once — used to clip the slice fed to saxes.\n if (\n sheetDataEnd < 0 &&\n bytes[i + 1] === 0x2f /* '/' */ &&\n bytes[i + 2] === 0x73 /* 's' */ &&\n bytes[i + 3] === 0x68 /* 'h' */ &&\n bytes[i + 4] === 0x65 /* 'e' */ &&\n bytes[i + 5] === 0x65 /* 'e' */ &&\n bytes[i + 6] === 0x74 /* 't' */ &&\n bytes[i + 7] === 0x44 /* 'D' */ &&\n bytes[i + 8] === 0x61 /* 'a' */ &&\n bytes[i + 9] === 0x74 /* 't' */ &&\n bytes[i + 10] === 0x61 /* 'a' */ &&\n bytes[i + 11] === 0x3e /* '>' */\n ) {\n sheetDataEnd = i;\n break;\n }\n // Match `<row` followed by ASCII whitespace or '>'.\n if (\n bytes[i + 1] !== 0x72 /* 'r' */ ||\n bytes[i + 2] !== 0x6f /* 'o' */ ||\n bytes[i + 3] !== 0x77 /* 'w' */\n ) {\n i++;\n continue;\n }\n const next = bytes[i + 4];\n if (\n next !== 0x20 /* sp */ &&\n next !== 0x09 /* tab */ &&\n next !== 0x0a /* lf */ &&\n next !== 0x0d /* cr */ &&\n next !== 0x3e /* > */ &&\n next !== 0x2f /* / */\n ) {\n i++;\n continue;\n }\n // Walk to the closing '>'; the attrs region carries `r=\"N\"`.\n const start = i;\n let j = i + 4;\n while (j < bytes.length && bytes[j] !== 0x3e) j++;\n if (j >= bytes.length) break;\n const attrsBuf = bytes.subarray(start + 4, j);\n const attrs = new TextDecoder('ascii', { fatal: false }).decode(attrsBuf);\n const m = /\\sr=\"(\\d+)\"/.exec(attrs);\n if (m?.[1]) {\n const row = Number.parseInt(m[1], 10);\n if (Number.isInteger(row)) out.push({ row, offset: start });\n }\n i = j + 1;\n }\n if (sheetDataEnd < 0) sheetDataEnd = bytes.length;\n return { index: out, sheetDataEnd };\n};\n\n/**\n * Binary-search the row index for the first entry with `row >= target`. Returns\n * -1 when every recorded row is below the target.\n */\nconst firstRowAtOrAfter = (\n index: ReadonlyArray<{ row: number; offset: number }>,\n target: number,\n): number => {\n let lo = 0;\n let hi = index.length;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n const entry = index[mid];\n if (!entry || entry.row < target) lo = mid + 1;\n else hi = mid;\n }\n return lo < index.length ? lo : -1;\n};\n\n/**\n * Slice a worksheet's bytes to start at the row at index `idxPos` of the\n * row-offset index, wrapping the result with a synthetic `<sheetData>` envelope\n * so saxes parses it in the right namespace.\n */\nconst SHEET_DATA_OPEN = `<?xml version=\"1.0\" encoding=\"UTF-8\"?><sheetData xmlns=\"${SHEET_MAIN_NS}\">`;\nconst SHEET_DATA_CLOSE = `</sheetData>`;\nconst sliceFromRow = (\n bytes: Uint8Array,\n fromOffset: number,\n sheetDataEnd: number,\n): Uint8Array => {\n const prefix = new TextEncoder().encode(SHEET_DATA_OPEN);\n const suffix = new TextEncoder().encode(SHEET_DATA_CLOSE);\n const middle = bytes.subarray(fromOffset, sheetDataEnd);\n const out = new Uint8Array(prefix.length + middle.length + suffix.length);\n out.set(prefix, 0);\n out.set(middle, prefix.length);\n out.set(suffix, prefix.length + middle.length);\n return out;\n};\n\n/**\n * Factory: build a {@link ReadOnlyWorksheet} bound to a single worksheet part\n * inside an opened archive. SAX iteration runs lazily — `iterRows` re-reads the\n * part bytes each time so the caller can iterate the same sheet repeatedly\n * without keeping a buffered decoder around.\n *\n * For `iterRows({ minRow > 1 })`, a row-offset index is built lazily on first\n * use and cached; subsequent band queries jump straight to the byte offset of\n * the first matching row instead of SAX-walking the entire `<sheetData>`.\n */\nconst makeStreamingReadOnlyWorksheet = (\n title: string,\n archive: ZipArchive,\n partPath: string,\n sst: ReadonlyArray<string>,\n): ReadOnlyWorksheet => {\n // Lazy + cached. The index is small (~16 B per row); for 1M rows that's 16 MB\n // of working set, vs. the alternative of walking the sheet bytes through\n // saxes on every band query.\n let cached: ReturnType<typeof buildRowOffsetIndex> | undefined;\n const ensureIndex = (bytes: Uint8Array) => {\n if (!cached) cached = buildRowOffsetIndex(bytes);\n return cached;\n };\n\n const iterRows = (opts: IterRowsOptions = {}): AsyncIterableIterator<ReadOnlyCell[]> => {\n const minRow = opts.minRow ?? 1;\n if (minRow <= 1) {\n // Whole-sheet (or no-min) iter — feed the SAX parser directly off the\n // archive's streaming inflate path so the worksheet's inflated payload\n // is never fully resident. Peak memory for the walk drops to the\n // inflate window + SAX state instead of the entire `<sheetData>` body.\n return iterSheetRows(archive.readStream(partPath), sst, opts);\n }\n // Band query (minRow > 1): the row-offset index needs the full inflated\n // bytes so we can binary-search to the byte offset of the first matching\n // row. Materialise once and reuse via `ensureIndex`.\n const bytes = archive.read(partPath);\n const { index, sheetDataEnd } = ensureIndex(bytes);\n if (index.length === 0) return iterSheetRows(bytes, sst, opts);\n const pos = firstRowAtOrAfter(index, minRow);\n if (pos < 0) {\n // Every row is below minRow — nothing to yield.\n return (async function* () {})();\n }\n const target = index[pos];\n if (!target) return iterSheetRows(bytes, sst, opts);\n const sliced = sliceFromRow(bytes, target.offset, sheetDataEnd);\n return iterSheetRows(sliced, sst, opts);\n };\n const iterValues = async function* (opts: IterRowsOptions = {}): AsyncIterableIterator<CellValue[]> {\n for await (const row of iterRows(opts)) {\n yield row.map((c) => c.value);\n }\n };\n return { title, iterRows, iterValues };\n};\n\n/**\n * Factory: build a {@link ReadOnlyWorkbook} from an opened archive + pre-parsed\n * sheet list / styles / shared strings. Per the project-wide \"no classes\" rule\n * (CLAUDE.md), the workbook is a plain object closing over the archive handle.\n */\nconst makeStreamingReadOnlyWorkbook = (\n sheetNames: string[],\n styles: Stylesheet,\n archive: ZipArchive,\n entries: ReadonlyMap<string, SheetEntry>,\n sst: ReadonlyArray<string>,\n): ReadOnlyWorkbook => ({\n sheetNames,\n styles,\n openWorksheet(name) {\n const entry = entries.get(name);\n if (!entry) {\n throw new OpenXmlSchemaError(`loadWorkbookStream: no worksheet named \"${name}\"`);\n }\n return makeStreamingReadOnlyWorksheet(name, archive, entry.partPath, sst);\n },\n async close() {\n archive.close();\n },\n});\n\n/** Options for {@link loadWorkbookStream}. */\nexport interface LoadWorkbookStreamOptions {\n /**\n * Decompression-bomb safeguards applied while inflating zip entries.\n * Defaults to limits that fit any legitimate xlsx; pass `false` to disable\n * (only safe for fully trusted sources).\n */\n decompressionLimits?: DecompressionLimits | false;\n}\n\n/** Open an xlsx for read-only streaming access. */\nexport async function loadWorkbookStream(\n source: XlsxSource,\n opts: LoadWorkbookStreamOptions = {},\n): Promise<ReadOnlyWorkbook> {\n const archive = await openZip(\n source,\n opts.decompressionLimits === undefined ? {} : { decompressionLimits: opts.decompressionLimits },\n );\n if (!archive.has(ARC_CONTENT_TYPES)) {\n throw new OpenXmlSchemaError(`loadWorkbookStream: missing \"${ARC_CONTENT_TYPES}\"`);\n }\n // Manifest parse is intentionally cheap and discarded — we resolve sheets by\n // walking workbook.xml.rels directly.\n manifestFromBytes(archive.read(ARC_CONTENT_TYPES));\n\n if (!archive.has(ARC_ROOT_RELS)) {\n throw new OpenXmlSchemaError(`loadWorkbookStream: missing \"${ARC_ROOT_RELS}\"`);\n }\n const rootRels = relsFromBytes(archive.read(ARC_ROOT_RELS));\n const officeDocRel = rootRels.rels.find((r) => r.type === `${REL_NS}/officeDocument`);\n if (!officeDocRel) {\n throw new OpenXmlSchemaError(`loadWorkbookStream: no officeDocument relationship in root rels`);\n }\n const workbookPath = resolveRelTarget('', officeDocRel.target);\n if (!archive.has(workbookPath)) {\n throw new OpenXmlSchemaError(`loadWorkbookStream: workbook part \"${workbookPath}\" missing`);\n }\n const sheetEntries = parseSheetList(archive.read(workbookPath), workbookPath, archive);\n const entryMap = new Map<string, SheetEntry>();\n for (const e of sheetEntries) entryMap.set(e.name, e);\n\n let sst: SharedStringsTable = { entries: [], index: new Map() };\n if (archive.has(ARC_SHARED_STRINGS)) {\n sst = parseSharedStringsXml(archive.read(ARC_SHARED_STRINGS));\n }\n let styles: Stylesheet = makeStylesheet();\n if (archive.has(ARC_STYLE)) {\n styles = parseStylesheetXml(archive.read(ARC_STYLE));\n }\n\n return makeStreamingReadOnlyWorkbook(\n sheetEntries.map((e) => e.name),\n styles,\n archive,\n entryMap,\n sst.entries.map((e) => (typeof e === 'string' ? e : e.runs.map((r) => r.text).join(''))),\n );\n}\n","// Streaming write-only workbook.\n//\n// `createWriteOnlyWorkbook` lets callers append rows one at a time without\n// holding a full Workbook in memory. Each `appendRow` serialises the row\n// directly into a string buffer (no `Cell` objects, no Worksheet rows Map) —\n// when `close()` runs we glue the rows under a `<sheetData>` envelope and hand\n// the bytes to the streaming-deflate ZIP writer. The buffer keeps ~30 bytes per\n// cell of XML text instead of the ~200-byte V8 footprint a Cell + Map entry\n// costs, so the heap budget at 3M cells drops roughly an order of magnitude vs.\n// the previous setCell-based path.\n\nimport type { Cell, CellValue } from '../cell/cell';\nimport type { XlsxSink } from '../io/sink';\nimport { addDefault, addOverride, makeManifest, manifestToBytes } from '../packaging/manifest';\nimport { makeRelationships, relsToBytes } from '../packaging/relationships';\nimport {\n addBorder,\n addCellXf,\n addFill,\n addFont,\n addNumFmt,\n type CellXf,\n defaultCellXf,\n makeStylesheet,\n type Stylesheet,\n} from '../styles/stylesheet';\nimport { stylesheetToBytes } from '../styles/stylesheet-writer';\nimport type { Alignment } from '../styles/alignment';\nimport type { Border } from '../styles/borders';\nimport type { Fill } from '../styles/fills';\nimport type { Font } from '../styles/fonts';\nimport type { Protection } from '../styles/protection';\nimport { escapeXmlAttr } from '../utils/escape';\nimport { OpenXmlIoError } from '../utils/exceptions';\nimport { utf8ByteLength } from '../utils/utf8';\nimport { makeSharedStrings, sharedStringsToBytes } from '../workbook/shared-strings';\nimport { validateSheetTitle } from '../workbook/workbook';\nimport { serializeCell } from '../worksheet/writer';\nimport {\n ARC_CONTENT_TYPES,\n ARC_ROOT_RELS,\n ARC_SHARED_STRINGS,\n ARC_STYLE,\n ARC_WORKBOOK,\n ARC_WORKBOOK_RELS,\n PKG_REL_NS,\n REL_NS,\n SHARED_STRINGS_TYPE,\n SHEET_MAIN_NS,\n STYLES_TYPE,\n WORKSHEET_TYPE,\n XLSX_TYPE,\n} from '../xml/namespaces';\nimport { createZipWriter } from '../zip/writer';\n\nconst escapeAttr = escapeXmlAttr;\n\nexport interface WriteOnlyOptions {\n /** Reserved — currently ignored (the buffered backend doesn't honour it). */\n estimatedMaxRow?: number;\n}\n\nexport interface WriteOnlyStyle {\n font?: Font;\n fill?: Fill;\n border?: Border;\n alignment?: Alignment;\n numberFormat?: string;\n protection?: Protection;\n}\n\nexport type WriteOnlyRowItem = CellValue | { value: CellValue; style?: WriteOnlyStyle };\n\nexport interface WriteOnlyWorksheet {\n readonly title: string;\n appendRow(row: WriteOnlyRowItem[]): Promise<void>;\n setColumnWidth(col: number, width: number): void;\n close(): Promise<void>;\n}\n\nexport interface WriteOnlyWorkbook {\n /** Add a new worksheet. The previous worksheet must be `close()`d first. */\n addWorksheet(title: string): Promise<WriteOnlyWorksheet>;\n /** Finalise the archive: emits styles / sharedStrings / workbook / manifest / rels. */\n finalize(): Promise<void>;\n /**\n * Release the sink without finalising the archive. Call this from a\n * surrounding catch block when the producer pipeline throws before\n * `finalize()` — without it, streaming destinations (`toFile` /\n * `toWritable`) keep the file descriptor / Writable open and the partial\n * xlsx looks valid on disk.\n *\n * Idempotent. Subsequent `addWorksheet` / `finalize` calls throw.\n */\n abort(cause?: unknown): void;\n}\n\nconst validateTitle = (title: string, taken: Set<string>): void => {\n const reason = validateSheetTitle(title);\n if (reason) {\n throw new OpenXmlIoError(`Worksheet title \"${title}\": ${reason}`);\n }\n if (taken.has(title.toLowerCase())) {\n throw new OpenXmlIoError(`Worksheet title \"${title}\" is already in use`);\n }\n};\n\n/** Allocate a CellXf id for a style spec. Mirrors cell-style.ts but works directly on the pool. */\nconst allocateXfId = (ss: Stylesheet, style: WriteOnlyStyle): number => {\n // `xfId` is intentionally omitted: leaving it undefined skips the\n // cellStyleXfs bounds check and matches what Excel emits when there is no\n // parent style.\n let xf: CellXf = { fontId: 0, fillId: 0, borderId: 0, numFmtId: 0 };\n if (style.font !== undefined) {\n xf = { ...xf, fontId: addFont(ss, style.font), applyFont: true };\n }\n if (style.fill !== undefined) {\n xf = { ...xf, fillId: addFill(ss, style.fill), applyFill: true };\n }\n if (style.border !== undefined) {\n xf = { ...xf, borderId: addBorder(ss, style.border), applyBorder: true };\n }\n if (style.numberFormat !== undefined) {\n xf = { ...xf, numFmtId: addNumFmt(ss, style.numberFormat), applyNumberFormat: true };\n }\n if (style.alignment !== undefined) {\n xf = { ...xf, alignment: style.alignment, applyAlignment: true };\n }\n if (style.protection !== undefined) {\n xf = { ...xf, protection: style.protection, applyProtection: true };\n }\n return addCellXf(ss, xf);\n};\n\ninterface WorkbookState {\n styles: Stylesheet;\n sst: ReturnType<typeof makeSharedStrings>;\n /** Sheet emit metadata, in addWorksheet order. */\n sheets: Array<{\n title: string;\n sheetId: number;\n }>;\n /** True once finalize() has been called (further mutations throw). */\n finalised: boolean;\n /** True while a worksheet is open (the next addWorksheet must wait). */\n hasOpenWorksheet: boolean;\n /** ZIP writer the workbook + each open worksheet stream chunks through. */\n writer: import('../zip/writer').ZipWriter;\n}\n\n/**\n * Flush threshold for the worksheet's pending-row text buffer. Smaller values\n * minimise heap; larger values amortise the TextEncoder + push overhead. 64 KB\n * is a sweet spot — heap stays low and per-row JS work is dominated by the\n * actual XML construction, not flushing.\n */\nconst FLUSH_THRESHOLD_BYTES = 64 * 1024;\n\n/**\n * Factory: build a {@link WriteOnlyWorksheet} that closes over the shared\n * {@link WorkbookState}. Per the project-wide \"no classes\" rule (CLAUDE.md) the\n * worksheet is a plain object holding the row buffer + column-width map in\n * closure state.\n *\n * The worksheet streams its `<sheetData>` body chunk-by-chunk through the ZIP\n * writer's `addStreamingEntry` API, so the heap footprint stays at one ~64 KB\n * pending text buffer plus deflate scratch — no Cell objects, no all-rows\n * accumulation. The XML envelope (decl / worksheet open / cols / sheetData\n * open) flushes on the first `appendRow` (or `close()` if the sheet is empty);\n * column widths staged via `setColumnWidth` *must* land before the first row.\n */\nconst makeWriteOnlyWorksheet = (state: WorkbookState, title: string, sheetId: number): WriteOnlyWorksheet => {\n let nextRow = 1;\n let closed = false;\n let headerFlushed = false;\n const columnWidths = new Map<number, number>();\n const dummyCtx = { sharedStrings: state.sst, rels: makeRelationships() };\n const encoder = new TextEncoder();\n const stream = state.writer.addStreamingEntry(`xl/worksheets/sheet${sheetId}.xml`);\n let pendingText = '';\n let pendingBytes = 0;\n\n const writeText = (text: string): void => {\n pendingText += text;\n // UTF-8 byte length, computed without a full encode: scan once and add the\n // exact codepoint cost. `text.length` would undercount CJK by ~3× and let\n // the buffer balloon past FLUSH_THRESHOLD_BYTES on Japanese / Chinese\n // workloads.\n pendingBytes += utf8ByteLength(text);\n if (pendingBytes >= FLUSH_THRESHOLD_BYTES) {\n stream.write(encoder.encode(pendingText));\n pendingText = '';\n pendingBytes = 0;\n }\n };\n\n const flushHeader = (): void => {\n if (headerFlushed) return;\n headerFlushed = true;\n let header = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>';\n header += `<worksheet xmlns=\"${SHEET_MAIN_NS}\" xmlns:r=\"${REL_NS}\">`;\n if (columnWidths.size > 0) {\n header += '<cols>';\n const sorted = [...columnWidths.entries()].sort((a, b) => a[0] - b[0]);\n for (const [col, width] of sorted) {\n header += `<col min=\"${col}\" max=\"${col}\" width=\"${width}\" customWidth=\"1\"/>`;\n }\n header += '</cols>';\n }\n header += '<sheetData>';\n writeText(header);\n };\n\n const appendRow = async (row: WriteOnlyRowItem[]): Promise<void> => {\n if (closed) throw new OpenXmlIoError('appendRow: worksheet already closed');\n flushHeader();\n const r = nextRow++;\n let xml = `<row r=\"${r}\">`;\n for (let i = 0; i < row.length; i++) {\n const item = row[i];\n if (item === undefined || item === null) continue;\n const col = i + 1;\n let value: CellValue;\n let style: WriteOnlyStyle | undefined;\n if (item !== null && typeof item === 'object' && 'value' in (item as object)) {\n const wrapped = item as { value: CellValue; style?: WriteOnlyStyle };\n value = wrapped.value;\n style = wrapped.style;\n } else {\n value = item as CellValue;\n }\n const styleId = style ? allocateXfId(state.styles, style) : 0;\n // Ephemeral cell-shaped object — discarded as soon as serializeCell\n // returns its `<c .../>` string. Keeps the heap footprint at the size of\n // the pending text buffer instead of a full Worksheet model.\n const cell: Cell = { row: r, col, value, styleId };\n xml += serializeCell(cell, dummyCtx);\n }\n xml += '</row>';\n writeText(xml);\n };\n\n const setColumnWidth = (col: number, width: number): void => {\n if (closed) throw new OpenXmlIoError('setColumnWidth: worksheet already closed');\n if (headerFlushed) {\n throw new OpenXmlIoError(\n 'setColumnWidth: must be called before the first appendRow — column widths are emitted as part of the worksheet header',\n );\n }\n columnWidths.set(col, width);\n };\n\n const close = async (): Promise<void> => {\n if (closed) return;\n closed = true;\n flushHeader();\n writeText('</sheetData></worksheet>');\n if (pendingText.length > 0) {\n stream.write(encoder.encode(pendingText));\n pendingText = '';\n pendingBytes = 0;\n }\n await stream.end();\n state.sheets.push({ title, sheetId });\n state.hasOpenWorksheet = false;\n };\n\n return { title, appendRow, setColumnWidth, close };\n};\n\n/**\n * Factory: build a {@link WriteOnlyWorkbook} from a sink. State lives in a\n * closure rather than on a class instance per the project-wide \"no classes\"\n * rule (CLAUDE.md).\n */\nconst makeWriteOnlyWorkbook = (sink: XlsxSink): WriteOnlyWorkbook => {\n const styles = makeStylesheet();\n // Reserve cellXfs[0] for the default (no apply* flags). Unstyled cells point\n // at this slot via styleId=0; user-styled cells start at index 1 so the\n // writer emits an `s=\"N\"` attribute for them.\n addCellXf(styles, defaultCellXf());\n // The ZIP writer is created up front: each addWorksheet opens a streaming\n // entry on it and flushes row chunks through the deflate stream as they\n // arrive. Sheets emit before styles / sst / workbook / rels / content-types\n // so the writer can serialise them in order.\n const state: WorkbookState = {\n styles,\n sst: makeSharedStrings(),\n sheets: [],\n finalised: false,\n hasOpenWorksheet: false,\n writer: createZipWriter(sink),\n };\n\n const addWorksheet = async (title: string): Promise<WriteOnlyWorksheet> => {\n if (state.finalised) {\n throw new OpenXmlIoError('addWorksheet: workbook already finalised');\n }\n if (state.hasOpenWorksheet) {\n throw new OpenXmlIoError(\n 'addWorksheet: previous worksheet still open — call close() before opening the next one',\n );\n }\n const taken = new Set(state.sheets.map((s) => s.title.toLowerCase()));\n validateTitle(title, taken);\n state.hasOpenWorksheet = true;\n const sheetId = state.sheets.length + 1;\n return makeWriteOnlyWorksheet(state, title, sheetId);\n };\n\n const finalize = async (): Promise<void> => {\n if (state.finalised) {\n throw new OpenXmlIoError('finalize: already finalised');\n }\n if (state.hasOpenWorksheet) {\n throw new OpenXmlIoError('finalize: a worksheet is still open — call close() before finalising');\n }\n state.finalised = true;\n const writer = state.writer;\n try {\n await finalizeImpl(state, writer);\n } catch (err) {\n // Release the sink so the half-emitted archive doesn't linger as a\n // valid-looking file on disk. abort() is idempotent.\n writer.abort(err);\n throw err;\n }\n };\n\n const abort = (cause?: unknown): void => {\n if (state.finalised) return;\n state.finalised = true;\n state.writer.abort(cause);\n };\n\n return { addWorksheet, finalize, abort };\n};\n\nasync function finalizeImpl(state: WorkbookState, writer: WorkbookState['writer']): Promise<void> {\n // 1. Worksheets — already streamed through writer.addStreamingEntry\n // during each WriteOnlyWorksheet's appendRow / close cycle.\n\n // 2. Stylesheet.\n await writer.addEntry(ARC_STYLE, stylesheetToBytes(state.styles));\n\n // 3. SharedStrings (only when non-empty).\n if (state.sst.entries.length > 0) {\n await writer.addEntry(ARC_SHARED_STRINGS, sharedStringsToBytes(state.sst));\n }\n\n // 4. workbook.xml.\n const workbookXml = serializeWorkbookXml(state.sheets);\n await writer.addEntry(ARC_WORKBOOK, new TextEncoder().encode(workbookXml));\n\n // 5. workbook.xml.rels.\n const wbRels = makeRelationships();\n state.sheets.forEach((s, i) => {\n wbRels.rels.push({\n id: `rId${i + 1}`,\n type: `${REL_NS}/worksheet`,\n target: `worksheets/sheet${s.sheetId}.xml`,\n });\n });\n if (state.sst.entries.length > 0) {\n wbRels.rels.push({\n id: `rId${wbRels.rels.length + 1}`,\n type: `${REL_NS}/sharedStrings`,\n target: 'sharedStrings.xml',\n });\n }\n wbRels.rels.push({\n id: `rId${wbRels.rels.length + 1}`,\n type: `${REL_NS}/styles`,\n target: 'styles.xml',\n });\n await writer.addEntry(ARC_WORKBOOK_RELS, relsToBytes(wbRels));\n\n // 6. root rels.\n const rootRels = makeRelationships();\n rootRels.rels.push({\n id: 'rId1',\n type: `${REL_NS}/officeDocument`,\n target: 'xl/workbook.xml',\n });\n await writer.addEntry(ARC_ROOT_RELS, relsToBytes(rootRels));\n void PKG_REL_NS; // imported for future docProps support\n\n // 7. [Content_Types].xml.\n const manifest = makeManifest();\n // Excel rejects packages whose [Content_Types].xml is missing the Default\n // entries for `rels` / `xml` — without them the package relationships file\n // can't be classified and Excel refuses to open.\n addDefault(manifest, 'rels', 'application/vnd.openxmlformats-package.relationships+xml');\n addDefault(manifest, 'xml', 'application/xml');\n addOverride(manifest, `/${ARC_WORKBOOK}`, XLSX_TYPE);\n for (const s of state.sheets) {\n addOverride(manifest, `/xl/worksheets/sheet${s.sheetId}.xml`, WORKSHEET_TYPE);\n }\n addOverride(manifest, `/${ARC_STYLE}`, STYLES_TYPE);\n if (state.sst.entries.length > 0) {\n addOverride(manifest, `/${ARC_SHARED_STRINGS}`, SHARED_STRINGS_TYPE);\n }\n await writer.addEntry(ARC_CONTENT_TYPES, manifestToBytes(manifest));\n\n await writer.finalize();\n}\n\nconst serializeWorkbookXml = (\n sheets: ReadonlyArray<{ title: string; sheetId: number }>,\n): string => {\n const parts: string[] = [\n '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>',\n `<workbook xmlns=\"${SHEET_MAIN_NS}\" xmlns:r=\"${REL_NS}\">`,\n '<sheets>',\n ];\n sheets.forEach((s, i) => {\n parts.push(\n `<sheet name=\"${escapeAttr(s.title)}\" sheetId=\"${s.sheetId}\" r:id=\"rId${i + 1}\"/>`,\n );\n });\n parts.push('</sheets></workbook>');\n return parts.join('');\n};\n\n/** Open a workbook for streaming write-only output. */\nexport async function createWriteOnlyWorkbook(\n sink: XlsxSink,\n _opts: WriteOnlyOptions = {},\n): Promise<WriteOnlyWorkbook> {\n // The streaming-deflate ZIP writer is constructed eagerly here: each\n // addWorksheet opens an entry on it and flushes row chunks through fflate's\n // `Zip` + `ZipDeflate` immediately, so peak memory stays at one pending row\n // buffer plus deflate scratch (no all-sheets accumulation).\n return makeWriteOnlyWorkbook(sink);\n}\n\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAM,YAAY,IAAI,cAAc;AACpC,MAAM,aAAa,IAAI,cAAc;AAmCrC,MAAM,kBAAkB,aAAyB,cAAsB,YAAsC;CAE3G,MAAM,WAAW,UADJ,SAAS,WACQ,GAAG,UAAU;CAC3C,IAAI,CAAC,UAAU,OAAO,CAAC;CACvB,MAAM,aAAa,YAAY,YAAY;CAC3C,MAAM,SAAS,QAAQ,IAAI,UAAU,IAAI,cAAc,QAAQ,KAAK,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;CAC9F,MAAM,MAAoB,CAAC;CAC3B,KAAK,MAAM,SAAS,aAAa,UAAU,SAAS,GAAG;EACrD,MAAM,OAAO,MAAM,MAAM;EACzB,MAAM,MAAM,MAAM,MAAM,IAAI,OAAO;EACnC,IAAI,CAAC,QAAQ,CAAC,KAAK;EACnB,MAAM,MAAM,SAAS,QAAQ,GAAG;EAChC,IAAI,CAAC,KAAK;EACV,MAAM,WAAW,iBAAiB,cAAc,IAAI,MAAM;EAC1D,IAAI,KAAK;GAAE;GAAM;GAAK;EAAS,CAAC;CAClC;CACA,OAAO;AACT;AAEA,MAAM,eAAe,aAA6B;CAChD,MAAM,IAAI,SAAS,YAAY,GAAG;CAClC,IAAI,IAAI,GAAG,OAAO,SAAS,SAAS;CACpC,OAAO,GAAG,SAAS,MAAM,GAAG,CAAC,EAAE,SAAS,SAAS,MAAM,IAAI,CAAC,EAAE;AAChE;AAEA,MAAM,aAAa,UAA0B;CAC3C,MAAM,IAAI,MAAM,YAAY,GAAG;CAC/B,OAAO,IAAI,IAAI,QAAQ,MAAM,MAAM,IAAI,CAAC;AAC1C;AAEA,MAAM,mBACJ,GACA,OACA,YACA,QACc;CACd,QAAQ,GAAR;EACE,KAAK,KACH,OAAO,UAAU,KAAA,KAAa,UAAU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M,wBACJ,WACW;CACX,MAAM,QAAkB;EACtB;EACA,oBAAoB,cAAc,aAAa,OAAO;EACtD;CACF;CACA,OAAO,SAAS,GAAG,MAAM;EACvB,MAAM,KACJ,gBAAgB,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,aAAa,IAAI,EAAE,IAChF;CACF,CAAC;CACD,MAAM,KAAK,sBAAsB;CACjC,OAAO,MAAM,KAAK,EAAE;AACtB;;AAGA,eAAsB,wBACpB,MACA,QAA0B,CAAC,GACC;CAK5B,OAAO,sBAAsB,IAAI;AACnC"}
@@ -0,0 +1,33 @@
1
+ export type HorizontalAlignment = 'general' | 'left' | 'center' | 'right' | 'fill' | 'justify' | 'centerContinuous' | 'distributed';
2
+ export type VerticalAlignment = 'top' | 'center' | 'bottom' | 'justify' | 'distributed';
3
+ export declare const HORIZONTAL_ALIGNMENTS: ReadonlyArray<HorizontalAlignment>;
4
+ export declare const VERTICAL_ALIGNMENTS: ReadonlyArray<VerticalAlignment>;
5
+ export interface Alignment {
6
+ readonly horizontal?: HorizontalAlignment;
7
+ readonly vertical?: VerticalAlignment;
8
+ /** 0..180 (degrees) OR 255 (vertical stacked text). */
9
+ readonly textRotation?: number;
10
+ readonly wrapText?: boolean;
11
+ readonly shrinkToFit?: boolean;
12
+ /** 0..255 indent levels. */
13
+ readonly indent?: number;
14
+ /** -255..255 relative indent. */
15
+ readonly relativeIndent?: number;
16
+ readonly justifyLastLine?: boolean;
17
+ /** 0 = context-dependent, 1 = LTR, 2 = RTL. */
18
+ readonly readingOrder?: number;
19
+ }
20
+ export declare function makeAlignment(opts?: Partial<Alignment>): Alignment;
21
+ export declare const DEFAULT_ALIGNMENT: Alignment;
22
+ /**
23
+ * Translate an {@link Alignment} to a CSS-property record suitable for
24
+ * HTML preview. `horizontal` → `text-align`, `vertical` →
25
+ * `vertical-align` (table-cell semantics), `wrapText` → `white-space:
26
+ * pre-wrap`, `textRotation` → `transform: rotate(<-deg>)` (Excel rotates
27
+ * counter-clockwise relative to CSS) plus `transform-origin` to keep
28
+ * the text anchored, and `indent` → `padding-left: <n>em`. `255`
29
+ * stacked-text rotation maps to a 180° flip with `writing-mode`.
30
+ *
31
+ * Empty / undefined Alignment returns `{}`.
32
+ */
33
+ export declare function alignmentToCss(alignment: Alignment | undefined): Record<string, string>;
@@ -0,0 +1,3 @@
1
+ import { type Schema } from '../schema/core';
2
+ import type { Alignment } from './alignment';
3
+ export declare const AlignmentSchema: Schema<Alignment>;
@@ -0,0 +1,40 @@
1
+ import { type Color } from './colors';
2
+ export type SideStyle = 'thin' | 'medium' | 'thick' | 'double' | 'hair' | 'dotted' | 'dashed' | 'dashDot' | 'dashDotDot' | 'mediumDashed' | 'mediumDashDot' | 'mediumDashDotDot' | 'slantDashDot';
3
+ export declare const SIDE_STYLES: ReadonlyArray<SideStyle>;
4
+ export interface Side {
5
+ readonly style?: SideStyle;
6
+ readonly color?: Color;
7
+ }
8
+ /** Build an immutable {@link Side}. */
9
+ export declare function makeSide(opts?: Partial<Side>): Side;
10
+ export interface Border {
11
+ /** Left edge. */
12
+ readonly left?: Side;
13
+ readonly right?: Side;
14
+ readonly top?: Side;
15
+ readonly bottom?: Side;
16
+ /** Diagonal stroke (governed together with diagonalUp / diagonalDown). */
17
+ readonly diagonal?: Side;
18
+ /** Vertical stroke between cells of a merged range. */
19
+ readonly vertical?: Side;
20
+ /** Horizontal stroke between cells of a merged range. */
21
+ readonly horizontal?: Side;
22
+ readonly diagonalUp?: boolean;
23
+ readonly diagonalDown?: boolean;
24
+ /** Outline-only flag; defaults to true. */
25
+ readonly outline?: boolean;
26
+ }
27
+ /** Build an immutable {@link Border}. */
28
+ export declare function makeBorder(opts?: Partial<Border>): Border;
29
+ /** Default empty side — convenient sentinel for `no edge stroke`. */
30
+ export declare const EMPTY_SIDE: Side;
31
+ /** Default empty border — every cell starts here until styled otherwise. */
32
+ export declare const DEFAULT_BORDER: Border;
33
+ /**
34
+ * Translate a {@link Border} to a CSS-property record suitable for HTML
35
+ * preview. Each present side becomes `border-<edge>: <width> <style> <#color>`.
36
+ * Theme/auto/missing colours fall back to `currentColor`. Diagonal / vertical /
37
+ * horizontal sides are skipped (CSS has no native equivalent for in-cell
38
+ * strokes). Empty Border returns `{}`.
39
+ */
40
+ export declare function borderToCss(border: Border | undefined): Record<string, string>;
@@ -0,0 +1,4 @@
1
+ import { type Schema } from '../schema/core';
2
+ import type { Border, Side } from './borders';
3
+ export declare const SideSchema: Schema<Side>;
4
+ export declare const BorderSchema: Schema<Border>;
@@ -0,0 +1,270 @@
1
+ import type { Cell } from '../cell/cell';
2
+ import type { Workbook } from '../workbook/workbook';
3
+ import { type Worksheet } from '../worksheet/worksheet';
4
+ import type { Alignment, HorizontalAlignment, VerticalAlignment } from './alignment';
5
+ import type { Border, SideStyle } from './borders';
6
+ import type { Color } from './colors';
7
+ import type { Fill } from './fills';
8
+ import type { Font, UnderlineStyle } from './fonts';
9
+ import type { Protection } from './protection';
10
+ export declare function getCellFont(wb: Workbook, c: Cell): Font;
11
+ export declare function getCellFill(wb: Workbook, c: Cell): Fill;
12
+ export declare function getCellBorder(wb: Workbook, c: Cell): Border;
13
+ export declare function getCellAlignment(wb: Workbook, c: Cell): Alignment;
14
+ export declare function getCellProtection(wb: Workbook, c: Cell): Protection;
15
+ /**
16
+ * Returns the cell's number-format **code** (e.g. `"0.00"`, `"General"`).
17
+ * Built-in IDs resolve through `builtinFormatCode`; custom IDs come from the
18
+ * workbook's numFmts map.
19
+ */
20
+ export declare function getCellNumberFormat(wb: Workbook, c: Cell): string;
21
+ /**
22
+ * Aggregate `fontToCss` + `fillToCss` + `borderToCss` + `alignmentToCss` for a
23
+ * cell into a single CSS-property record. Resolves the cell's `styleId` against
24
+ * the workbook stylesheet, then merges the four partials. On key collision the
25
+ * priority is alignment > border > fill > font (alignment is most specific,
26
+ * font is the broad default). A fully-default cell (`styleId === 0` with empty
27
+ * pools) returns `{}`.
28
+ */
29
+ export declare function cellStyleToCss(wb: Workbook, c: Cell): Record<string, string>;
30
+ export declare function setCellFont(wb: Workbook, c: Cell, font: Font): void;
31
+ export declare function setCellFill(wb: Workbook, c: Cell, fill: Fill): void;
32
+ export declare function setCellBorder(wb: Workbook, c: Cell, border: Border): void;
33
+ export declare function setCellAlignment(wb: Workbook, c: Cell, alignment: Alignment): void;
34
+ export declare function setCellProtection(wb: Workbook, c: Cell, protection: Protection): void;
35
+ /**
36
+ * Set the cell's number format by its **code** string. Built-in codes resolve
37
+ * to their canonical id; custom codes are registered via `addNumFmt`.
38
+ */
39
+ export declare function setCellNumberFormat(wb: Workbook, c: Cell, formatCode: string): void;
40
+ /**
41
+ * Copy the source cell's `styleId` to the target cell. Both cells share the
42
+ * same workbook stylesheet, so the styled appearance carries over without
43
+ * allocating a new xf entry. Pass cells from different workbooks via {@link
44
+ * cloneCellStyle} if you need a deep copy across workbooks.
45
+ */
46
+ export declare function copyCellStyle(_wb: Workbook, source: Cell, target: Cell): void;
47
+ /**
48
+ * Reset a cell back to the default (unstyled) appearance — equivalent to
49
+ * Excel's "Clear Formatting" command. After the call, the cell inherits the
50
+ * workbook's default font / fill / border / alignment / protection /
51
+ * numberFormat. The underlying xf pool is **not** shrunk (Excel doesn't bother
52
+ * either; the orphaned xf is harmless).
53
+ */
54
+ export declare function clearCellStyle(_wb: Workbook, c: Cell): void;
55
+ /**
56
+ * Range-level shortcut for {@link clearCellStyle}. Walks every cell actually
57
+ * present in the range and resets its `styleId` to 0; cells that don't exist
58
+ * yet are **not** materialised (no-op for sparse regions, unlike the styled
59
+ * `setRange*` family which has to create cells to make the patch observable).
60
+ */
61
+ export declare function clearRangeStyle(wb: Workbook, ws: Worksheet, range: string): void;
62
+ /**
63
+ * Deep-copy the source cell's full xf (font / fill / border / alignment /
64
+ * protection / numberFormat) into a possibly-different workbook. Returns the
65
+ * new styleId in the target workbook.
66
+ */
67
+ export declare function cloneCellStyle(sourceWb: Workbook, source: Cell, targetWb: Workbook, target: Cell): number;
68
+ /**
69
+ * Build a single CellXf id from a multi-axis style spec, then apply it to every
70
+ * cell in `range`. The xf is registered once per style shape, so a 1000-cell
71
+ * range allocates one xf — much faster than looping `setCellStyle` per cell.
72
+ */
73
+ export declare function setRangeStyle(wb: Workbook, ws: Worksheet, range: string, opts: {
74
+ font?: Font;
75
+ fill?: Fill;
76
+ border?: Border;
77
+ alignment?: Alignment;
78
+ protection?: Protection;
79
+ numberFormat?: string;
80
+ }): void;
81
+ /**
82
+ * Combined cell-style setter. Each axis is independent — pass any subset and
83
+ * the corresponding `applyXxx` flags get set on the underlying CellXf. Avoids
84
+ * 5+ separate stylesheet round-trips when a caller wants to style a single cell
85
+ * across multiple axes (Excel dedupes the resulting xf record on every call).
86
+ */
87
+ export declare function setCellStyle(wb: Workbook, c: Cell, opts: {
88
+ font?: Font;
89
+ fill?: Fill;
90
+ border?: Border;
91
+ alignment?: Alignment;
92
+ protection?: Protection;
93
+ numberFormat?: string;
94
+ }): void;
95
+ /**
96
+ * Set the cell's background to a solid color. Accepts a hex string
97
+ * (`'FFAAFFAA'`) or a partial `Color` object (`{ theme: 4, tint: 0.4 }`).
98
+ * Equivalent to `setCellFill(wb, c, makePatternFill({ patternType: 'solid',
99
+ * fgColor: makeColor(...) }))`.
100
+ */
101
+ export declare function setCellBackgroundColor(wb: Workbook, c: Cell, color: string | Partial<Color>): void;
102
+ /** Strip the cell's background fill, returning it to the default. */
103
+ export declare function clearCellBackground(wb: Workbook, c: Cell): void;
104
+ /**
105
+ * Range-level shortcut for `setCellBackgroundColor`. Each cell in the range
106
+ * gets the same solid pattern fill via `setRangeStyle`, so the fill pool dedups
107
+ * to a single entry across the whole range.
108
+ */
109
+ export declare function setRangeBackgroundColor(wb: Workbook, ws: Worksheet, range: string, color: string | Partial<Color>): void;
110
+ /** Range-level shortcut for `setCellFont` (full Font replacement). */
111
+ export declare function setRangeFont(wb: Workbook, ws: Worksheet, range: string, font: Font): void;
112
+ /**
113
+ * Range-level shortcut for `setCellNumberFormat`. Stamps the same format-code
114
+ * onto every cell in the range; the numFmt pool dedups the code so callers
115
+ * don't pay per-cell pool churn.
116
+ */
117
+ export declare function setRangeNumberFormat(wb: Workbook, ws: Worksheet, range: string, formatCode: string): void;
118
+ /**
119
+ * Range-level shortcut for `setCellProtection`. Stamps the same Protection
120
+ * (locked / hidden) onto every cell in the range. Pass a full `Protection`
121
+ * value or a partial — partials default missing fields to `false` per Excel's
122
+ * `<protection>` semantics.
123
+ *
124
+ * Common usage: `setRangeProtection(wb, ws, 'B2:B100', { locked: false })` to
125
+ * leave just an input column editable when the sheet is protected.
126
+ */
127
+ export declare function setRangeProtection(wb: Workbook, ws: Worksheet, range: string, protection: Protection | Partial<Protection>): void;
128
+ /**
129
+ * Range-level shortcut for `wrapCellText`. Toggles "Wrap Text" on every cell in
130
+ * the range while preserving each cell's existing alignment (horizontal /
131
+ * vertical / textRotation / indent are not touched). Empty cells in the range
132
+ * are materialised so the alignment patch is observable on round-trip.
133
+ */
134
+ export declare function setRangeWrapText(wb: Workbook, ws: Worksheet, range: string, on?: boolean): void;
135
+ /**
136
+ * Range-level Alignment setter. Two modes:
137
+ *
138
+ * - `mode: 'merge'` (default) — each cell's existing alignment is
139
+ * preserved; the supplied partial overlays it. Use this when you
140
+ * want to set just `horizontal` or `vertical` without wiping the
141
+ * other axes.
142
+ * - `mode: 'replace'` — each cell's alignment is **wholly replaced**
143
+ * by the supplied value. Indent / textRotation / wrapText that
144
+ * weren't supplied are dropped.
145
+ *
146
+ * Empty cells in the range are materialised so the patch is observable on
147
+ * round-trip.
148
+ */
149
+ export declare function setRangeAlignment(wb: Workbook, ws: Worksheet, range: string, alignment: Partial<Alignment>, mode?: 'merge' | 'replace'): void;
150
+ /** Toggle bold on a cell. Preserves other font fields. */
151
+ export declare function setBold(wb: Workbook, c: Cell, on?: boolean): void;
152
+ /** Toggle italic on a cell. */
153
+ export declare function setItalic(wb: Workbook, c: Cell, on?: boolean): void;
154
+ /** Toggle strike-through on a cell. */
155
+ export declare function setStrikethrough(wb: Workbook, c: Cell, on?: boolean): void;
156
+ /**
157
+ * Set the underline style. Pass `false` to drop underline; pass `'single' |
158
+ * 'double' | 'singleAccounting' | 'doubleAccounting'` to apply that style; pass
159
+ * `true` for the most common single-line.
160
+ */
161
+ export declare function setUnderline(wb: Workbook, c: Cell, style?: UnderlineStyle | boolean): void;
162
+ /** Set the font size in points (e.g. 14). Preserves other fields. */
163
+ export declare function setFontSize(wb: Workbook, c: Cell, size: number): void;
164
+ /** Set the font family name (e.g. "Arial"). Preserves other fields. */
165
+ export declare function setFontName(wb: Workbook, c: Cell, name: string): void;
166
+ /**
167
+ * Set the font color. Accepts a hex string ("FFAA0033") or a partial `Color`
168
+ * object (`{ theme: 4, tint: 0.4 }`). Preserves other font fields.
169
+ */
170
+ export declare function setFontColor(wb: Workbook, c: Cell, color: string | Partial<Color>): void;
171
+ /**
172
+ * Center a cell horizontally + vertically. Mirrors Excel's "Merge & Center" UI
173
+ * button (without the merge — see {@link mergeCells} for that). Preserves any
174
+ * other alignment fields already present.
175
+ */
176
+ export declare function centerCell(wb: Workbook, c: Cell): void;
177
+ /** Toggle "Wrap Text" on a cell, preserving other alignment fields. */
178
+ export declare function wrapCellText(wb: Workbook, c: Cell, wrap?: boolean): void;
179
+ /** Set the horizontal alignment in isolation. */
180
+ export declare function alignCellHorizontal(wb: Workbook, c: Cell, horizontal: HorizontalAlignment): void;
181
+ /** Set the vertical alignment in isolation. */
182
+ export declare function alignCellVertical(wb: Workbook, c: Cell, vertical: VerticalAlignment): void;
183
+ /**
184
+ * Rotate the cell's text. `degrees` accepts 0..180 (clockwise) or 255 for
185
+ * Excel's "vertical stacked" mode. Mirrors the rotate icons in the alignment
186
+ * ribbon.
187
+ */
188
+ export declare function rotateCellText(wb: Workbook, c: Cell, degrees: number): void;
189
+ /** Set or clear the indent level (0..255). */
190
+ export declare function indentCell(wb: Workbook, c: Cell, levels: number): void;
191
+ /**
192
+ * Format a cell as currency. Produces one of:
193
+ * - default → `"$#,##0.00"` (US dollar, 2 decimals)
194
+ * - `{ symbol: "€" }` → `"€#,##0.00"`
195
+ * - `{ symbol: "¥", decimals: 0 }` → `"¥#,##0"`
196
+ * - `{ accounting: true }` → `"_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-"`
197
+ * (Excel's "Accounting" subtype with right-aligned symbol).
198
+ */
199
+ export declare function setCellAsCurrency(wb: Workbook, c: Cell, opts?: {
200
+ symbol?: string;
201
+ decimals?: number;
202
+ accounting?: boolean;
203
+ }): void;
204
+ /**
205
+ * Format a cell as a percentage. `decimals` defaults to 0 → `"0%"`; `decimals:
206
+ * 2` → `"0.00%"`. The cell value is multiplied by 100 by Excel during display.
207
+ */
208
+ export declare function setCellAsPercent(wb: Workbook, c: Cell, decimals?: number): void;
209
+ /**
210
+ * Format a cell as a date. `format` defaults to Excel's default
211
+ * locale-independent ISO-style date `"yyyy-mm-dd"`. Common alternatives:
212
+ * `"m/d/yyyy"`, `"dd-mmm-yy"`, `"yyyy-mm-dd hh:mm:ss"`.
213
+ */
214
+ export declare function setCellAsDate(wb: Workbook, c: Cell, format?: string): void;
215
+ /**
216
+ * Format a cell as a thousands-separated number. `decimals` defaults to 0 →
217
+ * `"#,##0"`; `decimals: 2` → `"#,##0.00"`.
218
+ */
219
+ export declare function setCellAsNumber(wb: Workbook, c: Cell, decimals?: number): void;
220
+ /**
221
+ * Apply Excel's stock "table header" formatting to a range: bold white text on
222
+ * a dark fill, plus a thick bottom border. Override any axis via `opts` — pass
223
+ * `bold: false` to drop the bold, or `fillColor: 'FF305496'` for a different
224
+ * shade. Defaults match Excel's "Table Style Medium 2" header row.
225
+ */
226
+ export declare function formatAsHeader(wb: Workbook, ws: Worksheet, range: string, opts?: {
227
+ fillColor?: string | Partial<Color>;
228
+ fontColor?: string | Partial<Color>;
229
+ bold?: boolean;
230
+ bottomBorder?: SideStyle | false;
231
+ bottomBorderColor?: string | Partial<Color>;
232
+ }): void;
233
+ /**
234
+ * Apply a built-in Excel style ("Heading 1" / "Total" / "Good" / "Bad" /
235
+ * "Calculation" / etc.) to a single cell. Registers the built-in on the
236
+ * Stylesheet (idempotent) and points the cell's xf at it via `xfId` while
237
+ * inheriting the matching font/fill/border/ numFmt ids so the cell renders
238
+ * correctly on its own.
239
+ *
240
+ * Throws when `name` isn't in {@link BUILTIN_NAMED_STYLES}; use {@link
241
+ * applyNamedStyle} for user-registered styles.
242
+ */
243
+ export declare function applyBuiltinStyle(wb: Workbook, c: Cell, name: string): void;
244
+ /**
245
+ * Apply a NamedStyle that's already registered on the workbook (via
246
+ * `addNamedStyle` or `ensureBuiltinStyle`) to a single cell, by name.
247
+ */
248
+ export declare function applyNamedStyle(wb: Workbook, c: Cell, name: string): void;
249
+ /**
250
+ * Apply the same {@link SideStyle} to all four edges of a single cell. Optional
251
+ * color via hex string or `Color` partial. Equivalent to `setCellBorder(wb, c,
252
+ * makeBorder({ left, right, top, bottom: side }))` with all four sides
253
+ * identical.
254
+ */
255
+ export declare function setCellBorderAll(wb: Workbook, c: Cell, opts?: {
256
+ style: SideStyle;
257
+ color?: string | Partial<Color>;
258
+ }): void;
259
+ /**
260
+ * Draw an outer border around a rectangular range. Cells on the perimeter
261
+ * receive a partial border (only the edges that face outside the range); inner
262
+ * cells are unaffected unless `inner` is provided, in which case every cell in
263
+ * the range receives a border combining its perimeter edges with the `inner`
264
+ * style for the inside edges.
265
+ */
266
+ export declare function setRangeBorderBox(wb: Workbook, ws: Worksheet, range: string, opts?: {
267
+ style: SideStyle;
268
+ color?: string | Partial<Color>;
269
+ inner?: SideStyle;
270
+ }): void;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Colour reference. All fields are optional but Excel expects exactly one of
3
+ * {rgb, indexed, theme, auto} to be set; if none is, the cell inherits the
4
+ * parent style's colour.
5
+ *
6
+ * `tint` modulates the resolved colour; -1 = full black, +1 = full white.
7
+ */
8
+ export interface Color {
9
+ /** "AARRGGBB" hex (uppercase). 6-hex inputs are auto-padded with `00` alpha. */
10
+ readonly rgb?: string;
11
+ /** 0..63 → COLOR_INDEX entry. 64 = system foreground, 65 = system background. */
12
+ readonly indexed?: number;
13
+ /** Theme colour index. */
14
+ readonly theme?: number;
15
+ /** "Auto" / system default. */
16
+ readonly auto?: boolean;
17
+ /** Lightness modulation in [-1, 1]. */
18
+ readonly tint?: number;
19
+ }
20
+ /**
21
+ * Legacy 64-entry palette indexed colours fall back to. Verbatim from
22
+ * openpyxl/openpyxl/styles/colors.py — must not be reordered.
23
+ */
24
+ export declare const COLOR_INDEX: readonly string[];
25
+ /**
26
+ * Convenience constants — match openpyxl's exports. Inlined rather than indexed
27
+ * off COLOR_INDEX to keep the type system from widening to `string | undefined`
28
+ * on tuple lookup.
29
+ */
30
+ export declare const BLACK = "00000000";
31
+ export declare const WHITE = "00FFFFFF";
32
+ export declare const BLUE = "000000FF";
33
+ /**
34
+ * Normalise an aRGB hex string. Accepts either 6 or 8 hex digits; 6-digit input
35
+ * is padded to 8 by prefixing `00` (alpha=0 = fully opaque per Excel
36
+ * convention). Returns the canonical uppercase form.
37
+ */
38
+ export declare function normaliseRgb(value: string): string;
39
+ /**
40
+ * Build an immutable {@link Color}. Validates ranges (indexed in [0, 65], tint
41
+ * in [-1, 1]) and normalises rgb hex.
42
+ */
43
+ export declare function makeColor(opts?: Partial<Color>): Color;
44
+ /**
45
+ * Resolve `indexed` references against {@link COLOR_INDEX}. Returns undefined
46
+ * for 64/65 (system fg/bg, not in the palette) or out-of-range.
47
+ */
48
+ export declare function resolveIndexedColor(idx: number): string | undefined;
49
+ /** Shortcut for the common opaque solid colour. */
50
+ export declare function rgbColor(hex: string): Color;
51
+ /**
52
+ * Read a {@link Color} value-object back to a normalised ARGB hex. Resolution
53
+ * order: explicit `rgb` → `indexed` palette lookup. Returns `undefined` for
54
+ * `theme` / `auto` / empty inputs (unresolvable without a theme), so callers
55
+ * can fall back to a default.
56
+ */
57
+ export declare function colorToHex(color: Color | undefined): string | undefined;
58
+ /**
59
+ * Compute the relative luminance of an ARGB / RGB hex string per the WCAG 2.x
60
+ * formula. Returns a value in `[0, 1]` where 0 is black and 1 is white. The
61
+ * alpha channel (if present) is ignored.
62
+ */
63
+ export declare function luminance(hex: string): number;
64
+ /**
65
+ * WCAG contrast ratio between two ARGB hex colors. Returns a value in `[1,
66
+ * 21]`; 1 = identical luminance, 21 = pure black on pure white. The order of
67
+ * arguments doesn't matter.
68
+ */
69
+ export declare function contrastRatio(hexA: string, hexB: string): number;
70
+ /**
71
+ * Pick the higher-contrast text color (`'FF000000'` black or `'FFFFFFFF'`
72
+ * white) for a background hex. Useful when applying a solid fill and wanting
73
+ * the cell text to stay readable.
74
+ */
75
+ export declare function pickReadableTextColor(backgroundHex: string): 'FF000000' | 'FFFFFFFF';
76
+ /**
77
+ * Lighten a color by mixing it with white. `amount` is in `[0, 1]`: 0 returns
78
+ * the input unchanged, 1 returns pure white. Alpha channel is preserved.
79
+ * Equivalent to `mixColors(hex, 'FFFFFFFF', amount)`.
80
+ */
81
+ export declare function lighten(hex: string, amount: number): string;
82
+ /**
83
+ * Darken a color by mixing it with black. `amount` is in `[0, 1]`: 0 returns
84
+ * the input unchanged, 1 returns pure black (preserving the alpha channel).
85
+ */
86
+ export declare function darken(hex: string, amount: number): string;
87
+ /**
88
+ * Linearly interpolate between two ARGB colors. `t = 0` returns `hexA`; `t = 1`
89
+ * returns `hexB`; intermediate values mix per channel (including alpha).
90
+ */
91
+ export declare function mixColors(hexA: string, hexB: string, t: number): string;
92
+ /**
93
+ * Convert an ARGB / RGB hex to its HSL representation. Returns `{ h, s, l, a }`
94
+ * with `h ∈ [0, 360)`, `s ∈ [0, 1]`, `l ∈ [0, 1]`, `a ∈ [0, 255]` (alpha as the
95
+ * original byte). Useful for theme tweaking (rotate hue, desaturate, etc.)
96
+ * before round-tripping through {@link hslToHex}.
97
+ */
98
+ export declare function hexToHsl(hex: string): {
99
+ h: number;
100
+ s: number;
101
+ l: number;
102
+ a: number;
103
+ };
104
+ /**
105
+ * Rotate the hue of a color by `degrees` (positive = clockwise). Saturation and
106
+ * lightness are preserved; alpha is preserved. Equivalent to `hexToHsl` →
107
+ * adjust `h` → `hslToHex`.
108
+ */
109
+ export declare function rotateHue(hex: string, degrees: number): string;
110
+ /**
111
+ * Adjust the saturation of a color by `delta` (added directly to the `[0, 1]`
112
+ * saturation channel and clamped). Positive = more vivid, negative = closer to
113
+ * gray. Hue, lightness, and alpha are preserved.
114
+ */
115
+ export declare function adjustSaturation(hex: string, delta: number): string;
116
+ /**
117
+ * Adjust the lightness of a color by `delta` (added directly to the `[0, 1]`
118
+ * lightness channel and clamped). Positive = lighter, negative = darker.
119
+ * Distinct from {@link lighten} / {@link darken} which mix toward white/black
120
+ * in RGB space.
121
+ */
122
+ export declare function adjustLightness(hex: string, delta: number): string;
123
+ /**
124
+ * Convert HSL components back to an ARGB hex string. `h` wraps mod-360, `s` and
125
+ * `l` clamp to `[0, 1]`. `alpha` is the byte (default 255 = opaque), placed in
126
+ * the high byte of the result.
127
+ */
128
+ export declare function hslToHex(h: number, s: number, l: number, alpha?: number): string;
@@ -0,0 +1,3 @@
1
+ import { type Schema } from '../schema/core';
2
+ import type { Color } from './colors';
3
+ export declare const ColorSchema: Schema<Color>;
@@ -0,0 +1,41 @@
1
+ import type { Alignment } from './alignment';
2
+ import type { Border } from './borders';
3
+ import type { Fill } from './fills';
4
+ import type { Font } from './fonts';
5
+ import type { NumberFormat } from './numbers';
6
+ import type { Protection } from './protection';
7
+ import type { Stylesheet } from './stylesheet';
8
+ /**
9
+ * Differential ("partial") style. Every component is optional; only
10
+ * the set fields override the base style of whatever the DXF is
11
+ * applied to.
12
+ */
13
+ export interface DifferentialStyle {
14
+ readonly font?: Font;
15
+ readonly fill?: Fill;
16
+ readonly border?: Border;
17
+ readonly alignment?: Alignment;
18
+ readonly protection?: Protection;
19
+ /**
20
+ * NumberFormat carries both the id and the format code so DXFs can
21
+ * reference custom user-defined number formats without ambiguity.
22
+ */
23
+ readonly numFmt?: NumberFormat;
24
+ }
25
+ export declare function makeDifferentialStyle(opts?: Partial<DifferentialStyle>): DifferentialStyle;
26
+ /**
27
+ * Stylesheet pool extension. The DXF list is allocated lazily on first
28
+ * use so empty stylesheets stay slim.
29
+ */
30
+ export interface StylesheetWithDxfs extends Stylesheet {
31
+ dxfs?: DifferentialStyle[];
32
+ _dxfIdByKey?: Map<string, number>;
33
+ }
34
+ /**
35
+ * Add a DifferentialStyle to the stylesheet's `dxfs` pool. Returns
36
+ * the 0-based index. Idempotent on structural equality (via
37
+ * stableStringify).
38
+ */
39
+ export declare function addDxf(ss: Stylesheet, dxf: DifferentialStyle): number;
40
+ /** Read-only access to the dxfs pool. Returns `[]` when none registered. */
41
+ export declare function getDxfs(ss: Stylesheet): ReadonlyArray<DifferentialStyle>;