@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,142 @@
1
+ import { NotSupportedError, OfficeIMOError } from "../core/errors.js";
2
+ import { copyExportLink } from "../core/links.js";
3
+ import { checkAbort, pause, taskYieldDue } from "../core/iteration.js";
4
+ import { presentation, color } from "./settings.js";
5
+ import { wrapShapedPdfText } from "./shaped-text.js";
6
+ import { PdfFont } from "./font.js";
7
+ /** @internal A run list is a PDF presentation value, never an alternate shared table value model. */
8
+ export function capturePdfText(value, base, settings, fonts, countEmpty = true) {
9
+ const input = typeof value === "string" ? [{ text: value }] : value;
10
+ if (!Array.isArray(input)) {
11
+ if (input && typeof input.then === "function")
12
+ void Promise.resolve(input).catch(() => { });
13
+ throw new TypeError("PDF text must be a string or a synchronous array of text runs.");
14
+ }
15
+ if (typeof value !== "string" && input.length > settings.limits.maxTextRuns)
16
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxTextRuns exceeded.");
17
+ let characters = 0;
18
+ const runs = [];
19
+ for (const run of input) {
20
+ if (!run || typeof run !== "object" || Object.keys(run).some(key => !["text", "bold", "italic", "color", "link", "font"].includes(key)))
21
+ throw new TypeError("PDF text runs support text, bold, italic, color, link and font.");
22
+ const { text, bold, italic, color, link, font } = run;
23
+ if (typeof text !== "string")
24
+ throw new TypeError("PDF run text must be a string.");
25
+ if (font !== undefined) {
26
+ if (!(font instanceof PdfFont))
27
+ throw new TypeError("A PDF run font must be a PdfFont.");
28
+ fonts.registerFont(font);
29
+ }
30
+ characters += text.length;
31
+ if (characters > settings.limits.maxCellCharacters)
32
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded.");
33
+ const style = presentation({ ...base, ...(bold === undefined ? {} : { bold }), ...(italic === undefined ? {} : { italic }), ...(color === undefined ? {} : { color }) });
34
+ if (settings.options.tagged && link !== undefined && text.length && !text.trim())
35
+ throw new TypeError("Tagged PDF inline links require nonempty displayed text.");
36
+ runs.push(Object.freeze({ text, style, ...(font === undefined ? {} : { font }), ...(link === undefined ? {} : { link: copyExportLink(link) }) }));
37
+ }
38
+ // Reserve before allocating a joined rich-text value or retaining it in a kept paragraph chain.
39
+ if (characters || countEmpty)
40
+ settings.budget.reserve(1, characters);
41
+ return Object.freeze({ text: runs.map(run => run.text).join(""), runs: Object.freeze(runs) });
42
+ }
43
+ /** @internal Greedy wrapping over the continuous text stream, preserving run emphasis and URI geometry. */
44
+ export async function wrapPdfText(captured, fonts, size, width, settings, wrap = true) {
45
+ if (settings.options.textShaper)
46
+ return wrapShapedPdfText(captured, fonts, size, width, settings, wrap);
47
+ const { signal } = settings.options, { text, runs } = captured;
48
+ checkAbort(signal);
49
+ const faces = runs.map(run => fonts.select(run.style.bold, run.style.italic, run.font));
50
+ const fallback = fonts.select(), lines = [];
51
+ let chars = [], advances = [], owners = [], measured = 0, breakAt = -1;
52
+ let runIndex = 0, runEnd = runs[0]?.text.length ?? 0, scanned = 0;
53
+ const emit = (count) => {
54
+ if (lines.length >= settings.limits.maxRowLines)
55
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxRowLines exceeded.");
56
+ const segments = [];
57
+ let lineWidth = 0, lineHeight = 0, ascent = 0;
58
+ for (let begin = 0; begin < count;) {
59
+ const owner = owners[begin], run = runs[owner], font = faces[owner];
60
+ let end = begin + 1;
61
+ while (end < count && owners[end] === owner)
62
+ end++;
63
+ const segmentWidth = advances.slice(begin, end).reduce((total, advance) => total + advance, 0);
64
+ segments.push({ text: chars.slice(begin, end).join(""), width: segmentWidth, font,
65
+ ...(run.style.color === undefined ? {} : { color: run.style.color }), ...(run.link ? { link: run.link } : {}) });
66
+ lineWidth += segmentWidth;
67
+ lineHeight = Math.max(lineHeight, font.lineHeight(size));
68
+ ascent = Math.max(ascent, (font.program?.ascent ?? 800) * size / 1000);
69
+ begin = end;
70
+ }
71
+ // Empty physical lines remain observable line breaks without creating zero-area links.
72
+ if (!segments.length) {
73
+ const font = faces[0] ?? fallback;
74
+ segments.push({ text: "", width: 0, font, ...(runs[0]?.style.color === undefined ? {} : { color: runs[0].style.color }) });
75
+ lineHeight = font.lineHeight(size);
76
+ ascent = (font.program?.ascent ?? 800) * size / 1000;
77
+ }
78
+ lines.push({ text: chars.slice(0, count).join(""), width: lineWidth, segments, lineHeight, ascent });
79
+ chars = chars.slice(count);
80
+ advances = advances.slice(count);
81
+ owners = owners.slice(count);
82
+ measured = advances.reduce((total, advance) => total + advance, 0);
83
+ breakAt = -1;
84
+ for (let i = 0; i < chars.length; i++)
85
+ if (chars[i] === " ")
86
+ breakAt = i;
87
+ };
88
+ const append = (character, owner) => {
89
+ const advance = faces[owner].width(character.codePointAt(0)) * size / 1000;
90
+ if (advance > width + .001)
91
+ throw new RangeError("PDF column is too narrow for a glyph. Increase page/column width or reduce padding/font size.");
92
+ if (measured + advance > width + .001) {
93
+ if (!wrap)
94
+ throw new RangeError("Unwrapped PDF cell exceeds its column width.");
95
+ emit(breakAt >= 0 ? breakAt + 1 : chars.length);
96
+ if (measured + advance > width + .001)
97
+ emit(chars.length);
98
+ }
99
+ chars.push(character);
100
+ advances.push(advance);
101
+ owners.push(owner);
102
+ measured += advance;
103
+ if (character === " ")
104
+ breakAt = chars.length - 1;
105
+ };
106
+ for (let offset = 0; offset < text.length;) {
107
+ while (offset >= runEnd && runIndex < runs.length - 1)
108
+ runEnd += runs[++runIndex].text.length;
109
+ const owner = runIndex, scalar = text.codePointAt(offset), character = String.fromCodePoint(scalar);
110
+ if (offset + character.length > runEnd && runIndex < runs.length - 1) {
111
+ let next = runIndex + 1;
112
+ while (!runs[next].text.length)
113
+ next++;
114
+ const first = runs[owner], other = runs[next], firstFace = faces[owner], nextFace = faces[next];
115
+ const sameFace = firstFace.font === nextFace.font && (firstFace.font ?
116
+ firstFace.syntheticBold === nextFace.syntheticBold && firstFace.syntheticItalic === nextFace.syntheticItalic :
117
+ firstFace.bold === nextFace.bold && firstFace.italic === nextFace.italic);
118
+ if (!sameFace || color(first.style.color ?? "111827") !== color(other.style.color ?? "111827") ||
119
+ first.link?.target !== other.link?.target || first.link?.tooltip !== other.link?.tooltip)
120
+ throw new NotSupportedError("A PDF presentation boundary cannot split a UTF-16 scalar.");
121
+ }
122
+ offset += character.length;
123
+ if (character === "\r" || character === "\n") {
124
+ if (character === "\r" && text[offset] === "\n")
125
+ offset++;
126
+ emit(chars.length);
127
+ }
128
+ else if (character === "\t") {
129
+ for (let i = 0; i < 4; i++)
130
+ append(" ", owner);
131
+ }
132
+ else
133
+ append(character, owner);
134
+ if ((++scanned & 4095) === 0) {
135
+ if (taskYieldDue())
136
+ await pause();
137
+ checkAbort(signal);
138
+ }
139
+ }
140
+ emit(chars.length);
141
+ return lines;
142
+ }
@@ -0,0 +1,15 @@
1
+ import type { ExportLink } from "../core/links.js";
2
+ import type { PdfFont } from "./font.js";
3
+ /** One text run. Omitted emphasis/color inherits the paragraph or cell presentation. */
4
+ export interface PdfTextRun {
5
+ readonly text: string;
6
+ readonly bold?: boolean;
7
+ readonly italic?: boolean;
8
+ readonly color?: string;
9
+ /** Exact embedded face. Bold/italic flags apply synthetic emphasis to an explicit face. No font fallback occurs. */
10
+ readonly font?: PdfFont;
11
+ /** Native URI annotation over each painted run fragment. */
12
+ readonly link?: ExportLink;
13
+ }
14
+ /** Literal text or ordered inline runs; run boundaries do not introduce spaces or line breaks. */
15
+ export type PdfText = string | readonly PdfTextRun[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { PdfListBlock, PdfListItem } from "./document-types.js";
2
+ import type { PdfFontResources } from "./font-resources.js";
3
+ import type { PdfSettings } from "./settings.js";
4
+ export declare function captureListOptions(block: PdfListBlock, settings: PdfSettings): PdfCapturedListOptions;
5
+ /** Capture the whole rich item before layout can yield; marker and body share fonts, bounds and cancellation. */
6
+ export declare function prepareListItem(item: PdfListItem, index: number, options: PdfCapturedListOptions, settings: PdfSettings, fonts: PdfFontResources): Promise<PdfPreparedListItem>;
@@ -0,0 +1,49 @@
1
+ import { capturePdfText, wrapPdfText } from "./inline-text.js";
2
+ import { captureParagraph, prepareParagraph } from "./paragraph-layout.js";
3
+ import { resolveParagraphStyle } from "./paragraph-styles.js";
4
+ export function captureListOptions(block, settings) {
5
+ const { items, ordered = false, start: inputStart, itemStyle, indent, markerGap } = block;
6
+ const start = inputStart === undefined ? 1 : inputStart;
7
+ if (typeof ordered !== "boolean")
8
+ throw new TypeError("PDF list ordered must be boolean.");
9
+ if (!Number.isSafeInteger(start) || start < 1)
10
+ throw new RangeError("PDF list start must be a positive safe integer.");
11
+ if (!ordered && inputStart !== undefined)
12
+ throw new TypeError("PDF list start requires ordered:true.");
13
+ for (const [name, value] of [["indent", indent], ["markerGap", markerGap]])
14
+ if (value !== undefined && (!Number.isFinite(value) || value < 0 || value > 14400))
15
+ throw new RangeError("PDF list " + name + " must be from zero through 14,400 points.");
16
+ if (resolveParagraphStyle(itemStyle, {}, settings.paragraphStyles).keepWithNext)
17
+ throw new TypeError("PDF list item styles cannot use keepWithNext.");
18
+ return Object.freeze({ items, ordered, start, ...(itemStyle === undefined ? {} : { itemStyle }),
19
+ ...(indent === undefined ? {} : { indent }), ...(markerGap === undefined ? {} : { markerGap }) });
20
+ }
21
+ /** Capture the whole rich item before layout can yield; marker and body share fonts, bounds and cancellation. */
22
+ export async function prepareListItem(item, index, options, settings, fonts) {
23
+ if (!item || typeof item !== "object" || Array.isArray(item) || Object.keys(item).some(key => !["text", "style", "keepTogether"].includes(key)))
24
+ throw new TypeError("PDF list items support text, style and keepTogether.");
25
+ if (!Number.isSafeInteger(index) || index < 0 || !Number.isSafeInteger(options.start + index))
26
+ throw new RangeError("PDF list numbering must remain within positive safe integers.");
27
+ const { text, style = options.itemStyle, keepTogether } = item;
28
+ const captured = captureParagraph({ kind: "paragraph", text, ...(style === undefined ? {} : { style }),
29
+ ...(keepTogether === undefined ? {} : { keepTogether }) }, settings, fonts);
30
+ if (captured.keepWithNext)
31
+ throw new TypeError("PDF list item styles cannot use keepWithNext.");
32
+ if (!captured.text.text.trim().length)
33
+ throw new TypeError("PDF list items require nonempty text.");
34
+ const markerText = options.ordered ? String(options.start + index) + "." : "•";
35
+ const capturedMarker = capturePdfText(markerText, captured.style, settings, fonts);
36
+ settings.budget.cell(markerText, markerText.length);
37
+ const width = settings.page.width - settings.margins.left - settings.margins.right;
38
+ const marker = (await wrapPdfText(capturedMarker, fonts, captured.size, width, settings, false))[0];
39
+ const markerGap = options.markerGap ?? captured.size / 2, indent = options.indent ?? Math.max(captured.size * 2, marker.width + markerGap);
40
+ if (marker.width + markerGap > indent + .001)
41
+ throw new RangeError("PDF list indent cannot fit its marker and gap.");
42
+ if (indent >= width)
43
+ throw new RangeError("PDF list indent leaves no body text area.");
44
+ const paragraph = await prepareParagraph(captured, settings, fonts, width - indent), first = paragraph.lines[0];
45
+ const lineHeight = Math.max(first.lineHeight, marker.lineHeight), ascent = Math.max(first.ascent, marker.ascent);
46
+ return { marker, indent, markerGap, paragraph: { ...paragraph,
47
+ lines: [{ ...first, lineHeight, ascent }, ...paragraph.lines.slice(1)],
48
+ height: paragraph.height + lineHeight - first.lineHeight, firstHeight: paragraph.spaceBefore + lineHeight } };
49
+ }
@@ -0,0 +1,2 @@
1
+ export declare function pdfNumber(value: number): string;
2
+ export declare function unicodeHex(text: string): string;
@@ -0,0 +1,143 @@
1
+ import { checkAbort, withAbort, pause, taskYieldDue } from "../core/iteration.js";
2
+ import { OfficeIMOError } from "../core/errors.js";
3
+ export function pdfNumber(value) {
4
+ if (!Number.isFinite(value) || Math.abs(value) > 1e9)
5
+ throw new RangeError("PDF coordinates and metrics must be finite and bounded.");
6
+ return String(Math.round(value * 1000) / 1000);
7
+ }
8
+ export function unicodeHex(text) {
9
+ let hex = "";
10
+ for (let i = 0; i < text.length; i++) {
11
+ const code = text.charCodeAt(i);
12
+ if (code >= 0xd800 && code <= 0xdbff && !(text.charCodeAt(i + 1) >= 0xdc00 && text.charCodeAt(i + 1) <= 0xdfff) ||
13
+ code >= 0xdc00 && code <= 0xdfff && !(text.charCodeAt(i - 1) >= 0xd800 && text.charCodeAt(i - 1) <= 0xdbff))
14
+ throw new TypeError("PDF text contains an unpaired UTF-16 surrogate.");
15
+ hex += code.toString(16).padStart(4, "0");
16
+ }
17
+ return hex;
18
+ }
19
+ /** @internal Forward-only PDF objects. Only xref offsets and page references survive a completed page. */
20
+ export class PdfObjects {
21
+ sink;
22
+ signal;
23
+ maxBytes;
24
+ offsets = [0];
25
+ encoder = new TextEncoder();
26
+ buffer = new Uint8Array(32768);
27
+ buffered = 0;
28
+ bytes = 0;
29
+ constructor(sink, signal, maxBytes = Number.MAX_SAFE_INTEGER) {
30
+ this.sink = sink;
31
+ this.signal = signal;
32
+ this.maxBytes = maxBytes;
33
+ }
34
+ reserve() { this.offsets.push(undefined); return this.offsets.length - 1; }
35
+ async raw(bytes) {
36
+ checkAbort(this.signal);
37
+ if (this.bytes + bytes.length > this.maxBytes)
38
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxOutputBytes exceeded.");
39
+ this.bytes += bytes.length;
40
+ for (let offset = 0; offset < bytes.length;) {
41
+ const n = Math.min(this.buffer.length - this.buffered, bytes.length - offset);
42
+ this.buffer.set(bytes.subarray(offset, offset + n), this.buffered);
43
+ offset += n;
44
+ this.buffered += n;
45
+ if (this.buffered === this.buffer.length)
46
+ await this.flush();
47
+ }
48
+ }
49
+ async text(text) { await this.raw(this.encoder.encode(text)); }
50
+ async flush() {
51
+ if (this.buffered) {
52
+ const bytes = this.buffer.subarray(0, this.buffered);
53
+ await withAbort(Promise.resolve(this.sink.write(bytes)), this.signal);
54
+ this.buffer = new Uint8Array(32768);
55
+ this.buffered = 0;
56
+ }
57
+ if (taskYieldDue())
58
+ await pause();
59
+ checkAbort(this.signal);
60
+ }
61
+ async object(id, body) {
62
+ this.start(id);
63
+ if (typeof body === "string") {
64
+ await this.text(id + " 0 obj\n" + body + "\nendobj\n");
65
+ return;
66
+ }
67
+ // Logical parent arrays can be large. Coalesce small tokens without materializing the whole object.
68
+ let chunk = id + " 0 obj\n";
69
+ for (const part of body) {
70
+ for (let offset = 0; offset < part.length;) {
71
+ const end = Math.min(part.length, offset + 32768 - chunk.length);
72
+ chunk += part.slice(offset, end);
73
+ offset = end;
74
+ if (chunk.length === 32768) {
75
+ // Keep a trailing high surrogate with the next token, matching one-shot UTF-8 encoding.
76
+ const code = chunk.charCodeAt(chunk.length - 1), length = code >= 0xd800 && code <= 0xdbff ? chunk.length - 1 : chunk.length;
77
+ await this.text(chunk.slice(0, length));
78
+ chunk = chunk.slice(length);
79
+ }
80
+ }
81
+ }
82
+ await this.text(chunk + "\nendobj\n");
83
+ }
84
+ start(id) {
85
+ if (!Number.isInteger(id) || id <= 0 || id >= this.offsets.length || this.offsets[id] !== undefined)
86
+ throw new Error("Invalid PDF object state.");
87
+ this.offsets[id] = this.bytes;
88
+ }
89
+ async stream(id, source, dictionary = "", compression = true, owned = false) {
90
+ const bytes = typeof source === "string" ? this.encoder.encode(source) : source;
91
+ let compressor;
92
+ if (compression && typeof CompressionStream === "function" && bytes.length) {
93
+ try {
94
+ compressor = new CompressionStream("deflate");
95
+ }
96
+ catch { /* PDF streams can remain uncompressed. */ }
97
+ }
98
+ if (!compressor) {
99
+ this.start(id);
100
+ await this.text(id + " 0 obj\n<< /Length " + bytes.length + " " + dictionary + " >>\nstream\n");
101
+ await this.raw(bytes);
102
+ await this.text("\nendstream\nendobj\n");
103
+ return;
104
+ }
105
+ // Verified internal producers can transfer immutable ownership; other byte sources retain the defensive snapshot.
106
+ const sourceBytes = typeof source === "string" || owned ? bytes : new Uint8Array(bytes);
107
+ const input = new ReadableStream({ start(controller) { controller.enqueue(sourceBytes); controller.close(); } });
108
+ const reader = input.pipeThrough(compressor).getReader(), lengthId = this.reserve();
109
+ let length = 0, complete = false;
110
+ try {
111
+ this.start(id);
112
+ await this.text(id + " 0 obj\n<< /Length " + lengthId + " 0 R /Filter /FlateDecode " + dictionary + " >>\nstream\n");
113
+ while (true) {
114
+ const next = await withAbort(reader.read(), this.signal);
115
+ if (next.done) {
116
+ complete = true;
117
+ break;
118
+ }
119
+ length += next.value.length;
120
+ await this.raw(next.value);
121
+ }
122
+ await this.text("\nendstream\nendobj\n");
123
+ await this.object(lengthId, String(length));
124
+ }
125
+ finally {
126
+ if (!complete)
127
+ void reader.cancel(this.signal?.reason).catch(() => { });
128
+ reader.releaseLock();
129
+ }
130
+ }
131
+ async finish(root, info) {
132
+ if (this.offsets.slice(1).some(offset => offset === undefined))
133
+ throw new Error("PDF contains unwritten objects.");
134
+ if (this.bytes > 9999999999)
135
+ throw new OfficeIMOError("RESOURCE_LIMIT", "PDF exceeds classic cross-reference offset capacity.");
136
+ const start = this.bytes;
137
+ await this.text("xref\n0 " + this.offsets.length + "\n0000000000 65535 f \n");
138
+ for (let i = 1; i < this.offsets.length; i++)
139
+ await this.text(String(this.offsets[i]).padStart(10, "0") + " 00000 n \n");
140
+ await this.text("trailer\n<< /Size " + this.offsets.length + " /Root " + root + " 0 R /Info " + info + " 0 R >>\nstartxref\n" + start + "\n%%EOF\n");
141
+ await this.flush();
142
+ }
143
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,55 @@
1
+ import { OfficeIMOError } from "../core/errors.js";
2
+ import { checkAbort } from "../core/iteration.js";
3
+ import { pdfNumber, unicodeHex } from "./objects.js";
4
+ /** @internal Bounded native bookmarks; destinations are captured only when their content is painted. */
5
+ export class PdfOutlines {
6
+ objects;
7
+ settings;
8
+ root;
9
+ items = [];
10
+ top = [];
11
+ stack = [];
12
+ constructor(objects, settings) {
13
+ this.objects = objects;
14
+ this.settings = settings;
15
+ }
16
+ add(bookmark, page, y) {
17
+ checkAbort(this.settings.options.signal);
18
+ if (this.items.length >= this.settings.limits.maxBookmarks)
19
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxBookmarks exceeded.");
20
+ this.root ??= this.objects.reserve();
21
+ const level = bookmark.level ?? 1;
22
+ while (this.stack.length && this.stack.at(-1).level >= level)
23
+ this.stack.pop();
24
+ const parent = this.stack.at(-1), siblings = parent?.children ?? this.top, previous = siblings.at(-1);
25
+ const item = { id: this.objects.reserve(), title: bookmark.title, page, y, level,
26
+ parent: parent?.id ?? this.root, children: [], previous: previous?.id, next: undefined };
27
+ if (previous)
28
+ previous.next = item.id;
29
+ siblings.push(item);
30
+ this.items.push(item);
31
+ this.stack.push(item);
32
+ }
33
+ get count() { return this.items.length; }
34
+ /** A completed analytical group cannot parent later groups, including unnamed ones. */
35
+ closeGroup(level) {
36
+ while (this.stack.length && this.stack.at(-1).level >= level)
37
+ this.stack.pop();
38
+ }
39
+ get catalogDictionary() { return this.root === undefined ? "" : " /Outlines " + this.root + " 0 R"; }
40
+ async finish() {
41
+ if (this.root === undefined)
42
+ return;
43
+ const descendants = new Map();
44
+ for (const item of [...this.items].reverse())
45
+ descendants.set(item.id, item.children.reduce((n, child) => n + 1 + descendants.get(child.id), 0));
46
+ for (const item of this.items) {
47
+ checkAbort(this.settings.options.signal);
48
+ await this.objects.object(item.id, "<< /Title <feff" + unicodeHex(item.title) + "> /Parent " + item.parent + " 0 R" +
49
+ (item.previous === undefined ? "" : " /Prev " + item.previous + " 0 R") + (item.next === undefined ? "" : " /Next " + item.next + " 0 R") +
50
+ (item.children.length ? " /First " + item.children[0].id + " 0 R /Last " + item.children.at(-1).id + " 0 R /Count " + descendants.get(item.id) : "") +
51
+ " /Dest [" + item.page + " 0 R /XYZ null " + pdfNumber(item.y) + " null] >>");
52
+ }
53
+ await this.objects.object(this.root, "<< /Type /Outlines /First " + this.top[0].id + " 0 R /Last " + this.top.at(-1).id + " 0 R /Count " + this.items.length + " >>");
54
+ }
55
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { settings } from "./settings.js";
2
+ /** @internal Every section derives from captured document defaults, never the preceding section. */
3
+ export function sectionSettings(base, section) {
4
+ const { pageSize, orientation, margins, pageHeader, pageFooter, pageNumbers } = section;
5
+ const options = { ...base.options,
6
+ ...(pageSize === undefined ? {} : { pageSize }), ...(orientation === undefined ? {} : { orientation }),
7
+ ...(margins === undefined ? {} : { margins }), ...(pageHeader === undefined ? {} : { pageHeader }),
8
+ ...(pageFooter === undefined ? {} : { pageFooter }), ...(pageNumbers === undefined ? {} : { pageNumbers }) };
9
+ // Reuse the existing public normalizer; section changes cannot acquire new limits or reset counters.
10
+ const derived = settings(options, true);
11
+ return { ...base, page: derived.page, margins: derived.margins, options };
12
+ }
@@ -0,0 +1 @@
1
+ export {};