@evotecit/officeimo 0.1.0 → 0.1.2
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 +842 -377
- package/bundles/officeimo-canopyx.mjs +729 -265
- package/bundles/officeimo-csv.js +29 -19
- package/bundles/officeimo-csv.mjs +17 -7
- package/bundles/officeimo-datatables.js +835 -379
- package/bundles/officeimo-datatables.mjs +723 -268
- package/bundles/officeimo-execution.js +35 -25
- package/bundles/officeimo-execution.mjs +17 -7
- package/bundles/officeimo-pdf.js +737 -291
- package/bundles/officeimo-pdf.mjs +688 -243
- package/bundles/officeimo-xlsx.js +114 -94
- package/bundles/officeimo-xlsx.mjs +48 -28
- package/bundles/officeimo.js +819 -363
- package/bundles/officeimo.mjs +709 -254
- 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/opc/index.js +14 -9
- 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 +28 -28
- 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/xlsx/workbook.js +7 -4
- package/dist/xlsx/worksheet.js +2 -1
- package/dist/xml/index.js +3 -3
- package/dist/zip/entry.js +1 -1
- package/dist/zip/index.js +1 -1
- package/package.json +1 -1
|
@@ -38,7 +38,7 @@ return _exports;
|
|
|
38
38
|
const _m4 = (() => {
|
|
39
39
|
function checkAbort(signal) {
|
|
40
40
|
if (signal?.aborted)
|
|
41
|
-
throw signal.reason
|
|
41
|
+
throw signal.reason;
|
|
42
42
|
}
|
|
43
43
|
/** Race a pending producer or sink operation without leaving abort listeners behind. */
|
|
44
44
|
function withAbort(promise, signal) {
|
|
@@ -46,7 +46,7 @@ function withAbort(promise, signal) {
|
|
|
46
46
|
return Promise.resolve(promise);
|
|
47
47
|
return new Promise((resolve, reject) => {
|
|
48
48
|
const cleanup = () => signal.removeEventListener("abort", abort);
|
|
49
|
-
const abort = () => { cleanup(); reject(signal.reason
|
|
49
|
+
const abort = () => { cleanup(); reject(signal.reason); };
|
|
50
50
|
signal.addEventListener("abort", abort, { once: true });
|
|
51
51
|
Promise.resolve(promise).then(value => { cleanup(); resolve(value); }, error => { cleanup(); reject(error); });
|
|
52
52
|
if (signal.aborted)
|
|
@@ -199,8 +199,9 @@ async function withDestination(destination, operation) {
|
|
|
199
199
|
// Native streams can belong to another browser realm; constructor identity is not portable.
|
|
200
200
|
if (destination && typeof destination.getWriter === "function") {
|
|
201
201
|
const writer = destination.getWriter();
|
|
202
|
+
// Native streams may retain accepted chunks after write resolves.
|
|
202
203
|
try {
|
|
203
|
-
return await operation({ write: bytes => writer.write(bytes) });
|
|
204
|
+
return await operation({ write: bytes => writer.write(new Uint8Array(bytes)) });
|
|
204
205
|
}
|
|
205
206
|
finally {
|
|
206
207
|
writer.releaseLock();
|
|
@@ -498,11 +499,18 @@ function createRowProjector(columns, worksheet, signal, validate = assertExportV
|
|
|
498
499
|
const getters = columns.some(column => column.value);
|
|
499
500
|
return (row, rowIndex = 0) => {
|
|
500
501
|
if (Array.isArray(row) && !getters) {
|
|
501
|
-
|
|
502
|
+
const length = row.length;
|
|
503
|
+
if (length > columns.length)
|
|
502
504
|
throw new RangeError("Row has more values than declared columns.");
|
|
503
|
-
|
|
505
|
+
// Resolve each positional value once, just like key/value projections. Returning the
|
|
506
|
+
// source array would let an accessor change a value after the portable-value check.
|
|
507
|
+
const values = new Array(length);
|
|
508
|
+
for (let index = 0; index < length; index++) {
|
|
509
|
+
const value = row[index];
|
|
504
510
|
validate(value);
|
|
505
|
-
|
|
511
|
+
values[index] = value;
|
|
512
|
+
}
|
|
513
|
+
return values;
|
|
506
514
|
}
|
|
507
515
|
if (!row || typeof row !== "object" || isDate(row))
|
|
508
516
|
throw new TypeError("A row must be an array or object.");
|
|
@@ -531,7 +539,7 @@ function createRowProjector(columns, worksheet, signal, validate = assertExportV
|
|
|
531
539
|
};
|
|
532
540
|
}
|
|
533
541
|
/** @internal Shared metadata fields for full columns and adapter-owned partial overrides. */
|
|
534
|
-
const columnOptionFields = ["header", "key", "value", "width", "type", "format", "wrapText", "alignment", "groups", "style", "valueFormatter"];
|
|
542
|
+
const columnOptionFields = ["header", "key", "value", "width", "type", "format", "wrapText", "alignment", "rowHeader", "groups", "style", "valueFormatter"];
|
|
535
543
|
function copyColumns(columns, workbookStyles = false) {
|
|
536
544
|
if (!Array.isArray(columns))
|
|
537
545
|
throw new TypeError("Declare the columns in export order.");
|
|
@@ -547,6 +555,8 @@ function copyColumns(columns, workbookStyles = false) {
|
|
|
547
555
|
throw new TypeError("Each column needs a string header and an optional string key.");
|
|
548
556
|
if (captured.value !== undefined && typeof captured.value !== "function")
|
|
549
557
|
throw new TypeError("Column value getters must be functions.");
|
|
558
|
+
if (captured.rowHeader !== undefined && typeof captured.rowHeader !== "boolean")
|
|
559
|
+
throw new TypeError("Column rowHeader must be boolean.");
|
|
550
560
|
if (captured.groups !== undefined) {
|
|
551
561
|
if (!Array.isArray(captured.groups))
|
|
552
562
|
throw new TypeError("Column groups must be an array of strings.");
|
|
@@ -1279,6 +1289,8 @@ const { OfficeIMOError } = _m2;
|
|
|
1279
1289
|
const { ChunkedTextSink } = _m3;
|
|
1280
1290
|
|
|
1281
1291
|
const xmlDeclaration = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
1292
|
+
const xmlEscapes = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'",
|
|
1293
|
+
"\r": " ", "\n": " ", "\t": "	" };
|
|
1282
1294
|
/** XML 1.0 characters; Unicode mode retains valid surrogate pairs. */
|
|
1283
1295
|
function cleanXml(value, policy = "strip") {
|
|
1284
1296
|
if (policy !== "strip" && policy !== "reject")
|
|
@@ -1290,9 +1302,7 @@ function cleanXml(value, policy = "strip") {
|
|
|
1290
1302
|
}
|
|
1291
1303
|
/** Escape data, including whitespace that XML parsers otherwise normalize. */
|
|
1292
1304
|
function escapeXml(value, policy = "strip") {
|
|
1293
|
-
|
|
1294
|
-
"\r": " ", "\n": " ", "\t": "	" };
|
|
1295
|
-
return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => escapes[c]);
|
|
1305
|
+
return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => xmlEscapes[c]);
|
|
1296
1306
|
}
|
|
1297
1307
|
/** Encode an OOXML ST_Xstring attribute without interpreting literal escape tokens as characters. */
|
|
1298
1308
|
function escapeOoxmlAttribute(value, policy = "strip") {
|
|
@@ -1432,7 +1442,7 @@ class EntryWriter {
|
|
|
1432
1442
|
closed = false;
|
|
1433
1443
|
cleaned = false;
|
|
1434
1444
|
lifetime = new AbortController();
|
|
1435
|
-
abort = () => { this.fail(this.signal?.reason
|
|
1445
|
+
abort = () => { this.fail(this.signal?.reason); };
|
|
1436
1446
|
constructor(compression, sink, signal) {
|
|
1437
1447
|
this.sink = sink;
|
|
1438
1448
|
this.signal = signal;
|
|
@@ -1596,7 +1606,7 @@ class ZipWriter {
|
|
|
1596
1606
|
/** Pending header/directory writes and source reads must also stop on explicit discard. */
|
|
1597
1607
|
async acceptance(operation) {
|
|
1598
1608
|
const signal = this.options.signal;
|
|
1599
|
-
const abort = () => this.lifetime.abort(signal?.reason
|
|
1609
|
+
const abort = () => this.lifetime.abort(signal?.reason);
|
|
1600
1610
|
signal?.addEventListener("abort", abort, { once: true });
|
|
1601
1611
|
try {
|
|
1602
1612
|
checkAbort(signal);
|
|
@@ -1890,8 +1900,11 @@ class OpcPackage {
|
|
|
1890
1900
|
return uri;
|
|
1891
1901
|
}
|
|
1892
1902
|
addPart(part) {
|
|
1893
|
-
const uri
|
|
1894
|
-
|
|
1903
|
+
const { uri: requestedUri, contentType, data } = part;
|
|
1904
|
+
// Structural accessors and byte ownership are captured before reserving metadata.
|
|
1905
|
+
const capturedData = data instanceof Uint8Array ? new Uint8Array(data) : data;
|
|
1906
|
+
const uri = this.reserve(requestedUri, contentType);
|
|
1907
|
+
this.parts.set(uri.toLowerCase(), { uri, contentType, data: capturedData });
|
|
1895
1908
|
}
|
|
1896
1909
|
/** @internal */
|
|
1897
1910
|
addPrepared(uri, type, prepared) {
|
|
@@ -1916,17 +1929,19 @@ class OpcPackage {
|
|
|
1916
1929
|
checkAbort(this.options.signal);
|
|
1917
1930
|
this.open();
|
|
1918
1931
|
source = source === "/" ? source : partUri(source);
|
|
1919
|
-
|
|
1932
|
+
const { id, type, target: requestedTarget, external } = relationship;
|
|
1933
|
+
this.open();
|
|
1934
|
+
if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(id))
|
|
1920
1935
|
throw new TypeError("Relationship id must be an XML ID.");
|
|
1921
|
-
if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(
|
|
1936
|
+
if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(type))
|
|
1922
1937
|
throw new TypeError("Relationship type must be an absolute URI.");
|
|
1923
|
-
const target =
|
|
1924
|
-
if (
|
|
1938
|
+
const target = external ? requestedTarget : partUri(requestedTarget);
|
|
1939
|
+
if (external && (!target || /[\u0000-\u0020]/.test(target)))
|
|
1925
1940
|
throw new TypeError("Invalid external relationship target.");
|
|
1926
1941
|
const key = source.toLowerCase(), list = this.relationships.get(key) ?? new Map();
|
|
1927
|
-
if (list.has(
|
|
1928
|
-
throw new TypeError("Duplicate relationship id: " +
|
|
1929
|
-
list.set(
|
|
1942
|
+
if (list.has(id))
|
|
1943
|
+
throw new TypeError("Duplicate relationship id: " + id);
|
|
1944
|
+
list.set(id, { id, type, target, ...(external === undefined ? {} : { external }) });
|
|
1930
1945
|
this.relationships.set(key, list);
|
|
1931
1946
|
}
|
|
1932
1947
|
setProperties(core = {}, app = {}) {
|
|
@@ -2548,12 +2563,13 @@ function sheetName(requested, names, policy, register = true) {
|
|
|
2548
2563
|
throw new TypeError("Sheet name must be a string.");
|
|
2549
2564
|
// Validate and deduplicate the decoded literal value, before ST_Xstring attribute encoding.
|
|
2550
2565
|
// A requested _xHHHH_ token is literal text; the serializer protects its leading underscore.
|
|
2551
|
-
let base = cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_").
|
|
2566
|
+
let base = cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_").replace(/^[\s']+|[\s']+$/g, "");
|
|
2567
|
+
// Clipping can expose an internal apostrophe or the reserved History name.
|
|
2568
|
+
base = clipName(base, 31).replace(/[\s']+$/g, "");
|
|
2552
2569
|
if (!base)
|
|
2553
2570
|
base = "Sheet";
|
|
2554
2571
|
if (base.toLowerCase() === "history")
|
|
2555
2572
|
base += "_";
|
|
2556
|
-
base = clipName(base, 31);
|
|
2557
2573
|
let name = base, suffix = 2;
|
|
2558
2574
|
while (names.has(name.toLowerCase())) {
|
|
2559
2575
|
const tail = " (" + suffix++ + ")";
|
|
@@ -3736,7 +3752,8 @@ class Worksheet {
|
|
|
3736
3752
|
});
|
|
3737
3753
|
const originalCharacters = typeof value === "string" ? value.length : 0;
|
|
3738
3754
|
let reservedCharacters = this.preserved || header || footer ? originalCharacters : undefined;
|
|
3739
|
-
|
|
3755
|
+
// Cleaning removes characters; ordinary strings cannot cross Excel's limit.
|
|
3756
|
+
if (type === "string" && originalCharacters > 32767 && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
|
|
3740
3757
|
const cell = col.letter + row;
|
|
3741
3758
|
if (link || this.linkedCells.has(cell))
|
|
3742
3759
|
throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
|
|
@@ -4956,12 +4973,15 @@ class Workbook {
|
|
|
4956
4973
|
});
|
|
4957
4974
|
}
|
|
4958
4975
|
addPart(part) {
|
|
4976
|
+
this.assertOpen();
|
|
4977
|
+
const { uri, contentType, data, relationship } = part;
|
|
4978
|
+
const capturedRelationship = relationship && { id: relationship.id, type: relationship.type, source: relationship.source };
|
|
4959
4979
|
this.assertOpen();
|
|
4960
4980
|
// Reserve now so collisions and invalid names fail at the call site.
|
|
4961
|
-
this.package.addPart(
|
|
4962
|
-
if (
|
|
4963
|
-
const { source,
|
|
4964
|
-
this.package.addRelationship(source ?? "/xl/workbook.xml", {
|
|
4981
|
+
this.package.addPart({ uri, contentType, data });
|
|
4982
|
+
if (capturedRelationship) {
|
|
4983
|
+
const { source, id, type } = capturedRelationship;
|
|
4984
|
+
this.package.addRelationship(source ?? "/xl/workbook.xml", { id, type, target: uri });
|
|
4965
4985
|
}
|
|
4966
4986
|
}
|
|
4967
4987
|
/** Complete the archive and return counts. Does not close or dispose a caller-owned sink. */
|
|
@@ -5661,10 +5681,34 @@ function captureWideTable(input) {
|
|
|
5661
5681
|
if (repeatColumns !== undefined && !Array.isArray(repeatColumns))
|
|
5662
5682
|
throw new TypeError("repeatColumns must be an array.");
|
|
5663
5683
|
const repeats = repeatColumns === undefined ? [] : [...repeatColumns];
|
|
5664
|
-
if (repeats.some(
|
|
5665
|
-
throw new RangeError("repeatColumns must contain
|
|
5684
|
+
if (repeats.some(value => typeof value === "number" ? !Number.isSafeInteger(value) || value < 0 : typeof value !== "string" || !value.length))
|
|
5685
|
+
throw new RangeError("repeatColumns must contain nonnegative indices or nonempty stable keys.");
|
|
5686
|
+
if (repeats.every(value => typeof value === "number") && repeats.some((value, index) => index > 0 && value <= repeats[index - 1]))
|
|
5687
|
+
throw new RangeError("Numeric repeatColumns must contain sorted unique nonnegative indices.");
|
|
5666
5688
|
return Object.freeze({ mode, ...(minimumColumnWidth === undefined ? {} : { minimumColumnWidth }), repeatColumns: Object.freeze(repeats) });
|
|
5667
5689
|
}
|
|
5690
|
+
/** Resolve identities against this table's captured selection, without consulting a grid or opening its rows. */
|
|
5691
|
+
function repeatedColumns(policy, columns) {
|
|
5692
|
+
if (typeof policy !== "object")
|
|
5693
|
+
return Object.freeze([]);
|
|
5694
|
+
const selected = new Set();
|
|
5695
|
+
for (const selector of policy.repeatColumns ?? []) {
|
|
5696
|
+
let position;
|
|
5697
|
+
if (typeof selector === "number")
|
|
5698
|
+
position = selector;
|
|
5699
|
+
else {
|
|
5700
|
+
position = columns.findIndex(column => column.key === selector);
|
|
5701
|
+
if (position < 0 || columns.some((column, index) => index !== position && column.key === selector))
|
|
5702
|
+
throw new TypeError("repeatColumns requires an unambiguous selected column key: " + selector);
|
|
5703
|
+
}
|
|
5704
|
+
if (position >= columns.length)
|
|
5705
|
+
throw new RangeError("repeatColumns index exceeds the declared columns.");
|
|
5706
|
+
if (selected.has(position))
|
|
5707
|
+
throw new TypeError("repeatColumns selects the same column more than once.");
|
|
5708
|
+
selected.add(position);
|
|
5709
|
+
}
|
|
5710
|
+
return Object.freeze([...selected].sort((left, right) => left - right));
|
|
5711
|
+
}
|
|
5668
5712
|
function settings(input, document = false) {
|
|
5669
5713
|
const configuration = { ...capturePdfOptions(input) };
|
|
5670
5714
|
configuration.booleanText = captureBooleanText(configuration.booleanText);
|
|
@@ -5766,17 +5810,76 @@ function settings(input, document = false) {
|
|
|
5766
5810
|
}
|
|
5767
5811
|
const maxImageWorkingBytes = options.limits?.maxImageWorkingBytes;
|
|
5768
5812
|
return { options: { ...options, paragraphStyles }, paragraphStyles, page, margins, fontSize, padding,
|
|
5813
|
+
repeatedColumns: document ? Object.freeze([]) : repeatedColumns(options.wideTable, columns),
|
|
5769
5814
|
limits: { ...limits, ...(maxImageWorkingBytes === undefined ? {} : { maxImageWorkingBytes }) }, budget };
|
|
5770
5815
|
}
|
|
5771
5816
|
const _exports = Object.freeze({ positive: _m57.positive, color: _m57.color, presentation: _m57.presentation, pdfOptionFields: pdfOptionFields, pdfLimitFields: pdfLimitFields, capturePdfOptions: capturePdfOptions, capturePdfLimits: capturePdfLimits, captureWideTable: captureWideTable, settings: settings });
|
|
5772
5817
|
return _exports;
|
|
5773
5818
|
})();
|
|
5774
5819
|
|
|
5820
|
+
const _m60 = (() => {
|
|
5821
|
+
/** @internal One type byte, an eight-byte offset/container number and a two-byte generation/index. */
|
|
5822
|
+
const pdfXrefEntryBytes = 11;
|
|
5823
|
+
function unsigned(bytes, offset, value, width) {
|
|
5824
|
+
if (!Number.isSafeInteger(value) || value < 0 || value >= 2 ** (width * 8))
|
|
5825
|
+
throw new RangeError("Invalid PDF cross-reference field.");
|
|
5826
|
+
// Bitwise shifts truncate to 32 bits. Arithmetic preserves every supported byte offset.
|
|
5827
|
+
for (let index = width - 1; index >= 0; index--) {
|
|
5828
|
+
bytes[offset + index] = value % 256;
|
|
5829
|
+
value = Math.floor(value / 256);
|
|
5830
|
+
}
|
|
5831
|
+
}
|
|
5832
|
+
/** @internal Stream a complete single-section xref, including its own ordinary-object entry.
|
|
5833
|
+
* A defined member index means that the location is an object-stream number rather than a byte offset. */
|
|
5834
|
+
function* pdfXrefChunks(locations, indices) {
|
|
5835
|
+
if (locations.length !== indices.length)
|
|
5836
|
+
throw new Error("PDF cross-reference locations must align.");
|
|
5837
|
+
const perChunk = Math.floor(32768 / pdfXrefEntryBytes);
|
|
5838
|
+
for (let first = 0; first < locations.length; first += perChunk) {
|
|
5839
|
+
const count = Math.min(perChunk, locations.length - first), bytes = new Uint8Array(count * pdfXrefEntryBytes);
|
|
5840
|
+
for (let index = 0; index < count; index++) {
|
|
5841
|
+
const id = first + index, position = index * pdfXrefEntryBytes, location = locations[id], member = indices.at(id);
|
|
5842
|
+
if (location === undefined)
|
|
5843
|
+
throw new Error("PDF contains unwritten objects.");
|
|
5844
|
+
bytes[position] = id === 0 ? 0 : member === undefined ? 1 : 2;
|
|
5845
|
+
unsigned(bytes, position + 1, location, 8);
|
|
5846
|
+
unsigned(bytes, position + 9, id === 0 ? 65535 : member ?? 0, 2);
|
|
5847
|
+
}
|
|
5848
|
+
yield bytes;
|
|
5849
|
+
}
|
|
5850
|
+
}
|
|
5851
|
+
const _exports = Object.freeze({ pdfXrefEntryBytes: pdfXrefEntryBytes, pdfXrefChunks: pdfXrefChunks });
|
|
5852
|
+
return _exports;
|
|
5853
|
+
})();
|
|
5854
|
+
|
|
5775
5855
|
const _m59 = (() => {
|
|
5776
5856
|
const { checkAbort, withAbort, pause, taskYieldDue } = _m4;
|
|
5777
5857
|
|
|
5778
5858
|
const { OfficeIMOError } = _m2;
|
|
5779
5859
|
|
|
5860
|
+
const { pdfXrefChunks, pdfXrefEntryBytes } = _m60;
|
|
5861
|
+
|
|
5862
|
+
const compactObjectCount = 256, compactObjectBytes = 32768;
|
|
5863
|
+
const compactIndexChunkEntries = 4096;
|
|
5864
|
+
/** Lazy Uint16 chunks store compact membership; untouched zero slots denote ordinary objects. */
|
|
5865
|
+
class PdfCompactIndices {
|
|
5866
|
+
count;
|
|
5867
|
+
chunks = [];
|
|
5868
|
+
constructor(count) {
|
|
5869
|
+
this.count = count;
|
|
5870
|
+
}
|
|
5871
|
+
get length() { return this.count; }
|
|
5872
|
+
reserve() { this.count++; }
|
|
5873
|
+
set(id, member) {
|
|
5874
|
+
const chunk = this.chunks[Math.floor(id / compactIndexChunkEntries)] ??= new Uint16Array(compactIndexChunkEntries);
|
|
5875
|
+
// The current batch cap permits indices 0..255; adding one preserves index 255 as 256.
|
|
5876
|
+
chunk[id % compactIndexChunkEntries] = member + 1;
|
|
5877
|
+
}
|
|
5878
|
+
at(id) {
|
|
5879
|
+
const encoded = this.chunks[Math.floor(id / compactIndexChunkEntries)]?.[id % compactIndexChunkEntries] ?? 0;
|
|
5880
|
+
return encoded ? encoded - 1 : undefined;
|
|
5881
|
+
}
|
|
5882
|
+
}
|
|
5780
5883
|
function pdfNumber(value) {
|
|
5781
5884
|
if (!Number.isFinite(value) || Math.abs(value) > 1e9)
|
|
5782
5885
|
throw new RangeError("PDF coordinates and metrics must be finite and bounded.");
|
|
@@ -5793,25 +5896,33 @@ function unicodeHex(text) {
|
|
|
5793
5896
|
}
|
|
5794
5897
|
return hex;
|
|
5795
5898
|
}
|
|
5796
|
-
/** @internal Forward-only PDF objects.
|
|
5899
|
+
/** @internal Forward-only PDF objects. Completed objects retain only their xref location. */
|
|
5797
5900
|
class PdfObjects {
|
|
5798
5901
|
sink;
|
|
5799
5902
|
signal;
|
|
5800
5903
|
maxBytes;
|
|
5904
|
+
compressObjects;
|
|
5801
5905
|
offsets = [0];
|
|
5906
|
+
// A defined index changes the corresponding full-width offset into an object-stream number.
|
|
5907
|
+
// Membership chunks are allocated only when a compact member needs their ID range.
|
|
5908
|
+
compactIndices;
|
|
5909
|
+
compactBatch;
|
|
5910
|
+
compactArena;
|
|
5911
|
+
compactUnavailable = false;
|
|
5802
5912
|
encoder = new TextEncoder();
|
|
5803
5913
|
buffer = new Uint8Array(32768);
|
|
5804
5914
|
buffered = 0;
|
|
5805
5915
|
bytes = 0;
|
|
5806
|
-
constructor(sink, signal, maxBytes = Number.MAX_SAFE_INTEGER) {
|
|
5916
|
+
constructor(sink, signal, maxBytes = Number.MAX_SAFE_INTEGER, compressObjects = false) {
|
|
5807
5917
|
this.sink = sink;
|
|
5808
5918
|
this.signal = signal;
|
|
5809
5919
|
this.maxBytes = maxBytes;
|
|
5920
|
+
this.compressObjects = compressObjects;
|
|
5810
5921
|
}
|
|
5811
|
-
reserve() { this.offsets.push(undefined); return this.offsets.length - 1; }
|
|
5922
|
+
reserve() { this.offsets.push(undefined); this.compactIndices?.reserve(); return this.offsets.length - 1; }
|
|
5812
5923
|
async raw(bytes) {
|
|
5813
5924
|
checkAbort(this.signal);
|
|
5814
|
-
if (this.bytes + bytes.length > this.maxBytes)
|
|
5925
|
+
if (!Number.isSafeInteger(this.bytes + bytes.length) || this.bytes + bytes.length > this.maxBytes)
|
|
5815
5926
|
throw new OfficeIMOError("RESOURCE_LIMIT", "maxOutputBytes exceeded.");
|
|
5816
5927
|
this.bytes += bytes.length;
|
|
5817
5928
|
for (let offset = 0; offset < bytes.length;) {
|
|
@@ -5820,21 +5931,139 @@ class PdfObjects {
|
|
|
5820
5931
|
offset += n;
|
|
5821
5932
|
this.buffered += n;
|
|
5822
5933
|
if (this.buffered === this.buffer.length)
|
|
5823
|
-
await this.
|
|
5934
|
+
await this.flushBytes();
|
|
5824
5935
|
}
|
|
5825
5936
|
}
|
|
5826
5937
|
async text(text) { await this.raw(this.encoder.encode(text)); }
|
|
5827
5938
|
async flush() {
|
|
5939
|
+
await this.flushCompact();
|
|
5940
|
+
await this.flushBytes();
|
|
5941
|
+
}
|
|
5942
|
+
/** Publish completed page bytes without forcing a partial structure container to end. */
|
|
5943
|
+
async flushBytes() {
|
|
5828
5944
|
if (this.buffered) {
|
|
5829
5945
|
const bytes = this.buffer.subarray(0, this.buffered);
|
|
5830
5946
|
await withAbort(Promise.resolve(this.sink.write(bytes)), this.signal);
|
|
5831
|
-
this
|
|
5947
|
+
// The sink borrows this view until acceptance; failed or cancelled writes must not reuse it.
|
|
5832
5948
|
this.buffered = 0;
|
|
5833
5949
|
}
|
|
5834
5950
|
if (taskYieldDue())
|
|
5835
5951
|
await pause();
|
|
5836
5952
|
checkAbort(this.signal);
|
|
5837
5953
|
}
|
|
5954
|
+
/** @internal Append only when an existing compact batch can accept a member without async work. */
|
|
5955
|
+
tryCompactObject(id, body) {
|
|
5956
|
+
checkAbort(this.signal);
|
|
5957
|
+
this.validateObject(id);
|
|
5958
|
+
const batch = this.compactBatch;
|
|
5959
|
+
if (!batch || !this.compressObjects || this.compactUnavailable || typeof CompressionStream !== "function" ||
|
|
5960
|
+
body.length > compactObjectBytes || batch.ids.length + 1 >= compactObjectCount)
|
|
5961
|
+
return false;
|
|
5962
|
+
const indexBytes = String(id).length + String(batch.bodyBytes).length + 2;
|
|
5963
|
+
const written = this.encodeCompactBody(body, batch.bodyBytes, compactObjectBytes - batch.indexBytes - indexBytes - batch.bodyBytes - 2);
|
|
5964
|
+
if (written === undefined)
|
|
5965
|
+
return false;
|
|
5966
|
+
this.storeCompactBody(batch, id, written);
|
|
5967
|
+
return true;
|
|
5968
|
+
}
|
|
5969
|
+
/** Small logical structure values share one bounded object-stream container. Other callers keep
|
|
5970
|
+
* ordinary objects; unavailable deflate preserves the classic representation before packing starts. */
|
|
5971
|
+
async compactObject(id, body) {
|
|
5972
|
+
checkAbort(this.signal);
|
|
5973
|
+
this.validateObject(id);
|
|
5974
|
+
if (!this.compressObjects || this.compactUnavailable || body.length > compactObjectBytes)
|
|
5975
|
+
return this.object(id, body);
|
|
5976
|
+
if (typeof CompressionStream !== "function") {
|
|
5977
|
+
if (this.compactIndices)
|
|
5978
|
+
throw new Error("PDF object compression became unavailable.");
|
|
5979
|
+
this.compactUnavailable = true;
|
|
5980
|
+
return this.object(id, body);
|
|
5981
|
+
}
|
|
5982
|
+
const firstIndexBytes = String(id).length + 4;
|
|
5983
|
+
let batch = this.compactBatch;
|
|
5984
|
+
const indexBytes = String(id).length + String(batch?.bodyBytes ?? 0).length + 2;
|
|
5985
|
+
let written = batch && batch.ids.length < compactObjectCount ? this.encodeCompactBody(body, batch.bodyBytes, compactObjectBytes - batch.indexBytes - indexBytes - batch.bodyBytes - 2) : undefined;
|
|
5986
|
+
if (batch && written === undefined) {
|
|
5987
|
+
// Partial encodings only touch the uncommitted suffix. Flush the committed prefix and retry
|
|
5988
|
+
// the whole string so a multibyte scalar is never split between containers.
|
|
5989
|
+
await this.flushCompact();
|
|
5990
|
+
batch = undefined;
|
|
5991
|
+
checkAbort(this.signal);
|
|
5992
|
+
}
|
|
5993
|
+
if (!batch) {
|
|
5994
|
+
written = this.encodeCompactBody(body, 0, compactObjectBytes - firstIndexBytes - 1);
|
|
5995
|
+
if (written === undefined)
|
|
5996
|
+
return this.object(id, body);
|
|
5997
|
+
let compressor;
|
|
5998
|
+
// Probe before selecting the compact representation. Later batches need no idle native
|
|
5999
|
+
// codec while they accumulate, including while ordinary page streams are compressed.
|
|
6000
|
+
if (!this.compactIndices) {
|
|
6001
|
+
try {
|
|
6002
|
+
compressor = new CompressionStream("deflate");
|
|
6003
|
+
}
|
|
6004
|
+
catch {
|
|
6005
|
+
this.compactUnavailable = true;
|
|
6006
|
+
return this.object(id, body);
|
|
6007
|
+
}
|
|
6008
|
+
}
|
|
6009
|
+
batch = { id: this.reserve(), compressor, ids: [], bodyOffsets: [], bodyBytes: 0, indexBytes: 1 };
|
|
6010
|
+
this.compactIndices ??= new PdfCompactIndices(this.offsets.length);
|
|
6011
|
+
this.compactBatch = batch;
|
|
6012
|
+
}
|
|
6013
|
+
this.storeCompactBody(batch, id, written);
|
|
6014
|
+
if (batch.ids.length === compactObjectCount)
|
|
6015
|
+
await this.flushCompact();
|
|
6016
|
+
}
|
|
6017
|
+
storeCompactBody(batch, id, written) {
|
|
6018
|
+
this.offsets[id] = batch.id;
|
|
6019
|
+
this.compactIndices.set(id, batch.ids.length);
|
|
6020
|
+
batch.indexBytes += String(id).length + String(batch.bodyBytes).length + 2;
|
|
6021
|
+
batch.ids.push(id);
|
|
6022
|
+
batch.bodyOffsets.push(batch.bodyBytes);
|
|
6023
|
+
this.compactArena[batch.bodyBytes + written] = 10;
|
|
6024
|
+
batch.bodyBytes += written + 1;
|
|
6025
|
+
}
|
|
6026
|
+
/** An incomplete encoding leaves only scratch bytes beyond the committed batch prefix. */
|
|
6027
|
+
encodeCompactBody(body, offset, available) {
|
|
6028
|
+
if (available < 0)
|
|
6029
|
+
return undefined;
|
|
6030
|
+
const destination = (this.compactArena ??= new Uint8Array(compactObjectBytes)).subarray(offset, offset + available);
|
|
6031
|
+
if (typeof this.encoder.encodeInto === "function") {
|
|
6032
|
+
const result = this.encoder.encodeInto(body, destination);
|
|
6033
|
+
return result.read === body.length ? result.written : undefined;
|
|
6034
|
+
}
|
|
6035
|
+
// Preserve TextEncoder implementations that only expose encode().
|
|
6036
|
+
const bytes = this.encoder.encode(body);
|
|
6037
|
+
if (bytes.length > available)
|
|
6038
|
+
return undefined;
|
|
6039
|
+
destination.set(bytes);
|
|
6040
|
+
return bytes.length;
|
|
6041
|
+
}
|
|
6042
|
+
async flushCompact() {
|
|
6043
|
+
const batch = this.compactBatch;
|
|
6044
|
+
if (!batch)
|
|
6045
|
+
return;
|
|
6046
|
+
this.compactBatch = undefined;
|
|
6047
|
+
let index = "";
|
|
6048
|
+
for (let member = 0; member < batch.ids.length; member++)
|
|
6049
|
+
index += batch.ids[member] + " " + batch.bodyOffsets[member] + " ";
|
|
6050
|
+
const header = this.encoder.encode(index + "\n"), count = batch.ids.length;
|
|
6051
|
+
// Keep the index separate from the arena. Reuse waits for the compressed read or all raw
|
|
6052
|
+
// writes below, so later members cannot overwrite a borrowed batch body.
|
|
6053
|
+
const body = this.compactArena.subarray(0, batch.bodyBytes);
|
|
6054
|
+
batch.ids.length = 0;
|
|
6055
|
+
batch.bodyOffsets.length = 0;
|
|
6056
|
+
if (batch.compressor) {
|
|
6057
|
+
await this.compressedStream(batch.id, body, "/Type /ObjStm /N " + count + " /First " + header.length, batch.compressor, header);
|
|
6058
|
+
}
|
|
6059
|
+
else {
|
|
6060
|
+
this.start(batch.id);
|
|
6061
|
+
await this.text(batch.id + " 0 obj\n<< /Length " + (header.length + body.length) + " /Type /ObjStm /N " + count + " /First " + header.length + " >>\nstream\n");
|
|
6062
|
+
await this.raw(header);
|
|
6063
|
+
await this.raw(body);
|
|
6064
|
+
await this.text("\nendstream\nendobj\n");
|
|
6065
|
+
}
|
|
6066
|
+
}
|
|
5838
6067
|
async object(id, body) {
|
|
5839
6068
|
this.start(id);
|
|
5840
6069
|
if (typeof body === "string") {
|
|
@@ -5858,9 +6087,12 @@ class PdfObjects {
|
|
|
5858
6087
|
}
|
|
5859
6088
|
await this.text(chunk + "\nendobj\n");
|
|
5860
6089
|
}
|
|
5861
|
-
|
|
5862
|
-
if (!Number.
|
|
6090
|
+
validateObject(id) {
|
|
6091
|
+
if (!Number.isSafeInteger(id) || id <= 0 || id >= this.offsets.length || this.offsets[id] !== undefined)
|
|
5863
6092
|
throw new Error("Invalid PDF object state.");
|
|
6093
|
+
}
|
|
6094
|
+
start(id) {
|
|
6095
|
+
this.validateObject(id);
|
|
5864
6096
|
this.offsets[id] = this.bytes;
|
|
5865
6097
|
}
|
|
5866
6098
|
async stream(id, source, dictionary = "", compression = true, owned = false) {
|
|
@@ -5881,7 +6113,15 @@ class PdfObjects {
|
|
|
5881
6113
|
}
|
|
5882
6114
|
// Verified internal producers can transfer immutable ownership; other byte sources retain the defensive snapshot.
|
|
5883
6115
|
const sourceBytes = typeof source === "string" || owned ? bytes : new Uint8Array(bytes);
|
|
5884
|
-
|
|
6116
|
+
await this.compressedStream(id, sourceBytes, dictionary, compressor);
|
|
6117
|
+
}
|
|
6118
|
+
async compressedStream(id, sourceBytes, dictionary, compressor, prefix) {
|
|
6119
|
+
const input = new ReadableStream({ start(controller) {
|
|
6120
|
+
if (prefix)
|
|
6121
|
+
controller.enqueue(prefix);
|
|
6122
|
+
controller.enqueue(sourceBytes);
|
|
6123
|
+
controller.close();
|
|
6124
|
+
} });
|
|
5885
6125
|
const reader = input.pipeThrough(compressor).getReader(), lengthId = this.reserve();
|
|
5886
6126
|
let length = 0, complete = false;
|
|
5887
6127
|
try {
|
|
@@ -5906,10 +6146,14 @@ class PdfObjects {
|
|
|
5906
6146
|
}
|
|
5907
6147
|
}
|
|
5908
6148
|
async finish(root, info) {
|
|
5909
|
-
|
|
5910
|
-
|
|
6149
|
+
await this.flushCompact();
|
|
6150
|
+
for (let id = 1; id < this.offsets.length; id++)
|
|
6151
|
+
if (this.offsets[id] === undefined)
|
|
6152
|
+
throw new Error("PDF contains unwritten objects.");
|
|
5911
6153
|
if (this.bytes > 9999999999)
|
|
5912
6154
|
throw new OfficeIMOError("RESOURCE_LIMIT", "PDF exceeds classic cross-reference offset capacity.");
|
|
6155
|
+
if (this.compactIndices)
|
|
6156
|
+
return this.finishCompact(root, info);
|
|
5913
6157
|
const start = this.bytes;
|
|
5914
6158
|
await this.text("xref\n0 " + this.offsets.length + "\n0000000000 65535 f \n");
|
|
5915
6159
|
for (let i = 1; i < this.offsets.length; i++)
|
|
@@ -5917,12 +6161,26 @@ class PdfObjects {
|
|
|
5917
6161
|
await this.text("trailer\n<< /Size " + this.offsets.length + " /Root " + root + " 0 R /Info " + info + " 0 R >>\nstartxref\n" + start + "\n%%EOF\n");
|
|
5918
6162
|
await this.flush();
|
|
5919
6163
|
}
|
|
6164
|
+
/** Xref payloads have a known length and are emitted in bounded chunks, without another copy
|
|
6165
|
+
* of the document's random-access location arrays or a whole-xref compression buffer. */
|
|
6166
|
+
async finishCompact(root, info) {
|
|
6167
|
+
const id = this.reserve(), start = this.bytes, length = this.offsets.length * pdfXrefEntryBytes;
|
|
6168
|
+
if (!Number.isSafeInteger(length))
|
|
6169
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "PDF cross-reference stream is too large.");
|
|
6170
|
+
this.start(id);
|
|
6171
|
+
await this.text(id + " 0 obj\n<< /Type /XRef /Size " + this.offsets.length + " /W [1 8 2] /Root " + root + " 0 R /Info " + info +
|
|
6172
|
+
" 0 R /Length " + length + " >>\nstream\n");
|
|
6173
|
+
for (const chunk of pdfXrefChunks(this.offsets, this.compactIndices))
|
|
6174
|
+
await this.raw(chunk);
|
|
6175
|
+
await this.text("\nendstream\nendobj\nstartxref\n" + start + "\n%%EOF\n");
|
|
6176
|
+
await this.flushBytes();
|
|
6177
|
+
}
|
|
5920
6178
|
}
|
|
5921
6179
|
const _exports = Object.freeze({ pdfNumber: pdfNumber, unicodeHex: unicodeHex, PdfObjects: PdfObjects });
|
|
5922
6180
|
return _exports;
|
|
5923
6181
|
})();
|
|
5924
6182
|
|
|
5925
|
-
const
|
|
6183
|
+
const _m64 = (() => {
|
|
5926
6184
|
/** @internal Bounded big-endian reader used for caller-provided TrueType programs. */
|
|
5927
6185
|
class FontReader {
|
|
5928
6186
|
bytes;
|
|
@@ -5951,8 +6209,8 @@ const _exports = Object.freeze({ FontReader: FontReader, checksum: checksum, ali
|
|
|
5951
6209
|
return _exports;
|
|
5952
6210
|
})();
|
|
5953
6211
|
|
|
5954
|
-
const
|
|
5955
|
-
const { align4 } =
|
|
6212
|
+
const _m65 = (() => {
|
|
6213
|
+
const { align4 } = _m64;
|
|
5956
6214
|
|
|
5957
6215
|
const { checkAbort, pause, taskYieldDue } = _m4;
|
|
5958
6216
|
|
|
@@ -6175,12 +6433,12 @@ const _exports = Object.freeze({ subsetTrueType: subsetTrueType, subsetTrueTypeC
|
|
|
6175
6433
|
return _exports;
|
|
6176
6434
|
})();
|
|
6177
6435
|
|
|
6178
|
-
const
|
|
6436
|
+
const _m63 = (() => {
|
|
6179
6437
|
const { NotSupportedError } = _m2;
|
|
6180
6438
|
|
|
6181
|
-
const { FontReader } =
|
|
6439
|
+
const { FontReader } = _m64;
|
|
6182
6440
|
|
|
6183
|
-
const { subsetTrueType, subsetTrueTypeCooperatively } =
|
|
6441
|
+
const { subsetTrueType, subsetTrueTypeCooperatively } = _m65;
|
|
6184
6442
|
|
|
6185
6443
|
const { checkAbort, pause, taskYieldDue } = _m4;
|
|
6186
6444
|
|
|
@@ -6419,8 +6677,8 @@ const _exports = Object.freeze({ TrueTypeFont: TrueTypeFont });
|
|
|
6419
6677
|
return _exports;
|
|
6420
6678
|
})();
|
|
6421
6679
|
|
|
6422
|
-
const
|
|
6423
|
-
const { TrueTypeFont } =
|
|
6680
|
+
const _m62 = (() => {
|
|
6681
|
+
const { TrueTypeFont } = _m63;
|
|
6424
6682
|
|
|
6425
6683
|
const { beginTask, checkAbort } = _m4;
|
|
6426
6684
|
|
|
@@ -6482,7 +6740,7 @@ const _exports = Object.freeze({ fontProgram: fontProgram, PdfFont: PdfFont });
|
|
|
6482
6740
|
return _exports;
|
|
6483
6741
|
})();
|
|
6484
6742
|
|
|
6485
|
-
const
|
|
6743
|
+
const _m67 = (() => {
|
|
6486
6744
|
// Generated by scripts/pdf-widths.mjs from OfficeIMO.Pdf's Adobe AFM-derived metrics.
|
|
6487
6745
|
const helveticaWidths = new Map([
|
|
6488
6746
|
[32, [278, 278]],
|
|
@@ -6804,12 +7062,12 @@ const _exports = Object.freeze({ helveticaWidths: helveticaWidths });
|
|
|
6804
7062
|
return _exports;
|
|
6805
7063
|
})();
|
|
6806
7064
|
|
|
6807
|
-
const
|
|
7065
|
+
const _m66 = (() => {
|
|
6808
7066
|
const { OfficeIMOError } = _m2;
|
|
6809
7067
|
|
|
6810
|
-
const { PdfFont, fontProgram } =
|
|
7068
|
+
const { PdfFont, fontProgram } = _m62;
|
|
6811
7069
|
|
|
6812
|
-
const { helveticaWidths } =
|
|
7070
|
+
const { helveticaWidths } = _m67;
|
|
6813
7071
|
|
|
6814
7072
|
const winAnsiExtras = new Map([0x20ac, 0, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6, 0x2030, 0x160, 0x2039, 0x152, 0, 0x17d, 0, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc, 0x2122, 0x161, 0x203a, 0x153, 0, 0x17e, 0x178].map((cp, i) => [cp, i + 128]));
|
|
6815
7073
|
/** @internal Called after scalar support succeeds when encoding a standard-font run. */
|
|
@@ -6872,17 +7130,18 @@ const _exports = Object.freeze({ standardCode: standardCode, resolveScalar: reso
|
|
|
6872
7130
|
return _exports;
|
|
6873
7131
|
})();
|
|
6874
7132
|
|
|
6875
|
-
const
|
|
7133
|
+
const _m61 = (() => {
|
|
6876
7134
|
const { NotSupportedError, OfficeIMOError } = _m2;
|
|
6877
7135
|
|
|
6878
|
-
const { fontProgram } =
|
|
7136
|
+
const { fontProgram } = _m62;
|
|
6879
7137
|
|
|
6880
|
-
const { resolveScalar, selectFont, standardCode, validateFonts } =
|
|
7138
|
+
const { resolveScalar, selectFont, standardCode, validateFonts } = _m66;
|
|
6881
7139
|
|
|
6882
7140
|
const { pdfNumber, unicodeHex } = _m59;
|
|
6883
7141
|
|
|
6884
7142
|
const { checkAbort, pause, taskYieldDue } = _m4;
|
|
6885
7143
|
|
|
7144
|
+
const standardHexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
|
|
6886
7145
|
class PdfFontResource {
|
|
6887
7146
|
index;
|
|
6888
7147
|
bold;
|
|
@@ -6945,7 +7204,7 @@ class PdfFontResource {
|
|
|
6945
7204
|
for (const char of text) {
|
|
6946
7205
|
const cp = char.codePointAt(0);
|
|
6947
7206
|
this.width(cp);
|
|
6948
|
-
hex +=
|
|
7207
|
+
hex += this.program ? this.mappings.get(cp).cid.toString(16).padStart(4, "0") : standardHexBytes[standardCode(cp)];
|
|
6949
7208
|
}
|
|
6950
7209
|
return "<" + hex + ">";
|
|
6951
7210
|
}
|
|
@@ -7083,7 +7342,7 @@ const _exports = Object.freeze({ PdfFontResource: PdfFontResource, PdfFontResour
|
|
|
7083
7342
|
return _exports;
|
|
7084
7343
|
})();
|
|
7085
7344
|
|
|
7086
|
-
const
|
|
7345
|
+
const _m69 = (() => {
|
|
7087
7346
|
const { OfficeIMOError } = _m2;
|
|
7088
7347
|
|
|
7089
7348
|
const { ExportCell, assertExportValue } = _m5;
|
|
@@ -7094,6 +7353,11 @@ const { isDate } = _m6;
|
|
|
7094
7353
|
|
|
7095
7354
|
const { defaultBooleanText } = _m18;
|
|
7096
7355
|
|
|
7356
|
+
/** @internal Charge displayed characters: tabs paint four spaces, while CR/LF only separate lines.
|
|
7357
|
+
* Raw text remains authoritative for input limits and layout. Skip normalization when no text ceiling observes it. */
|
|
7358
|
+
function pdfBudgetText(text, budget) {
|
|
7359
|
+
return budget.limits.maxTextCharacters === undefined ? text : text.replace(/[\t\r\n]/g, character => character === "\t" ? " " : "");
|
|
7360
|
+
}
|
|
7097
7361
|
function synchronousText(value, name) {
|
|
7098
7362
|
if (typeof value === "string")
|
|
7099
7363
|
return value;
|
|
@@ -7185,11 +7449,11 @@ function* wrapSteps(text, font, size, width, maxCharacters, maxLines, wrap) {
|
|
|
7185
7449
|
}
|
|
7186
7450
|
return lines;
|
|
7187
7451
|
}
|
|
7188
|
-
const _exports = Object.freeze({ synchronousText: synchronousText, displayText: displayText, wrapText: wrapText, wrapTextCooperatively: wrapTextCooperatively });
|
|
7452
|
+
const _exports = Object.freeze({ pdfBudgetText: pdfBudgetText, synchronousText: synchronousText, displayText: displayText, wrapText: wrapText, wrapTextCooperatively: wrapTextCooperatively });
|
|
7189
7453
|
return _exports;
|
|
7190
7454
|
})();
|
|
7191
7455
|
|
|
7192
|
-
const
|
|
7456
|
+
const _m71 = (() => {
|
|
7193
7457
|
const { NotSupportedError, OfficeIMOError } = _m2;
|
|
7194
7458
|
|
|
7195
7459
|
const { checkAbort, pause, taskYieldDue, withAbort } = _m4;
|
|
@@ -7401,7 +7665,7 @@ const _exports = Object.freeze({ wrapShapedPdfText: wrapShapedPdfText });
|
|
|
7401
7665
|
return _exports;
|
|
7402
7666
|
})();
|
|
7403
7667
|
|
|
7404
|
-
const
|
|
7668
|
+
const _m70 = (() => {
|
|
7405
7669
|
const { NotSupportedError, OfficeIMOError } = _m2;
|
|
7406
7670
|
|
|
7407
7671
|
const { copyExportLink } = _m7;
|
|
@@ -7410,21 +7674,30 @@ const { checkAbort, pause, taskYieldDue } = _m4;
|
|
|
7410
7674
|
|
|
7411
7675
|
const { presentation, color } = _m55;
|
|
7412
7676
|
|
|
7413
|
-
const { wrapShapedPdfText } =
|
|
7677
|
+
const { wrapShapedPdfText } = _m71;
|
|
7414
7678
|
|
|
7415
|
-
const { PdfFont } =
|
|
7679
|
+
const { PdfFont } = _m62;
|
|
7416
7680
|
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7681
|
+
const { pdfBudgetText } = _m69;
|
|
7682
|
+
|
|
7683
|
+
/** @internal Callers supply an owned, validated, frozen base presentation. A run list is a PDF presentation value, never an alternate shared table value model. */
|
|
7684
|
+
function capturePdfText(value, base, settings, fonts, countEmpty = true, reserveBudget = true) {
|
|
7685
|
+
if (typeof value === "string") {
|
|
7686
|
+
if (value.length > settings.limits.maxCellCharacters)
|
|
7687
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded.");
|
|
7688
|
+
if (reserveBudget && (value.length || countEmpty))
|
|
7689
|
+
settings.budget.reserve(1, pdfBudgetText(value, settings.budget).length);
|
|
7690
|
+
return Object.freeze({ text: value, runs: Object.freeze([Object.freeze({ text: value, style: base })]) });
|
|
7691
|
+
}
|
|
7692
|
+
const input = value;
|
|
7420
7693
|
if (!Array.isArray(input)) {
|
|
7421
7694
|
if (input && typeof input.then === "function")
|
|
7422
7695
|
void Promise.resolve(input).catch(() => { });
|
|
7423
7696
|
throw new TypeError("PDF text must be a string or a synchronous array of text runs.");
|
|
7424
7697
|
}
|
|
7425
|
-
if (
|
|
7698
|
+
if (input.length > settings.limits.maxTextRuns)
|
|
7426
7699
|
throw new OfficeIMOError("RESOURCE_LIMIT", "maxTextRuns exceeded.");
|
|
7427
|
-
let characters = 0;
|
|
7700
|
+
let characters = 0, budgetCharacters = 0;
|
|
7428
7701
|
const runs = [];
|
|
7429
7702
|
for (const run of input) {
|
|
7430
7703
|
if (!run || typeof run !== "object" || Object.keys(run).some(key => !["text", "bold", "italic", "color", "link", "font"].includes(key)))
|
|
@@ -7440,14 +7713,16 @@ function capturePdfText(value, base, settings, fonts, countEmpty = true) {
|
|
|
7440
7713
|
characters += text.length;
|
|
7441
7714
|
if (characters > settings.limits.maxCellCharacters)
|
|
7442
7715
|
throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded.");
|
|
7716
|
+
if (reserveBudget)
|
|
7717
|
+
budgetCharacters += pdfBudgetText(text, settings.budget).length;
|
|
7443
7718
|
const style = presentation({ ...base, ...(bold === undefined ? {} : { bold }), ...(italic === undefined ? {} : { italic }), ...(color === undefined ? {} : { color }) });
|
|
7444
7719
|
if (settings.options.tagged && link !== undefined && text.length && !text.trim())
|
|
7445
7720
|
throw new TypeError("Tagged PDF inline links require nonempty displayed text.");
|
|
7446
7721
|
runs.push(Object.freeze({ text, style, ...(font === undefined ? {} : { font }), ...(link === undefined ? {} : { link: copyExportLink(link) }) }));
|
|
7447
7722
|
}
|
|
7448
7723
|
// Reserve before allocating a joined rich-text value or retaining it in a kept paragraph chain.
|
|
7449
|
-
if (characters || countEmpty)
|
|
7450
|
-
settings.budget.reserve(1,
|
|
7724
|
+
if (reserveBudget && (characters || countEmpty))
|
|
7725
|
+
settings.budget.reserve(1, budgetCharacters);
|
|
7451
7726
|
return Object.freeze({ text: runs.map(run => run.text).join(""), runs: Object.freeze(runs) });
|
|
7452
7727
|
}
|
|
7453
7728
|
/** @internal Greedy wrapping over the continuous text stream, preserving run emphasis and URI geometry. */
|
|
@@ -7456,8 +7731,39 @@ async function wrapPdfText(captured, fonts, size, width, settings, wrap = true)
|
|
|
7456
7731
|
return wrapShapedPdfText(captured, fonts, size, width, settings, wrap);
|
|
7457
7732
|
const { signal } = settings.options, { text, runs } = captured;
|
|
7458
7733
|
checkAbort(signal);
|
|
7459
|
-
|
|
7460
|
-
const
|
|
7734
|
+
// Keep font-selection order while deferring a single-run face array until wrapping needs it.
|
|
7735
|
+
const single = runs.length === 1 ? runs[0] : undefined;
|
|
7736
|
+
const singleFace = single && fonts.select(single.style.bold, single.style.italic, single.font);
|
|
7737
|
+
const selectedFaces = singleFace ? undefined : runs.map(run => fonts.select(run.style.bold, run.style.italic, run.font));
|
|
7738
|
+
const fallback = fonts.select();
|
|
7739
|
+
// Short fitting runs need no per-character layout arrays. Longer text keeps the existing
|
|
7740
|
+
// cooperative checkpoints; controls or the first overflowing advance use the general path.
|
|
7741
|
+
if (single && text.length > 0 && text.length < 4096) {
|
|
7742
|
+
const run = single, font = singleFace;
|
|
7743
|
+
let widthSoFar = 0, fits = true;
|
|
7744
|
+
for (let offset = 0; offset < text.length;) {
|
|
7745
|
+
const scalar = text.codePointAt(offset);
|
|
7746
|
+
if (scalar === 9 || scalar === 10 || scalar === 13) {
|
|
7747
|
+
fits = false;
|
|
7748
|
+
break;
|
|
7749
|
+
}
|
|
7750
|
+
const advance = font.width(scalar) * size / 1000;
|
|
7751
|
+
if (advance > width + .001 || widthSoFar + advance > width + .001) {
|
|
7752
|
+
fits = false;
|
|
7753
|
+
break;
|
|
7754
|
+
}
|
|
7755
|
+
widthSoFar += advance;
|
|
7756
|
+
offset += scalar > 0xffff ? 2 : 1;
|
|
7757
|
+
}
|
|
7758
|
+
if (fits) {
|
|
7759
|
+
if (settings.limits.maxRowLines < 1)
|
|
7760
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxRowLines exceeded.");
|
|
7761
|
+
return [{ text, width: widthSoFar, segments: [{ text, width: widthSoFar, font,
|
|
7762
|
+
...(run.style.color === undefined ? {} : { color: run.style.color }), ...(run.link ? { link: run.link } : {}) }],
|
|
7763
|
+
lineHeight: font.lineHeight(size), ascent: Math.max(0, (font.program?.ascent ?? 800) * size / 1000) }];
|
|
7764
|
+
}
|
|
7765
|
+
}
|
|
7766
|
+
const faces = selectedFaces ?? [singleFace], lines = [];
|
|
7461
7767
|
let chars = [], advances = [], owners = [], measured = 0, breakAt = -1;
|
|
7462
7768
|
let runIndex = 0, runEnd = runs[0]?.text.length ?? 0, scanned = 0;
|
|
7463
7769
|
const emit = (count) => {
|
|
@@ -7554,19 +7860,17 @@ const _exports = Object.freeze({ capturePdfText: capturePdfText, wrapPdfText: wr
|
|
|
7554
7860
|
return _exports;
|
|
7555
7861
|
})();
|
|
7556
7862
|
|
|
7557
|
-
const
|
|
7863
|
+
const _m72 = (() => {
|
|
7558
7864
|
const { OfficeIMOError } = _m2;
|
|
7559
7865
|
|
|
7560
|
-
const { wrapPdfText } =
|
|
7866
|
+
const { wrapPdfText } = _m70;
|
|
7561
7867
|
|
|
7562
7868
|
/** Plan without opening a source. Exact column widths never shrink in band mode. */
|
|
7563
7869
|
function planTableBands(widths, settings) {
|
|
7564
7870
|
const policy = settings.options.wideTable;
|
|
7565
7871
|
if (typeof policy !== "object")
|
|
7566
7872
|
return undefined;
|
|
7567
|
-
const available = settings.page.width - settings.margins.left - settings.margins.right, repeats =
|
|
7568
|
-
if (repeats.some(index => index >= widths.length))
|
|
7569
|
-
throw new RangeError("repeatColumns index exceeds the declared columns.");
|
|
7873
|
+
const available = settings.page.width - settings.margins.left - settings.margins.right, repeats = settings.repeatedColumns;
|
|
7570
7874
|
const repeated = new Set(repeats), rest = widths.map((_, index) => index).filter(index => !repeated.has(index));
|
|
7571
7875
|
const prefix = repeats.reduce((sum, index) => sum + widths[index], 0);
|
|
7572
7876
|
if (prefix > available + .001)
|
|
@@ -7646,7 +7950,7 @@ const _exports = Object.freeze({ planTableBands: planTableBands, projectBandRows
|
|
|
7646
7950
|
return _exports;
|
|
7647
7951
|
})();
|
|
7648
7952
|
|
|
7649
|
-
const
|
|
7953
|
+
const _m68 = (() => {
|
|
7650
7954
|
const { ExportCell } = _m5;
|
|
7651
7955
|
|
|
7652
7956
|
const { copyExportLink } = _m7;
|
|
@@ -7657,11 +7961,11 @@ const { createTotals } = _m12;
|
|
|
7657
7961
|
|
|
7658
7962
|
const { presentation, positive } = _m55;
|
|
7659
7963
|
|
|
7660
|
-
const { displayText } =
|
|
7964
|
+
const { displayText, pdfBudgetText } = _m69;
|
|
7661
7965
|
|
|
7662
|
-
const { capturePdfText, wrapPdfText } =
|
|
7966
|
+
const { capturePdfText, wrapPdfText } = _m70;
|
|
7663
7967
|
|
|
7664
|
-
const { planTableBands, projectBandRows, alignBandBlocks } =
|
|
7968
|
+
const { planTableBands, projectBandRows, alignBandBlocks } = _m72;
|
|
7665
7969
|
|
|
7666
7970
|
class PdfTableLayout {
|
|
7667
7971
|
settings;
|
|
@@ -7674,11 +7978,13 @@ class PdfTableLayout {
|
|
|
7674
7978
|
totals;
|
|
7675
7979
|
repeatedColumns;
|
|
7676
7980
|
structuredBandRows = new WeakMap();
|
|
7981
|
+
/** Plain/alternate ordinary-data defaults, validated only when a column first needs them. */
|
|
7982
|
+
dataPresentations = [];
|
|
7677
7983
|
constructor(settings, fonts) {
|
|
7678
7984
|
this.settings = settings;
|
|
7679
7985
|
this.fonts = fonts;
|
|
7680
7986
|
const { options, padding, fontSize, page, margins } = settings, columns = options.columns, available = page.width - margins.left - margins.right;
|
|
7681
|
-
this.repeatedColumns = new Set(
|
|
7987
|
+
this.repeatedColumns = new Set(settings.repeatedColumns);
|
|
7682
7988
|
let digit;
|
|
7683
7989
|
if (options.columnWidths && options.columnWidths.length !== columns.length)
|
|
7684
7990
|
throw new RangeError("columnWidths must declare one point width per column.");
|
|
@@ -7719,13 +8025,22 @@ class PdfTableLayout {
|
|
|
7719
8025
|
this.headings = headings;
|
|
7720
8026
|
this.totals = createTotals(columns, options.footer?.totals);
|
|
7721
8027
|
}
|
|
7722
|
-
async cell(value, first, span, row, style) {
|
|
8028
|
+
async cell(value, first, span, row, style, ordinaryData = false) {
|
|
7723
8029
|
const { options, padding, fontSize, budget } = this.settings, column = options.columns[first];
|
|
7724
8030
|
const own = value instanceof ExportCell ? value.presentation : undefined;
|
|
7725
8031
|
const link = value instanceof ExportCell && value.link ? copyExportLink(value.link) : undefined;
|
|
7726
|
-
const
|
|
7727
|
-
|
|
7728
|
-
|
|
8032
|
+
const alternate = ordinaryData && row % 2 && options.alternateRowColor ? options.alternateRowColor : undefined;
|
|
8033
|
+
const slot = first * 2 + (alternate ? 1 : 0), reusable = ordinaryData && own === undefined;
|
|
8034
|
+
let combined = reusable ? this.dataPresentations[slot] : undefined;
|
|
8035
|
+
if (!combined) {
|
|
8036
|
+
const rowStyle = ordinaryData ? alternate ? { background: alternate } : {} : style;
|
|
8037
|
+
combined = presentation({ ...(column.alignment === undefined ? {} : { alignment: column.alignment }),
|
|
8038
|
+
...(column.wrapText === undefined ? {} : { wrapText: column.wrapText }), ...rowStyle, ...own });
|
|
8039
|
+
// Validate only the first reached default; an authored cell may override invalid column defaults.
|
|
8040
|
+
if (reusable)
|
|
8041
|
+
this.dataPresentations[slot] = combined;
|
|
8042
|
+
}
|
|
8043
|
+
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);
|
|
7729
8044
|
const context = { rowIndex: row, columnIndex: first, column }, raw = value instanceof ExportCell ? value.value : value;
|
|
7730
8045
|
let text;
|
|
7731
8046
|
if (options.formatRuns && row >= 0 && !(value instanceof ExportCell && value.text !== undefined)) {
|
|
@@ -7744,10 +8059,11 @@ class PdfTableLayout {
|
|
|
7744
8059
|
throw new TypeError("Tagged PDF cell links require nonempty displayed text.");
|
|
7745
8060
|
if (link && captured.runs.some(run => run.link))
|
|
7746
8061
|
throw new TypeError("A PDF cell link cannot be combined with inline run links.");
|
|
8062
|
+
const budgetText = pdfBudgetText(captured.text, budget);
|
|
7747
8063
|
if (this.bands)
|
|
7748
|
-
budget.release(1,
|
|
8064
|
+
budget.release(1, budgetText.length);
|
|
7749
8065
|
else
|
|
7750
|
-
budget.cell(
|
|
8066
|
+
budget.cell(budgetText, budgetText.length);
|
|
7751
8067
|
const lines = await wrapPdfText(captured, this.fonts, fontSize, width - padding * 2, this.settings, combined.wrapText !== false);
|
|
7752
8068
|
return { first, span, width, font, style: combined, lineHeight: lines.reduce((height, line) => Math.max(height, line.lineHeight), font.lineHeight(fontSize)),
|
|
7753
8069
|
...(link ? { link } : {}), ...(this.bands ? { captured } : {}),
|
|
@@ -7846,8 +8162,8 @@ class PdfTableLayout {
|
|
|
7846
8162
|
const value = values[column], raw = value instanceof ExportCell ? value.value : value;
|
|
7847
8163
|
if (!footer)
|
|
7848
8164
|
this.totals[column].accept(raw);
|
|
7849
|
-
const
|
|
7850
|
-
cells.push(
|
|
8165
|
+
const cell = await this.cell(value, column, 1, index, footer ? options.footerPresentation ?? {} : undefined, !footer);
|
|
8166
|
+
cells.push(!footer && options.columns[column].rowHeader ? { ...cell, rowHeader: true } : cell);
|
|
7851
8167
|
}
|
|
7852
8168
|
return this.row(cells);
|
|
7853
8169
|
}
|
|
@@ -7864,7 +8180,7 @@ const _exports = Object.freeze({ PdfTableLayout: PdfTableLayout });
|
|
|
7864
8180
|
return _exports;
|
|
7865
8181
|
})();
|
|
7866
8182
|
|
|
7867
|
-
const
|
|
8183
|
+
const _m74 = (() => {
|
|
7868
8184
|
const { OfficeIMOError } = _m2;
|
|
7869
8185
|
|
|
7870
8186
|
const { checkAbort } = _m4;
|
|
@@ -7908,7 +8224,7 @@ class PdfTableBandFlow {
|
|
|
7908
8224
|
await this.flush();
|
|
7909
8225
|
}
|
|
7910
8226
|
async row(row, allowFirstFragment = false) {
|
|
7911
|
-
const { padding, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
|
|
8227
|
+
const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
|
|
7912
8228
|
if (minimumHeight > this.painter.firstFullCapacity + .001 || minimumHeight > this.painter.continuationCapacity + .001)
|
|
7913
8229
|
throw new RangeError("Repeated PDF identifiers must fit intact below the first and continued band headings/context.");
|
|
7914
8230
|
// Keep ordinary rows intact when they fit fresh. A kept heading/caption can deliberately
|
|
@@ -7934,16 +8250,29 @@ class PdfTableBandFlow {
|
|
|
7934
8250
|
const lines = Math.min(row.lines - first, Math.floor((this.capacity - this.height - padding * 2 + .001) / row.lineHeight));
|
|
7935
8251
|
if (lines < 1)
|
|
7936
8252
|
throw new RangeError("PDF page cannot fit a table line below horizontal band headings.");
|
|
7937
|
-
|
|
8253
|
+
// Reserve one shared logical fragment, but paint only each band's visible cell geometry.
|
|
8254
|
+
const reservedLines = Math.max(lines, minimumLines), height = reservedLines * row.lineHeight + padding * 2;
|
|
7938
8255
|
const projected = await this.layout.bandRows([row]);
|
|
7939
|
-
const
|
|
7940
|
-
|
|
7941
|
-
|
|
7942
|
-
|
|
7943
|
-
|
|
7944
|
-
|
|
7945
|
-
|
|
7946
|
-
|
|
8256
|
+
const exhaustedBands = [];
|
|
8257
|
+
const fragments = projected.map((rows, index) => {
|
|
8258
|
+
let remaining = false;
|
|
8259
|
+
const cells = rows[0].cells.map(cell => {
|
|
8260
|
+
const source = this.layout.bands[index].columns[cell.first];
|
|
8261
|
+
const repeated = this.layout.repeatedColumn(source), visible = repeated ? cell.lines : cell.lines.slice(first, first + lines);
|
|
8262
|
+
if (!repeated && (visible.length > 0 || cell.link !== undefined))
|
|
8263
|
+
remaining = true;
|
|
8264
|
+
const { height: _height, ...plain } = cell;
|
|
8265
|
+
return { ...plain, lines: visible,
|
|
8266
|
+
lineHeight: visible.reduce((value, line) => Math.max(value, line.lineHeight), cell.font.lineHeight(fontSize)),
|
|
8267
|
+
...(first > 0 && repeated ? { semanticArtifact: true } : {}) };
|
|
8268
|
+
});
|
|
8269
|
+
const fragmentLines = Math.max(1, ...cells.map(cell => cell.lines.length));
|
|
8270
|
+
const lineHeight = Math.max(this.layout.lineHeight, ...cells.filter(cell => cell.lines.length > 0).map(cell => cell.lineHeight));
|
|
8271
|
+
// Never omit an initial/new row, a structured block, or a nonrepeated link obligation.
|
|
8272
|
+
exhaustedBands.push(first > 0 && !remaining);
|
|
8273
|
+
return [{ ...rows[0], cells, lines: fragmentLines, lineHeight, height: fragmentLines * lineHeight + padding * 2 }];
|
|
8274
|
+
});
|
|
8275
|
+
await this.accept({ rows: fragments, height, count: 1, completed: first + lines >= row.lines ? [row] : [], exhaustedBands });
|
|
7947
8276
|
first += lines;
|
|
7948
8277
|
if (first < row.lines)
|
|
7949
8278
|
await this.flush();
|
|
@@ -7955,7 +8284,7 @@ class PdfTableBandFlow {
|
|
|
7955
8284
|
throw new OfficeIMOError("RESOURCE_LIMIT", "A structured PDF block exceeds maxTableWindowRows.");
|
|
7956
8285
|
for (const row of rows)
|
|
7957
8286
|
await this.painter.prepareRow?.(row);
|
|
7958
|
-
await this.accept({ rows: projected, height, count: rows.length, completed: rows });
|
|
8287
|
+
await this.accept({ rows: projected, height, count: rows.length, completed: rows, exhaustedBands: projected.map(() => false) });
|
|
7959
8288
|
}
|
|
7960
8289
|
async keptRows(rows, allowFirstFragment = false) {
|
|
7961
8290
|
const height = rows.reduce((sum, row) => sum + row.height, 0), fits = height <= this.painter.continuationCapacity + .001;
|
|
@@ -7969,6 +8298,8 @@ class PdfTableBandFlow {
|
|
|
7969
8298
|
return;
|
|
7970
8299
|
for (let band = 0; band < this.layout.bands.length; band++) {
|
|
7971
8300
|
checkAbort(this.layout.settings.options.signal);
|
|
8301
|
+
if (!this.firstWindow && this.entries.length > 0 && this.entries.every(entry => entry.exhaustedBands[band]))
|
|
8302
|
+
continue;
|
|
7972
8303
|
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);
|
|
7973
8304
|
}
|
|
7974
8305
|
for (const entry of this.entries)
|
|
@@ -7985,7 +8316,7 @@ const _exports = Object.freeze({ PdfTableBandFlow: PdfTableBandFlow });
|
|
|
7985
8316
|
return _exports;
|
|
7986
8317
|
})();
|
|
7987
8318
|
|
|
7988
|
-
const
|
|
8319
|
+
const _m75 = (() => {
|
|
7989
8320
|
/** @internal Source-cell identities survive page fragments and horizontal band projections.
|
|
7990
8321
|
* Only column headers and still-owned row objects remain reachable from this table owner. */
|
|
7991
8322
|
class PdfTableStructure {
|
|
@@ -7995,6 +8326,8 @@ class PdfTableStructure {
|
|
|
7995
8326
|
cells = new WeakMap();
|
|
7996
8327
|
rows = new WeakMap();
|
|
7997
8328
|
columnHeaders = [];
|
|
8329
|
+
/** Ordinary cells without row headers share immutable dictionary references, bounded by column count. */
|
|
8330
|
+
ordinaryAttributes = [];
|
|
7998
8331
|
headerCount = 0;
|
|
7999
8332
|
headersPrepared = false;
|
|
8000
8333
|
constructor(structure, table, headers) {
|
|
@@ -8035,19 +8368,30 @@ class PdfTableStructure {
|
|
|
8035
8368
|
return row.cells.map(cell => this.cells.get(cell));
|
|
8036
8369
|
const rowId = this.structure.element("TR", parent);
|
|
8037
8370
|
this.rows.set(row, rowId);
|
|
8038
|
-
const
|
|
8039
|
-
|
|
8040
|
-
//
|
|
8371
|
+
const headers = row.cells.map((cell, index) => rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex);
|
|
8372
|
+
// Allocate in source order, then resolve every row header before associating even earlier data cells.
|
|
8373
|
+
// Generated summary labels override detail roles so numeric subtotal cells never become row headers.
|
|
8374
|
+
const ids = row.cells.map((cell, index) => {
|
|
8375
|
+
const id = this.structure.element(headers[index] ? "TH" : "TD", rowId);
|
|
8376
|
+
this.cells.set(cell, id);
|
|
8377
|
+
return id;
|
|
8378
|
+
});
|
|
8379
|
+
const rowHeaders = [];
|
|
8380
|
+
for (let index = 0; index < ids.length; index++)
|
|
8381
|
+
if (headers[index])
|
|
8382
|
+
rowHeaders.push(await this.structure.identifier(ids[index]));
|
|
8041
8383
|
for (let index = 0; index < row.cells.length; index++) {
|
|
8042
|
-
const cell = row.cells[index]
|
|
8384
|
+
const cell = row.cells[index];
|
|
8385
|
+
if (!rowHeaders.length && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
|
|
8386
|
+
const attributes = this.ordinaryAttributes[cell.first] ??=
|
|
8387
|
+
await this.structure.attributeReference(this.attributeDictionary(cell, this.associations(cell)));
|
|
8388
|
+
this.structure.setAttributes(ids[index], attributes);
|
|
8389
|
+
continue;
|
|
8390
|
+
}
|
|
8043
8391
|
const associations = this.associations(cell);
|
|
8044
|
-
if (
|
|
8045
|
-
associations.push(
|
|
8046
|
-
|
|
8047
|
-
this.cells.set(cell, id);
|
|
8048
|
-
ids.push(id);
|
|
8049
|
-
if (isRowHeader)
|
|
8050
|
-
rowHeaderIdentifier = await this.structure.identifier(id);
|
|
8392
|
+
if (!headers[index])
|
|
8393
|
+
associations.push(...rowHeaders);
|
|
8394
|
+
this.structure.setAttributes(ids[index], this.attributes(cell, associations, headers[index] ? "Row" : undefined));
|
|
8051
8395
|
}
|
|
8052
8396
|
return ids;
|
|
8053
8397
|
}
|
|
@@ -8073,7 +8417,10 @@ class PdfTableStructure {
|
|
|
8073
8417
|
return [...headers].sort((left, right) => left.order - right.order).map(header => header.identifier);
|
|
8074
8418
|
}
|
|
8075
8419
|
attributes(cell, headers, scope) {
|
|
8076
|
-
return " /A
|
|
8420
|
+
return " /A " + this.attributeDictionary(cell, headers, scope);
|
|
8421
|
+
}
|
|
8422
|
+
attributeDictionary(cell, headers, scope) {
|
|
8423
|
+
return "<< /O /Table" + (scope === undefined ? "" : " /Scope /" + scope) +
|
|
8077
8424
|
(cell.span > 1 ? " /ColSpan " + cell.span : "") + ((cell.rowSpan ?? 1) > 1 ? " /RowSpan " + cell.rowSpan : "") +
|
|
8078
8425
|
(headers.length ? " /Headers [" + headers.map(id => "(" + id + ")").join(" ") + "]" : "") + " >>";
|
|
8079
8426
|
}
|
|
@@ -8082,7 +8429,7 @@ const _exports = Object.freeze({ PdfTableStructure: PdfTableStructure });
|
|
|
8082
8429
|
return _exports;
|
|
8083
8430
|
})();
|
|
8084
8431
|
|
|
8085
|
-
const
|
|
8432
|
+
const _m76 = (() => {
|
|
8086
8433
|
const { OfficeIMOError } = _m2;
|
|
8087
8434
|
|
|
8088
8435
|
const { pdfNumber, unicodeHex } = _m59;
|
|
@@ -8127,7 +8474,7 @@ const _exports = Object.freeze({ linkAnnotation: linkAnnotation });
|
|
|
8127
8474
|
return _exports;
|
|
8128
8475
|
})();
|
|
8129
8476
|
|
|
8130
|
-
const
|
|
8477
|
+
const _m77 = (() => {
|
|
8131
8478
|
const { OfficeIMOError } = _m2;
|
|
8132
8479
|
|
|
8133
8480
|
const { unicodeHex } = _m59;
|
|
@@ -8175,7 +8522,7 @@ const _exports = Object.freeze({ captureBookmark: captureBookmark, captureSectio
|
|
|
8175
8522
|
return _exports;
|
|
8176
8523
|
})();
|
|
8177
8524
|
|
|
8178
|
-
const
|
|
8525
|
+
const _m78 = (() => {
|
|
8179
8526
|
const { settings } = _m55;
|
|
8180
8527
|
|
|
8181
8528
|
/** @internal Every section derives from captured document defaults, never the preceding section. */
|
|
@@ -8193,7 +8540,7 @@ const _exports = Object.freeze({ sectionSettings: sectionSettings });
|
|
|
8193
8540
|
return _exports;
|
|
8194
8541
|
})();
|
|
8195
8542
|
|
|
8196
|
-
const
|
|
8543
|
+
const _m73 = (() => {
|
|
8197
8544
|
const { OfficeIMOError } = _m2;
|
|
8198
8545
|
|
|
8199
8546
|
const { checkAbort } = _m4;
|
|
@@ -8202,19 +8549,19 @@ const { pdfNumber } = _m59;
|
|
|
8202
8549
|
|
|
8203
8550
|
const { color } = _m55;
|
|
8204
8551
|
|
|
8205
|
-
const { PdfTableBandFlow } =
|
|
8552
|
+
const { PdfTableBandFlow } = _m74;
|
|
8206
8553
|
|
|
8207
|
-
const { PdfTableStructure } =
|
|
8554
|
+
const { PdfTableStructure } = _m75;
|
|
8208
8555
|
|
|
8209
|
-
const { wrapText, wrapTextCooperatively, synchronousText } =
|
|
8556
|
+
const { wrapText, wrapTextCooperatively, synchronousText, pdfBudgetText } = _m69;
|
|
8210
8557
|
|
|
8211
|
-
const { linkAnnotation } =
|
|
8558
|
+
const { linkAnnotation } = _m76;
|
|
8212
8559
|
|
|
8213
8560
|
const { unicodeHex } = _m59;
|
|
8214
8561
|
|
|
8215
|
-
const { captureSection, captureBookmark } =
|
|
8562
|
+
const { captureSection, captureBookmark } = _m77;
|
|
8216
8563
|
|
|
8217
|
-
const { sectionSettings } =
|
|
8564
|
+
const { sectionSettings } = _m78;
|
|
8218
8565
|
|
|
8219
8566
|
/** @internal One page of drawing commands and O(page count) references, never the complete report body. */
|
|
8220
8567
|
class PdfPages {
|
|
@@ -8352,8 +8699,9 @@ class PdfPages {
|
|
|
8352
8699
|
const lineActualText = !this.structure && line.actualText !== undefined && line.actualText.length > 0;
|
|
8353
8700
|
if (lineActualText)
|
|
8354
8701
|
this.add("/Span << /ActualText <FEFF" + unicodeHex(line.actualText) + "> >> BDC\n");
|
|
8355
|
-
|
|
8702
|
+
let marks;
|
|
8356
8703
|
if (line.actualText !== undefined && this.structure && element !== undefined) {
|
|
8704
|
+
marks = new Map();
|
|
8357
8705
|
// Allocate MCIDs/Link children in logical order, then paint the independently positioned visual order.
|
|
8358
8706
|
for (const segment of [...line.segments].sort((a, b) => (a.logicalStart ?? 0) - (b.logicalStart ?? 0))) {
|
|
8359
8707
|
const owner = segment.link ? this.structure.link(element, segment.link) : element;
|
|
@@ -8361,7 +8709,7 @@ class PdfPages {
|
|
|
8361
8709
|
}
|
|
8362
8710
|
}
|
|
8363
8711
|
for (const segment of line.segments) {
|
|
8364
|
-
const registered = marks
|
|
8712
|
+
const registered = marks?.get(segment), owner = registered?.owner ?? (segment.link && this.structure && element !== undefined ? this.structure.link(element, segment.link) : element);
|
|
8365
8713
|
if (segment.glyphs) {
|
|
8366
8714
|
const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
|
|
8367
8715
|
let cursor = x, command = "q " + this.rgb(segment.color ?? "111827") + " rg " + this.rgb(segment.color ?? "111827") + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
|
|
@@ -8395,7 +8743,7 @@ class PdfPages {
|
|
|
8395
8743
|
decoration(text, x, y, width) {
|
|
8396
8744
|
if (!text)
|
|
8397
8745
|
return;
|
|
8398
|
-
this.settings.budget.cell(text);
|
|
8746
|
+
this.settings.budget.cell(pdfBudgetText(text, this.settings.budget));
|
|
8399
8747
|
const font = this.fonts.select(), lines = wrapText(text, font, this.settings.fontSize, width, this.settings.limits.maxCellCharacters, 1, false);
|
|
8400
8748
|
this.text(lines[0].text, font, this.settings.fontSize, x, y);
|
|
8401
8749
|
}
|
|
@@ -8456,9 +8804,7 @@ class PdfPages {
|
|
|
8456
8804
|
}
|
|
8457
8805
|
const headers = preparedHeadings ?? (tableHeadings && this.layout ? this.activeHeadings ??= await this.layout.headers() : []), headerHeight = headers.reduce((n, h) => n + h.height, 0), continuation = tableHeadings && this.layout ? this.continuationCaption : undefined;
|
|
8458
8806
|
if (continuation?.lines.length) {
|
|
8459
|
-
if (this.continuationCaptionPaints++
|
|
8460
|
-
this.settings.budget.cell(continuation.text.text);
|
|
8461
|
-
else
|
|
8807
|
+
if (this.continuationCaptionPaints++ === 0)
|
|
8462
8808
|
this.tableCaptionOwner = this.captionAnnotations(continuation, this.tableCaptionOwner);
|
|
8463
8809
|
await this.paragraphs([continuation], headerHeight + lineHeight + this.settings.padding * 2, true, { artifact: true, ...(this.tableCaptionOwner === undefined ? {} : { annotationParent: this.tableCaptionOwner }) });
|
|
8464
8810
|
}
|
|
@@ -8479,7 +8825,7 @@ class PdfPages {
|
|
|
8479
8825
|
// Charge physical repeats without recapturing callbacks or making them semantic duplicates.
|
|
8480
8826
|
for (const cell of header.cells)
|
|
8481
8827
|
if (!this.bandCellBudget && this.paintedHeaderBudgetCells.has(cell.source ?? cell))
|
|
8482
|
-
this.settings.budget.cell(cell.lines.map(line => line.text).join(""));
|
|
8828
|
+
this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" : cell.lines.map(line => line.text).join(""));
|
|
8483
8829
|
const elements = this.tableStructure ? header.cells.map(cell => this.tableStructure.owner(cell.source ?? cell)) : undefined;
|
|
8484
8830
|
const repeated = header.cells.map(cell => this.paintedHeaderCells.has(cell.source ?? cell));
|
|
8485
8831
|
this.draw(header, 0, header.lines, elements, repeated);
|
|
@@ -8500,7 +8846,8 @@ class PdfPages {
|
|
|
8500
8846
|
const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
|
|
8501
8847
|
for (const [index, cell] of row.cells.entries()) {
|
|
8502
8848
|
if (this.bandCellBudget)
|
|
8503
|
-
this.settings.budget.cell(
|
|
8849
|
+
this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
|
|
8850
|
+
(cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
|
|
8504
8851
|
const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
|
|
8505
8852
|
if (cell.style.background)
|
|
8506
8853
|
this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + n(x) + " " + n(this.y - cellHeight) + " " + n(cell.width) + " " + n(cellHeight) + " re f Q\n"));
|
|
@@ -8576,7 +8923,7 @@ class PdfPages {
|
|
|
8576
8923
|
async paragraph(text, style = {}, size = this.settings.fontSize, paginate = true, headingLevel) {
|
|
8577
8924
|
await this.ensureStarted();
|
|
8578
8925
|
const { margins, page, limits } = this.settings, font = this.fonts.select(style.bold, style.italic), lineHeight = font.lineHeight(size);
|
|
8579
|
-
this.settings.budget.cell(text);
|
|
8926
|
+
this.settings.budget.cell(pdfBudgetText(text, this.settings.budget));
|
|
8580
8927
|
const lines = await wrapTextCooperatively(text, font, size, page.width - margins.left - margins.right, limits.maxCellCharacters, limits.maxRowLines, true, this.settings.options.signal);
|
|
8581
8928
|
if (lineHeight > page.height - margins.top - margins.bottom)
|
|
8582
8929
|
throw new RangeError("PDF page cannot fit a paragraph line at the selected font metrics.");
|
|
@@ -8619,6 +8966,8 @@ class PdfPages {
|
|
|
8619
8966
|
if (keepTogether && visible.length)
|
|
8620
8967
|
await this.reserveSpace(visible.reduce((height, paragraph) => height + paragraph.height, 0) + reservations.at(-1), "Kept PDF paragraph group");
|
|
8621
8968
|
for (const [index, paragraph] of visible.entries()) {
|
|
8969
|
+
if (paragraph.budgetOnPaint)
|
|
8970
|
+
this.settings.budget.cell(pdfBudgetText(paragraph.text.text, this.settings.budget));
|
|
8622
8971
|
if (paragraph.keepTogether || paragraph.keepWithNext)
|
|
8623
8972
|
await this.reserveSpace(paragraph.height + reservations[index], "Kept PDF paragraph chain");
|
|
8624
8973
|
const { margins, page } = this.settings;
|
|
@@ -8671,10 +9020,11 @@ class PdfPages {
|
|
|
8671
9020
|
/** The generated summary label is a row heading; no localized text/style inference is used. */
|
|
8672
9021
|
summary(row) { this.summaryRows.add(row); }
|
|
8673
9022
|
/** Begin an independent table on the current page, retaining its headings on continuation pages.
|
|
8674
|
-
* Group context uses captionArtifact: it stays visually complete without duplicating logical headings.
|
|
8675
|
-
|
|
9023
|
+
* Group context uses captionArtifact: it stays visually complete without duplicating logical headings.
|
|
9024
|
+
* An already-painted opening path only suppresses its artifact caption on that existing page. */
|
|
9025
|
+
async beginTable(layout, preparedHeadings, minimumDataHeight = layout.lineHeight + this.settings.padding * 2, caption, continuationCaption, headingsOnNewPageOnly = false, captionArtifact = false, openingContextAlreadyPainted = false) {
|
|
8676
9026
|
if (layout.bands)
|
|
8677
|
-
return this.beginBands(layout, preparedHeadings, minimumDataHeight, caption, continuationCaption, captionArtifact);
|
|
9027
|
+
return this.beginBands(layout, preparedHeadings, minimumDataHeight, caption, continuationCaption, captionArtifact, openingContextAlreadyPainted);
|
|
8678
9028
|
await this.ensureStarted();
|
|
8679
9029
|
this.layout = layout;
|
|
8680
9030
|
this.paintedHeaderCells = new WeakSet();
|
|
@@ -8688,7 +9038,7 @@ class PdfPages {
|
|
|
8688
9038
|
// Its own headings remain available when it moves or splits onto a fresh page.
|
|
8689
9039
|
const initialHeadings = headingsOnNewPageOnly && this.bodyAdded && !this.structure ? [] : headings;
|
|
8690
9040
|
const height = initialHeadings.reduce((n, row) => n + row.height, 0);
|
|
8691
|
-
if (caption) {
|
|
9041
|
+
if (caption && !(captionArtifact && openingContextAlreadyPainted)) {
|
|
8692
9042
|
await this.reserveSpace(caption.height + height + minimumDataHeight, "Kept PDF table caption and first data fragment");
|
|
8693
9043
|
this.tableCaptionOwner = captionArtifact ? this.captionAnnotations(caption)
|
|
8694
9044
|
: caption.lines.length ? this.structure?.element("Caption", this.tableElement) : undefined;
|
|
@@ -8710,7 +9060,7 @@ class PdfPages {
|
|
|
8710
9060
|
this.dataTop = this.y;
|
|
8711
9061
|
}
|
|
8712
9062
|
/** Bind the bounded logical-window owner to the existing physical page painter. */
|
|
8713
|
-
async beginBands(layout, preparedHeadings, minimumDataHeight, caption, continuation, captionArtifact) {
|
|
9063
|
+
async beginBands(layout, preparedHeadings, minimumDataHeight, caption, continuation, captionArtifact, openingContextAlreadyPainted) {
|
|
8714
9064
|
await this.ensureStarted();
|
|
8715
9065
|
const logicalHeadings = preparedHeadings ?? await layout.headers(), headings = await layout.bandRows(logicalHeadings, true);
|
|
8716
9066
|
const headerHeight = headings[0].reduce((sum, row) => sum + row.height, 0), { page, margins, padding } = this.settings;
|
|
@@ -8719,13 +9069,15 @@ class PdfPages {
|
|
|
8719
9069
|
const continuationCapacity = page.height - margins.top - margins.bottom - headerHeight - (continuation?.height ?? 0);
|
|
8720
9070
|
if (continuationCapacity + .001 < layout.lineHeight + padding * 2)
|
|
8721
9071
|
throw new RangeError("PDF band headings and continuation context leave no room for a data line.");
|
|
8722
|
-
|
|
9072
|
+
let openingContextPainted = captionArtifact && openingContextAlreadyPainted;
|
|
9073
|
+
if (this.y - margins.bottom - headerHeight - (openingContextPainted ? 0 : caption?.height ?? 0) + .001 < minimum) {
|
|
8723
9074
|
await this.pageBreak();
|
|
8724
|
-
|
|
8725
|
-
|
|
9075
|
+
openingContextPainted = false;
|
|
9076
|
+
}
|
|
9077
|
+
const firstCapacity = this.y - margins.bottom - headerHeight - (openingContextPainted ? 0 : caption?.height ?? 0);
|
|
8726
9078
|
if (firstCapacity + .001 < minimum)
|
|
8727
9079
|
throw new RangeError("PDF band caption and headings leave no room for a data line.");
|
|
8728
|
-
let
|
|
9080
|
+
let continuationPaints = 0;
|
|
8729
9081
|
this.tableElement = this.structure?.element("Table", this.groupParent);
|
|
8730
9082
|
this.paintedHeaderCells = new WeakSet();
|
|
8731
9083
|
let captionElement = this.structure && caption?.lines.length ? captionArtifact ? this.captionAnnotations(caption)
|
|
@@ -8739,21 +9091,16 @@ class PdfPages {
|
|
|
8739
9091
|
this.bandFlow = new PdfTableBandFlow(layout, headings, { firstCapacity, firstFullCapacity, continuationCapacity,
|
|
8740
9092
|
prepareRow: async (row) => { await this.tableStructure?.prepareHeaders(); await this.rowElements(row); },
|
|
8741
9093
|
completeRow: async (row) => { await this.tableStructure?.completeRow(row.source ?? row); },
|
|
8742
|
-
moveFirstToFreshPage: async () => { await this.pageBreak();
|
|
9094
|
+
moveFirstToFreshPage: async () => { await this.pageBreak(); openingContextPainted = false; },
|
|
8743
9095
|
paint: async (band, headers, rows, currentCaption, firstWindow, firstBand) => {
|
|
8744
9096
|
if (!(firstWindow && firstBand))
|
|
8745
9097
|
await this.pageBreak();
|
|
8746
|
-
if (firstWindow && !firstBand)
|
|
8747
|
-
this.y -= initialOffset;
|
|
8748
9098
|
const frame = layout.bands[band];
|
|
8749
9099
|
this.layout = { lefts: frame.lefts, lineHeight: layout.lineHeight, headers: async () => headers };
|
|
8750
9100
|
this.bandCellBudget = true;
|
|
8751
9101
|
try {
|
|
8752
|
-
if (currentCaption?.lines.length) {
|
|
8753
|
-
|
|
8754
|
-
if (paints > 0)
|
|
8755
|
-
this.settings.budget.cell(currentCaption.text.text);
|
|
8756
|
-
if (!firstWindow && paints === 0)
|
|
9102
|
+
if (currentCaption?.lines.length && !(firstWindow && firstBand && openingContextPainted)) {
|
|
9103
|
+
if (!firstWindow && continuationPaints++ === 0)
|
|
8757
9104
|
captionElement = this.captionAnnotations(currentCaption, captionElement);
|
|
8758
9105
|
const annotationParent = captionElement;
|
|
8759
9106
|
await this.paragraphs([currentCaption], headerHeight + minimum, true, firstWindow && firstBand && !captionArtifact ? { role: "Caption", keepOpen: true, ...(captionElement === undefined ? {} : { owner: captionElement }) }
|
|
@@ -8857,7 +9204,7 @@ class PdfPages {
|
|
|
8857
9204
|
this.annotations = [];
|
|
8858
9205
|
this.commandBytes = 0;
|
|
8859
9206
|
this.current = 0;
|
|
8860
|
-
await this.objects.
|
|
9207
|
+
await this.objects.flushBytes();
|
|
8861
9208
|
}
|
|
8862
9209
|
async finish() {
|
|
8863
9210
|
if (this.bandFlow) {
|
|
@@ -8888,7 +9235,7 @@ const _exports = Object.freeze({ PdfPages: PdfPages });
|
|
|
8888
9235
|
return _exports;
|
|
8889
9236
|
})();
|
|
8890
9237
|
|
|
8891
|
-
const
|
|
9238
|
+
const _m80 = (() => {
|
|
8892
9239
|
/** @internal Incremental PDF number tree: at most 64 entries/children per retained level. */
|
|
8893
9240
|
class PdfParentTree {
|
|
8894
9241
|
objects;
|
|
@@ -8950,15 +9297,38 @@ const _exports = Object.freeze({ PdfParentTree: PdfParentTree });
|
|
|
8950
9297
|
return _exports;
|
|
8951
9298
|
})();
|
|
8952
9299
|
|
|
8953
|
-
const
|
|
9300
|
+
const _m79 = (() => {
|
|
8954
9301
|
const { OfficeIMOError } = _m2;
|
|
8955
9302
|
|
|
8956
9303
|
const { checkAbort } = _m4;
|
|
8957
9304
|
|
|
8958
9305
|
const { unicodeHex } = _m59;
|
|
8959
9306
|
|
|
8960
|
-
const { PdfParentTree } =
|
|
9307
|
+
const { PdfParentTree } = _m80;
|
|
8961
9308
|
|
|
9309
|
+
/** Same-page marked content uses integer K; cross-page MCR and annotation OBJR stay explicit. */
|
|
9310
|
+
function structureChild(child) {
|
|
9311
|
+
return typeof child === "number" ? (child < 0 ? -child - 1 + " " : child + " 0 R ") : child + " ";
|
|
9312
|
+
}
|
|
9313
|
+
function structurePrefix(element) {
|
|
9314
|
+
return "<< /Type /StructElem /S /" + element.role + " /P " + element.parent + " 0 R" +
|
|
9315
|
+
(element.markedPage === undefined ? "" : " /Pg " + element.markedPage + " 0 R") +
|
|
9316
|
+
(element.identifier === undefined ? "" : " /ID (" + element.identifier + ")") + " /K [";
|
|
9317
|
+
}
|
|
9318
|
+
/** Keep the same bounded small-object representation for both completion paths. */
|
|
9319
|
+
function compactStructureBody(element, prefix) {
|
|
9320
|
+
const remaining = 32768 - prefix.length - element.attributes.length - 4;
|
|
9321
|
+
if (remaining < 0)
|
|
9322
|
+
return undefined;
|
|
9323
|
+
let children = "";
|
|
9324
|
+
for (const child of element.children) {
|
|
9325
|
+
const token = structureChild(child);
|
|
9326
|
+
if (children.length + token.length > remaining)
|
|
9327
|
+
return undefined;
|
|
9328
|
+
children += token;
|
|
9329
|
+
}
|
|
9330
|
+
return prefix + children + "]" + element.attributes + " >>";
|
|
9331
|
+
}
|
|
8962
9332
|
/** A sorted name tree retains only a small open leaf and branch at each level. */
|
|
8963
9333
|
class PdfStructureIds {
|
|
8964
9334
|
objects;
|
|
@@ -9048,7 +9418,7 @@ class PdfStructure {
|
|
|
9048
9418
|
checkAbort(this.settings.options.signal);
|
|
9049
9419
|
if (++this.allocated > this.settings.limits.maxStructureElements)
|
|
9050
9420
|
throw new OfficeIMOError("RESOURCE_LIMIT", "maxStructureElements exceeded.");
|
|
9051
|
-
const id = this.objects.reserve(), element = { id, parent, role, children: [], attributes
|
|
9421
|
+
const id = this.objects.reserve(), element = { id, parent, role, children: [], attributes };
|
|
9052
9422
|
this.elements.set(id, element);
|
|
9053
9423
|
const owner = this.elements.get(parent);
|
|
9054
9424
|
// A continuation-only linked caption is discovered during painting, after rows may exist.
|
|
@@ -9059,6 +9429,20 @@ class PdfStructure {
|
|
|
9059
9429
|
owner?.children.push(id);
|
|
9060
9430
|
return id;
|
|
9061
9431
|
}
|
|
9432
|
+
/** Attach resolved table associations while a source-ordered logical element is still open. */
|
|
9433
|
+
setAttributes(elementId, attributes) {
|
|
9434
|
+
const element = this.elements.get(elementId);
|
|
9435
|
+
if (!element)
|
|
9436
|
+
throw new Error("PDF structure attributes require an open logical owner.");
|
|
9437
|
+
element.attributes = attributes;
|
|
9438
|
+
}
|
|
9439
|
+
/** Write one immutable attribute dictionary. Its caller owns the bounded scope of reference reuse. */
|
|
9440
|
+
async attributeReference(dictionary) {
|
|
9441
|
+
checkAbort(this.settings.options.signal);
|
|
9442
|
+
const id = this.objects.reserve();
|
|
9443
|
+
await this.objects.object(id, dictionary);
|
|
9444
|
+
return " /A " + id + " 0 R";
|
|
9445
|
+
}
|
|
9062
9446
|
/** Flat visual sections share the same logical Document and cumulative resource policy. */
|
|
9063
9447
|
async beginSection() {
|
|
9064
9448
|
await this.complete(this.section);
|
|
@@ -9092,7 +9476,8 @@ class PdfStructure {
|
|
|
9092
9476
|
return existing;
|
|
9093
9477
|
const id = this.element("Link", parent, alternativeText === undefined ? "" : " /Alt <feff" + unicodeHex(alternativeText) + ">");
|
|
9094
9478
|
parents.set(parent, id);
|
|
9095
|
-
this.elements.get(parent)
|
|
9479
|
+
const owner = this.elements.get(parent);
|
|
9480
|
+
(owner.linkIdentities ??= []).push(identity);
|
|
9096
9481
|
return id;
|
|
9097
9482
|
}
|
|
9098
9483
|
/** Associate a native annotation in both directions: OBJR child and annotation ParentTree entry. */
|
|
@@ -9115,7 +9500,9 @@ class PdfStructure {
|
|
|
9115
9500
|
throw new Error("Marked content requires an open logical owner.");
|
|
9116
9501
|
const mcid = this.pageParents.length;
|
|
9117
9502
|
this.pageParents.push(elementId);
|
|
9118
|
-
element.
|
|
9503
|
+
element.markedPage ??= this.pageId;
|
|
9504
|
+
element.children.push(element.markedPage === this.pageId ? -(mcid + 1) :
|
|
9505
|
+
"<< /Type /MCR /Pg " + this.pageId + " 0 R /MCID " + mcid + " >>");
|
|
9119
9506
|
return "/" + element.role + " << /MCID " + mcid + (actualText === undefined ? "" : " /ActualText <FEFF" + unicodeHex(actualText) + ">") + " >> BDC\n";
|
|
9120
9507
|
}
|
|
9121
9508
|
get pageDictionary() { return " /StructParents " + this.pageKey + " /Tabs /S"; }
|
|
@@ -9139,37 +9526,49 @@ class PdfStructure {
|
|
|
9139
9526
|
if (!element)
|
|
9140
9527
|
return;
|
|
9141
9528
|
for (const child of element.children)
|
|
9142
|
-
if (typeof child === "number" && this.
|
|
9529
|
+
if (typeof child === "number" && child > 0 && !this.completeBuffered(child))
|
|
9143
9530
|
await this.complete(child);
|
|
9144
9531
|
checkAbort(this.settings.options.signal);
|
|
9145
|
-
const prefix =
|
|
9146
|
-
(element.identifier === undefined ? "" : " /ID (" + element.identifier + ")") + " /K [";
|
|
9147
|
-
const remaining = 32768 - prefix.length - element.attributes.length - 4;
|
|
9148
|
-
let children = "", small = remaining >= 0;
|
|
9149
|
-
if (small)
|
|
9150
|
-
for (const child of element.children) {
|
|
9151
|
-
const token = typeof child === "number" ? child + " 0 R " : child + " ";
|
|
9152
|
-
if (children.length + token.length > remaining) {
|
|
9153
|
-
small = false;
|
|
9154
|
-
break;
|
|
9155
|
-
}
|
|
9156
|
-
children += token;
|
|
9157
|
-
}
|
|
9532
|
+
const prefix = structurePrefix(element), body = compactStructureBody(element, prefix);
|
|
9158
9533
|
// Most table cells/rows fit in one encoding. Large parents and alternatives remain streamed.
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9534
|
+
if (body !== undefined) {
|
|
9535
|
+
if (!this.objects.tryCompactObject(id, body))
|
|
9536
|
+
await this.objects.compactObject(id, body);
|
|
9537
|
+
}
|
|
9538
|
+
else
|
|
9539
|
+
await this.objects.object(id, this.body(element, prefix));
|
|
9540
|
+
this.releaseElement(element);
|
|
9541
|
+
}
|
|
9542
|
+
/** Close already-bufferable children without creating an async chain per leaf. A false result
|
|
9543
|
+
* leaves the current owner open for the existing awaited flush or ordinary-object path. */
|
|
9544
|
+
completeBuffered(id) {
|
|
9545
|
+
const element = this.elements.get(id);
|
|
9546
|
+
if (!element)
|
|
9547
|
+
return true;
|
|
9171
9548
|
for (const child of element.children)
|
|
9172
|
-
|
|
9549
|
+
if (typeof child === "number" && child > 0 && !this.completeBuffered(child))
|
|
9550
|
+
return false;
|
|
9551
|
+
checkAbort(this.settings.options.signal);
|
|
9552
|
+
const body = compactStructureBody(element, structurePrefix(element));
|
|
9553
|
+
if (body === undefined || !this.objects.tryCompactObject(id, body))
|
|
9554
|
+
return false;
|
|
9555
|
+
this.releaseElement(element);
|
|
9556
|
+
return true;
|
|
9557
|
+
}
|
|
9558
|
+
releaseElement(element) {
|
|
9559
|
+
if (element.linkIdentities)
|
|
9560
|
+
for (const identity of element.linkIdentities) {
|
|
9561
|
+
const parents = this.links.get(identity);
|
|
9562
|
+
parents?.delete(element.id);
|
|
9563
|
+
if (!parents?.size)
|
|
9564
|
+
this.links.delete(identity);
|
|
9565
|
+
}
|
|
9566
|
+
this.elements.delete(element.id);
|
|
9567
|
+
}
|
|
9568
|
+
*body(element, prefix) {
|
|
9569
|
+
yield prefix;
|
|
9570
|
+
for (const child of element.children)
|
|
9571
|
+
yield structureChild(child);
|
|
9173
9572
|
yield "]" + element.attributes + " >>";
|
|
9174
9573
|
}
|
|
9175
9574
|
async completeRow(cells) {
|
|
@@ -9209,7 +9608,7 @@ const _exports = Object.freeze({ PdfStructure: PdfStructure, graphicAlternative:
|
|
|
9209
9608
|
return _exports;
|
|
9210
9609
|
})();
|
|
9211
9610
|
|
|
9212
|
-
const
|
|
9611
|
+
const _m81 = (() => {
|
|
9213
9612
|
const { OfficeIMOError } = _m2;
|
|
9214
9613
|
|
|
9215
9614
|
const { checkAbort } = _m4;
|
|
@@ -9275,15 +9674,15 @@ return _exports;
|
|
|
9275
9674
|
const _m58 = (() => {
|
|
9276
9675
|
const { PdfObjects, unicodeHex } = _m59;
|
|
9277
9676
|
|
|
9278
|
-
const { PdfFontResources } =
|
|
9677
|
+
const { PdfFontResources } = _m61;
|
|
9279
9678
|
|
|
9280
|
-
const { PdfTableLayout } =
|
|
9679
|
+
const { PdfTableLayout } = _m68;
|
|
9281
9680
|
|
|
9282
|
-
const { PdfPages } =
|
|
9681
|
+
const { PdfPages } = _m73;
|
|
9283
9682
|
|
|
9284
|
-
const { PdfStructure } =
|
|
9683
|
+
const { PdfStructure } = _m79;
|
|
9285
9684
|
|
|
9286
|
-
const { PdfOutlines } =
|
|
9685
|
+
const { PdfOutlines } = _m81;
|
|
9287
9686
|
|
|
9288
9687
|
/** One resource/catalog owner shared by table convenience exports and composed documents. */
|
|
9289
9688
|
class PdfWriteSession {
|
|
@@ -9300,7 +9699,7 @@ class PdfWriteSession {
|
|
|
9300
9699
|
info;
|
|
9301
9700
|
constructor(sink, settings, table = false) {
|
|
9302
9701
|
this.settings = settings;
|
|
9303
|
-
this.objects = new PdfObjects(sink, settings.options.signal, settings.budget.limits.maxOutputBytes);
|
|
9702
|
+
this.objects = new PdfObjects(sink, settings.options.signal, settings.budget.limits.maxOutputBytes, settings.options.compression !== false);
|
|
9304
9703
|
this.root = this.objects.reserve();
|
|
9305
9704
|
this.parent = this.objects.reserve();
|
|
9306
9705
|
this.resources = this.objects.reserve();
|
|
@@ -9406,7 +9805,7 @@ const _exports = Object.freeze({ writePdf: writePdf, writePdfTo: writePdfTo });
|
|
|
9406
9805
|
return _exports;
|
|
9407
9806
|
})();
|
|
9408
9807
|
|
|
9409
|
-
const
|
|
9808
|
+
const _m85 = (() => {
|
|
9410
9809
|
const { NotSupportedError, OfficeIMOError } = _m2;
|
|
9411
9810
|
|
|
9412
9811
|
const { checkAbort, pause, taskYieldDue, withAbort } = _m4;
|
|
@@ -9673,12 +10072,12 @@ const _exports = Object.freeze({ pngPixels: pngPixels });
|
|
|
9673
10072
|
return _exports;
|
|
9674
10073
|
})();
|
|
9675
10074
|
|
|
9676
|
-
const
|
|
10075
|
+
const _m84 = (() => {
|
|
9677
10076
|
const { NotSupportedError, OfficeIMOError } = _m2;
|
|
9678
10077
|
|
|
9679
10078
|
const { checkAbort, pause, taskYieldDue } = _m4;
|
|
9680
10079
|
|
|
9681
|
-
const { pngPixels } =
|
|
10080
|
+
const { pngPixels } = _m85;
|
|
9682
10081
|
|
|
9683
10082
|
/** Shared document image resources; source objects are captured on first consumption. */
|
|
9684
10083
|
class PdfDocumentImages {
|
|
@@ -9806,7 +10205,7 @@ const _exports = Object.freeze({ PdfDocumentImages: PdfDocumentImages });
|
|
|
9806
10205
|
return _exports;
|
|
9807
10206
|
})();
|
|
9808
10207
|
|
|
9809
|
-
const
|
|
10208
|
+
const _m86 = (() => {
|
|
9810
10209
|
const { OfficeIMOError } = _m2;
|
|
9811
10210
|
|
|
9812
10211
|
const { checkAbort, pause, taskYieldDue } = _m4;
|
|
@@ -9892,7 +10291,7 @@ const _exports = Object.freeze({ vectorCommands: vectorCommands });
|
|
|
9892
10291
|
return _exports;
|
|
9893
10292
|
})();
|
|
9894
10293
|
|
|
9895
|
-
const
|
|
10294
|
+
const _m87 = (() => {
|
|
9896
10295
|
const { NotSupportedError, OfficeIMOError } = _m2;
|
|
9897
10296
|
|
|
9898
10297
|
const { checkAbort, pause, taskYieldDue } = _m4;
|
|
@@ -10138,21 +10537,23 @@ const _exports = Object.freeze({ checkDrawingBlock: checkDrawingBlock, prepareDr
|
|
|
10138
10537
|
return _exports;
|
|
10139
10538
|
})();
|
|
10140
10539
|
|
|
10141
|
-
const
|
|
10540
|
+
const _m88 = (() => {
|
|
10142
10541
|
const { OfficeIMOError } = _m2;
|
|
10143
10542
|
|
|
10144
|
-
const { capturePdfText, wrapPdfText } =
|
|
10543
|
+
const { capturePdfText, wrapPdfText } = _m70;
|
|
10145
10544
|
|
|
10146
10545
|
const { positive } = _m55;
|
|
10147
10546
|
|
|
10148
10547
|
const { resolveParagraphStyle } = _m56;
|
|
10149
10548
|
|
|
10150
|
-
const { captureBookmark } =
|
|
10549
|
+
const { captureBookmark } = _m77;
|
|
10151
10550
|
|
|
10152
10551
|
const { captureFields } = _m10;
|
|
10153
10552
|
|
|
10553
|
+
const { pdfBudgetText } = _m69;
|
|
10554
|
+
|
|
10154
10555
|
/** @internal Copy public paragraph input before any cooperative layout or source enumeration. */
|
|
10155
|
-
function captureParagraph(block, settings, fonts) {
|
|
10556
|
+
function captureParagraph(block, settings, fonts, budgetOnPaint = false) {
|
|
10156
10557
|
if (!block || block.kind !== "paragraph")
|
|
10157
10558
|
throw new TypeError("PDF paragraph groups accept paragraph blocks only.");
|
|
10158
10559
|
const { text, headingLevel, presentation: inputStyle, fontSize, keepTogether, keepWithNext, spaceBefore, spaceAfter, style: styleName, bookmark: inputBookmark } = block;
|
|
@@ -10165,7 +10566,8 @@ function captureParagraph(block, settings, fonts) {
|
|
|
10165
10566
|
}, settings.paragraphStyles);
|
|
10166
10567
|
const style = resolved.presentation ?? Object.freeze({}), size = positive(resolved.fontSize ?? settings.fontSize, "Paragraph font size", 144);
|
|
10167
10568
|
const bookmark = captureBookmark(inputBookmark, settings);
|
|
10168
|
-
return Object.freeze({ text: capturePdfText(text, style, settings, fonts, false), style, size,
|
|
10569
|
+
return Object.freeze({ text: capturePdfText(text, style, settings, fonts, false, !budgetOnPaint), style, size,
|
|
10570
|
+
...(budgetOnPaint ? { budgetOnPaint: true } : {}),
|
|
10169
10571
|
...(headingLevel === undefined ? {} : { headingLevel }), ...(bookmark === undefined ? {} : { bookmark }),
|
|
10170
10572
|
keepTogether: resolved.keepTogether ?? false, keepWithNext: resolved.keepWithNext ?? false,
|
|
10171
10573
|
spaceBefore: resolved.spaceBefore ?? 0, spaceAfter: resolved.spaceAfter ?? 8 });
|
|
@@ -10176,13 +10578,16 @@ function captureCaption(caption, settings, fonts) {
|
|
|
10176
10578
|
Object.keys(caption).some(key => !["text", "style", "fontSize", "presentation", "spaceBefore", "spaceAfter"].includes(key)))
|
|
10177
10579
|
throw new TypeError("PDF captions support text, style, fontSize, presentation, spaceBefore and spaceAfter.");
|
|
10178
10580
|
return captureParagraph({ ...captureFields(caption, ["text", "style", "fontSize", "presentation", "spaceBefore", "spaceAfter"]),
|
|
10179
|
-
kind: "paragraph", keepTogether: true, keepWithNext: true }, settings, fonts);
|
|
10581
|
+
kind: "paragraph", keepTogether: true, keepWithNext: true }, settings, fonts, true);
|
|
10180
10582
|
}
|
|
10181
10583
|
/** @internal Layout is bounded by the same per-cell text and wrapped-line limits as table cells. */
|
|
10182
10584
|
async function prepareParagraph(captured, settings, fonts, width = settings.page.width - settings.margins.left - settings.margins.right) {
|
|
10183
10585
|
if (!captured.text.text)
|
|
10184
10586
|
return { ...captured, lines: [], height: 0, firstHeight: 0 };
|
|
10185
|
-
|
|
10587
|
+
if (!captured.budgetOnPaint) {
|
|
10588
|
+
const budgetText = pdfBudgetText(captured.text.text, settings.budget);
|
|
10589
|
+
settings.budget.cell(budgetText, budgetText.length);
|
|
10590
|
+
}
|
|
10186
10591
|
const lines = await wrapPdfText(captured.text, fonts, captured.size, positive(width, "Paragraph width"), settings);
|
|
10187
10592
|
return { ...captured, lines, height: captured.spaceBefore + lines.reduce((height, line) => height + line.lineHeight, 0) + captured.spaceAfter,
|
|
10188
10593
|
firstHeight: captured.spaceBefore + lines[0].lineHeight };
|
|
@@ -10215,10 +10620,10 @@ const _exports = Object.freeze({ captureParagraph: captureParagraph, captureCapt
|
|
|
10215
10620
|
return _exports;
|
|
10216
10621
|
})();
|
|
10217
10622
|
|
|
10218
|
-
const
|
|
10219
|
-
const { capturePdfText, wrapPdfText } =
|
|
10623
|
+
const _m89 = (() => {
|
|
10624
|
+
const { capturePdfText, wrapPdfText } = _m70;
|
|
10220
10625
|
|
|
10221
|
-
const { captureParagraph, prepareParagraph } =
|
|
10626
|
+
const { captureParagraph, prepareParagraph } = _m88;
|
|
10222
10627
|
|
|
10223
10628
|
const { resolveParagraphStyle } = _m56;
|
|
10224
10629
|
|
|
@@ -10272,7 +10677,7 @@ const _exports = Object.freeze({ captureListOptions: captureListOptions, prepare
|
|
|
10272
10677
|
return _exports;
|
|
10273
10678
|
})();
|
|
10274
10679
|
|
|
10275
|
-
const
|
|
10680
|
+
const _m91 = (() => {
|
|
10276
10681
|
const { assertGroupedReportSource } = _m8;
|
|
10277
10682
|
|
|
10278
10683
|
const { captureFields } = _m10;
|
|
@@ -10321,22 +10726,22 @@ const _exports = Object.freeze({ groupedPdfLabelFields: groupedPdfLabelFields, g
|
|
|
10321
10726
|
return _exports;
|
|
10322
10727
|
})();
|
|
10323
10728
|
|
|
10324
|
-
const
|
|
10729
|
+
const _m90 = (() => {
|
|
10325
10730
|
const { assertGroupedReportSource, groupedReportOperation } = _m8;
|
|
10326
10731
|
|
|
10327
10732
|
const { consumeRows } = _m4;
|
|
10328
10733
|
|
|
10329
10734
|
const { ExportCell } = _m5;
|
|
10330
10735
|
|
|
10331
|
-
const { captureGroupedPdfTableOptions } =
|
|
10736
|
+
const { captureGroupedPdfTableOptions } = _m91;
|
|
10332
10737
|
|
|
10333
10738
|
const { settings } = _m55;
|
|
10334
10739
|
|
|
10335
|
-
const { PdfTableLayout } =
|
|
10740
|
+
const { PdfTableLayout } = _m68;
|
|
10336
10741
|
|
|
10337
|
-
const { captureCaption, captureParagraph, prepareParagraph } =
|
|
10742
|
+
const { captureCaption, captureParagraph, prepareParagraph } = _m88;
|
|
10338
10743
|
|
|
10339
|
-
const { synchronousText } =
|
|
10744
|
+
const { synchronousText } = _m69;
|
|
10340
10745
|
|
|
10341
10746
|
/** @internal Render one analytical source in the existing document session. Retain one detail row and
|
|
10342
10747
|
* at most four closing subtotals. All captions, rows, pages, bytes and fonts use the document owners. */
|
|
@@ -10365,10 +10770,44 @@ async function renderGroupedPdfTable(block, context) {
|
|
|
10365
10770
|
const continuationLabels = new WeakMap();
|
|
10366
10771
|
let pending;
|
|
10367
10772
|
const closing = [];
|
|
10368
|
-
const
|
|
10773
|
+
const aggregatePositions = report.columns.flatMap((column, index) => Object.hasOwn(report.totals, column.key) ? [index] : []);
|
|
10774
|
+
const summaryValues = (label, values, positions) => Object.freeze([
|
|
10369
10775
|
new ExportCell(label, { text: label, presentation: table.options.footerPresentation }),
|
|
10370
|
-
...values.map(value => new ExportCell(value, { presentation: table.options.footerPresentation }))
|
|
10776
|
+
...(positions ? positions.map(index => values[index]) : values).map(value => new ExportCell(value, { presentation: table.options.footerPresentation }))
|
|
10371
10777
|
]);
|
|
10778
|
+
// Independent summaries have no detail values in non-aggregate columns. Project their
|
|
10779
|
+
// declared operations, including zero/null results, rather than emitting label-only bands.
|
|
10780
|
+
// Keep callback positions in the original source model after this physical projection.
|
|
10781
|
+
const summaryLayouts = new Map();
|
|
10782
|
+
const summaryLayout = (grand) => {
|
|
10783
|
+
const existing = summaryLayouts.get(grand);
|
|
10784
|
+
if (existing)
|
|
10785
|
+
return existing;
|
|
10786
|
+
const positions = [0, ...aggregatePositions.map(index => index + 1)];
|
|
10787
|
+
const projected = positions.map(position => {
|
|
10788
|
+
const column = columns[position];
|
|
10789
|
+
if (!grand)
|
|
10790
|
+
return column;
|
|
10791
|
+
const { groups: _groups, ...leaf } = column;
|
|
10792
|
+
return leaf;
|
|
10793
|
+
});
|
|
10794
|
+
const originalPosition = (position) => {
|
|
10795
|
+
const columnIndex = positions[position.columnIndex];
|
|
10796
|
+
return { ...position, columnIndex, column: columns[columnIndex] };
|
|
10797
|
+
};
|
|
10798
|
+
const repeatColumns = positions.flatMap((position, index) => position === 0 || table.repeatedColumns.includes(position) ? [index] : []);
|
|
10799
|
+
const wideTable = table.options.wideTable;
|
|
10800
|
+
const projectedSettings = { ...sharedTable,
|
|
10801
|
+
repeatedColumns: Object.freeze(repeatColumns), options: { ...table.options, columns: projected,
|
|
10802
|
+
...(table.options.columnWidths === undefined ? {} : { columnWidths: positions.map(position => table.options.columnWidths[position]) }),
|
|
10803
|
+
...(typeof wideTable !== "object" ? {} : { wideTable: { ...wideTable, repeatColumns } }),
|
|
10804
|
+
...(table.options.formatValue === undefined ? {} : { formatValue: (value, position) => table.options.formatValue(value, originalPosition(position)) }),
|
|
10805
|
+
...(table.options.formatRuns === undefined ? {} : { formatRuns: (value, position) => table.options.formatRuns(value, originalPosition(position)) })
|
|
10806
|
+
} };
|
|
10807
|
+
const projectedLayout = new PdfTableLayout(projectedSettings, fonts);
|
|
10808
|
+
summaryLayouts.set(grand, projectedLayout);
|
|
10809
|
+
return projectedLayout;
|
|
10810
|
+
};
|
|
10372
10811
|
const prepareGroupContext = async () => {
|
|
10373
10812
|
const caption = await prepareParagraph(captureCaption({ text: path.map(group => group.label).join("\n"),
|
|
10374
10813
|
presentation: { bold: true }, spaceAfter: 4 }, pages.settings, fonts), pages.settings, fonts);
|
|
@@ -10431,26 +10870,46 @@ async function renderGroupedPdfTable(block, context) {
|
|
|
10431
10870
|
...(group.label.trim() ? { bookmark: { title: group.label, level: (groupHeadingLevel + group.level) } } : {})
|
|
10432
10871
|
}, pages.settings, fonts), pages.settings, fonts));
|
|
10433
10872
|
const groupHeight = groupHeadings.reduce((height, heading) => height + heading.height, 0);
|
|
10434
|
-
|
|
10435
|
-
|
|
10873
|
+
// Newly opened semantic headings already paint the end of this path. Only the open
|
|
10874
|
+
// ancestor prefix needs an artifact here; later physical bands still paint the full path.
|
|
10875
|
+
const ancestorCaption = semantic && semanticDepth > 0 ? await prepareParagraph(captureCaption({
|
|
10876
|
+
text: path.slice(0, semanticDepth).map(group => group.label).join("\n"), presentation: { bold: true }, spaceAfter: 4
|
|
10877
|
+
}, pages.settings, fonts), pages.settings, fonts) : undefined;
|
|
10878
|
+
const openingHeight = semantic ? (ancestorCaption?.height ?? 0) + groupHeight : caption.height;
|
|
10879
|
+
await context.flushParagraphs(openingHeight + headingHeight + minimum);
|
|
10880
|
+
if (ancestorCaption)
|
|
10881
|
+
await pages.paragraphs([ancestorCaption], groupHeight + headingHeight + minimum, true, { artifact: true });
|
|
10882
|
+
let followingHeight = groupHeight + (semantic ? 0 : caption.height) + headingHeight + minimum;
|
|
10436
10883
|
for (const heading of groupHeadings) {
|
|
10437
10884
|
followingHeight -= heading.height;
|
|
10438
10885
|
await pages.beginGroup(semanticDepth++, heading, followingHeight);
|
|
10439
10886
|
}
|
|
10440
|
-
await pages.beginTable(layout, headings, minimum, caption, continuation, false, semantic);
|
|
10887
|
+
await pages.beginTable(layout, headings, minimum, caption, continuation, false, semantic, semantic);
|
|
10441
10888
|
started = true;
|
|
10442
10889
|
firstFragment = (caption?.lines.length ?? 0) > 0 || groupHeadings.some(heading => heading.lines.length > 0);
|
|
10443
10890
|
};
|
|
10444
|
-
const semanticSubtotal = async (row, level) => {
|
|
10891
|
+
const semanticSubtotal = async (row, level, values) => {
|
|
10892
|
+
if (level === report.groupBy.length - 1) {
|
|
10893
|
+
// A leaf's own subtotal shares its detail table and header identities. Keep the last
|
|
10894
|
+
// detail/summary bundle when it fits; the existing flow owns continuation and limits.
|
|
10895
|
+
pages.summary(row);
|
|
10896
|
+
closing.push(row);
|
|
10897
|
+
await finishLeaf();
|
|
10898
|
+
await pages.endGroup(level);
|
|
10899
|
+
semanticDepth = level;
|
|
10900
|
+
path = path.slice(0, level);
|
|
10901
|
+
return;
|
|
10902
|
+
}
|
|
10445
10903
|
await finishLeaf();
|
|
10446
10904
|
const { caption, continuation } = await prepareGroupContext();
|
|
10447
|
-
const
|
|
10448
|
-
await
|
|
10905
|
+
const projected = summaryLayout(false), summaryHeadings = await projected.headers();
|
|
10906
|
+
const summaryRow = await projected.data(values, 0, true), minimum = projected.minimumRowHeight(summaryRow);
|
|
10907
|
+
await context.flushParagraphs(caption.height + await projected.blockHeight(summaryHeadings) + minimum);
|
|
10449
10908
|
// An ancestor subtotal belongs to that ancestor's section, never the final child's table.
|
|
10450
10909
|
// Its own visible column headings keep the separate logical summary table truthful.
|
|
10451
|
-
await pages.beginTable(
|
|
10452
|
-
pages.summary(
|
|
10453
|
-
await pages.row(
|
|
10910
|
+
await pages.beginTable(projected, summaryHeadings, minimum, caption, continuation, false, true);
|
|
10911
|
+
pages.summary(summaryRow);
|
|
10912
|
+
await pages.row(summaryRow, caption.lines.length > 0 || summaryHeadings.length > 0);
|
|
10454
10913
|
await pages.endTable();
|
|
10455
10914
|
await pages.endGroup(level);
|
|
10456
10915
|
semanticDepth = level;
|
|
@@ -10460,25 +10919,19 @@ async function renderGroupedPdfTable(block, context) {
|
|
|
10460
10919
|
await finishLeaf();
|
|
10461
10920
|
if (!includeGrandTotal && summary.rows !== 0)
|
|
10462
10921
|
return;
|
|
10463
|
-
const
|
|
10464
|
-
const { groups: _groups, ...leaf } = column;
|
|
10465
|
-
return leaf;
|
|
10466
|
-
});
|
|
10467
|
-
const completeTable = settings({ ...table.options, columns: completeColumns,
|
|
10468
|
-
includeHeader: input.includeHeader ?? true });
|
|
10469
|
-
const completeLayout = summary.rows === 0 ? layout : new PdfTableLayout({ ...completeTable, budget: prepared.budget }, fonts);
|
|
10922
|
+
const completeLayout = summary.rows === 0 ? layout : summaryLayout(true);
|
|
10470
10923
|
const completeHeadings = summary.rows === 0 ? headings : await completeLayout.headers();
|
|
10471
10924
|
rowIndex = -1;
|
|
10472
10925
|
let total;
|
|
10473
10926
|
if (includeGrandTotal) {
|
|
10474
10927
|
context.acceptRow(false);
|
|
10475
|
-
total = await completeLayout.data(summaryValues(synchronousText(grandTotalLabel(summary), "grandTotalLabel"), summary.totals), 0, true);
|
|
10928
|
+
total = await completeLayout.data(summaryValues(synchronousText(grandTotalLabel(summary), "grandTotalLabel"), summary.totals, summary.rows === 0 ? undefined : aggregatePositions), 0, true);
|
|
10476
10929
|
}
|
|
10477
10930
|
if (!completeHeadings.length && !total)
|
|
10478
10931
|
return;
|
|
10479
10932
|
const minimum = total ? completeLayout.minimumRowHeight(total) : 0;
|
|
10480
10933
|
await context.flushParagraphs(await completeLayout.blockHeight(completeHeadings) + minimum);
|
|
10481
|
-
await pages.beginTable(completeLayout, completeHeadings, minimum
|
|
10934
|
+
await pages.beginTable(completeLayout, completeHeadings, minimum);
|
|
10482
10935
|
if (total) {
|
|
10483
10936
|
if (semantic)
|
|
10484
10937
|
pages.summary(total);
|
|
@@ -10506,9 +10959,11 @@ async function renderGroupedPdfTable(block, context) {
|
|
|
10506
10959
|
case "groupEnd": {
|
|
10507
10960
|
rowIndex = -1;
|
|
10508
10961
|
context.acceptRow(false);
|
|
10509
|
-
const
|
|
10962
|
+
const separate = semantic && event.level !== report.groupBy.length - 1;
|
|
10963
|
+
const values = summaryValues(synchronousText(subtotalLabel(event), "subtotalLabel"), event.totals, separate ? aggregatePositions : undefined);
|
|
10964
|
+
const row = separate ? undefined : await layout.data(values, 0, true);
|
|
10510
10965
|
if (semantic)
|
|
10511
|
-
await semanticSubtotal(row, event.level);
|
|
10966
|
+
await semanticSubtotal(row, event.level, values);
|
|
10512
10967
|
else
|
|
10513
10968
|
closing.push(row);
|
|
10514
10969
|
break;
|
|
@@ -10528,7 +10983,7 @@ const _exports = Object.freeze({ renderGroupedPdfTable: renderGroupedPdfTable })
|
|
|
10528
10983
|
return _exports;
|
|
10529
10984
|
})();
|
|
10530
10985
|
|
|
10531
|
-
const
|
|
10986
|
+
const _m83 = (() => {
|
|
10532
10987
|
const { BlobByteSink, withDestination } = _m3;
|
|
10533
10988
|
|
|
10534
10989
|
const { OfficeIMOError } = _m2;
|
|
@@ -10545,25 +11000,25 @@ const { settings, captureWideTable } = _m55;
|
|
|
10545
11000
|
|
|
10546
11001
|
const { pdfNumber: n } = _m59;
|
|
10547
11002
|
|
|
10548
|
-
const { PdfTableLayout } =
|
|
11003
|
+
const { PdfTableLayout } = _m68;
|
|
10549
11004
|
|
|
10550
11005
|
const { PdfWriteSession } = _m58;
|
|
10551
11006
|
|
|
10552
|
-
const { PdfDocumentImages } =
|
|
11007
|
+
const { PdfDocumentImages } = _m84;
|
|
10553
11008
|
|
|
10554
|
-
const { vectorCommands } =
|
|
11009
|
+
const { vectorCommands } = _m86;
|
|
10555
11010
|
|
|
10556
|
-
const { graphicAlternative } =
|
|
11011
|
+
const { graphicAlternative } = _m79;
|
|
10557
11012
|
|
|
10558
|
-
const { checkDrawingBlock, prepareDrawing } =
|
|
11013
|
+
const { checkDrawingBlock, prepareDrawing } = _m87;
|
|
10559
11014
|
|
|
10560
|
-
const { captureParagraph, captureCaption, prepareParagraph, checkParagraphBuffer, paragraphStartHeight } =
|
|
11015
|
+
const { captureParagraph, captureCaption, prepareParagraph, checkParagraphBuffer, paragraphStartHeight } = _m88;
|
|
10561
11016
|
|
|
10562
|
-
const { captureListOptions, prepareListItem } =
|
|
11017
|
+
const { captureListOptions, prepareListItem } = _m89;
|
|
10563
11018
|
|
|
10564
|
-
const { captureSection } =
|
|
11019
|
+
const { captureSection } = _m77;
|
|
10565
11020
|
|
|
10566
|
-
const { renderGroupedPdfTable } =
|
|
11021
|
+
const { renderGroupedPdfTable } = _m90;
|
|
10567
11022
|
|
|
10568
11023
|
const tableOptionFields = ["columns", "includeHeader", "headerRows", "footer", "headerPresentation", "footerPresentation", "alternateRowColor", "columnWidths", "wideTable", "formatValue", "formatRuns"];
|
|
10569
11024
|
/** Capture typed columns for a single-use table source in a composed document. */
|
|
@@ -10821,18 +11276,18 @@ const _exports = Object.freeze({ pdfTable: pdfTable, writePdfDocument: writePdfD
|
|
|
10821
11276
|
return _exports;
|
|
10822
11277
|
})();
|
|
10823
11278
|
|
|
10824
|
-
const
|
|
11279
|
+
const _m82 = (() => {
|
|
10825
11280
|
const { assertGroupedReportSource } = _m8;
|
|
10826
11281
|
|
|
10827
11282
|
const { BlobByteSink } = _m3;
|
|
10828
11283
|
|
|
10829
|
-
const { writePdfDocumentTo } =
|
|
11284
|
+
const { writePdfDocumentTo } = _m83;
|
|
10830
11285
|
|
|
10831
11286
|
const { pdfOptionFields } = _m55;
|
|
10832
11287
|
|
|
10833
11288
|
const { captureFields } = _m10;
|
|
10834
11289
|
|
|
10835
|
-
const { pdfGroupedTable, groupedPdfLabelFields, groupedPdfTableFields } =
|
|
11290
|
+
const { pdfGroupedTable, groupedPdfLabelFields, groupedPdfTableFields } = _m91;
|
|
10836
11291
|
|
|
10837
11292
|
|
|
10838
11293
|
|
|
@@ -10866,14 +11321,14 @@ async function writeGroupedPdfTo(report, destination, configuration) {
|
|
|
10866
11321
|
delete documentOptions.footer;
|
|
10867
11322
|
return writePdfDocumentTo([pdfGroupedTable(report, tableOptions)], destination, documentOptions);
|
|
10868
11323
|
}
|
|
10869
|
-
const _exports = Object.freeze({ pdfGroupedTable:
|
|
11324
|
+
const _exports = Object.freeze({ pdfGroupedTable: _m91.pdfGroupedTable, writeGroupedPdf: writeGroupedPdf, writeGroupedPdfTo: writeGroupedPdfTo });
|
|
10870
11325
|
return _exports;
|
|
10871
11326
|
})();
|
|
10872
11327
|
|
|
10873
|
-
const
|
|
10874
|
-
const { fontProgram } =
|
|
11328
|
+
const _m92 = (() => {
|
|
11329
|
+
const { fontProgram } = _m62;
|
|
10875
11330
|
|
|
10876
|
-
const { resolveScalar, selectFont, validateFonts } =
|
|
11331
|
+
const { resolveScalar, selectFont, validateFonts } = _m66;
|
|
10877
11332
|
|
|
10878
11333
|
/**
|
|
10879
11334
|
* Check one text run against the writer's selected font and scalar-layout rules.
|
|
@@ -10911,11 +11366,11 @@ return _exports;
|
|
|
10911
11366
|
|
|
10912
11367
|
const _m53 = (() => {
|
|
10913
11368
|
|
|
10914
|
-
const _exports = Object.freeze({ writePdf: _m54.writePdf, writePdfTo: _m54.writePdfTo, writeGroupedPdf:
|
|
11369
|
+
const _exports = Object.freeze({ writePdf: _m54.writePdf, writePdfTo: _m54.writePdfTo, writeGroupedPdf: _m82.writeGroupedPdf, writeGroupedPdfTo: _m82.writeGroupedPdfTo, pdfGroupedTable: _m82.pdfGroupedTable, createGroupedReport: _m8.createGroupedReport, writePdfDocument: _m83.writePdfDocument, writePdfDocumentTo: _m83.writePdfDocumentTo, pdfTable: _m83.pdfTable, PdfFont: _m62.PdfFont, preflightPdfText: _m92.preflightPdfText, ExportCell: _m5.ExportCell, saveBlob: _m1.saveBlob });
|
|
10915
11370
|
return _exports;
|
|
10916
11371
|
})();
|
|
10917
11372
|
|
|
10918
|
-
const
|
|
11373
|
+
const _m93 = (() => {
|
|
10919
11374
|
/** @internal Runtime-checked calls across the optional third-party API boundary. */
|
|
10920
11375
|
function call(owner, name, ...args) {
|
|
10921
11376
|
const fn = member(owner, name);
|
|
@@ -10947,12 +11402,12 @@ const _exports = Object.freeze({ call: call, member: member, array: array, index
|
|
|
10947
11402
|
return _exports;
|
|
10948
11403
|
})();
|
|
10949
11404
|
|
|
10950
|
-
const
|
|
11405
|
+
const _m94 = (() => {
|
|
10951
11406
|
const { ExportCell, assertExportValue } = _m5;
|
|
10952
11407
|
|
|
10953
11408
|
const { tableSpans } = _m17;
|
|
10954
11409
|
|
|
10955
|
-
const { member } =
|
|
11410
|
+
const { member } = _m93;
|
|
10956
11411
|
|
|
10957
11412
|
/** @internal */
|
|
10958
11413
|
function value(input) {
|
|
@@ -11020,18 +11475,18 @@ const _exports = Object.freeze({ value: value, text: text, headings: headings })
|
|
|
11020
11475
|
return _exports;
|
|
11021
11476
|
})();
|
|
11022
11477
|
|
|
11023
|
-
const
|
|
11478
|
+
const _m95 = (() => {
|
|
11024
11479
|
const { checkAbort, pause, rowsFromBatches, taskYieldDue } = _m4;
|
|
11025
11480
|
|
|
11026
11481
|
const { ExportBudget } = _m9;
|
|
11027
11482
|
|
|
11028
11483
|
const { captureFields } = _m10;
|
|
11029
11484
|
|
|
11030
|
-
const { columnOptionFields } = _m11;
|
|
11485
|
+
const { columnOptionFields, copyColumns } = _m11;
|
|
11031
11486
|
|
|
11032
|
-
const { array, call, indexes, member } =
|
|
11487
|
+
const { array, call, indexes, member } = _m93;
|
|
11033
11488
|
|
|
11034
|
-
const { headings, text, value } =
|
|
11489
|
+
const { headings, text, value } = _m94;
|
|
11035
11490
|
|
|
11036
11491
|
function safeOptions(options) {
|
|
11037
11492
|
options = captureFields(options, ["rows", "columns", "modifier", "orthogonal", "stripHtml", "stripNewlines", "decodeEntities", "escapeExcelFormula", "trim", "format", "customizeData"]);
|
|
@@ -11106,10 +11561,10 @@ function captureDataTablesExport(host, table, options = {}, omitted) {
|
|
|
11106
11561
|
for (const index of columnIndexes)
|
|
11107
11562
|
if (member(options.columnOptions?.[index], "value") !== undefined)
|
|
11108
11563
|
throw new TypeError("DataTables columnOptions describes columns; resolve values with project.");
|
|
11109
|
-
const columns = Object.freeze(leaf.map((label, index) =>
|
|
11564
|
+
const columns = Object.freeze(copyColumns(leaf.map((label, index) => ({
|
|
11110
11565
|
header: text(label), key: "dt:" + columnIndexes[index], ...options.columnOptions?.[columnIndexes[index]],
|
|
11111
11566
|
...(heading.groups[index].length ? { groups: Object.freeze(heading.groups[index]) } : {})
|
|
11112
|
-
})));
|
|
11567
|
+
}))).map(column => Object.freeze(column)));
|
|
11113
11568
|
// Explicit heading overrides also apply to CSV's leaf heading.
|
|
11114
11569
|
if (!heading.structure)
|
|
11115
11570
|
heading.rows[heading.rows.length - 1] = columns.map(column => column.header);
|
|
@@ -11237,7 +11692,7 @@ const _exports = Object.freeze({ createDataTablesExport: createDataTablesExport,
|
|
|
11237
11692
|
return _exports;
|
|
11238
11693
|
})();
|
|
11239
11694
|
|
|
11240
|
-
const
|
|
11695
|
+
const _m96 = (() => {
|
|
11241
11696
|
const { captureFields } = _m10;
|
|
11242
11697
|
|
|
11243
11698
|
const { ExportBudget } = _m9;
|
|
@@ -11294,15 +11749,15 @@ const { writePdfTo } = _m53;
|
|
|
11294
11749
|
|
|
11295
11750
|
const { portableSheet, portableWorkbook } = _m50;
|
|
11296
11751
|
|
|
11297
|
-
const { call, member } =
|
|
11752
|
+
const { call, member } = _m93;
|
|
11298
11753
|
|
|
11299
|
-
const { value } =
|
|
11754
|
+
const { value } = _m94;
|
|
11300
11755
|
|
|
11301
|
-
const { captureDataTablesExport } =
|
|
11756
|
+
const { captureDataTablesExport } = _m95;
|
|
11302
11757
|
|
|
11303
11758
|
const { captureFields } = _m10;
|
|
11304
11759
|
|
|
11305
|
-
const { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfOptions, mergeAdapterLimits } =
|
|
11760
|
+
const { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfOptions, mergeAdapterLimits } = _m96;
|
|
11306
11761
|
|
|
11307
11762
|
|
|
11308
11763
|
|
|
@@ -11463,7 +11918,7 @@ function registerDataTablesButtons(host, options = {}) {
|
|
|
11463
11918
|
};
|
|
11464
11919
|
}
|
|
11465
11920
|
}
|
|
11466
|
-
const _exports = Object.freeze({ createDataTablesExport:
|
|
11921
|
+
const _exports = Object.freeze({ createDataTablesExport: _m95.createDataTablesExport, ExportCell: _m5.ExportCell, PdfFont: _m62.PdfFont, writeDataTableTo: writeDataTableTo, exportDataTable: exportDataTable, registerDataTablesButtons: registerDataTablesButtons });
|
|
11467
11922
|
return _exports;
|
|
11468
11923
|
})();
|
|
11469
11924
|
const { createDataTablesExport, ExportCell, PdfFont, writeDataTableTo, exportDataTable, registerDataTablesButtons } = _m0;
|