@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,19 @@
1
+ import type { CellPresentation } from "../core/index.js";
2
+ import type { PdfCapturedText, PdfInlineLine } from "./inline-text.js";
3
+ import type { PdfBookmark } from "./section-types.js";
4
+ export interface PdfCapturedParagraph {
5
+ readonly text: PdfCapturedText;
6
+ readonly style: Readonly<CellPresentation>;
7
+ readonly size: number;
8
+ readonly headingLevel?: number;
9
+ readonly bookmark?: Readonly<PdfBookmark>;
10
+ readonly keepTogether: boolean;
11
+ readonly keepWithNext: boolean;
12
+ readonly spaceBefore: number;
13
+ readonly spaceAfter: number;
14
+ }
15
+ export interface PdfPreparedParagraph extends PdfCapturedParagraph {
16
+ readonly lines: readonly PdfInlineLine[];
17
+ readonly height: number;
18
+ readonly firstHeight: number;
19
+ }
@@ -0,0 +1,66 @@
1
+ import { OfficeIMOError } from "../core/errors.js";
2
+ import { capturePdfText, wrapPdfText } from "./inline-text.js";
3
+ import { positive } from "./settings.js";
4
+ import { resolveParagraphStyle } from "./paragraph-styles.js";
5
+ import { captureBookmark } from "./section-types.js";
6
+ import { captureFields } from "../internal/capture.js";
7
+ /** @internal Copy public paragraph input before any cooperative layout or source enumeration. */
8
+ export function captureParagraph(block, settings, fonts) {
9
+ if (!block || block.kind !== "paragraph")
10
+ throw new TypeError("PDF paragraph groups accept paragraph blocks only.");
11
+ const { text, headingLevel, presentation: inputStyle, fontSize, keepTogether, keepWithNext, spaceBefore, spaceAfter, style: styleName, bookmark: inputBookmark } = block;
12
+ if (headingLevel !== undefined && (!Number.isInteger(headingLevel) || headingLevel < 1 || headingLevel > 6))
13
+ throw new TypeError("Paragraph headingLevel must be an integer from 1 through 6.");
14
+ const resolved = resolveParagraphStyle(styleName, {
15
+ ...(fontSize === undefined ? {} : { fontSize }), ...(inputStyle === undefined ? {} : { presentation: inputStyle }),
16
+ ...(keepTogether === undefined ? {} : { keepTogether }), ...(keepWithNext === undefined ? {} : { keepWithNext }),
17
+ ...(spaceBefore === undefined ? {} : { spaceBefore }), ...(spaceAfter === undefined ? {} : { spaceAfter })
18
+ }, settings.paragraphStyles);
19
+ const style = resolved.presentation ?? Object.freeze({}), size = positive(resolved.fontSize ?? settings.fontSize, "Paragraph font size", 144);
20
+ const bookmark = captureBookmark(inputBookmark, settings);
21
+ return Object.freeze({ text: capturePdfText(text, style, settings, fonts, false), style, size,
22
+ ...(headingLevel === undefined ? {} : { headingLevel }), ...(bookmark === undefined ? {} : { bookmark }),
23
+ keepTogether: resolved.keepTogether ?? false, keepWithNext: resolved.keepWithNext ?? false,
24
+ spaceBefore: resolved.spaceBefore ?? 0, spaceAfter: resolved.spaceAfter ?? 8 });
25
+ }
26
+ /** @internal Captions reuse rich text layout while their actual table/figure supplies the semantic owner. */
27
+ export function captureCaption(caption, settings, fonts) {
28
+ if (!caption || typeof caption !== "object" || Array.isArray(caption) ||
29
+ Object.keys(caption).some(key => !["text", "style", "fontSize", "presentation", "spaceBefore", "spaceAfter"].includes(key)))
30
+ throw new TypeError("PDF captions support text, style, fontSize, presentation, spaceBefore and spaceAfter.");
31
+ return captureParagraph({ ...captureFields(caption, ["text", "style", "fontSize", "presentation", "spaceBefore", "spaceAfter"]),
32
+ kind: "paragraph", keepTogether: true, keepWithNext: true }, settings, fonts);
33
+ }
34
+ /** @internal Layout is bounded by the same per-cell text and wrapped-line limits as table cells. */
35
+ export async function prepareParagraph(captured, settings, fonts, width = settings.page.width - settings.margins.left - settings.margins.right) {
36
+ if (!captured.text.text)
37
+ return { ...captured, lines: [], height: 0, firstHeight: 0 };
38
+ settings.budget.cell(captured.text.text, captured.text.text.length);
39
+ const lines = await wrapPdfText(captured.text, fonts, captured.size, positive(width, "Paragraph width"), settings);
40
+ return { ...captured, lines, height: captured.spaceBefore + lines.reduce((height, line) => height + line.lineHeight, 0) + captured.spaceAfter,
41
+ firstHeight: captured.spaceBefore + lines[0].lineHeight };
42
+ }
43
+ /** @internal Pending keep chains/groups cannot retain an unbounded report or consume a table source. */
44
+ export function checkParagraphBuffer(paragraphs, settings) {
45
+ if (paragraphs.length > settings.limits.maxGroupBlocks)
46
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxGroupBlocks exceeded.");
47
+ let characters = 0, runs = 0;
48
+ for (const paragraph of paragraphs) {
49
+ characters += paragraph.text.text.length;
50
+ runs += paragraph.text.runs.length;
51
+ if (characters > settings.limits.maxCellCharacters)
52
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded by a paragraph group or keep chain.");
53
+ if (runs > settings.limits.maxTextRuns)
54
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxTextRuns exceeded by a paragraph group or keep chain.");
55
+ }
56
+ }
57
+ /** @internal Minimum leading fragment compatible with the first visible paragraph's own keep requests. */
58
+ export function paragraphStartHeight(paragraphs) {
59
+ const visible = paragraphs.filter(paragraph => paragraph.lines.length > 0);
60
+ let required = 0;
61
+ for (let i = visible.length - 1; i >= 0; i--) {
62
+ const paragraph = visible[i];
63
+ required = paragraph.keepWithNext ? paragraph.height + required : paragraph.keepTogether ? paragraph.height : paragraph.firstHeight;
64
+ }
65
+ return required;
66
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,66 @@
1
+ import { OfficeIMOError } from "../core/errors.js";
2
+ import { positive, presentation } from "./presentation-settings.js";
3
+ const fields = ["fontSize", "presentation", "keepTogether", "keepWithNext", "spaceBefore", "spaceAfter"];
4
+ const presentationFields = ["bold", "italic", "color", "alignment"];
5
+ /** @internal Copy only paragraph appearance and keep rules, without semantics or an inheritance graph. */
6
+ export function captureParagraphStyle(input) {
7
+ if (input && typeof input.then === "function") {
8
+ void Promise.resolve(input).catch(() => { });
9
+ throw new TypeError("PDF paragraph styles must be synchronous objects.");
10
+ }
11
+ if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some(key => !fields.includes(key)))
12
+ throw new TypeError("PDF paragraph styles support fontSize, presentation, keepTogether, keepWithNext, spaceBefore and spaceAfter.");
13
+ const { fontSize, presentation: inputPresentation, keepTogether, keepWithNext, spaceBefore, spaceAfter } = input;
14
+ if (fontSize !== undefined)
15
+ positive(fontSize, "Paragraph font size", 144);
16
+ for (const [name, flag] of [["keepTogether", keepTogether], ["keepWithNext", keepWithNext]])
17
+ if (flag !== undefined && typeof flag !== "boolean")
18
+ throw new TypeError("Paragraph " + name + " must be boolean.");
19
+ for (const value of [spaceBefore, spaceAfter])
20
+ if (value !== undefined && (!Number.isFinite(value) || value < 0 || value > 14400))
21
+ throw new RangeError("Paragraph spacing must be from zero through 14,400 points.");
22
+ if (inputPresentation !== undefined && (!inputPresentation || typeof inputPresentation !== "object" || Array.isArray(inputPresentation) ||
23
+ Object.keys(inputPresentation).some(key => !presentationFields.includes(key))))
24
+ throw new TypeError("PDF paragraph presentation supports bold, italic, color and alignment.");
25
+ return Object.freeze({
26
+ ...(fontSize === undefined ? {} : { fontSize }),
27
+ ...(inputPresentation === undefined ? {} : { presentation: presentation(inputPresentation) }),
28
+ ...(keepTogether === undefined ? {} : { keepTogether }), ...(keepWithNext === undefined ? {} : { keepWithNext }),
29
+ ...(spaceBefore === undefined ? {} : { spaceBefore }), ...(spaceAfter === undefined ? {} : { spaceAfter })
30
+ });
31
+ }
32
+ /** @internal Snapshot a bounded own-property registry before any report source is enumerated. */
33
+ export function captureParagraphStyles(input, maximum) {
34
+ if (!Number.isSafeInteger(maximum) || maximum < 0)
35
+ throw new RangeError("maxParagraphStyles must be a nonnegative safe integer.");
36
+ const result = Object.create(null);
37
+ if (input === undefined)
38
+ return Object.freeze(result);
39
+ if (input && typeof input.then === "function") {
40
+ void Promise.resolve(input).catch(() => { });
41
+ throw new TypeError("paragraphStyles must be a synchronous record.");
42
+ }
43
+ if (!input || typeof input !== "object" || Array.isArray(input))
44
+ throw new TypeError("paragraphStyles must be a record of named paragraph styles.");
45
+ const names = Object.keys(input);
46
+ if (names.length > maximum)
47
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxParagraphStyles exceeded.");
48
+ for (const name of names) {
49
+ if (!name.trim())
50
+ throw new TypeError("Paragraph style names must be nonempty text.");
51
+ result[name] = captureParagraphStyle(input[name]);
52
+ }
53
+ return Object.freeze(result);
54
+ }
55
+ /** @internal Explicit values win; member-wise presentation preserves the remaining named appearance. */
56
+ export function resolveParagraphStyle(name, overrides, styles) {
57
+ let named = {};
58
+ if (name !== undefined) {
59
+ if (typeof name !== "string" || !Object.prototype.hasOwnProperty.call(styles, name))
60
+ throw new TypeError("Unknown PDF paragraph style: " + String(name));
61
+ named = styles[name];
62
+ }
63
+ const captured = captureParagraphStyle(overrides);
64
+ return Object.freeze({ ...named, ...captured,
65
+ ...(named.presentation || captured.presentation ? { presentation: Object.freeze({ ...named.presentation, ...captured.presentation }) } : {}) });
66
+ }
@@ -0,0 +1,9 @@
1
+ export interface PngPixels {
2
+ readonly width: number;
3
+ readonly height: number;
4
+ readonly components: 3;
5
+ readonly data: Uint8Array;
6
+ readonly alpha?: Uint8Array;
7
+ }
8
+ /** Decode the static unprofiled 8-bit RGB/RGBA profile without canvas or a second compression engine. */
9
+ export declare function pngPixels(inputSource: Uint8Array, maxPixels: number, signal?: AbortSignal, maxWorkingBytes?: number): Promise<PngPixels>;
@@ -0,0 +1,259 @@
1
+ import { NotSupportedError, OfficeIMOError } from "../core/errors.js";
2
+ import { checkAbort, pause, taskYieldDue, withAbort } from "../core/iteration.js";
3
+ import { Crc32 } from "../internal/crc32.js";
4
+ const signature = [137, 80, 78, 71, 13, 10, 26, 10];
5
+ const unsupportedChunks = new Set(["PLTE", "tRNS", "iCCP", "sRGB", "gAMA", "cHRM", "cICP", "mDCV", "cLLI", "sBIT", "eXIf", "acTL", "fcTL", "fdAT"]);
6
+ /** Decode the static unprofiled 8-bit RGB/RGBA profile without canvas or a second compression engine. */
7
+ export async function pngPixels(inputSource, maxPixels, signal, maxWorkingBytes) {
8
+ checkAbort(signal);
9
+ const shape = pngShape(inputSource, maxPixels);
10
+ const imagePixels = shape.width * shape.height;
11
+ const workingBytes = inputSource.length + imagePixels * shape.components + (shape.components === 4 ? shape.width * 8 : 0);
12
+ if (maxWorkingBytes !== undefined && workingBytes > maxWorkingBytes)
13
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageWorkingBytes exceeded by PNG source, image planes and scanlines.");
14
+ const source = new Uint8Array(inputSource);
15
+ const header = await pngHeader(source, shape, signal);
16
+ checkAbort(signal);
17
+ let stream;
18
+ try {
19
+ if (typeof DecompressionStream !== "function")
20
+ throw new TypeError("Missing DecompressionStream");
21
+ stream = new DecompressionStream("deflate");
22
+ }
23
+ catch (cause) {
24
+ throw new OfficeIMOError("PLATFORM_UNAVAILABLE", "PNG intake requires native DecompressionStream(\"deflate\").", { cause });
25
+ }
26
+ const { width, height, components } = header, rowBytes = width * components;
27
+ const expected = (rowBytes + 1) * height;
28
+ // All dimensions and the exact filtered length are bounded before allocating decoded pixels.
29
+ if (!Number.isSafeInteger(expected) || expected > 0x7fffffff)
30
+ throw new OfficeIMOError("RESOURCE_LIMIT", "PNG filtered data exceeds the supported decoded byte length.");
31
+ // RGBA is reconstructed one scanline at a time directly into PDF RGB/alpha planes.
32
+ // It never retains an additional full interleaved RGBA image.
33
+ const pixels = new Uint8Array(width * height * 3), alpha = components === 4 ? new Uint8Array(imagePixels) : undefined;
34
+ let previous = components === 4 ? new Uint8Array(rowBytes) : undefined, current = components === 4 ? new Uint8Array(rowBytes) : undefined;
35
+ const reader = pngCompressedInput(source, header, signal).pipeThrough(stream).getReader();
36
+ let inflated = 0, output = 0, rgbOutput = 0, alphaOutput = 0, column = 0, filter = 0;
37
+ try {
38
+ while (true) {
39
+ const item = await withAbort(reader.read(), signal).catch(cause => {
40
+ checkAbort(signal);
41
+ throw new TypeError("Invalid PNG zlib image data.", { cause });
42
+ });
43
+ checkAbort(signal);
44
+ if (item.done)
45
+ break;
46
+ if (item.value.length > expected - inflated)
47
+ throw new TypeError("PNG inflated bytes exceed the exact IHDR scanline length.");
48
+ for (let p = 0; p < item.value.length; p++) {
49
+ const value = item.value[p];
50
+ if (column === 0) {
51
+ filter = value;
52
+ if (filter > 4)
53
+ throw new TypeError("Invalid PNG scanline filter.");
54
+ }
55
+ else {
56
+ const index = column - 1;
57
+ let decoded = value;
58
+ if (filter !== 0) {
59
+ const left = column > components ? current ? current[index - components] : pixels[output - components] : 0;
60
+ const up = previous ? previous[index] : output >= rowBytes ? pixels[output - rowBytes] : 0;
61
+ const upperLeft = column > components ? previous ? previous[index - components] : output >= rowBytes ? pixels[output - rowBytes - components] : 0 : 0;
62
+ decoded = (value + (filter === 1 ? left : filter === 2 ? up :
63
+ filter === 3 ? Math.floor((left + up) / 2) : paeth(left, up, upperLeft))) & 255;
64
+ }
65
+ if (current)
66
+ current[index] = decoded;
67
+ else
68
+ pixels[output] = decoded;
69
+ output++;
70
+ }
71
+ if (column === rowBytes) {
72
+ column = 0;
73
+ if (current && alpha) {
74
+ // Split each completed row once: no per-byte division or channel dispatch,
75
+ // and filter reconstruction still uses only these same two scanlines.
76
+ for (let c = 0; c < rowBytes; c += 4) {
77
+ pixels[rgbOutput++] = current[c];
78
+ pixels[rgbOutput++] = current[c + 1];
79
+ pixels[rgbOutput++] = current[c + 2];
80
+ alpha[alphaOutput++] = current[c + 3];
81
+ if ((c & 16383) === 16380) {
82
+ if (taskYieldDue())
83
+ await pause();
84
+ checkAbort(signal);
85
+ }
86
+ }
87
+ const completed = current;
88
+ current = previous;
89
+ previous = completed;
90
+ }
91
+ }
92
+ else
93
+ column++;
94
+ if ((p & 16383) === 16383) {
95
+ if (taskYieldDue())
96
+ await pause();
97
+ checkAbort(signal);
98
+ }
99
+ }
100
+ inflated += item.value.length;
101
+ if (taskYieldDue())
102
+ await pause();
103
+ checkAbort(signal);
104
+ }
105
+ if (inflated !== expected)
106
+ throw new TypeError("PNG inflated bytes must match the exact IHDR scanline length.");
107
+ await verifyPngZlibEnd(source, header, expected, signal);
108
+ return { width, height, components: 3, data: pixels, ...(alpha ? { alpha } : {}) };
109
+ }
110
+ catch (error) {
111
+ void reader.cancel(error).catch(() => { });
112
+ throw error;
113
+ }
114
+ finally {
115
+ reader.releaseLock();
116
+ }
117
+ }
118
+ /** Feed bounded IDAT slices without retaining another copy of the compressed image. */
119
+ function pngCompressedInput(source, header, signal, changeLastByte = false) {
120
+ const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
121
+ let chunk = header.firstData, position = chunk + 8, end = position + view.getUint32(chunk);
122
+ return new ReadableStream({ pull(controller) {
123
+ checkAbort(signal);
124
+ while (position === end) {
125
+ chunk = end + 4;
126
+ if (chunk === header.dataEnd) {
127
+ controller.close();
128
+ return;
129
+ }
130
+ position = chunk + 8;
131
+ end = position + view.getUint32(chunk);
132
+ }
133
+ if (changeLastByte && position === header.lastDataByte) {
134
+ controller.enqueue(Uint8Array.of(source[position++] ^ 1));
135
+ return;
136
+ }
137
+ const next = Math.min(end, position + 4096, changeLastByte && position < header.lastDataByte ? header.lastDataByte : end);
138
+ controller.enqueue(source.subarray(position, next));
139
+ position = next;
140
+ } }, { highWaterMark: 0 });
141
+ }
142
+ /** A complete zlib stream must consume its final Adler-32 byte. Older native inflaters
143
+ * silently ignore trailing input. Change only the final IDAT byte and require rejection:
144
+ * an ignored suffix still succeeds, whereas a consumed checksum byte cannot remain valid.
145
+ * The second native pass discards bounded output; it never allocates another image plane. */
146
+ async function verifyPngZlibEnd(source, header, expected, signal) {
147
+ const reader = pngCompressedInput(source, header, signal, true).pipeThrough(new DecompressionStream("deflate")).getReader();
148
+ let rejected = false, output = 0;
149
+ try {
150
+ while (true) {
151
+ let item;
152
+ try {
153
+ item = await withAbort(reader.read(), signal);
154
+ }
155
+ catch {
156
+ checkAbort(signal);
157
+ rejected = true;
158
+ break;
159
+ }
160
+ checkAbort(signal);
161
+ if (item.done)
162
+ break;
163
+ output += item.value.length;
164
+ if (output > expected)
165
+ throw new TypeError("Invalid PNG zlib image data.");
166
+ if (taskYieldDue())
167
+ await pause();
168
+ checkAbort(signal);
169
+ }
170
+ if (!rejected)
171
+ throw new TypeError("Invalid PNG zlib image data: trailing bytes after the checksum.");
172
+ }
173
+ finally {
174
+ void reader.cancel().catch(() => { });
175
+ reader.releaseLock();
176
+ }
177
+ }
178
+ /** Verify the complete source and critical chunk order before any decompressed image allocation. */
179
+ async function pngHeader(source, shape, signal) {
180
+ const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
181
+ let firstData = 0, dataEnd = 0, lastDataByte = -1, dataClosed = false;
182
+ for (let offset = 8; offset < source.length;) {
183
+ checkAbort(signal);
184
+ if (offset + 12 > source.length)
185
+ throw new TypeError("Truncated PNG chunk.");
186
+ const length = view.getUint32(offset), end = offset + 12 + length;
187
+ if (length > 0x7fffffff || end > source.length)
188
+ throw new TypeError("Truncated or oversized PNG chunk.");
189
+ const type = String.fromCharCode(...source.subarray(offset + 4, offset + 8));
190
+ if (!/^[A-Za-z]{2}[A-Z][A-Za-z]$/.test(type))
191
+ throw new TypeError("Invalid PNG chunk type.");
192
+ const crc = new Crc32();
193
+ for (let p = offset + 4; p < end - 4; p += 65536) {
194
+ crc.update(source.subarray(p, Math.min(end - 4, p + 65536)));
195
+ if (taskYieldDue())
196
+ await pause();
197
+ checkAbort(signal);
198
+ }
199
+ if (crc.value !== view.getUint32(end - 4))
200
+ throw new TypeError("PNG chunk CRC mismatch: " + type + ".");
201
+ if (offset === 8 && type !== "IHDR")
202
+ throw new TypeError("PNG IHDR must be the first chunk.");
203
+ if (type === "IHDR") {
204
+ if (offset !== 8 || length !== 13)
205
+ throw new TypeError("PNG requires one 13-byte IHDR first.");
206
+ }
207
+ else if (type === "IDAT") {
208
+ if (dataClosed)
209
+ throw new TypeError("PNG IDAT chunks must be consecutive.");
210
+ firstData ||= offset;
211
+ dataEnd = end;
212
+ if (length)
213
+ lastDataByte = end - 5;
214
+ }
215
+ else {
216
+ if (firstData)
217
+ dataClosed = true;
218
+ if (type === "IEND") {
219
+ if (length !== 0 || !firstData || end !== source.length)
220
+ throw new TypeError("PNG requires a final empty IEND after IDAT.");
221
+ return { ...shape, firstData, dataEnd, lastDataByte };
222
+ }
223
+ if (unsupportedChunks.has(type))
224
+ throw new NotSupportedError("PNG chunk " + type + "; normalize color, orientation, transparency or animation first");
225
+ if ((source[offset + 4] & 32) === 0)
226
+ throw new NotSupportedError("Required PNG chunk " + type);
227
+ }
228
+ offset = end;
229
+ }
230
+ throw new TypeError("PNG requires a complete final IEND chunk.");
231
+ }
232
+ /** Check source metadata synchronously, before capturing source bytes or allocating any image plane. */
233
+ function pngShape(source, maxPixels) {
234
+ if (source.length < 33 || signature.some((value, index) => source[index] !== value))
235
+ throw new TypeError("Invalid PNG signature or truncated IHDR.");
236
+ const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
237
+ if (view.getUint32(8) !== 13 || String.fromCharCode(...source.subarray(12, 16)) !== "IHDR")
238
+ throw new TypeError("PNG requires one 13-byte IHDR first.");
239
+ const width = view.getUint32(16), height = view.getUint32(20);
240
+ if (!width || !height || width > 0x7fffffff || height > 0x7fffffff)
241
+ throw new TypeError("Invalid PNG dimensions.");
242
+ if (!Number.isSafeInteger(width * height) || width * height > maxPixels)
243
+ throw new OfficeIMOError("RESOURCE_LIMIT", "PNG dimensions exceed maxImagePixels.");
244
+ if (source[24] !== 8 || ![2, 6].includes(source[25]))
245
+ throw new NotSupportedError("PNG intake requires 8-bit RGB or RGBA pixels");
246
+ if (source[26] !== 0 || source[27] !== 0)
247
+ throw new NotSupportedError("PNG compression or filter method");
248
+ if (source[28] !== 0)
249
+ throw new NotSupportedError("Interlaced PNG intake");
250
+ const components = source[25] === 6 ? 4 : 3;
251
+ if (!Number.isSafeInteger((width * components + 1) * height) || (width * components + 1) * height > 0x7fffffff)
252
+ throw new OfficeIMOError("RESOURCE_LIMIT", "PNG filtered data exceeds the supported decoded byte length.");
253
+ return { width, height, components };
254
+ }
255
+ function paeth(left, up, upperLeft) {
256
+ const prediction = left + up - upperLeft;
257
+ const a = Math.abs(prediction - left), b = Math.abs(prediction - up), c = Math.abs(prediction - upperLeft);
258
+ return a <= b && a <= c ? left : b <= c ? up : upperLeft;
259
+ }
@@ -0,0 +1,7 @@
1
+ import type { PdfTextPreflightOptions, PdfTextPreflightResult } from "./types.js";
2
+ /**
3
+ * Check one text run against the writer's selected font and scalar-layout rules.
4
+ * Returns the first text issue at its original UTF-16 index. This does not check
5
+ * wrapping, page geometry, resource budgets or document accessibility.
6
+ */
7
+ export declare function preflightPdfText(text: string, options?: PdfTextPreflightOptions): PdfTextPreflightResult;
@@ -0,0 +1,32 @@
1
+ import { fontProgram } from "./font.js";
2
+ import { resolveScalar, selectFont, validateFonts } from "./font-support.js";
3
+ /**
4
+ * Check one text run against the writer's selected font and scalar-layout rules.
5
+ * Returns the first text issue at its original UTF-16 index. This does not check
6
+ * wrapping, page geometry, resource budgets or document accessibility.
7
+ */
8
+ export function preflightPdfText(text, options = {}) {
9
+ if (typeof text !== "string")
10
+ throw new TypeError("PDF preflight text must be a string.");
11
+ if (!options || typeof options !== "object")
12
+ throw new TypeError("PDF preflight options must be an object.");
13
+ for (const key of ["bold", "italic"])
14
+ if (options[key] !== undefined && typeof options[key] !== "boolean")
15
+ throw new TypeError("PDF preflight " + key + " must be boolean.");
16
+ validateFonts(options.fonts);
17
+ const bold = options.bold ?? false, { font } = selectFont(options.fonts, bold, options.italic ?? false);
18
+ const program = font ? fontProgram(font) : undefined, checked = new Set();
19
+ for (let index = 0; index < text.length;) {
20
+ const scalar = text.codePointAt(index);
21
+ // wrapText treats CR/LF as paragraph boundaries and expands tabs to spaces.
22
+ const displayed = scalar === 9 ? 32 : scalar;
23
+ if (scalar !== 10 && scalar !== 13 && !checked.has(displayed)) {
24
+ const result = resolveScalar(displayed, program, bold);
25
+ if (!result.supported)
26
+ return { ...result, index, ...(result.code === "unpaired-surrogate" ? {} : { scalar }) };
27
+ checked.add(displayed);
28
+ }
29
+ index += scalar > 0xffff ? 2 : 1;
30
+ }
31
+ return { supported: true };
32
+ }
@@ -0,0 +1,5 @@
1
+ import type { CellPresentation } from "../core/index.js";
2
+ /** Pure validation shared by document settings and named paragraph styles. */
3
+ export declare function positive(value: number, name: string, max?: number): number;
4
+ export declare function color(value: string): string;
5
+ export declare function presentation(value?: CellPresentation): Readonly<CellPresentation>;
@@ -0,0 +1,28 @@
1
+ import { captureFields } from "../internal/capture.js";
2
+ /** Pure validation shared by document settings and named paragraph styles. */
3
+ export function positive(value, name, max = 14400) {
4
+ if (!Number.isFinite(value) || value <= 0 || value > max)
5
+ throw new RangeError(name + " must be positive and at most " + max + ".");
6
+ return value;
7
+ }
8
+ export function color(value) {
9
+ if (typeof value !== "string" || !/^#?[0-9a-f]{6}$/i.test(value))
10
+ throw new TypeError("PDF colors must be six-digit RGB hex strings.");
11
+ const hex = value.replace(/^#/, "");
12
+ return [0, 2, 4].map(i => String(Math.round(parseInt(hex.slice(i, i + 2), 16) / 255 * 10000) / 10000)).join(" ");
13
+ }
14
+ export function presentation(value = {}) {
15
+ if (!value || typeof value !== "object")
16
+ throw new TypeError("PDF presentation must be an object.");
17
+ const snapshot = captureFields(value, ["background", "color", "numberFormat", "bold", "italic", "wrapText", "alignment"]);
18
+ if (snapshot.background !== undefined)
19
+ color(snapshot.background);
20
+ if (snapshot.color !== undefined)
21
+ color(snapshot.color);
22
+ for (const key of ["bold", "italic", "wrapText"])
23
+ if (snapshot[key] !== undefined && typeof snapshot[key] !== "boolean")
24
+ throw new TypeError("PDF presentation " + key + " must be boolean.");
25
+ if (snapshot.alignment !== undefined && !["left", "center", "right"].includes(snapshot.alignment))
26
+ throw new TypeError("PDF table alignment supports left, center and right.");
27
+ return Object.freeze(snapshot);
28
+ }
@@ -0,0 +1,60 @@
1
+ import type { PdfTextShaper } from "../text-shaping-types.js";
2
+ interface HbFont {
3
+ setScale(x: number, y: number): void;
4
+ }
5
+ interface HbBuffer {
6
+ add(codePoint: number, cluster: number): void;
7
+ reset(): void;
8
+ guessSegmentProperties(): void;
9
+ setDirection(direction: 4 | 5): void;
10
+ setLanguage(language: string): void;
11
+ setClusterLevel(level: 0): void;
12
+ getGlyphInfos(): {
13
+ codepoint: number;
14
+ cluster: number;
15
+ }[];
16
+ getGlyphPositions(): {
17
+ xAdvance: number;
18
+ yAdvance: number;
19
+ xOffset: number;
20
+ yOffset: number;
21
+ }[];
22
+ getLength(): number;
23
+ }
24
+ /** Structural subset of harfbuzzjs 1.6.3. The host imports its ESM/WASM module explicitly. */
25
+ export interface PdfHarfBuzzModule {
26
+ readonly Blob: new (bytes: ArrayBuffer) => object;
27
+ readonly Face: new (blob: never) => object;
28
+ readonly Font: new (face: never) => HbFont;
29
+ readonly Buffer: new () => HbBuffer;
30
+ shape(font: never, buffer: never): void;
31
+ }
32
+ export interface PdfBidiLevels {
33
+ readonly levels: Uint8Array;
34
+ readonly paragraphs: readonly {
35
+ start: number;
36
+ end: number;
37
+ level: number;
38
+ }[];
39
+ }
40
+ /** Structural subset of an initialized bidi-js 1.1.0 instance (Unicode 13.0 data). */
41
+ export interface PdfBidiEngine {
42
+ getEmbeddingLevels(text: string, direction?: "auto" | "ltr" | "rtl"): PdfBidiLevels;
43
+ getReorderedIndices(text: string, levels: PdfBidiLevels, start?: number, end?: number): number[];
44
+ getBidiCharTypeName(character: string): string;
45
+ }
46
+ export interface PdfHarfBuzzOptions {
47
+ readonly harfbuzz: PdfHarfBuzzModule;
48
+ readonly bidi: PdfBidiEngine;
49
+ /** Optional BCP 47 shaping language; defaults to und. */
50
+ readonly language?: string;
51
+ }
52
+ export interface PdfHarfBuzzTextShaper extends PdfTextShaper {
53
+ /** Drop strong font/buffer references and reject future calls. HarfBuzz v1 frees native objects through finalizers. */
54
+ dispose(): void;
55
+ }
56
+ /** Adapt host-loaded HarfBuzz and bidi engines. No fetch, package import, font fallback or WASM initialization occurs here.
57
+ * Qualified profile: horizontal static TrueType fonts, at most 16 cached font identities, 4,096 UTF-16 units per paragraph.
58
+ * Cancellation is checked between bounded synchronous engine calls; worker termination owns deterministic WASM lifetime. */
59
+ export declare function createHarfBuzzTextShaper(options: PdfHarfBuzzOptions): PdfHarfBuzzTextShaper;
60
+ export {};