@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,112 @@
1
+ import { checkAbort } from "../../core/iteration.js";
2
+ import { NotSupportedError, OfficeIMOError } from "../../core/errors.js";
3
+ import { isUnicode13ProfileScalar } from "./unicode13-profile.js";
4
+ /** Adapt host-loaded HarfBuzz and bidi engines. No fetch, package import, font fallback or WASM initialization occurs here.
5
+ * Qualified profile: horizontal static TrueType fonts, at most 16 cached font identities, 4,096 UTF-16 units per paragraph.
6
+ * Cancellation is checked between bounded synchronous engine calls; worker termination owns deterministic WASM lifetime. */
7
+ export function createHarfBuzzTextShaper(options) {
8
+ const { harfbuzz: hb, bidi } = options;
9
+ if (!hb || !bidi || [hb.Blob, hb.Face, hb.Font, hb.Buffer, hb.shape, bidi.getEmbeddingLevels, bidi.getReorderedIndices, bidi.getBidiCharTypeName].some(method => typeof method !== "function"))
10
+ throw new TypeError("Supply initialized HarfBuzz and bidi engines.");
11
+ const language = options.language ?? "und";
12
+ if (typeof language !== "string" || language.length > 63 || Intl.getCanonicalLocales(language).length !== 1)
13
+ throw new TypeError("Invalid shaping language.");
14
+ const fonts = new Map();
15
+ let buffer, disposed = false;
16
+ let previousText, previousDirection, previousLevels;
17
+ const getFont = (source) => {
18
+ const cached = fonts.get(source);
19
+ if (cached)
20
+ return cached.font;
21
+ if (fonts.size >= 16)
22
+ throw new OfficeIMOError("RESOURCE_LIMIT", "The optional text provider supports at most 16 cached font identities.");
23
+ // Constructor arguments are opaque because the loaded module owns its native handle classes.
24
+ const bytes = source.toBytes(), blob = new hb.Blob(bytes.buffer), face = new hb.Face(blob), font = new hb.Font(face);
25
+ font.setScale(1000, 1000);
26
+ fonts.set(source, { blob, face, font });
27
+ return font;
28
+ };
29
+ return {
30
+ shapeLine(request) {
31
+ if (disposed)
32
+ throw new TypeError("The text provider has been disposed.");
33
+ checkAbort(request.signal);
34
+ const { text, start, end, runs, direction } = request;
35
+ if (!["auto", "ltr", "rtl"].includes(direction))
36
+ throw new TypeError("Invalid shaping direction.");
37
+ if (text.length > 4096)
38
+ throw new OfficeIMOError("RESOURCE_LIMIT", "The optional text provider supports at most 4,096 UTF-16 units per physical paragraph.");
39
+ if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end < start || end > text.length)
40
+ throw new TypeError("Invalid shaping line range.");
41
+ if (start === end)
42
+ return [];
43
+ const levels = previousText === text && previousDirection === direction ? previousLevels : bidi.getEmbeddingLevels(text, direction);
44
+ previousText = text;
45
+ previousDirection = direction;
46
+ previousLevels = levels;
47
+ if (!(levels.levels instanceof Uint8Array) || levels.levels.length !== text.length)
48
+ throw new TypeError("Invalid bidi embedding levels.");
49
+ const base = levels.paragraphs.find(paragraph => paragraph.start <= start && paragraph.end >= end - 1)?.level;
50
+ if (base === undefined)
51
+ throw new TypeError("A shaped line must stay within one physical bidi paragraph.");
52
+ const lineText = text.slice(start, end), lineLevels = levels.levels.slice(start, end);
53
+ // Resolve L1 trailing whitespace on the line-local view while retaining paragraph embedding levels.
54
+ for (let i = lineText.length - 1; i >= 0 && ["S", "WS", "B", "LRI", "RLI", "FSI", "PDI", "BN", "RLE", "LRE", "RLO", "LRO", "PDF"].includes(bidi.getBidiCharTypeName(lineText[i])); i--)
55
+ lineLevels[i] = base;
56
+ const items = [];
57
+ for (let offset = start; offset < end;) {
58
+ const run = runs.find(run => run.start <= offset && run.end > offset);
59
+ if (!run)
60
+ throw new TypeError("Every shaped character needs a registered font.");
61
+ const scalar = text.codePointAt(offset), length = scalar > 0xffff ? 2 : 1, level = lineLevels[offset - start];
62
+ if (scalar >= 0xd800 && scalar <= 0xdfff || offset + length > end)
63
+ throw new TypeError("Shaping ranges must not split UTF-16 scalars.");
64
+ if (!isUnicode13ProfileScalar(scalar))
65
+ throw new NotSupportedError("The optional provider's Unicode 13.0 profile supports Latin, Arabic, Common and Inherited characters assigned in that version.");
66
+ const previous = items.at(-1);
67
+ // Same-font presentation boundaries remain in one shaping run, preserving contextual joining.
68
+ if (previous && previous.font === run.font && previous.level === level)
69
+ previous.end = offset + length;
70
+ else
71
+ items.push({ start: offset, end: offset + length, font: run.font, level });
72
+ offset += length;
73
+ }
74
+ const visual = bidi.getReorderedIndices(lineText, { levels: lineLevels, paragraphs: [{ start: 0, end: lineText.length - 1, level: base }] }), ranks = new Map();
75
+ visual.forEach((offset, rank) => ranks.set(offset + start, rank));
76
+ items.sort((a, b) => Math.min(...Array.from({ length: a.end - a.start }, (_, i) => ranks.get(a.start + i) ?? Infinity)) -
77
+ Math.min(...Array.from({ length: b.end - b.start }, (_, i) => ranks.get(b.start + i) ?? Infinity)));
78
+ const output = [];
79
+ let count = 0;
80
+ for (const item of items) {
81
+ checkAbort(request.signal);
82
+ const font = getFont(item.font);
83
+ buffer ??= new hb.Buffer();
84
+ buffer.reset();
85
+ for (let offset = item.start; offset < item.end;) {
86
+ const scalar = text.codePointAt(offset);
87
+ buffer.add(scalar, offset);
88
+ offset += scalar > 0xffff ? 2 : 1;
89
+ }
90
+ buffer.setClusterLevel(0);
91
+ buffer.setDirection(item.level & 1 ? 5 : 4);
92
+ buffer.setLanguage(language);
93
+ buffer.guessSegmentProperties();
94
+ hb.shape(font, buffer);
95
+ checkAbort(request.signal);
96
+ count += buffer.getLength();
97
+ if (count > 32768)
98
+ throw new OfficeIMOError("RESOURCE_LIMIT", "The optional text provider exceeded 32,768 glyphs.");
99
+ const infos = buffer.getGlyphInfos(), positions = buffer.getGlyphPositions();
100
+ if (infos.length !== positions.length)
101
+ throw new TypeError("HarfBuzz returned inconsistent glyph arrays.");
102
+ const clusters = [...new Set(infos.map(info => info.cluster))].sort((a, b) => a - b), ends = new Map(clusters.map((cluster, i) => [cluster, clusters[i + 1] ?? item.end]));
103
+ const glyphs = infos.map((info, i) => ({ id: info.codepoint, clusterStart: info.cluster, clusterEnd: ends.get(info.cluster), ...positions[i] }));
104
+ if (glyphs.some(glyph => !glyph.id))
105
+ throw new NotSupportedError("The supplied font has a missing glyph in shaped text.");
106
+ output.push({ font: item.font, glyphs });
107
+ }
108
+ return output;
109
+ },
110
+ dispose() { disposed = true; fonts.clear(); buffer = undefined; previousText = undefined; previousLevels = undefined; }
111
+ };
112
+ }
@@ -0,0 +1,2 @@
1
+ /** Normative data stays within the optional provider graph, independent of host Unicode regex versions. */
2
+ export declare function isUnicode13ProfileScalar(scalar: number): boolean;
@@ -0,0 +1,115 @@
1
+ /*
2
+ * Unicode13 Latin/Arabic/Common/Inherited scalar repertoire.
3
+ * Derived from https://www.unicode.org/Public/13.0.0/ucd/Scripts.txt
4
+ * Source SHA-256: 9a5ed1ec9b5f0d7147e9371ad792ab39203611af7637cff2aa4a5c663b172cde
5
+ * Generation: select these four Script records, sort ranges, merge adjacent ranges.
6
+ * Original data: Copyright 2020 Unicode, Inc.
7
+ *
8
+ * UNICODE LICENSE V3
9
+ *
10
+ * COPYRIGHT AND PERMISSION NOTICE
11
+ *
12
+ * Copyright © 1991-2026 Unicode, Inc.
13
+ *
14
+ * NOTICE TO USER: Carefully read the following legal agreement. BY
15
+ * DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
16
+ * SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
17
+ * TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
18
+ * DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
19
+ *
20
+ * Permission is hereby granted, free of charge, to any person obtaining a
21
+ * copy of data files and any associated documentation (the "Data Files") or
22
+ * software and any associated documentation (the "Software") to deal in the
23
+ * Data Files or Software without restriction, including without limitation
24
+ * the rights to use, copy, modify, merge, publish, distribute, and/or sell
25
+ * copies of the Data Files or Software, and to permit persons to whom the
26
+ * Data Files or Software are furnished to do so, provided that either (a)
27
+ * this copyright and permission notice appear with all copies of the Data
28
+ * Files or Software, or (b) this copyright and permission notice appear in
29
+ * associated Documentation.
30
+ *
31
+ * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
32
+ * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
34
+ * THIRD PARTY RIGHTS.
35
+ *
36
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
37
+ * BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
38
+ * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
41
+ * FILES OR SOFTWARE.
42
+ *
43
+ * Except as contained in this notice, the name of a copyright holder shall
44
+ * not be used in advertising or otherwise to promote the sale, use or other
45
+ * dealings in these Data Files or Software without prior written
46
+ * authorization of the copyright holder.
47
+ */
48
+ const ranges = [
49
+ 0x0, 0x2e9, 0x2ec, 0x36f, 0x374, 0x374, 0x37e, 0x37e,
50
+ 0x385, 0x385, 0x387, 0x387, 0x485, 0x486, 0x600, 0x61c,
51
+ 0x61e, 0x6ff, 0x750, 0x77f, 0x8a0, 0x8b4, 0x8b6, 0x8c7,
52
+ 0x8d3, 0x8ff, 0x951, 0x954, 0x964, 0x965, 0xe3f, 0xe3f,
53
+ 0xfd5, 0xfd8, 0x10fb, 0x10fb, 0x16eb, 0x16ed, 0x1735, 0x1736,
54
+ 0x1802, 0x1803, 0x1805, 0x1805, 0x1ab0, 0x1ac0, 0x1cd0, 0x1cfa,
55
+ 0x1d00, 0x1d25, 0x1d2c, 0x1d5c, 0x1d62, 0x1d65, 0x1d6b, 0x1d77,
56
+ 0x1d79, 0x1dbe, 0x1dc0, 0x1df9, 0x1dfb, 0x1eff, 0x2000, 0x2064,
57
+ 0x2066, 0x2071, 0x2074, 0x208e, 0x2090, 0x209c, 0x20a0, 0x20bf,
58
+ 0x20d0, 0x20f0, 0x2100, 0x2125, 0x2127, 0x218b, 0x2190, 0x2426,
59
+ 0x2440, 0x244a, 0x2460, 0x27ff, 0x2900, 0x2b73, 0x2b76, 0x2b95,
60
+ 0x2b97, 0x2bff, 0x2c60, 0x2c7f, 0x2e00, 0x2e52, 0x2ff0, 0x2ffb,
61
+ 0x3000, 0x3004, 0x3006, 0x3006, 0x3008, 0x3020, 0x302a, 0x302d,
62
+ 0x3030, 0x3037, 0x303c, 0x303f, 0x3099, 0x309c, 0x30a0, 0x30a0,
63
+ 0x30fb, 0x30fc, 0x3190, 0x319f, 0x31c0, 0x31e3, 0x3220, 0x325f,
64
+ 0x327f, 0x32cf, 0x32ff, 0x32ff, 0x3358, 0x33ff, 0x4dc0, 0x4dff,
65
+ 0xa700, 0xa7bf, 0xa7c2, 0xa7ca, 0xa7f5, 0xa7ff, 0xa830, 0xa839,
66
+ 0xa92e, 0xa92e, 0xa9cf, 0xa9cf, 0xab30, 0xab64, 0xab66, 0xab6b,
67
+ 0xfb00, 0xfb06, 0xfb50, 0xfbc1, 0xfbd3, 0xfd3f, 0xfd50, 0xfd8f,
68
+ 0xfd92, 0xfdc7, 0xfdf0, 0xfdfd, 0xfe00, 0xfe19, 0xfe20, 0xfe2d,
69
+ 0xfe30, 0xfe52, 0xfe54, 0xfe66, 0xfe68, 0xfe6b, 0xfe70, 0xfe74,
70
+ 0xfe76, 0xfefc, 0xfeff, 0xfeff, 0xff01, 0xff65, 0xff70, 0xff70,
71
+ 0xff9e, 0xff9f, 0xffe0, 0xffe6, 0xffe8, 0xffee, 0xfff9, 0xfffd,
72
+ 0x10100, 0x10102, 0x10107, 0x10133, 0x10137, 0x1013f, 0x10190, 0x1019c,
73
+ 0x101d0, 0x101fd, 0x102e0, 0x102fb, 0x10e60, 0x10e7e, 0x1133b, 0x1133b,
74
+ 0x16fe2, 0x16fe3, 0x1bca0, 0x1bca3, 0x1d000, 0x1d0f5, 0x1d100, 0x1d126,
75
+ 0x1d129, 0x1d1e8, 0x1d2e0, 0x1d2f3, 0x1d300, 0x1d356, 0x1d360, 0x1d378,
76
+ 0x1d400, 0x1d454, 0x1d456, 0x1d49c, 0x1d49e, 0x1d49f, 0x1d4a2, 0x1d4a2,
77
+ 0x1d4a5, 0x1d4a6, 0x1d4a9, 0x1d4ac, 0x1d4ae, 0x1d4b9, 0x1d4bb, 0x1d4bb,
78
+ 0x1d4bd, 0x1d4c3, 0x1d4c5, 0x1d505, 0x1d507, 0x1d50a, 0x1d50d, 0x1d514,
79
+ 0x1d516, 0x1d51c, 0x1d51e, 0x1d539, 0x1d53b, 0x1d53e, 0x1d540, 0x1d544,
80
+ 0x1d546, 0x1d546, 0x1d54a, 0x1d550, 0x1d552, 0x1d6a5, 0x1d6a8, 0x1d7cb,
81
+ 0x1d7ce, 0x1d7ff, 0x1ec71, 0x1ecb4, 0x1ed01, 0x1ed3d, 0x1ee00, 0x1ee03,
82
+ 0x1ee05, 0x1ee1f, 0x1ee21, 0x1ee22, 0x1ee24, 0x1ee24, 0x1ee27, 0x1ee27,
83
+ 0x1ee29, 0x1ee32, 0x1ee34, 0x1ee37, 0x1ee39, 0x1ee39, 0x1ee3b, 0x1ee3b,
84
+ 0x1ee42, 0x1ee42, 0x1ee47, 0x1ee47, 0x1ee49, 0x1ee49, 0x1ee4b, 0x1ee4b,
85
+ 0x1ee4d, 0x1ee4f, 0x1ee51, 0x1ee52, 0x1ee54, 0x1ee54, 0x1ee57, 0x1ee57,
86
+ 0x1ee59, 0x1ee59, 0x1ee5b, 0x1ee5b, 0x1ee5d, 0x1ee5d, 0x1ee5f, 0x1ee5f,
87
+ 0x1ee61, 0x1ee62, 0x1ee64, 0x1ee64, 0x1ee67, 0x1ee6a, 0x1ee6c, 0x1ee72,
88
+ 0x1ee74, 0x1ee77, 0x1ee79, 0x1ee7c, 0x1ee7e, 0x1ee7e, 0x1ee80, 0x1ee89,
89
+ 0x1ee8b, 0x1ee9b, 0x1eea1, 0x1eea3, 0x1eea5, 0x1eea9, 0x1eeab, 0x1eebb,
90
+ 0x1eef0, 0x1eef1, 0x1f000, 0x1f02b, 0x1f030, 0x1f093, 0x1f0a0, 0x1f0ae,
91
+ 0x1f0b1, 0x1f0bf, 0x1f0c1, 0x1f0cf, 0x1f0d1, 0x1f0f5, 0x1f100, 0x1f1ad,
92
+ 0x1f1e6, 0x1f1ff, 0x1f201, 0x1f202, 0x1f210, 0x1f23b, 0x1f240, 0x1f248,
93
+ 0x1f250, 0x1f251, 0x1f260, 0x1f265, 0x1f300, 0x1f6d7, 0x1f6e0, 0x1f6ec,
94
+ 0x1f6f0, 0x1f6fc, 0x1f700, 0x1f773, 0x1f780, 0x1f7d8, 0x1f7e0, 0x1f7eb,
95
+ 0x1f800, 0x1f80b, 0x1f810, 0x1f847, 0x1f850, 0x1f859, 0x1f860, 0x1f887,
96
+ 0x1f890, 0x1f8ad, 0x1f8b0, 0x1f8b1, 0x1f900, 0x1f978, 0x1f97a, 0x1f9cb,
97
+ 0x1f9cd, 0x1fa53, 0x1fa60, 0x1fa6d, 0x1fa70, 0x1fa74, 0x1fa78, 0x1fa7a,
98
+ 0x1fa80, 0x1fa86, 0x1fa90, 0x1faa8, 0x1fab0, 0x1fab6, 0x1fac0, 0x1fac2,
99
+ 0x1fad0, 0x1fad6, 0x1fb00, 0x1fb92, 0x1fb94, 0x1fbca, 0x1fbf0, 0x1fbf9,
100
+ 0xe0001, 0xe0001, 0xe0020, 0xe007f, 0xe0100, 0xe01ef,
101
+ ];
102
+ /** Normative data stays within the optional provider graph, independent of host Unicode regex versions. */
103
+ export function isUnicode13ProfileScalar(scalar) {
104
+ let left = 0, right = ranges.length / 2 - 1;
105
+ while (left <= right) {
106
+ const middle = (left + right) >>> 1, start = ranges[middle * 2], end = ranges[middle * 2 + 1];
107
+ if (scalar < start)
108
+ right = middle - 1;
109
+ else if (scalar > end)
110
+ left = middle + 1;
111
+ else
112
+ return true;
113
+ }
114
+ return false;
115
+ }
@@ -0,0 +1,15 @@
1
+ import type { PdfOptions } from "./types.js";
2
+ /** A native PDF outline entry whose destination follows the paragraph's actual painted position. */
3
+ export interface PdfBookmark {
4
+ readonly title: string;
5
+ readonly level?: 1 | 2 | 3 | 4 | 5 | 6;
6
+ }
7
+ /** A flat section boundary. Following blocks use this section until the next boundary. */
8
+ export interface PdfSectionBlock extends Pick<PdfOptions, "pageSize" | "orientation" | "margins" | "pageHeader" | "pageFooter" | "pageNumbers"> {
9
+ readonly kind: "section";
10
+ readonly title: string;
11
+ readonly level?: 1 | 2 | 3 | 4 | 5 | 6;
12
+ readonly includeHeading?: boolean;
13
+ readonly bookmark?: boolean;
14
+ readonly headingStyle?: string;
15
+ }
@@ -0,0 +1,40 @@
1
+ import { OfficeIMOError } from "../core/errors.js";
2
+ import { unicodeHex } from "./objects.js";
3
+ import { captureFields } from "../internal/capture.js";
4
+ /** @internal Capture bookmark metadata before source enumeration or cooperative layout. */
5
+ export function captureBookmark(value, settings) {
6
+ if (value === undefined)
7
+ return undefined;
8
+ if (!value || typeof value !== "object")
9
+ throw new TypeError("PDF bookmark must provide a title and optional level.");
10
+ const { title, level = 1 } = value;
11
+ if (typeof title !== "string" || !title.trim())
12
+ throw new TypeError("PDF bookmark title must be nonempty text.");
13
+ if (title.length > settings.limits.maxCellCharacters)
14
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded by bookmark title.");
15
+ if (!Number.isInteger(level) || level < 1 || level > 6)
16
+ throw new TypeError("PDF bookmark level must be an integer from 1 through 6.");
17
+ unicodeHex(title);
18
+ return Object.freeze({ title, level });
19
+ }
20
+ /** @internal Sections capture only geometry/decorations; fonts, styles and resource policy remain document-owned. */
21
+ export function captureSection(block, settings) {
22
+ if (!block || block.kind !== "section")
23
+ throw new TypeError("PDF section boundary required.");
24
+ if (Object.keys(block).some(key => !["kind", "title", "level", "includeHeading", "bookmark", "headingStyle", "pageSize", "orientation", "margins", "pageHeader", "pageFooter", "pageNumbers"].includes(key)))
25
+ throw new TypeError("PDF sections support title, heading/bookmark controls, page geometry and decorations only.");
26
+ const { title, level, includeHeading = true, bookmark = true, headingStyle, pageSize, orientation, margins, pageHeader, pageFooter, pageNumbers } = block;
27
+ const checked = captureBookmark({ title, ...(level === undefined ? {} : { level }) }, settings);
28
+ for (const [name, value] of [["includeHeading", includeHeading], ["bookmark", bookmark], ["pageNumbers", pageNumbers]])
29
+ if (value !== undefined && typeof value !== "boolean")
30
+ throw new TypeError("PDF section " + name + " must be boolean.");
31
+ if (headingStyle !== undefined && (typeof headingStyle !== "string" || !headingStyle.trim()))
32
+ throw new TypeError("PDF section headingStyle must be nonempty text.");
33
+ return Object.freeze({ kind: "section", title: checked.title, level: checked.level, includeHeading, bookmark,
34
+ ...(headingStyle === undefined ? {} : { headingStyle }),
35
+ ...(pageSize === undefined ? {} : { pageSize: typeof pageSize === "object" ? Object.freeze(captureFields(pageSize, ["width", "height"])) : pageSize }),
36
+ ...(orientation === undefined ? {} : { orientation }),
37
+ ...(margins === undefined ? {} : { margins: typeof margins === "object" ? Object.freeze(captureFields(margins, ["top", "right", "bottom", "left"])) : margins }),
38
+ ...(pageHeader === undefined ? {} : { pageHeader }), ...(pageFooter === undefined ? {} : { pageFooter }),
39
+ ...(pageNumbers === undefined ? {} : { pageNumbers }) });
40
+ }
@@ -0,0 +1,25 @@
1
+ import type { ByteSink } from "../core/index.js";
2
+ import { PdfObjects } from "./objects.js";
3
+ import { PdfFontResources } from "./font-resources.js";
4
+ import { PdfTableLayout } from "./table-layout.js";
5
+ import { PdfPages } from "./pages.js";
6
+ import type { PdfSettings } from "./settings.js";
7
+ import { PdfStructure } from "./structure.js";
8
+ import { PdfOutlines } from "./outlines.js";
9
+ /** One resource/catalog owner shared by table convenience exports and composed documents. */
10
+ export declare class PdfWriteSession {
11
+ private readonly settings;
12
+ readonly objects: PdfObjects;
13
+ readonly fonts: PdfFontResources;
14
+ readonly pages: PdfPages;
15
+ readonly layout: PdfTableLayout | undefined;
16
+ readonly structure: PdfStructure | undefined;
17
+ readonly outlines: PdfOutlines;
18
+ private readonly root;
19
+ private readonly parent;
20
+ private readonly resources;
21
+ private readonly info;
22
+ constructor(sink: ByteSink, settings: PdfSettings, table?: boolean);
23
+ start(): Promise<void>;
24
+ finish(): Promise<void>;
25
+ }
@@ -0,0 +1,55 @@
1
+ import { PdfObjects, unicodeHex } from "./objects.js";
2
+ import { PdfFontResources } from "./font-resources.js";
3
+ import { PdfTableLayout } from "./table-layout.js";
4
+ import { PdfPages } from "./pages.js";
5
+ import { PdfStructure } from "./structure.js";
6
+ import { PdfOutlines } from "./outlines.js";
7
+ /** One resource/catalog owner shared by table convenience exports and composed documents. */
8
+ export class PdfWriteSession {
9
+ settings;
10
+ objects;
11
+ fonts;
12
+ pages;
13
+ layout;
14
+ structure;
15
+ outlines;
16
+ root;
17
+ parent;
18
+ resources;
19
+ info;
20
+ constructor(sink, settings, table = false) {
21
+ this.settings = settings;
22
+ this.objects = new PdfObjects(sink, settings.options.signal, settings.budget.limits.maxOutputBytes, settings.options.compression !== false);
23
+ this.root = this.objects.reserve();
24
+ this.parent = this.objects.reserve();
25
+ this.resources = this.objects.reserve();
26
+ this.info = this.objects.reserve();
27
+ this.structure = settings.options.tagged ? new PdfStructure(this.objects, settings) : undefined;
28
+ this.outlines = new PdfOutlines(this.objects, settings);
29
+ this.fonts = new PdfFontResources(this.objects, settings.options.fonts, settings.limits.maxFontBytes, settings.options.signal);
30
+ this.layout = table ? new PdfTableLayout(settings, this.fonts) : undefined;
31
+ this.pages = new PdfPages(this.objects, settings, this.fonts, this.parent, this.resources, this.layout, this.structure, this.outlines);
32
+ }
33
+ async start() {
34
+ await this.objects.text("%PDF-1.7\n");
35
+ await this.objects.raw(Uint8Array.of(0x25, 0xe2, 0xe3, 0xcf, 0xd3, 0x0a));
36
+ if (this.layout?.bands)
37
+ await this.pages.beginTable(this.layout);
38
+ else if (this.layout)
39
+ await this.pages.start(true);
40
+ }
41
+ async finish() {
42
+ const { options } = this.settings, { objects, fonts, pages } = this;
43
+ await pages.finish();
44
+ for (const font of fonts.resources)
45
+ await font.write(objects, options.compression !== false);
46
+ await objects.object(this.resources, "<< /Font " + fonts.dictionary() + pages.xobjects() + " >>");
47
+ await objects.object(this.parent, "<< /Type /Pages /Count " + pages.references.length + " /Kids [" + pages.references.map(id => id + " 0 R").join(" ") + "] >>");
48
+ if (this.structure)
49
+ await this.structure.finish();
50
+ await this.outlines.finish();
51
+ await objects.object(this.root, "<< /Type /Catalog /Pages " + this.parent + " 0 R" + (this.structure?.catalogDictionary ?? "") + this.outlines.catalogDictionary + " >>");
52
+ await objects.object(this.info, "<< /Producer (OfficeIMO.js)" + (options.title === undefined ? "" : " /Title <feff" + unicodeHex(options.title) + ">") + " >>");
53
+ await objects.finish(this.root, this.info);
54
+ }
55
+ }
@@ -0,0 +1,17 @@
1
+ import { ExportBudget } from "../core/limits.js";
2
+ import type { PdfOptions, PdfMargins, PdfPageSize, PdfLimits } from "./types.js";
3
+ import type { PdfDocumentOptions, PdfParagraphStyle } from "./document-types.js";
4
+ export { positive, color, presentation } from "./presentation-settings.js";
5
+ export interface PdfSettings {
6
+ readonly options: PdfOptions & Pick<PdfDocumentOptions, "paragraphStyles">;
7
+ readonly paragraphStyles: Readonly<Record<string, Readonly<PdfParagraphStyle>>>;
8
+ readonly page: PdfPageSize;
9
+ readonly margins: PdfMargins;
10
+ readonly fontSize: number;
11
+ readonly padding: number;
12
+ readonly limits: Required<Pick<PdfLimits, "maxPages" | "maxColumns" | "maxTableBands" | "maxTableWindowRows" | "maxCellCharacters" | "maxTextRuns" | "maxGroupBlocks" | "maxRowLines" | "maxFontBytes" | "maxPageBytes" | "maxHyperlinks" | "maxImageBytes" | "maxImagePixels" | "maxVectorCommands" | "maxDrawingElements" | "maxStructureElements" | "maxMarkedContentReferences" | "maxListItems" | "maxParagraphStyles" | "maxSections" | "maxBookmarks">> & Pick<PdfLimits, "maxImageWorkingBytes">;
13
+ readonly budget: ExportBudget;
14
+ /** Captured identities resolved once to selected table positions, shared by layout and band planning. */
15
+ readonly repeatedColumns: readonly number[];
16
+ }
17
+ export declare function settings(input: PdfOptions & Pick<PdfDocumentOptions, "paragraphStyles">, document?: boolean): PdfSettings;
@@ -0,0 +1,196 @@
1
+ import { OfficeIMOError } from "../core/errors.js";
2
+ import { ExportBudget } from "../core/limits.js";
3
+ import { copyColumns } from "../internal/rows.js";
4
+ import { captureTableSpans } from "../internal/table-spans.js";
5
+ import { copyExportValue } from "../internal/export-values.js";
6
+ import { captureFields } from "../internal/capture.js";
7
+ import { captureParagraphStyles } from "./paragraph-styles.js";
8
+ import { captureBooleanText } from "../core/value-text.js";
9
+ import { positive, color, presentation } from "./presentation-settings.js";
10
+ export { positive, color, presentation } from "./presentation-settings.js";
11
+ const sizes = {
12
+ A3: { width: 841.89, height: 1190.551 }, A4: { width: 595.276, height: 841.89 }, A5: { width: 419.528, height: 595.276 },
13
+ LETTER: { width: 612, height: 792 }, LEGAL: { width: 612, height: 1008 }, TABLOID: { width: 792, height: 1224 }
14
+ };
15
+ /** @internal Shared capture schema for thin format adapters and the grouped writer. */
16
+ export const pdfOptionFields = ["columns", "signal", "onProgress", "limits", "textShaper", "textDirection", "pageSize", "orientation", "margins", "fonts", "tagged", "fontSize",
17
+ "title", "messageTop", "messageBottom", "includeHeader", "headerRows", "footer", "headerPresentation", "footerPresentation", "alternateRowColor", "padding",
18
+ "columnWidths", "wideTable", "pageHeader", "pageFooter", "pageNumbers", "pageNumberLabels", "booleanText", "formatValue", "formatRuns", "compression", "paragraphStyles"];
19
+ /** @internal Complete PDF limit schema used when a host combines format and shared limits. */
20
+ export const pdfLimitFields = ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes", "maxPages", "maxColumns", "maxTableBands", "maxTableWindowRows", "maxCellCharacters", "maxTextRuns", "maxGroupBlocks", "maxRowLines",
21
+ "maxFontBytes", "maxPageBytes", "maxHyperlinks", "maxImageBytes", "maxImagePixels", "maxImageWorkingBytes", "maxVectorCommands", "maxDrawingElements", "maxStructureElements",
22
+ "maxMarkedContentReferences", "maxSections", "maxBookmarks", "maxListItems", "maxParagraphStyles"];
23
+ /** @internal Capture supported structural properties once, including class-based options with prototype accessors. */
24
+ export function capturePdfOptions(input) {
25
+ if (!input || typeof input !== "object" || Array.isArray(input))
26
+ throw new TypeError("PDF options must be an object.");
27
+ const captured = captureFields(input, pdfOptionFields);
28
+ const policy = captured.wideTable;
29
+ return { ...captured, ...(policy === undefined ? {} : { wideTable: captureWideTable(policy) }) };
30
+ }
31
+ /** @internal Capture the complete PDF budget before an adapter adds its shared row/output limits. */
32
+ export function capturePdfLimits(input) {
33
+ if (!input || typeof input !== "object" || Array.isArray(input))
34
+ throw new TypeError("PDF limits must be an object.");
35
+ const captured = captureFields(input, pdfLimitFields);
36
+ for (const [key, value] of Object.entries(captured))
37
+ if (value !== undefined && (!Number.isSafeInteger(value) || value < 0))
38
+ throw new RangeError(key + " must be a nonnegative safe integer.");
39
+ return Object.freeze(captured);
40
+ }
41
+ function captureFooter(input, columns) {
42
+ if (!input || typeof input !== "object" || Array.isArray(input))
43
+ throw new TypeError("PDF footer must be an object.");
44
+ const { values, totals, rows } = input;
45
+ if (values !== undefined && !Array.isArray(values))
46
+ throw new TypeError("PDF footer values must be an array.");
47
+ return Object.freeze({ ...(values === undefined ? {} : { values: Object.freeze(values.map(copyExportValue)) }),
48
+ ...(totals === undefined ? {} : { totals: Object.freeze({ ...totals }) }),
49
+ ...(rows === undefined ? {} : { rows: captureTableSpans(rows, columns) }) });
50
+ }
51
+ /** @internal Capture a band policy and its array before asynchronous layout or row production. */
52
+ export function captureWideTable(input) {
53
+ if (input === undefined || input === "fit" || input === "reject")
54
+ return input;
55
+ if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some(key => !["mode", "minimumColumnWidth", "repeatColumns"].includes(key)))
56
+ throw new TypeError("wideTable must be fit, reject or a bands policy.");
57
+ const { mode, minimumColumnWidth, repeatColumns } = input;
58
+ if (mode !== "bands")
59
+ throw new TypeError("wideTable.mode must be bands.");
60
+ if (minimumColumnWidth !== undefined)
61
+ positive(minimumColumnWidth, "Minimum PDF column width");
62
+ if (repeatColumns !== undefined && !Array.isArray(repeatColumns))
63
+ throw new TypeError("repeatColumns must be an array.");
64
+ const repeats = repeatColumns === undefined ? [] : [...repeatColumns];
65
+ if (repeats.some(value => typeof value === "number" ? !Number.isSafeInteger(value) || value < 0 : typeof value !== "string" || !value.length))
66
+ throw new RangeError("repeatColumns must contain nonnegative indices or nonempty stable keys.");
67
+ if (repeats.every(value => typeof value === "number") && repeats.some((value, index) => index > 0 && value <= repeats[index - 1]))
68
+ throw new RangeError("Numeric repeatColumns must contain sorted unique nonnegative indices.");
69
+ return Object.freeze({ mode, ...(minimumColumnWidth === undefined ? {} : { minimumColumnWidth }), repeatColumns: Object.freeze(repeats) });
70
+ }
71
+ /** Resolve identities against this table's captured selection, without consulting a grid or opening its rows. */
72
+ function repeatedColumns(policy, columns) {
73
+ if (typeof policy !== "object")
74
+ return Object.freeze([]);
75
+ const selected = new Set();
76
+ for (const selector of policy.repeatColumns ?? []) {
77
+ let position;
78
+ if (typeof selector === "number")
79
+ position = selector;
80
+ else {
81
+ position = columns.findIndex(column => column.key === selector);
82
+ if (position < 0 || columns.some((column, index) => index !== position && column.key === selector))
83
+ throw new TypeError("repeatColumns requires an unambiguous selected column key: " + selector);
84
+ }
85
+ if (position >= columns.length)
86
+ throw new RangeError("repeatColumns index exceeds the declared columns.");
87
+ if (selected.has(position))
88
+ throw new TypeError("repeatColumns selects the same column more than once.");
89
+ selected.add(position);
90
+ }
91
+ return Object.freeze([...selected].sort((left, right) => left - right));
92
+ }
93
+ export function settings(input, document = false) {
94
+ const configuration = { ...capturePdfOptions(input) };
95
+ configuration.booleanText = captureBooleanText(configuration.booleanText);
96
+ if (configuration.limits !== undefined)
97
+ configuration.limits = capturePdfLimits(configuration.limits);
98
+ if (configuration.pageSize && typeof configuration.pageSize === "object")
99
+ configuration.pageSize = Object.freeze(captureFields(configuration.pageSize, ["width", "height"]));
100
+ if (configuration.margins && typeof configuration.margins === "object")
101
+ configuration.margins = Object.freeze(captureFields(configuration.margins, ["top", "right", "bottom", "left"]));
102
+ if (configuration.pageNumberLabels !== undefined) {
103
+ const labels = configuration.pageNumberLabels;
104
+ if (!labels || typeof labels !== "object" || Array.isArray(labels))
105
+ throw new TypeError("pageNumberLabels must provide literal text.");
106
+ const { prefix = "Page ", separator = " of ", suffix = "" } = labels;
107
+ if ([prefix, separator, suffix].some(value => typeof value !== "string"))
108
+ throw new TypeError("Page-number labels must be text.");
109
+ configuration.pageNumberLabels = Object.freeze({ prefix, separator, suffix });
110
+ }
111
+ const textShaper = configuration.textShaper, shapeLine = textShaper?.shapeLine;
112
+ if (textShaper !== undefined && (!textShaper || typeof shapeLine !== "function"))
113
+ throw new TypeError("textShaper must provide shapeLine.");
114
+ if (configuration.textDirection !== undefined && !["auto", "ltr", "rtl"].includes(configuration.textDirection))
115
+ throw new TypeError("textDirection must be auto, ltr or rtl.");
116
+ const columns = document ? [] : copyColumns(configuration.columns).map(c => Object.freeze(c));
117
+ if (document)
118
+ configuration.includeHeader = false;
119
+ if (!columns.length && !document)
120
+ throw new TypeError("PDF tables need at least one declared column.");
121
+ const capturedFonts = configuration.fonts === undefined ? undefined : captureFields(configuration.fonts, ["regular", "bold", "italic", "boldItalic"]);
122
+ const options = { ...configuration, columns,
123
+ ...(textShaper ? { textShaper: Object.freeze({ shapeLine: shapeLine.bind(textShaper) }) } : {}),
124
+ ...(configuration.tagged ? { tagged: Object.freeze(captureFields(configuration.tagged, ["language"])) } : {}),
125
+ ...(configuration.headerRows ? { headerRows: captureTableSpans(configuration.headerRows, columns.length) } : {}),
126
+ ...(capturedFonts ? { fonts: Object.freeze(capturedFonts) } : {}),
127
+ ...(configuration.columnWidths ? { columnWidths: Object.freeze([...configuration.columnWidths]) } : {}),
128
+ ...(configuration.footer === undefined ? {} : { footer: captureFooter(configuration.footer, columns.length) }),
129
+ headerPresentation: Object.freeze({ background: "e7edf5", bold: true, ...presentation(configuration.headerPresentation) }),
130
+ footerPresentation: Object.freeze({ background: "eef2f6", bold: true, ...presentation(configuration.footerPresentation) }) };
131
+ const budget = new ExportBudget(options.limits);
132
+ const limits = { maxPages: 10000, maxColumns: 1024, maxTableBands: 64, maxTableWindowRows: 256, maxCellCharacters: 1000000, maxTextRuns: 10000, maxGroupBlocks: 256, maxRowLines: 100000, maxFontBytes: 16 * 1024 * 1024, maxPageBytes: 8 * 1024 * 1024, maxHyperlinks: 100000,
133
+ maxImageBytes: 32 * 1024 * 1024, maxImagePixels: 16 * 1024 * 1024, maxVectorCommands: 100000, maxDrawingElements: 100000,
134
+ maxStructureElements: 1000000, maxMarkedContentReferences: 2000000,
135
+ maxListItems: 100000, maxParagraphStyles: 256, maxSections: 1000, maxBookmarks: 10000 };
136
+ for (const key of Object.keys(limits)) {
137
+ const override = options.limits?.[key];
138
+ if (override !== undefined)
139
+ limits[key] = override;
140
+ }
141
+ const paragraphStyles = captureParagraphStyles(options.paragraphStyles, limits.maxParagraphStyles);
142
+ if (columns.length > limits.maxColumns)
143
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxColumns exceeded.");
144
+ const size = typeof options.pageSize === "string" || options.pageSize === undefined ? sizes[options.pageSize ?? "A4"] : options.pageSize;
145
+ if (!size)
146
+ throw new TypeError("Unsupported PDF page size.");
147
+ positive(size.width, "Page width");
148
+ positive(size.height, "Page height");
149
+ if (options.orientation !== undefined && !["portrait", "landscape"].includes(options.orientation))
150
+ throw new TypeError("Invalid PDF orientation.");
151
+ const landscape = options.orientation === "landscape", page = { width: landscape ? Math.max(size.width, size.height) : Math.min(size.width, size.height), height: landscape ? Math.min(size.width, size.height) : Math.max(size.width, size.height) };
152
+ const margins = { top: 36, right: 36, bottom: 36, left: 36, ...(typeof options.margins === "number" ? { top: options.margins, right: options.margins, bottom: options.margins, left: options.margins } : options.margins) };
153
+ for (const value of Object.values(margins))
154
+ if (!Number.isFinite(value) || value < 0)
155
+ throw new RangeError("PDF margins must be finite and nonnegative.");
156
+ if (margins.left + margins.right >= page.width || margins.top + margins.bottom >= page.height)
157
+ throw new RangeError("PDF margins leave no content area.");
158
+ const fontSize = positive(options.fontSize ?? 9, "Font size", 144), padding = options.padding ?? 4;
159
+ if (!Number.isFinite(padding) || padding < 0 || padding > 72)
160
+ throw new RangeError("PDF padding must be from 0 through 72 points.");
161
+ for (const key of ["title", "messageTop", "messageBottom"])
162
+ if (options[key] !== undefined && typeof options[key] !== "string")
163
+ throw new TypeError(key + " must be text.");
164
+ for (const key of ["pageHeader", "pageFooter"])
165
+ if (options[key] !== undefined && typeof options[key] !== "string" && typeof options[key] !== "function")
166
+ throw new TypeError(key + " must be text or a synchronous callback.");
167
+ for (const key of ["formatValue", "formatRuns"])
168
+ if (options[key] !== undefined && typeof options[key] !== "function")
169
+ throw new TypeError(key + " must be a synchronous function.");
170
+ for (const key of ["compression", "includeHeader", "pageNumbers"])
171
+ if (options[key] !== undefined && typeof options[key] !== "boolean")
172
+ throw new TypeError(key + " must be boolean.");
173
+ if (options.alternateRowColor !== undefined)
174
+ color(options.alternateRowColor);
175
+ if (options.footer?.values && options.footer.values.length > columns.length)
176
+ throw new RangeError("Footer has more values than declared columns.");
177
+ if (options.footer?.rows && (options.footer.values !== undefined || options.footer.totals !== undefined))
178
+ throw new TypeError("Structured footer rows cannot be combined with values/totals.");
179
+ if (options.headerRows && options.includeHeader === false)
180
+ throw new TypeError("headerRows requires includeHeader.");
181
+ if (options.tagged !== undefined) {
182
+ if (!options.tagged || typeof options.tagged !== "object" || typeof options.tagged.language !== "string" || options.tagged.language.length > 63)
183
+ throw new TypeError("tagged.language must be a language tag such as en or en-US.");
184
+ try {
185
+ if (Intl.getCanonicalLocales(options.tagged.language).length !== 1)
186
+ throw new RangeError();
187
+ }
188
+ catch {
189
+ throw new TypeError("tagged.language must be a language tag such as en or en-US.");
190
+ }
191
+ }
192
+ const maxImageWorkingBytes = options.limits?.maxImageWorkingBytes;
193
+ return { options: { ...options, paragraphStyles }, paragraphStyles, page, margins, fontSize, padding,
194
+ repeatedColumns: document ? Object.freeze([]) : repeatedColumns(options.wideTable, columns),
195
+ limits: { ...limits, ...(maxImageWorkingBytes === undefined ? {} : { maxImageWorkingBytes }) }, budget };
196
+ }
@@ -0,0 +1,5 @@
1
+ import type { PdfFontResources } from "./font-resources.js";
2
+ import type { PdfCapturedText, PdfInlineLine } from "./inline-text.js";
3
+ import type { PdfSettings } from "./settings.js";
4
+ /** Core-owned bounded line flow. Shape finalized lines again so Arabic joining reflects the actual break. */
5
+ export declare function wrapShapedPdfText(captured: PdfCapturedText, fonts: PdfFontResources, size: number, width: number, settings: PdfSettings, wrap: boolean): Promise<readonly PdfInlineLine[]>;