@evotecit/officeimo 0.1.19 → 0.1.43
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 +44 -10
- package/bundles/officeimo-canopyx-adapter.js +147 -65
- package/bundles/officeimo-canopyx-adapter.min.js +1 -1
- package/bundles/officeimo-canopyx-adapter.min.mjs +1 -1
- package/bundles/officeimo-canopyx-adapter.mjs +134 -53
- package/bundles/officeimo-canopyx.js +554 -234
- package/bundles/officeimo-canopyx.min.js +1 -1
- package/bundles/officeimo-canopyx.min.mjs +1 -1
- package/bundles/officeimo-canopyx.mjs +477 -158
- package/bundles/officeimo-chartforgex-adapter.js +1924 -0
- package/bundles/officeimo-chartforgex-adapter.min.js +2 -0
- package/bundles/officeimo-chartforgex-adapter.min.mjs +2 -0
- package/bundles/officeimo-chartforgex-adapter.mjs +1910 -0
- package/bundles/officeimo-chartforgex.js +13594 -0
- package/bundles/officeimo-chartforgex.min.js +2 -0
- package/bundles/officeimo-chartforgex.min.mjs +2 -0
- package/bundles/officeimo-chartforgex.mjs +13487 -0
- package/bundles/officeimo-csv.js +12 -7
- package/bundles/officeimo-csv.min.js +1 -1
- package/bundles/officeimo-csv.min.mjs +1 -1
- package/bundles/officeimo-csv.mjs +8 -3
- package/bundles/officeimo-datatables-adapter.js +11 -11
- package/bundles/officeimo-datatables-adapter.min.js +1 -1
- package/bundles/officeimo-datatables-adapter.min.mjs +1 -1
- package/bundles/officeimo-datatables-adapter.mjs +7 -7
- package/bundles/officeimo-datatables.js +418 -180
- package/bundles/officeimo-datatables.min.js +1 -1
- package/bundles/officeimo-datatables.min.mjs +1 -1
- package/bundles/officeimo-datatables.mjs +350 -112
- package/bundles/officeimo-execution.js +14 -9
- package/bundles/officeimo-execution.min.js +1 -1
- package/bundles/officeimo-execution.min.mjs +1 -1
- package/bundles/officeimo-execution.mjs +8 -3
- package/bundles/officeimo-pdf.js +286 -120
- package/bundles/officeimo-pdf.min.js +1 -1
- package/bundles/officeimo-pdf.min.mjs +1 -1
- package/bundles/officeimo-pdf.mjs +244 -78
- package/bundles/officeimo-xlsx.js +136 -59
- package/bundles/officeimo-xlsx.min.js +1 -1
- package/bundles/officeimo-xlsx.min.mjs +1 -1
- package/bundles/officeimo-xlsx.mjs +114 -37
- package/bundles/officeimo.js +416 -178
- package/bundles/officeimo.min.js +1 -1
- package/bundles/officeimo.min.mjs +1 -1
- package/bundles/officeimo.mjs +351 -113
- package/dist/core/progress.js +7 -2
- package/dist/index.d.ts +1 -1
- package/dist/integrations/canopyx/index.js +13 -4
- package/dist/integrations/canopyx/pdf-number.js +9 -6
- package/dist/integrations/canopyx/rule-predicates.d.ts +1 -1
- package/dist/integrations/canopyx/rule-predicates.js +2 -1
- package/dist/integrations/canopyx/rules.d.ts +1 -1
- package/dist/integrations/canopyx/rules.js +11 -13
- package/dist/integrations/canopyx/source.js +57 -7
- package/dist/integrations/canopyx/tones.d.ts +10 -0
- package/dist/integrations/canopyx/tones.js +12 -0
- package/dist/integrations/canopyx/types.d.ts +8 -1
- package/dist/integrations/chartforgex/capture.d.ts +31 -0
- package/dist/integrations/chartforgex/capture.js +103 -0
- package/dist/integrations/chartforgex/index.d.ts +13 -0
- package/dist/integrations/chartforgex/index.js +88 -0
- package/dist/integrations/chartforgex/svg-drawing.d.ts +5 -0
- package/dist/integrations/chartforgex/svg-drawing.js +775 -0
- package/dist/integrations/chartforgex/svg-geometry.d.ts +23 -0
- package/dist/integrations/chartforgex/svg-geometry.js +304 -0
- package/dist/integrations/chartforgex/svg-image.d.ts +9 -0
- package/dist/integrations/chartforgex/svg-image.js +46 -0
- package/dist/integrations/chartforgex/svg-markup.d.ts +10 -0
- package/dist/integrations/chartforgex/svg-markup.js +124 -0
- package/dist/integrations/chartforgex/svg-paint.d.ts +16 -0
- package/dist/integrations/chartforgex/svg-paint.js +146 -0
- package/dist/integrations/chartforgex/types.d.ts +77 -0
- package/dist/integrations/chartforgex/types.js +1 -0
- package/dist/integrations/chartforgex/winansi.d.ts +4 -0
- package/dist/integrations/chartforgex/winansi.js +48 -0
- package/dist/integrations/chartforgex/workbook.d.ts +12 -0
- package/dist/integrations/chartforgex/workbook.js +137 -0
- package/dist/pdf/document-drawings.d.ts +1 -1
- package/dist/pdf/document-drawings.js +91 -17
- package/dist/pdf/document-images.d.ts +7 -1
- package/dist/pdf/document-images.js +59 -24
- package/dist/pdf/document-types.d.ts +3 -1
- package/dist/pdf/document.d.ts +2 -2
- package/dist/pdf/document.js +3 -1
- package/dist/pdf/drawing-types.d.ts +37 -10
- package/dist/pdf/font-resources.d.ts +1 -1
- package/dist/pdf/font-resources.js +6 -3
- package/dist/pdf/index.d.ts +1 -1
- package/dist/pdf/pages.js +15 -0
- package/dist/pdf/png.d.ts +11 -2
- package/dist/pdf/png.js +50 -23
- package/dist/pdf/session.js +3 -2
- package/dist/pdf/settings.d.ts +2 -2
- package/dist/pdf/settings.js +7 -3
- package/dist/xlsx/options.js +2 -2
- package/dist/xlsx/portable.js +1 -1
- package/dist/xlsx/styles.js +28 -18
- package/dist/xlsx/types.d.ts +13 -1
- package/dist/xlsx/workbook.js +9 -1
- package/dist/xlsx/worksheet.d.ts +13 -1
- package/dist/xlsx/worksheet.js +65 -11
- package/package.json +9 -2
package/bundles/officeimo.mjs
CHANGED
|
@@ -1783,15 +1783,20 @@ return _exports;
|
|
|
1783
1783
|
const _m23 = (() => {
|
|
1784
1784
|
/** @internal Notify synchronously; observe an accidental promise before rejecting its unsupported use. */
|
|
1785
1785
|
function notifyProgress(callback, progress) {
|
|
1786
|
+
notifySynchronously("onProgress", callback, progress);
|
|
1787
|
+
}
|
|
1788
|
+
/** @internal Run a host notification that must finish before the export continues. A returned promise is observed,
|
|
1789
|
+
* so its rejection is never unhandled, and the export fails instead of reporting success before the callback ends. */
|
|
1790
|
+
function notifySynchronously(name, callback, value) {
|
|
1786
1791
|
if (!callback)
|
|
1787
1792
|
return;
|
|
1788
|
-
const result = callback(
|
|
1793
|
+
const result = callback(value);
|
|
1789
1794
|
if (result && typeof result.then === "function") {
|
|
1790
1795
|
void Promise.resolve(result).catch(() => { });
|
|
1791
|
-
throw new TypeError("
|
|
1796
|
+
throw new TypeError(name + " must be synchronous.");
|
|
1792
1797
|
}
|
|
1793
1798
|
}
|
|
1794
|
-
const _exports = Object.freeze({ notifyProgress: notifyProgress });
|
|
1799
|
+
const _exports = Object.freeze({ notifyProgress: notifyProgress, notifySynchronously: notifySynchronously });
|
|
1795
1800
|
return _exports;
|
|
1796
1801
|
})();
|
|
1797
1802
|
|
|
@@ -1928,6 +1933,24 @@ const { DifferentialStyles } = _m26;
|
|
|
1928
1933
|
|
|
1929
1934
|
|
|
1930
1935
|
const spreadsheetNamespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
|
1936
|
+
const borderStyles = ["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"];
|
|
1937
|
+
/** @internal Validate and normalize border edges without registering a workbook style. */
|
|
1938
|
+
function normalizeBorder(border) {
|
|
1939
|
+
if (!border || typeof border !== "object")
|
|
1940
|
+
throw new TypeError("A border must be an object of edges.");
|
|
1941
|
+
const result = {};
|
|
1942
|
+
for (const side of ["left", "right", "top", "bottom"]) {
|
|
1943
|
+
const edge = border[side];
|
|
1944
|
+
if (edge) {
|
|
1945
|
+
// Read each property once, so the validated edge is the one that is stored.
|
|
1946
|
+
const { style, color } = edge;
|
|
1947
|
+
if (!borderStyles.includes(style))
|
|
1948
|
+
throw new TypeError("Invalid border style.");
|
|
1949
|
+
result[side] = { style, ...(color ? { color: colorArgb(color) } : {}) };
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
return result;
|
|
1953
|
+
}
|
|
1931
1954
|
const NumberFormats = { General: "General", Integer: "0", Decimal: "0.00", Percent: "0.00%", Date: "yyyy-mm-dd", DateTime: "yyyy-mm-dd hh:mm:ss" };
|
|
1932
1955
|
function index(value, count, kind) {
|
|
1933
1956
|
if (!Number.isInteger(value) || value < 0 || value >= count)
|
|
@@ -2000,32 +2023,24 @@ class StyleRegistry {
|
|
|
2000
2023
|
/** @internal */
|
|
2001
2024
|
addDifferentials(styles) { this.checkDifferentials(styles); return this.differential.add(styles); }
|
|
2002
2025
|
addFont(font) {
|
|
2003
|
-
|
|
2026
|
+
const { name: requested, size: requestedSize, bold, italic, underline, strike, color } = font;
|
|
2027
|
+
if (requested !== undefined && typeof requested !== "string")
|
|
2004
2028
|
throw new TypeError("Font name must be a string.");
|
|
2005
|
-
const name = cleanXml(
|
|
2029
|
+
const name = cleanXml(requested ?? "Calibri", this.policy), size = requestedSize ?? 11;
|
|
2006
2030
|
if (typeof name !== "string" || !name || name.length > 31)
|
|
2007
2031
|
throw new TypeError("Font name must contain 1 through 31 characters.");
|
|
2008
2032
|
if (!Number.isFinite(size) || size <= 0 || size > 409)
|
|
2009
2033
|
throw new RangeError("Font size must be positive and at most 409.");
|
|
2010
|
-
return deduplicate(this.fonts, this.fontIndexes, { name, size, bold: !!
|
|
2034
|
+
return deduplicate(this.fonts, this.fontIndexes, { name, size, bold: !!bold, italic: !!italic, underline: !!underline, strike: !!strike, color: color ? colorArgb(color) : "" }, this.maximum);
|
|
2011
2035
|
}
|
|
2012
2036
|
addFill(fill) {
|
|
2013
|
-
const pattern = fill.pattern ?? (
|
|
2014
|
-
if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !
|
|
2037
|
+
const { color } = fill, pattern = fill.pattern ?? (color ? "solid" : "none");
|
|
2038
|
+
if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !color) || (pattern !== "solid" && color))
|
|
2015
2039
|
throw new TypeError("A solid fill requires a color; none and gray125 have no color.");
|
|
2016
|
-
return deduplicate(this.fills, this.fillIndexes, { pattern, color:
|
|
2040
|
+
return deduplicate(this.fills, this.fillIndexes, { pattern, color: color ? colorArgb(color) : "" }, this.maximum + 1);
|
|
2017
2041
|
}
|
|
2018
2042
|
addBorder(border) {
|
|
2019
|
-
|
|
2020
|
-
for (const side of ["left", "right", "top", "bottom"]) {
|
|
2021
|
-
const edge = border[side];
|
|
2022
|
-
if (edge) {
|
|
2023
|
-
if (!["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"].includes(edge.style))
|
|
2024
|
-
throw new TypeError("Invalid border style.");
|
|
2025
|
-
result[side] = { style: edge.style, ...(edge.color ? { color: colorArgb(edge.color) } : {}) };
|
|
2026
|
-
}
|
|
2027
|
-
}
|
|
2028
|
-
return deduplicate(this.borders, this.borderIndexes, result, this.maximum);
|
|
2043
|
+
return deduplicate(this.borders, this.borderIndexes, normalizeBorder(border), this.maximum);
|
|
2029
2044
|
}
|
|
2030
2045
|
addNumberFormat(format) {
|
|
2031
2046
|
if (typeof format !== "string" || !format || format.length > 255)
|
|
@@ -2091,7 +2106,7 @@ class StyleRegistry {
|
|
|
2091
2106
|
return this.compose(base, { numberFormat: this.styles[this.validateStyle(dateStyle)].numberFormat });
|
|
2092
2107
|
}
|
|
2093
2108
|
/** @internal Column shorthand and header style composition. */
|
|
2094
|
-
forColumn(column, header = false, fill, date = false) {
|
|
2109
|
+
forColumn(column, header = false, fill, date = false, border) {
|
|
2095
2110
|
const base = !header && column.style !== undefined ? this.styles[this.validateStyle(column.style)] : undefined;
|
|
2096
2111
|
const format = column.format !== undefined ? column.format || NumberFormats.General : base?.numberFormat || (column.type === "date" || date ? NumberFormats.DateTime : NumberFormats.General);
|
|
2097
2112
|
return this.add({
|
|
@@ -2100,7 +2115,7 @@ class StyleRegistry {
|
|
|
2100
2115
|
wrapText: column.wrapText ?? base?.wrapText ?? false,
|
|
2101
2116
|
...(column.alignment ? { alignment: column.alignment } : base?.alignment ? { alignment: base.alignment } : {}),
|
|
2102
2117
|
...(base?.verticalAlignment ? { verticalAlignment: base.verticalAlignment } : {}),
|
|
2103
|
-
...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {})
|
|
2118
|
+
...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {}), ...(border ? { border } : {})
|
|
2104
2119
|
});
|
|
2105
2120
|
}
|
|
2106
2121
|
toXml() {
|
|
@@ -2125,7 +2140,7 @@ class StyleRegistry {
|
|
|
2125
2140
|
}).join("") + '</cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>' + this.differential.toXml() + '</styleSheet>';
|
|
2126
2141
|
}
|
|
2127
2142
|
}
|
|
2128
|
-
const _exports = Object.freeze({ colorArgb: _m25.colorArgb, spreadsheetNamespace: spreadsheetNamespace, NumberFormats: NumberFormats, validateStylePatch: validateStylePatch, copyStylePatch: copyStylePatch, StyleRegistry: StyleRegistry });
|
|
2143
|
+
const _exports = Object.freeze({ colorArgb: _m25.colorArgb, spreadsheetNamespace: spreadsheetNamespace, normalizeBorder: normalizeBorder, NumberFormats: NumberFormats, validateStylePatch: validateStylePatch, copyStylePatch: copyStylePatch, StyleRegistry: StyleRegistry });
|
|
2129
2144
|
return _exports;
|
|
2130
2145
|
})();
|
|
2131
2146
|
|
|
@@ -3339,7 +3354,7 @@ const { ChunkedTextSink, BlobByteSink } = _m3;
|
|
|
3339
3354
|
|
|
3340
3355
|
const { OfficeIMOError } = _m2;
|
|
3341
3356
|
|
|
3342
|
-
const { notifyProgress } = _m23;
|
|
3357
|
+
const { notifyProgress, notifySynchronously } = _m23;
|
|
3343
3358
|
|
|
3344
3359
|
const { copyColumns, createRowProjector } = _m11;
|
|
3345
3360
|
|
|
@@ -3411,8 +3426,14 @@ class Worksheet {
|
|
|
3411
3426
|
pendingCharacters = 0;
|
|
3412
3427
|
reservedLayout = false;
|
|
3413
3428
|
internalLinks = [];
|
|
3429
|
+
// Evicted entries become holes and are compacted in one pass when the links are read, keeping eviction O(1).
|
|
3414
3430
|
links = [];
|
|
3431
|
+
evictedLinks = 0;
|
|
3415
3432
|
linkedCells = new Set();
|
|
3433
|
+
/** Indexes in `links` of data-cell links that `hyperlinkOverflow: "drop"` may give up, in row order. */
|
|
3434
|
+
droppable = [];
|
|
3435
|
+
droppableLinks = new WeakSet();
|
|
3436
|
+
droppedLinks = 0;
|
|
3416
3437
|
pictures = [];
|
|
3417
3438
|
nativeCharts = [];
|
|
3418
3439
|
conditional;
|
|
@@ -3443,8 +3464,9 @@ class Worksheet {
|
|
|
3443
3464
|
book.checkLinks(this.links.length);
|
|
3444
3465
|
this.declared = this.columns.map((column, i) => ({ column, letter: columnName(i + 1),
|
|
3445
3466
|
style: book.styles.forColumn(column), dateStyle: book.styles.forColumn(column, false, undefined, true),
|
|
3446
|
-
headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header,
|
|
3447
|
-
...(column.
|
|
3467
|
+
headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header,
|
|
3468
|
+
...((options.headerWrap ?? column.wrapText) === undefined ? {} : { wrapText: options.headerWrap ?? column.wrapText }),
|
|
3469
|
+
...(column.alignment === undefined ? {} : { alignment: column.alignment }) }, options.boldHeader !== false, options.headerFill, false, options.headerBorder) : 0
|
|
3448
3470
|
}));
|
|
3449
3471
|
// Register conditional styles only after worksheet construction can no longer reject its options.
|
|
3450
3472
|
this.conditional = new ConditionalFormats(conditional, book.styles);
|
|
@@ -3496,6 +3518,8 @@ class Worksheet {
|
|
|
3496
3518
|
throw new TypeError("A frozen header or autofilter requires a header row.");
|
|
3497
3519
|
if (options.headerFill !== undefined)
|
|
3498
3520
|
colorArgb(options.headerFill);
|
|
3521
|
+
if (options.headerWrap !== undefined && typeof options.headerWrap !== "boolean")
|
|
3522
|
+
throw new TypeError("headerWrap must be boolean.");
|
|
3499
3523
|
if (options.headerStyle !== undefined)
|
|
3500
3524
|
book.styles.validateStyle(options.headerStyle);
|
|
3501
3525
|
if (options.alternatingRowStyle !== undefined)
|
|
@@ -3621,7 +3645,8 @@ class Worksheet {
|
|
|
3621
3645
|
const cell = col.letter + row;
|
|
3622
3646
|
if (link || this.linkedCells.has(cell))
|
|
3623
3647
|
throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
|
|
3624
|
-
|
|
3648
|
+
this.makeLinkRoom();
|
|
3649
|
+
checkHyperlinkCount(this.linkCount + 1);
|
|
3625
3650
|
this.book.checkLinks(1);
|
|
3626
3651
|
// Replace a generated cell's original reservation with its preview and overflow records.
|
|
3627
3652
|
if (reservedCharacters !== undefined) {
|
|
@@ -3635,7 +3660,7 @@ class Worksheet {
|
|
|
3635
3660
|
value = preserved.preview;
|
|
3636
3661
|
}
|
|
3637
3662
|
if (link)
|
|
3638
|
-
this.appendHyperlink({ cell: col.letter + row, ...link });
|
|
3663
|
+
this.appendHyperlink({ cell: col.letter + row, ...link }, !header && !footer && !title && this.book.settings.hyperlinkOverflow === "drop");
|
|
3639
3664
|
if (type === "date")
|
|
3640
3665
|
value = excelDate(value, this.book.settings.dateMode);
|
|
3641
3666
|
if (!header && !footer && visible && (!formula || !isSubtotalFormula(formula)))
|
|
@@ -3944,20 +3969,61 @@ class Worksheet {
|
|
|
3944
3969
|
throw this.error;
|
|
3945
3970
|
this.appendHyperlink(link);
|
|
3946
3971
|
}
|
|
3947
|
-
appendHyperlink(link) {
|
|
3972
|
+
appendHyperlink(link, droppable = false) {
|
|
3973
|
+
// Validate before any overflow decision, so a dropped link can never hide an unsafe target.
|
|
3948
3974
|
const copied = copyHyperlink(link, this.book.settings.invalidCharacterPolicy);
|
|
3949
3975
|
const position = cellPosition(copied.cell);
|
|
3950
3976
|
if (this.layout.regions.covered(position.column, position.row))
|
|
3951
3977
|
throw new TypeError("Hyperlinks cannot address a covered merged cell.");
|
|
3952
3978
|
if (this.linkedCells.has(copied.cell))
|
|
3953
3979
|
throw new TypeError("Duplicate hyperlink cell: " + copied.cell);
|
|
3954
|
-
|
|
3980
|
+
if (droppable && this.linkCount >= maximumHyperlinks) {
|
|
3981
|
+
this.droppedLinks++;
|
|
3982
|
+
return;
|
|
3983
|
+
}
|
|
3984
|
+
if (!droppable)
|
|
3985
|
+
this.makeLinkRoom();
|
|
3986
|
+
checkHyperlinkCount(this.linkCount + 1);
|
|
3955
3987
|
this.book.retainLink();
|
|
3988
|
+
if (droppable) {
|
|
3989
|
+
this.droppable.push(this.links.length);
|
|
3990
|
+
this.droppableLinks.add(copied);
|
|
3991
|
+
}
|
|
3956
3992
|
this.links.push(copied);
|
|
3957
3993
|
this.linkedCells.add(copied.cell);
|
|
3958
3994
|
}
|
|
3995
|
+
/** Links the worksheet holds now, not counting evicted holes. */
|
|
3996
|
+
get linkCount() { return this.links.length - this.evictedLinks + this.internalLinks.length; }
|
|
3997
|
+
/** A full worksheet gives up its latest data-cell link for a link that cannot be dropped. Hyperlinks are serialized after
|
|
3998
|
+
* the rows, so the cell keeps its written value. The entry becomes a hole, so other indexes stay valid until compaction. */
|
|
3999
|
+
makeLinkRoom() {
|
|
4000
|
+
if (this.linkCount < maximumHyperlinks || !this.droppable.length)
|
|
4001
|
+
return;
|
|
4002
|
+
const index = this.droppable.pop(), removed = this.links[index];
|
|
4003
|
+
this.links[index] = undefined;
|
|
4004
|
+
this.evictedLinks++;
|
|
4005
|
+
this.linkedCells.delete(removed.cell);
|
|
4006
|
+
this.book.releaseLink();
|
|
4007
|
+
this.droppedLinks++;
|
|
4008
|
+
}
|
|
4009
|
+
/** One ordered pass removes evicted holes and rebuilds the droppable indexes. */
|
|
4010
|
+
compactLinks() {
|
|
4011
|
+
if (this.evictedLinks) {
|
|
4012
|
+
const kept = [], droppable = [];
|
|
4013
|
+
for (const link of this.links)
|
|
4014
|
+
if (link) {
|
|
4015
|
+
if (this.droppableLinks.has(link))
|
|
4016
|
+
droppable.push(kept.length);
|
|
4017
|
+
kept.push(link);
|
|
4018
|
+
}
|
|
4019
|
+
this.links = kept;
|
|
4020
|
+
this.droppable = droppable;
|
|
4021
|
+
this.evictedLinks = 0;
|
|
4022
|
+
}
|
|
4023
|
+
return this.links;
|
|
4024
|
+
}
|
|
3959
4025
|
/** @internal */
|
|
3960
|
-
get hyperlinks() { return this.
|
|
4026
|
+
get hyperlinks() { return this.compactLinks(); }
|
|
3961
4027
|
/** @internal */
|
|
3962
4028
|
get images() { return this.pictures; }
|
|
3963
4029
|
/** @internal An empty export has no data table; it still emits the declared headers. */
|
|
@@ -4008,7 +4074,7 @@ class Worksheet {
|
|
|
4008
4074
|
for (const binding of this.chartSources)
|
|
4009
4075
|
binding.finish();
|
|
4010
4076
|
this.chartSources.length = 0;
|
|
4011
|
-
for (const link of this.
|
|
4077
|
+
for (const link of this.compactLinks()) {
|
|
4012
4078
|
const position = cellPosition(link.cell);
|
|
4013
4079
|
if (position.column > this.columns.length || position.row > this.totalRows)
|
|
4014
4080
|
throw new RangeError("Hyperlinks must address cells within the exported rows and columns.");
|
|
@@ -4038,8 +4104,11 @@ class Worksheet {
|
|
|
4038
4104
|
await this.buffer.write(xml);
|
|
4039
4105
|
for (const xml of dataValidationsXml(this.validations, this.headerRows, this.count, detailRanges))
|
|
4040
4106
|
await this.buffer.write(xml);
|
|
4041
|
-
if (this.
|
|
4042
|
-
|
|
4107
|
+
if (this.droppedLinks)
|
|
4108
|
+
notifySynchronously("onHyperlinkOverflow", this.book.settings.onHyperlinkOverflow, Object.freeze({ sheetName: this.name, dropped: this.droppedLinks }));
|
|
4109
|
+
const links = this.compactLinks();
|
|
4110
|
+
if (links.length || this.internalLinks.length)
|
|
4111
|
+
await this.buffer.write(hyperlinksXml(links, this.book.settings.invalidCharacterPolicy, this.internalLinks));
|
|
4043
4112
|
await this.buffer.write(printXml(this.options.print, this.book.settings.invalidCharacterPolicy));
|
|
4044
4113
|
if (this.pictures.length || this.nativeCharts.length)
|
|
4045
4114
|
await this.buffer.write('<drawing r:id="drawing"/>');
|
|
@@ -4184,9 +4253,9 @@ const _m43 = (() => {
|
|
|
4184
4253
|
const { captureFields } = _m10;
|
|
4185
4254
|
|
|
4186
4255
|
/** @internal The workbook owner captures these settings before validation or adapter merging. */
|
|
4187
|
-
const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "creator", "title", "subject", "description", "created", "modified"];
|
|
4256
|
+
const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "hyperlinkOverflow", "onHyperlinkOverflow", "creator", "title", "subject", "description", "created", "modified"];
|
|
4188
4257
|
/** @internal Worksheet settings also used by the portable sheet owner. */
|
|
4189
|
-
const sheetOptionFields = ["columns", "includeHeader", "headerRows", "freezeHeader", "autoFilter", "boldHeader", "headerFill", "headerStyle", "alternatingRowStyle", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel", "outlineSummaryBelow", "outlineSummaryRight", "columnOutlines", "rowHeight", "headerHeight", "defaultColumnWidth", "freezeColumns", "table", "autoSize", "footer", "print", "title", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation"];
|
|
4258
|
+
const sheetOptionFields = ["columns", "includeHeader", "headerRows", "freezeHeader", "autoFilter", "boldHeader", "headerFill", "headerBorder", "headerWrap", "headerStyle", "alternatingRowStyle", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel", "outlineSummaryBelow", "outlineSummaryRight", "columnOutlines", "rowHeight", "headerHeight", "defaultColumnWidth", "freezeColumns", "table", "autoSize", "footer", "print", "title", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation"];
|
|
4190
4259
|
/** @internal Includes inherited format-specific ceilings before a wrapper combines stream settings. */
|
|
4191
4260
|
const workbookLimitFields = ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes", "maxStyles", "maxSheets", "maxOverflowCharacters", "maxHyperlinks", "maxImageBytes", "maxBufferedCells", "maxBufferedCharacters", "maxMergedRanges", "maxConditionalFormats", "maxDifferentialStyles", "maxCharts", "maxChartPoints", "maxChartTextCharacters", "maxFormulaCharacters", "maxDataValidations", "maxValidationTextCharacters"];
|
|
4192
4261
|
/** @internal Capture the workbook's known ceilings without dropping supported prototype fields. */
|
|
@@ -4518,7 +4587,7 @@ const { OpcPackage, officeRelationshipsNamespace, relationshipTypes, corePropert
|
|
|
4518
4587
|
|
|
4519
4588
|
const { escapeOoxmlAttribute, cleanXml, xmlDeclaration } = _m17;
|
|
4520
4589
|
|
|
4521
|
-
const { StyleRegistry, spreadsheetNamespace } = _m24;
|
|
4590
|
+
const { StyleRegistry, spreadsheetNamespace, normalizeBorder } = _m24;
|
|
4522
4591
|
|
|
4523
4592
|
const { sheetName, assertXlsxValue, copyValue } = _m27;
|
|
4524
4593
|
|
|
@@ -4559,6 +4628,8 @@ function captureSheet(options, policy) {
|
|
|
4559
4628
|
return { ...captured, columns,
|
|
4560
4629
|
...(captured.columnOutlines === undefined ? {} : { columnOutlines: captureColumnOutlines(captured.columnOutlines, columns.length) }),
|
|
4561
4630
|
...(captured.headerRows === undefined ? {} : { headerRows: captureTableSpans(captured.headerRows, columns.length) }),
|
|
4631
|
+
// Preflight and every header style read this one snapshot of the edges.
|
|
4632
|
+
...(captured.headerBorder === undefined ? {} : { headerBorder: normalizeBorder(captured.headerBorder) }),
|
|
4562
4633
|
...(footer ? { footer: { ...footer,
|
|
4563
4634
|
...(footer.rows === undefined ? {} : { rows: captureTableSpans(footer.rows, columns.length) }),
|
|
4564
4635
|
...(footer.values === undefined ? {} : { values: footer.values.map(copyValue) }) } } : {}),
|
|
@@ -4634,6 +4705,10 @@ class Workbook {
|
|
|
4634
4705
|
throw new RangeError("compression must be auto or store.");
|
|
4635
4706
|
if (options.oversizedText !== undefined && !["reject", "preserve"].includes(options.oversizedText))
|
|
4636
4707
|
throw new RangeError("oversizedText must be reject or preserve.");
|
|
4708
|
+
if (options.hyperlinkOverflow !== undefined && !["reject", "drop"].includes(options.hyperlinkOverflow))
|
|
4709
|
+
throw new RangeError("hyperlinkOverflow must be reject or drop.");
|
|
4710
|
+
if (options.onHyperlinkOverflow !== undefined && typeof options.onHyperlinkOverflow !== "function")
|
|
4711
|
+
throw new TypeError("onHyperlinkOverflow must be a function.");
|
|
4637
4712
|
cleanXml("", policy);
|
|
4638
4713
|
corePropertiesXml(options, policy);
|
|
4639
4714
|
this.budget = new ExportBudget(options.limits);
|
|
@@ -4711,6 +4786,8 @@ class Workbook {
|
|
|
4711
4786
|
}
|
|
4712
4787
|
/** @internal Reserve a preflighted worksheet batch or one row hyperlink. */
|
|
4713
4788
|
retainLink(count = 1) { this.checkLinks(count); this.links += count; }
|
|
4789
|
+
/** @internal A worksheet dropped a data-cell link it had retained. */
|
|
4790
|
+
releaseLink() { this.links--; }
|
|
4714
4791
|
/** @internal */
|
|
4715
4792
|
checkImage(bytes) {
|
|
4716
4793
|
if (this.settings.limits?.maxImageBytes !== undefined && this.imageBytes + bytes > this.settings.limits.maxImageBytes)
|
|
@@ -5009,7 +5086,7 @@ function value(result) {
|
|
|
5009
5086
|
function portableSheet(options = {}) {
|
|
5010
5087
|
options = captureFields(options, sheetOptionFields);
|
|
5011
5088
|
if (options.headerStyle !== undefined)
|
|
5012
|
-
throw new TypeError("Workbook-local header styles require the advanced Workbook API; use boldHeader and
|
|
5089
|
+
throw new TypeError("Workbook-local header styles require the advanced Workbook API; use boldHeader, headerFill, headerBorder and headerWrap.");
|
|
5013
5090
|
style(options.alternatingRowStyle);
|
|
5014
5091
|
style(options.title?.style);
|
|
5015
5092
|
style(options.footer?.style);
|
|
@@ -5711,12 +5788,16 @@ const sizes = {
|
|
|
5711
5788
|
};
|
|
5712
5789
|
/** @internal Shared capture schema for thin format adapters and the grouped writer. */
|
|
5713
5790
|
const pdfOptionFields = ["columns", "signal", "onProgress", "limits", "textShaper", "textDirection", "pageSize", "orientation", "margins", "fonts", "tagged", "fontSize",
|
|
5714
|
-
"title", "messageTop", "messageBottom", "includeHeader", "headerRows", "footer", "headerPresentation", "footerPresentation", "alternateRowColor", "padding",
|
|
5791
|
+
"title", "metadataTitle", "messageTop", "messageBottom", "includeHeader", "headerRows", "footer", "headerPresentation", "footerPresentation", "alternateRowColor", "padding",
|
|
5715
5792
|
"columnWidths", "wideTable", "pageHeader", "pageFooter", "pageNumbers", "pageNumberLabels", "booleanText", "formatValue", "formatRuns", "compression", "paragraphStyles"];
|
|
5716
5793
|
/** @internal Complete PDF limit schema used when a host combines format and shared limits. */
|
|
5717
5794
|
const pdfLimitFields = ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes", "maxPages", "maxColumns", "maxTableBands", "maxTableWindowRows", "maxCellCharacters", "maxTextRuns", "maxGroupBlocks", "maxRowLines",
|
|
5718
5795
|
"maxFontBytes", "maxPageBytes", "maxHyperlinks", "maxImageBytes", "maxImagePixels", "maxImageWorkingBytes", "maxVectorCommands", "maxDrawingElements", "maxStructureElements",
|
|
5719
5796
|
"maxMarkedContentReferences", "maxSections", "maxBookmarks", "maxListItems", "maxParagraphStyles"];
|
|
5797
|
+
/** @internal Default ceilings shared by the drawing writer and its producers. */
|
|
5798
|
+
const pdfDrawingLimits = Object.freeze({ maxVectorCommands: 100000, maxDrawingElements: 100000 });
|
|
5799
|
+
/** @internal Maximum number of retained drawing levels including the leaf. */
|
|
5800
|
+
const pdfDrawingMaxDepth = 32;
|
|
5720
5801
|
/** @internal Capture supported structural properties once, including class-based options with prototype accessors. */
|
|
5721
5802
|
function capturePdfOptions(input) {
|
|
5722
5803
|
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
@@ -5827,7 +5908,7 @@ function settings(input, document = false) {
|
|
|
5827
5908
|
footerPresentation: Object.freeze({ background: "eef2f6", bold: true, ...presentation(configuration.footerPresentation) }) };
|
|
5828
5909
|
const budget = new ExportBudget(options.limits);
|
|
5829
5910
|
const limits = { maxPages: 10000, maxColumns: 1024, maxTableBands: 64, maxTableWindowRows: 256, maxCellCharacters: 1000000, maxTextRuns: 10000, maxGroupBlocks: 256, maxRowLines: 100000, maxFontBytes: 16 * 1024 * 1024, maxPageBytes: 8 * 1024 * 1024, maxHyperlinks: 100000,
|
|
5830
|
-
maxImageBytes: 32 * 1024 * 1024, maxImagePixels: 16 * 1024 * 1024,
|
|
5911
|
+
maxImageBytes: 32 * 1024 * 1024, maxImagePixels: 16 * 1024 * 1024, ...pdfDrawingLimits,
|
|
5831
5912
|
maxStructureElements: 1000000, maxMarkedContentReferences: 2000000,
|
|
5832
5913
|
maxListItems: 100000, maxParagraphStyles: 256, maxSections: 1000, maxBookmarks: 10000 };
|
|
5833
5914
|
for (const key of Object.keys(limits)) {
|
|
@@ -5855,7 +5936,7 @@ function settings(input, document = false) {
|
|
|
5855
5936
|
const fontSize = positive(options.fontSize ?? 9, "Font size", 144), padding = options.padding ?? 4;
|
|
5856
5937
|
if (!Number.isFinite(padding) || padding < 0 || padding > 72)
|
|
5857
5938
|
throw new RangeError("PDF padding must be from 0 through 72 points.");
|
|
5858
|
-
for (const key of ["title", "messageTop", "messageBottom"])
|
|
5939
|
+
for (const key of ["title", "metadataTitle", "messageTop", "messageBottom"])
|
|
5859
5940
|
if (options[key] !== undefined && typeof options[key] !== "string")
|
|
5860
5941
|
throw new TypeError(key + " must be text.");
|
|
5861
5942
|
for (const key of ["pageHeader", "pageFooter"])
|
|
@@ -5891,7 +5972,7 @@ function settings(input, document = false) {
|
|
|
5891
5972
|
repeatedColumns: document ? Object.freeze([]) : repeatedColumns(options.wideTable, columns),
|
|
5892
5973
|
limits: { ...limits, ...(maxImageWorkingBytes === undefined ? {} : { maxImageWorkingBytes }) }, budget };
|
|
5893
5974
|
}
|
|
5894
|
-
const _exports = Object.freeze({ positive: _m58.positive, color: _m58.color, presentation: _m58.presentation, pdfOptionFields: pdfOptionFields, pdfLimitFields: pdfLimitFields, capturePdfOptions: capturePdfOptions, capturePdfLimits: capturePdfLimits, captureWideTable: captureWideTable, settings: settings });
|
|
5975
|
+
const _exports = Object.freeze({ positive: _m58.positive, color: _m58.color, presentation: _m58.presentation, pdfOptionFields: pdfOptionFields, pdfLimitFields: pdfLimitFields, pdfDrawingLimits: pdfDrawingLimits, pdfDrawingMaxDepth: pdfDrawingMaxDepth, capturePdfOptions: capturePdfOptions, capturePdfLimits: capturePdfLimits, captureWideTable: captureWideTable, settings: settings });
|
|
5895
5976
|
return _exports;
|
|
5896
5977
|
})();
|
|
5897
5978
|
|
|
@@ -7409,7 +7490,7 @@ class PdfFontResources {
|
|
|
7409
7490
|
this.fontBytes += bytes;
|
|
7410
7491
|
this.registered.add(font);
|
|
7411
7492
|
}
|
|
7412
|
-
select(bold = false, italic = false, explicit) {
|
|
7493
|
+
select(bold = false, italic = false, explicit, standardForMissingFace = false) {
|
|
7413
7494
|
if (explicit)
|
|
7414
7495
|
this.registerFont(explicit);
|
|
7415
7496
|
let selections = this.selections;
|
|
@@ -7419,10 +7500,13 @@ class PdfFontResources {
|
|
|
7419
7500
|
if (!found)
|
|
7420
7501
|
this.explicitSelections.set(explicit, selections);
|
|
7421
7502
|
}
|
|
7422
|
-
const
|
|
7503
|
+
const fallback = standardForMissingFace && !explicit && this.fonts !== undefined &&
|
|
7504
|
+
this.fonts[bold ? italic ? "boldItalic" : "bold" : italic ? "italic" : "regular"] === undefined;
|
|
7505
|
+
const key = (bold ? 2 : 0) | (italic ? 1 : 0) | (fallback ? 4 : 0), existing = selections.get(key);
|
|
7423
7506
|
if (existing)
|
|
7424
7507
|
return existing;
|
|
7425
|
-
const { font, syntheticBold, syntheticItalic } = explicit ? { font: explicit, syntheticBold: bold, syntheticItalic: italic } :
|
|
7508
|
+
const { font, syntheticBold, syntheticItalic } = explicit ? { font: explicit, syntheticBold: bold, syntheticItalic: italic } :
|
|
7509
|
+
selectFont(fallback ? undefined : this.fonts, bold, italic);
|
|
7426
7510
|
const shared = font ? this.programs.get(font) : undefined;
|
|
7427
7511
|
const resource = new PdfFontResource(this.resources.length + 1, bold, italic, font, this.objects, syntheticBold, syntheticItalic, shared, this.signal);
|
|
7428
7512
|
if (!shared) {
|
|
@@ -8716,6 +8800,7 @@ class PdfPages {
|
|
|
8716
8800
|
rectangleLefts;
|
|
8717
8801
|
rectangleColumns = [];
|
|
8718
8802
|
externalObjects = new Map();
|
|
8803
|
+
opacityStates = new Map();
|
|
8719
8804
|
bandFlow;
|
|
8720
8805
|
bandCellBudget = false;
|
|
8721
8806
|
tableElement;
|
|
@@ -9298,6 +9383,20 @@ class PdfPages {
|
|
|
9298
9383
|
}
|
|
9299
9384
|
async pageBreak() { await this.ensureStarted(); await this.finishPage(); await this.start(false); }
|
|
9300
9385
|
registerXObject(name, id) { this.externalObjects.set(name, id); }
|
|
9386
|
+
/** One shared constant-opacity graphics state per serialized alpha value. */
|
|
9387
|
+
opacityState(alpha) {
|
|
9388
|
+
const value = pdfNumber(alpha);
|
|
9389
|
+
let name = this.opacityStates.get(value);
|
|
9390
|
+
if (!name) {
|
|
9391
|
+
name = "GA" + (this.opacityStates.size + 1);
|
|
9392
|
+
this.opacityStates.set(value, name);
|
|
9393
|
+
}
|
|
9394
|
+
return name;
|
|
9395
|
+
}
|
|
9396
|
+
graphicsStates() {
|
|
9397
|
+
const entries = [...this.opacityStates].map(([alpha, name]) => "/" + name + " << /ca " + alpha + " /CA " + alpha + " >>");
|
|
9398
|
+
return entries.length ? " /ExtGState << " + entries.join(" ") + " >>" : "";
|
|
9399
|
+
}
|
|
9301
9400
|
/** Height after the existing fit-to-page graphic policy, used by heading keep constraints. */
|
|
9302
9401
|
graphicHeight(width, height) {
|
|
9303
9402
|
const { page, margins } = this.settings;
|
|
@@ -9884,13 +9983,14 @@ class PdfWriteSession {
|
|
|
9884
9983
|
await pages.finish();
|
|
9885
9984
|
for (const font of fonts.resources)
|
|
9886
9985
|
await font.write(objects, options.compression !== false);
|
|
9887
|
-
await objects.object(this.resources, "<< /Font " + fonts.dictionary() + pages.xobjects() + " >>");
|
|
9986
|
+
await objects.object(this.resources, "<< /Font " + fonts.dictionary() + pages.xobjects() + pages.graphicsStates() + " >>");
|
|
9888
9987
|
await objects.object(this.parent, "<< /Type /Pages /Count " + pages.references.length + " /Kids [" + pages.references.map(id => id + " 0 R").join(" ") + "] >>");
|
|
9889
9988
|
if (this.structure)
|
|
9890
9989
|
await this.structure.finish();
|
|
9891
9990
|
await this.outlines.finish();
|
|
9892
9991
|
await objects.object(this.root, "<< /Type /Catalog /Pages " + this.parent + " 0 R" + (this.structure?.catalogDictionary ?? "") + this.outlines.catalogDictionary + " >>");
|
|
9893
|
-
|
|
9992
|
+
const title = options.metadataTitle ?? options.title;
|
|
9993
|
+
await objects.object(this.info, "<< /Producer (OfficeIMO.js)" + (title === undefined ? "" : " /Title <feff" + unicodeHex(title) + ">") + " >>");
|
|
9894
9994
|
await objects.finish(this.root, this.info);
|
|
9895
9995
|
}
|
|
9896
9996
|
}
|
|
@@ -9975,15 +10075,10 @@ const { Crc32 } = _m16;
|
|
|
9975
10075
|
|
|
9976
10076
|
const signature = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
9977
10077
|
const unsupportedChunks = new Set(["PLTE", "tRNS", "iCCP", "sRGB", "gAMA", "cHRM", "cICP", "mDCV", "cLLI", "sBIT", "eXIf", "acTL", "fcTL", "fdAT"]);
|
|
9978
|
-
/** Decode
|
|
9979
|
-
async function pngPixels(
|
|
10078
|
+
/** Decode an owned static unprofiled PNG without canvas or a second compression engine. */
|
|
10079
|
+
async function pngPixels(source, shape, signal) {
|
|
9980
10080
|
checkAbort(signal);
|
|
9981
|
-
const shape = pngShape(inputSource, maxPixels);
|
|
9982
10081
|
const imagePixels = shape.width * shape.height;
|
|
9983
|
-
const workingBytes = inputSource.length + imagePixels * shape.components + (shape.components === 4 ? shape.width * 8 : 0);
|
|
9984
|
-
if (maxWorkingBytes !== undefined && workingBytes > maxWorkingBytes)
|
|
9985
|
-
throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageWorkingBytes exceeded by PNG source, image planes and scanlines.");
|
|
9986
|
-
const source = new Uint8Array(inputSource);
|
|
9987
10082
|
const header = await pngHeader(source, shape, signal);
|
|
9988
10083
|
checkAbort(signal);
|
|
9989
10084
|
let stream;
|
|
@@ -9997,9 +10092,6 @@ async function pngPixels(inputSource, maxPixels, signal, maxWorkingBytes) {
|
|
|
9997
10092
|
}
|
|
9998
10093
|
const { width, height, components } = header, rowBytes = width * components;
|
|
9999
10094
|
const expected = (rowBytes + 1) * height;
|
|
10000
|
-
// All dimensions and the exact filtered length are bounded before allocating decoded pixels.
|
|
10001
|
-
if (!Number.isSafeInteger(expected) || expected > 0x7fffffff)
|
|
10002
|
-
throw new OfficeIMOError("RESOURCE_LIMIT", "PNG filtered data exceeds the supported decoded byte length.");
|
|
10003
10095
|
// RGBA is reconstructed one scanline at a time directly into PDF RGB/alpha planes.
|
|
10004
10096
|
// It never retains an additional full interleaved RGBA image.
|
|
10005
10097
|
const pixels = new Uint8Array(width * height * 3), alpha = components === 4 ? new Uint8Array(imagePixels) : undefined;
|
|
@@ -10147,20 +10239,55 @@ async function verifyPngZlibEnd(source, header, expected, signal) {
|
|
|
10147
10239
|
reader.releaseLock();
|
|
10148
10240
|
}
|
|
10149
10241
|
}
|
|
10242
|
+
function pngChunk(source, view, offset) {
|
|
10243
|
+
if (offset + 12 > source.length)
|
|
10244
|
+
throw new TypeError("Truncated PNG chunk.");
|
|
10245
|
+
const length = view.getUint32(offset), end = offset + 12 + length;
|
|
10246
|
+
if (length > 0x7fffffff || end > source.length)
|
|
10247
|
+
throw new TypeError("Truncated or oversized PNG chunk.");
|
|
10248
|
+
const type = String.fromCharCode(...source.subarray(offset + 4, offset + 8));
|
|
10249
|
+
if (!/^[A-Za-z]{2}[A-Z][A-Za-z]$/.test(type))
|
|
10250
|
+
throw new TypeError("Invalid PNG chunk type.");
|
|
10251
|
+
return { length, end, type };
|
|
10252
|
+
}
|
|
10253
|
+
function checkAncillaryChunk(type) {
|
|
10254
|
+
if (unsupportedChunks.has(type))
|
|
10255
|
+
throw new NotSupportedError("PNG chunk " + type + "; normalize color, orientation, transparency or animation first");
|
|
10256
|
+
if (type.charCodeAt(0) < 97)
|
|
10257
|
+
throw new NotSupportedError("Required PNG chunk " + type);
|
|
10258
|
+
}
|
|
10259
|
+
/** Check the image profile for SVG placement without inflating pixels. Embedding still verifies CRCs and image data. */
|
|
10260
|
+
function pngEmbeddableSize(source) {
|
|
10261
|
+
const shape = pngShape(source, Infinity);
|
|
10262
|
+
const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
10263
|
+
let hasData = false, dataClosed = false;
|
|
10264
|
+
for (let offset = 33; offset < source.length;) {
|
|
10265
|
+
const { length, end, type } = pngChunk(source, view, offset);
|
|
10266
|
+
if (type === "IEND") {
|
|
10267
|
+
if (length === 0 && hasData && end === source.length)
|
|
10268
|
+
return shape;
|
|
10269
|
+
break;
|
|
10270
|
+
}
|
|
10271
|
+
if (type === "IDAT") {
|
|
10272
|
+
if (dataClosed)
|
|
10273
|
+
throw new TypeError("PNG IDAT chunks must be consecutive.");
|
|
10274
|
+
hasData = true;
|
|
10275
|
+
}
|
|
10276
|
+
else {
|
|
10277
|
+
checkAncillaryChunk(type);
|
|
10278
|
+
dataClosed ||= hasData;
|
|
10279
|
+
}
|
|
10280
|
+
offset = end;
|
|
10281
|
+
}
|
|
10282
|
+
throw new TypeError("PNG requires a final empty IEND after IDAT.");
|
|
10283
|
+
}
|
|
10150
10284
|
/** Verify the complete source and critical chunk order before any decompressed image allocation. */
|
|
10151
10285
|
async function pngHeader(source, shape, signal) {
|
|
10152
10286
|
const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
10153
10287
|
let firstData = 0, dataEnd = 0, lastDataByte = -1, dataClosed = false;
|
|
10154
10288
|
for (let offset = 8; offset < source.length;) {
|
|
10155
10289
|
checkAbort(signal);
|
|
10156
|
-
|
|
10157
|
-
throw new TypeError("Truncated PNG chunk.");
|
|
10158
|
-
const length = view.getUint32(offset), end = offset + 12 + length;
|
|
10159
|
-
if (length > 0x7fffffff || end > source.length)
|
|
10160
|
-
throw new TypeError("Truncated or oversized PNG chunk.");
|
|
10161
|
-
const type = String.fromCharCode(...source.subarray(offset + 4, offset + 8));
|
|
10162
|
-
if (!/^[A-Za-z]{2}[A-Z][A-Za-z]$/.test(type))
|
|
10163
|
-
throw new TypeError("Invalid PNG chunk type.");
|
|
10290
|
+
const { length, end, type } = pngChunk(source, view, offset);
|
|
10164
10291
|
const crc = new Crc32();
|
|
10165
10292
|
for (let p = offset + 4; p < end - 4; p += 65536) {
|
|
10166
10293
|
crc.update(source.subarray(p, Math.min(end - 4, p + 65536)));
|
|
@@ -10192,17 +10319,14 @@ async function pngHeader(source, shape, signal) {
|
|
|
10192
10319
|
throw new TypeError("PNG requires a final empty IEND after IDAT.");
|
|
10193
10320
|
return { ...shape, firstData, dataEnd, lastDataByte };
|
|
10194
10321
|
}
|
|
10195
|
-
|
|
10196
|
-
throw new NotSupportedError("PNG chunk " + type + "; normalize color, orientation, transparency or animation first");
|
|
10197
|
-
if ((source[offset + 4] & 32) === 0)
|
|
10198
|
-
throw new NotSupportedError("Required PNG chunk " + type);
|
|
10322
|
+
checkAncillaryChunk(type);
|
|
10199
10323
|
}
|
|
10200
10324
|
offset = end;
|
|
10201
10325
|
}
|
|
10202
10326
|
throw new TypeError("PNG requires a complete final IEND chunk.");
|
|
10203
10327
|
}
|
|
10204
10328
|
/** Check source metadata synchronously, before capturing source bytes or allocating any image plane. */
|
|
10205
|
-
function pngShape(source, maxPixels) {
|
|
10329
|
+
function pngShape(source, maxPixels, maxWorkingBytes) {
|
|
10206
10330
|
if (source.length < 33 || signature.some((value, index) => source[index] !== value))
|
|
10207
10331
|
throw new TypeError("Invalid PNG signature or truncated IHDR.");
|
|
10208
10332
|
const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
@@ -10222,6 +10346,9 @@ function pngShape(source, maxPixels) {
|
|
|
10222
10346
|
const components = source[25] === 6 ? 4 : 3;
|
|
10223
10347
|
if (!Number.isSafeInteger((width * components + 1) * height) || (width * components + 1) * height > 0x7fffffff)
|
|
10224
10348
|
throw new OfficeIMOError("RESOURCE_LIMIT", "PNG filtered data exceeds the supported decoded byte length.");
|
|
10349
|
+
const workingBytes = source.length + width * height * components + (components === 4 ? width * 8 : 0);
|
|
10350
|
+
if (maxWorkingBytes !== undefined && workingBytes > maxWorkingBytes)
|
|
10351
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageWorkingBytes exceeded by PNG source, image planes and scanlines.");
|
|
10225
10352
|
return { width, height, components };
|
|
10226
10353
|
}
|
|
10227
10354
|
function paeth(left, up, upperLeft) {
|
|
@@ -10229,7 +10356,7 @@ function paeth(left, up, upperLeft) {
|
|
|
10229
10356
|
const a = Math.abs(prediction - left), b = Math.abs(prediction - up), c = Math.abs(prediction - upperLeft);
|
|
10230
10357
|
return a <= b && a <= c ? left : b <= c ? up : upperLeft;
|
|
10231
10358
|
}
|
|
10232
|
-
const _exports = Object.freeze({ pngPixels: pngPixels });
|
|
10359
|
+
const _exports = Object.freeze({ pngPixels: pngPixels, pngEmbeddableSize: pngEmbeddableSize, pngShape: pngShape });
|
|
10233
10360
|
return _exports;
|
|
10234
10361
|
})();
|
|
10235
10362
|
|
|
@@ -10238,54 +10365,83 @@ const { NotSupportedError, OfficeIMOError } = _m2;
|
|
|
10238
10365
|
|
|
10239
10366
|
const { checkAbort, pause, taskYieldDue } = _m4;
|
|
10240
10367
|
|
|
10241
|
-
const { pngPixels } = _m86;
|
|
10368
|
+
const { pngPixels, pngShape } = _m86;
|
|
10242
10369
|
|
|
10243
10370
|
/** Shared document image resources; source objects are captured on first consumption. */
|
|
10244
10371
|
class PdfDocumentImages {
|
|
10245
10372
|
objects;
|
|
10246
10373
|
settings;
|
|
10247
10374
|
images = new Map();
|
|
10375
|
+
snapshots = new WeakMap();
|
|
10248
10376
|
bytes = 0;
|
|
10377
|
+
pendingBytes = 0;
|
|
10249
10378
|
constructor(objects, settings) {
|
|
10250
10379
|
this.objects = objects;
|
|
10251
10380
|
this.settings = settings;
|
|
10252
10381
|
}
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
if (
|
|
10256
|
-
return
|
|
10382
|
+
/** Own a drawing image before preparing earlier elements can yield to the caller. */
|
|
10383
|
+
snapshot(image) {
|
|
10384
|
+
if (this.images.has(image) || this.snapshots.has(image))
|
|
10385
|
+
return;
|
|
10386
|
+
const captured = this.capture(image);
|
|
10387
|
+
this.snapshots.set(image, captured);
|
|
10388
|
+
this.pendingBytes += captured.data.length;
|
|
10389
|
+
}
|
|
10390
|
+
capture(image) {
|
|
10257
10391
|
const { limits, options } = this.settings;
|
|
10392
|
+
checkAbort(options.signal);
|
|
10258
10393
|
if (!image || typeof image !== "object")
|
|
10259
10394
|
throw new TypeError("PDF images require a byte array.");
|
|
10260
|
-
const
|
|
10395
|
+
const format = image.format;
|
|
10396
|
+
// Dimension getters may change a resizable backing buffer. Read them before measuring the byte view.
|
|
10397
|
+
const raw = format === "rgb" || format === "rgba" ? image : undefined;
|
|
10398
|
+
const widthValue = raw?.width, heightValue = raw?.height;
|
|
10399
|
+
const data = image.data;
|
|
10261
10400
|
if (!(data instanceof Uint8Array))
|
|
10262
10401
|
throw new TypeError("PDF images require a byte array.");
|
|
10263
10402
|
const byteLength = data.length;
|
|
10264
|
-
if (this.bytes + byteLength > limits.maxImageBytes)
|
|
10403
|
+
if (this.bytes + this.pendingBytes + byteLength > limits.maxImageBytes)
|
|
10265
10404
|
throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageBytes exceeded.");
|
|
10266
|
-
let width, height, components, decoded, decodedAlpha;
|
|
10267
10405
|
const maximumWorkingBytes = limits.maxImageWorkingBytes;
|
|
10268
|
-
if (format === "png")
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
|
|
10406
|
+
if (format === "png") {
|
|
10407
|
+
const shape = pngShape(data, limits.maxImagePixels, maximumWorkingBytes);
|
|
10408
|
+
return { format, shape, data: new Uint8Array(data) };
|
|
10409
|
+
}
|
|
10410
|
+
let shape;
|
|
10411
|
+
if (format === "jpeg")
|
|
10412
|
+
shape = jpegSize(data);
|
|
10272
10413
|
else if (format === "rgb" || format === "rgba") {
|
|
10273
|
-
|
|
10274
|
-
components = format === "rgba" ? 4 : 3;
|
|
10414
|
+
shape = { width: widthValue, height: heightValue, components: format === "rgba" ? 4 : 3 };
|
|
10275
10415
|
}
|
|
10276
10416
|
else
|
|
10277
10417
|
throw new NotSupportedError("PDF images support unprofiled PNG/JPEG or decoded RGB/RGBA pixels.");
|
|
10418
|
+
const { width, height, components } = shape;
|
|
10278
10419
|
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 1 || height < 1 ||
|
|
10279
10420
|
!Number.isSafeInteger(width * height) || width * height > limits.maxImagePixels)
|
|
10280
10421
|
throw new OfficeIMOError("RESOURCE_LIMIT", "Image dimensions must be positive integers within maxImagePixels.");
|
|
10281
|
-
if (
|
|
10422
|
+
if (format !== "jpeg" && byteLength !== width * height * components)
|
|
10282
10423
|
throw new RangeError("Raw image bytes must match width × height × channels exactly.");
|
|
10283
|
-
if (
|
|
10424
|
+
if (maximumWorkingBytes !== undefined && byteLength + (components === 4 ? width * height : 0) > maximumWorkingBytes)
|
|
10284
10425
|
throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageWorkingBytes exceeded by image snapshot and alpha plane.");
|
|
10426
|
+
return { format, shape, data: new Uint8Array(data) };
|
|
10427
|
+
}
|
|
10428
|
+
async prepare(image) {
|
|
10429
|
+
const existing = this.images.get(image);
|
|
10430
|
+
if (existing)
|
|
10431
|
+
return existing;
|
|
10432
|
+
const { options } = this.settings, snapshot = this.snapshots.get(image);
|
|
10433
|
+
const source = snapshot ?? this.capture(image);
|
|
10434
|
+
if (snapshot) {
|
|
10435
|
+
this.snapshots.delete(image);
|
|
10436
|
+
this.pendingBytes -= source.data.length;
|
|
10437
|
+
}
|
|
10438
|
+
this.bytes += source.data.length;
|
|
10439
|
+
const { format } = source;
|
|
10440
|
+
const decoded = format === "png" ? await pngPixels(source.data, source.shape, options.signal) : undefined;
|
|
10441
|
+
const { width, height, components } = decoded ?? source.shape;
|
|
10285
10442
|
checkAbort(options.signal);
|
|
10286
10443
|
const id = this.objects.reserve(), name = "Image" + (this.images.size + 1);
|
|
10287
|
-
|
|
10288
|
-
const captured = decoded ?? new Uint8Array(data);
|
|
10444
|
+
const captured = decoded?.data ?? source.data, decodedAlpha = decoded?.alpha;
|
|
10289
10445
|
let pixels = captured, alpha = decodedAlpha, mask;
|
|
10290
10446
|
if (components === 4) {
|
|
10291
10447
|
// Compact the owned RGBA snapshot in place. Forward writes never overwrite unread channels.
|
|
@@ -10307,20 +10463,22 @@ class PdfDocumentImages {
|
|
|
10307
10463
|
mask = this.objects.reserve();
|
|
10308
10464
|
await this.objects.stream(mask, alpha, "/Type /XObject /Subtype /Image /Width " + width + " /Height " + height + " /ColorSpace /DeviceGray /BitsPerComponent 8", options.compression !== false, true);
|
|
10309
10465
|
}
|
|
10466
|
+
const jpegFilter = format === "jpeg" ? " /Filter /DCTDecode" +
|
|
10467
|
+
(source.shape.colorTransform === 0 ? " /DecodeParms << /ColorTransform 0 >>" : "") : "";
|
|
10310
10468
|
const dictionary = "/Type /XObject /Subtype /Image /Width " + width + " /Height " + height + " /ColorSpace /" +
|
|
10311
10469
|
(components === 1 ? "DeviceGray" : "DeviceRGB") + " /BitsPerComponent 8" + (mask ? " /SMask " + mask + " 0 R" : "") +
|
|
10312
|
-
|
|
10470
|
+
jpegFilter;
|
|
10313
10471
|
await this.objects.stream(id, pixels, dictionary, format === "jpeg" ? false : options.compression !== false, true);
|
|
10314
10472
|
const resource = { name, id, width, height };
|
|
10315
10473
|
this.images.set(image, resource);
|
|
10316
10474
|
return resource;
|
|
10317
10475
|
}
|
|
10318
10476
|
}
|
|
10319
|
-
/** Inspect bounded JPEG headers; JPEG entropy decoding remains the independent reader's job. */
|
|
10477
|
+
/** @internal Inspect bounded JPEG headers; JPEG entropy decoding remains the independent reader's job. */
|
|
10320
10478
|
function jpegSize(bytes) {
|
|
10321
10479
|
if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216 || bytes[bytes.length - 2] !== 255 || bytes[bytes.length - 1] !== 217)
|
|
10322
10480
|
throw new TypeError("JPEG images need complete SOI/EOI markers.");
|
|
10323
|
-
let result;
|
|
10481
|
+
let result, rgb = false, adobe = false;
|
|
10324
10482
|
for (let p = 2; p < bytes.length;) {
|
|
10325
10483
|
if (bytes[p++] !== 255)
|
|
10326
10484
|
throw new TypeError("Invalid JPEG marker.");
|
|
@@ -10330,7 +10488,8 @@ function jpegSize(bytes) {
|
|
|
10330
10488
|
if (marker === 218) {
|
|
10331
10489
|
if (!result)
|
|
10332
10490
|
throw new TypeError("JPEG scan precedes its frame header.");
|
|
10333
|
-
|
|
10491
|
+
// PDF decoders otherwise assume a color transform for three-component JPEGs.
|
|
10492
|
+
return rgb && !adobe ? { ...result, colorTransform: 0 } : result;
|
|
10334
10493
|
}
|
|
10335
10494
|
if (marker === 217)
|
|
10336
10495
|
break;
|
|
@@ -10339,6 +10498,8 @@ function jpegSize(bytes) {
|
|
|
10339
10498
|
const length = bytes[p] * 256 + bytes[p + 1], end = p + length;
|
|
10340
10499
|
if (length < 2 || end > bytes.length)
|
|
10341
10500
|
throw new TypeError("Truncated JPEG segment.");
|
|
10501
|
+
if (marker === 238 && length >= 14 && String.fromCharCode(...bytes.subarray(p + 2, p + 7)) === "Adobe")
|
|
10502
|
+
adobe = true;
|
|
10342
10503
|
if (marker === 226 && length >= 14 && String.fromCharCode(...bytes.subarray(p + 2, p + 14)) === "ICC_PROFILE\0")
|
|
10343
10504
|
throw new NotSupportedError("Normalize ICC-profiled JPEG colors before PDF embedding.");
|
|
10344
10505
|
if (marker === 225 && length >= 8 && String.fromCharCode(...bytes.subarray(p + 2, p + 8)) === "Exif\0\0")
|
|
@@ -10351,7 +10512,8 @@ function jpegSize(bytes) {
|
|
|
10351
10512
|
throw new NotSupportedError("PDF JPEG images require grayscale or RGB components; CMYK is unsupported.");
|
|
10352
10513
|
if (components === 3) {
|
|
10353
10514
|
const ids = [bytes[p + 8], bytes[p + 11], bytes[p + 14]].join(",");
|
|
10354
|
-
|
|
10515
|
+
rgb = ids === "82,71,66";
|
|
10516
|
+
if (ids !== "1,2,3" && !rgb)
|
|
10355
10517
|
throw new NotSupportedError("Unsupported JPEG component color layout.");
|
|
10356
10518
|
}
|
|
10357
10519
|
if (result)
|
|
@@ -10362,7 +10524,7 @@ function jpegSize(bytes) {
|
|
|
10362
10524
|
}
|
|
10363
10525
|
throw new TypeError("JPEG image has no complete frame and scan.");
|
|
10364
10526
|
}
|
|
10365
|
-
const _exports = Object.freeze({ PdfDocumentImages: PdfDocumentImages });
|
|
10527
|
+
const _exports = Object.freeze({ PdfDocumentImages: PdfDocumentImages, jpegSize: jpegSize });
|
|
10366
10528
|
return _exports;
|
|
10367
10529
|
})();
|
|
10368
10530
|
|
|
@@ -10457,7 +10619,7 @@ const { NotSupportedError, OfficeIMOError } = _m2;
|
|
|
10457
10619
|
|
|
10458
10620
|
const { checkAbort, pause, taskYieldDue } = _m4;
|
|
10459
10621
|
|
|
10460
|
-
const { color, positive } = _m56;
|
|
10622
|
+
const { color, pdfDrawingMaxDepth, positive } = _m56;
|
|
10461
10623
|
|
|
10462
10624
|
const { pdfNumber: n } = _m60;
|
|
10463
10625
|
|
|
@@ -10479,22 +10641,50 @@ function clipRectangle(value) {
|
|
|
10479
10641
|
const clip = record(value, ["x", "y", "width", "height"], "drawing clip");
|
|
10480
10642
|
return { x: coordinate(clip.x), y: coordinate(clip.y), width: positive(clip.width, "Drawing clip width", 1000000), height: positive(clip.height, "Drawing clip height", 1000000) };
|
|
10481
10643
|
}
|
|
10644
|
+
/** A PDF dash array: 1 through 16 nonnegative lengths, not all zero, and a finite phase. */
|
|
10645
|
+
function dashPattern(value, offset) {
|
|
10646
|
+
if (value === undefined) {
|
|
10647
|
+
if (offset !== undefined)
|
|
10648
|
+
throw new TypeError("Drawing dashOffset requires dash.");
|
|
10649
|
+
return "";
|
|
10650
|
+
}
|
|
10651
|
+
if (!Array.isArray(value) || !value.length || value.length > 16)
|
|
10652
|
+
throw new TypeError("Drawing dash must list 1 through 16 nonnegative lengths with at least one positive length.");
|
|
10653
|
+
const lengths = Array.from(value, item => {
|
|
10654
|
+
if (typeof item !== "number" || !Number.isFinite(item) || item < 0 || item > 14400)
|
|
10655
|
+
throw new TypeError("Drawing dash lengths must be from 0 through 14,400 points.");
|
|
10656
|
+
return n(item);
|
|
10657
|
+
});
|
|
10658
|
+
if (lengths.every(length => length === "0"))
|
|
10659
|
+
throw new TypeError("Drawing dash needs a positive length after PDF rounding.");
|
|
10660
|
+
let phase = coordinate(offset ?? 0);
|
|
10661
|
+
if (phase < 0) {
|
|
10662
|
+
// Work in serialized thousandths of a point. Odd arrays repeat twice before the paint state repeats.
|
|
10663
|
+
const period = lengths.reduce((sum, length) => sum + Math.round(Number(length) * 1000), 0) * (lengths.length % 2 ? 2 : 1);
|
|
10664
|
+
phase = ((Math.round(phase * 1000) % period + period) % period) / 1000;
|
|
10665
|
+
}
|
|
10666
|
+
return "[" + lengths.join(" ") + "] " + n(phase) + " d\n";
|
|
10667
|
+
}
|
|
10482
10668
|
async function cooperate(settings) {
|
|
10483
10669
|
if (taskYieldDue())
|
|
10484
10670
|
await pause();
|
|
10485
10671
|
checkAbort(settings.options.signal);
|
|
10486
10672
|
}
|
|
10487
10673
|
/** Take ownership of one bounded schema before any cooperative or font work can run caller code. */
|
|
10488
|
-
function captureDrawing(drawing, settings, used) {
|
|
10674
|
+
function captureDrawing(drawing, settings, used, images) {
|
|
10489
10675
|
checkAbort(settings.options.signal);
|
|
10490
|
-
const root = record(drawing, ["version", "width", "height", "elements"], "drawing");
|
|
10491
|
-
|
|
10492
|
-
|
|
10676
|
+
const root = record(drawing, ["version", "width", "height", "elements", "standardFonts"], "drawing");
|
|
10677
|
+
const standardFonts = root.standardFonts;
|
|
10678
|
+
if (standardFonts !== undefined && typeof standardFonts !== "boolean")
|
|
10679
|
+
throw new TypeError("Drawing standardFonts must be boolean.");
|
|
10680
|
+
const version = root.version;
|
|
10681
|
+
if (version !== 1 && version !== 2)
|
|
10682
|
+
throw new NotSupportedError("Only portable drawing versions 1 and 2 are supported.");
|
|
10493
10683
|
const width = positive(root.width, "Drawing width"), height = positive(root.height, "Drawing height");
|
|
10494
10684
|
let commands = used.commands, elements = used.elements;
|
|
10495
10685
|
const ancestors = new Set();
|
|
10496
10686
|
function path(value) {
|
|
10497
|
-
record(value, ["kind", "commands", "fill", "stroke", "strokeWidth", "fillRule", "lineCap", "lineJoin"], "drawing path");
|
|
10687
|
+
record(value, ["kind", "commands", "fill", "stroke", "strokeWidth", "fillRule", "lineCap", "lineJoin", "miterLimit", "dash", "dashOffset"], "drawing path");
|
|
10498
10688
|
const source = value.commands;
|
|
10499
10689
|
if (!Array.isArray(source))
|
|
10500
10690
|
throw new TypeError("Drawing path commands must be an array.");
|
|
@@ -10516,6 +10706,10 @@ function captureDrawing(drawing, settings, used) {
|
|
|
10516
10706
|
throw new TypeError("Invalid drawing lineCap.");
|
|
10517
10707
|
if (lineJoin !== undefined && !["miter", "round", "bevel"].includes(lineJoin))
|
|
10518
10708
|
throw new TypeError("Invalid drawing lineJoin.");
|
|
10709
|
+
const miterLimit = positive(value.miterLimit ?? 10, "Drawing miter limit", 1000000);
|
|
10710
|
+
if (miterLimit < 1)
|
|
10711
|
+
throw new RangeError("Drawing miter limit must be at least 1.");
|
|
10712
|
+
const dash = dashPattern(value.dash, value.dashOffset);
|
|
10519
10713
|
for (let i = 0; i < snapshot.length; i++) {
|
|
10520
10714
|
const c = snapshot[i];
|
|
10521
10715
|
if (!c || typeof c !== "object")
|
|
@@ -10548,11 +10742,12 @@ function captureDrawing(drawing, settings, used) {
|
|
|
10548
10742
|
if (!started)
|
|
10549
10743
|
throw new TypeError("A drawing path needs at least one command.");
|
|
10550
10744
|
return { kind: "path", commands: copied, style: (fill === undefined ? "" : fill + " rg\n") + (stroke === undefined ? "" : stroke + " RG\n" + n(strokeWidth) + " w\n") +
|
|
10551
|
-
String(["butt", "round", "square"].indexOf(lineCap ?? "butt")) + " J\n" + String(["miter", "round", "bevel"].indexOf(lineJoin ?? "miter")) +
|
|
10745
|
+
String(["butt", "round", "square"].indexOf(lineCap ?? "butt")) + " J\n" + String(["miter", "round", "bevel"].indexOf(lineJoin ?? "miter")) +
|
|
10746
|
+
" j\n" + n(miterLimit) + " M\n" + dash,
|
|
10552
10747
|
paint: (fill !== undefined && stroke !== undefined ? "B" : fill !== undefined ? "f" : "S") + (fill !== undefined && fillRule === "evenodd" ? "*" : "") + "\n" };
|
|
10553
10748
|
}
|
|
10554
10749
|
function text(value) {
|
|
10555
|
-
record(value, ["kind", "text", "x", "y", "font", "fontSize", "color"], "drawing text");
|
|
10750
|
+
record(value, ["kind", "text", "x", "y", "font", "fontSize", "color", "anchor", "rotation"], "drawing text");
|
|
10556
10751
|
const snapshot = value.text, slot = value.font;
|
|
10557
10752
|
if (typeof snapshot !== "string")
|
|
10558
10753
|
throw new TypeError("Drawing text must be a string.");
|
|
@@ -10563,14 +10758,33 @@ function captureDrawing(drawing, settings, used) {
|
|
|
10563
10758
|
if (!["regular", "bold", "italic", "boldItalic"].includes(slot))
|
|
10564
10759
|
throw new TypeError("Invalid drawing font slot.");
|
|
10565
10760
|
const x = coordinate(value.x), y = coordinate(value.y), size = positive(value.fontSize, "Drawing font size"), foreground = color(value.color);
|
|
10761
|
+
const anchor = value.anchor, rotation = value.rotation ?? 0;
|
|
10762
|
+
if (anchor !== undefined && !["start", "middle", "end"].includes(anchor))
|
|
10763
|
+
throw new TypeError("Invalid drawing text anchor.");
|
|
10764
|
+
if (typeof rotation !== "number" || !Number.isFinite(rotation) || Math.abs(rotation) > 360)
|
|
10765
|
+
throw new RangeError("Drawing text rotation must be finite degrees within -360 through 360.");
|
|
10566
10766
|
settings.budget.cell(snapshot);
|
|
10567
|
-
|
|
10767
|
+
// Quarter turns stay exact so upright and vertical axis labels keep integral matrices.
|
|
10768
|
+
const turn = rotation % 90 === 0 ? (((rotation / 90) % 4) + 4) % 4 : -1, radians = rotation * Math.PI / 180;
|
|
10769
|
+
const cos = turn < 0 ? Math.cos(radians) : [1, 0, -1, 0][turn], sin = turn < 0 ? Math.sin(radians) : [0, 1, 0, -1][turn];
|
|
10770
|
+
return { kind: "text", text: snapshot, x, y, size, color: foreground, font: slot, anchor: anchor === "middle" ? .5 : anchor === "end" ? 1 : 0, cos, sin };
|
|
10771
|
+
}
|
|
10772
|
+
function image(value) {
|
|
10773
|
+
record(value, ["kind", "image", "x", "y", "width", "height", "opacity"], "drawing image");
|
|
10774
|
+
const x = coordinate(value.x), y = coordinate(value.y), suppliedOpacity = value.opacity;
|
|
10775
|
+
const opacity = suppliedOpacity === undefined ? 1 : suppliedOpacity;
|
|
10776
|
+
const width = positive(value.width, "Drawing image width", 1000000), height = positive(value.height, "Drawing image height", 1000000);
|
|
10777
|
+
if (typeof opacity !== "number" || !(opacity >= 0 && opacity <= 1))
|
|
10778
|
+
throw new RangeError("Drawing image opacity must be from 0 through 1.");
|
|
10779
|
+
const source = value.image;
|
|
10780
|
+
images.snapshot(source);
|
|
10781
|
+
return { kind: "image", image: source, x, y, width, height, opacity };
|
|
10568
10782
|
}
|
|
10569
10783
|
function children(input, depth) {
|
|
10570
10784
|
if (!Array.isArray(input))
|
|
10571
10785
|
throw new TypeError("Drawing elements must be an array.");
|
|
10572
|
-
if (depth >
|
|
10573
|
-
throw new RangeError("Drawing groups support at most
|
|
10786
|
+
if (depth > pdfDrawingMaxDepth && input.length)
|
|
10787
|
+
throw new RangeError("Drawing groups support at most " + pdfDrawingMaxDepth + " element levels.");
|
|
10574
10788
|
if (elements + input.length > settings.limits.maxDrawingElements)
|
|
10575
10789
|
throw new OfficeIMOError("RESOURCE_LIMIT", "maxDrawingElements exceeded.");
|
|
10576
10790
|
checkAbort(settings.options.signal);
|
|
@@ -10588,6 +10802,8 @@ function captureDrawing(drawing, settings, used) {
|
|
|
10588
10802
|
output.push(path(value));
|
|
10589
10803
|
else if (kind === "text")
|
|
10590
10804
|
output.push(text(value));
|
|
10805
|
+
else if (kind === "image" && version === 2)
|
|
10806
|
+
output.push(image(value));
|
|
10591
10807
|
else if (kind === "group") {
|
|
10592
10808
|
record(value, ["kind", "clip", "elements"], "drawing group");
|
|
10593
10809
|
const clipValue = value.clip, clip = clipValue === undefined ? undefined : clipRectangle(clipValue);
|
|
@@ -10604,29 +10820,35 @@ function captureDrawing(drawing, settings, used) {
|
|
|
10604
10820
|
}
|
|
10605
10821
|
const plan = children(root.elements, 1);
|
|
10606
10822
|
checkAbort(settings.options.signal);
|
|
10607
|
-
return { width, height, plan, commands: commands - used.commands, elements: elements - used.elements };
|
|
10823
|
+
return { width, height, plan, commands: commands - used.commands, elements: elements - used.elements, standardFonts: standardFonts === true };
|
|
10608
10824
|
}
|
|
10609
10825
|
/** Preflight and paint owned records. The existing font owner retains glyph maps and subsets. */
|
|
10610
|
-
async function prepareDrawing(drawing, settings, fonts, used) {
|
|
10826
|
+
async function prepareDrawing(drawing, settings, fonts, used, resources) {
|
|
10611
10827
|
// A drawing's bounded capture is synchronous; yielding here would leave later caller records borrowed.
|
|
10612
|
-
const captured = captureDrawing(drawing, settings, used), drawingFonts = new Map();
|
|
10828
|
+
const { images } = resources, captured = captureDrawing(drawing, settings, used, images), drawingFonts = new Map();
|
|
10613
10829
|
function fontFor(slot) {
|
|
10614
10830
|
const existing = drawingFonts.get(slot);
|
|
10615
10831
|
if (existing)
|
|
10616
10832
|
return existing;
|
|
10617
|
-
const font = fonts.select(slot === "bold" || slot === "boldItalic", slot === "italic" || slot === "boldItalic");
|
|
10618
|
-
if (
|
|
10833
|
+
const font = fonts.select(slot === "bold" || slot === "boldItalic", slot === "italic" || slot === "boldItalic", undefined, captured.standardFonts);
|
|
10834
|
+
if (font.syntheticBold || font.syntheticItalic || !font.program && !captured.standardFonts)
|
|
10619
10835
|
throw new NotSupportedError("Drawing text without an exact embedded font face at fonts." + slot);
|
|
10620
10836
|
drawingFonts.set(slot, font);
|
|
10621
10837
|
return font;
|
|
10622
10838
|
}
|
|
10623
10839
|
// The work budget belongs to the drawing, including short runs in separate sibling groups.
|
|
10624
10840
|
let preflightCharacters = 0, preflightElements = 0;
|
|
10841
|
+
const imageNames = new Map();
|
|
10625
10842
|
async function preflight(nodes) {
|
|
10626
10843
|
for (let i = 0; i < nodes.length; i++) {
|
|
10627
10844
|
const node = nodes[i];
|
|
10628
10845
|
if (node.kind === "group")
|
|
10629
10846
|
await preflight(node.children);
|
|
10847
|
+
else if (node.kind === "image" && !imageNames.has(node.image)) {
|
|
10848
|
+
const resource = await images.prepare(node.image);
|
|
10849
|
+
resources.registerImage(resource.name, resource.id);
|
|
10850
|
+
imageNames.set(node.image, resource.name);
|
|
10851
|
+
}
|
|
10630
10852
|
else if (node.kind === "text") {
|
|
10631
10853
|
const font = fontFor(node.font);
|
|
10632
10854
|
for (const character of node.text) {
|
|
@@ -10669,9 +10891,23 @@ async function prepareDrawing(drawing, settings, fonts, used) {
|
|
|
10669
10891
|
}
|
|
10670
10892
|
add(node.paint);
|
|
10671
10893
|
}
|
|
10894
|
+
else if (node.kind === "image") {
|
|
10895
|
+
// Image space is a unit square with a bottom-left origin; the drawing's y axis points down.
|
|
10896
|
+
if (node.opacity < 1)
|
|
10897
|
+
add("/" + resources.opacity(node.opacity) + " gs\n");
|
|
10898
|
+
add([node.width, 0, 0, -node.height, node.x, node.y + node.height].map(n).join(" ") + " cm /" + imageNames.get(node.image) + " Do\n");
|
|
10899
|
+
}
|
|
10672
10900
|
else {
|
|
10673
10901
|
const font = fontFor(node.font);
|
|
10674
|
-
|
|
10902
|
+
let shift = 0;
|
|
10903
|
+
if (node.anchor) {
|
|
10904
|
+
for (const character of node.text)
|
|
10905
|
+
shift += font.width(character.codePointAt(0));
|
|
10906
|
+
shift *= node.size / 1000 * node.anchor;
|
|
10907
|
+
}
|
|
10908
|
+
// Text space is upright in the drawing's downward y axis; rotation turns the baseline clockwise about its anchor.
|
|
10909
|
+
add(node.color + " rg\nBT /" + font.name + " " + n(node.size) + " Tf 0 Tr " +
|
|
10910
|
+
[node.cos, node.sin, node.sin, -node.cos, node.x - shift * node.cos, node.y - shift * node.sin].map(n).join(" ") + " Tm <");
|
|
10675
10911
|
let chunk = "";
|
|
10676
10912
|
for (const character of node.text) {
|
|
10677
10913
|
chunk += character;
|
|
@@ -11394,7 +11630,9 @@ async function writePdfDocumentTo(blocks, destination, configuration = {}) {
|
|
|
11394
11630
|
const inputDrawing = block.drawing, capturedCaption = snapshotCaption(block.caption), alternative = graphicAlternative(block, pages.settings), alignment = graphicAlignment(block.alignment);
|
|
11395
11631
|
if (capturedCaption && alternative === undefined)
|
|
11396
11632
|
throw new TypeError("A captioned PDF graphic requires alternativeText and cannot be decorative.");
|
|
11397
|
-
const drawing = await prepareDrawing(inputDrawing, pages.settings, fonts, { commands, elements: drawingElements }
|
|
11633
|
+
const drawing = await prepareDrawing(inputDrawing, pages.settings, fonts, { commands, elements: drawingElements }, {
|
|
11634
|
+
images, registerImage: (name, id) => pages.registerXObject(name, id), opacity: alpha => pages.opacityState(alpha)
|
|
11635
|
+
}), caption = await prepareCaption(capturedCaption);
|
|
11398
11636
|
commands += drawing.commands;
|
|
11399
11637
|
drawingElements += drawing.elements;
|
|
11400
11638
|
await flushParagraphs((caption?.height ?? 0) + pages.graphicHeight(drawing.width, drawing.height));
|
|
@@ -11536,6 +11774,6 @@ const _m0 = (() => {
|
|
|
11536
11774
|
const _exports = Object.freeze({ core: _m1, zip: _m14, xml: _m17, opc: _m18, xlsx: _m21, csv: _m50, pdf: _m54, Workbook: _m21.Workbook, Worksheet: _m21.Worksheet, Cell: _m21.Cell, FormulaCell: _m21.FormulaCell, StyleRegistry: _m21.StyleRegistry, NumberFormats: _m21.NumberFormats, writeXlsx: _m21.writeXlsx, writeXlsxTo: _m21.writeXlsxTo, writeCsv: _m50.writeCsv, writeCsvTo: _m50.writeCsvTo, createGroupedReport: _m8.createGroupedReport, writeGroupedXlsx: _m48.writeGroupedXlsx, writeGroupedXlsxTo: _m48.writeGroupedXlsxTo, addGroupedXlsx: _m48.addGroupedXlsx, writeGroupedPdf: _m83.writeGroupedPdf, writeGroupedPdfTo: _m83.writeGroupedPdfTo, pdfGroupedTable: _m83.pdfGroupedTable, writePdf: _m54.writePdf, writePdfTo: _m54.writePdfTo, writePdfDocument: _m54.writePdfDocument, writePdfDocumentTo: _m54.writePdfDocumentTo, pdfTable: _m54.pdfTable, PdfFont: _m54.PdfFont, preflightPdfText: _m54.preflightPdfText, OfficeIMOError: _m1.OfficeIMOError, NotSupportedError: _m1.NotSupportedError, detectFeatures: _m1.detectFeatures, saveBlob: _m1.saveBlob, ExportCell: _m1.ExportCell });
|
|
11537
11775
|
return _exports;
|
|
11538
11776
|
})();
|
|
11539
|
-
const __officeimoModules = Object.freeze({ "81b3d47c02b7d8443b79e02b3cfb52032d6b73d9a3fb592b777ebe028ad0ef00": _m1, "
|
|
11777
|
+
const __officeimoModules = Object.freeze({ "81b3d47c02b7d8443b79e02b3cfb52032d6b73d9a3fb592b777ebe028ad0ef00": _m1, "4eea31c4336d3c43bc743739843a3ef31803d8f0ed553f5645ee9de2554eb244": _m23, "406ac6c93ee68eae70c6f52a1e6f4c56b84f43cae12576040c766dcc5598a580": _m50, "edf1bf5cb6d749de0e6823397df6610a6c1cc88768898c1b4d7083ee96ef6759": _m21, "344fd55ffe1a37b32a8eb6a2bdaa14dff90e0fee0f37282457f9e4c3b7bce1ca": _m54, "d6884428c3e4d15a691ecf2523372a03b32de22a890edfbfc9961f2dc92711c2": _m47, "732224f6995c2478cf33a6ed01f3e3d3dcccb159a731d6db9280104bd5040fc5": _m5, "d56b24243cff6f3552a2f7b45521af4491494375ec76117e9ac1ebb047ce02da": _m30, "87c24efeaa0f1579c19afeeb4918caeb4f8f65a88d24a246e2cfd712b37dbac3": _m4, "42faf379960e5674a6fdfa8c8fca0bb68bbd74587231248d2524d7004def3671": _m9, "50b3c10b690ceff693c8c5f809195ba6845b20e60f408e791a750d2ecbd5c669": _m10, "0391fe35ea7d02b25804ab4d0e7543136d6bb615f368f268c74aa135f23aa6bc": _m11, "f0627ba89e5c8fcb376ebe3ce72dcc8d68c34952981f8703e36b8bb1a9894208": _m53, "6c92204b587bb12cfa85c60eb1fd921804dfa51304538c7be3353e2927551b02": _m56, "fd70ccda89f27c6b874c8840ac944b3ec723dbdef3dfe7600f7bdb81f4660c96": _m43, "d9c1509dff0538488752433e47cd0927ece5f93c559ad0e32dc56602dfd44596": _m63, "e88a83ca79cd099fc2de29689554c913c7d04b17018098f81c43044064fcdfb8": _m27, "046b305cdccf817d847addb75a778131622de23f2840830bbe1c0c26053a68c0": _m8, "c9fde2c438e186da56f740105fcd41c265fdfdd855a4f1b811d556a02387479b": _m12, "227236fd7adc9472e188831b8f16fdc69338c4d779f2b69a8abbd8dbfa95b585": _m17, "5337d1e3bd5ae0c1d10a476fcd31540d20337ccf7aa93c7e9e26c2b1a7dab92b": _m3, "59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070": _m67, "d5c945064d81fdd257960f48c421125e106e5f270427d170bb05587dd96a44ea": _m2, "e716b8b1da464094622f5f671518493c78e63ff22a029d61544d2d193b63ce8f": _m60, "32ca4982f963f400829c2e364b7d3479f36d91740dafb32d600f29b5cac487ec": _m85, "6b0244b5ec6d550c705b4e4cbb47997331f1ecd99e2bf8a06f7c646eebbffbf8": _m86, "8d96d0024443ac9aeaea70e9324b53aacef098c2385d4e6a89a76d184e28556a": _m24 });
|
|
11540
11778
|
const { core, zip, xml, opc, xlsx, csv, pdf, Workbook, Worksheet, Cell, FormulaCell, StyleRegistry, NumberFormats, writeXlsx, writeXlsxTo, writeCsv, writeCsvTo, createGroupedReport, writeGroupedXlsx, writeGroupedXlsxTo, addGroupedXlsx, writeGroupedPdf, writeGroupedPdfTo, pdfGroupedTable, writePdf, writePdfTo, writePdfDocument, writePdfDocumentTo, pdfTable, PdfFont, preflightPdfText, OfficeIMOError, NotSupportedError, detectFeatures, saveBlob, ExportCell } = _m0;
|
|
11541
11779
|
export { core, zip, xml, opc, xlsx, csv, pdf, Workbook, Worksheet, Cell, FormulaCell, StyleRegistry, NumberFormats, writeXlsx, writeXlsxTo, writeCsv, writeCsvTo, createGroupedReport, writeGroupedXlsx, writeGroupedXlsxTo, addGroupedXlsx, writeGroupedPdf, writeGroupedPdfTo, pdfGroupedTable, writePdf, writePdfTo, writePdfDocument, writePdfDocumentTo, pdfTable, PdfFont, preflightPdfText, OfficeIMOError, NotSupportedError, detectFeatures, saveBlob, ExportCell, __officeimoModules };
|