@file-viewer/renderer-pptx 3.3.3 → 3.3.4

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.
Files changed (2) hide show
  1. package/dist/index.js +42 -105
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -72,93 +72,23 @@ const clampZoomPercent = (value) => {
72
72
  return Math.min(300, Math.max(25, Math.round(value)));
73
73
  };
74
74
  const pptxDiagnosticMessages = {
75
- PPTX_FILE_EMPTY: {
76
- zh: '文件为空或过小,无法读取。',
77
- en: 'The file is empty or too small to read.',
78
- ja: 'ファイルが空であるか小さすぎるため、読み込めません。',
79
- de: 'Die Datei ist leer oder zu klein zum Lesen.',
80
- },
81
- PPTX_FILE_TOO_LARGE: {
82
- zh: '文件超过浏览器安全预览体积限制。',
83
- en: 'The file is larger than the browser-safe preview limit.',
84
- ja: 'ファイルがブラウザーで安全にプレビューできるサイズ上限を超えています。',
85
- de: 'Die Datei überschreitet die sichere Vorschaugröße des Browsers.',
86
- },
87
- PPTX_INVALID_ZIP: {
88
- zh: '文件不是有效的 PowerPoint OpenXML 压缩包。',
89
- en: 'The file is not a valid PowerPoint OpenXML package.',
90
- ja: '有効な PowerPoint OpenXML パッケージではありません。',
91
- de: 'Die Datei ist kein gültiges PowerPoint-OpenXML-Paket.',
92
- },
93
- PPTX_MISSING_CONTENT_TYPES: {
94
- zh: '文件缺少 [Content_Types].xml,无法识别内部结构。',
95
- en: 'The package is missing [Content_Types].xml, so its structure cannot be identified.',
96
- ja: '[Content_Types].xml がないため、内部構造を識別できません。',
97
- de: '[Content_Types].xml fehlt; die Paketstruktur kann nicht erkannt werden.',
98
- },
99
- PPTX_MISSING_PRESENTATION: {
100
- zh: '文件缺少 ppt/presentation.xml,无法读取幻灯片列表。',
101
- en: 'The package is missing ppt/presentation.xml, so the slide list cannot be read.',
102
- ja: 'ppt/presentation.xml がないため、スライド一覧を読み込めません。',
103
- de: 'ppt/presentation.xml fehlt; die Folienliste kann nicht gelesen werden.',
104
- },
105
- PPTX_NO_SLIDES: {
106
- zh: '文件中没有找到可预览的幻灯片。',
107
- en: 'No previewable slides were found in the file.',
108
- ja: 'プレビュー可能なスライドが見つかりませんでした。',
109
- de: 'Es wurden keine Folien für die Vorschau gefunden.',
110
- },
111
- PPTX_MISSING_SLIDE: {
112
- zh: '文件缺少某一页幻灯片内容。',
113
- en: 'The package is missing one of the slide parts.',
114
- ja: 'スライド部品の一部がありません。',
115
- de: 'Ein Folienbestandteil fehlt im Paket.',
116
- },
117
- PPTX_SLIDE_RENDER_FAILED: {
118
- zh: '某一页幻灯片解析失败。',
119
- en: 'One slide failed to parse.',
120
- ja: 'スライドの解析に失敗しました。',
121
- de: 'Eine Folie konnte nicht verarbeitet werden.',
122
- },
123
- PPTX_WORKER_FAILED: {
124
- zh: 'PPTX Worker 启动或运行失败。',
125
- en: 'The PPTX Worker failed to start or run.',
126
- ja: 'PPTX Worker の起動または実行に失敗しました。',
127
- de: 'Der PPTX-Worker konnte nicht gestartet oder ausgeführt werden.',
128
- },
129
- PPTX_PARSE_FAILED: {
130
- zh: 'PPTX 文件解析失败。',
131
- en: 'The PPTX file could not be parsed.',
132
- ja: 'PPTX ファイルを解析できませんでした。ファイルを再保存するか、入力元を確認してください。',
133
- de: 'Die PPTX-Datei konnte nicht verarbeitet werden.',
134
- },
75
+ "PPTX_FILE_EMPTY": "presentation.diagnostic.reason.PPTX_FILE_EMPTY",
76
+ "PPTX_FILE_TOO_LARGE": "presentation.diagnostic.reason.PPTX_FILE_TOO_LARGE",
77
+ "PPTX_INVALID_ZIP": "presentation.diagnostic.reason.PPTX_INVALID_ZIP",
78
+ "PPTX_MISSING_CONTENT_TYPES": "presentation.diagnostic.reason.PPTX_MISSING_CONTENT_TYPES",
79
+ "PPTX_MISSING_PRESENTATION": "presentation.diagnostic.reason.PPTX_MISSING_PRESENTATION",
80
+ "PPTX_NO_SLIDES": "presentation.diagnostic.reason.PPTX_NO_SLIDES",
81
+ "PPTX_MISSING_SLIDE": "presentation.diagnostic.reason.PPTX_MISSING_SLIDE",
82
+ "PPTX_SLIDE_RENDER_FAILED": "presentation.diagnostic.reason.PPTX_SLIDE_RENDER_FAILED",
83
+ "PPTX_WORKER_FAILED": "presentation.diagnostic.reason.PPTX_WORKER_FAILED",
84
+ "PPTX_PARSE_FAILED": "presentation.diagnostic.reason.PPTX_PARSE_FAILED"
135
85
  };
