@evotecit/officeimo 0.0.0-stage → 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.
Files changed (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1219 -2
  3. package/bundles/officeimo-canopyx.js +11286 -0
  4. package/bundles/officeimo-canopyx.mjs +11185 -0
  5. package/bundles/officeimo-csv.js +1254 -0
  6. package/bundles/officeimo-csv.mjs +1229 -0
  7. package/bundles/officeimo-datatables.js +11572 -0
  8. package/bundles/officeimo-datatables.mjs +11470 -0
  9. package/bundles/officeimo-execution.js +1503 -0
  10. package/bundles/officeimo-execution.mjs +1479 -0
  11. package/bundles/officeimo-pdf.js +6564 -0
  12. package/bundles/officeimo-pdf.mjs +6502 -0
  13. package/bundles/officeimo-xlsx.js +5333 -0
  14. package/bundles/officeimo-xlsx.mjs +5279 -0
  15. package/bundles/officeimo.js +11022 -0
  16. package/bundles/officeimo.mjs +10924 -0
  17. package/dist/core/dates.d.ts +1 -0
  18. package/dist/core/dates.js +16 -0
  19. package/dist/core/errors.d.ts +12 -0
  20. package/dist/core/errors.js +31 -0
  21. package/dist/core/grouped-report.d.ts +87 -0
  22. package/dist/core/grouped-report.js +252 -0
  23. package/dist/core/index.d.ts +72 -0
  24. package/dist/core/index.js +37 -0
  25. package/dist/core/iteration.d.ts +7 -0
  26. package/dist/core/iteration.js +149 -0
  27. package/dist/core/limits.d.ts +7 -0
  28. package/dist/core/limits.js +56 -0
  29. package/dist/core/links.d.ts +5 -0
  30. package/dist/core/links.js +14 -0
  31. package/dist/core/presentation.d.ts +29 -0
  32. package/dist/core/presentation.js +59 -0
  33. package/dist/core/progress.d.ts +1 -0
  34. package/dist/core/progress.js +10 -0
  35. package/dist/core/sinks.d.ts +33 -0
  36. package/dist/core/sinks.js +101 -0
  37. package/dist/core/table.d.ts +8 -0
  38. package/dist/core/table.js +1 -0
  39. package/dist/core/value-text.d.ts +7 -0
  40. package/dist/core/value-text.js +13 -0
  41. package/dist/csv/index.d.ts +44 -0
  42. package/dist/csv/index.js +133 -0
  43. package/dist/csv/options.d.ts +1 -0
  44. package/dist/csv/options.js +8 -0
  45. package/dist/csv/structured-rows.d.ts +3 -0
  46. package/dist/csv/structured-rows.js +15 -0
  47. package/dist/execution/host.d.ts +5 -0
  48. package/dist/execution/host.js +164 -0
  49. package/dist/execution/index.d.ts +3 -0
  50. package/dist/execution/index.js +2 -0
  51. package/dist/execution/protocol.d.ts +48 -0
  52. package/dist/execution/protocol.js +173 -0
  53. package/dist/execution/types.d.ts +42 -0
  54. package/dist/execution/types.js +1 -0
  55. package/dist/execution/worker.d.ts +3 -0
  56. package/dist/execution/worker.js +147 -0
  57. package/dist/index.d.ts +32 -0
  58. package/dist/index.js +14 -0
  59. package/dist/integrations/canopyx/dates.d.ts +1 -0
  60. package/dist/integrations/canopyx/dates.js +34 -0
  61. package/dist/integrations/canopyx/index.d.ts +10 -0
  62. package/dist/integrations/canopyx/index.js +45 -0
  63. package/dist/integrations/canopyx/source.d.ts +3 -0
  64. package/dist/integrations/canopyx/source.js +116 -0
  65. package/dist/integrations/canopyx/types.d.ts +83 -0
  66. package/dist/integrations/canopyx/types.js +1 -0
  67. package/dist/integrations/datatables/api.d.ts +1 -0
  68. package/dist/integrations/datatables/api.js +27 -0
  69. package/dist/integrations/datatables/headings.d.ts +1 -0
  70. package/dist/integrations/datatables/headings.js +65 -0
  71. package/dist/integrations/datatables/index.d.ts +12 -0
  72. package/dist/integrations/datatables/index.js +167 -0
  73. package/dist/integrations/datatables/snapshot.d.ts +3 -0
  74. package/dist/integrations/datatables/snapshot.js +206 -0
  75. package/dist/integrations/datatables/types.d.ts +98 -0
  76. package/dist/integrations/datatables/types.js +1 -0
  77. package/dist/integrations/options.d.ts +13 -0
  78. package/dist/integrations/options.js +34 -0
  79. package/dist/internal/capture.d.ts +4 -0
  80. package/dist/internal/capture.js +14 -0
  81. package/dist/internal/columns.d.ts +27 -0
  82. package/dist/internal/columns.js +1 -0
  83. package/dist/internal/crc32.d.ts +6 -0
  84. package/dist/internal/crc32.js +17 -0
  85. package/dist/internal/export-values.d.ts +3 -0
  86. package/dist/internal/export-values.js +14 -0
  87. package/dist/internal/rows.d.ts +6 -0
  88. package/dist/internal/rows.js +68 -0
  89. package/dist/internal/table-spans.d.ts +11 -0
  90. package/dist/internal/table-spans.js +58 -0
  91. package/dist/internal/totals.d.ts +15 -0
  92. package/dist/internal/totals.js +42 -0
  93. package/dist/opc/index.d.ts +67 -0
  94. package/dist/opc/index.js +233 -0
  95. package/dist/opc/properties.d.ts +15 -0
  96. package/dist/opc/properties.js +18 -0
  97. package/dist/opc/uri.d.ts +5 -0
  98. package/dist/opc/uri.js +41 -0
  99. package/dist/pdf/annotations.d.ts +1 -0
  100. package/dist/pdf/annotations.js +38 -0
  101. package/dist/pdf/binary.d.ts +6 -0
  102. package/dist/pdf/binary.js +24 -0
  103. package/dist/pdf/document-drawings.d.ts +15 -0
  104. package/dist/pdf/document-drawings.js +237 -0
  105. package/dist/pdf/document-grouped.d.ts +1 -0
  106. package/dist/pdf/document-grouped.js +194 -0
  107. package/dist/pdf/document-images.d.ts +19 -0
  108. package/dist/pdf/document-images.js +125 -0
  109. package/dist/pdf/document-types.d.ts +160 -0
  110. package/dist/pdf/document-types.js +1 -0
  111. package/dist/pdf/document-vectors.d.ts +11 -0
  112. package/dist/pdf/document-vectors.js +77 -0
  113. package/dist/pdf/document.d.ts +9 -0
  114. package/dist/pdf/document.js +270 -0
  115. package/dist/pdf/drawing-types.d.ts +53 -0
  116. package/dist/pdf/drawing-types.js +1 -0
  117. package/dist/pdf/font-resources.d.ts +43 -0
  118. package/dist/pdf/font-resources.js +201 -0
  119. package/dist/pdf/font-support.d.ts +1 -0
  120. package/dist/pdf/font-support.js +60 -0
  121. package/dist/pdf/font.d.ts +17 -0
  122. package/dist/pdf/font.js +56 -0
  123. package/dist/pdf/grouped-table.d.ts +6 -0
  124. package/dist/pdf/grouped-table.js +40 -0
  125. package/dist/pdf/grouped-types.d.ts +34 -0
  126. package/dist/pdf/grouped-types.js +1 -0
  127. package/dist/pdf/grouped.d.ts +10 -0
  128. package/dist/pdf/grouped.js +37 -0
  129. package/dist/pdf/index.d.ts +22 -0
  130. package/dist/pdf/index.js +8 -0
  131. package/dist/pdf/inline-text.d.ts +30 -0
  132. package/dist/pdf/inline-text.js +142 -0
  133. package/dist/pdf/inline-types.d.ts +15 -0
  134. package/dist/pdf/inline-types.js +1 -0
  135. package/dist/pdf/list-layout.d.ts +6 -0
  136. package/dist/pdf/list-layout.js +49 -0
  137. package/dist/pdf/objects.d.ts +2 -0
  138. package/dist/pdf/objects.js +143 -0
  139. package/dist/pdf/outlines.d.ts +1 -0
  140. package/dist/pdf/outlines.js +55 -0
  141. package/dist/pdf/page-context.d.ts +1 -0
  142. package/dist/pdf/page-context.js +12 -0
  143. package/dist/pdf/pages.d.ts +1 -0
  144. package/dist/pdf/pages.js +679 -0
  145. package/dist/pdf/paragraph-layout.d.ts +19 -0
  146. package/dist/pdf/paragraph-layout.js +66 -0
  147. package/dist/pdf/paragraph-styles.d.ts +1 -0
  148. package/dist/pdf/paragraph-styles.js +66 -0
  149. package/dist/pdf/png.d.ts +9 -0
  150. package/dist/pdf/png.js +259 -0
  151. package/dist/pdf/preflight.d.ts +7 -0
  152. package/dist/pdf/preflight.js +32 -0
  153. package/dist/pdf/presentation-settings.d.ts +5 -0
  154. package/dist/pdf/presentation-settings.js +28 -0
  155. package/dist/pdf/providers/harfbuzz.d.ts +60 -0
  156. package/dist/pdf/providers/harfbuzz.js +112 -0
  157. package/dist/pdf/providers/unicode13-profile.d.ts +2 -0
  158. package/dist/pdf/providers/unicode13-profile.js +115 -0
  159. package/dist/pdf/section-types.d.ts +15 -0
  160. package/dist/pdf/section-types.js +40 -0
  161. package/dist/pdf/session.d.ts +25 -0
  162. package/dist/pdf/session.js +55 -0
  163. package/dist/pdf/settings.d.ts +15 -0
  164. package/dist/pdf/settings.js +171 -0
  165. package/dist/pdf/shaped-text.d.ts +5 -0
  166. package/dist/pdf/shaped-text.js +205 -0
  167. package/dist/pdf/standard-widths.d.ts +1 -0
  168. package/dist/pdf/standard-widths.js +317 -0
  169. package/dist/pdf/structure-parent-tree.d.ts +1 -0
  170. package/dist/pdf/structure-parent-tree.js +57 -0
  171. package/dist/pdf/structure.d.ts +6 -0
  172. package/dist/pdf/structure.js +250 -0
  173. package/dist/pdf/table-band-flow.d.ts +34 -0
  174. package/dist/pdf/table-band-flow.js +114 -0
  175. package/dist/pdf/table-band-plan.d.ts +10 -0
  176. package/dist/pdf/table-band-plan.js +85 -0
  177. package/dist/pdf/table-layout.d.ts +71 -0
  178. package/dist/pdf/table-layout.js +205 -0
  179. package/dist/pdf/table-structure.d.ts +1 -0
  180. package/dist/pdf/table-structure.js +92 -0
  181. package/dist/pdf/text-shaping-types.d.ts +39 -0
  182. package/dist/pdf/text-shaping-types.js +1 -0
  183. package/dist/pdf/text.d.ts +13 -0
  184. package/dist/pdf/text.js +96 -0
  185. package/dist/pdf/truetype-subset.d.ts +5 -0
  186. package/dist/pdf/truetype-subset.js +217 -0
  187. package/dist/pdf/truetype.d.ts +1 -0
  188. package/dist/pdf/truetype.js +235 -0
  189. package/dist/pdf/types.d.ts +169 -0
  190. package/dist/pdf/types.js +1 -0
  191. package/dist/pdf/write.d.ts +6 -0
  192. package/dist/pdf/write.js +57 -0
  193. package/dist/xlsx/attachments.d.ts +30 -0
  194. package/dist/xlsx/attachments.js +67 -0
  195. package/dist/xlsx/chart-bindings.d.ts +1 -0
  196. package/dist/xlsx/chart-bindings.js +122 -0
  197. package/dist/xlsx/chart-types.d.ts +73 -0
  198. package/dist/xlsx/chart-types.js +1 -0
  199. package/dist/xlsx/chart-xml.d.ts +2 -0
  200. package/dist/xlsx/chart-xml.js +103 -0
  201. package/dist/xlsx/charts.d.ts +1 -0
  202. package/dist/xlsx/charts.js +159 -0
  203. package/dist/xlsx/conditional-formatting.d.ts +1 -0
  204. package/dist/xlsx/conditional-formatting.js +158 -0
  205. package/dist/xlsx/conditional-types.d.ts +64 -0
  206. package/dist/xlsx/conditional-types.js +1 -0
  207. package/dist/xlsx/data-row-ranges.d.ts +5 -0
  208. package/dist/xlsx/data-row-ranges.js +39 -0
  209. package/dist/xlsx/differential-styles.d.ts +1 -0
  210. package/dist/xlsx/differential-styles.js +102 -0
  211. package/dist/xlsx/formula.d.ts +8 -0
  212. package/dist/xlsx/formula.js +104 -0
  213. package/dist/xlsx/grouped-layout.d.ts +61 -0
  214. package/dist/xlsx/grouped-layout.js +79 -0
  215. package/dist/xlsx/grouped.d.ts +16 -0
  216. package/dist/xlsx/grouped.js +161 -0
  217. package/dist/xlsx/index.d.ts +24 -0
  218. package/dist/xlsx/index.js +10 -0
  219. package/dist/xlsx/layout.d.ts +1 -0
  220. package/dist/xlsx/layout.js +186 -0
  221. package/dist/xlsx/options.d.ts +1 -0
  222. package/dist/xlsx/options.js +16 -0
  223. package/dist/xlsx/portable.d.ts +27 -0
  224. package/dist/xlsx/portable.js +44 -0
  225. package/dist/xlsx/preservation.d.ts +1 -0
  226. package/dist/xlsx/preservation.js +60 -0
  227. package/dist/xlsx/ranges.d.ts +1 -0
  228. package/dist/xlsx/ranges.js +24 -0
  229. package/dist/xlsx/regions.d.ts +1 -0
  230. package/dist/xlsx/regions.js +97 -0
  231. package/dist/xlsx/structured-rows.d.ts +11 -0
  232. package/dist/xlsx/structured-rows.js +28 -0
  233. package/dist/xlsx/style-xml.d.ts +1 -0
  234. package/dist/xlsx/style-xml.js +6 -0
  235. package/dist/xlsx/styles.d.ts +70 -0
  236. package/dist/xlsx/styles.js +203 -0
  237. package/dist/xlsx/table.d.ts +12 -0
  238. package/dist/xlsx/table.js +35 -0
  239. package/dist/xlsx/types.d.ts +180 -0
  240. package/dist/xlsx/types.js +1 -0
  241. package/dist/xlsx/validation-types.d.ts +18 -0
  242. package/dist/xlsx/validation-types.js +1 -0
  243. package/dist/xlsx/validation.d.ts +1 -0
  244. package/dist/xlsx/validation.js +92 -0
  245. package/dist/xlsx/values.d.ts +13 -0
  246. package/dist/xlsx/values.js +86 -0
  247. package/dist/xlsx/workbook.d.ts +50 -0
  248. package/dist/xlsx/workbook.js +452 -0
  249. package/dist/xlsx/worksheet.d.ts +71 -0
  250. package/dist/xlsx/worksheet.js +700 -0
  251. package/dist/xlsx/write.d.ts +15 -0
  252. package/dist/xlsx/write.js +47 -0
  253. package/dist/xml/index.d.ts +24 -0
  254. package/dist/xml/index.js +74 -0
  255. package/dist/zip/entry.d.ts +39 -0
  256. package/dist/zip/entry.js +122 -0
  257. package/dist/zip/index.d.ts +44 -0
  258. package/dist/zip/index.js +248 -0
  259. package/package.json +104 -4
@@ -0,0 +1,57 @@
1
+ import { BlobByteSink, withDestination } from "../core/sinks.js";
2
+ import { beginTask, checkAbort, consumeRows, pause, taskYieldDue } from "../core/iteration.js";
3
+ import { notifyProgress } from "../core/progress.js";
4
+ import { createRowProjector } from "../internal/rows.js";
5
+ import { settings } from "./settings.js";
6
+ import { PdfWriteSession } from "./session.js";
7
+ export async function writePdf(rows, configuration) {
8
+ const sink = new BlobByteSink();
9
+ try {
10
+ await writePdfTo(rows, sink, configuration);
11
+ return sink.toBlob("application/pdf");
12
+ }
13
+ catch (error) {
14
+ sink.discard();
15
+ throw error;
16
+ }
17
+ }
18
+ export async function writePdfTo(rows, destination, configuration) {
19
+ const prepared = settings(configuration), { options, budget } = prepared;
20
+ beginTask();
21
+ checkAbort(options.signal);
22
+ return withDestination(destination, async (sink) => {
23
+ const session = new PdfWriteSession(sink, prepared, true), { objects, pages } = session, layout = session.layout;
24
+ const project = createRowProjector(options.columns, undefined, options.signal);
25
+ let count = 0;
26
+ await session.start();
27
+ const completed = () => {
28
+ count++;
29
+ if (count % 256 === 0) {
30
+ notifyProgress(options.onProgress, { phase: "rows", rows: count, bytes: objects.bytes });
31
+ if (taskYieldDue())
32
+ return pause().then(() => { checkAbort(options.signal); });
33
+ }
34
+ checkAbort(options.signal);
35
+ };
36
+ await consumeRows(rows, options.signal, async (row) => {
37
+ budget.row(count + 1);
38
+ const values = project(row, count);
39
+ return pages.row(await layout.data(values, count)).then(completed);
40
+ });
41
+ const footer = await layout.footer(count);
42
+ if (footer) {
43
+ if (options.footer?.rows)
44
+ await pages.block(footer);
45
+ else
46
+ await pages.row(footer[0]);
47
+ }
48
+ if (layout.bands)
49
+ await pages.endTable();
50
+ if (options.messageBottom)
51
+ await pages.paragraph(options.messageBottom);
52
+ await session.finish();
53
+ notifyProgress(options.onProgress, { phase: "complete", rows: count, bytes: objects.bytes });
54
+ checkAbort(options.signal);
55
+ return { rows: count, columns: options.columns.length, bytes: objects.bytes };
56
+ });
57
+ }
@@ -0,0 +1,30 @@
1
+ import type { InvalidCharacterPolicy } from "../xml/index.js";
2
+ /** A link attached to an existing cell. Its value and presentation remain ordinary cell data. */
3
+ export interface Hyperlink {
4
+ readonly cell: string;
5
+ readonly target: string;
6
+ readonly tooltip?: string;
7
+ }
8
+ /** One-based worksheet anchor and display size in CSS pixels at 96 DPI. */
9
+ export interface WorksheetAnchor {
10
+ readonly row: number;
11
+ readonly column: number;
12
+ readonly width: number;
13
+ readonly height: number;
14
+ readonly description?: string;
15
+ }
16
+ /** PNG bytes anchored in worksheet coordinates. */
17
+ export interface WorksheetImage extends WorksheetAnchor {
18
+ readonly data: Uint8Array;
19
+ }
20
+ export declare function cellPosition(reference: string): {
21
+ row: number;
22
+ column: number;
23
+ };
24
+ export declare function copyHyperlink(link: Hyperlink, policy: InvalidCharacterPolicy): Hyperlink;
25
+ export declare function copyImage(image: WorksheetImage, policy: InvalidCharacterPolicy, checkBytes?: (bytes: number) => void): WorksheetImage;
26
+ export declare function hyperlinksXml(links: readonly Hyperlink[], policy: InvalidCharacterPolicy, internal?: readonly {
27
+ cell: string;
28
+ location: string;
29
+ }[]): string;
30
+ export declare const drawingContentType = "application/vnd.openxmlformats-officedocument.drawing+xml";
@@ -0,0 +1,67 @@
1
+ import { cleanXml, escapeXml, escapeOoxmlAttribute, xmlDeclaration } from "../xml/index.js";
2
+ import { copyExportLink } from "../core/links.js";
3
+ import { officeRelationshipsNamespace } from "../opc/index.js";
4
+ import { chartAnchorXml } from "./chart-xml.js";
5
+ import { captureFields } from "../internal/capture.js";
6
+ /** @internal Native charts and images use the same drawing coordinate policy. */
7
+ export function copyDrawingAnchor(anchor, policy) {
8
+ anchor = captureFields(anchor, ["row", "column", "width", "height", "description"]);
9
+ if (!Number.isInteger(anchor.row) || anchor.row < 1 || anchor.row > 1048576 || !Number.isInteger(anchor.column) || anchor.column < 1 || anchor.column > 16384)
10
+ throw new RangeError("Drawing anchors must be one-based worksheet rows and columns.");
11
+ for (const size of [anchor.width, anchor.height])
12
+ if (!Number.isFinite(size) || size <= 0 || size > 100000)
13
+ throw new RangeError("Drawing display dimensions must be positive and at most 100,000 pixels.");
14
+ if (anchor.description !== undefined && typeof anchor.description !== "string")
15
+ throw new TypeError("Drawing description must be a string.");
16
+ return Object.freeze({ row: anchor.row, column: anchor.column, width: anchor.width, height: anchor.height,
17
+ ...(anchor.description === undefined ? {} : { description: cleanXml(anchor.description, policy) }) });
18
+ }
19
+ export function cellPosition(reference) {
20
+ const match = typeof reference === "string" && /^([A-Z]{1,3})([1-9][0-9]{0,6})$/.exec(reference);
21
+ if (!match)
22
+ throw new TypeError("Use a single uppercase A1 cell reference.");
23
+ const row = Number(match[2]);
24
+ let column = 0;
25
+ for (const letter of match[1])
26
+ column = column * 26 + letter.charCodeAt(0) - 64;
27
+ if (column > 16384 || row > 1048576)
28
+ throw new RangeError("Cell reference exceeds Excel's worksheet bounds.");
29
+ return { row, column };
30
+ }
31
+ export function copyHyperlink(link, policy) {
32
+ link = captureFields(link, ["cell", "target", "tooltip"]);
33
+ cellPosition(link.cell);
34
+ const copied = copyExportLink(link);
35
+ return Object.freeze({ cell: link.cell, target: copied.target,
36
+ ...(copied.tooltip === undefined ? {} : { tooltip: cleanXml(copied.tooltip, policy) }) });
37
+ }
38
+ export function copyImage(image, policy, checkBytes) {
39
+ image = captureFields(image, ["data", "row", "column", "width", "height", "description"]);
40
+ if (image.data instanceof Uint8Array)
41
+ checkBytes?.(image.data.length);
42
+ if (!(image.data instanceof Uint8Array) || image.data.length < 33 ||
43
+ ![137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82].every((byte, i) => image.data[i] === byte))
44
+ throw new TypeError("Images require PNG bytes with a valid signature and IHDR header.");
45
+ const header = new DataView(image.data.buffer, image.data.byteOffset, image.data.byteLength);
46
+ if (!header.getUint32(16) || !header.getUint32(20))
47
+ throw new RangeError("PNG dimensions must be positive.");
48
+ return Object.freeze({ ...copyDrawingAnchor(image, policy), data: new Uint8Array(image.data) });
49
+ }
50
+ export function hyperlinksXml(links, policy, internal = []) {
51
+ return '<hyperlinks>' + links.map((link, i) => '<hyperlink ref="' + link.cell + '" r:id="link' + (i + 1) + '"' +
52
+ (link.tooltip === undefined ? "" : ' tooltip="' + escapeOoxmlAttribute(link.tooltip, policy) + '"') + '/>').join("") +
53
+ internal.map(link => '<hyperlink ref="' + link.cell + '" location="' + escapeOoxmlAttribute(link.location, policy) + '"/>').join("") + '</hyperlinks>';
54
+ }
55
+ /** @internal Package drawing serialization does not form part of the worksheet input contract. */
56
+ export function drawingXml(images, policy, charts = []) {
57
+ const ns = "http://schemas.openxmlformats.org/drawingml/2006/";
58
+ return xmlDeclaration + '<xdr:wsDr xmlns:xdr="' + ns + 'spreadsheetDrawing" xmlns:a="' + ns + 'main" xmlns:r="' + officeRelationshipsNamespace + '">' +
59
+ images.map((image, i) => {
60
+ const size = ' cx="' + Math.round(image.width * 9525) + '" cy="' + Math.round(image.height * 9525) + '"';
61
+ return '<xdr:oneCellAnchor><xdr:from><xdr:col>' + (image.column - 1) + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + (image.row - 1) + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>' +
62
+ '<xdr:ext' + size + '/><xdr:pic><xdr:nvPicPr><xdr:cNvPr id="' + (i + 1) + '" name="Image ' + (i + 1) + '" descr="' + escapeXml(image.description ?? "", policy) + '"/><xdr:cNvPicPr/></xdr:nvPicPr>' +
63
+ '<xdr:blipFill><a:blip r:embed="image' + (i + 1) + '"/><a:stretch><a:fillRect/></a:stretch></xdr:blipFill>' +
64
+ '<xdr:spPr><a:xfrm><a:off x="0" y="0"/><a:ext' + size + '/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic><xdr:clientData/></xdr:oneCellAnchor>';
65
+ }).join("") + charts.map((chart, i) => chartAnchorXml(chart, images.length + i + 1, policy)).join("") + '</xdr:wsDr>';
66
+ }
67
+ export const drawingContentType = "application/vnd.openxmlformats-officedocument.drawing+xml";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,122 @@
1
+ import { checkAbort } from "../core/iteration.js";
2
+ import { NotSupportedError, OfficeIMOError } from "../core/errors.js";
3
+ import { cleanXml } from "../xml/index.js";
4
+ import { captureFields } from "../internal/capture.js";
5
+ function record(value, allowed, context) {
6
+ if (!value || typeof value !== "object" || Array.isArray(value))
7
+ throw new TypeError(context + " must be an object.");
8
+ for (const key of Object.keys(value))
9
+ if (!allowed.includes(key))
10
+ throw new NotSupportedError(context + "." + key);
11
+ return captureFields(value, allowed);
12
+ }
13
+ function column(value) {
14
+ if (typeof value === "string" ? !value.length : typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > 16384)
15
+ throw new TypeError("Chart columns require a declared key or a one-based column number.");
16
+ }
17
+ /** @internal Capture each caller property once before resolving workbook identities. */
18
+ export function captureChartRange(input) {
19
+ const value = record(input, ["kind", "sheet", "firstRow", "rowCount", "categoryColumn", "series"], "chart.data");
20
+ if (value.kind !== "range")
21
+ throw new TypeError("A chart range must declare kind: range.");
22
+ if (!value.sheet || typeof value.sheet !== "object" || Array.isArray(value.sheet))
23
+ throw new TypeError("A chart range needs its owning worksheet.");
24
+ const firstRow = value.firstRow === undefined ? 0 : value.firstRow, rowCount = value.rowCount;
25
+ if (!Number.isSafeInteger(firstRow) || firstRow < 0 || !Number.isSafeInteger(rowCount) || rowCount < 1 ||
26
+ firstRow + rowCount > 1048576)
27
+ throw new RangeError("Chart data rows must form a nonempty finite Excel range.");
28
+ column(value.categoryColumn);
29
+ if (!Array.isArray(value.series) || value.series.length < 1 || value.series.length > 255)
30
+ throw new RangeError("A chart needs from 1 through 255 series.");
31
+ const series = value.series.map(item => {
32
+ const copy = record(item, ["column", "name", "color"], "chart.data.series");
33
+ column(copy.column);
34
+ if (copy.name !== undefined && typeof copy.name !== "string")
35
+ throw new TypeError("Chart series name must be a string.");
36
+ if (copy.color !== undefined && (typeof copy.color !== "string" || !/^#?[0-9a-fA-F]{6}$/.test(copy.color)))
37
+ throw new TypeError("Chart colors must be opaque six-digit RGB hex values.");
38
+ return Object.freeze(copy);
39
+ });
40
+ return Object.freeze({ kind: "range", sheet: value.sheet, firstRow, rowCount, categoryColumn: value.categoryColumn, series: Object.freeze(series) });
41
+ }
42
+ /**
43
+ * @internal Retain only the declared finite cache while the owning sheet writes once.
44
+ * Initial series-name text is returned for registration; category text is charged
45
+ * before copying through retainText. The workbook resolves source identity and A1.
46
+ */
47
+ export function prepareChartBinding(input, descriptor, budgets, signal, type = "columnClustered") {
48
+ checkAbort(signal);
49
+ const count = input.rowCount, first = input.firstRow ?? 0, points = count * input.series.length, categoryColumn = descriptor.categoryColumn;
50
+ if (points > budgets.availablePoints)
51
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxChartPoints exceeded.");
52
+ if (descriptor.source !== input.sheet || !Number.isInteger(descriptor.headerRows) || descriptor.headerRows < 0 || descriptor.headerRows + first + count > 1048576 ||
53
+ descriptor.seriesColumns.length !== input.series.length || descriptor.seriesNames.length !== input.series.length ||
54
+ descriptor.valueFormulas.length !== input.series.length || descriptor.nameFormulas.length !== input.series.length)
55
+ throw new TypeError("Resolved chart range does not match its declared columns and data rows.");
56
+ for (const index of [descriptor.categoryColumn, ...descriptor.seriesColumns])
57
+ if (!Number.isInteger(index) || index < 1 || index > 16384)
58
+ throw new RangeError("Resolved chart columns must be one-based Excel columns.");
59
+ if (descriptor.seriesColumns.includes(categoryColumn))
60
+ throw new TypeError("Chart category and numeric series must use different columns.");
61
+ let textCharacters = 0;
62
+ const names = input.series.map((series, i) => {
63
+ const name = series.name ?? descriptor.seriesNames[i];
64
+ if (typeof name !== "string" || name.length > 32767)
65
+ throw new TypeError("Chart series names must fit Excel text cells.");
66
+ textCharacters += name.length;
67
+ if (textCharacters > budgets.availableText)
68
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxChartTextCharacters exceeded.");
69
+ return cleanXml(name, budgets.policy);
70
+ });
71
+ const colors = input.series.map(series => series.color?.replace(/^#/, "").toUpperCase());
72
+ const categories = new Array(count), values = input.series.map(() => new Array(count));
73
+ const captured = input.series.map(() => 0), positive = input.series.map(() => false);
74
+ let categoryCount = 0, completed;
75
+ const finish = () => {
76
+ checkAbort(signal);
77
+ if (completed)
78
+ return;
79
+ if (categoryCount !== count || captured.some(value => value !== count))
80
+ throw new TypeError("Chart range did not receive every declared data row and numeric value.");
81
+ if (type === "pie" && !positive[0])
82
+ throw new RangeError("A pie chart needs at least one positive value.");
83
+ completed = Object.freeze({ categories: Object.freeze(categories), series: Object.freeze(values.map((points, i) => Object.freeze({
84
+ name: names[i], values: Object.freeze(points), ...(colors[i] === undefined ? {} : { color: colors[i] })
85
+ }))) });
86
+ };
87
+ const data = Object.freeze({ get categories() { finish(); return completed.categories; }, get series() { finish(); return completed.series; } });
88
+ const seriesByColumn = new Map();
89
+ descriptor.seriesColumns.forEach((index, i) => { const indexes = seriesByColumn.get(index) ?? []; indexes.push(i); seriesByColumn.set(index, indexes); });
90
+ return Object.freeze({ source: descriptor.source, points, textCharacters, data,
91
+ references: Object.freeze({ categories: descriptor.categoryFormula, values: Object.freeze([...descriptor.valueFormulas]),
92
+ names: Object.freeze(descriptor.nameFormulas.map((formula, i) => input.series[i].name === undefined ? formula : undefined)) }),
93
+ observe(dataRowIndex, columnIndex, value) {
94
+ checkAbort(signal);
95
+ const position = dataRowIndex - first;
96
+ if (position < 0 || position >= count)
97
+ return;
98
+ if (completed)
99
+ throw new OfficeIMOError("INVALID_STATE", "Chart cache is already finalized.");
100
+ if (columnIndex === categoryColumn) {
101
+ if (typeof value !== "string" || value.length > 32767)
102
+ throw new TypeError("Chart category cells must contain strings of at most 32,767 UTF-16 units.");
103
+ if (categories[position] !== undefined)
104
+ throw new OfficeIMOError("INVALID_STATE", "A chart category cell was observed more than once.");
105
+ budgets.retainText(value.length);
106
+ categories[position] = cleanXml(value, budgets.policy);
107
+ categoryCount++;
108
+ }
109
+ for (const i of seriesByColumn.get(columnIndex) ?? []) {
110
+ if (typeof value !== "number" || !Number.isFinite(value))
111
+ throw new TypeError("Chart series cells require finite numbers or numeric formula caches.");
112
+ if (type === "pie" && value < 0)
113
+ throw new RangeError("Pie charts require nonnegative values.");
114
+ if (values[i][position] !== undefined)
115
+ throw new OfficeIMOError("INVALID_STATE", "A chart value cell was observed more than once.");
116
+ values[i][position] = value;
117
+ captured[i] = captured[i] + 1;
118
+ if (value > 0)
119
+ positive[i] = true;
120
+ }
121
+ }, finish });
122
+ }
@@ -0,0 +1,73 @@
1
+ import type { WorksheetAnchor } from "./attachments.js";
2
+ import type { Worksheet } from "./worksheet.js";
3
+ /** Native, editable Excel chart families. Names follow OfficeIMO's shared chart vocabulary. */
4
+ export type ChartType = "columnClustered" | "barClustered" | "line" | "pie";
5
+ /** Values align with the categories. Strings, missing points and nonfinite values are rejected. */
6
+ export interface ChartSeries {
7
+ readonly name: string;
8
+ readonly values: readonly number[];
9
+ /** Opaque RGB color, with or without a leading #. Excel supplies its palette when omitted. */
10
+ readonly color?: string;
11
+ }
12
+ /** An independent snapshot; the workbook writes its editable source cells on a hidden data sheet. */
13
+ export interface ChartData {
14
+ readonly categories: readonly string[];
15
+ readonly series: readonly ChartSeries[];
16
+ }
17
+ /** A declared column key or a one-based worksheet column number. */
18
+ export type ChartColumn = string | number;
19
+ /** One numeric series read from the visible worksheet during its ordinary writer pass. */
20
+ export interface ChartRangeSeries {
21
+ readonly column: ChartColumn;
22
+ /** Uses the declared column heading when omitted. */
23
+ readonly name?: string;
24
+ readonly color?: string;
25
+ }
26
+ /**
27
+ * A finite vertical range in a visible worksheet of this workbook. Register the chart
28
+ * before the first selected data row is written. Data-row offsets exclude report
29
+ * titles, headings and footers; numeric series require finite numbers or numeric
30
+ * formula caches, and category cells require strings.
31
+ */
32
+ export interface ChartRangeData {
33
+ readonly kind: "range";
34
+ readonly sheet: Worksheet;
35
+ /** Zero-based offset into the worksheet's data rows; defaults to zero. */
36
+ readonly firstRow?: number;
37
+ readonly rowCount: number;
38
+ readonly categoryColumn: ChartColumn;
39
+ readonly series: readonly ChartRangeSeries[];
40
+ }
41
+ /** Labels are native Excel labels and remain editable after export. */
42
+ export interface ChartDataLabels {
43
+ readonly showValue?: boolean;
44
+ readonly showCategoryName?: boolean;
45
+ readonly showSeriesName?: boolean;
46
+ /** Percent labels are supported only by pie charts. */
47
+ readonly showPercent?: boolean;
48
+ readonly position?: "center" | "insideEnd" | "outsideEnd" | "bestFit" | "above" | "below" | "left" | "right";
49
+ readonly numberFormat?: string;
50
+ }
51
+ export interface ChartCategoryAxis {
52
+ readonly title?: string;
53
+ }
54
+ export interface ChartValueAxis {
55
+ readonly title?: string;
56
+ readonly minimum?: number;
57
+ readonly maximum?: number;
58
+ readonly numberFormat?: string;
59
+ }
60
+ /** A native chart placed in worksheet coordinates, separate from PNG or portable drawing rendering. */
61
+ export interface WorksheetChart extends WorksheetAnchor {
62
+ readonly type: ChartType;
63
+ readonly data: ChartData | ChartRangeData;
64
+ /** Optional language metadata, for example pl-PL. Omitted metadata leaves the choice to Excel. */
65
+ readonly language?: string;
66
+ readonly title?: string;
67
+ /** The legend is on the right by default. */
68
+ readonly legend?: "right" | "bottom" | "left" | "top" | false;
69
+ readonly dataLabels?: ChartDataLabels;
70
+ /** Pie charts have no axes and reject axis options. */
71
+ readonly categoryAxis?: ChartCategoryAxis;
72
+ readonly valueAxis?: ChartValueAxis;
73
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const chartNamespace = "http://schemas.openxmlformats.org/drawingml/2006/chart";
2
+ export declare const chartContentType = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml";
@@ -0,0 +1,103 @@
1
+ import { ChunkedTextSink } from "../core/sinks.js";
2
+ import { escapeXml, xmlDeclaration } from "../xml/index.js";
3
+ import { officeRelationshipsNamespace } from "../opc/index.js";
4
+ import { columnName } from "./values.js";
5
+ export const chartNamespace = "http://schemas.openxmlformats.org/drawingml/2006/chart";
6
+ export const chartContentType = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml";
7
+ /** @internal Graphic frames share a drawing with worksheet images; their nonvisual IDs must be unique. */
8
+ export function chartAnchorXml(chart, objectId, policy) {
9
+ const size = ' cx="' + Math.round(chart.width * 9525) + '" cy="' + Math.round(chart.height * 9525) + '"';
10
+ return '<xdr:oneCellAnchor><xdr:from><xdr:col>' + (chart.column - 1) + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + (chart.row - 1) + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>' +
11
+ '<xdr:ext' + size + '/><xdr:graphicFrame macro=""><xdr:nvGraphicFramePr><xdr:cNvPr id="' + objectId + '" name="Chart ' + chart.id + '" descr="' + escapeXml(chart.description ?? chart.title ?? "", policy) + '"/>' +
12
+ '<xdr:cNvGraphicFramePr/></xdr:nvGraphicFramePr><xdr:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></xdr:xfrm><a:graphic><a:graphicData uri="' + chartNamespace + '">' +
13
+ '<c:chart xmlns:c="' + chartNamespace + '" r:id="chart' + chart.id + '"/></a:graphicData></a:graphic></xdr:graphicFrame><xdr:clientData/></xdr:oneCellAnchor>';
14
+ }
15
+ function titleXml(value, policy) {
16
+ return '<c:title><c:tx><c:rich><a:bodyPr/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:r><a:t xml:space="preserve">' +
17
+ escapeXml(value, policy) + '</a:t></a:r></a:p></c:rich></c:tx><c:overlay val="0"/></c:title>';
18
+ }
19
+ function* reference(kind, formula, values, policy) {
20
+ yield '<c:' + kind + 'Ref><c:f>' + escapeXml(formula, policy) + '</c:f><c:' + kind + 'Cache>';
21
+ if (kind === "num")
22
+ yield '<c:formatCode>General</c:formatCode>';
23
+ yield '<c:ptCount val="' + values.length + '"/>';
24
+ for (let i = 0; i < values.length; i++)
25
+ yield '<c:pt idx="' + i + '"><c:v xml:space="preserve">' + escapeXml(String(values[i]), policy) + '</c:v></c:pt>';
26
+ yield '</c:' + kind + 'Cache></c:' + kind + 'Ref>';
27
+ }
28
+ function labelsXml(chart, policy) {
29
+ const labels = chart.dataLabels;
30
+ if (!labels)
31
+ return "";
32
+ const positions = { center: "ctr", insideEnd: "inEnd", outsideEnd: "outEnd", bestFit: "bestFit", above: "t", below: "b", left: "l", right: "r" };
33
+ return '<c:dLbls>' + (labels.numberFormat === undefined ? "" : '<c:numFmt formatCode="' + escapeXml(labels.numberFormat, policy) + '" sourceLinked="0"/>') +
34
+ (labels.position === undefined ? "" : '<c:dLblPos val="' + positions[labels.position] + '"/>') + '<c:showLegendKey val="0"/><c:showVal val="' + (labels.showValue === false ? 0 : 1) +
35
+ '"/><c:showCatName val="' + (labels.showCategoryName ? 1 : 0) + '"/><c:showSerName val="' + (labels.showSeriesName ? 1 : 0) +
36
+ '"/><c:showPercent val="' + (labels.showPercent ? 1 : 0) + '"/><c:showBubbleSize val="0"/></c:dLbls>';
37
+ }
38
+ function axesXml(chart, policy) {
39
+ const horizontal = chart.type === "barClustered", value = chart.valueAxis;
40
+ const scaling = '<c:scaling><c:orientation val="minMax"/>' + (value?.maximum === undefined ? "" : '<c:max val="' + value.maximum + '"/>') +
41
+ (value?.minimum === undefined ? "" : '<c:min val="' + value.minimum + '"/>') + '</c:scaling>';
42
+ const ticks = '<c:majorTickMark val="none"/><c:minorTickMark val="none"/><c:tickLblPos val="nextTo"/>';
43
+ return '<c:catAx><c:axId val="1"/><c:scaling><c:orientation val="minMax"/></c:scaling><c:delete val="0"/><c:axPos val="' + (horizontal ? "l" : "b") + '"/>' +
44
+ (chart.categoryAxis?.title ? titleXml(chart.categoryAxis.title, policy) : "") + '<c:numFmt formatCode="General" sourceLinked="1"/>' + ticks +
45
+ '<c:crossAx val="2"/><c:crosses val="autoZero"/><c:auto val="1"/><c:lblAlgn val="ctr"/><c:lblOffset val="100"/><c:noMultiLvlLbl val="0"/></c:catAx>' +
46
+ '<c:valAx><c:axId val="2"/>' + scaling + '<c:delete val="0"/><c:axPos val="' + (horizontal ? "b" : "l") + '"/><c:majorGridlines/>' +
47
+ (value?.title ? titleXml(value.title, policy) : "") + '<c:numFmt formatCode="' + escapeXml(value?.numberFormat ?? "General", policy) + '" sourceLinked="' + (value?.numberFormat === undefined ? 1 : 0) + '"/>' + ticks +
48
+ '<c:crossAx val="1"/><c:crosses val="autoZero"/><c:crossBetween val="between"/></c:valAx>';
49
+ }
50
+ function* chartXml(chart, policy) {
51
+ const pie = chart.type === "pie", line = chart.type === "line", tag = pie ? "pieChart" : line ? "lineChart" : "barChart";
52
+ const source = "'" + chart.dataSheetName.replace(/'/g, "''") + "'!", end = chart.data.categories.length + 1;
53
+ yield xmlDeclaration + '<c:chartSpace xmlns:c="' + chartNamespace + '" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="' + officeRelationshipsNamespace + '"><c:date1904 val="0"/>' +
54
+ (chart.language === undefined ? "" : '<c:lang val="' + escapeXml(chart.language, policy) + '"/>') + '<c:chart>';
55
+ if (chart.title)
56
+ yield titleXml(chart.title, policy);
57
+ yield '<c:autoTitleDeleted val="' + (chart.title ? 0 : 1) + '"/><c:plotArea><c:layout/><c:' + tag + '>';
58
+ if (!pie)
59
+ yield line ? '<c:grouping val="standard"/>' : '<c:barDir val="' + (chart.type === "barClustered" ? "bar" : "col") + '"/><c:grouping val="clustered"/>';
60
+ yield '<c:varyColors val="' + (pie ? 1 : 0) + '"/>';
61
+ for (let i = 0; i < chart.data.series.length; i++) {
62
+ const series = chart.data.series[i], column = "$" + columnName(i + 2);
63
+ yield '<c:ser><c:idx val="' + i + '"/><c:order val="' + i + '"/><c:tx>';
64
+ const nameFormula = chart.binding ? chart.binding.references.names[i] : source + column + "$1";
65
+ if (nameFormula === undefined)
66
+ yield '<c:v>' + escapeXml(series.name, policy) + '</c:v>';
67
+ else
68
+ yield* reference("str", nameFormula, [series.name], policy);
69
+ yield '</c:tx>';
70
+ if (series.color)
71
+ yield '<c:spPr>' + (line ? '<a:ln w="25400">' : "") + '<a:solidFill><a:srgbClr val="' + series.color + '"/></a:solidFill>' + (line ? '</a:ln>' : "") + '</c:spPr>';
72
+ if (!line && !pie)
73
+ yield '<c:invertIfNegative val="0"/>';
74
+ yield '<c:cat>';
75
+ yield* reference("str", chart.binding?.references.categories ?? source + '$A$2:$A$' + end, chart.data.categories, policy);
76
+ yield '</c:cat><c:val>';
77
+ yield* reference("num", chart.binding?.references.values[i] ?? source + column + "$2:" + column + "$" + end, series.values, policy);
78
+ yield '</c:val>' + (line ? '<c:smooth val="0"/>' : "") + '</c:ser>';
79
+ }
80
+ yield labelsXml(chart, policy);
81
+ if (!pie && !line)
82
+ yield '<c:gapWidth val="150"/><c:overlap val="0"/>';
83
+ if (!pie)
84
+ yield '<c:axId val="1"/><c:axId val="2"/>';
85
+ yield '</c:' + tag + '>';
86
+ if (!pie)
87
+ yield axesXml(chart, policy);
88
+ yield '</c:plotArea>';
89
+ if (chart.legend !== false) {
90
+ const position = { right: "r", bottom: "b", left: "l", top: "t" }[chart.legend ?? "right"];
91
+ yield '<c:legend><c:legendPos val="' + position + '"/><c:layout/><c:overlay val="0"/></c:legend>';
92
+ }
93
+ // Snapshot data sheets are hidden; bound sources remain visible and respect native visibility.
94
+ yield '<c:plotVisOnly val="' + (chart.binding ? 1 : 0) + '"/><c:dispBlanksAs val="gap"/><c:showDLblsOverMax val="0"/></c:chart></c:chartSpace>';
95
+ }
96
+ /** @internal Stream cache points through the existing bounded, cancellation-aware XML sink. */
97
+ export async function writeChartXml(chart, destination, policy, signal) {
98
+ const text = new ChunkedTextSink(destination, signal);
99
+ for (const fragment of chartXml(chart, policy))
100
+ if (text.append(fragment))
101
+ await text.flush();
102
+ await text.close();
103
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,159 @@
1
+ import { checkAbort } from "../core/iteration.js";
2
+ import { NotSupportedError, OfficeIMOError } from "../core/errors.js";
3
+ import { cleanXml } from "../xml/index.js";
4
+ import { copyDrawingAnchor } from "./attachments.js";
5
+ import { captureFields } from "../internal/capture.js";
6
+ import { captureChartRange, prepareChartBinding } from "./chart-bindings.js";
7
+ function fields(value, allowed, context) {
8
+ if (!value || typeof value !== "object" || Array.isArray(value))
9
+ throw new TypeError(context + " must be an object.");
10
+ for (const key of Object.keys(value))
11
+ if (!allowed.includes(key))
12
+ throw new NotSupportedError(context + "." + key);
13
+ }
14
+ function snapshot(value, allowed, context) {
15
+ fields(value, allowed, context);
16
+ return captureFields(value, allowed);
17
+ }
18
+ /** @internal Preflight bounds before copying any chart data. Failed registration reserves nothing. */
19
+ export function prepareChart(input, policy, availablePoints, availableText, signal, resolveBinding) {
20
+ checkAbort(signal);
21
+ input = snapshot(input, ["type", "data", "row", "column", "width", "height", "description", "title", "language", "legend", "dataLabels", "categoryAxis", "valueAxis"], "chart");
22
+ if (!["columnClustered", "barClustered", "line", "pie"].includes(input.type))
23
+ throw new NotSupportedError("chart type " + input.type);
24
+ const type = input.type;
25
+ const requested = snapshot(input.data, ["kind", "sheet", "firstRow", "rowCount", "categoryColumn", "categories", "series"], "chart.data");
26
+ const bound = requested.kind === "range" ? captureChartRange(requested) : undefined;
27
+ if (!bound)
28
+ fields(requested, ["categories", "series"], "chart.data");
29
+ const categories = bound ? undefined : requested.categories, series = bound?.series ?? requested.series;
30
+ if (!bound && !Array.isArray(categories))
31
+ throw new TypeError("Chart categories must be a nonempty array of strings.");
32
+ if (!Array.isArray(series))
33
+ throw new RangeError("A chart needs from 1 through 255 series.");
34
+ const categoryCount = bound?.rowCount ?? categories.length, seriesCount = series.length;
35
+ if (!categoryCount)
36
+ throw new TypeError("Chart categories must be a nonempty array of strings.");
37
+ if (!seriesCount || seriesCount > 255)
38
+ throw new RangeError("A chart needs from 1 through 255 series.");
39
+ if (!bound && categoryCount > 1048575)
40
+ throw new RangeError("Chart data must fit Excel's rows including its header.");
41
+ if (type === "pie" && seriesCount !== 1)
42
+ throw new TypeError("A pie chart supports exactly one series.");
43
+ const points = categoryCount * seriesCount;
44
+ if (points > availablePoints)
45
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxChartPoints exceeded.");
46
+ let textCharacters = 0;
47
+ const text = (value, context) => {
48
+ if (typeof value !== "string")
49
+ throw new TypeError(context + " must be a string.");
50
+ if (value.length > 32767)
51
+ throw new RangeError(context + " exceeds 32,767 UTF-16 units.");
52
+ textCharacters += value.length;
53
+ if (textCharacters > availableText)
54
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxChartTextCharacters exceeded.");
55
+ return cleanXml(value, policy);
56
+ };
57
+ const optionalText = (value, context) => value === undefined ? undefined : text(value, context);
58
+ const title = optionalText(input.title, "Chart title"), description = optionalText(input.description, "Chart description");
59
+ const requestedLanguage = optionalText(input.language, "Chart language");
60
+ let language;
61
+ if (requestedLanguage !== undefined) {
62
+ try {
63
+ language = Intl.getCanonicalLocales(requestedLanguage)[0];
64
+ if (!language)
65
+ throw new RangeError();
66
+ }
67
+ catch {
68
+ throw new TypeError("Chart language must be a language tag such as pl or pl-PL.");
69
+ }
70
+ }
71
+ const anchor = copyDrawingAnchor({ row: input.row, column: input.column, width: input.width, height: input.height,
72
+ ...(description === undefined ? {} : { description }) }, policy);
73
+ if (input.legend !== undefined && input.legend !== false && !["right", "bottom", "left", "top"].includes(input.legend))
74
+ throw new TypeError("Unsupported chart legend position.");
75
+ let dataLabels;
76
+ if (input.dataLabels !== undefined) {
77
+ const labels = snapshot(input.dataLabels, ["showValue", "showCategoryName", "showSeriesName", "showPercent", "position", "numberFormat"], "chart.dataLabels");
78
+ for (const key of ["showValue", "showCategoryName", "showSeriesName", "showPercent"])
79
+ if (labels[key] !== undefined && typeof labels[key] !== "boolean")
80
+ throw new TypeError("Chart label flags must be booleans.");
81
+ if (labels.showPercent && type !== "pie")
82
+ throw new TypeError("Percent data labels require a pie chart.");
83
+ const positions = type === "pie" ? ["center", "insideEnd", "outsideEnd", "bestFit"] : type === "line" ? ["center", "above", "below", "left", "right"] : ["center", "insideEnd", "outsideEnd"];
84
+ if (labels.position !== undefined && !positions.includes(labels.position))
85
+ throw new TypeError("Data label position is unsupported for this chart type.");
86
+ const numberFormat = optionalText(labels.numberFormat, "Data label number format");
87
+ if (numberFormat !== undefined && !numberFormat.trim())
88
+ throw new TypeError("Data label number format cannot be blank.");
89
+ dataLabels = Object.freeze({ ...labels, ...(numberFormat === undefined ? {} : { numberFormat }) });
90
+ }
91
+ if (type === "pie" && (input.categoryAxis !== undefined || input.valueAxis !== undefined))
92
+ throw new TypeError("Pie charts have no axes.");
93
+ let categoryAxis, valueAxis;
94
+ if (input.categoryAxis !== undefined) {
95
+ const axisTitle = optionalText(snapshot(input.categoryAxis, ["title"], "chart.categoryAxis").title, "Category axis title");
96
+ categoryAxis = Object.freeze(axisTitle === undefined ? {} : { title: axisTitle });
97
+ }
98
+ if (input.valueAxis !== undefined) {
99
+ const axis = snapshot(input.valueAxis, ["title", "minimum", "maximum", "numberFormat"], "chart.valueAxis");
100
+ for (const value of [axis.minimum, axis.maximum])
101
+ if (value !== undefined && !Number.isFinite(value))
102
+ throw new TypeError("Chart axis bounds must be finite numbers.");
103
+ if (axis.minimum !== undefined && axis.maximum !== undefined && axis.minimum >= axis.maximum)
104
+ throw new RangeError("Chart axis minimum must be below its maximum.");
105
+ const axisTitle = optionalText(axis.title, "Value axis title"), numberFormat = optionalText(axis.numberFormat, "Value axis number format");
106
+ if (numberFormat !== undefined && !numberFormat.trim())
107
+ throw new TypeError("Value axis number format cannot be blank.");
108
+ valueAxis = Object.freeze({ ...axis, ...(axisTitle === undefined ? {} : { title: axisTitle }), ...(numberFormat === undefined ? {} : { numberFormat }) });
109
+ }
110
+ const common = { ...anchor, type,
111
+ ...(language === undefined ? {} : { language }),
112
+ ...(title === undefined ? {} : { title }), ...(description === undefined ? {} : { description }),
113
+ ...(input.legend === undefined ? {} : { legend: input.legend }), ...(dataLabels === undefined ? {} : { dataLabels }),
114
+ ...(categoryAxis === undefined ? {} : { categoryAxis }), ...(valueAxis === undefined ? {} : { valueAxis }) };
115
+ if (bound) {
116
+ if (!resolveBinding)
117
+ throw new TypeError("A chart range must belong to the current workbook.");
118
+ const { descriptor, retainText } = resolveBinding(bound);
119
+ const binding = prepareChartBinding(bound, descriptor, { availablePoints, availableText: availableText - textCharacters, retainText, policy }, signal, type);
120
+ return Object.freeze({ ...common, data: binding.data, binding, points, textCharacters: textCharacters + binding.textCharacters });
121
+ }
122
+ // Length budgets precede allocation; each source property/array element is read once.
123
+ const categoryValues = categories;
124
+ const copiedCategories = [], copiedSeries = [];
125
+ for (let i = 0; i < categoryCount; i++) {
126
+ if ((i & 255) === 0)
127
+ checkAbort(signal);
128
+ copiedCategories.push(text(categoryValues[i], "Chart category"));
129
+ }
130
+ for (let seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) {
131
+ const item = series[seriesIndex];
132
+ const captured = snapshot(item, ["name", "values", "color"], "chart.series");
133
+ const name = text(captured.name, "Chart series name"), values = captured.values, color = captured.color;
134
+ if (!Array.isArray(values) || values.length !== categoryCount)
135
+ throw new TypeError("Chart series values must match the category count.");
136
+ if (color !== undefined && (typeof color !== "string" || !/^#?[0-9a-fA-F]{6}$/.test(color)))
137
+ throw new TypeError("Chart colors must be opaque six-digit RGB hex values.");
138
+ let positive = false;
139
+ const copiedValues = [];
140
+ for (let i = 0; i < categoryCount; i++) {
141
+ if ((i & 255) === 0)
142
+ checkAbort(signal);
143
+ const value = values[i];
144
+ if (typeof value !== "number" || !Number.isFinite(value))
145
+ throw new TypeError("Chart values must be finite numbers.");
146
+ if (type === "pie" && value < 0)
147
+ throw new RangeError("Pie charts require nonnegative values.");
148
+ if (value > 0)
149
+ positive = true;
150
+ copiedValues.push(value);
151
+ }
152
+ if (type === "pie" && !positive)
153
+ throw new RangeError("A pie chart needs at least one positive value.");
154
+ copiedSeries.push(Object.freeze({ name, values: Object.freeze(copiedValues), ...(color === undefined ? {} : { color: color.replace(/^#/, "").toUpperCase() }) }));
155
+ }
156
+ return Object.freeze({ ...common,
157
+ data: Object.freeze({ categories: Object.freeze(copiedCategories), series: Object.freeze(copiedSeries) }),
158
+ points, textCharacters });
159
+ }
@@ -0,0 +1 @@
1
+ export {};