@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.
- package/LICENSE +21 -0
- package/README.md +1222 -2
- package/bundles/officeimo-canopyx.js +11741 -0
- package/bundles/officeimo-canopyx.mjs +11639 -0
- package/bundles/officeimo-csv.js +1264 -0
- package/bundles/officeimo-csv.mjs +1239 -0
- package/bundles/officeimo-datatables.js +12018 -0
- package/bundles/officeimo-datatables.mjs +11915 -0
- package/bundles/officeimo-execution.js +1513 -0
- package/bundles/officeimo-execution.mjs +1489 -0
- package/bundles/officeimo-pdf.js +7009 -0
- package/bundles/officeimo-pdf.mjs +6946 -0
- package/bundles/officeimo-xlsx.js +5344 -0
- package/bundles/officeimo-xlsx.mjs +5290 -0
- package/bundles/officeimo.js +11468 -0
- package/bundles/officeimo.mjs +11369 -0
- package/dist/core/dates.d.ts +1 -0
- package/dist/core/dates.js +16 -0
- package/dist/core/errors.d.ts +12 -0
- package/dist/core/errors.js +31 -0
- package/dist/core/grouped-report.d.ts +87 -0
- package/dist/core/grouped-report.js +252 -0
- package/dist/core/index.d.ts +74 -0
- package/dist/core/index.js +37 -0
- package/dist/core/iteration.d.ts +7 -0
- package/dist/core/iteration.js +149 -0
- package/dist/core/limits.d.ts +7 -0
- package/dist/core/limits.js +56 -0
- package/dist/core/links.d.ts +5 -0
- package/dist/core/links.js +14 -0
- package/dist/core/presentation.d.ts +29 -0
- package/dist/core/presentation.js +59 -0
- package/dist/core/progress.d.ts +1 -0
- package/dist/core/progress.js +10 -0
- package/dist/core/sinks.d.ts +33 -0
- package/dist/core/sinks.js +102 -0
- package/dist/core/table.d.ts +8 -0
- package/dist/core/table.js +1 -0
- package/dist/core/value-text.d.ts +7 -0
- package/dist/core/value-text.js +13 -0
- package/dist/csv/index.d.ts +44 -0
- package/dist/csv/index.js +133 -0
- package/dist/csv/options.d.ts +1 -0
- package/dist/csv/options.js +8 -0
- package/dist/csv/structured-rows.d.ts +3 -0
- package/dist/csv/structured-rows.js +15 -0
- package/dist/execution/host.d.ts +5 -0
- package/dist/execution/host.js +164 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/protocol.d.ts +48 -0
- package/dist/execution/protocol.js +173 -0
- package/dist/execution/types.d.ts +42 -0
- package/dist/execution/types.js +1 -0
- package/dist/execution/worker.d.ts +3 -0
- package/dist/execution/worker.js +147 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +14 -0
- package/dist/integrations/canopyx/dates.d.ts +1 -0
- package/dist/integrations/canopyx/dates.js +34 -0
- package/dist/integrations/canopyx/index.d.ts +10 -0
- package/dist/integrations/canopyx/index.js +45 -0
- package/dist/integrations/canopyx/source.d.ts +3 -0
- package/dist/integrations/canopyx/source.js +122 -0
- package/dist/integrations/canopyx/types.d.ts +83 -0
- package/dist/integrations/canopyx/types.js +1 -0
- package/dist/integrations/datatables/api.d.ts +1 -0
- package/dist/integrations/datatables/api.js +27 -0
- package/dist/integrations/datatables/headings.d.ts +1 -0
- package/dist/integrations/datatables/headings.js +65 -0
- package/dist/integrations/datatables/index.d.ts +12 -0
- package/dist/integrations/datatables/index.js +167 -0
- package/dist/integrations/datatables/snapshot.d.ts +3 -0
- package/dist/integrations/datatables/snapshot.js +206 -0
- package/dist/integrations/datatables/types.d.ts +98 -0
- package/dist/integrations/datatables/types.js +1 -0
- package/dist/integrations/options.d.ts +13 -0
- package/dist/integrations/options.js +34 -0
- package/dist/internal/capture.d.ts +4 -0
- package/dist/internal/capture.js +14 -0
- package/dist/internal/columns.d.ts +27 -0
- package/dist/internal/columns.js +1 -0
- package/dist/internal/crc32.d.ts +6 -0
- package/dist/internal/crc32.js +17 -0
- package/dist/internal/export-values.d.ts +3 -0
- package/dist/internal/export-values.js +14 -0
- package/dist/internal/rows.d.ts +6 -0
- package/dist/internal/rows.js +77 -0
- package/dist/internal/table-spans.d.ts +11 -0
- package/dist/internal/table-spans.js +58 -0
- package/dist/internal/totals.d.ts +15 -0
- package/dist/internal/totals.js +42 -0
- package/dist/opc/index.d.ts +67 -0
- package/dist/opc/index.js +233 -0
- package/dist/opc/properties.d.ts +15 -0
- package/dist/opc/properties.js +18 -0
- package/dist/opc/uri.d.ts +5 -0
- package/dist/opc/uri.js +41 -0
- package/dist/pdf/annotations.d.ts +1 -0
- package/dist/pdf/annotations.js +38 -0
- package/dist/pdf/binary.d.ts +6 -0
- package/dist/pdf/binary.js +24 -0
- package/dist/pdf/document-drawings.d.ts +15 -0
- package/dist/pdf/document-drawings.js +237 -0
- package/dist/pdf/document-grouped.d.ts +1 -0
- package/dist/pdf/document-grouped.js +244 -0
- package/dist/pdf/document-images.d.ts +19 -0
- package/dist/pdf/document-images.js +125 -0
- package/dist/pdf/document-types.d.ts +160 -0
- package/dist/pdf/document-types.js +1 -0
- package/dist/pdf/document-vectors.d.ts +11 -0
- package/dist/pdf/document-vectors.js +77 -0
- package/dist/pdf/document.d.ts +9 -0
- package/dist/pdf/document.js +270 -0
- package/dist/pdf/drawing-types.d.ts +53 -0
- package/dist/pdf/drawing-types.js +1 -0
- package/dist/pdf/font-resources.d.ts +43 -0
- package/dist/pdf/font-resources.js +202 -0
- package/dist/pdf/font-support.d.ts +1 -0
- package/dist/pdf/font-support.js +60 -0
- package/dist/pdf/font.d.ts +17 -0
- package/dist/pdf/font.js +56 -0
- package/dist/pdf/grouped-table.d.ts +6 -0
- package/dist/pdf/grouped-table.js +40 -0
- package/dist/pdf/grouped-types.d.ts +34 -0
- package/dist/pdf/grouped-types.js +1 -0
- package/dist/pdf/grouped.d.ts +10 -0
- package/dist/pdf/grouped.js +37 -0
- package/dist/pdf/index.d.ts +22 -0
- package/dist/pdf/index.js +8 -0
- package/dist/pdf/inline-text.d.ts +30 -0
- package/dist/pdf/inline-text.js +183 -0
- package/dist/pdf/inline-types.d.ts +15 -0
- package/dist/pdf/inline-types.js +1 -0
- package/dist/pdf/list-layout.d.ts +6 -0
- package/dist/pdf/list-layout.js +49 -0
- package/dist/pdf/objects.d.ts +2 -0
- package/dist/pdf/objects.js +320 -0
- package/dist/pdf/outlines.d.ts +1 -0
- package/dist/pdf/outlines.js +55 -0
- package/dist/pdf/page-context.d.ts +1 -0
- package/dist/pdf/page-context.js +12 -0
- package/dist/pdf/pages.d.ts +1 -0
- package/dist/pdf/pages.js +678 -0
- package/dist/pdf/paragraph-layout.d.ts +21 -0
- package/dist/pdf/paragraph-layout.js +71 -0
- package/dist/pdf/paragraph-styles.d.ts +1 -0
- package/dist/pdf/paragraph-styles.js +66 -0
- package/dist/pdf/png.d.ts +9 -0
- package/dist/pdf/png.js +259 -0
- package/dist/pdf/preflight.d.ts +7 -0
- package/dist/pdf/preflight.js +32 -0
- package/dist/pdf/presentation-settings.d.ts +5 -0
- package/dist/pdf/presentation-settings.js +28 -0
- package/dist/pdf/providers/harfbuzz.d.ts +60 -0
- package/dist/pdf/providers/harfbuzz.js +112 -0
- package/dist/pdf/providers/unicode13-profile.d.ts +2 -0
- package/dist/pdf/providers/unicode13-profile.js +115 -0
- package/dist/pdf/section-types.d.ts +15 -0
- package/dist/pdf/section-types.js +40 -0
- package/dist/pdf/session.d.ts +25 -0
- package/dist/pdf/session.js +55 -0
- package/dist/pdf/settings.d.ts +17 -0
- package/dist/pdf/settings.js +196 -0
- package/dist/pdf/shaped-text.d.ts +5 -0
- package/dist/pdf/shaped-text.js +205 -0
- package/dist/pdf/standard-widths.d.ts +1 -0
- package/dist/pdf/standard-widths.js +317 -0
- package/dist/pdf/structure-parent-tree.d.ts +1 -0
- package/dist/pdf/structure-parent-tree.js +57 -0
- package/dist/pdf/structure.d.ts +6 -0
- package/dist/pdf/structure.js +302 -0
- package/dist/pdf/table-band-flow.d.ts +34 -0
- package/dist/pdf/table-band-flow.js +129 -0
- package/dist/pdf/table-band-plan.d.ts +10 -0
- package/dist/pdf/table-band-plan.js +83 -0
- package/dist/pdf/table-layout.d.ts +75 -0
- package/dist/pdf/table-layout.js +217 -0
- package/dist/pdf/table-structure.d.ts +1 -0
- package/dist/pdf/table-structure.js +108 -0
- package/dist/pdf/text-shaping-types.d.ts +39 -0
- package/dist/pdf/text-shaping-types.js +1 -0
- package/dist/pdf/text.d.ts +13 -0
- package/dist/pdf/text.js +101 -0
- package/dist/pdf/truetype-subset.d.ts +5 -0
- package/dist/pdf/truetype-subset.js +217 -0
- package/dist/pdf/truetype.d.ts +1 -0
- package/dist/pdf/truetype.js +235 -0
- package/dist/pdf/types.d.ts +171 -0
- package/dist/pdf/types.js +1 -0
- package/dist/pdf/write.d.ts +6 -0
- package/dist/pdf/write.js +57 -0
- package/dist/pdf/xref.d.ts +1 -0
- package/dist/pdf/xref.js +30 -0
- package/dist/xlsx/attachments.d.ts +30 -0
- package/dist/xlsx/attachments.js +67 -0
- package/dist/xlsx/chart-bindings.d.ts +1 -0
- package/dist/xlsx/chart-bindings.js +122 -0
- package/dist/xlsx/chart-types.d.ts +73 -0
- package/dist/xlsx/chart-types.js +1 -0
- package/dist/xlsx/chart-xml.d.ts +2 -0
- package/dist/xlsx/chart-xml.js +103 -0
- package/dist/xlsx/charts.d.ts +1 -0
- package/dist/xlsx/charts.js +159 -0
- package/dist/xlsx/conditional-formatting.d.ts +1 -0
- package/dist/xlsx/conditional-formatting.js +158 -0
- package/dist/xlsx/conditional-types.d.ts +64 -0
- package/dist/xlsx/conditional-types.js +1 -0
- package/dist/xlsx/data-row-ranges.d.ts +5 -0
- package/dist/xlsx/data-row-ranges.js +39 -0
- package/dist/xlsx/differential-styles.d.ts +1 -0
- package/dist/xlsx/differential-styles.js +102 -0
- package/dist/xlsx/formula.d.ts +8 -0
- package/dist/xlsx/formula.js +104 -0
- package/dist/xlsx/grouped-layout.d.ts +61 -0
- package/dist/xlsx/grouped-layout.js +79 -0
- package/dist/xlsx/grouped.d.ts +16 -0
- package/dist/xlsx/grouped.js +161 -0
- package/dist/xlsx/index.d.ts +24 -0
- package/dist/xlsx/index.js +10 -0
- package/dist/xlsx/layout.d.ts +1 -0
- package/dist/xlsx/layout.js +186 -0
- package/dist/xlsx/options.d.ts +1 -0
- package/dist/xlsx/options.js +16 -0
- package/dist/xlsx/portable.d.ts +27 -0
- package/dist/xlsx/portable.js +44 -0
- package/dist/xlsx/preservation.d.ts +1 -0
- package/dist/xlsx/preservation.js +60 -0
- package/dist/xlsx/ranges.d.ts +1 -0
- package/dist/xlsx/ranges.js +24 -0
- package/dist/xlsx/regions.d.ts +1 -0
- package/dist/xlsx/regions.js +97 -0
- package/dist/xlsx/structured-rows.d.ts +11 -0
- package/dist/xlsx/structured-rows.js +28 -0
- package/dist/xlsx/style-xml.d.ts +1 -0
- package/dist/xlsx/style-xml.js +6 -0
- package/dist/xlsx/styles.d.ts +70 -0
- package/dist/xlsx/styles.js +203 -0
- package/dist/xlsx/table.d.ts +12 -0
- package/dist/xlsx/table.js +35 -0
- package/dist/xlsx/types.d.ts +180 -0
- package/dist/xlsx/types.js +1 -0
- package/dist/xlsx/validation-types.d.ts +18 -0
- package/dist/xlsx/validation-types.js +1 -0
- package/dist/xlsx/validation.d.ts +1 -0
- package/dist/xlsx/validation.js +92 -0
- package/dist/xlsx/values.d.ts +13 -0
- package/dist/xlsx/values.js +87 -0
- package/dist/xlsx/workbook.d.ts +50 -0
- package/dist/xlsx/workbook.js +452 -0
- package/dist/xlsx/worksheet.d.ts +71 -0
- package/dist/xlsx/worksheet.js +700 -0
- package/dist/xlsx/write.d.ts +15 -0
- package/dist/xlsx/write.js +47 -0
- package/dist/xml/index.d.ts +24 -0
- package/dist/xml/index.js +74 -0
- package/dist/zip/entry.d.ts +39 -0
- package/dist/zip/entry.js +122 -0
- package/dist/zip/index.d.ts +44 -0
- package/dist/zip/index.js +248 -0
- package/package.json +104 -4
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
2
|
+
import { checkAbort } from "../core/iteration.js";
|
|
3
|
+
import { unicodeHex } from "./objects.js";
|
|
4
|
+
import { PdfParentTree } from "./structure-parent-tree.js";
|
|
5
|
+
/** Same-page marked content uses integer K; cross-page MCR and annotation OBJR stay explicit. */
|
|
6
|
+
function structureChild(child) {
|
|
7
|
+
return typeof child === "number" ? (child < 0 ? -child - 1 + " " : child + " 0 R ") : child + " ";
|
|
8
|
+
}
|
|
9
|
+
function structurePrefix(element) {
|
|
10
|
+
return "<< /Type /StructElem /S /" + element.role + " /P " + element.parent + " 0 R" +
|
|
11
|
+
(element.markedPage === undefined ? "" : " /Pg " + element.markedPage + " 0 R") +
|
|
12
|
+
(element.identifier === undefined ? "" : " /ID (" + element.identifier + ")") + " /K [";
|
|
13
|
+
}
|
|
14
|
+
/** Keep the same bounded small-object representation for both completion paths. */
|
|
15
|
+
function compactStructureBody(element, prefix) {
|
|
16
|
+
const remaining = 32768 - prefix.length - element.attributes.length - 4;
|
|
17
|
+
if (remaining < 0)
|
|
18
|
+
return undefined;
|
|
19
|
+
let children = "";
|
|
20
|
+
for (const child of element.children) {
|
|
21
|
+
const token = structureChild(child);
|
|
22
|
+
if (children.length + token.length > remaining)
|
|
23
|
+
return undefined;
|
|
24
|
+
children += token;
|
|
25
|
+
}
|
|
26
|
+
return prefix + children + "]" + element.attributes + " >>";
|
|
27
|
+
}
|
|
28
|
+
/** A sorted name tree retains only a small open leaf and branch at each level. */
|
|
29
|
+
class PdfStructureIds {
|
|
30
|
+
objects;
|
|
31
|
+
root;
|
|
32
|
+
entries = [];
|
|
33
|
+
levels = [];
|
|
34
|
+
lastKey = "";
|
|
35
|
+
constructor(objects, root) {
|
|
36
|
+
this.objects = objects;
|
|
37
|
+
this.root = root;
|
|
38
|
+
}
|
|
39
|
+
async append(key, value) {
|
|
40
|
+
if (key <= this.lastKey)
|
|
41
|
+
throw new Error("PDF structure IDs must be appended in increasing order.");
|
|
42
|
+
this.lastKey = key;
|
|
43
|
+
this.entries.push({ key, value });
|
|
44
|
+
if (this.entries.length === 64)
|
|
45
|
+
await this.leaf();
|
|
46
|
+
}
|
|
47
|
+
async leaf() {
|
|
48
|
+
if (!this.entries.length)
|
|
49
|
+
return;
|
|
50
|
+
const id = this.objects.reserve(), first = this.entries[0].key, last = this.entries.at(-1).key;
|
|
51
|
+
const body = "<< /Limits [(" + first + ") (" + last + ")] /Names [" +
|
|
52
|
+
this.entries.map(entry => "(" + entry.key + ") " + entry.value + " 0 R").join(" ") + "] >>";
|
|
53
|
+
this.entries.length = 0;
|
|
54
|
+
await this.objects.object(id, body);
|
|
55
|
+
await this.node({ id, first, last }, 0);
|
|
56
|
+
}
|
|
57
|
+
async node(node, level) {
|
|
58
|
+
const nodes = this.levels[level] ??= [];
|
|
59
|
+
nodes.push(node);
|
|
60
|
+
if (nodes.length === 64) {
|
|
61
|
+
const parent = await this.branch(nodes);
|
|
62
|
+
nodes.length = 0;
|
|
63
|
+
await this.node(parent, level + 1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async branch(nodes) {
|
|
67
|
+
const id = this.objects.reserve(), first = nodes[0].first, last = nodes.at(-1).last;
|
|
68
|
+
await this.objects.object(id, "<< /Limits [(" + first + ") (" + last + ")] /Kids [" +
|
|
69
|
+
nodes.map(node => node.id + " 0 R").join(" ") + "] >>");
|
|
70
|
+
return { id, first, last };
|
|
71
|
+
}
|
|
72
|
+
async finish() {
|
|
73
|
+
await this.leaf();
|
|
74
|
+
for (let level = 0; level < this.levels.length - 1; level++) {
|
|
75
|
+
const nodes = this.levels[level];
|
|
76
|
+
if (nodes.length) {
|
|
77
|
+
const parent = await this.branch(nodes);
|
|
78
|
+
nodes.length = 0;
|
|
79
|
+
await this.node(parent, level + 1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const nodes = this.levels.at(-1) ?? [];
|
|
83
|
+
await this.objects.object(this.root, nodes.length ? "<< /Kids [" + nodes.map(node => node.id + " 0 R").join(" ") + "] >>" : "<< /Names [] >>");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** @internal Only open logical elements retain content; completed subtrees retain compact parent references. */
|
|
87
|
+
export class PdfStructure {
|
|
88
|
+
objects;
|
|
89
|
+
settings;
|
|
90
|
+
root;
|
|
91
|
+
document;
|
|
92
|
+
parentTree;
|
|
93
|
+
elements = new Map();
|
|
94
|
+
parentTreeWriter;
|
|
95
|
+
annotations = [];
|
|
96
|
+
links = new WeakMap();
|
|
97
|
+
identifiers;
|
|
98
|
+
pageParents = [];
|
|
99
|
+
pageId = 0;
|
|
100
|
+
pageKey = 0;
|
|
101
|
+
nextParentKey = 0;
|
|
102
|
+
references = 0;
|
|
103
|
+
allocated = 0;
|
|
104
|
+
section;
|
|
105
|
+
constructor(objects, settings) {
|
|
106
|
+
this.objects = objects;
|
|
107
|
+
this.settings = settings;
|
|
108
|
+
this.root = objects.reserve();
|
|
109
|
+
this.parentTree = objects.reserve();
|
|
110
|
+
this.parentTreeWriter = new PdfParentTree(objects, this.parentTree);
|
|
111
|
+
this.document = this.element("Document", this.root);
|
|
112
|
+
}
|
|
113
|
+
element(role, parent = this.section ?? this.document, attributes = "") {
|
|
114
|
+
checkAbort(this.settings.options.signal);
|
|
115
|
+
if (++this.allocated > this.settings.limits.maxStructureElements)
|
|
116
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxStructureElements exceeded.");
|
|
117
|
+
const id = this.objects.reserve(), element = { id, parent, role, children: [], attributes };
|
|
118
|
+
this.elements.set(id, element);
|
|
119
|
+
const owner = this.elements.get(parent);
|
|
120
|
+
// A continuation-only linked caption is discovered during painting, after rows may exist.
|
|
121
|
+
// Its one logical Caption still precedes the Table's rows; other owners retain source order.
|
|
122
|
+
if (role === "Caption" && owner?.role === "Table")
|
|
123
|
+
owner.children.unshift(id);
|
|
124
|
+
else
|
|
125
|
+
owner?.children.push(id);
|
|
126
|
+
return id;
|
|
127
|
+
}
|
|
128
|
+
/** Attach resolved table associations while a source-ordered logical element is still open. */
|
|
129
|
+
setAttributes(elementId, attributes) {
|
|
130
|
+
const element = this.elements.get(elementId);
|
|
131
|
+
if (!element)
|
|
132
|
+
throw new Error("PDF structure attributes require an open logical owner.");
|
|
133
|
+
element.attributes = attributes;
|
|
134
|
+
}
|
|
135
|
+
/** Write one immutable attribute dictionary. Its caller owns the bounded scope of reference reuse. */
|
|
136
|
+
async attributeReference(dictionary) {
|
|
137
|
+
checkAbort(this.settings.options.signal);
|
|
138
|
+
const id = this.objects.reserve();
|
|
139
|
+
await this.objects.object(id, dictionary);
|
|
140
|
+
return " /A " + id + " 0 R";
|
|
141
|
+
}
|
|
142
|
+
/** Flat visual sections share the same logical Document and cumulative resource policy. */
|
|
143
|
+
async beginSection() {
|
|
144
|
+
await this.complete(this.section);
|
|
145
|
+
this.section = this.element("Sect", this.document);
|
|
146
|
+
}
|
|
147
|
+
/** Register an explicit header identity in allocation order, without retaining completed headers. */
|
|
148
|
+
async identifier(elementId) {
|
|
149
|
+
checkAbort(this.settings.options.signal);
|
|
150
|
+
const element = this.elements.get(elementId);
|
|
151
|
+
if (!element)
|
|
152
|
+
throw new Error("PDF structure IDs require an open logical owner.");
|
|
153
|
+
if (element.identifier !== undefined)
|
|
154
|
+
return element.identifier;
|
|
155
|
+
// Object numbers increase monotonically. Fixed-width ASCII preserves name-tree lexical ordering.
|
|
156
|
+
const identifier = "e" + String(elementId).padStart(16, "0");
|
|
157
|
+
this.identifiers ??= new PdfStructureIds(this.objects, this.objects.reserve());
|
|
158
|
+
await this.identifiers.append(identifier, elementId);
|
|
159
|
+
element.identifier = identifier;
|
|
160
|
+
return identifier;
|
|
161
|
+
}
|
|
162
|
+
beginPage(pageId) { this.pageId = pageId; this.pageParents = []; this.pageKey = this.nextParentKey++; }
|
|
163
|
+
/** A source link retains one logical identity when its text/annotation continues on another page. */
|
|
164
|
+
link(parent, identity, alternativeText) {
|
|
165
|
+
let parents = this.links.get(identity);
|
|
166
|
+
if (!parents) {
|
|
167
|
+
parents = new Map();
|
|
168
|
+
this.links.set(identity, parents);
|
|
169
|
+
}
|
|
170
|
+
const existing = parents.get(parent);
|
|
171
|
+
if (existing !== undefined)
|
|
172
|
+
return existing;
|
|
173
|
+
const id = this.element("Link", parent, alternativeText === undefined ? "" : " /Alt <feff" + unicodeHex(alternativeText) + ">");
|
|
174
|
+
parents.set(parent, id);
|
|
175
|
+
const owner = this.elements.get(parent);
|
|
176
|
+
(owner.linkIdentities ??= []).push(identity);
|
|
177
|
+
return id;
|
|
178
|
+
}
|
|
179
|
+
/** Associate a native annotation in both directions: OBJR child and annotation ParentTree entry. */
|
|
180
|
+
annotation(elementId, annotationId) {
|
|
181
|
+
checkAbort(this.settings.options.signal);
|
|
182
|
+
const element = this.elements.get(elementId);
|
|
183
|
+
if (!element || element.role !== "Link")
|
|
184
|
+
throw new Error("Tagged link annotations require a logical Link owner.");
|
|
185
|
+
const key = this.nextParentKey++;
|
|
186
|
+
element.children.push("<< /Type /OBJR /Obj " + annotationId + " 0 R /Pg " + this.pageId + " 0 R >>");
|
|
187
|
+
this.annotations.push({ key, owner: elementId });
|
|
188
|
+
return key;
|
|
189
|
+
}
|
|
190
|
+
/** Every MCID is local to its page; its parent entry points back to the owning logical element. */
|
|
191
|
+
mark(elementId, actualText) {
|
|
192
|
+
if (++this.references > this.settings.limits.maxMarkedContentReferences)
|
|
193
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxMarkedContentReferences exceeded.");
|
|
194
|
+
const element = this.elements.get(elementId);
|
|
195
|
+
if (!element)
|
|
196
|
+
throw new Error("Marked content requires an open logical owner.");
|
|
197
|
+
const mcid = this.pageParents.length;
|
|
198
|
+
this.pageParents.push(elementId);
|
|
199
|
+
element.markedPage ??= this.pageId;
|
|
200
|
+
element.children.push(element.markedPage === this.pageId ? -(mcid + 1) :
|
|
201
|
+
"<< /Type /MCR /Pg " + this.pageId + " 0 R /MCID " + mcid + " >>");
|
|
202
|
+
return "/" + element.role + " << /MCID " + mcid + (actualText === undefined ? "" : " /ActualText <FEFF" + unicodeHex(actualText) + ">") + " >> BDC\n";
|
|
203
|
+
}
|
|
204
|
+
get pageDictionary() { return " /StructParents " + this.pageKey + " /Tabs /S"; }
|
|
205
|
+
get catalogDictionary() {
|
|
206
|
+
return " /MarkInfo << /Marked true >> /Lang <feff" + unicodeHex(this.settings.options.tagged.language) + "> /StructTreeRoot " + this.root + " 0 R";
|
|
207
|
+
}
|
|
208
|
+
async finishPage() {
|
|
209
|
+
const array = this.objects.reserve();
|
|
210
|
+
await this.objects.object(array, "[" + this.pageParents.map(id => id + " 0 R").join(" ") + "]");
|
|
211
|
+
await this.parentTreeWriter.append(this.pageKey, array);
|
|
212
|
+
for (const annotation of this.annotations)
|
|
213
|
+
await this.parentTreeWriter.append(annotation.key, annotation.owner);
|
|
214
|
+
this.annotations.length = 0;
|
|
215
|
+
this.pageParents = [];
|
|
216
|
+
}
|
|
217
|
+
/** Complete only after the last fragment/annotation; split content keeps the same owner until then. */
|
|
218
|
+
async complete(id) {
|
|
219
|
+
if (id === undefined)
|
|
220
|
+
return;
|
|
221
|
+
const element = this.elements.get(id);
|
|
222
|
+
if (!element)
|
|
223
|
+
return;
|
|
224
|
+
for (const child of element.children)
|
|
225
|
+
if (typeof child === "number" && child > 0 && !this.completeBuffered(child))
|
|
226
|
+
await this.complete(child);
|
|
227
|
+
checkAbort(this.settings.options.signal);
|
|
228
|
+
const prefix = structurePrefix(element), body = compactStructureBody(element, prefix);
|
|
229
|
+
// Most table cells/rows fit in one encoding. Large parents and alternatives remain streamed.
|
|
230
|
+
if (body !== undefined) {
|
|
231
|
+
if (!this.objects.tryCompactObject(id, body))
|
|
232
|
+
await this.objects.compactObject(id, body);
|
|
233
|
+
}
|
|
234
|
+
else
|
|
235
|
+
await this.objects.object(id, this.body(element, prefix));
|
|
236
|
+
this.releaseElement(element);
|
|
237
|
+
}
|
|
238
|
+
/** Close already-bufferable children without creating an async chain per leaf. A false result
|
|
239
|
+
* leaves the current owner open for the existing awaited flush or ordinary-object path. */
|
|
240
|
+
completeBuffered(id) {
|
|
241
|
+
const element = this.elements.get(id);
|
|
242
|
+
if (!element)
|
|
243
|
+
return true;
|
|
244
|
+
for (const child of element.children)
|
|
245
|
+
if (typeof child === "number" && child > 0 && !this.completeBuffered(child))
|
|
246
|
+
return false;
|
|
247
|
+
checkAbort(this.settings.options.signal);
|
|
248
|
+
const body = compactStructureBody(element, structurePrefix(element));
|
|
249
|
+
if (body === undefined || !this.objects.tryCompactObject(id, body))
|
|
250
|
+
return false;
|
|
251
|
+
this.releaseElement(element);
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
releaseElement(element) {
|
|
255
|
+
if (element.linkIdentities)
|
|
256
|
+
for (const identity of element.linkIdentities) {
|
|
257
|
+
const parents = this.links.get(identity);
|
|
258
|
+
parents?.delete(element.id);
|
|
259
|
+
if (!parents?.size)
|
|
260
|
+
this.links.delete(identity);
|
|
261
|
+
}
|
|
262
|
+
this.elements.delete(element.id);
|
|
263
|
+
}
|
|
264
|
+
*body(element, prefix) {
|
|
265
|
+
yield prefix;
|
|
266
|
+
for (const child of element.children)
|
|
267
|
+
yield structureChild(child);
|
|
268
|
+
yield "]" + element.attributes + " >>";
|
|
269
|
+
}
|
|
270
|
+
async completeRow(cells) {
|
|
271
|
+
if (cells?.length)
|
|
272
|
+
await this.complete(this.elements.get(cells[0])?.parent);
|
|
273
|
+
}
|
|
274
|
+
async finish() {
|
|
275
|
+
await this.complete(this.document);
|
|
276
|
+
await this.parentTreeWriter.finish();
|
|
277
|
+
await this.identifiers?.finish();
|
|
278
|
+
await this.objects.object(this.root, "<< /Type /StructTreeRoot /K [" + this.document + " 0 R] /ParentTree " +
|
|
279
|
+
this.parentTree + " 0 R /ParentTreeNextKey " + this.nextParentKey +
|
|
280
|
+
(this.identifiers ? " /IDTree " + this.identifiers.root + " 0 R" : "") + " >>");
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/** Validate author intent even in untagged output so a later opt-in cannot silently change meaning. */
|
|
284
|
+
export function graphicAlternative(value, settings) {
|
|
285
|
+
const decorative = value.decorative, alternativeText = value.alternativeText;
|
|
286
|
+
if (decorative !== undefined && typeof decorative !== "boolean")
|
|
287
|
+
throw new TypeError("Graphic decorative must be boolean.");
|
|
288
|
+
if (alternativeText !== undefined) {
|
|
289
|
+
if (typeof alternativeText !== "string" || !alternativeText.trim())
|
|
290
|
+
throw new TypeError("Graphic alternativeText must be nonempty text.");
|
|
291
|
+
if (alternativeText.length > settings.limits.maxCellCharacters)
|
|
292
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded by graphic alternativeText.");
|
|
293
|
+
unicodeHex(alternativeText);
|
|
294
|
+
if (decorative)
|
|
295
|
+
throw new TypeError("A decorative graphic cannot also have alternativeText.");
|
|
296
|
+
}
|
|
297
|
+
if (settings.options.tagged && alternativeText === undefined && decorative !== true)
|
|
298
|
+
throw new TypeError("Tagged PDF graphics require alternativeText or decorative:true.");
|
|
299
|
+
if (settings.options.tagged && alternativeText !== undefined)
|
|
300
|
+
settings.budget.cell(alternativeText);
|
|
301
|
+
return alternativeText;
|
|
302
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PdfLayoutRow, PdfTableLayout } from "./table-layout.js";
|
|
2
|
+
import type { PdfPreparedParagraph } from "./paragraph-layout.js";
|
|
3
|
+
interface BandWindowPainter {
|
|
4
|
+
prepareRow?(row: PdfLayoutRow): Promise<void>;
|
|
5
|
+
completeRow?(row: PdfLayoutRow): Promise<void>;
|
|
6
|
+
readonly firstCapacity: number;
|
|
7
|
+
readonly firstFullCapacity: number;
|
|
8
|
+
moveFirstToFreshPage(): Promise<void>;
|
|
9
|
+
readonly continuationCapacity: number;
|
|
10
|
+
paint(band: number, headers: readonly PdfLayoutRow[], rows: readonly PdfLayoutRow[], caption: PdfPreparedParagraph | undefined, firstWindow: boolean, firstBand: boolean): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/** One source pass and one bounded window. A slow sink is awaited before accepting further source rows.
|
|
13
|
+
* Data projection, formatting and numeric totals belong to the logical layout, never the physical bands. */
|
|
14
|
+
export declare class PdfTableBandFlow {
|
|
15
|
+
private readonly layout;
|
|
16
|
+
private readonly headings;
|
|
17
|
+
private readonly painter;
|
|
18
|
+
private readonly caption?;
|
|
19
|
+
private readonly continuation?;
|
|
20
|
+
private entries;
|
|
21
|
+
private height;
|
|
22
|
+
private count;
|
|
23
|
+
private firstWindow;
|
|
24
|
+
private firstCapacity;
|
|
25
|
+
private painted;
|
|
26
|
+
constructor(layout: PdfTableLayout, headings: readonly (readonly PdfLayoutRow[])[], painter: BandWindowPainter, caption?: PdfPreparedParagraph | undefined, continuation?: PdfPreparedParagraph | undefined);
|
|
27
|
+
private get capacity();
|
|
28
|
+
private accept;
|
|
29
|
+
row(row: PdfLayoutRow, allowFirstFragment?: boolean): Promise<void>;
|
|
30
|
+
block(rows: readonly PdfLayoutRow[]): Promise<void>;
|
|
31
|
+
keptRows(rows: readonly PdfLayoutRow[], allowFirstFragment?: boolean): Promise<void>;
|
|
32
|
+
flush(forceHeadings?: boolean): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
2
|
+
import { checkAbort } from "../core/iteration.js";
|
|
3
|
+
/** One source pass and one bounded window. A slow sink is awaited before accepting further source rows.
|
|
4
|
+
* Data projection, formatting and numeric totals belong to the logical layout, never the physical bands. */
|
|
5
|
+
export class PdfTableBandFlow {
|
|
6
|
+
layout;
|
|
7
|
+
headings;
|
|
8
|
+
painter;
|
|
9
|
+
caption;
|
|
10
|
+
continuation;
|
|
11
|
+
entries = [];
|
|
12
|
+
height = 0;
|
|
13
|
+
count = 0;
|
|
14
|
+
firstWindow = true;
|
|
15
|
+
firstCapacity;
|
|
16
|
+
painted = false;
|
|
17
|
+
constructor(layout, headings, painter, caption, continuation) {
|
|
18
|
+
this.layout = layout;
|
|
19
|
+
this.headings = headings;
|
|
20
|
+
this.painter = painter;
|
|
21
|
+
this.caption = caption;
|
|
22
|
+
this.continuation = continuation;
|
|
23
|
+
this.firstCapacity = painter.firstCapacity;
|
|
24
|
+
}
|
|
25
|
+
get capacity() { return this.firstWindow ? this.firstCapacity : this.painter.continuationCapacity; }
|
|
26
|
+
async accept(entry) {
|
|
27
|
+
if (this.entries.length && (this.height + entry.height > this.capacity + .001 || this.count + entry.count > this.layout.settings.limits.maxTableWindowRows))
|
|
28
|
+
await this.flush();
|
|
29
|
+
if (this.firstWindow && !this.entries.length && entry.height > this.capacity + .001 && entry.height <= this.painter.firstFullCapacity + .001) {
|
|
30
|
+
await this.painter.moveFirstToFreshPage();
|
|
31
|
+
this.firstCapacity = this.painter.firstFullCapacity;
|
|
32
|
+
}
|
|
33
|
+
if (entry.height > this.capacity + .001)
|
|
34
|
+
throw new RangeError("PDF band window cannot fit the requested table fragment.");
|
|
35
|
+
this.entries.push(entry);
|
|
36
|
+
this.height += entry.height;
|
|
37
|
+
this.count += entry.count;
|
|
38
|
+
if (this.count >= this.layout.settings.limits.maxTableWindowRows)
|
|
39
|
+
await this.flush();
|
|
40
|
+
}
|
|
41
|
+
async row(row, allowFirstFragment = false) {
|
|
42
|
+
const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
|
|
43
|
+
if (minimumHeight > this.painter.firstFullCapacity + .001 || minimumHeight > this.painter.continuationCapacity + .001)
|
|
44
|
+
throw new RangeError("Repeated PDF identifiers must fit intact below the first and continued band headings/context.");
|
|
45
|
+
// Keep ordinary rows intact when they fit fresh. A kept heading/caption can deliberately
|
|
46
|
+
// retain the first fragment here instead of being orphaned by a later table-only page move.
|
|
47
|
+
if (this.entries.length && row.height <= this.painter.continuationCapacity + .001 && row.height > this.capacity - this.height + .001)
|
|
48
|
+
await this.flush();
|
|
49
|
+
if (!allowFirstFragment && this.firstWindow && !this.entries.length && row.height > this.capacity + .001 && row.height <= this.painter.firstFullCapacity + .001) {
|
|
50
|
+
await this.painter.moveFirstToFreshPage();
|
|
51
|
+
this.firstCapacity = this.painter.firstFullCapacity;
|
|
52
|
+
}
|
|
53
|
+
await this.painter.prepareRow?.(row);
|
|
54
|
+
let first = 0;
|
|
55
|
+
while (first < row.lines) {
|
|
56
|
+
checkAbort(options.signal);
|
|
57
|
+
if (this.entries.length && this.capacity - this.height + .001 < minimumHeight)
|
|
58
|
+
await this.flush();
|
|
59
|
+
if (this.firstWindow && !this.entries.length && this.capacity + .001 < minimumHeight) {
|
|
60
|
+
await this.painter.moveFirstToFreshPage();
|
|
61
|
+
this.firstCapacity = this.painter.firstFullCapacity;
|
|
62
|
+
}
|
|
63
|
+
if (this.capacity - this.height + .001 < minimumHeight)
|
|
64
|
+
throw new RangeError("PDF band window cannot fit its complete repeated identifiers.");
|
|
65
|
+
const lines = Math.min(row.lines - first, Math.floor((this.capacity - this.height - padding * 2 + .001) / row.lineHeight));
|
|
66
|
+
if (lines < 1)
|
|
67
|
+
throw new RangeError("PDF page cannot fit a table line below horizontal band headings.");
|
|
68
|
+
// Reserve one shared logical fragment, but paint only each band's visible cell geometry.
|
|
69
|
+
const reservedLines = Math.max(lines, minimumLines), height = reservedLines * row.lineHeight + padding * 2;
|
|
70
|
+
const projected = await this.layout.bandRows([row]);
|
|
71
|
+
const exhaustedBands = [];
|
|
72
|
+
const fragments = projected.map((rows, index) => {
|
|
73
|
+
let remaining = false;
|
|
74
|
+
const cells = rows[0].cells.map(cell => {
|
|
75
|
+
const source = this.layout.bands[index].columns[cell.first];
|
|
76
|
+
const repeated = this.layout.repeatedColumn(source), visible = repeated ? cell.lines : cell.lines.slice(first, first + lines);
|
|
77
|
+
if (!repeated && (visible.length > 0 || cell.link !== undefined))
|
|
78
|
+
remaining = true;
|
|
79
|
+
const { height: _height, ...plain } = cell;
|
|
80
|
+
return { ...plain, lines: visible,
|
|
81
|
+
lineHeight: visible.reduce((value, line) => Math.max(value, line.lineHeight), cell.font.lineHeight(fontSize)),
|
|
82
|
+
...(first > 0 && repeated ? { semanticArtifact: true } : {}) };
|
|
83
|
+
});
|
|
84
|
+
const fragmentLines = Math.max(1, ...cells.map(cell => cell.lines.length));
|
|
85
|
+
const lineHeight = Math.max(this.layout.lineHeight, ...cells.filter(cell => cell.lines.length > 0).map(cell => cell.lineHeight));
|
|
86
|
+
// Never omit an initial/new row, a structured block, or a nonrepeated link obligation.
|
|
87
|
+
exhaustedBands.push(first > 0 && !remaining);
|
|
88
|
+
return [{ ...rows[0], cells, lines: fragmentLines, lineHeight, height: fragmentLines * lineHeight + padding * 2 }];
|
|
89
|
+
});
|
|
90
|
+
await this.accept({ rows: fragments, height, count: 1, completed: first + lines >= row.lines ? [row] : [], exhaustedBands });
|
|
91
|
+
first += lines;
|
|
92
|
+
if (first < row.lines)
|
|
93
|
+
await this.flush();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async block(rows) {
|
|
97
|
+
const projected = await this.layout.bandRows(rows, true), height = projected[0].reduce((sum, row) => sum + row.height, 0);
|
|
98
|
+
if (rows.length > this.layout.settings.limits.maxTableWindowRows)
|
|
99
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "A structured PDF block exceeds maxTableWindowRows.");
|
|
100
|
+
for (const row of rows)
|
|
101
|
+
await this.painter.prepareRow?.(row);
|
|
102
|
+
await this.accept({ rows: projected, height, count: rows.length, completed: rows, exhaustedBands: projected.map(() => false) });
|
|
103
|
+
}
|
|
104
|
+
async keptRows(rows, allowFirstFragment = false) {
|
|
105
|
+
const height = rows.reduce((sum, row) => sum + row.height, 0), fits = height <= this.painter.continuationCapacity + .001;
|
|
106
|
+
if (this.entries.length && fits && height > this.capacity - this.height + .001)
|
|
107
|
+
await this.flush();
|
|
108
|
+
for (const [index, row] of rows.entries())
|
|
109
|
+
await this.row(row, !fits && index === 0 && allowFirstFragment);
|
|
110
|
+
}
|
|
111
|
+
async flush(forceHeadings = false) {
|
|
112
|
+
if (!this.entries.length && (!forceHeadings || this.painted || !this.headings.some(rows => rows.length)))
|
|
113
|
+
return;
|
|
114
|
+
for (let band = 0; band < this.layout.bands.length; band++) {
|
|
115
|
+
checkAbort(this.layout.settings.options.signal);
|
|
116
|
+
if (!this.firstWindow && this.entries.length > 0 && this.entries.every(entry => entry.exhaustedBands[band]))
|
|
117
|
+
continue;
|
|
118
|
+
await this.painter.paint(band, this.headings[band], this.entries.flatMap(entry => entry.rows[band]), this.firstWindow ? this.caption : this.continuation, this.firstWindow, band === 0);
|
|
119
|
+
}
|
|
120
|
+
for (const entry of this.entries)
|
|
121
|
+
for (const row of entry.completed)
|
|
122
|
+
await this.painter.completeRow?.(row);
|
|
123
|
+
this.entries = [];
|
|
124
|
+
this.height = 0;
|
|
125
|
+
this.count = 0;
|
|
126
|
+
this.firstWindow = false;
|
|
127
|
+
this.painted = true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PdfSettings } from "./settings.js";
|
|
2
|
+
import type { PdfLayoutRow } from "./table-layout.js";
|
|
3
|
+
import type { PdfFontResources } from "./font-resources.js";
|
|
4
|
+
/** Plan without opening a source. Exact column widths never shrink in band mode. */
|
|
5
|
+
export declare function planTableBands(widths: readonly number[], settings: PdfSettings): readonly PdfTableBand[] | undefined;
|
|
6
|
+
/** A span crossing a band boundary repeats its captured text at each visible intersection.
|
|
7
|
+
* Runs/formatters are never recaptured, and vertical spans retain their original row ownership. */
|
|
8
|
+
export declare function projectBandRows(rows: readonly PdfLayoutRow[], band: PdfTableBand, widths: readonly number[], settings: PdfSettings, fonts: PdfFontResources): Promise<readonly PdfLayoutRow[]>;
|
|
9
|
+
/** Equal row heights across every physical band keep structured headings and row windows aligned. */
|
|
10
|
+
export declare function alignBandBlocks(bands: readonly (readonly PdfLayoutRow[])[], settings: PdfSettings): readonly (readonly PdfLayoutRow[])[];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
2
|
+
import { wrapPdfText } from "./inline-text.js";
|
|
3
|
+
/** Plan without opening a source. Exact column widths never shrink in band mode. */
|
|
4
|
+
export function planTableBands(widths, settings) {
|
|
5
|
+
const policy = settings.options.wideTable;
|
|
6
|
+
if (typeof policy !== "object")
|
|
7
|
+
return undefined;
|
|
8
|
+
const available = settings.page.width - settings.margins.left - settings.margins.right, repeats = settings.repeatedColumns;
|
|
9
|
+
const repeated = new Set(repeats), rest = widths.map((_, index) => index).filter(index => !repeated.has(index));
|
|
10
|
+
const prefix = repeats.reduce((sum, index) => sum + widths[index], 0);
|
|
11
|
+
if (prefix > available + .001)
|
|
12
|
+
throw new RangeError("Repeated PDF columns exceed the printable width.");
|
|
13
|
+
const groups = [];
|
|
14
|
+
let current = [...repeats], used = prefix;
|
|
15
|
+
for (const index of rest) {
|
|
16
|
+
const width = widths[index];
|
|
17
|
+
if (prefix + width > available + .001)
|
|
18
|
+
throw new RangeError("A PDF column and its repeated identifiers cannot fit a band.");
|
|
19
|
+
if (used + width > available + .001) {
|
|
20
|
+
groups.push(current);
|
|
21
|
+
current = [...repeats];
|
|
22
|
+
used = prefix;
|
|
23
|
+
}
|
|
24
|
+
current.push(index);
|
|
25
|
+
used += width;
|
|
26
|
+
}
|
|
27
|
+
if (current.length)
|
|
28
|
+
groups.push(current);
|
|
29
|
+
if (groups.length > settings.limits.maxTableBands)
|
|
30
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxTableBands exceeded.");
|
|
31
|
+
if (settings.limits.maxTableWindowRows < 1)
|
|
32
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxTableWindowRows must allow at least one row fragment.");
|
|
33
|
+
return Object.freeze(groups.map(columns => {
|
|
34
|
+
let x = settings.margins.left;
|
|
35
|
+
const lefts = columns.map(index => { const left = x; x += widths[index]; return left; });
|
|
36
|
+
return Object.freeze({ columns: Object.freeze(columns), lefts: Object.freeze(lefts) });
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
/** A span crossing a band boundary repeats its captured text at each visible intersection.
|
|
40
|
+
* Runs/formatters are never recaptured, and vertical spans retain their original row ownership. */
|
|
41
|
+
export async function projectBandRows(rows, band, widths, settings, fonts) {
|
|
42
|
+
const result = [];
|
|
43
|
+
for (const row of rows) {
|
|
44
|
+
const cells = [];
|
|
45
|
+
for (const cell of row.cells) {
|
|
46
|
+
for (let first = 0; first < band.columns.length;) {
|
|
47
|
+
const source = band.columns[first];
|
|
48
|
+
if (source < cell.first || source >= cell.first + cell.span) {
|
|
49
|
+
first++;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
let end = first + 1;
|
|
53
|
+
while (end < band.columns.length && band.columns[end] === band.columns[end - 1] + 1 && band.columns[end] < cell.first + cell.span)
|
|
54
|
+
end++;
|
|
55
|
+
const width = band.columns.slice(first, end).reduce((sum, index) => sum + widths[index], 0);
|
|
56
|
+
const lines = cell.span === 1 ? cell.lines : await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
|
|
57
|
+
cells.push({ ...cell, source: cell.source ?? cell, first, span: end - first, width, lines,
|
|
58
|
+
lineHeight: lines.reduce((height, line) => Math.max(height, line.lineHeight), cell.font.lineHeight(settings.fontSize)) });
|
|
59
|
+
first = end;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
cells.sort((a, b) => a.first - b.first);
|
|
63
|
+
result.push({ ...row, source: row.source ?? row, cells });
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
/** Equal row heights across every physical band keep structured headings and row windows aligned. */
|
|
68
|
+
export function alignBandBlocks(bands, settings) {
|
|
69
|
+
if (!bands.length || !bands[0].length)
|
|
70
|
+
return bands;
|
|
71
|
+
const rows = bands[0].length;
|
|
72
|
+
const heights = Array.from({ length: rows }, (_, index) => Math.max(...bands.map(band => Math.max(settings.padding * 2 + band[index].lineHeight, ...band[index].cells.filter(cell => (cell.rowSpan ?? 1) === 1).map(cell => cell.lines.length * cell.lineHeight + settings.padding * 2)))));
|
|
73
|
+
for (const band of bands)
|
|
74
|
+
for (const [index, row] of band.entries())
|
|
75
|
+
for (const cell of row.cells) {
|
|
76
|
+
const span = cell.rowSpan ?? 1, height = heights.slice(index, index + span).reduce((sum, value) => sum + value, 0), needed = cell.lines.length * cell.lineHeight + settings.padding * 2;
|
|
77
|
+
if (needed > height)
|
|
78
|
+
for (let i = index; i < index + span; i++)
|
|
79
|
+
heights[i] += (needed - height) / span;
|
|
80
|
+
}
|
|
81
|
+
return bands.map(band => band.map((row, index) => ({ ...row, structured: true, height: heights[index],
|
|
82
|
+
cells: row.cells.map(cell => ({ ...cell, height: heights.slice(index, index + (cell.rowSpan ?? 1)).reduce((sum, value) => sum + value, 0) })) })));
|
|
83
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ExportLink } from "../core/links.js";
|
|
2
|
+
import type { ExportValue, CellPresentation, TableSpanRows } from "../core/index.js";
|
|
3
|
+
import type { NumericAggregate } from "../internal/totals.js";
|
|
4
|
+
import type { PdfFontResources, PdfFontResource } from "./font-resources.js";
|
|
5
|
+
import type { PdfSettings } from "./settings.js";
|
|
6
|
+
import type { PdfTableBand } from "./table-band-plan.js";
|
|
7
|
+
import type { PdfCapturedText } from "./inline-text.js";
|
|
8
|
+
import type { PdfInlineLine } from "./inline-text.js";
|
|
9
|
+
export interface PdfLayoutCell {
|
|
10
|
+
/** Original source anchor when a captured cell is projected into a physical band. */
|
|
11
|
+
readonly source?: PdfLayoutCell;
|
|
12
|
+
/** Repeated visual content has no second logical reading occurrence. */
|
|
13
|
+
readonly semanticArtifact?: boolean;
|
|
14
|
+
/** Captured detail-column intent; headings and generated footer/summary values never inherit it. */
|
|
15
|
+
readonly rowHeader?: boolean;
|
|
16
|
+
readonly first: number;
|
|
17
|
+
readonly span: number;
|
|
18
|
+
readonly width: number;
|
|
19
|
+
readonly font: PdfFontResource;
|
|
20
|
+
readonly style: Readonly<CellPresentation>;
|
|
21
|
+
readonly lines: readonly PdfInlineLine[];
|
|
22
|
+
readonly lineHeight: number;
|
|
23
|
+
readonly rowSpan?: number;
|
|
24
|
+
readonly height?: number;
|
|
25
|
+
readonly link?: Readonly<ExportLink>;
|
|
26
|
+
/** Captured once for band span projection; ordinary layouts do not retain it. */
|
|
27
|
+
readonly captured?: PdfCapturedText;
|
|
28
|
+
}
|
|
29
|
+
export interface PdfLayoutRow {
|
|
30
|
+
readonly cells: readonly PdfLayoutCell[];
|
|
31
|
+
readonly lines: number;
|
|
32
|
+
readonly lineHeight: number;
|
|
33
|
+
readonly height: number;
|
|
34
|
+
readonly structured?: boolean;
|
|
35
|
+
/** Original logical row retained only by its bounded physical window. */
|
|
36
|
+
readonly source?: PdfLayoutRow;
|
|
37
|
+
}
|
|
38
|
+
interface HeadingCell {
|
|
39
|
+
readonly first: number;
|
|
40
|
+
readonly span: number;
|
|
41
|
+
readonly text: string;
|
|
42
|
+
}
|
|
43
|
+
export declare class PdfTableLayout {
|
|
44
|
+
readonly settings: PdfSettings;
|
|
45
|
+
readonly fonts: PdfFontResources;
|
|
46
|
+
readonly bands: readonly PdfTableBand[] | undefined;
|
|
47
|
+
readonly widths: readonly number[];
|
|
48
|
+
readonly lefts: readonly number[];
|
|
49
|
+
readonly lineHeight: number;
|
|
50
|
+
readonly headings: readonly (readonly HeadingCell[])[];
|
|
51
|
+
readonly totals: readonly NumericAggregate[];
|
|
52
|
+
private readonly repeatedColumns;
|
|
53
|
+
private readonly structuredBandRows;
|
|
54
|
+
/** Plain/alternate ordinary-data defaults, validated only when a column first needs them. */
|
|
55
|
+
private readonly dataPresentations;
|
|
56
|
+
constructor(settings: PdfSettings, fonts: PdfFontResources);
|
|
57
|
+
private cell;
|
|
58
|
+
private row;
|
|
59
|
+
headers(): Promise<readonly PdfLayoutRow[]>;
|
|
60
|
+
block(matrix: TableSpanRows, style: CellPresentation): Promise<readonly PdfLayoutRow[]>;
|
|
61
|
+
/** Repeated identifiers stay complete on every vertical fragment at the row's shared line height. */
|
|
62
|
+
minimumRowLines(row: PdfLayoutRow): number;
|
|
63
|
+
minimumRowHeight(row: PdfLayoutRow): number;
|
|
64
|
+
repeatedColumn(index: number): boolean;
|
|
65
|
+
/** Measure the physical block before kept content is painted. Structured band projections are
|
|
66
|
+
* shared with the painter, so measurement cannot disagree with narrower span intersections. */
|
|
67
|
+
blockHeight(rows: readonly PdfLayoutRow[]): Promise<number>;
|
|
68
|
+
/** Project already captured cells. Cache only bounded structured headings/footer matrices;
|
|
69
|
+
* ordinary data windows remain owned and released by PdfTableBandFlow. */
|
|
70
|
+
bandRows(rows: readonly PdfLayoutRow[], structured?: boolean): Promise<readonly (readonly PdfLayoutRow[])[]>;
|
|
71
|
+
private projectBandRows;
|
|
72
|
+
data(values: readonly ExportValue[], index: number, footer?: boolean): Promise<PdfLayoutRow>;
|
|
73
|
+
footer(index: number): Promise<readonly PdfLayoutRow[] | undefined>;
|
|
74
|
+
}
|
|
75
|
+
export {};
|