@file-viewer/renderer-pptx 3.0.2 → 3.1.0

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.en.md CHANGED
@@ -7,3 +7,5 @@ import { pptxRenderer } from '@file-viewer/renderer-pptx'
7
7
  ```
8
8
 
9
9
  Install `@file-viewer/renderer-ppt` explicitly for legacy `.ppt`, or keep using the compatibility aggregate `@file-viewer/renderer-presentation` when both are required.
10
+
11
+ Worker resolution first honors `presentation.workerUrl` or a configured shared asset base, then uses an emitted or directly served package asset, then checks the standard asset-copy manifest. Unknown locations never fall back to a guessed application-relative URL; Angular, offline, and separate static directories use the standard asset-copy command without application aliases.
package/README.md CHANGED
@@ -7,3 +7,5 @@ import { pptxRenderer } from '@file-viewer/renderer-pptx'
7
7
  ```
8
8
 
9
9
  需要同时支持旧 `.ppt` 时,可显式安装 `@file-viewer/renderer-ppt`,或继续使用兼容聚合包 `@file-viewer/renderer-presentation`。
10
+
11
+ Worker 选择顺序为显式 `presentation.workerUrl` 或共享资源根目录、打包器已输出或包目录内可解析的 Worker、标准复制工具的资源清单。未知路径不会回退为猜测的应用相对地址;Angular、离线或独立静态目录使用标准资产复制,无需业务 alias。
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { PptxViewer, RECOMMENDED_ZIP_LIMITS } from '@file-viewer/pptx';
2
- import { DEFAULT_RENDERER_DEFINITIONS, createFileViewerTranslator, createFileViewerZoomChangeEmitter, getFileViewerShadowRootForNode, normalizeFileViewerErrorMessage, registerFileViewerZoomProvider, resolveFileViewerLocale, resolveFileViewerPresentationWorkerUrl, resolveFileViewerRuntimeAssetBaseUrl, waitForFileViewerNextPaint, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
1
+ import { PptxViewer, RECOMMENDED_ZIP_LIMITS, resolvePptxPackageWorkerUrl } from '@file-viewer/pptx';
2
+ import { DEFAULT_RENDERER_DEFINITIONS, attachFileViewerErrorMessage, createFileViewerTranslator, createFileViewerZoomChangeEmitter, getFileViewerShadowRootForNode, getDefaultFileViewerAssetBaseUrl, normalizeFileViewerErrorMessage, registerFileViewerZoomProvider, resolveFileViewerLocale, resolveFileViewerPresentationWorkerUrl, resolveFileViewerCopiedAssetUrl, resolveFileViewerRuntimeAssetBaseUrl, waitForFileViewerNextPaint, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
3
3
  const pptxStyle = `
4
4
  .pptx-viewer-shell{position:relative;box-sizing:border-box;min-height:100%;padding:24px 20px;background:var(--file-viewer-render-surface-background,#eef3f8);color:#1f2d3b;font-family:Aptos,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif}
5
5
  .pptx-render-surface{min-height:240px}
@@ -235,8 +235,10 @@ const formatPptxDiagnosticError = (error, fallback, context) => {
235
235
  ? rawReason || localizedReason
236
236
  : localizedReason || rawReason) || fallback;
237
237
  const detail = sanitizePptxDiagnosticText(error.detail);
238
- const hint = sanitizePptxDiagnosticText(error.hint) ||
239
- localizePptxDiagnosticCopy(pptxDiagnosticFallbackHints[code], locale);
238
+ // Engine diagnostics may carry source-language hints. A known code has a
239
+ // wrapper-owned translation, so prefer it over the engine's raw copy.
240
+ const hint = localizePptxDiagnosticCopy(pptxDiagnosticFallbackHints[code], locale) ||
241
+ sanitizePptxDiagnosticText(error.hint);
240
242
  const stage = sanitizePptxDiagnosticText(error.stage);
241
243
  const usesWesternPunctuation = locale === 'en-US' || locale === 'de-DE';
242
244
  const separator = usesWesternPunctuation ? ': ' : ':';
@@ -471,6 +473,14 @@ export default async function renderPptx(buffer, target, _type, context) {
471
473
  var _a;
472
474
  (_a = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _a === void 0 ? void 0 : _a.call(context, buildExportAdapter(surface, targetWindow, () => viewer));
473
475
  };
476
+ const reportPptxFailure = (failure) => {
477
+ var _a;
478
+ state = 'error';
479
+ errorMessage = formatErrorMessage(failure, t('presentation.error.parseFailed'), context);
480
+ (_a = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _a === void 0 ? void 0 : _a.call(context, null);
481
+ syncUi();
482
+ return attachFileViewerErrorMessage(failure, errorMessage);
483
+ };
474
484
  registerFileViewerZoomProvider(shell, {
475
485
  zoomIn: () => setZoom(getCurrentZoomPercent() + 15),
476
486
  zoomOut: () => setZoom(getCurrentZoomPercent() - 15),
@@ -508,17 +518,24 @@ export default async function renderPptx(buffer, target, _type, context) {
508
518
  if ((_c = context === null || context === void 0 ? void 0 : context.signal) === null || _c === void 0 ? void 0 : _c.aborted) {
509
519
  throw context.signal.reason || new DOMException('PPTX rendering aborted.', 'AbortError');
510
520
  }
521
+ // Use a package-emitted Worker without probing unrelated manifest URLs.
522
+ // Angular production still needs the CLI's verified copy when its builder
523
+ // leaves dependency-relative Worker references untouched.
524
+ const workerUrl = (presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.workerUrl) || getDefaultFileViewerAssetBaseUrl()
525
+ ? resolveFileViewerPresentationWorkerUrl(presentationOptions, resolveFileViewerRuntimeAssetBaseUrl(documentRef))
526
+ : resolvePptxPackageWorkerUrl() ||
527
+ await resolveFileViewerCopiedAssetUrl(documentRef, 'office-presentation', 'pptx-worker', context === null || context === void 0 ? void 0 : context.signal);
528
+ if ((_d = context === null || context === void 0 ? void 0 : context.signal) === null || _d === void 0 ? void 0 : _d.aborted) {
529
+ throw context.signal.reason || new DOMException('PPTX rendering aborted.', 'AbortError');
530
+ }
531
+ if (!workerUrl) {
532
+ throw new Error('PPTX Worker URL is unavailable. Run file-viewer-copy-assets or provide presentation.workerUrl.');
533
+ }
511
534
  const nextViewer = await PptxViewer.open(buffer, surface, {
512
535
  styleRoot: resolvePptxStyleRoot(surface, context),
513
536
  fitMode: 'contain',
514
537
  zoomPercent,
515
- // Keep the PPTX package's own worker fallback when the host did not
516
- // configure a self-hosted worker. Resolving the generic default here
517
- // would point Vite development at /vendor/pptx/pptx.worker.js, where
518
- // the SPA fallback is HTML rather than worker JavaScript.
519
- workerUrl: (presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.workerUrl)
520
- ? resolveFileViewerPresentationWorkerUrl(presentationOptions, resolveFileViewerRuntimeAssetBaseUrl(documentRef))
521
- : undefined,
538
+ workerUrl,
522
539
  workerType: presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.workerType,
523
540
  zipLimits: RECOMMENDED_ZIP_LIMITS,
524
541
  lazySlides: true,
@@ -558,25 +575,21 @@ export default async function renderPptx(buffer, target, _type, context) {
558
575
  console.warn('PPTX slide render warning:', error);
559
576
  },
560
577
  onError: error => {
561
- var _a, _b;
578
+ var _a;
562
579
  if (disposed || ((_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.aborted)) {
563
580
  return;
564
581
  }
565
- state = 'error';
566
- errorMessage = formatErrorMessage(error, t('presentation.error.parseFailed'), context);
567
- (_b = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _b === void 0 ? void 0 : _b.call(context, null);
568
- syncUi();
569
- rejectCompletion(error);
582
+ rejectCompletion(reportPptxFailure(error));
570
583
  },
571
584
  });
572
- if (disposed || ((_d = context === null || context === void 0 ? void 0 : context.signal) === null || _d === void 0 ? void 0 : _d.aborted)) {
585
+ if (disposed || ((_e = context === null || context === void 0 ? void 0 : context.signal) === null || _e === void 0 ? void 0 : _e.aborted)) {
573
586
  nextViewer.destroy();
574
- throw ((_e = context === null || context === void 0 ? void 0 : context.signal) === null || _e === void 0 ? void 0 : _e.reason) || new DOMException('PPTX rendering aborted.', 'AbortError');
587
+ throw ((_f = context === null || context === void 0 ? void 0 : context.signal) === null || _f === void 0 ? void 0 : _f.reason) || new DOMException('PPTX rendering aborted.', 'AbortError');
575
588
  }
576
589
  viewer = nextViewer;
577
590
  await completion;
578
- if (disposed || ((_f = context === null || context === void 0 ? void 0 : context.signal) === null || _f === void 0 ? void 0 : _f.aborted)) {
579
- throw ((_g = context === null || context === void 0 ? void 0 : context.signal) === null || _g === void 0 ? void 0 : _g.reason) || new DOMException('PPTX rendering aborted.', 'AbortError');
591
+ if (disposed || ((_g = context === null || context === void 0 ? void 0 : context.signal) === null || _g === void 0 ? void 0 : _g.aborted)) {
592
+ throw ((_h = context === null || context === void 0 ? void 0 : context.signal) === null || _h === void 0 ? void 0 : _h.reason) || new DOMException('PPTX rendering aborted.', 'AbortError');
580
593
  }
581
594
  zoomPercent = getCurrentZoomPercent();
582
595
  registerExportAdapter();
@@ -584,16 +597,12 @@ export default async function renderPptx(buffer, target, _type, context) {
584
597
  zoomEmitter.emit();
585
598
  }
586
599
  catch (error) {
587
- if (disposed || ((_h = context === null || context === void 0 ? void 0 : context.signal) === null || _h === void 0 ? void 0 : _h.aborted)) {
600
+ if (disposed || ((_j = context === null || context === void 0 ? void 0 : context.signal) === null || _j === void 0 ? void 0 : _j.aborted)) {
588
601
  throw error;
589
602
  }
590
603
  viewer === null || viewer === void 0 ? void 0 : viewer.destroy();
591
604
  viewer = null;
592
- state = 'error';
593
- errorMessage = formatErrorMessage(error, t('presentation.error.parseFailed'), context);
594
- (_j = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _j === void 0 ? void 0 : _j.call(context, null);
595
- syncUi();
596
- throw error;
605
+ throw reportPptxFailure(error);
597
606
  }
598
607
  finally {
599
608
  (_k = context === null || context === void 0 ? void 0 : context.signal) === null || _k === void 0 ? void 0 : _k.removeEventListener('abort', abort);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-pptx",
3
- "version": "3.0.2",
3
+ "version": "3.1.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone OpenXML PowerPoint renderer for PPTX, PPTM, POTX, POTM, PPSX, and PPSM files.",
@@ -53,8 +53,8 @@
53
53
  "LICENSE"
54
54
  ],
55
55
  "dependencies": {
56
- "@file-viewer/core": "3.0.2",
57
- "@file-viewer/pptx": "3.0.2"
56
+ "@file-viewer/core": "3.1.0",
57
+ "@file-viewer/pptx": "3.1.0"
58
58
  },
59
59
  "devDependencies": {
60
60
  "typescript": "^6.0.3"