136
86
  const pptxDiagnosticFallbackHints = {
137
- PPTX_INVALID_ZIP: {
138
- zh: '请确认接口返回的是原始 .pptx 二进制文件,而不是登录页、HTML/JSON 错误响应或被截断的内容。',
139
- en: 'Confirm that the response is the original .pptx binary, not a login page, HTML/JSON error response, or truncated download.',
140
- ja: 'レスポンスがログインページや HTML/JSON エラー、途中で切れたデータではなく、元の .pptx バイナリであることを確認してください。',
141
- de: 'Prüfen Sie, ob die Antwort die ursprüngliche .pptx-Datei und keine Anmeldeseite, HTML/JSON-Fehlerantwort oder unvollständige Datei enthält.',
142
- },
143
- PPTX_WORKER_FAILED: {
144
- zh: '请检查 presentation.workerUrl、Worker 文件路径、MIME 类型、CSP 和跨域策略。',
145
- en: 'Check presentation.workerUrl, the Worker file path, MIME type, CSP, and cross-origin policy.',
146
- ja: 'presentation.workerUrl、Worker のパス、MIME type、CSP、cross-origin policy を確認してください。',
147
- de: 'Prüfen Sie presentation.workerUrl, den Worker-Pfad, den MIME-Typ, CSP und die Cross-Origin-Richtlinie.',
148
- },
149
- PPTX_NO_SLIDES: {
150
- zh: '请重新保存演示文稿,或检查包内是否存在 ppt/slides/slide*.xml。',
151
- en: 'Re-save the presentation, or check whether ppt/slides/slide*.xml exists inside the package.',
152
- ja: 'プレゼンテーションを再保存するか、パッケージに ppt/slides/slide*.xml があるか確認してください。',
153
- de: 'Speichern Sie die Präsentation erneut oder prüfen Sie, ob ppt/slides/slide*.xml im Paket vorhanden ist.',
154
- },
155
- };
156
- const localizePptxDiagnosticCopy = (copy, locale) => {
157
- if (!copy) {
158
- return '';
159
- }
160
- return locale === 'zh-CN' ? copy.zh : locale === 'ja-JP' ? copy.ja : locale === 'de-DE' ? copy.de : copy.en;
87
+ "PPTX_INVALID_ZIP": "presentation.diagnostic.hint.PPTX_INVALID_ZIP",
88
+ "PPTX_WORKER_FAILED": "presentation.diagnostic.hint.PPTX_WORKER_FAILED",
89
+ "PPTX_NO_SLIDES": "presentation.diagnostic.hint.PPTX_NO_SLIDES"
161
90
  };
