@evotecit/officeimo 0.1.0 → 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/README.md +13 -10
- package/bundles/officeimo-canopyx.js +813 -358
- package/bundles/officeimo-canopyx.mjs +700 -246
- package/bundles/officeimo-csv.js +29 -19
- package/bundles/officeimo-csv.mjs +17 -7
- package/bundles/officeimo-datatables.js +806 -360
- package/bundles/officeimo-datatables.mjs +694 -249
- package/bundles/officeimo-execution.js +35 -25
- package/bundles/officeimo-execution.mjs +17 -7
- package/bundles/officeimo-pdf.js +734 -289
- package/bundles/officeimo-pdf.mjs +685 -241
- package/bundles/officeimo-xlsx.js +88 -77
- package/bundles/officeimo-xlsx.mjs +22 -11
- package/bundles/officeimo.js +790 -344
- package/bundles/officeimo.mjs +680 -235
- package/dist/core/index.d.ts +2 -0
- package/dist/core/iteration.js +2 -2
- package/dist/core/sinks.js +2 -1
- package/dist/integrations/canopyx/source.js +13 -7
- package/dist/integrations/datatables/snapshot.js +3 -3
- package/dist/internal/rows.js +13 -4
- package/dist/pdf/document-grouped.js +72 -22
- package/dist/pdf/font-resources.js +2 -1
- package/dist/pdf/inline-text.js +50 -9
- package/dist/pdf/objects.js +188 -11
- package/dist/pdf/pages.js +25 -26
- package/dist/pdf/paragraph-layout.d.ts +2 -0
- package/dist/pdf/paragraph-layout.js +9 -4
- package/dist/pdf/session.js +1 -1
- package/dist/pdf/settings.d.ts +2 -0
- package/dist/pdf/settings.js +27 -2
- package/dist/pdf/structure.js +80 -28
- package/dist/pdf/table-band-flow.js +26 -11
- package/dist/pdf/table-band-plan.js +1 -3
- package/dist/pdf/table-layout.d.ts +4 -0
- package/dist/pdf/table-layout.js +22 -10
- package/dist/pdf/table-structure.js +28 -12
- package/dist/pdf/text.js +5 -0
- package/dist/pdf/types.d.ts +4 -2
- package/dist/pdf/xref.d.ts +1 -0
- package/dist/pdf/xref.js +30 -0
- package/dist/xlsx/values.js +3 -2
- package/dist/zip/entry.js +1 -1
- package/dist/zip/index.js +1 -1
- package/package.json +1 -1
package/dist/pdf/structure.js
CHANGED
|
@@ -2,6 +2,29 @@ import { OfficeIMOError } from "../core/errors.js";
|
|
|
2
2
|
import { checkAbort } from "../core/iteration.js";
|
|
3
3
|
import { unicodeHex } from "./objects.js";
|
|
4
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
|
+
}
|
|
5
28
|
/** A sorted name tree retains only a small open leaf and branch at each level. */
|
|
6
29
|
class PdfStructureIds {
|
|
7
30
|
objects;
|
|
@@ -91,7 +114,7 @@ export class PdfStructure {
|
|
|
91
114
|
checkAbort(this.settings.options.signal);
|
|
92
115
|
if (++this.allocated > this.settings.limits.maxStructureElements)
|
|
93
116
|
throw new OfficeIMOError("RESOURCE_LIMIT", "maxStructureElements exceeded.");
|
|
94
|
-
const id = this.objects.reserve(), element = { id, parent, role, children: [], attributes
|
|
117
|
+
const id = this.objects.reserve(), element = { id, parent, role, children: [], attributes };
|
|
95
118
|
this.elements.set(id, element);
|
|
96
119
|
const owner = this.elements.get(parent);
|
|
97
120
|
// A continuation-only linked caption is discovered during painting, after rows may exist.
|
|
@@ -102,6 +125,20 @@ export class PdfStructure {
|
|
|
102
125
|
owner?.children.push(id);
|
|
103
126
|
return id;
|
|
104
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
|
+
}
|
|
105
142
|
/** Flat visual sections share the same logical Document and cumulative resource policy. */
|
|
106
143
|
async beginSection() {
|
|
107
144
|
await this.complete(this.section);
|
|
@@ -135,7 +172,8 @@ export class PdfStructure {
|
|
|
135
172
|
return existing;
|
|
136
173
|
const id = this.element("Link", parent, alternativeText === undefined ? "" : " /Alt <feff" + unicodeHex(alternativeText) + ">");
|
|
137
174
|
parents.set(parent, id);
|
|
138
|
-
this.elements.get(parent)
|
|
175
|
+
const owner = this.elements.get(parent);
|
|
176
|
+
(owner.linkIdentities ??= []).push(identity);
|
|
139
177
|
return id;
|
|
140
178
|
}
|
|
141
179
|
/** Associate a native annotation in both directions: OBJR child and annotation ParentTree entry. */
|
|
@@ -158,7 +196,9 @@ export class PdfStructure {
|
|
|
158
196
|
throw new Error("Marked content requires an open logical owner.");
|
|
159
197
|
const mcid = this.pageParents.length;
|
|
160
198
|
this.pageParents.push(elementId);
|
|
161
|
-
element.
|
|
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 + " >>");
|
|
162
202
|
return "/" + element.role + " << /MCID " + mcid + (actualText === undefined ? "" : " /ActualText <FEFF" + unicodeHex(actualText) + ">") + " >> BDC\n";
|
|
163
203
|
}
|
|
164
204
|
get pageDictionary() { return " /StructParents " + this.pageKey + " /Tabs /S"; }
|
|
@@ -182,37 +222,49 @@ export class PdfStructure {
|
|
|
182
222
|
if (!element)
|
|
183
223
|
return;
|
|
184
224
|
for (const child of element.children)
|
|
185
|
-
if (typeof child === "number" && this.
|
|
225
|
+
if (typeof child === "number" && child > 0 && !this.completeBuffered(child))
|
|
186
226
|
await this.complete(child);
|
|
187
227
|
checkAbort(this.settings.options.signal);
|
|
188
|
-
const prefix =
|
|
189
|
-
(element.identifier === undefined ? "" : " /ID (" + element.identifier + ")") + " /K [";
|
|
190
|
-
const remaining = 32768 - prefix.length - element.attributes.length - 4;
|
|
191
|
-
let children = "", small = remaining >= 0;
|
|
192
|
-
if (small)
|
|
193
|
-
for (const child of element.children) {
|
|
194
|
-
const token = typeof child === "number" ? child + " 0 R " : child + " ";
|
|
195
|
-
if (children.length + token.length > remaining) {
|
|
196
|
-
small = false;
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
children += token;
|
|
200
|
-
}
|
|
228
|
+
const prefix = structurePrefix(element), body = compactStructureBody(element, prefix);
|
|
201
229
|
// Most table cells/rows fit in one encoding. Large parents and alternatives remain streamed.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
parents?.delete(id);
|
|
206
|
-
if (!parents?.size)
|
|
207
|
-
this.links.delete(identity);
|
|
230
|
+
if (body !== undefined) {
|
|
231
|
+
if (!this.objects.tryCompactObject(id, body))
|
|
232
|
+
await this.objects.compactObject(id, body);
|
|
208
233
|
}
|
|
209
|
-
|
|
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);
|
|
210
263
|
}
|
|
211
|
-
*body(element) {
|
|
212
|
-
yield
|
|
213
|
-
(element.identifier === undefined ? "" : " /ID (" + element.identifier + ")") + " /K [";
|
|
264
|
+
*body(element, prefix) {
|
|
265
|
+
yield prefix;
|
|
214
266
|
for (const child of element.children)
|
|
215
|
-
yield
|
|
267
|
+
yield structureChild(child);
|
|
216
268
|
yield "]" + element.attributes + " >>";
|
|
217
269
|
}
|
|
218
270
|
async completeRow(cells) {
|
|
@@ -39,7 +39,7 @@ export class PdfTableBandFlow {
|
|
|
39
39
|
await this.flush();
|
|
40
40
|
}
|
|
41
41
|
async row(row, allowFirstFragment = false) {
|
|
42
|
-
const { padding, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
|
|
42
|
+
const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
|
|
43
43
|
if (minimumHeight > this.painter.firstFullCapacity + .001 || minimumHeight > this.painter.continuationCapacity + .001)
|
|
44
44
|
throw new RangeError("Repeated PDF identifiers must fit intact below the first and continued band headings/context.");
|
|
45
45
|
// Keep ordinary rows intact when they fit fresh. A kept heading/caption can deliberately
|
|
@@ -65,16 +65,29 @@ export class PdfTableBandFlow {
|
|
|
65
65
|
const lines = Math.min(row.lines - first, Math.floor((this.capacity - this.height - padding * 2 + .001) / row.lineHeight));
|
|
66
66
|
if (lines < 1)
|
|
67
67
|
throw new RangeError("PDF page cannot fit a table line below horizontal band headings.");
|
|
68
|
-
|
|
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;
|
|
69
70
|
const projected = await this.layout.bandRows([row]);
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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 });
|
|
78
91
|
first += lines;
|
|
79
92
|
if (first < row.lines)
|
|
80
93
|
await this.flush();
|
|
@@ -86,7 +99,7 @@ export class PdfTableBandFlow {
|
|
|
86
99
|
throw new OfficeIMOError("RESOURCE_LIMIT", "A structured PDF block exceeds maxTableWindowRows.");
|
|
87
100
|
for (const row of rows)
|
|
88
101
|
await this.painter.prepareRow?.(row);
|
|
89
|
-
await this.accept({ rows: projected, height, count: rows.length, completed: rows });
|
|
102
|
+
await this.accept({ rows: projected, height, count: rows.length, completed: rows, exhaustedBands: projected.map(() => false) });
|
|
90
103
|
}
|
|
91
104
|
async keptRows(rows, allowFirstFragment = false) {
|
|
92
105
|
const height = rows.reduce((sum, row) => sum + row.height, 0), fits = height <= this.painter.continuationCapacity + .001;
|
|
@@ -100,6 +113,8 @@ export class PdfTableBandFlow {
|
|
|
100
113
|
return;
|
|
101
114
|
for (let band = 0; band < this.layout.bands.length; band++) {
|
|
102
115
|
checkAbort(this.layout.settings.options.signal);
|
|
116
|
+
if (!this.firstWindow && this.entries.length > 0 && this.entries.every(entry => entry.exhaustedBands[band]))
|
|
117
|
+
continue;
|
|
103
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);
|
|
104
119
|
}
|
|
105
120
|
for (const entry of this.entries)
|
|
@@ -5,9 +5,7 @@ export function planTableBands(widths, settings) {
|
|
|
5
5
|
const policy = settings.options.wideTable;
|
|
6
6
|
if (typeof policy !== "object")
|
|
7
7
|
return undefined;
|
|
8
|
-
const available = settings.page.width - settings.margins.left - settings.margins.right, repeats =
|
|
9
|
-
if (repeats.some(index => index >= widths.length))
|
|
10
|
-
throw new RangeError("repeatColumns index exceeds the declared columns.");
|
|
8
|
+
const available = settings.page.width - settings.margins.left - settings.margins.right, repeats = settings.repeatedColumns;
|
|
11
9
|
const repeated = new Set(repeats), rest = widths.map((_, index) => index).filter(index => !repeated.has(index));
|
|
12
10
|
const prefix = repeats.reduce((sum, index) => sum + widths[index], 0);
|
|
13
11
|
if (prefix > available + .001)
|
|
@@ -11,6 +11,8 @@ export interface PdfLayoutCell {
|
|
|
11
11
|
readonly source?: PdfLayoutCell;
|
|
12
12
|
/** Repeated visual content has no second logical reading occurrence. */
|
|
13
13
|
readonly semanticArtifact?: boolean;
|
|
14
|
+
/** Captured detail-column intent; headings and generated footer/summary values never inherit it. */
|
|
15
|
+
readonly rowHeader?: boolean;
|
|
14
16
|
readonly first: number;
|
|
15
17
|
readonly span: number;
|
|
16
18
|
readonly width: number;
|
|
@@ -49,6 +51,8 @@ export declare class PdfTableLayout {
|
|
|
49
51
|
readonly totals: readonly NumericAggregate[];
|
|
50
52
|
private readonly repeatedColumns;
|
|
51
53
|
private readonly structuredBandRows;
|
|
54
|
+
/** Plain/alternate ordinary-data defaults, validated only when a column first needs them. */
|
|
55
|
+
private readonly dataPresentations;
|
|
52
56
|
constructor(settings: PdfSettings, fonts: PdfFontResources);
|
|
53
57
|
private cell;
|
|
54
58
|
private row;
|
package/dist/pdf/table-layout.js
CHANGED
|
@@ -3,7 +3,7 @@ import { copyExportLink } from "../core/links.js";
|
|
|
3
3
|
import { tableSpans } from "../internal/table-spans.js";
|
|
4
4
|
import { createTotals } from "../internal/totals.js";
|
|
5
5
|
import { presentation, positive } from "./settings.js";
|
|
6
|
-
import { displayText } from "./text.js";
|
|
6
|
+
import { displayText, pdfBudgetText } from "./text.js";
|
|
7
7
|
import { capturePdfText, wrapPdfText } from "./inline-text.js";
|
|
8
8
|
import { planTableBands, projectBandRows, alignBandBlocks } from "./table-band-plan.js";
|
|
9
9
|
export class PdfTableLayout {
|
|
@@ -17,11 +17,13 @@ export class PdfTableLayout {
|
|
|
17
17
|
totals;
|
|
18
18
|
repeatedColumns;
|
|
19
19
|
structuredBandRows = new WeakMap();
|
|
20
|
+
/** Plain/alternate ordinary-data defaults, validated only when a column first needs them. */
|
|
21
|
+
dataPresentations = [];
|
|
20
22
|
constructor(settings, fonts) {
|
|
21
23
|
this.settings = settings;
|
|
22
24
|
this.fonts = fonts;
|
|
23
25
|
const { options, padding, fontSize, page, margins } = settings, columns = options.columns, available = page.width - margins.left - margins.right;
|
|
24
|
-
this.repeatedColumns = new Set(
|
|
26
|
+
this.repeatedColumns = new Set(settings.repeatedColumns);
|
|
25
27
|
let digit;
|
|
26
28
|
if (options.columnWidths && options.columnWidths.length !== columns.length)
|
|
27
29
|
throw new RangeError("columnWidths must declare one point width per column.");
|
|
@@ -62,13 +64,22 @@ export class PdfTableLayout {
|
|
|
62
64
|
this.headings = headings;
|
|
63
65
|
this.totals = createTotals(columns, options.footer?.totals);
|
|
64
66
|
}
|
|
65
|
-
async cell(value, first, span, row, style) {
|
|
67
|
+
async cell(value, first, span, row, style, ordinaryData = false) {
|
|
66
68
|
const { options, padding, fontSize, budget } = this.settings, column = options.columns[first];
|
|
67
69
|
const own = value instanceof ExportCell ? value.presentation : undefined;
|
|
68
70
|
const link = value instanceof ExportCell && value.link ? copyExportLink(value.link) : undefined;
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
const alternate = ordinaryData && row % 2 && options.alternateRowColor ? options.alternateRowColor : undefined;
|
|
72
|
+
const slot = first * 2 + (alternate ? 1 : 0), reusable = ordinaryData && own === undefined;
|
|
73
|
+
let combined = reusable ? this.dataPresentations[slot] : undefined;
|
|
74
|
+
if (!combined) {
|
|
75
|
+
const rowStyle = ordinaryData ? alternate ? { background: alternate } : {} : style;
|
|
76
|
+
combined = presentation({ ...(column.alignment === undefined ? {} : { alignment: column.alignment }),
|
|
77
|
+
...(column.wrapText === undefined ? {} : { wrapText: column.wrapText }), ...rowStyle, ...own });
|
|
78
|
+
// Validate only the first reached default; an authored cell may override invalid column defaults.
|
|
79
|
+
if (reusable)
|
|
80
|
+
this.dataPresentations[slot] = combined;
|
|
81
|
+
}
|
|
82
|
+
const font = this.fonts.select(combined.bold, combined.italic), width = span === 1 ? this.widths[first] : this.widths.slice(first, first + span).reduce((n, w) => n + w, 0);
|
|
72
83
|
const context = { rowIndex: row, columnIndex: first, column }, raw = value instanceof ExportCell ? value.value : value;
|
|
73
84
|
let text;
|
|
74
85
|
if (options.formatRuns && row >= 0 && !(value instanceof ExportCell && value.text !== undefined)) {
|
|
@@ -87,10 +98,11 @@ export class PdfTableLayout {
|
|
|
87
98
|
throw new TypeError("Tagged PDF cell links require nonempty displayed text.");
|
|
88
99
|
if (link && captured.runs.some(run => run.link))
|
|
89
100
|
throw new TypeError("A PDF cell link cannot be combined with inline run links.");
|
|
101
|
+
const budgetText = pdfBudgetText(captured.text, budget);
|
|
90
102
|
if (this.bands)
|
|
91
|
-
budget.release(1,
|
|
103
|
+
budget.release(1, budgetText.length);
|
|
92
104
|
else
|
|
93
|
-
budget.cell(
|
|
105
|
+
budget.cell(budgetText, budgetText.length);
|
|
94
106
|
const lines = await wrapPdfText(captured, this.fonts, fontSize, width - padding * 2, this.settings, combined.wrapText !== false);
|
|
95
107
|
return { first, span, width, font, style: combined, lineHeight: lines.reduce((height, line) => Math.max(height, line.lineHeight), font.lineHeight(fontSize)),
|
|
96
108
|
...(link ? { link } : {}), ...(this.bands ? { captured } : {}),
|
|
@@ -189,8 +201,8 @@ export class PdfTableLayout {
|
|
|
189
201
|
const value = values[column], raw = value instanceof ExportCell ? value.value : value;
|
|
190
202
|
if (!footer)
|
|
191
203
|
this.totals[column].accept(raw);
|
|
192
|
-
const
|
|
193
|
-
cells.push(
|
|
204
|
+
const cell = await this.cell(value, column, 1, index, footer ? options.footerPresentation ?? {} : undefined, !footer);
|
|
205
|
+
cells.push(!footer && options.columns[column].rowHeader ? { ...cell, rowHeader: true } : cell);
|
|
194
206
|
}
|
|
195
207
|
return this.row(cells);
|
|
196
208
|
}
|
|
@@ -7,6 +7,8 @@ export class PdfTableStructure {
|
|
|
7
7
|
cells = new WeakMap();
|
|
8
8
|
rows = new WeakMap();
|
|
9
9
|
columnHeaders = [];
|
|
10
|
+
/** Ordinary cells without row headers share immutable dictionary references, bounded by column count. */
|
|
11
|
+
ordinaryAttributes = [];
|
|
10
12
|
headerCount = 0;
|
|
11
13
|
headersPrepared = false;
|
|
12
14
|
constructor(structure, table, headers) {
|
|
@@ -47,19 +49,30 @@ export class PdfTableStructure {
|
|
|
47
49
|
return row.cells.map(cell => this.cells.get(cell));
|
|
48
50
|
const rowId = this.structure.element("TR", parent);
|
|
49
51
|
this.rows.set(row, rowId);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
//
|
|
52
|
+
const headers = row.cells.map((cell, index) => rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex);
|
|
53
|
+
// Allocate in source order, then resolve every row header before associating even earlier data cells.
|
|
54
|
+
// Generated summary labels override detail roles so numeric subtotal cells never become row headers.
|
|
55
|
+
const ids = row.cells.map((cell, index) => {
|
|
56
|
+
const id = this.structure.element(headers[index] ? "TH" : "TD", rowId);
|
|
57
|
+
this.cells.set(cell, id);
|
|
58
|
+
return id;
|
|
59
|
+
});
|
|
60
|
+
const rowHeaders = [];
|
|
61
|
+
for (let index = 0; index < ids.length; index++)
|
|
62
|
+
if (headers[index])
|
|
63
|
+
rowHeaders.push(await this.structure.identifier(ids[index]));
|
|
53
64
|
for (let index = 0; index < row.cells.length; index++) {
|
|
54
|
-
const cell = row.cells[index]
|
|
65
|
+
const cell = row.cells[index];
|
|
66
|
+
if (!rowHeaders.length && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
|
|
67
|
+
const attributes = this.ordinaryAttributes[cell.first] ??=
|
|
68
|
+
await this.structure.attributeReference(this.attributeDictionary(cell, this.associations(cell)));
|
|
69
|
+
this.structure.setAttributes(ids[index], attributes);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
55
72
|
const associations = this.associations(cell);
|
|
56
|
-
if (
|
|
57
|
-
associations.push(
|
|
58
|
-
|
|
59
|
-
this.cells.set(cell, id);
|
|
60
|
-
ids.push(id);
|
|
61
|
-
if (isRowHeader)
|
|
62
|
-
rowHeaderIdentifier = await this.structure.identifier(id);
|
|
73
|
+
if (!headers[index])
|
|
74
|
+
associations.push(...rowHeaders);
|
|
75
|
+
this.structure.setAttributes(ids[index], this.attributes(cell, associations, headers[index] ? "Row" : undefined));
|
|
63
76
|
}
|
|
64
77
|
return ids;
|
|
65
78
|
}
|
|
@@ -85,7 +98,10 @@ export class PdfTableStructure {
|
|
|
85
98
|
return [...headers].sort((left, right) => left.order - right.order).map(header => header.identifier);
|
|
86
99
|
}
|
|
87
100
|
attributes(cell, headers, scope) {
|
|
88
|
-
return " /A
|
|
101
|
+
return " /A " + this.attributeDictionary(cell, headers, scope);
|
|
102
|
+
}
|
|
103
|
+
attributeDictionary(cell, headers, scope) {
|
|
104
|
+
return "<< /O /Table" + (scope === undefined ? "" : " /Scope /" + scope) +
|
|
89
105
|
(cell.span > 1 ? " /ColSpan " + cell.span : "") + ((cell.rowSpan ?? 1) > 1 ? " /RowSpan " + cell.rowSpan : "") +
|
|
90
106
|
(headers.length ? " /Headers [" + headers.map(id => "(" + id + ")").join(" ") + "]" : "") + " >>";
|
|
91
107
|
}
|
package/dist/pdf/text.js
CHANGED
|
@@ -3,6 +3,11 @@ import { ExportCell, assertExportValue } from "../core/presentation.js";
|
|
|
3
3
|
import { checkAbort, pause, taskYieldDue } from "../core/iteration.js";
|
|
4
4
|
import { isDate } from "../core/dates.js";
|
|
5
5
|
import { defaultBooleanText } from "../core/value-text.js";
|
|
6
|
+
/** @internal Charge displayed characters: tabs paint four spaces, while CR/LF only separate lines.
|
|
7
|
+
* Raw text remains authoritative for input limits and layout. Skip normalization when no text ceiling observes it. */
|
|
8
|
+
export function pdfBudgetText(text, budget) {
|
|
9
|
+
return budget.limits.maxTextCharacters === undefined ? text : text.replace(/[\t\r\n]/g, character => character === "\t" ? " " : "");
|
|
10
|
+
}
|
|
6
11
|
export function synchronousText(value, name) {
|
|
7
12
|
if (typeof value === "string")
|
|
8
13
|
return value;
|
package/dist/pdf/types.d.ts
CHANGED
|
@@ -8,9 +8,11 @@ export interface PdfTableBands {
|
|
|
8
8
|
readonly mode: "bands";
|
|
9
9
|
/** Minimum point width when columnWidths is absent. Default 72; shared Column.width can increase it. */
|
|
10
10
|
readonly minimumColumnWidth?: number;
|
|
11
|
-
/**
|
|
11
|
+
/** Zero-based positions or exact stable column keys, repeated in selected source order on every band.
|
|
12
|
+
* Numeric-only lists retain their sorted unique positional contract. Keys resolve only within the selected columns;
|
|
13
|
+
* duplicate positions, including aliases, reject. Grouped tables include their leading label at numeric position zero.
|
|
12
14
|
* Repeated cell contents must fit below the headings/context on one fresh page. */
|
|
13
|
-
readonly repeatColumns?: readonly number[];
|
|
15
|
+
readonly repeatColumns?: readonly (number | string)[];
|
|
14
16
|
}
|
|
15
17
|
/** PDF lengths are points (72 points per inch). */
|
|
16
18
|
export interface PdfPageSize {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/pdf/xref.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** @internal One type byte, an eight-byte offset/container number and a two-byte generation/index. */
|
|
2
|
+
export const pdfXrefEntryBytes = 11;
|
|
3
|
+
function unsigned(bytes, offset, value, width) {
|
|
4
|
+
if (!Number.isSafeInteger(value) || value < 0 || value >= 2 ** (width * 8))
|
|
5
|
+
throw new RangeError("Invalid PDF cross-reference field.");
|
|
6
|
+
// Bitwise shifts truncate to 32 bits. Arithmetic preserves every supported byte offset.
|
|
7
|
+
for (let index = width - 1; index >= 0; index--) {
|
|
8
|
+
bytes[offset + index] = value % 256;
|
|
9
|
+
value = Math.floor(value / 256);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** @internal Stream a complete single-section xref, including its own ordinary-object entry.
|
|
13
|
+
* A defined member index means that the location is an object-stream number rather than a byte offset. */
|
|
14
|
+
export function* pdfXrefChunks(locations, indices) {
|
|
15
|
+
if (locations.length !== indices.length)
|
|
16
|
+
throw new Error("PDF cross-reference locations must align.");
|
|
17
|
+
const perChunk = Math.floor(32768 / pdfXrefEntryBytes);
|
|
18
|
+
for (let first = 0; first < locations.length; first += perChunk) {
|
|
19
|
+
const count = Math.min(perChunk, locations.length - first), bytes = new Uint8Array(count * pdfXrefEntryBytes);
|
|
20
|
+
for (let index = 0; index < count; index++) {
|
|
21
|
+
const id = first + index, position = index * pdfXrefEntryBytes, location = locations[id], member = indices.at(id);
|
|
22
|
+
if (location === undefined)
|
|
23
|
+
throw new Error("PDF contains unwritten objects.");
|
|
24
|
+
bytes[position] = id === 0 ? 0 : member === undefined ? 1 : 2;
|
|
25
|
+
unsigned(bytes, position + 1, location, 8);
|
|
26
|
+
unsigned(bytes, position + 9, id === 0 ? 65535 : member ?? 0, 2);
|
|
27
|
+
}
|
|
28
|
+
yield bytes;
|
|
29
|
+
}
|
|
30
|
+
}
|
package/dist/xlsx/values.js
CHANGED
|
@@ -57,12 +57,13 @@ export function sheetName(requested, names, policy, register = true) {
|
|
|
57
57
|
throw new TypeError("Sheet name must be a string.");
|
|
58
58
|
// Validate and deduplicate the decoded literal value, before ST_Xstring attribute encoding.
|
|
59
59
|
// A requested _xHHHH_ token is literal text; the serializer protects its leading underscore.
|
|
60
|
-
let base = cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_").
|
|
60
|
+
let base = cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_").replace(/^[\s']+|[\s']+$/g, "");
|
|
61
|
+
// Clipping can expose an internal apostrophe or the reserved History name.
|
|
62
|
+
base = clipName(base, 31).replace(/[\s']+$/g, "");
|
|
61
63
|
if (!base)
|
|
62
64
|
base = "Sheet";
|
|
63
65
|
if (base.toLowerCase() === "history")
|
|
64
66
|
base += "_";
|
|
65
|
-
base = clipName(base, 31);
|
|
66
67
|
let name = base, suffix = 2;
|
|
67
68
|
while (names.has(name.toLowerCase())) {
|
|
68
69
|
const tail = " (" + suffix++ + ")";
|
package/dist/zip/entry.js
CHANGED
|
@@ -24,7 +24,7 @@ export class EntryWriter {
|
|
|
24
24
|
closed = false;
|
|
25
25
|
cleaned = false;
|
|
26
26
|
lifetime = new AbortController();
|
|
27
|
-
abort = () => { this.fail(this.signal?.reason
|
|
27
|
+
abort = () => { this.fail(this.signal?.reason); };
|
|
28
28
|
constructor(compression, sink, signal) {
|
|
29
29
|
this.sink = sink;
|
|
30
30
|
this.signal = signal;
|
package/dist/zip/index.js
CHANGED
|
@@ -55,7 +55,7 @@ export class ZipWriter {
|
|
|
55
55
|
/** Pending header/directory writes and source reads must also stop on explicit discard. */
|
|
56
56
|
async acceptance(operation) {
|
|
57
57
|
const signal = this.options.signal;
|
|
58
|
-
const abort = () => this.lifetime.abort(signal?.reason
|
|
58
|
+
const abort = () => this.lifetime.abort(signal?.reason);
|
|
59
59
|
signal?.addEventListener("abort", abort, { once: true });
|
|
60
60
|
try {
|
|
61
61
|
checkAbort(signal);
|