@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
|
@@ -956,15 +956,20 @@ return _exports;
|
|
|
956
956
|
const _m14 = (() => {
|
|
957
957
|
/** @internal Notify synchronously; observe an accidental promise before rejecting its unsupported use. */
|
|
958
958
|
function notifyProgress(callback, progress) {
|
|
959
|
+
notifySynchronously("onProgress", callback, progress);
|
|
960
|
+
}
|
|
961
|
+
/** @internal Run a host notification that must finish before the export continues. A returned promise is observed,
|
|
962
|
+
* so its rejection is never unhandled, and the export fails instead of reporting success before the callback ends. */
|
|
963
|
+
function notifySynchronously(name, callback, value) {
|
|
959
964
|
if (!callback)
|
|
960
965
|
return;
|
|
961
|
-
const result = callback(
|
|
966
|
+
const result = callback(value);
|
|
962
967
|
if (result && typeof result.then === "function") {
|
|
963
968
|
void Promise.resolve(result).catch(() => { });
|
|
964
|
-
throw new TypeError("
|
|
969
|
+
throw new TypeError(name + " must be synchronous.");
|
|
965
970
|
}
|
|
966
971
|
}
|
|
967
|
-
const _exports = Object.freeze({ notifyProgress: notifyProgress });
|
|
972
|
+
const _exports = Object.freeze({ notifyProgress: notifyProgress, notifySynchronously: notifySynchronously });
|
|
968
973
|
return _exports;
|
|
969
974
|
})();
|
|
970
975
|
|
|
@@ -2199,6 +2204,24 @@ const { DifferentialStyles } = _m31;
|
|
|
2199
2204
|
|
|
2200
2205
|
|
|
2201
2206
|
const spreadsheetNamespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
|
2207
|
+
const borderStyles = ["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"];
|
|
2208
|
+
/** @internal Validate and normalize border edges without registering a workbook style. */
|
|
2209
|
+
function normalizeBorder(border) {
|
|
2210
|
+
if (!border || typeof border !== "object")
|
|
2211
|
+
throw new TypeError("A border must be an object of edges.");
|
|
2212
|
+
const result = {};
|
|
2213
|
+
for (const side of ["left", "right", "top", "bottom"]) {
|
|
2214
|
+
const edge = border[side];
|
|
2215
|
+
if (edge) {
|
|
2216
|
+
// Read each property once, so the validated edge is the one that is stored.
|
|
2217
|
+
const { style, color } = edge;
|
|
2218
|
+
if (!borderStyles.includes(style))
|
|
2219
|
+
throw new TypeError("Invalid border style.");
|
|
2220
|
+
result[side] = { style, ...(color ? { color: colorArgb(color) } : {}) };
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
return result;
|
|
2224
|
+
}
|
|
2202
2225
|
const NumberFormats = { General: "General", Integer: "0", Decimal: "0.00", Percent: "0.00%", Date: "yyyy-mm-dd", DateTime: "yyyy-mm-dd hh:mm:ss" };
|
|
2203
2226
|
function index(value, count, kind) {
|
|
2204
2227
|
if (!Number.isInteger(value) || value < 0 || value >= count)
|
|
@@ -2271,32 +2294,24 @@ class StyleRegistry {
|
|
|
2271
2294
|
/** @internal */
|
|
2272
2295
|
addDifferentials(styles) { this.checkDifferentials(styles); return this.differential.add(styles); }
|
|
2273
2296
|
addFont(font) {
|
|
2274
|
-
|
|
2297
|
+
const { name: requested, size: requestedSize, bold, italic, underline, strike, color } = font;
|
|
2298
|
+
if (requested !== undefined && typeof requested !== "string")
|
|
2275
2299
|
throw new TypeError("Font name must be a string.");
|
|
2276
|
-
const name = cleanXml(
|
|
2300
|
+
const name = cleanXml(requested ?? "Calibri", this.policy), size = requestedSize ?? 11;
|
|
2277
2301
|
if (typeof name !== "string" || !name || name.length > 31)
|
|
2278
2302
|
throw new TypeError("Font name must contain 1 through 31 characters.");
|
|
2279
2303
|
if (!Number.isFinite(size) || size <= 0 || size > 409)
|
|
2280
2304
|
throw new RangeError("Font size must be positive and at most 409.");
|
|
2281
|
-
return deduplicate(this.fonts, this.fontIndexes, { name, size, bold: !!
|
|
2305
|
+
return deduplicate(this.fonts, this.fontIndexes, { name, size, bold: !!bold, italic: !!italic, underline: !!underline, strike: !!strike, color: color ? colorArgb(color) : "" }, this.maximum);
|
|
2282
2306
|
}
|
|
2283
2307
|
addFill(fill) {
|
|
2284
|
-
const pattern = fill.pattern ?? (
|
|
2285
|
-
if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !
|
|
2308
|
+
const { color } = fill, pattern = fill.pattern ?? (color ? "solid" : "none");
|
|
2309
|
+
if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !color) || (pattern !== "solid" && color))
|
|
2286
2310
|
throw new TypeError("A solid fill requires a color; none and gray125 have no color.");
|
|
2287
|
-
return deduplicate(this.fills, this.fillIndexes, { pattern, color:
|
|
2311
|
+
return deduplicate(this.fills, this.fillIndexes, { pattern, color: color ? colorArgb(color) : "" }, this.maximum + 1);
|
|
2288
2312
|
}
|
|
2289
2313
|
addBorder(border) {
|
|
2290
|
-
|
|
2291
|
-
for (const side of ["left", "right", "top", "bottom"]) {
|
|
2292
|
-
const edge = border[side];
|
|
2293
|
-
if (edge) {
|
|
2294
|
-
if (!["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"].includes(edge.style))
|
|
2295
|
-
throw new TypeError("Invalid border style.");
|
|
2296
|
-
result[side] = { style: edge.style, ...(edge.color ? { color: colorArgb(edge.color) } : {}) };
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
return deduplicate(this.borders, this.borderIndexes, result, this.maximum);
|
|
2314
|
+
return deduplicate(this.borders, this.borderIndexes, normalizeBorder(border), this.maximum);
|
|
2300
2315
|
}
|
|
2301
2316
|
addNumberFormat(format) {
|
|
2302
2317
|
if (typeof format !== "string" || !format || format.length > 255)
|
|
@@ -2362,7 +2377,7 @@ class StyleRegistry {
|
|
|
2362
2377
|
return this.compose(base, { numberFormat: this.styles[this.validateStyle(dateStyle)].numberFormat });
|
|
2363
2378
|
}
|
|
2364
2379
|
/** @internal Column shorthand and header style composition. */
|
|
2365
|
-
forColumn(column, header = false, fill, date = false) {
|
|
2380
|
+
forColumn(column, header = false, fill, date = false, border) {
|
|
2366
2381
|
const base = !header && column.style !== undefined ? this.styles[this.validateStyle(column.style)] : undefined;
|
|
2367
2382
|
const format = column.format !== undefined ? column.format || NumberFormats.General : base?.numberFormat || (column.type === "date" || date ? NumberFormats.DateTime : NumberFormats.General);
|
|
2368
2383
|
return this.add({
|
|
@@ -2371,7 +2386,7 @@ class StyleRegistry {
|
|
|
2371
2386
|
wrapText: column.wrapText ?? base?.wrapText ?? false,
|
|
2372
2387
|
...(column.alignment ? { alignment: column.alignment } : base?.alignment ? { alignment: base.alignment } : {}),
|
|
2373
2388
|
...(base?.verticalAlignment ? { verticalAlignment: base.verticalAlignment } : {}),
|
|
2374
|
-
...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {})
|
|
2389
|
+
...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {}), ...(border ? { border } : {})
|
|
2375
2390
|
});
|
|
2376
2391
|
}
|
|
2377
2392
|
toXml() {
|
|
@@ -2396,7 +2411,7 @@ class StyleRegistry {
|
|
|
2396
2411
|
}).join("") + '</cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>' + this.differential.toXml() + '</styleSheet>';
|
|
2397
2412
|
}
|
|
2398
2413
|
}
|
|
2399
|
-
const _exports = Object.freeze({ colorArgb: _m30.colorArgb, spreadsheetNamespace: spreadsheetNamespace, NumberFormats: NumberFormats, validateStylePatch: validateStylePatch, copyStylePatch: copyStylePatch, StyleRegistry: StyleRegistry });
|
|
2414
|
+
const _exports = Object.freeze({ colorArgb: _m30.colorArgb, spreadsheetNamespace: spreadsheetNamespace, normalizeBorder: normalizeBorder, NumberFormats: NumberFormats, validateStylePatch: validateStylePatch, copyStylePatch: copyStylePatch, StyleRegistry: StyleRegistry });
|
|
2400
2415
|
return _exports;
|
|
2401
2416
|
})();
|
|
2402
2417
|
|
|
@@ -3545,7 +3560,7 @@ const { ChunkedTextSink, BlobByteSink } = _m3;
|
|
|
3545
3560
|
|
|
3546
3561
|
const { OfficeIMOError } = _m2;
|
|
3547
3562
|
|
|
3548
|
-
const { notifyProgress } = _m14;
|
|
3563
|
+
const { notifyProgress, notifySynchronously } = _m14;
|
|
3549
3564
|
|
|
3550
3565
|
const { copyColumns, createRowProjector } = _m11;
|
|
3551
3566
|
|
|
@@ -3617,8 +3632,14 @@ class Worksheet {
|
|
|
3617
3632
|
pendingCharacters = 0;
|
|
3618
3633
|
reservedLayout = false;
|
|
3619
3634
|
internalLinks = [];
|
|
3635
|
+
// Evicted entries become holes and are compacted in one pass when the links are read, keeping eviction O(1).
|
|
3620
3636
|
links = [];
|
|
3637
|
+
evictedLinks = 0;
|
|
3621
3638
|
linkedCells = new Set();
|
|
3639
|
+
/** Indexes in `links` of data-cell links that `hyperlinkOverflow: "drop"` may give up, in row order. */
|
|
3640
|
+
droppable = [];
|
|
3641
|
+
droppableLinks = new WeakSet();
|
|
3642
|
+
droppedLinks = 0;
|
|
3622
3643
|
pictures = [];
|
|
3623
3644
|
nativeCharts = [];
|
|
3624
3645
|
conditional;
|
|
@@ -3649,8 +3670,9 @@ class Worksheet {
|
|
|
3649
3670
|
book.checkLinks(this.links.length);
|
|
3650
3671
|
this.declared = this.columns.map((column, i) => ({ column, letter: columnName(i + 1),
|
|
3651
3672
|
style: book.styles.forColumn(column), dateStyle: book.styles.forColumn(column, false, undefined, true),
|
|
3652
|
-
headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header,
|
|
3653
|
-
...(column.
|
|
3673
|
+
headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header,
|
|
3674
|
+
...((options.headerWrap ?? column.wrapText) === undefined ? {} : { wrapText: options.headerWrap ?? column.wrapText }),
|
|
3675
|
+
...(column.alignment === undefined ? {} : { alignment: column.alignment }) }, options.boldHeader !== false, options.headerFill, false, options.headerBorder) : 0
|
|
3654
3676
|
}));
|
|
3655
3677
|
// Register conditional styles only after worksheet construction can no longer reject its options.
|
|
3656
3678
|
this.conditional = new ConditionalFormats(conditional, book.styles);
|
|
@@ -3702,6 +3724,8 @@ class Worksheet {
|
|
|
3702
3724
|
throw new TypeError("A frozen header or autofilter requires a header row.");
|
|
3703
3725
|
if (options.headerFill !== undefined)
|
|
3704
3726
|
colorArgb(options.headerFill);
|
|
3727
|
+
if (options.headerWrap !== undefined && typeof options.headerWrap !== "boolean")
|
|
3728
|
+
throw new TypeError("headerWrap must be boolean.");
|
|
3705
3729
|
if (options.headerStyle !== undefined)
|
|
3706
3730
|
book.styles.validateStyle(options.headerStyle);
|
|
3707
3731
|
if (options.alternatingRowStyle !== undefined)
|
|
@@ -3827,7 +3851,8 @@ class Worksheet {
|
|
|
3827
3851
|
const cell = col.letter + row;
|
|
3828
3852
|
if (link || this.linkedCells.has(cell))
|
|
3829
3853
|
throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
|
|
3830
|
-
|
|
3854
|
+
this.makeLinkRoom();
|
|
3855
|
+
checkHyperlinkCount(this.linkCount + 1);
|
|
3831
3856
|
this.book.checkLinks(1);
|
|
3832
3857
|
// Replace a generated cell's original reservation with its preview and overflow records.
|
|
3833
3858
|
if (reservedCharacters !== undefined) {
|
|
@@ -3841,7 +3866,7 @@ class Worksheet {
|
|
|
3841
3866
|
value = preserved.preview;
|
|
3842
3867
|
}
|
|
3843
3868
|
if (link)
|
|
3844
|
-
this.appendHyperlink({ cell: col.letter + row, ...link });
|
|
3869
|
+
this.appendHyperlink({ cell: col.letter + row, ...link }, !header && !footer && !title && this.book.settings.hyperlinkOverflow === "drop");
|
|
3845
3870
|
if (type === "date")
|
|
3846
3871
|
value = excelDate(value, this.book.settings.dateMode);
|
|
3847
3872
|
if (!header && !footer && visible && (!formula || !isSubtotalFormula(formula)))
|
|
@@ -4150,20 +4175,61 @@ class Worksheet {
|
|
|
4150
4175
|
throw this.error;
|
|
4151
4176
|
this.appendHyperlink(link);
|
|
4152
4177
|
}
|
|
4153
|
-
appendHyperlink(link) {
|
|
4178
|
+
appendHyperlink(link, droppable = false) {
|
|
4179
|
+
// Validate before any overflow decision, so a dropped link can never hide an unsafe target.
|
|
4154
4180
|
const copied = copyHyperlink(link, this.book.settings.invalidCharacterPolicy);
|
|
4155
4181
|
const position = cellPosition(copied.cell);
|
|
4156
4182
|
if (this.layout.regions.covered(position.column, position.row))
|
|
4157
4183
|
throw new TypeError("Hyperlinks cannot address a covered merged cell.");
|
|
4158
4184
|
if (this.linkedCells.has(copied.cell))
|
|
4159
4185
|
throw new TypeError("Duplicate hyperlink cell: " + copied.cell);
|
|
4160
|
-
|
|
4186
|
+
if (droppable && this.linkCount >= maximumHyperlinks) {
|
|
4187
|
+
this.droppedLinks++;
|
|
4188
|
+
return;
|
|
4189
|
+
}
|
|
4190
|
+
if (!droppable)
|
|
4191
|
+
this.makeLinkRoom();
|
|
4192
|
+
checkHyperlinkCount(this.linkCount + 1);
|
|
4161
4193
|
this.book.retainLink();
|
|
4194
|
+
if (droppable) {
|
|
4195
|
+
this.droppable.push(this.links.length);
|
|
4196
|
+
this.droppableLinks.add(copied);
|
|
4197
|
+
}
|
|
4162
4198
|
this.links.push(copied);
|
|
4163
4199
|
this.linkedCells.add(copied.cell);
|
|
4164
4200
|
}
|
|
4201
|
+
/** Links the worksheet holds now, not counting evicted holes. */
|
|
4202
|
+
get linkCount() { return this.links.length - this.evictedLinks + this.internalLinks.length; }
|
|
4203
|
+
/** A full worksheet gives up its latest data-cell link for a link that cannot be dropped. Hyperlinks are serialized after
|
|
4204
|
+
* the rows, so the cell keeps its written value. The entry becomes a hole, so other indexes stay valid until compaction. */
|
|
4205
|
+
makeLinkRoom() {
|
|
4206
|
+
if (this.linkCount < maximumHyperlinks || !this.droppable.length)
|
|
4207
|
+
return;
|
|
4208
|
+
const index = this.droppable.pop(), removed = this.links[index];
|
|
4209
|
+
this.links[index] = undefined;
|
|
4210
|
+
this.evictedLinks++;
|
|
4211
|
+
this.linkedCells.delete(removed.cell);
|
|
4212
|
+
this.book.releaseLink();
|
|
4213
|
+
this.droppedLinks++;
|
|
4214
|
+
}
|
|
4215
|
+
/** One ordered pass removes evicted holes and rebuilds the droppable indexes. */
|
|
4216
|
+
compactLinks() {
|
|
4217
|
+
if (this.evictedLinks) {
|
|
4218
|
+
const kept = [], droppable = [];
|
|
4219
|
+
for (const link of this.links)
|
|
4220
|
+
if (link) {
|
|
4221
|
+
if (this.droppableLinks.has(link))
|
|
4222
|
+
droppable.push(kept.length);
|
|
4223
|
+
kept.push(link);
|
|
4224
|
+
}
|
|
4225
|
+
this.links = kept;
|
|
4226
|
+
this.droppable = droppable;
|
|
4227
|
+
this.evictedLinks = 0;
|
|
4228
|
+
}
|
|
4229
|
+
return this.links;
|
|
4230
|
+
}
|
|
4165
4231
|
/** @internal */
|
|
4166
|
-
get hyperlinks() { return this.
|
|
4232
|
+
get hyperlinks() { return this.compactLinks(); }
|
|
4167
4233
|
/** @internal */
|
|
4168
4234
|
get images() { return this.pictures; }
|
|
4169
4235
|
/** @internal An empty export has no data table; it still emits the declared headers. */
|
|
@@ -4214,7 +4280,7 @@ class Worksheet {
|
|
|
4214
4280
|
for (const binding of this.chartSources)
|
|
4215
4281
|
binding.finish();
|
|
4216
4282
|
this.chartSources.length = 0;
|
|
4217
|
-
for (const link of this.
|
|
4283
|
+
for (const link of this.compactLinks()) {
|
|
4218
4284
|
const position = cellPosition(link.cell);
|
|
4219
4285
|
if (position.column > this.columns.length || position.row > this.totalRows)
|
|
4220
4286
|
throw new RangeError("Hyperlinks must address cells within the exported rows and columns.");
|
|
@@ -4244,8 +4310,11 @@ class Worksheet {
|
|
|
4244
4310
|
await this.buffer.write(xml);
|
|
4245
4311
|
for (const xml of dataValidationsXml(this.validations, this.headerRows, this.count, detailRanges))
|
|
4246
4312
|
await this.buffer.write(xml);
|
|
4247
|
-
if (this.
|
|
4248
|
-
|
|
4313
|
+
if (this.droppedLinks)
|
|
4314
|
+
notifySynchronously("onHyperlinkOverflow", this.book.settings.onHyperlinkOverflow, Object.freeze({ sheetName: this.name, dropped: this.droppedLinks }));
|
|
4315
|
+
const links = this.compactLinks();
|
|
4316
|
+
if (links.length || this.internalLinks.length)
|
|
4317
|
+
await this.buffer.write(hyperlinksXml(links, this.book.settings.invalidCharacterPolicy, this.internalLinks));
|
|
4249
4318
|
await this.buffer.write(printXml(this.options.print, this.book.settings.invalidCharacterPolicy));
|
|
4250
4319
|
if (this.pictures.length || this.nativeCharts.length)
|
|
4251
4320
|
await this.buffer.write('<drawing r:id="drawing"/>');
|
|
@@ -4390,9 +4459,9 @@ const _m47 = (() => {
|
|
|
4390
4459
|
const { captureFields } = _m10;
|
|
4391
4460
|
|
|
4392
4461
|
/** @internal The workbook owner captures these settings before validation or adapter merging. */
|
|
4393
|
-
const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "creator", "title", "subject", "description", "created", "modified"];
|
|
4462
|
+
const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "hyperlinkOverflow", "onHyperlinkOverflow", "creator", "title", "subject", "description", "created", "modified"];
|
|
4394
4463
|
/** @internal Worksheet settings also used by the portable sheet owner. */
|
|
4395
|
-
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"];
|
|
4464
|
+
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"];
|
|
4396
4465
|
/** @internal Includes inherited format-specific ceilings before a wrapper combines stream settings. */
|
|
4397
4466
|
const workbookLimitFields = ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes", "maxStyles", "maxSheets", "maxOverflowCharacters", "maxHyperlinks", "maxImageBytes", "maxBufferedCells", "maxBufferedCharacters", "maxMergedRanges", "maxConditionalFormats", "maxDifferentialStyles", "maxCharts", "maxChartPoints", "maxChartTextCharacters", "maxFormulaCharacters", "maxDataValidations", "maxValidationTextCharacters"];
|
|
4398
4467
|
/** @internal Capture the workbook's known ceilings without dropping supported prototype fields. */
|
|
@@ -4724,7 +4793,7 @@ const { OpcPackage, officeRelationshipsNamespace, relationshipTypes, corePropert
|
|
|
4724
4793
|
|
|
4725
4794
|
const { escapeOoxmlAttribute, cleanXml, xmlDeclaration } = _m25;
|
|
4726
4795
|
|
|
4727
|
-
const { StyleRegistry, spreadsheetNamespace } = _m29;
|
|
4796
|
+
const { StyleRegistry, spreadsheetNamespace, normalizeBorder } = _m29;
|
|
4728
4797
|
|
|
4729
4798
|
const { sheetName, assertXlsxValue, copyValue } = _m32;
|
|
4730
4799
|
|
|
@@ -4765,6 +4834,8 @@ function captureSheet(options, policy) {
|
|
|
4765
4834
|
return { ...captured, columns,
|
|
4766
4835
|
...(captured.columnOutlines === undefined ? {} : { columnOutlines: captureColumnOutlines(captured.columnOutlines, columns.length) }),
|
|
4767
4836
|
...(captured.headerRows === undefined ? {} : { headerRows: captureTableSpans(captured.headerRows, columns.length) }),
|
|
4837
|
+
// Preflight and every header style read this one snapshot of the edges.
|
|
4838
|
+
...(captured.headerBorder === undefined ? {} : { headerBorder: normalizeBorder(captured.headerBorder) }),
|
|
4768
4839
|
...(footer ? { footer: { ...footer,
|
|
4769
4840
|
...(footer.rows === undefined ? {} : { rows: captureTableSpans(footer.rows, columns.length) }),
|
|
4770
4841
|
...(footer.values === undefined ? {} : { values: footer.values.map(copyValue) }) } } : {}),
|
|
@@ -4840,6 +4911,10 @@ class Workbook {
|
|
|
4840
4911
|
throw new RangeError("compression must be auto or store.");
|
|
4841
4912
|
if (options.oversizedText !== undefined && !["reject", "preserve"].includes(options.oversizedText))
|
|
4842
4913
|
throw new RangeError("oversizedText must be reject or preserve.");
|
|
4914
|
+
if (options.hyperlinkOverflow !== undefined && !["reject", "drop"].includes(options.hyperlinkOverflow))
|
|
4915
|
+
throw new RangeError("hyperlinkOverflow must be reject or drop.");
|
|
4916
|
+
if (options.onHyperlinkOverflow !== undefined && typeof options.onHyperlinkOverflow !== "function")
|
|
4917
|
+
throw new TypeError("onHyperlinkOverflow must be a function.");
|
|
4843
4918
|
cleanXml("", policy);
|
|
4844
4919
|
corePropertiesXml(options, policy);
|
|
4845
4920
|
this.budget = new ExportBudget(options.limits);
|
|
@@ -4917,6 +4992,8 @@ class Workbook {
|
|
|
4917
4992
|
}
|
|
4918
4993
|
/** @internal Reserve a preflighted worksheet batch or one row hyperlink. */
|
|
4919
4994
|
retainLink(count = 1) { this.checkLinks(count); this.links += count; }
|
|
4995
|
+
/** @internal A worksheet dropped a data-cell link it had retained. */
|
|
4996
|
+
releaseLink() { this.links--; }
|
|
4920
4997
|
/** @internal */
|
|
4921
4998
|
checkImage(bytes) {
|
|
4922
4999
|
if (this.settings.limits?.maxImageBytes !== undefined && this.imageBytes + bytes > this.settings.limits.maxImageBytes)
|
|
@@ -5215,7 +5292,7 @@ function value(result) {
|
|
|
5215
5292
|
function portableSheet(options = {}) {
|
|
5216
5293
|
options = captureFields(options, sheetOptionFields);
|
|
5217
5294
|
if (options.headerStyle !== undefined)
|
|
5218
|
-
throw new TypeError("Workbook-local header styles require the advanced Workbook API; use boldHeader and
|
|
5295
|
+
throw new TypeError("Workbook-local header styles require the advanced Workbook API; use boldHeader, headerFill, headerBorder and headerWrap.");
|
|
5219
5296
|
style(options.alternatingRowStyle);
|
|
5220
5297
|
style(options.title?.style);
|
|
5221
5298
|
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 } = _m28;
|
|
|
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));
|