91
+ const localizePptxDiagnosticCopy = (key, input) => key ? createFileViewerTranslator(input)(key) : '';
162
92
  const sanitizePptxDiagnosticText = (value) => {
163
93
  if (typeof value !== 'string') {
164
94
  return '';
@@ -223,29 +153,28 @@ const classifyPptxErrorString = (message) => {
223
153
  }
224
154
  return null;
225
155
  };
226
- const formatPptxDiagnosticError = (error, fallback, context) => {
227
- const locale = resolveFileViewerLocale(context === null || context === void 0 ? void 0 : context.options);
156
+ const formatPptxDiagnosticError = (error, fallback, context, i18n = (context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options)) => {
157
+ const t = createFileViewerTranslator(i18n);
158
+ const locale = resolveFileViewerLocale(i18n);
228
159
  const code = String(error.code || 'PPTX_PARSE_FAILED');
229
- const localizedReason = localizePptxDiagnosticCopy(pptxDiagnosticMessages[code], locale);
160
+ const localizedReason = localizePptxDiagnosticCopy(pptxDiagnosticMessages[code], i18n);
230
161
  const rawReason = sanitizePptxDiagnosticText(error.message);
231
- const reason = (locale === 'zh-CN'
232
- ? rawReason || localizedReason
233
- : localizedReason || rawReason) || fallback;
162
+ const reason = localizedReason || rawReason || fallback;
234
163
  const detail = sanitizePptxDiagnosticText(error.detail);
235
- const hint = localizePptxDiagnosticCopy(pptxDiagnosticFallbackHints[code], locale) ||
164
+ const hint = localizePptxDiagnosticCopy(pptxDiagnosticFallbackHints[code], i18n) ||
236
165
  sanitizePptxDiagnosticText(error.hint);
237
166
  const stage = sanitizePptxDiagnosticText(error.stage);
238
- const usesWesternPunctuation = locale === 'en-US' || locale === 'de-DE';
167
+ const usesWesternPunctuation = !locale.startsWith('zh') && locale !== 'ja-JP';
239
168
  const separator = usesWesternPunctuation ? ': ' : ':';
240
169
  const parts = [`${fallback}${separator}${reason}`];
241
170
  if (stage) {
242
- parts.push(locale === 'zh-CN' ? `阶段:${stage}` : locale === 'ja-JP' ? `段階:${stage}` : locale === 'de-DE' ? `Phase: ${stage}` : `Stage: ${stage}`);
171
+ parts.push(t('presentation.diagnostic.stage', { value: stage }));
243
172
  }
244
173
  if (detail && detail !== reason) {
245
- parts.push(locale === 'zh-CN' ? `详情:${detail}` : locale === 'ja-JP' ? `詳細:${detail}` : locale === 'de-DE' ? `Details: ${detail}` : `Detail: ${detail}`);
174
+ parts.push(t('presentation.diagnostic.detail', { value: detail }));
246
175
  }
247
176
  if (hint) {
248
- parts.push(locale === 'zh-CN' ? `建议:${hint}` : locale === 'ja-JP' ? `対処:${hint}` : locale === 'de-DE' ? `Hinweis: ${hint}` : `Hint: ${hint}`);
177
+ parts.push(t('presentation.diagnostic.hint', { value: hint }));
249
178
  }
250
179
  return parts.join(usesWesternPunctuation ? '; ' : ';');
251
180
  };
@@ -254,7 +183,7 @@ const formatErrorMessage = (error, fallback, context) => {
254
183
  return formatPptxDiagnosticError(error, fallback, context);
255
184
  }
256
185
  if (error instanceof Error || typeof error === 'string') {
257
- const normalized = normalizeFileViewerErrorMessage(error, context === null || context === void 0 ? void 0 : context.options);
186
+ const normalized = normalizeFileViewerErrorMessage(error, (context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options));
258
187
  const classified = classifyPptxErrorString(normalized);
259
188
  if (classified) {
260
189
  return formatPptxDiagnosticError(classified, fallback, context);
@@ -303,13 +232,14 @@ const buildExportAdapter = (surface, targetWindow, getViewer) => ({
303
232
  });
304
233
  export default async function renderPptx(buffer, target, _type, context) {
305
234
  var _a;
306
- const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
235
+ const t = createFileViewerTranslator((context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options));
307
236
  const documentRef = target.ownerDocument || document;
308
237
  const targetWindow = documentRef.defaultView || (typeof window !== 'undefined' ? window : null);
309
238
  const zoomEmitter = createFileViewerZoomChangeEmitter();
310
239
  let viewer = null;
311
240
  let state = 'loading';
312
241
  let errorMessage = '';
242
+ let errorCopy;
313
243
  let zoomPercent = 100;
314
244
  let progressiveReady = false;
315
245
  let disposed = false;
@@ -318,16 +248,16 @@ export default async function renderPptx(buffer, target, _type, context) {
318
248
  shell.dataset.viewerZoomProvider = 'pptx';
319
249
  const loading = createElement(documentRef, 'div', 'pptx-loading');
320
250
  loading.setAttribute('aria-live', 'polite');
321
- loading.append(createElement(documentRef, 'span', 'pptx-loading-dot'), createElement(documentRef, 'span', undefined, t('presentation.state.loading')));
251
+ loading.append(createElement(documentRef, 'span', 'pptx-loading-dot'), t.text(createElement(documentRef, 'span', undefined), 'presentation.state.loading'));
322
252
  const error = createElement(documentRef, 'div', 'pptx-error');
323
- const errorTitle = createElement(documentRef, 'strong', undefined, t('presentation.error.title'));
253
+ const errorTitle = t.text(createElement(documentRef, 'strong', undefined), 'presentation.error.title');
324
254
  const errorText = createElement(documentRef, 'p');
325
255
  error.append(errorTitle, errorText);
326
256
  const slideshowButton = createElement(documentRef, 'button', 'pptx-slideshow-button');
327
257
  slideshowButton.type = 'button';
328
258
  slideshowButton.hidden = true;
329
259
  const slideshowGlyph = createElement(documentRef, 'span', 'pptx-slideshow-button-glyph', '▶');
330
- const slideshowText = createElement(documentRef, 'span', undefined, t('presentation.slideshow.start'));
260
+ const slideshowText = t.text(createElement(documentRef, 'span', undefined), 'presentation.slideshow.start');
331
261
  const slideshowKey = createElement(documentRef, 'span', 'pptx-slideshow-button-key', SLIDESHOW_HOTKEY_LABEL);
332
262
  slideshowButton.append(slideshowGlyph, slideshowText, slideshowKey);
333
263
  slideshowButton.addEventListener('click', () => {
@@ -447,13 +377,15 @@ export default async function renderPptx(buffer, target, _type, context) {
447
377
  var _a;
448
378
  loading.hidden = !(state === 'loading' && !errorMessage);
449
379
  error.hidden = state !== 'error';
450
- errorText.textContent = errorMessage;
380
+ t.bind(errorText, node => { node.textContent = (errorCopy === null || errorCopy === void 0 ? void 0 : errorCopy(context === null || context === void 0 ? void 0 : context.options)) || errorMessage; });
451
381
  surface.classList.toggle('is-loading', state === 'loading');
452
382
  const presenting = Boolean(viewer === null || viewer === void 0 ? void 0 : viewer.presenting);
453
383
  slideshowButton.hidden = state !== 'ready' || ((_a = viewer === null || viewer === void 0 ? void 0 : viewer.slideCount) !== null && _a !== void 0 ? _a : 0) === 0;
454
- slideshowText.textContent = presenting
455
- ? t('presentation.slideshow.exit')
456
- : t('presentation.slideshow.start');
384
+ t.bind(slideshowText, localizedNode => {
385
+ localizedNode.textContent = presenting
386
+ ? t('presentation.slideshow.exit')
387
+ : t('presentation.slideshow.start');
388
+ }, 'textContent');
457
389
  slideshowButton.setAttribute('aria-pressed', presenting ? 'true' : 'false');
458
390
  };
459
391
  const registerExportAdapter = () => {
@@ -463,10 +395,14 @@ export default async function renderPptx(buffer, target, _type, context) {
463
395
  const reportPptxFailure = (failure) => {
464
396
  var _a;
465
397
  state = 'error';
398
+ const retainedDiagnostic = isPptxDiagnosticErrorLike(failure)
399
+ ? { ...failure }
400
+ : classifyPptxErrorString(normalizeFileViewerErrorMessage(failure, (context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options)));
401
+ errorCopy = retainedDiagnostic ? i18n => formatPptxDiagnosticError(retainedDiagnostic, createFileViewerTranslator(i18n)('presentation.error.parseFailed'), context, i18n) : undefined;
466
402
  errorMessage = formatErrorMessage(failure, t('presentation.error.parseFailed'), context);
467
403
  (_a = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _a === void 0 ? void 0 : _a.call(context, null);
468
404
  syncUi();
469
- return attachFileViewerErrorMessage(failure, errorMessage);
405
+ return attachFileViewerErrorMessage(failure, errorCopy || errorMessage);
470
406
  };
471
407
  registerFileViewerZoomProvider(shell, {
472
408
  zoomIn: () => setZoom(getCurrentZoomPercent() + 15),
@@ -480,6 +416,7 @@ export default async function renderPptx(buffer, target, _type, context) {
480
416
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
481
417
  state = 'loading';
482
418
  errorMessage = '';
419
+ errorCopy = undefined;
483
420
  progressiveReady = false;
484
421
  syncUi();
485
422
  const presentationOptions = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.presentation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-pptx",
3
- "version": "3.3.3",
3
+ "version": "3.3.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone OpenXML PowerPoint renderer for PPTX, PPTM, POTX, POTM, PPSX, and PPSM files.",
@@ -54,8 +54,8 @@
54
54
  "README.zh-CN.md"
55
55
  ],
56
56
  "dependencies": {
57
- "@file-viewer/core": "3.3.3",
58
- "@file-viewer/pptx": "3.3.3"
57
+ "@file-viewer/core": "3.3.4",
58
+ "@file-viewer/pptx": "3.3.4"
59
59
  },
60
60
  "fileViewer": {
61
61
  "capabilityManifest": "./file-viewer.capability.json",