@evotecit/officeimo 0.1.1 → 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/bundles/officeimo-canopyx.js +95 -85
- package/bundles/officeimo-canopyx.mjs +29 -19
- package/bundles/officeimo-datatables.js +95 -85
- package/bundles/officeimo-datatables.mjs +29 -19
- package/bundles/officeimo-pdf.js +15 -14
- package/bundles/officeimo-pdf.mjs +3 -2
- package/bundles/officeimo-xlsx.js +78 -69
- package/bundles/officeimo-xlsx.mjs +26 -17
- package/bundles/officeimo.js +95 -85
- package/bundles/officeimo.mjs +29 -19
- package/dist/opc/index.js +14 -9
- package/dist/pdf/pages.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/package.json +1 -1
package/bundles/officeimo.mjs
CHANGED
|
@@ -1371,6 +1371,8 @@ const { OfficeIMOError } = _m2;
|
|
|
1371
1371
|
const { ChunkedTextSink } = _m3;
|
|
1372
1372
|
|
|
1373
1373
|
const xmlDeclaration = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
1374
|
+
const xmlEscapes = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'",
|
|
1375
|
+
"\r": " ", "\n": " ", "\t": "	" };
|
|
1374
1376
|
/** XML 1.0 characters; Unicode mode retains valid surrogate pairs. */
|
|
1375
1377
|
function cleanXml(value, policy = "strip") {
|
|
1376
1378
|
if (policy !== "strip" && policy !== "reject")
|
|
@@ -1382,9 +1384,7 @@ function cleanXml(value, policy = "strip") {
|
|
|
1382
1384
|
}
|
|
1383
1385
|
/** Escape data, including whitespace that XML parsers otherwise normalize. */
|
|
1384
1386
|
function escapeXml(value, policy = "strip") {
|
|
1385
|
-
|
|
1386
|
-
"\r": " ", "\n": " ", "\t": "	" };
|
|
1387
|
-
return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => escapes[c]);
|
|
1387
|
+
return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => xmlEscapes[c]);
|
|
1388
1388
|
}
|
|
1389
1389
|
/** Encode an OOXML ST_Xstring attribute without interpreting literal escape tokens as characters. */
|
|
1390
1390
|
function escapeOoxmlAttribute(value, policy = "strip") {
|
|
@@ -1617,8 +1617,11 @@ class OpcPackage {
|
|
|
1617
1617
|
return uri;
|
|
1618
1618
|
}
|
|
1619
1619
|
addPart(part) {
|
|
1620
|
-
const uri
|
|
1621
|
-
|
|
1620
|
+
const { uri: requestedUri, contentType, data } = part;
|
|
1621
|
+
// Structural accessors and byte ownership are captured before reserving metadata.
|
|
1622
|
+
const capturedData = data instanceof Uint8Array ? new Uint8Array(data) : data;
|
|
1623
|
+
const uri = this.reserve(requestedUri, contentType);
|
|
1624
|
+
this.parts.set(uri.toLowerCase(), { uri, contentType, data: capturedData });
|
|
1622
1625
|
}
|
|
1623
1626
|
/** @internal */
|
|
1624
1627
|
addPrepared(uri, type, prepared) {
|
|
@@ -1643,17 +1646,19 @@ class OpcPackage {
|
|
|
1643
1646
|
checkAbort(this.options.signal);
|
|
1644
1647
|
this.open();
|
|
1645
1648
|
source = source === "/" ? source : partUri(source);
|
|
1646
|
-
|
|
1649
|
+
const { id, type, target: requestedTarget, external } = relationship;
|
|
1650
|
+
this.open();
|
|
1651
|
+
if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(id))
|
|
1647
1652
|
throw new TypeError("Relationship id must be an XML ID.");
|
|
1648
|
-
if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(
|
|
1653
|
+
if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(type))
|
|
1649
1654
|
throw new TypeError("Relationship type must be an absolute URI.");
|
|
1650
|
-
const target =
|
|
1651
|
-
if (
|
|
1655
|
+
const target = external ? requestedTarget : partUri(requestedTarget);
|
|
1656
|
+
if (external && (!target || /[\u0000-\u0020]/.test(target)))
|
|
1652
1657
|
throw new TypeError("Invalid external relationship target.");
|
|
1653
1658
|
const key = source.toLowerCase(), list = this.relationships.get(key) ?? new Map();
|
|
1654
|
-
if (list.has(
|
|
1655
|
-
throw new TypeError("Duplicate relationship id: " +
|
|
1656
|
-
list.set(
|
|
1659
|
+
if (list.has(id))
|
|
1660
|
+
throw new TypeError("Duplicate relationship id: " + id);
|
|
1661
|
+
list.set(id, { id, type, target, ...(external === undefined ? {} : { external }) });
|
|
1657
1662
|
this.relationships.set(key, list);
|
|
1658
1663
|
}
|
|
1659
1664
|
setProperties(core = {}, app = {}) {
|
|
@@ -3544,7 +3549,8 @@ class Worksheet {
|
|
|
3544
3549
|
});
|
|
3545
3550
|
const originalCharacters = typeof value === "string" ? value.length : 0;
|
|
3546
3551
|
let reservedCharacters = this.preserved || header || footer ? originalCharacters : undefined;
|
|
3547
|
-
|
|
3552
|
+
// Cleaning removes characters; ordinary strings cannot cross Excel's limit.
|
|
3553
|
+
if (type === "string" && originalCharacters > 32767 && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
|
|
3548
3554
|
const cell = col.letter + row;
|
|
3549
3555
|
if (link || this.linkedCells.has(cell))
|
|
3550
3556
|
throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
|
|
@@ -4764,12 +4770,15 @@ class Workbook {
|
|
|
4764
4770
|
});
|
|
4765
4771
|
}
|
|
4766
4772
|
addPart(part) {
|
|
4773
|
+
this.assertOpen();
|
|
4774
|
+
const { uri, contentType, data, relationship } = part;
|
|
4775
|
+
const capturedRelationship = relationship && { id: relationship.id, type: relationship.type, source: relationship.source };
|
|
4767
4776
|
this.assertOpen();
|
|
4768
4777
|
// Reserve now so collisions and invalid names fail at the call site.
|
|
4769
|
-
this.package.addPart(
|
|
4770
|
-
if (
|
|
4771
|
-
const { source,
|
|
4772
|
-
this.package.addRelationship(source ?? "/xl/workbook.xml", {
|
|
4778
|
+
this.package.addPart({ uri, contentType, data });
|
|
4779
|
+
if (capturedRelationship) {
|
|
4780
|
+
const { source, id, type } = capturedRelationship;
|
|
4781
|
+
this.package.addRelationship(source ?? "/xl/workbook.xml", { id, type, target: uri });
|
|
4773
4782
|
}
|
|
4774
4783
|
}
|
|
4775
4784
|
/** Complete the archive and return counts. Does not close or dispose a caller-owned sink. */
|
|
@@ -8816,7 +8825,7 @@ class PdfPages {
|
|
|
8816
8825
|
// Charge physical repeats without recapturing callbacks or making them semantic duplicates.
|
|
8817
8826
|
for (const cell of header.cells)
|
|
8818
8827
|
if (!this.bandCellBudget && this.paintedHeaderBudgetCells.has(cell.source ?? cell))
|
|
8819
|
-
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(""));
|
|
8820
8829
|
const elements = this.tableStructure ? header.cells.map(cell => this.tableStructure.owner(cell.source ?? cell)) : undefined;
|
|
8821
8830
|
const repeated = header.cells.map(cell => this.paintedHeaderCells.has(cell.source ?? cell));
|
|
8822
8831
|
this.draw(header, 0, header.lines, elements, repeated);
|
|
@@ -8837,7 +8846,8 @@ class PdfPages {
|
|
|
8837
8846
|
const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
|
|
8838
8847
|
for (const [index, cell] of row.cells.entries()) {
|
|
8839
8848
|
if (this.bandCellBudget)
|
|
8840
|
-
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(""));
|
|
8841
8851
|
const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
|
|
8842
8852
|
if (cell.style.background)
|
|
8843
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"));
|
package/dist/opc/index.js
CHANGED
|
@@ -86,8 +86,11 @@ export class OpcPackage {
|
|
|
86
86
|
return uri;
|
|
87
87
|
}
|
|
88
88
|
addPart(part) {
|
|
89
|
-
const uri
|
|
90
|
-
|
|
89
|
+
const { uri: requestedUri, contentType, data } = part;
|
|
90
|
+
// Structural accessors and byte ownership are captured before reserving metadata.
|
|
91
|
+
const capturedData = data instanceof Uint8Array ? new Uint8Array(data) : data;
|
|
92
|
+
const uri = this.reserve(requestedUri, contentType);
|
|
93
|
+
this.parts.set(uri.toLowerCase(), { uri, contentType, data: capturedData });
|
|
91
94
|
}
|
|
92
95
|
/** @internal */
|
|
93
96
|
addPrepared(uri, type, prepared) {
|
|
@@ -112,17 +115,19 @@ export class OpcPackage {
|
|
|
112
115
|
checkAbort(this.options.signal);
|
|
113
116
|
this.open();
|
|
114
117
|
source = source === "/" ? source : partUri(source);
|
|
115
|
-
|
|
118
|
+
const { id, type, target: requestedTarget, external } = relationship;
|
|
119
|
+
this.open();
|
|
120
|
+
if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(id))
|
|
116
121
|
throw new TypeError("Relationship id must be an XML ID.");
|
|
117
|
-
if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(
|
|
122
|
+
if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(type))
|
|
118
123
|
throw new TypeError("Relationship type must be an absolute URI.");
|
|
119
|
-
const target =
|
|
120
|
-
if (
|
|
124
|
+
const target = external ? requestedTarget : partUri(requestedTarget);
|
|
125
|
+
if (external && (!target || /[\u0000-\u0020]/.test(target)))
|
|
121
126
|
throw new TypeError("Invalid external relationship target.");
|
|
122
127
|
const key = source.toLowerCase(), list = this.relationships.get(key) ?? new Map();
|
|
123
|
-
if (list.has(
|
|
124
|
-
throw new TypeError("Duplicate relationship id: " +
|
|
125
|
-
list.set(
|
|
128
|
+
if (list.has(id))
|
|
129
|
+
throw new TypeError("Duplicate relationship id: " + id);
|
|
130
|
+
list.set(id, { id, type, target, ...(external === undefined ? {} : { external }) });
|
|
126
131
|
this.relationships.set(key, list);
|
|
127
132
|
}
|
|
128
133
|
setProperties(core = {}, app = {}) {
|
package/dist/pdf/pages.js
CHANGED
|
@@ -271,7 +271,7 @@ export class PdfPages {
|
|
|
271
271
|
// Charge physical repeats without recapturing callbacks or making them semantic duplicates.
|
|
272
272
|
for (const cell of header.cells)
|
|
273
273
|
if (!this.bandCellBudget && this.paintedHeaderBudgetCells.has(cell.source ?? cell))
|
|
274
|
-
this.settings.budget.cell(cell.lines.map(line => line.text).join(""));
|
|
274
|
+
this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" : cell.lines.map(line => line.text).join(""));
|
|
275
275
|
const elements = this.tableStructure ? header.cells.map(cell => this.tableStructure.owner(cell.source ?? cell)) : undefined;
|
|
276
276
|
const repeated = header.cells.map(cell => this.paintedHeaderCells.has(cell.source ?? cell));
|
|
277
277
|
this.draw(header, 0, header.lines, elements, repeated);
|
|
@@ -292,7 +292,8 @@ export class PdfPages {
|
|
|
292
292
|
const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
|
|
293
293
|
for (const [index, cell] of row.cells.entries()) {
|
|
294
294
|
if (this.bandCellBudget)
|
|
295
|
-
this.settings.budget.cell(
|
|
295
|
+
this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
|
|
296
|
+
(cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
|
|
296
297
|
const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
|
|
297
298
|
if (cell.style.background)
|
|
298
299
|
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"));
|
package/dist/xlsx/workbook.js
CHANGED
|
@@ -315,12 +315,15 @@ export class Workbook {
|
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
317
|
addPart(part) {
|
|
318
|
+
this.assertOpen();
|
|
319
|
+
const { uri, contentType, data, relationship } = part;
|
|
320
|
+
const capturedRelationship = relationship && { id: relationship.id, type: relationship.type, source: relationship.source };
|
|
318
321
|
this.assertOpen();
|
|
319
322
|
// Reserve now so collisions and invalid names fail at the call site.
|
|
320
|
-
this.package.addPart(
|
|
321
|
-
if (
|
|
322
|
-
const { source,
|
|
323
|
-
this.package.addRelationship(source ?? "/xl/workbook.xml", {
|
|
323
|
+
this.package.addPart({ uri, contentType, data });
|
|
324
|
+
if (capturedRelationship) {
|
|
325
|
+
const { source, id, type } = capturedRelationship;
|
|
326
|
+
this.package.addRelationship(source ?? "/xl/workbook.xml", { id, type, target: uri });
|
|
324
327
|
}
|
|
325
328
|
}
|
|
326
329
|
/** Complete the archive and return counts. Does not close or dispose a caller-owned sink. */
|
package/dist/xlsx/worksheet.js
CHANGED
|
@@ -257,7 +257,8 @@ export class Worksheet {
|
|
|
257
257
|
});
|
|
258
258
|
const originalCharacters = typeof value === "string" ? value.length : 0;
|
|
259
259
|
let reservedCharacters = this.preserved || header || footer ? originalCharacters : undefined;
|
|
260
|
-
|
|
260
|
+
// Cleaning removes characters; ordinary strings cannot cross Excel's limit.
|
|
261
|
+
if (type === "string" && originalCharacters > 32767 && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
|
|
261
262
|
const cell = col.letter + row;
|
|
262
263
|
if (link || this.linkedCells.has(cell))
|
|
263
264
|
throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
|
package/dist/xml/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { OfficeIMOError } from "../core/errors.js";
|
|
2
2
|
import { ChunkedTextSink } from "../core/sinks.js";
|
|
3
3
|
export const xmlDeclaration = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
4
|
+
const xmlEscapes = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'",
|
|
5
|
+
"\r": " ", "\n": " ", "\t": "	" };
|
|
4
6
|
/** XML 1.0 characters; Unicode mode retains valid surrogate pairs. */
|
|
5
7
|
export function cleanXml(value, policy = "strip") {
|
|
6
8
|
if (policy !== "strip" && policy !== "reject")
|
|
@@ -12,9 +14,7 @@ export function cleanXml(value, policy = "strip") {
|
|
|
12
14
|
}
|
|
13
15
|
/** Escape data, including whitespace that XML parsers otherwise normalize. */
|
|
14
16
|
export function escapeXml(value, policy = "strip") {
|
|
15
|
-
|
|
16
|
-
"\r": " ", "\n": " ", "\t": "	" };
|
|
17
|
-
return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => escapes[c]);
|
|
17
|
+
return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => xmlEscapes[c]);
|
|
18
18
|
}
|
|
19
19
|
/** Encode an OOXML ST_Xstring attribute without interpreting literal escape tokens as characters. */
|
|
20
20
|
export function escapeOoxmlAttribute(value, policy = "strip") {
|