@evotecit/officeimo 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1222 -2
  3. package/bundles/officeimo-canopyx.js +11741 -0
  4. package/bundles/officeimo-canopyx.mjs +11639 -0
  5. package/bundles/officeimo-csv.js +1264 -0
  6. package/bundles/officeimo-csv.mjs +1239 -0
  7. package/bundles/officeimo-datatables.js +12018 -0
  8. package/bundles/officeimo-datatables.mjs +11915 -0
  9. package/bundles/officeimo-execution.js +1513 -0
  10. package/bundles/officeimo-execution.mjs +1489 -0
  11. package/bundles/officeimo-pdf.js +7009 -0
  12. package/bundles/officeimo-pdf.mjs +6946 -0
  13. package/bundles/officeimo-xlsx.js +5344 -0
  14. package/bundles/officeimo-xlsx.mjs +5290 -0
  15. package/bundles/officeimo.js +11468 -0
  16. package/bundles/officeimo.mjs +11369 -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 +74 -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 +102 -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 +122 -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 +77 -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 +244 -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 +202 -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 +183 -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 +320 -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 +678 -0
  145. package/dist/pdf/paragraph-layout.d.ts +21 -0
  146. package/dist/pdf/paragraph-layout.js +71 -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 +17 -0
  164. package/dist/pdf/settings.js +196 -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 +302 -0
  173. package/dist/pdf/table-band-flow.d.ts +34 -0
  174. package/dist/pdf/table-band-flow.js +129 -0
  175. package/dist/pdf/table-band-plan.d.ts +10 -0
  176. package/dist/pdf/table-band-plan.js +83 -0
  177. package/dist/pdf/table-layout.d.ts +75 -0
  178. package/dist/pdf/table-layout.js +217 -0
  179. package/dist/pdf/table-structure.d.ts +1 -0
  180. package/dist/pdf/table-structure.js +108 -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 +101 -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 +171 -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/pdf/xref.d.ts +1 -0
  194. package/dist/pdf/xref.js +30 -0
  195. package/dist/xlsx/attachments.d.ts +30 -0
  196. package/dist/xlsx/attachments.js +67 -0
  197. package/dist/xlsx/chart-bindings.d.ts +1 -0
  198. package/dist/xlsx/chart-bindings.js +122 -0
  199. package/dist/xlsx/chart-types.d.ts +73 -0
  200. package/dist/xlsx/chart-types.js +1 -0
  201. package/dist/xlsx/chart-xml.d.ts +2 -0
  202. package/dist/xlsx/chart-xml.js +103 -0
  203. package/dist/xlsx/charts.d.ts +1 -0
  204. package/dist/xlsx/charts.js +159 -0
  205. package/dist/xlsx/conditional-formatting.d.ts +1 -0
  206. package/dist/xlsx/conditional-formatting.js +158 -0
  207. package/dist/xlsx/conditional-types.d.ts +64 -0
  208. package/dist/xlsx/conditional-types.js +1 -0
  209. package/dist/xlsx/data-row-ranges.d.ts +5 -0
  210. package/dist/xlsx/data-row-ranges.js +39 -0
  211. package/dist/xlsx/differential-styles.d.ts +1 -0
  212. package/dist/xlsx/differential-styles.js +102 -0
  213. package/dist/xlsx/formula.d.ts +8 -0
  214. package/dist/xlsx/formula.js +104 -0
  215. package/dist/xlsx/grouped-layout.d.ts +61 -0
  216. package/dist/xlsx/grouped-layout.js +79 -0
  217. package/dist/xlsx/grouped.d.ts +16 -0
  218. package/dist/xlsx/grouped.js +161 -0
  219. package/dist/xlsx/index.d.ts +24 -0
  220. package/dist/xlsx/index.js +10 -0
  221. package/dist/xlsx/layout.d.ts +1 -0
  222. package/dist/xlsx/layout.js +186 -0
  223. package/dist/xlsx/options.d.ts +1 -0
  224. package/dist/xlsx/options.js +16 -0
  225. package/dist/xlsx/portable.d.ts +27 -0
  226. package/dist/xlsx/portable.js +44 -0
  227. package/dist/xlsx/preservation.d.ts +1 -0
  228. package/dist/xlsx/preservation.js +60 -0
  229. package/dist/xlsx/ranges.d.ts +1 -0
  230. package/dist/xlsx/ranges.js +24 -0
  231. package/dist/xlsx/regions.d.ts +1 -0
  232. package/dist/xlsx/regions.js +97 -0
  233. package/dist/xlsx/structured-rows.d.ts +11 -0
  234. package/dist/xlsx/structured-rows.js +28 -0
  235. package/dist/xlsx/style-xml.d.ts +1 -0
  236. package/dist/xlsx/style-xml.js +6 -0
  237. package/dist/xlsx/styles.d.ts +70 -0
  238. package/dist/xlsx/styles.js +203 -0
  239. package/dist/xlsx/table.d.ts +12 -0
  240. package/dist/xlsx/table.js +35 -0
  241. package/dist/xlsx/types.d.ts +180 -0
  242. package/dist/xlsx/types.js +1 -0
  243. package/dist/xlsx/validation-types.d.ts +18 -0
  244. package/dist/xlsx/validation-types.js +1 -0
  245. package/dist/xlsx/validation.d.ts +1 -0
  246. package/dist/xlsx/validation.js +92 -0
  247. package/dist/xlsx/values.d.ts +13 -0
  248. package/dist/xlsx/values.js +87 -0
  249. package/dist/xlsx/workbook.d.ts +50 -0
  250. package/dist/xlsx/workbook.js +452 -0
  251. package/dist/xlsx/worksheet.d.ts +71 -0
  252. package/dist/xlsx/worksheet.js +700 -0
  253. package/dist/xlsx/write.d.ts +15 -0
  254. package/dist/xlsx/write.js +47 -0
  255. package/dist/xml/index.d.ts +24 -0
  256. package/dist/xml/index.js +74 -0
  257. package/dist/zip/entry.d.ts +39 -0
  258. package/dist/zip/entry.js +122 -0
  259. package/dist/zip/index.d.ts +44 -0
  260. package/dist/zip/index.js +248 -0
  261. package/package.json +104 -4
