@yudaocode/univer-pdfs 1.6.215 → 1.6.216
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/PDF_BROWSER_RENDERING_CONTRACT.md +288 -22
- package/fixtures/pdf-s1-s7-fidelity-v1.json +2010 -0
- package/lib/cjs/facade/index.js +18 -10
- package/lib/cjs/facade/index.js.map +1 -1
- package/lib/cjs/index.js +557 -100
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/jsx/index.js +143 -68
- package/lib/cjs/jsx/index.js.map +1 -1
- package/lib/es/{chunk-DYTQBEM7.js → chunk-EMSHTYYU.js} +148 -70
- package/lib/es/chunk-EMSHTYYU.js.map +1 -0
- package/lib/es/facade/index.js +19 -10
- package/lib/es/facade/index.js.map +1 -1
- package/lib/es/index.js +408 -32
- package/lib/es/index.js.map +1 -1
- package/lib/es/jsx/index.js +1 -1
- package/lib/types/facade/index.d.ts +3 -0
- package/lib/types/index.d.ts +74 -4
- package/lib/types/jsx/index.d.ts +2 -2
- package/lib/types/jsx/jsx-dev-runtime.d.ts +1 -1
- package/lib/types/jsx/jsx-runtime.d.ts +1 -1
- package/lib/types/{jsx-dev-runtime-BFeiWVJj.d.ts → jsx-dev-runtime-Dm72R_Vm.d.ts} +15 -1
- package/package.json +3 -1
- package/lib/es/chunk-DYTQBEM7.js.map +0 -1
package/lib/es/index.js
CHANGED
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
computeExifTransformMatrix,
|
|
61
61
|
computeExpandedTextHeightMm,
|
|
62
62
|
computeExpandedTextHeightPt,
|
|
63
|
+
computeFontUrlCacheKey,
|
|
63
64
|
computeImageFitPlacement,
|
|
64
65
|
computePasteCascadeOffset,
|
|
65
66
|
computePdfTableSummaryRow,
|
|
@@ -175,7 +176,7 @@ import {
|
|
|
175
176
|
visitTemplateVariables,
|
|
176
177
|
wrapMixedCjkAndLatinLines,
|
|
177
178
|
wrapPdfTextLines
|
|
178
|
-
} from "./chunk-
|
|
179
|
+
} from "./chunk-EMSHTYYU.js";
|
|
179
180
|
import {
|
|
180
181
|
Fragment,
|
|
181
182
|
PDF_JSX_ELEMENT_SYMBOL,
|
|
@@ -7376,6 +7377,237 @@ function createPdfBrowserFidelitySamples() {
|
|
|
7376
7377
|
s7DefaultNoFont
|
|
7377
7378
|
};
|
|
7378
7379
|
}
|
|
7380
|
+
function stripUndefinedDeep(val) {
|
|
7381
|
+
return JSON.parse(JSON.stringify(val));
|
|
7382
|
+
}
|
|
7383
|
+
function createPdfBrowserFidelityExpectations() {
|
|
7384
|
+
const samples = createPdfBrowserFidelitySamples();
|
|
7385
|
+
const entries = [
|
|
7386
|
+
{
|
|
7387
|
+
id: "S1",
|
|
7388
|
+
sampleKey: "s1ShortCjk",
|
|
7389
|
+
title: samples.s1ShortCjk.name,
|
|
7390
|
+
inputSnapshot: stripUndefinedDeep(samples.s1ShortCjk),
|
|
7391
|
+
renderScenario: {
|
|
7392
|
+
cjkTextMode: "subset-ttf",
|
|
7393
|
+
suppliesSubsetFont: true,
|
|
7394
|
+
omitsRenderOptions: false,
|
|
7395
|
+
description: "subset-ttf vector CJK short text, fullwidth punctuation, and mixed CJK/Latin"
|
|
7396
|
+
},
|
|
7397
|
+
expected: {
|
|
7398
|
+
pageCount: 1,
|
|
7399
|
+
tableRowsPerPage: [],
|
|
7400
|
+
extractableTextSnippetsByPage: [
|
|
7401
|
+
[
|
|
7402
|
+
"Monthly Report \xB7 \u6708\u5EA6\u7ECF\u8425\u7B80\u62A5\uFF082026\uFF09",
|
|
7403
|
+
"Vector Subset Font & ToUnicode Verification Sample",
|
|
7404
|
+
"Report Period:",
|
|
7405
|
+
"\u4E00\u6708\uFF082026Q1\uFF09",
|
|
7406
|
+
"\u534E\u4E1C\xB7\u4E0A\u6D77\u6D66\u4E1C\u5F20\u6C5F\u9AD8\u79D1\u6280\u56ED\u533A",
|
|
7407
|
+
"\u5DF2\u6838\u9A8C\uFF1A\u4E13\u7968\u901A\u8FC7\uFF01\u3010\u6279\u6B21 A-108\u3011",
|
|
7408
|
+
"\u6838\u5FC3\u6A21\u5757 Controller-V2 \u5B8C\u6210\u5EA6 98.5\uFF05\uFF1B\u6B21\u65E5\u8FBE\u6B63\u5E38\uFF0C\u201C\u96F6\u5DEE\u9519\u201D\u4EA4\u4ED8"
|
|
7409
|
+
]
|
|
7410
|
+
],
|
|
7411
|
+
embedsType0SubsetFont: true,
|
|
7412
|
+
usesRasterTextImages: false
|
|
7413
|
+
}
|
|
7414
|
+
},
|
|
7415
|
+
{
|
|
7416
|
+
id: "S2",
|
|
7417
|
+
sampleKey: "s2LongTextBox",
|
|
7418
|
+
title: samples.s2LongTextBox.name,
|
|
7419
|
+
inputSnapshot: stripUndefinedDeep(samples.s2LongTextBox),
|
|
7420
|
+
renderScenario: {
|
|
7421
|
+
cjkTextMode: "subset-ttf",
|
|
7422
|
+
suppliesSubsetFont: true,
|
|
7423
|
+
omitsRenderOptions: false,
|
|
7424
|
+
description: "subset-ttf multi-paragraph wrapping, 3x3 alignment, box clipping, and autoFitFontSize shrink"
|
|
7425
|
+
},
|
|
7426
|
+
expected: {
|
|
7427
|
+
pageCount: 1,
|
|
7428
|
+
tableRowsPerPage: [],
|
|
7429
|
+
extractableTextSnippetsByPage: [
|
|
7430
|
+
[
|
|
7431
|
+
"S2 \u591A\u6BB5\u6DF7\u6392\u957F\u6587\u672C\u6846",
|
|
7432
|
+
"English words wrap cleanly while",
|
|
7433
|
+
"\u5C45\u4E2D\xB7\u5782\u76F4\u5C45\u4E2D\u793A\u4F8B\uFF08Center / Middle\uFF09",
|
|
7434
|
+
"99.2\uFF05",
|
|
7435
|
+
"\u53F3\u5BF9\u9F50\xB7\u5E95\u90E8\u793A\u4F8B\uFF08Right / Bottom\uFF09",
|
|
7436
|
+
"2026-01-31",
|
|
7437
|
+
"\u7F29\u5C0F\u5B57\u53F7\u81EA\u9002\u5E94\u793A\u4F8B\uFF08autoFitFontSize\uFF09",
|
|
7438
|
+
"Batch-2026-Q1"
|
|
7439
|
+
]
|
|
7440
|
+
],
|
|
7441
|
+
embedsType0SubsetFont: true,
|
|
7442
|
+
usesRasterTextImages: false
|
|
7443
|
+
}
|
|
7444
|
+
},
|
|
7445
|
+
{
|
|
7446
|
+
id: "S3",
|
|
7447
|
+
sampleKey: "s3SinglePageTable",
|
|
7448
|
+
title: samples.s3SinglePageTable.name,
|
|
7449
|
+
inputSnapshot: stripUndefinedDeep(samples.s3SinglePageTable),
|
|
7450
|
+
renderScenario: {
|
|
7451
|
+
cjkTextMode: "subset-ttf",
|
|
7452
|
+
suppliesSubsetFont: true,
|
|
7453
|
+
omitsRenderOptions: false,
|
|
7454
|
+
description: "subset-ttf single-page 5-column (1:2:1:1:1) formatted table with zebra stripes"
|
|
7455
|
+
},
|
|
7456
|
+
expected: {
|
|
7457
|
+
pageCount: 1,
|
|
7458
|
+
tableRowsPerPage: [6],
|
|
7459
|
+
extractableTextSnippetsByPage: [
|
|
7460
|
+
[
|
|
7461
|
+
"S3 \u91C7\u8D2D\u51FA\u5E93\u6838\u9A8C\u5355\u9875\u660E\u7EC6\u8868",
|
|
7462
|
+
"\u5546\u54C1\u89C4\u683C\u8BF4\u660E",
|
|
7463
|
+
"A-01",
|
|
7464
|
+
"\u5DE5\u4E1A\u4F20\u611F\u5668\u6A21\u5757\uFF08\u534E\u4E1C\u6807\u51C6\u7248\uFF09",
|
|
7465
|
+
"1,200",
|
|
7466
|
+
"\xA5358.50",
|
|
7467
|
+
"98.5%",
|
|
7468
|
+
"A-06",
|
|
7469
|
+
"\xA52,150.40",
|
|
7470
|
+
"95.0%"
|
|
7471
|
+
]
|
|
7472
|
+
],
|
|
7473
|
+
embedsType0SubsetFont: true,
|
|
7474
|
+
usesRasterTextImages: false
|
|
7475
|
+
}
|
|
7476
|
+
},
|
|
7477
|
+
{
|
|
7478
|
+
id: "S4",
|
|
7479
|
+
sampleKey: "s4CellOverflow",
|
|
7480
|
+
title: samples.s4CellOverflow.name,
|
|
7481
|
+
inputSnapshot: stripUndefinedDeep(samples.s4CellOverflow),
|
|
7482
|
+
renderScenario: {
|
|
7483
|
+
cjkTextMode: "subset-ttf",
|
|
7484
|
+
suppliesSubsetFont: true,
|
|
7485
|
+
omitsRenderOptions: false,
|
|
7486
|
+
description: "subset-ttf narrow-column cell overflow clipping and table autoFitFontSize"
|
|
7487
|
+
},
|
|
7488
|
+
expected: {
|
|
7489
|
+
pageCount: 1,
|
|
7490
|
+
tableRowsPerPage: [2],
|
|
7491
|
+
extractableTextSnippetsByPage: [
|
|
7492
|
+
[
|
|
7493
|
+
"S4-A \u9ED8\u8BA4\u56FA\u5B9A\u884C\u9AD8\uFF0824pt\uFF09\u7A84\u5217\u6EA2\u51FA\u4E25\u683C\u88C1\u5207",
|
|
7494
|
+
"\u7A84\u5217\u957F\u4E2D\u6587",
|
|
7495
|
+
"\u7A84\u5217\u8D85\u957F\u897F\u6587",
|
|
7496
|
+
"\u6B63\u5E38\u90BB\u683C A1",
|
|
7497
|
+
"\u6B63\u5E38\u90BB\u683C A2",
|
|
7498
|
+
"S4-B \u5F00\u542F\u8868\u683C\u5355\u5143\u683C\u7F29\u5C0F\u5B57\u53F7"
|
|
7499
|
+
]
|
|
7500
|
+
],
|
|
7501
|
+
embedsType0SubsetFont: true,
|
|
7502
|
+
usesRasterTextImages: false
|
|
7503
|
+
}
|
|
7504
|
+
},
|
|
7505
|
+
{
|
|
7506
|
+
id: "S5",
|
|
7507
|
+
sampleKey: "s5MultiPageTable",
|
|
7508
|
+
title: samples.s5MultiPageTable.name,
|
|
7509
|
+
inputSnapshot: stripUndefinedDeep(samples.s5MultiPageTable),
|
|
7510
|
+
renderScenario: {
|
|
7511
|
+
cjkTextMode: "subset-ttf",
|
|
7512
|
+
suppliesSubsetFont: true,
|
|
7513
|
+
omitsRenderOptions: false,
|
|
7514
|
+
description: "subset-ttf 35-row multi-page table (14 + 14 + 7) with repeated headers and trailing footer flow"
|
|
7515
|
+
},
|
|
7516
|
+
expected: {
|
|
7517
|
+
pageCount: 3,
|
|
7518
|
+
tableRowsPerPage: [14, 14, 7],
|
|
7519
|
+
extractableTextSnippetsByPage: [
|
|
7520
|
+
[
|
|
7521
|
+
"S5 \u591A\u9875\u51FA\u5165\u5E93\u6838\u9A8C\u660E\u7EC6\u8868",
|
|
7522
|
+
"\u5355\u636E\u72B6\u6001\uFF1A\u5DF2\u6838\u9A8C",
|
|
7523
|
+
"\u8BA2\u5355\u7F16\u53F7",
|
|
7524
|
+
"R-01",
|
|
7525
|
+
"\u534E\u4E1C\u4E0A\u6D77\u56ED\u533A\xB7\u5DE5\u4E1A\u4F20\u611F\u5668\u6A21\u5757",
|
|
7526
|
+
"\xA5125.50",
|
|
7527
|
+
"R-14",
|
|
7528
|
+
"\xA51,757.00"
|
|
7529
|
+
],
|
|
7530
|
+
[
|
|
7531
|
+
"\u8BA2\u5355\u7F16\u53F7",
|
|
7532
|
+
"R-15",
|
|
7533
|
+
"\xA51,882.50",
|
|
7534
|
+
"R-28",
|
|
7535
|
+
"\xA53,514.00"
|
|
7536
|
+
],
|
|
7537
|
+
[
|
|
7538
|
+
"\u8BA2\u5355\u7F16\u53F7",
|
|
7539
|
+
"R-29",
|
|
7540
|
+
"\xA53,639.50",
|
|
7541
|
+
"R-35",
|
|
7542
|
+
"\xA54,392.50",
|
|
7543
|
+
"\u8868\u540E\u7B7E\u6536\u680F\uFF1A\u5BA1\u6279\u4EBA \u5F20\u5DE5 \uFF5C \u8D22\u52A1\u4E13\u7528\u7AE0 \uFF5C \u4ED3\u5E93\u7B7E\u7AE0"
|
|
7544
|
+
]
|
|
7545
|
+
],
|
|
7546
|
+
embedsType0SubsetFont: true,
|
|
7547
|
+
usesRasterTextImages: false
|
|
7548
|
+
}
|
|
7549
|
+
},
|
|
7550
|
+
{
|
|
7551
|
+
id: "S6",
|
|
7552
|
+
sampleKey: "s6MissingGlyphs",
|
|
7553
|
+
title: samples.s6MissingGlyphs.name,
|
|
7554
|
+
inputSnapshot: stripUndefinedDeep(samples.s6MissingGlyphs),
|
|
7555
|
+
renderScenario: {
|
|
7556
|
+
cjkTextMode: "subset-ttf",
|
|
7557
|
+
suppliesSubsetFont: true,
|
|
7558
|
+
omitsRenderOptions: false,
|
|
7559
|
+
missingGlyph: "warn",
|
|
7560
|
+
description: "subset-ttf missing-glyph diagnostics ('error' throws MISSING_GLYPH; 'warn' emits warning and renders)"
|
|
7561
|
+
},
|
|
7562
|
+
expected: {
|
|
7563
|
+
pageCount: 1,
|
|
7564
|
+
tableRowsPerPage: [],
|
|
7565
|
+
extractableTextSnippetsByPage: [
|
|
7566
|
+
[
|
|
7567
|
+
"Monthly Report \xB7 \u6708\u5EA6\u7ECF\u8425\u7B80\u62A5\uFF082026\uFF09",
|
|
7568
|
+
"\u4E00\u6708\uFF082026Q1\uFF09",
|
|
7569
|
+
"\u7F3A\u5B57\u8BCA\u65AD\u5907\u6CE8\uFF1A\u751F\u50FB\u5B57",
|
|
7570
|
+
"\u4E0E\u56FE\u6807",
|
|
7571
|
+
"\u6838\u9A8C"
|
|
7572
|
+
]
|
|
7573
|
+
],
|
|
7574
|
+
embedsType0SubsetFont: true,
|
|
7575
|
+
usesRasterTextImages: false,
|
|
7576
|
+
expectedErrorWhenStrict: {
|
|
7577
|
+
code: "MISSING_GLYPH",
|
|
7578
|
+
pageId: "page-1",
|
|
7579
|
+
elementId: "s6-missing-note",
|
|
7580
|
+
missingCodePoints: ["U+9F98", "U+1F680"]
|
|
7581
|
+
}
|
|
7582
|
+
}
|
|
7583
|
+
},
|
|
7584
|
+
{
|
|
7585
|
+
id: "S7",
|
|
7586
|
+
sampleKey: "s7DefaultNoFont",
|
|
7587
|
+
title: samples.s7DefaultNoFont.name,
|
|
7588
|
+
inputSnapshot: stripUndefinedDeep(samples.s7DefaultNoFont),
|
|
7589
|
+
renderScenario: {
|
|
7590
|
+
cjkTextMode: "raster-hd",
|
|
7591
|
+
suppliesSubsetFont: false,
|
|
7592
|
+
omitsRenderOptions: true,
|
|
7593
|
+
description: "default omitted render options preserving raster-hd compatibility without fonts"
|
|
7594
|
+
},
|
|
7595
|
+
expected: {
|
|
7596
|
+
pageCount: 1,
|
|
7597
|
+
tableRowsPerPage: [],
|
|
7598
|
+
extractableTextSnippetsByPage: [],
|
|
7599
|
+
embedsType0SubsetFont: false,
|
|
7600
|
+
usesRasterTextImages: true
|
|
7601
|
+
}
|
|
7602
|
+
}
|
|
7603
|
+
];
|
|
7604
|
+
return {
|
|
7605
|
+
schema: "univer-pdf-fidelity-expectations",
|
|
7606
|
+
version: 1,
|
|
7607
|
+
samples: entries
|
|
7608
|
+
};
|
|
7609
|
+
}
|
|
7610
|
+
var PDF_S1_S7_FIDELITY_EXPECTATIONS = Object.freeze(createPdfBrowserFidelityExpectations());
|
|
7379
7611
|
|
|
7380
7612
|
// src/plugin.ts
|
|
7381
7613
|
import {
|
|
@@ -7799,7 +8031,51 @@ function detectImportFileFormat(file) {
|
|
|
7799
8031
|
}
|
|
7800
8032
|
return "pdf";
|
|
7801
8033
|
}
|
|
7802
|
-
function
|
|
8034
|
+
function createPdfAbortError(signal) {
|
|
8035
|
+
const reason = signal?.reason;
|
|
8036
|
+
if (reason && typeof reason === "object" && reason.name === "AbortError") {
|
|
8037
|
+
return reason;
|
|
8038
|
+
}
|
|
8039
|
+
return typeof DOMException === "function" ? new DOMException("The operation was aborted.", "AbortError") : Object.assign(new Error("The operation was aborted."), { name: "AbortError" });
|
|
8040
|
+
}
|
|
8041
|
+
function isAbortErrorLike(err) {
|
|
8042
|
+
return Boolean(err && typeof err === "object" && err.name === "AbortError");
|
|
8043
|
+
}
|
|
8044
|
+
function throwIfSignalAborted(signal) {
|
|
8045
|
+
if (signal?.aborted) {
|
|
8046
|
+
throw createPdfAbortError(signal);
|
|
8047
|
+
}
|
|
8048
|
+
}
|
|
8049
|
+
async function raceWithAbortSignal(promise, signal) {
|
|
8050
|
+
throwIfSignalAborted(signal);
|
|
8051
|
+
if (!signal) {
|
|
8052
|
+
return promise;
|
|
8053
|
+
}
|
|
8054
|
+
let onAbort = null;
|
|
8055
|
+
const abortPromise = new Promise((_, reject) => {
|
|
8056
|
+
if (signal.aborted) {
|
|
8057
|
+
reject(createPdfAbortError(signal));
|
|
8058
|
+
return;
|
|
8059
|
+
}
|
|
8060
|
+
onAbort = () => reject(createPdfAbortError(signal));
|
|
8061
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
8062
|
+
});
|
|
8063
|
+
void promise.catch(() => {
|
|
8064
|
+
});
|
|
8065
|
+
try {
|
|
8066
|
+
const result = await Promise.race([promise, abortPromise]);
|
|
8067
|
+
throwIfSignalAborted(signal);
|
|
8068
|
+
return result;
|
|
8069
|
+
} finally {
|
|
8070
|
+
if (onAbort) {
|
|
8071
|
+
signal.removeEventListener("abort", onAbort);
|
|
8072
|
+
}
|
|
8073
|
+
}
|
|
8074
|
+
}
|
|
8075
|
+
function attachSuggestedFallbackAndThrow(err, fallback, signal) {
|
|
8076
|
+
if (signal?.aborted || isAbortErrorLike(err)) {
|
|
8077
|
+
throw isAbortErrorLike(err) ? err : createPdfAbortError(signal);
|
|
8078
|
+
}
|
|
7803
8079
|
if (err && typeof err === "object") {
|
|
7804
8080
|
if (!err.suggestedFallback) {
|
|
7805
8081
|
try {
|
|
@@ -7814,6 +8090,7 @@ function attachSuggestedFallbackAndThrow(err, fallback) {
|
|
|
7814
8090
|
throw wrapped;
|
|
7815
8091
|
}
|
|
7816
8092
|
async function importPdfSource(source, options) {
|
|
8093
|
+
throwIfSignalAborted(options?.signal);
|
|
7817
8094
|
let bytes;
|
|
7818
8095
|
let fileName = options?.fileName || "imported.pdf";
|
|
7819
8096
|
if (source instanceof Uint8Array) {
|
|
@@ -7845,7 +8122,7 @@ async function importPdfSource(source, options) {
|
|
|
7845
8122
|
if ("name" in source && typeof source.name === "string" && source.name) {
|
|
7846
8123
|
fileName = options?.fileName || source.name;
|
|
7847
8124
|
}
|
|
7848
|
-
const ab = await source.arrayBuffer();
|
|
8125
|
+
const ab = await raceWithAbortSignal(source.arrayBuffer(), options?.signal);
|
|
7849
8126
|
bytes = new Uint8Array(ab);
|
|
7850
8127
|
} else {
|
|
7851
8128
|
throw new PdfImportError("INVALID_PDF_HEADER", "Unsupported PDF input source.");
|
|
@@ -7856,7 +8133,9 @@ async function importPdfSource(source, options) {
|
|
|
7856
8133
|
"Invalid PDF binary: missing %PDF- header signature."
|
|
7857
8134
|
);
|
|
7858
8135
|
}
|
|
8136
|
+
throwIfSignalAborted(options?.signal);
|
|
7859
8137
|
const { PDFArray: PDFArray4, PDFDict: PDFDict4, PDFDocument: PDFDocument4, PDFName: PDFName4 } = await import("pdf-lib");
|
|
8138
|
+
throwIfSignalAborted(options?.signal);
|
|
7860
8139
|
let pageSizes = [];
|
|
7861
8140
|
let warnings = [];
|
|
7862
8141
|
try {
|
|
@@ -7956,6 +8235,7 @@ async function importPdfSource(source, options) {
|
|
|
7956
8235
|
throw new PdfImportError("CORRUPT_PDF", `Corrupt PDF binary: ${errMsg}`);
|
|
7957
8236
|
}
|
|
7958
8237
|
}
|
|
8238
|
+
throwIfSignalAborted(options?.signal);
|
|
7959
8239
|
const b64 = uint8ToBase64(bytes);
|
|
7960
8240
|
const dataUri = `data:application/pdf;base64,${b64}`;
|
|
7961
8241
|
return {
|
|
@@ -7972,9 +8252,11 @@ async function importPdfSource(source, options) {
|
|
|
7972
8252
|
warnings
|
|
7973
8253
|
};
|
|
7974
8254
|
}
|
|
7975
|
-
async function fallbackReadFileAsOutcome(file, baseSnapshot, password) {
|
|
8255
|
+
async function fallbackReadFileAsOutcome(file, baseSnapshot, password, signal, explicitFileName) {
|
|
8256
|
+
throwIfSignalAborted(signal);
|
|
7976
8257
|
if (detectImportFileFormat(file) === "json") {
|
|
7977
|
-
const rawText = typeof file.text === "function" ? await file.text() : new TextDecoder().decode(await file.arrayBuffer());
|
|
8258
|
+
const rawText = typeof file.text === "function" ? await raceWithAbortSignal(file.text(), signal) : new TextDecoder().decode(await raceWithAbortSignal(file.arrayBuffer(), signal));
|
|
8259
|
+
throwIfSignalAborted(signal);
|
|
7978
8260
|
let parsed;
|
|
7979
8261
|
try {
|
|
7980
8262
|
parsed = JSON.parse(rawText);
|
|
@@ -7998,7 +8280,10 @@ async function fallbackReadFileAsOutcome(file, baseSnapshot, password) {
|
|
|
7998
8280
|
mode: "snapshot",
|
|
7999
8281
|
snapshot: fromPdfmeTemplate(parsed, {
|
|
8000
8282
|
id: baseSnapshot.id,
|
|
8001
|
-
name: (file.name || baseSnapshot.name || "Imported Template").replace(
|
|
8283
|
+
name: (explicitFileName || file.name || baseSnapshot.name || "Imported Template").replace(
|
|
8284
|
+
/\.json$/i,
|
|
8285
|
+
""
|
|
8286
|
+
)
|
|
8002
8287
|
})
|
|
8003
8288
|
};
|
|
8004
8289
|
}
|
|
@@ -8007,7 +8292,11 @@ async function fallbackReadFileAsOutcome(file, baseSnapshot, password) {
|
|
|
8007
8292
|
"\u672A\u8BC6\u522B\u7684 JSON \u6A21\u677F\u683C\u5F0F\uFF1A\u8BF7\u63D0\u4F9B\u6807\u51C6 IPdfUnitData \u6216 pdfme Template JSON\u3002"
|
|
8008
8293
|
);
|
|
8009
8294
|
}
|
|
8010
|
-
const imported = await importPdfSource(file, {
|
|
8295
|
+
const imported = await importPdfSource(file, {
|
|
8296
|
+
fileName: explicitFileName || file.name || "imported.pdf",
|
|
8297
|
+
password,
|
|
8298
|
+
signal
|
|
8299
|
+
});
|
|
8011
8300
|
return {
|
|
8012
8301
|
mode: "overlay",
|
|
8013
8302
|
sourceDocumentRef: imported.sourceDocumentRef,
|
|
@@ -8237,6 +8526,8 @@ var PdfIoService = class extends Disposable2 {
|
|
|
8237
8526
|
return report.outcome;
|
|
8238
8527
|
}
|
|
8239
8528
|
async importPdfWithReport(file, context) {
|
|
8529
|
+
const signal = context?.signal;
|
|
8530
|
+
throwIfSignalAborted(signal);
|
|
8240
8531
|
const { unitId, baseSnapshot } = this._resolveBaseSnapshotForImport(context);
|
|
8241
8532
|
const adapter = this._adapter$.getValue();
|
|
8242
8533
|
const caps = this.getIoCapabilities();
|
|
@@ -8245,11 +8536,12 @@ var PdfIoService = class extends Disposable2 {
|
|
|
8245
8536
|
const requested = context?.target ?? this.getDefaultIoTarget();
|
|
8246
8537
|
const effective = requested === "auto" ? fmtCap.defaultTarget : requested;
|
|
8247
8538
|
const defaultImport = async (f) => {
|
|
8539
|
+
throwIfSignalAborted(signal);
|
|
8248
8540
|
if (context?.defaultImport) {
|
|
8249
|
-
const customRaw = await context.defaultImport(f);
|
|
8541
|
+
const customRaw = await raceWithAbortSignal(context.defaultImport(f), signal);
|
|
8250
8542
|
return normalizeAdapterImportResult(customRaw).outcome;
|
|
8251
8543
|
}
|
|
8252
|
-
return fallbackReadFileAsOutcome(f, baseSnapshot, context?.password);
|
|
8544
|
+
return fallbackReadFileAsOutcome(f, baseSnapshot, context?.password, signal, context?.fileName);
|
|
8253
8545
|
};
|
|
8254
8546
|
let rawResult;
|
|
8255
8547
|
if (effective === "server") {
|
|
@@ -8259,49 +8551,85 @@ var PdfIoService = class extends Disposable2 {
|
|
|
8259
8551
|
);
|
|
8260
8552
|
}
|
|
8261
8553
|
try {
|
|
8262
|
-
rawResult = await
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8554
|
+
rawResult = await raceWithAbortSignal(
|
|
8555
|
+
adapter.importPdf(file, {
|
|
8556
|
+
unitId,
|
|
8557
|
+
snapshot: Tools6.deepClone(baseSnapshot),
|
|
8558
|
+
...signal ? { signal } : {},
|
|
8559
|
+
defaultImport
|
|
8560
|
+
}),
|
|
8561
|
+
signal
|
|
8562
|
+
);
|
|
8267
8563
|
} catch (err) {
|
|
8268
|
-
attachSuggestedFallbackAndThrow(err, "browser");
|
|
8564
|
+
attachSuggestedFallbackAndThrow(err, "browser", signal);
|
|
8269
8565
|
}
|
|
8270
8566
|
} else {
|
|
8271
8567
|
if (!context?.defaultImport && !fmtCap.browser) {
|
|
8272
8568
|
attachSuggestedFallbackAndThrow(
|
|
8273
8569
|
new Error(`\u5F53\u524D\u6D4F\u89C8\u5668\u7AEF\u672A\u542F\u7528 .${fmt} \u683C\u5F0F\u5BFC\u5165\uFF1B\u8BF7\u5207\u6362\u4E3A\u300C\u670D\u52A1\u7AEF\u5904\u7406\u300D\u91CD\u8BD5`),
|
|
8274
|
-
"server"
|
|
8570
|
+
"server",
|
|
8571
|
+
signal
|
|
8275
8572
|
);
|
|
8276
8573
|
}
|
|
8277
8574
|
try {
|
|
8278
|
-
rawResult = context?.defaultImport ? await context.defaultImport(file) : await fallbackReadFileAsOutcome(
|
|
8575
|
+
rawResult = context?.defaultImport ? await raceWithAbortSignal(context.defaultImport(file), signal) : await fallbackReadFileAsOutcome(
|
|
8576
|
+
file,
|
|
8577
|
+
baseSnapshot,
|
|
8578
|
+
context?.password,
|
|
8579
|
+
signal,
|
|
8580
|
+
context?.fileName
|
|
8581
|
+
);
|
|
8279
8582
|
} catch (err) {
|
|
8280
|
-
attachSuggestedFallbackAndThrow(err, "server");
|
|
8583
|
+
attachSuggestedFallbackAndThrow(err, "server", signal);
|
|
8281
8584
|
}
|
|
8282
8585
|
}
|
|
8586
|
+
throwIfSignalAborted(signal);
|
|
8283
8587
|
const { outcome, warnings } = normalizeAdapterImportResult(rawResult);
|
|
8284
8588
|
const candidateSnapshot = outcome.mode === "snapshot" ? Tools6.deepClone(outcome.snapshot) : buildOverlayImportCandidateSnapshot(baseSnapshot, outcome);
|
|
8589
|
+
throwIfSignalAborted(signal);
|
|
8285
8590
|
return {
|
|
8286
8591
|
snapshot: candidateSnapshot,
|
|
8287
8592
|
outcome,
|
|
8288
8593
|
warnings,
|
|
8289
8594
|
executedBy: effective,
|
|
8290
|
-
fileName: file?.name || (outcome.mode === "overlay" ? outcome.sourceDocumentRef.fileName : candidateSnapshot.name) || void 0
|
|
8595
|
+
fileName: context?.fileName || file?.name || (outcome.mode === "overlay" ? outcome.sourceDocumentRef.fileName : candidateSnapshot.name) || void 0
|
|
8291
8596
|
};
|
|
8292
8597
|
}
|
|
8598
|
+
async exportPdfWithTarget(params) {
|
|
8599
|
+
const signal = params.signal ?? params.options?.signal;
|
|
8600
|
+
throwIfSignalAborted(signal);
|
|
8601
|
+
const { unitId, baseSnapshot } = this._resolveBaseSnapshotForImport({
|
|
8602
|
+
unitId: params.unitId,
|
|
8603
|
+
snapshot: params.snapshot
|
|
8604
|
+
});
|
|
8605
|
+
return this.exportPdf({
|
|
8606
|
+
unitId,
|
|
8607
|
+
snapshot: params.snapshot ?? baseSnapshot,
|
|
8608
|
+
data: params.data,
|
|
8609
|
+
options: params.options,
|
|
8610
|
+
target: params.target,
|
|
8611
|
+
signal
|
|
8612
|
+
});
|
|
8613
|
+
}
|
|
8293
8614
|
async exportPdf(params) {
|
|
8615
|
+
const signal = params.signal ?? params.options?.signal;
|
|
8616
|
+
throwIfSignalAborted(signal);
|
|
8617
|
+
const effectiveOptions = signal ? { ...params.options ?? {}, signal } : params.options;
|
|
8294
8618
|
const beforeEvent = {
|
|
8295
8619
|
unitId: params.unitId,
|
|
8296
8620
|
snapshot: params.snapshot,
|
|
8297
8621
|
data: params.data,
|
|
8298
|
-
options:
|
|
8622
|
+
options: effectiveOptions,
|
|
8299
8623
|
cancel: false
|
|
8300
8624
|
};
|
|
8301
8625
|
if (this.runBeforeExportHooks(beforeEvent)) {
|
|
8302
8626
|
throw new CanceledError();
|
|
8303
8627
|
}
|
|
8304
|
-
|
|
8628
|
+
throwIfSignalAborted(signal);
|
|
8629
|
+
const defaultExport = () => raceWithAbortSignal(
|
|
8630
|
+
exportPdfBytes(params.snapshot, params.data, effectiveOptions),
|
|
8631
|
+
signal
|
|
8632
|
+
);
|
|
8305
8633
|
const adapter = this._adapter$.getValue();
|
|
8306
8634
|
const caps = this.getIoCapabilities();
|
|
8307
8635
|
const pdfExportCap = caps.formats.export.pdf;
|
|
@@ -8315,17 +8643,22 @@ var PdfIoService = class extends Disposable2 {
|
|
|
8315
8643
|
}
|
|
8316
8644
|
let bytes;
|
|
8317
8645
|
try {
|
|
8318
|
-
const raw = await
|
|
8319
|
-
|
|
8320
|
-
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
|
|
8325
|
-
|
|
8646
|
+
const raw = await raceWithAbortSignal(
|
|
8647
|
+
adapter.exportPdf({
|
|
8648
|
+
unitId: params.unitId,
|
|
8649
|
+
snapshot: params.snapshot,
|
|
8650
|
+
data: params.data,
|
|
8651
|
+
options: effectiveOptions,
|
|
8652
|
+
...signal ? { signal } : {},
|
|
8653
|
+
defaultExport
|
|
8654
|
+
}),
|
|
8655
|
+
signal
|
|
8656
|
+
);
|
|
8657
|
+
bytes = await raceWithAbortSignal(normalizeBinaryToUint8Array(raw), signal);
|
|
8326
8658
|
} catch (err) {
|
|
8327
|
-
attachSuggestedFallbackAndThrow(err, "browser");
|
|
8659
|
+
attachSuggestedFallbackAndThrow(err, "browser", signal);
|
|
8328
8660
|
}
|
|
8661
|
+
throwIfSignalAborted(signal);
|
|
8329
8662
|
this.notifyExported({
|
|
8330
8663
|
unitId: params.unitId,
|
|
8331
8664
|
bytes,
|
|
@@ -8337,11 +8670,13 @@ var PdfIoService = class extends Disposable2 {
|
|
|
8337
8670
|
if (!pdfExportCap.browser) {
|
|
8338
8671
|
attachSuggestedFallbackAndThrow(
|
|
8339
8672
|
new Error("\u5F53\u524D\u6D4F\u89C8\u5668\u7AEF\u672A\u542F\u7528 PDF \u5BFC\u51FA\uFF1B\u8BF7\u5207\u6362\u4E3A\u300C\u670D\u52A1\u7AEF\u5904\u7406\u300D\u91CD\u8BD5"),
|
|
8340
|
-
"server"
|
|
8673
|
+
"server",
|
|
8674
|
+
signal
|
|
8341
8675
|
);
|
|
8342
8676
|
}
|
|
8343
8677
|
try {
|
|
8344
8678
|
const bytes = await defaultExport();
|
|
8679
|
+
throwIfSignalAborted(signal);
|
|
8345
8680
|
this.notifyExported({
|
|
8346
8681
|
unitId: params.unitId,
|
|
8347
8682
|
bytes,
|
|
@@ -8350,7 +8685,7 @@ var PdfIoService = class extends Disposable2 {
|
|
|
8350
8685
|
});
|
|
8351
8686
|
return bytes;
|
|
8352
8687
|
} catch (err) {
|
|
8353
|
-
attachSuggestedFallbackAndThrow(err, "server");
|
|
8688
|
+
attachSuggestedFallbackAndThrow(err, "server", signal);
|
|
8354
8689
|
}
|
|
8355
8690
|
}
|
|
8356
8691
|
async silentPrint(params) {
|
|
@@ -8406,6 +8741,42 @@ var PdfIoService = class extends Disposable2 {
|
|
|
8406
8741
|
PdfIoService = __decorateClass([
|
|
8407
8742
|
__decorateParam(0, Optional(IUniverInstanceService4))
|
|
8408
8743
|
], PdfIoService);
|
|
8744
|
+
async function exportPdfWithTarget(arg1, arg2) {
|
|
8745
|
+
if (arg1 && typeof arg1.exportPdfWithTarget === "function") {
|
|
8746
|
+
return arg1.exportPdfWithTarget(arg2 ?? {});
|
|
8747
|
+
}
|
|
8748
|
+
if (arg1 && typeof arg1 === "object" && "document" in arg1 && "editState" in arg1) {
|
|
8749
|
+
const snap = arg1;
|
|
8750
|
+
const extIo = arg2?.ioService;
|
|
8751
|
+
if (extIo) {
|
|
8752
|
+
return extIo.exportPdfWithTarget({
|
|
8753
|
+
...arg2,
|
|
8754
|
+
unitId: arg2?.unitId ?? snap.id,
|
|
8755
|
+
snapshot: snap
|
|
8756
|
+
});
|
|
8757
|
+
}
|
|
8758
|
+
const localIo2 = new PdfIoService();
|
|
8759
|
+
try {
|
|
8760
|
+
return await localIo2.exportPdfWithTarget({
|
|
8761
|
+
...arg2,
|
|
8762
|
+
unitId: arg2?.unitId ?? snap.id,
|
|
8763
|
+
snapshot: snap
|
|
8764
|
+
});
|
|
8765
|
+
} finally {
|
|
8766
|
+
localIo2.dispose();
|
|
8767
|
+
}
|
|
8768
|
+
}
|
|
8769
|
+
const unified = arg1;
|
|
8770
|
+
if (unified.ioService) {
|
|
8771
|
+
return unified.ioService.exportPdfWithTarget(unified);
|
|
8772
|
+
}
|
|
8773
|
+
const localIo = new PdfIoService();
|
|
8774
|
+
try {
|
|
8775
|
+
return await localIo.exportPdfWithTarget(unified);
|
|
8776
|
+
} finally {
|
|
8777
|
+
localIo.dispose();
|
|
8778
|
+
}
|
|
8779
|
+
}
|
|
8409
8780
|
|
|
8410
8781
|
// src/plugin.ts
|
|
8411
8782
|
var UNIVER_PDFS_PLUGIN_NAME = "UNIVER_PDFS_PLUGIN";
|
|
@@ -8546,6 +8917,7 @@ export {
|
|
|
8546
8917
|
PDF_JSX_ELEMENT_SYMBOL,
|
|
8547
8918
|
PDF_JSX_FRAGMENT_SYMBOL,
|
|
8548
8919
|
PDF_PAGE_PRESETS,
|
|
8920
|
+
PDF_S1_S7_FIDELITY_EXPECTATIONS,
|
|
8549
8921
|
PDF_TABLE_THEME_PRESETS,
|
|
8550
8922
|
PT_PER_MM,
|
|
8551
8923
|
Page,
|
|
@@ -8628,6 +9000,7 @@ export {
|
|
|
8628
9000
|
computeExifTransformMatrix,
|
|
8629
9001
|
computeExpandedTextHeightMm,
|
|
8630
9002
|
computeExpandedTextHeightPt,
|
|
9003
|
+
computeFontUrlCacheKey,
|
|
8631
9004
|
computeImageFitPlacement,
|
|
8632
9005
|
computePasteCascadeOffset,
|
|
8633
9006
|
computePdfPayloadDigest,
|
|
@@ -8644,6 +9017,8 @@ export {
|
|
|
8644
9017
|
createDefaultElement,
|
|
8645
9018
|
createDefaultPdfUnitData,
|
|
8646
9019
|
createHttpSilentPrintAdapter,
|
|
9020
|
+
createPdfAbortError,
|
|
9021
|
+
createPdfBrowserFidelityExpectations,
|
|
8647
9022
|
createPdfBrowserFidelitySamples,
|
|
8648
9023
|
createPdfCjkFontSources,
|
|
8649
9024
|
createPdfJsxNode,
|
|
@@ -8681,6 +9056,7 @@ export {
|
|
|
8681
9056
|
exportPdfBytes,
|
|
8682
9057
|
exportPdfToDocxSnapshot,
|
|
8683
9058
|
exportPdfToWorkbookSnapshot,
|
|
9059
|
+
exportPdfWithTarget,
|
|
8684
9060
|
exportSignedPdfWithAuditSeal,
|
|
8685
9061
|
exportToPdfmeTemplate,
|
|
8686
9062
|
extractAcroFormValuesFromPdfBytes,
|