@yudaocode/univer-pdfs 1.6.214 → 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/lib/es/index.js CHANGED
@@ -5,6 +5,10 @@ import {
5
5
  Barcode,
6
6
  Box,
7
7
  CIRCLE_MARK_BEZIER_KAPPA,
8
+ DEFAULT_PDF_CJK_FONT_FAMILY,
9
+ DEFAULT_PDF_CJK_FONT_FILES,
10
+ DEFAULT_PDF_CJK_FONT_PACKAGE,
11
+ DEFAULT_PDF_CJK_FONT_VERSION,
8
12
  Document,
9
13
  Ellipse,
10
14
  Footer,
@@ -56,11 +60,13 @@ import {
56
60
  computeExifTransformMatrix,
57
61
  computeExpandedTextHeightMm,
58
62
  computeExpandedTextHeightPt,
63
+ computeFontUrlCacheKey,
59
64
  computeImageFitPlacement,
60
65
  computePasteCascadeOffset,
61
66
  computePdfTableSummaryRow,
62
67
  computeSmartSnapWithEqualGap,
63
68
  createDefaultPdfUnitData,
69
+ createPdfCjkFontSources,
64
70
  detectCJKCharacters,
65
71
  detectCJKInPdfInputs,
66
72
  detectCJKInPdfTemplate,
@@ -170,7 +176,7 @@ import {
170
176
  visitTemplateVariables,
171
177
  wrapMixedCjkAndLatinLines,
172
178
  wrapPdfTextLines
173
- } from "./chunk-4A226M74.js";
179
+ } from "./chunk-EMSHTYYU.js";
174
180
  import {
175
181
  Fragment,
176
182
  PDF_JSX_ELEMENT_SYMBOL,
@@ -7371,6 +7377,237 @@ function createPdfBrowserFidelitySamples() {
7371
7377
  s7DefaultNoFont
7372
7378
  };
7373
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());
7374
7611
 
7375
7612
  // src/plugin.ts
7376
7613
  import {
@@ -7794,7 +8031,51 @@ function detectImportFileFormat(file) {
7794
8031
  }
7795
8032
  return "pdf";
7796
8033
  }
7797
- function attachSuggestedFallbackAndThrow(err, fallback) {
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
+ }
7798
8079
  if (err && typeof err === "object") {
7799
8080
  if (!err.suggestedFallback) {
7800
8081
  try {
@@ -7809,6 +8090,7 @@ function attachSuggestedFallbackAndThrow(err, fallback) {
7809
8090
  throw wrapped;
7810
8091
  }
7811
8092
  async function importPdfSource(source, options) {
8093
+ throwIfSignalAborted(options?.signal);
7812
8094
  let bytes;
7813
8095
  let fileName = options?.fileName || "imported.pdf";
7814
8096
  if (source instanceof Uint8Array) {
@@ -7840,7 +8122,7 @@ async function importPdfSource(source, options) {
7840
8122
  if ("name" in source && typeof source.name === "string" && source.name) {
7841
8123
  fileName = options?.fileName || source.name;
7842
8124
  }
7843
- const ab = await source.arrayBuffer();
8125
+ const ab = await raceWithAbortSignal(source.arrayBuffer(), options?.signal);
7844
8126
  bytes = new Uint8Array(ab);
7845
8127
  } else {
7846
8128
  throw new PdfImportError("INVALID_PDF_HEADER", "Unsupported PDF input source.");
@@ -7851,7 +8133,9 @@ async function importPdfSource(source, options) {
7851
8133
  "Invalid PDF binary: missing %PDF- header signature."
7852
8134
  );
7853
8135
  }
8136
+ throwIfSignalAborted(options?.signal);
7854
8137
  const { PDFArray: PDFArray4, PDFDict: PDFDict4, PDFDocument: PDFDocument4, PDFName: PDFName4 } = await import("pdf-lib");
8138
+ throwIfSignalAborted(options?.signal);
7855
8139
  let pageSizes = [];
7856
8140
  let warnings = [];
7857
8141
  try {
@@ -7951,6 +8235,7 @@ async function importPdfSource(source, options) {
7951
8235
  throw new PdfImportError("CORRUPT_PDF", `Corrupt PDF binary: ${errMsg}`);
7952
8236
  }
7953
8237
  }
8238
+ throwIfSignalAborted(options?.signal);
7954
8239
  const b64 = uint8ToBase64(bytes);
7955
8240
  const dataUri = `data:application/pdf;base64,${b64}`;
7956
8241
  return {
@@ -7967,9 +8252,11 @@ async function importPdfSource(source, options) {
7967
8252
  warnings
7968
8253
  };
7969
8254
  }
7970
- async function fallbackReadFileAsOutcome(file, baseSnapshot, password) {
8255
+ async function fallbackReadFileAsOutcome(file, baseSnapshot, password, signal, explicitFileName) {
8256
+ throwIfSignalAborted(signal);
7971
8257
  if (detectImportFileFormat(file) === "json") {
7972
- 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);
7973
8260
  let parsed;
7974
8261
  try {
7975
8262
  parsed = JSON.parse(rawText);
@@ -7993,7 +8280,10 @@ async function fallbackReadFileAsOutcome(file, baseSnapshot, password) {
7993
8280
  mode: "snapshot",
7994
8281
  snapshot: fromPdfmeTemplate(parsed, {
7995
8282
  id: baseSnapshot.id,
7996
- name: (file.name || baseSnapshot.name || "Imported Template").replace(/\.json$/i, "")
8283
+ name: (explicitFileName || file.name || baseSnapshot.name || "Imported Template").replace(
8284
+ /\.json$/i,
8285
+ ""
8286
+ )
7997
8287
  })
7998
8288
  };
7999
8289
  }
@@ -8002,7 +8292,11 @@ async function fallbackReadFileAsOutcome(file, baseSnapshot, password) {
8002
8292
  "\u672A\u8BC6\u522B\u7684 JSON \u6A21\u677F\u683C\u5F0F\uFF1A\u8BF7\u63D0\u4F9B\u6807\u51C6 IPdfUnitData \u6216 pdfme Template JSON\u3002"
8003
8293
  );
8004
8294
  }
8005
- const imported = await importPdfSource(file, { fileName: file.name || "imported.pdf", password });
8295
+ const imported = await importPdfSource(file, {
8296
+ fileName: explicitFileName || file.name || "imported.pdf",
8297
+ password,
8298
+ signal
8299
+ });
8006
8300
  return {
8007
8301
  mode: "overlay",
8008
8302
  sourceDocumentRef: imported.sourceDocumentRef,
@@ -8232,6 +8526,8 @@ var PdfIoService = class extends Disposable2 {
8232
8526
  return report.outcome;
8233
8527
  }
8234
8528
  async importPdfWithReport(file, context) {
8529
+ const signal = context?.signal;
8530
+ throwIfSignalAborted(signal);
8235
8531
  const { unitId, baseSnapshot } = this._resolveBaseSnapshotForImport(context);
8236
8532
  const adapter = this._adapter$.getValue();
8237
8533
  const caps = this.getIoCapabilities();
@@ -8240,11 +8536,12 @@ var PdfIoService = class extends Disposable2 {
8240
8536
  const requested = context?.target ?? this.getDefaultIoTarget();
8241
8537
  const effective = requested === "auto" ? fmtCap.defaultTarget : requested;
8242
8538
  const defaultImport = async (f) => {
8539
+ throwIfSignalAborted(signal);
8243
8540
  if (context?.defaultImport) {
8244
- const customRaw = await context.defaultImport(f);
8541
+ const customRaw = await raceWithAbortSignal(context.defaultImport(f), signal);
8245
8542
  return normalizeAdapterImportResult(customRaw).outcome;
8246
8543
  }
8247
- return fallbackReadFileAsOutcome(f, baseSnapshot, context?.password);
8544
+ return fallbackReadFileAsOutcome(f, baseSnapshot, context?.password, signal, context?.fileName);
8248
8545
  };
8249
8546
  let rawResult;
8250
8547
  if (effective === "server") {
@@ -8254,49 +8551,85 @@ var PdfIoService = class extends Disposable2 {
8254
8551
  );
8255
8552
  }
8256
8553
  try {
8257
- rawResult = await adapter.importPdf(file, {
8258
- unitId,
8259
- snapshot: Tools6.deepClone(baseSnapshot),
8260
- defaultImport
8261
- });
8554
+ rawResult = await raceWithAbortSignal(
8555
+ adapter.importPdf(file, {
8556
+ unitId,
8557
+ snapshot: Tools6.deepClone(baseSnapshot),
8558
+ ...signal ? { signal } : {},
8559
+ defaultImport
8560
+ }),
8561
+ signal
8562
+ );
8262
8563
  } catch (err) {
8263
- attachSuggestedFallbackAndThrow(err, "browser");
8564
+ attachSuggestedFallbackAndThrow(err, "browser", signal);
8264
8565
  }
8265
8566
  } else {
8266
8567
  if (!context?.defaultImport && !fmtCap.browser) {
8267
8568
  attachSuggestedFallbackAndThrow(
8268
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`),
8269
- "server"
8570
+ "server",
8571
+ signal
8270
8572
  );
8271
8573
  }
8272
8574
  try {
8273
- rawResult = context?.defaultImport ? await context.defaultImport(file) : await fallbackReadFileAsOutcome(file, baseSnapshot, context?.password);
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
+ );
8274
8582
  } catch (err) {
8275
- attachSuggestedFallbackAndThrow(err, "server");
8583
+ attachSuggestedFallbackAndThrow(err, "server", signal);
8276
8584
  }
8277
8585
  }
8586
+ throwIfSignalAborted(signal);
8278
8587
  const { outcome, warnings } = normalizeAdapterImportResult(rawResult);
8279
8588
  const candidateSnapshot = outcome.mode === "snapshot" ? Tools6.deepClone(outcome.snapshot) : buildOverlayImportCandidateSnapshot(baseSnapshot, outcome);
8589
+ throwIfSignalAborted(signal);
8280
8590
  return {
8281
8591
  snapshot: candidateSnapshot,
8282
8592
  outcome,
8283
8593
  warnings,
8284
8594
  executedBy: effective,
8285
- 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
8286
8596
  };
8287
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
+ }
8288
8614
  async exportPdf(params) {
8615
+ const signal = params.signal ?? params.options?.signal;
8616
+ throwIfSignalAborted(signal);
8617
+ const effectiveOptions = signal ? { ...params.options ?? {}, signal } : params.options;
8289
8618
  const beforeEvent = {
8290
8619
  unitId: params.unitId,
8291
8620
  snapshot: params.snapshot,
8292
8621
  data: params.data,
8293
- options: params.options,
8622
+ options: effectiveOptions,
8294
8623
  cancel: false
8295
8624
  };
8296
8625
  if (this.runBeforeExportHooks(beforeEvent)) {
8297
8626
  throw new CanceledError();
8298
8627
  }
8299
- const defaultExport = () => exportPdfBytes(params.snapshot, params.data, params.options);
8628
+ throwIfSignalAborted(signal);
8629
+ const defaultExport = () => raceWithAbortSignal(
8630
+ exportPdfBytes(params.snapshot, params.data, effectiveOptions),
8631
+ signal
8632
+ );
8300
8633
  const adapter = this._adapter$.getValue();
8301
8634
  const caps = this.getIoCapabilities();
8302
8635
  const pdfExportCap = caps.formats.export.pdf;
@@ -8310,17 +8643,22 @@ var PdfIoService = class extends Disposable2 {
8310
8643
  }
8311
8644
  let bytes;
8312
8645
  try {
8313
- const raw = await adapter.exportPdf({
8314
- unitId: params.unitId,
8315
- snapshot: params.snapshot,
8316
- data: params.data,
8317
- options: params.options,
8318
- defaultExport
8319
- });
8320
- bytes = await normalizeBinaryToUint8Array(raw);
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);
8321
8658
  } catch (err) {
8322
- attachSuggestedFallbackAndThrow(err, "browser");
8659
+ attachSuggestedFallbackAndThrow(err, "browser", signal);
8323
8660
  }
8661
+ throwIfSignalAborted(signal);
8324
8662
  this.notifyExported({
8325
8663
  unitId: params.unitId,
8326
8664
  bytes,
@@ -8332,11 +8670,13 @@ var PdfIoService = class extends Disposable2 {
8332
8670
  if (!pdfExportCap.browser) {
8333
8671
  attachSuggestedFallbackAndThrow(
8334
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"),
8335
- "server"
8673
+ "server",
8674
+ signal
8336
8675
  );
8337
8676
  }
8338
8677
  try {
8339
8678
  const bytes = await defaultExport();
8679
+ throwIfSignalAborted(signal);
8340
8680
  this.notifyExported({
8341
8681
  unitId: params.unitId,
8342
8682
  bytes,
@@ -8345,7 +8685,7 @@ var PdfIoService = class extends Disposable2 {
8345
8685
  });
8346
8686
  return bytes;
8347
8687
  } catch (err) {
8348
- attachSuggestedFallbackAndThrow(err, "server");
8688
+ attachSuggestedFallbackAndThrow(err, "server", signal);
8349
8689
  }
8350
8690
  }
8351
8691
  async silentPrint(params) {
@@ -8401,6 +8741,42 @@ var PdfIoService = class extends Disposable2 {
8401
8741
  PdfIoService = __decorateClass([
8402
8742
  __decorateParam(0, Optional(IUniverInstanceService4))
8403
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
+ }
8404
8780
 
8405
8781
  // src/plugin.ts
8406
8782
  var UNIVER_PDFS_PLUGIN_NAME = "UNIVER_PDFS_PLUGIN";
@@ -8516,6 +8892,10 @@ export {
8516
8892
  Barcode,
8517
8893
  Box,
8518
8894
  CIRCLE_MARK_BEZIER_KAPPA,
8895
+ DEFAULT_PDF_CJK_FONT_FAMILY,
8896
+ DEFAULT_PDF_CJK_FONT_FILES,
8897
+ DEFAULT_PDF_CJK_FONT_PACKAGE,
8898
+ DEFAULT_PDF_CJK_FONT_VERSION,
8519
8899
  DeleteSelectedPdfElementsCommand,
8520
8900
  DistributeSelectedPdfElementsCommand,
8521
8901
  Document,
@@ -8537,6 +8917,7 @@ export {
8537
8917
  PDF_JSX_ELEMENT_SYMBOL,
8538
8918
  PDF_JSX_FRAGMENT_SYMBOL,
8539
8919
  PDF_PAGE_PRESETS,
8920
+ PDF_S1_S7_FIDELITY_EXPECTATIONS,
8540
8921
  PDF_TABLE_THEME_PRESETS,
8541
8922
  PT_PER_MM,
8542
8923
  Page,
@@ -8619,6 +9000,7 @@ export {
8619
9000
  computeExifTransformMatrix,
8620
9001
  computeExpandedTextHeightMm,
8621
9002
  computeExpandedTextHeightPt,
9003
+ computeFontUrlCacheKey,
8622
9004
  computeImageFitPlacement,
8623
9005
  computePasteCascadeOffset,
8624
9006
  computePdfPayloadDigest,
@@ -8635,7 +9017,10 @@ export {
8635
9017
  createDefaultElement,
8636
9018
  createDefaultPdfUnitData,
8637
9019
  createHttpSilentPrintAdapter,
9020
+ createPdfAbortError,
9021
+ createPdfBrowserFidelityExpectations,
8638
9022
  createPdfBrowserFidelitySamples,
9023
+ createPdfCjkFontSources,
8639
9024
  createPdfJsxNode,
8640
9025
  detectCJKCharacters,
8641
9026
  detectCJKInPdfInputs,
@@ -8671,6 +9056,7 @@ export {
8671
9056
  exportPdfBytes,
8672
9057
  exportPdfToDocxSnapshot,
8673
9058
  exportPdfToWorkbookSnapshot,
9059
+ exportPdfWithTarget,
8674
9060
  exportSignedPdfWithAuditSeal,
8675
9061
  exportToPdfmeTemplate,
8676
9062
  extractAcroFormValuesFromPdfBytes,