@@ -0,0 +1,125 @@
1
+ import { NotSupportedError, OfficeIMOError } from "../core/errors.js";
2
+ import { checkAbort, pause, taskYieldDue } from "../core/iteration.js";
3
+ import { pngPixels } from "./png.js";
4
+ /** Shared document image resources; source objects are captured on first consumption. */
5
+ export class PdfDocumentImages {
6
+ objects;
7
+ settings;
8
+ images = new Map();
9
+ bytes = 0;
10
+ constructor(objects, settings) {
11
+ this.objects = objects;
12
+ this.settings = settings;
13
+ }
14
+ async prepare(image) {
15
+ const existing = this.images.get(image);
16
+ if (existing)
17
+ return existing;
18
+ const { limits, options } = this.settings;
19
+ if (!image || typeof image !== "object")
20
+ throw new TypeError("PDF images require a byte array.");
21
+ const data = image.data, format = image.format;
22
+ if (!(data instanceof Uint8Array))
23
+ throw new TypeError("PDF images require a byte array.");
24
+ const byteLength = data.length;
25
+ if (this.bytes + byteLength > limits.maxImageBytes)
26
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageBytes exceeded.");
27
+ let width, height, components, decoded, decodedAlpha;
28
+ const maximumWorkingBytes = limits.maxImageWorkingBytes;
29
+ if (format === "png")
30
+ ({ width, height, components, data: decoded, alpha: decodedAlpha } = await pngPixels(data, limits.maxImagePixels, options.signal, maximumWorkingBytes));
31
+ else if (format === "jpeg")
32
+ ({ width, height, components } = jpegSize(data));
33
+ else if (format === "rgb" || format === "rgba") {
34
+ ({ width, height } = image);
35
+ components = format === "rgba" ? 4 : 3;
36
+ }
37
+ else
38
+ throw new NotSupportedError("PDF images support unprofiled PNG/JPEG or decoded RGB/RGBA pixels.");
39
+ if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 1 || height < 1 ||
40
+ !Number.isSafeInteger(width * height) || width * height > limits.maxImagePixels)
41
+ throw new OfficeIMOError("RESOURCE_LIMIT", "Image dimensions must be positive integers within maxImagePixels.");
42
+ if ((format === "rgb" || format === "rgba") && byteLength !== width * height * components)
43
+ throw new RangeError("Raw image bytes must match width × height × channels exactly.");
44
+ if (format !== "png" && maximumWorkingBytes !== undefined && byteLength + (components === 4 ? width * height : 0) > maximumWorkingBytes)
45
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageWorkingBytes exceeded by image snapshot and alpha plane.");
46
+ checkAbort(options.signal);
47
+ const id = this.objects.reserve(), name = "Image" + (this.images.size + 1);
48
+ this.bytes += byteLength;
49
+ const captured = decoded ?? new Uint8Array(data);
50
+ let pixels = captured, alpha = decodedAlpha, mask;
51
+ if (components === 4) {
52
+ // Compact the owned RGBA snapshot in place. Forward writes never overwrite unread channels.
53
+ pixels = captured.subarray(0, width * height * 3);
54
+ alpha = new Uint8Array(width * height);
55
+ for (let p = 0; p < alpha.length; p++) {
56
+ pixels[p * 3] = captured[p * 4];
57
+ pixels[p * 3 + 1] = captured[p * 4 + 1];
58
+ pixels[p * 3 + 2] = captured[p * 4 + 2];
59
+ alpha[p] = captured[p * 4 + 3];
60
+ if ((p & 16383) === 16383) {
61
+ if (taskYieldDue())
62
+ await pause();
63
+ checkAbort(options.signal);
64
+ }
65
+ }
66
+ }
67
+ if (alpha) {
68
+ mask = this.objects.reserve();
69
+ await this.objects.stream(mask, alpha, "/Type /XObject /Subtype /Image /Width " + width + " /Height " + height + " /ColorSpace /DeviceGray /BitsPerComponent 8", options.compression !== false, true);
70
+ }
71
+ const dictionary = "/Type /XObject /Subtype /Image /Width " + width + " /Height " + height + " /ColorSpace /" +
72
+ (components === 1 ? "DeviceGray" : "DeviceRGB") + " /BitsPerComponent 8" + (mask ? " /SMask " + mask + " 0 R" : "") +
73
+ (format === "jpeg" ? " /Filter /DCTDecode" : "");
74
+ await this.objects.stream(id, pixels, dictionary, format === "jpeg" ? false : options.compression !== false, true);
75
+ const resource = { name, id, width, height };
76
+ this.images.set(image, resource);
77
+ return resource;
78
+ }
79
+ }
80
+ /** Inspect bounded JPEG headers; JPEG entropy decoding remains the independent reader's job. */
81
+ function jpegSize(bytes) {
82
+ if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216 || bytes[bytes.length - 2] !== 255 || bytes[bytes.length - 1] !== 217)
83
+ throw new TypeError("JPEG images need complete SOI/EOI markers.");
84
+ let result;
85
+ for (let p = 2; p < bytes.length;) {
86
+ if (bytes[p++] !== 255)
87
+ throw new TypeError("Invalid JPEG marker.");
88
+ while (bytes[p] === 255)
89
+ p++;
90
+ const marker = bytes[p++];
91
+ if (marker === 218) {
92
+ if (!result)
93
+ throw new TypeError("JPEG scan precedes its frame header.");
94
+ return result;
95
+ }
96
+ if (marker === 217)
97
+ break;
98
+ if (p + 2 > bytes.length)
99
+ throw new TypeError("Truncated JPEG segment.");
100
+ const length = bytes[p] * 256 + bytes[p + 1], end = p + length;
101
+ if (length < 2 || end > bytes.length)
102
+ throw new TypeError("Truncated JPEG segment.");
103
+ if (marker === 226 && length >= 14 && String.fromCharCode(...bytes.subarray(p + 2, p + 14)) === "ICC_PROFILE\0")
104
+ throw new NotSupportedError("Normalize ICC-profiled JPEG colors before PDF embedding.");
105
+ if (marker === 225 && length >= 8 && String.fromCharCode(...bytes.subarray(p + 2, p + 8)) === "Exif\0\0")
106
+ throw new NotSupportedError("Normalize JPEG EXIF orientation before PDF embedding.");
107
+ if (marker >= 192 && marker <= 207 && ![196, 200, 204].includes(marker)) {
108
+ if (![192, 193, 194].includes(marker) || length < 8 || bytes[p + 2] !== 8)
109
+ throw new NotSupportedError("PDF JPEG images require 8-bit baseline, sequential or progressive frames.");
110
+ const components = bytes[p + 7];
111
+ if (![1, 3].includes(components) || length !== 8 + components * 3)
112
+ throw new NotSupportedError("PDF JPEG images require grayscale or RGB components; CMYK is unsupported.");
113
+ if (components === 3) {
114
+ const ids = [bytes[p + 8], bytes[p + 11], bytes[p + 14]].join(",");
115
+ if (ids !== "1,2,3" && ids !== "82,71,66")
116
+ throw new NotSupportedError("Unsupported JPEG component color layout.");
117
+ }
118
+ if (result)
119
+ throw new NotSupportedError("Multiple JPEG frame headers are unsupported.");
120
+ result = { width: bytes[p + 5] * 256 + bytes[p + 6], height: bytes[p + 3] * 256 + bytes[p + 4], components };
121
+ }
122
+ p = end;
123
+ }
124
+ throw new TypeError("JPEG image has no complete frame and scan.");
125
+ }
@@ -0,0 +1,160 @@
1
+ import type { CellPresentation } from "../core/index.js";
2
+ import type { PdfOptions } from "./types.js";
3
+ import type { PdfDrawingBlock } from "./drawing-types.js";
4
+ import type { PdfText } from "./inline-types.js";
5
+ import type { PdfBookmark, PdfSectionBlock } from "./section-types.js";
6
+ import type { GroupedReportSource } from "../core/grouped-report.js";
7
+ import type { GroupedPdfTableOptions } from "./grouped-types.js";
8
+ /** Page geometry, fonts, decorations and resource policy shared by every document block. */
9
+ export interface PdfDocumentOptions extends Omit<PdfOptions<never>, "columns" | "includeHeader" | "headerRows" | "footer" | "headerPresentation" | "footerPresentation" | "alternateRowColor" | "columnWidths" | "wideTable" | "formatValue" | "formatRuns"> {
10
+ /** Named paragraph appearance and keep rules, copied before the block source is consumed. No style inheritance. */
11
+ readonly paragraphStyles?: Readonly<Record<string, PdfParagraphStyle>>;
12
+ }
13
+ /** A table's own columns, repeated headings, presentation and numeric totals. */
14
+ export type PdfTableOptions<T = never> = Pick<PdfOptions<T>, "columns" | "includeHeader" | "headerRows" | "footer" | "headerPresentation" | "footerPresentation" | "alternateRowColor" | "columnWidths" | "wideTable" | "formatValue" | "formatRuns">;
15
+ /** Construct through pdfTable so column keys and getters are checked against the row type. */
16
+ export interface PdfTableBlock {
17
+ readonly kind: "table";
18
+ readonly rows: Iterable<object> | AsyncIterable<object>;
19
+ readonly options: PdfTableOptions;
20
+ /** Visible caption before the table, kept with its first heading/data fragment. */
21
+ readonly caption?: PdfCaption;
22
+ /** Repeated visual context before continuation headings; an artifact in tagged output. */
23
+ readonly continuationCaption?: PdfCaption;
24
+ }
25
+ /** A single-use analytical source with repeated ancestor context and source-owned numeric aggregates.
26
+ * Construct through pdfGroupedTable to capture its options. Tagged output preserves the group hierarchy. */
27
+ export interface PdfGroupedTableBlock {
28
+ readonly kind: "groupedTable";
29
+ readonly report: GroupedReportSource;
30
+ readonly options: GroupedPdfTableOptions;
31
+ }
32
+ /** Reusable paragraph appearance, spacing and keep rules. Semantic roles remain on their content blocks. */
33
+ export interface PdfParagraphStyle {
34
+ readonly fontSize?: number;
35
+ readonly presentation?: Omit<Pick<CellPresentation, "bold" | "italic" | "color" | "alignment">, "alignment"> & {
36
+ readonly alignment?: "left" | "center" | "right";
37
+ };
38
+ /** Move this paragraph intact; reject when its complete layout exceeds a fresh page. */
39
+ readonly keepTogether?: boolean;
40
+ /** Keep this paragraph with the next paragraph line, table heading/data fragment or complete graphic. */
41
+ readonly keepWithNext?: boolean;
42
+ /** Space in points, before this paragraph; default zero. */
43
+ readonly spaceBefore?: number;
44
+ /** Space in points, after this paragraph; default eight. */
45
+ readonly spaceAfter?: number;
46
+ }
47
+ /** Flowing text and inline emphasis/links, using the document's fonts and supported-script contract. */
48
+ export interface PdfParagraphBlock extends PdfParagraphStyle {
49
+ readonly kind: "paragraph";
50
+ readonly text: PdfText;
51
+ /** Name from paragraphStyles. Explicit fields override it; presentation merges member by member. */
52
+ readonly style?: string;
53
+ /** Heading level in tagged output; omitted text is a paragraph. Appearance uses presentation. */
54
+ readonly headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
55
+ /** Native navigation destination at this paragraph's actual first painted line. */
56
+ readonly bookmark?: PdfBookmark;
57
+ }
58
+ /** Visible label kept before its table or figure; numbering is authored as part of text. */
59
+ export interface PdfCaption extends Omit<PdfParagraphStyle, "keepTogether" | "keepWithNext"> {
60
+ readonly text: PdfText;
61
+ readonly style?: string;
62
+ }
63
+ /** One rich paragraph body. Explicit line breaks may separate a finding's title, message and scope. */
64
+ export interface PdfListItem {
65
+ readonly text: PdfText;
66
+ readonly style?: string;
67
+ /** Move this whole item intact; reject when it exceeds a fresh page. */
68
+ readonly keepTogether?: boolean;
69
+ }
70
+ /** A streamed semantic list, with hanging body text and one marker per item. Nested blocks are unsupported. */
71
+ export interface PdfListBlock {
72
+ readonly kind: "list";
73
+ readonly items: Iterable<PdfListItem> | AsyncIterable<PdfListItem>;
74
+ /** Decimal numbering when true; otherwise a bullet. Default false. */
75
+ readonly ordered?: boolean;
76
+ /** First positive safe-integer number; valid only for ordered lists. Default one. */
77
+ readonly start?: number;
78
+ /** Default paragraph style for items; an item's style replaces this name. keepWithNext is unsupported. */
79
+ readonly itemStyle?: string;
80
+ /** Body offset in points; default reserves at least two ems and enough room for the marker and gap. */
81
+ readonly indent?: number;
82
+ /** Gap between marker and body in points; default half an em. */
83
+ readonly markerGap?: number;
84
+ }
85
+ /** An explicitly bounded group of paragraphs. Keeps stay within the group; other block kinds and nested groups are rejected. */
86
+ export interface PdfGroupBlock {
87
+ readonly kind: "group";
88
+ readonly blocks: readonly PdfParagraphBlock[];
89
+ /** Keep the complete paragraph group on one page; reject an oversized group. Default true. */
90
+ readonly keepTogether?: boolean;
91
+ }
92
+ /** Explicitly finish the current page; the next block starts on a new page. */
93
+ export interface PdfPageBreakBlock {
94
+ readonly kind: "pageBreak";
95
+ }
96
+ /** Already-decoded row-major 8-bit pixels, with no row padding or premultiplied alpha. */
97
+ export interface PdfRawImage {
98
+ readonly format: "rgb" | "rgba";
99
+ readonly width: number;
100
+ readonly height: number;
101
+ readonly data: Uint8Array;
102
+ }
103
+ /** An 8-bit grayscale/RGB JPEG. CMYK, ICC-profiled and nonstandard component layouts are rejected. */
104
+ export interface PdfJpegImage {
105
+ readonly format: "jpeg";
106
+ readonly data: Uint8Array;
107
+ }
108
+ /** A complete static unprofiled, noninterlaced 8-bit RGB/RGBA PNG, decoded with native DecompressionStream. */
109
+ export interface PdfPngImage {
110
+ readonly format: "png";
111
+ readonly data: Uint8Array;
112
+ }
113
+ /** An indivisible image. Oversized display dimensions scale down to the printable page. */
114
+ export interface PdfImageBlock {
115
+ readonly kind: "image";
116
+ readonly image: PdfRawImage | PdfJpegImage | PdfPngImage;
117
+ /** Display lengths in PDF points; omitted dimensions retain the intrinsic aspect ratio at 96 DPI. */
118
+ readonly width?: number;
119
+ readonly height?: number;
120
+ readonly alignment?: "left" | "center" | "right";
121
+ /** Required for meaningful figures in tagged output; cannot accompany decorative:true. */
122
+ readonly alternativeText?: string;
123
+ /** Explicitly exclude a purely decorative graphic from the logical reading order. */
124
+ readonly decorative?: boolean;
125
+ /** Visible caption before the complete image; distinct from alternativeText. */
126
+ readonly caption?: PdfCaption;
127
+ }
128
+ /** Coordinates use points from the vector block's top-left corner. */
129
+ export type PdfPathCommand = {
130
+ readonly op: "move" | "line";
131
+ readonly x: number;
132
+ readonly y: number;
133
+ } | {
134
+ readonly op: "cubic";
135
+ readonly x1: number;
136
+ readonly y1: number;
137
+ readonly x2: number;
138
+ readonly y2: number;
139
+ readonly x: number;
140
+ readonly y: number;
141
+ } | {
142
+ readonly op: "close";
143
+ };
144
+ /** A bounded path, painted once. No SVG, CSS, gradients, text or external resources are interpreted. */
145
+ export interface PdfVectorBlock {
146
+ readonly kind: "vector";
147
+ readonly width: number;
148
+ readonly height: number;
149
+ readonly commands: readonly PdfPathCommand[];
150
+ readonly fill?: string;
151
+ readonly stroke?: string;
152
+ readonly strokeWidth?: number;
153
+ readonly fillRule?: "nonzero" | "evenodd";
154
+ readonly alignment?: "left" | "center" | "right";
155
+ readonly alternativeText?: string;
156
+ readonly decorative?: boolean;
157
+ readonly caption?: PdfCaption;
158
+ }
159
+ /** Blocks are consumed once in order; each table owns its row source until that table completes. */
160
+ export type PdfDocumentBlock = PdfParagraphBlock | PdfGroupBlock | PdfTableBlock | PdfGroupedTableBlock | PdfPageBreakBlock | PdfImageBlock | PdfVectorBlock | PdfDrawingBlock | PdfListBlock | PdfSectionBlock;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { PdfVectorBlock } from "./document-types.js";
2
+ import type { PdfSettings } from "./settings.js";
3
+ interface PreparedVector {
4
+ readonly width: number;
5
+ readonly height: number;
6
+ readonly count: number;
7
+ readonly content: string;
8
+ }
9
+ /** Capture and serialize one bounded display path, with no markup parser or resource loading. */
10
+ export declare function vectorCommands(block: PdfVectorBlock, settings: PdfSettings, used: number): Promise<PreparedVector>;
11
+ export {};
@@ -0,0 +1,77 @@
1
+ import { OfficeIMOError } from "../core/errors.js";
2
+ import { checkAbort, pause, taskYieldDue } from "../core/iteration.js";
3
+ import { color, positive } from "./settings.js";
4
+ import { pdfNumber as n } from "./objects.js";
5
+ /** Capture and serialize one bounded display path, with no markup parser or resource loading. */
6
+ export async function vectorCommands(block, settings, used) {
7
+ const width = positive(block.width, "Vector width"), height = positive(block.height, "Vector height");
8
+ const source = block.commands;
9
+ if (!Array.isArray(source))
10
+ throw new TypeError("Vector commands must be an array.");
11
+ if (used + source.length > settings.limits.maxVectorCommands)
12
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxVectorCommands exceeded.");
13
+ const input = source.map(c => {
14
+ if (!c || typeof c !== "object")
15
+ throw new TypeError("Invalid vector command.");
16
+ const op = c.op;
17
+ if (op === "move" || op === "line")
18
+ return { op, x: c.x, y: c.y };
19
+ if (op === "cubic")
20
+ return { op, x1: c.x1, y1: c.y1, x2: c.x2, y2: c.y2, x: c.x, y: c.y };
21
+ if (op === "close")
22
+ return { op };
23
+ throw new TypeError("Unsupported vector command.");
24
+ });
25
+ const fillValue = block.fill, strokeValue = block.stroke;
26
+ const fill = fillValue === undefined ? undefined : color(fillValue), stroke = strokeValue === undefined ? undefined : color(strokeValue);
27
+ if (fill === undefined && stroke === undefined)
28
+ throw new TypeError("A vector path requires fill or stroke.");
29
+ const strokeWidth = positive(block.strokeWidth ?? 1, "Vector stroke width", 144);
30
+ const fillRule = block.fillRule;
31
+ if (fillRule !== undefined && !["nonzero", "evenodd"].includes(fillRule))
32
+ throw new TypeError("Invalid vector fill rule.");
33
+ const commands = [];
34
+ let bytes = 0, started = false;
35
+ const coordinate = (value, bound) => {
36
+ if (!Number.isFinite(value) || value < 0 || value > bound)
37
+ throw new RangeError("Vector coordinates must stay inside their declared bounds.");
38
+ return n(value);
39
+ };
40
+ for (let i = 0; i < input.length; i++) {
41
+ const c = input[i];
42
+ let command;
43
+ if (!c || typeof c !== "object")
44
+ throw new TypeError("Invalid vector command.");
45
+ if (c.op === "move" || c.op === "line") {
46
+ if (c.op === "line" && !started)
47
+ throw new TypeError("A vector subpath must begin with move.");
48
+ command = coordinate(c.x, width) + " " + coordinate(c.y, height) + (c.op === "move" ? " m\n" : " l\n");
49
+ started = true;
50
+ }
51
+ else if (c.op === "cubic") {
52
+ if (!started)
53
+ throw new TypeError("A vector subpath must begin with move.");
54
+ command = [coordinate(c.x1, width), coordinate(c.y1, height), coordinate(c.x2, width), coordinate(c.y2, height), coordinate(c.x, width), coordinate(c.y, height)].join(" ") + " c\n";
55
+ }
56
+ else if (c.op === "close") {
57
+ if (!started)
58
+ throw new TypeError("Cannot close an empty vector path.");
59
+ command = "h\n";
60
+ }
61
+ else
62
+ throw new TypeError("Unsupported vector command.");
63
+ bytes += command.length;
64
+ if (bytes > settings.limits.maxPageBytes - 256)
65
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxPageBytes exceeded by vector commands.");
66
+ commands.push(command);
67
+ if ((i & 1023) === 1023) {
68
+ if (taskYieldDue())
69
+ await pause();
70
+ checkAbort(settings.options.signal);
71
+ }
72
+ }
73
+ if (!started)
74
+ throw new TypeError("A vector path needs at least one command.");
75
+ return { width, height, count: input.length, content: (fill === undefined ? "" : fill + " rg\n") + (stroke === undefined ? "" : stroke + " RG\n" + n(strokeWidth) + " w\n") +
76
+ commands.join("") + (fill !== undefined && stroke !== undefined ? "B" : fill !== undefined ? "f" : "S") + (fill !== undefined && fillRule === "evenodd" ? "*" : "") + "\n" };
77
+ }
@@ -0,0 +1,9 @@
1
+ import type { ExportResult, OutputDestination } from "../core/index.js";
2
+ import type { PdfDocumentBlock, PdfDocumentOptions, PdfTableBlock, PdfTableOptions } from "./document-types.js";
3
+ /** Capture typed columns for a single-use table source in a composed document. */
4
+ export declare function pdfTable<T extends object>(rows: Iterable<T> | AsyncIterable<T>, options: PdfTableOptions<NoInfer<T>>): PdfTableBlock;
5
+ /** Write sequential report blocks to a PDF Blob, retaining finished output proportional to file size. */
6
+ export declare function writePdfDocument(blocks: Iterable<PdfDocumentBlock> | AsyncIterable<PdfDocumentBlock>, options?: PdfDocumentOptions): Promise<Blob>;
7
+ /** Stream composed pages with backpressure. Rows sum table source rows; columns reports the widest table.
8
+ * Analytical subtotals/grand totals also consume the cumulative maxRows output budget. */
9
+ export declare function writePdfDocumentTo(blocks: Iterable<PdfDocumentBlock> | AsyncIterable<PdfDocumentBlock>, destination: OutputDestination, configuration?: PdfDocumentOptions): Promise<ExportResult>;